]> git.vomp.tv Git - vompclient.git/blob - videoomx.h
WIN32 compatibility
[vompclient.git] / videoomx.h
1 /*
2     Copyright 2004-2005 Chris Tallon 2009,2012 Marten Richter
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
18 */
19
20
21 #ifndef VIDEOOMX_H
22 #define VIDEOOMX_H
23
24 #include <stdio.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <sys/ioctl.h>
28 #include <string.h>
29 #include <stdint.h>
30 #include <list>
31 #include <vector>
32 #include <mutex>
33
34 #include "signal.h"
35
36 #include "defines.h"
37 #include "video.h"
38 #include "threadsystem.h"
39
40
41
42 #define OMX_SKIP64BIT
43
44 #include <IL/OMX_Core.h>
45 #include <IL/OMX_Types.h>
46 #include <IL/OMX_Component.h>
47 #include <IL/OMX_Broadcom.h>
48
49
50 struct VPE_OMX_EVENT {
51         OMX_IN OMX_HANDLETYPE handle;
52         OMX_IN OMX_PTR appdata;
53     OMX_IN OMX_EVENTTYPE event_type;
54     OMX_IN OMX_U32 data1;
55         OMX_IN OMX_U32 data2;
56         OMX_IN OMX_PTR event_data;
57 };
58
59
60
61
62 class AudioVPE;
63
64 class VideoOMX : public Video
65 {
66   friend class AudioOMX;
67   friend class ImageOMX;
68   public:
69     VideoOMX();
70     virtual ~VideoOMX();
71
72     int init(UCHAR format);
73     int shutdown();
74
75     UCHAR getSupportedFormats() { return COMPOSITERGB | HDMI;};
76     UINT supportedTVsize() { return ASPECT4X3|ASPECT16X9|ASPECT14X9 ;};
77     UCHAR supportedTVFormats() { return NTSC|PAL|PAL_M|NTSC_J;};
78
79     int setFormat(UCHAR format);
80     int setConnection(UCHAR connection);
81     int setAspectRatio(UCHAR aspectRatio, int tparx,int tpary);   // This one does the pin 8 scart widescreen switching
82     int setMode(UCHAR mode);
83     bool setVideoDisplay(VideoDisplay display);
84     int setTVsize(UCHAR size);               // Is the TV a widescreen?
85     UCHAR getTVsize();
86
87     void executePendingModeChanges();
88     int setDefaultAspect();
89     int setSource();
90     int setPosition(int x, int y);
91     int sync();
92     int play();
93     int stop();
94     int pause();
95     int unPause();
96     int fastForward();
97     int unFastForward();
98     int reset();
99     int blank();
100     int signalOn();
101     int signalOff();
102     int attachFrameBuffer(); // What does this do?
103     ULONG timecodeToFrameNumber(ULLONG timecode);
104     ULLONG getCurrentTimestamp();
105     bool displayIFrame(const UCHAR* bulibaver, UINT length);
106
107     virtual bool dtsTimefix(){return false;} //please we need dts time values
108     virtual int getTeletextBufferFaktor(){return 5;};
109
110     // Writing Data to Videodevice
111     virtual void PrepareMediaSample(const MediaPacketList&, UINT samplepos);
112     virtual UINT DeliverMediaSample(UCHAR* bulibaver, UINT* samplepos);
113
114
115         virtual bool supportsh264(){return true;};
116         virtual bool supportsmpeg2(){return mpeg2_supported;};
117
118         int WriteOutTS(const unsigned char *bulibaver,int length, int type);
119         void WriteOutPATPMT();
120
121
122
123         virtual long long SetStartOffset(long long curreftime, bool *rsync);
124         long long SetStartAudioOffset(long long curreftime, bool *rsync);
125         virtual void ResetTimeOffsets();
126
127         bool loadOptionsFromServer(VDR* vdr);
128         bool saveOptionstoServer();
129         bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane);
130         bool handleOptionChanges(Option* option);
131
132
133 #ifdef DEV
134     int test();
135     int test2();
136 #endif
137
138
139
140     static inline OMX_TICKS intToOMXTicks(long long pts) {
141         OMX_TICKS temp;
142         temp.nLowPart=pts;
143         temp.nHighPart=pts>>32;
144         return temp;
145     }
146
147
148
149   private:
150            int EnterIframePlayback();
151            bool iframemode;
152            bool InIframemode() {return iframemode;};
153
154            virtual bool DrainTargetBufferFull();
155
156            UINT DeliverMediaPacket(MediaPacket packet,const UCHAR* bulibaver,UINT *samplepos);
157
158 #define VPE_DECODER_OMX 1
159
160
161
162            bool offsetnotset;
163            bool offsetvideonotset;
164            bool offsetaudionotset;
165            long long startoffset;
166            long long lastrefvideotime;
167            long long lastrefaudiotime;
168           // long long cur_pts;
169            long long lastreftimeOMX;
170            ULLONG lastreftimePTS;
171
172         //   long long playbacktimeoffset; //this is the offset between the media time and system clock
173         //   long long pausetimecode;
174            bool clockpaused;
175
176          /*  static long long GetCurrentSystemTime();
177            static void WaitUntil(long long time);
178            void FrameWaitforDisplay(long long pts);
179            bool FrameSkip(long long pts);
180            bool skipping;
181            void AdjustAudioPTS(long long pts);*/
182
183
184
185
186            static OMX_ERRORTYPE EventHandler_OMX(OMX_IN OMX_HANDLETYPE handle,OMX_IN OMX_PTR appdata,
187            OMX_IN OMX_EVENTTYPE event_type,OMX_IN OMX_U32 data1,
188            OMX_IN OMX_U32 data2,OMX_IN OMX_PTR event_data);
189            static OMX_ERRORTYPE EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
190            static OMX_ERRORTYPE FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
191
192            UINT DeliverMediaPacketOMX(MediaPacket packet,
193                                                      const UCHAR* bulibaver,
194                                                      UINT *samplepos);
195
196            bool detectIFrame(const UCHAR *buffer,unsigned int length);
197
198            int PrepareInputBufsOMX();
199            int DestroyInputBufsOMX();
200
201            void AddOmxEvent(VPE_OMX_EVENT  new_event);
202            void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver);
203
204            int ChangeComponentState(OMX_HANDLETYPE handle,OMX_STATETYPE type, bool wait=true);
205            int CommandFinished(OMX_HANDLETYPE handle,OMX_U32 command,OMX_U32 data2);
206            int WaitForEvent(OMX_HANDLETYPE handle,OMX_U32 event,int wait=200);
207            int EnablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait);
208            int DisablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait=true);
209            int clearEvents();
210            int clearEventsForComponent(OMX_HANDLETYPE handle);
211            void checkForStalledBuffers();
212
213
214        int setClockExecutingandRunning();
215        int initClock();
216        void destroyClock();
217        int idleClock();
218        int getClockAudioandInit(OMX_HANDLETYPE *p_omx_clock,OMX_U32 *p_omx_clock_output_port);
219        int getClockVideoandInit();
220        void LockClock() {clock_mutex.lock();};
221        void UnlockClock() {clock_mutex.unlock();};
222        OMX_ERRORTYPE ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFERHEADERTYPE* buffer);
223        void clockPause();
224        void clockUnpause();
225        bool isClockPaused() {return clockpaused;};
226
227        void signalOmx() {omx_event_ready_signal.signal();};
228
229        void interlaceSwitch4Demux();
230
231        std::mutex clock_mutex; //clock mutex is now responsible for all omx stuff
232        long long cur_clock_time;
233
234
235
236            OMX_HANDLETYPE omx_vid_dec;
237            OMX_HANDLETYPE omx_vid_sched;
238            OMX_HANDLETYPE omx_vid_deint;
239            OMX_HANDLETYPE omx_vid_rend;
240            OMX_HANDLETYPE omx_clock;
241            int clock_references;
242            bool dodeint; //deinterlacer was activated in omx filtergraph
243            bool first_frame; //handle frame change
244            void FirstFrameFix();
245
246
247            OMX_U32 omx_codec_input_port;
248            OMX_U32 omx_codec_output_port;
249            OMX_U32 omx_deint_input_port;
250            OMX_U32 omx_deint_output_port;
251            OMX_U32 omx_rend_input_port;
252            OMX_U32 omx_shed_input_port;
253            OMX_U32 omx_shed_output_port;
254            OMX_U32 omx_shed_clock_port;
255            OMX_U32 omx_clock_output_port;
256          //  OMX_NALUFORMATSTYPE omx_nalu_format;
257            bool omx_vid_stalled;
258
259
260
261
262
263            int AllocateCodecsOMX();
264            int DeAllocateCodecsOMX();
265            int FlushRenderingPipe();
266
267            std::vector<OMX_BUFFERHEADERTYPE*> input_bufs_omx_all;
268            std::list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_free;
269            std::mutex input_bufs_omx_mutex;
270            OMX_BUFFERHEADERTYPE* cur_input_buf_omx;
271
272            void PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer);
273
274
275
276            bool omx_running;
277            bool omx_first_frame;
278
279            std::mutex omx_event_mutex;
280            Signal omx_event_ready_signal;
281
282            std::list<VPE_OMX_EVENT> omx_events;
283
284            bool omx_mpeg2;
285            bool omx_h264;
286            float xpos,ypos;
287            float width, height;
288            bool windowed;
289            int deinterlace;
290            void updateMode();//called internally to adjust for different parameters
291            void selectVideoMode(int interlaced);
292
293            UCHAR tvsystem;
294            bool signalon;
295            bool pendingmodechange;
296            bool hdmi;
297            bool mpeg2_supported;
298            int outputinterlaced;
299
300
301
302
303
304            bool firstsynched;
305
306
307            std::vector<MediaPacket> mediapackets;
308
309            char L_VPE_OMX_CLOCK[128];
310            char L_VPE_OMX_H264_DECODER[128];
311            char L_VPE_OMX_MPEG2_DECODER[128];
312            char L_VPE_OMX_VIDEO_SCHED[128];
313            char L_VPE_OMX_VIDEO_REND[128];
314            char L_VPE_OMX_VIDEO_DEINTERLACE[128];
315
316 };
317
318 #endif