]> git.vomp.tv Git - vompclient-marten.git/blob - videoomx.h
Fix bug in demuxer widescreen signaling
[vompclient-marten.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, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21
22 #ifndef VIDEOOMX_H
23 #define VIDEOOMX_H
24
25 #include "mutex.h"
26
27
28 #include <stdio.h>
29 #include <unistd.h>
30 #include <fcntl.h>
31 #include <sys/ioctl.h>
32 #include <string.h>
33
34 #include <stdint.h>
35
36 #include <list>
37 #include <vector>
38
39 #include "defines.h"
40 #include "video.h"
41 #include "threadsystem.h"
42
43 #define OMX_SKIP64BIT
44
45 #include <IL/OMX_Core.h>
46 #include <IL/OMX_Types.h>
47 #include <IL/OMX_Component.h>
48 #include <IL/OMX_Broadcom.h>
49
50
51 struct VPE_OMX_EVENT {
52         OMX_IN OMX_HANDLETYPE handle;
53         OMX_IN OMX_PTR appdata;
54     OMX_IN OMX_EVENTTYPE event_type;
55     OMX_IN OMX_U32 data1;
56         OMX_IN OMX_U32 data2;
57         OMX_IN OMX_PTR event_data;
58 };
59
60
61
62
63 class AudioVPE;
64
65 class VideoOMX : public Video
66 {
67   friend class AudioOMX;
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     int setTVsize(UCHAR size);               // Is the TV a widescreen?
84    UCHAR getTVsize();
85
86     void executePendingModeChanges();
87     int setDefaultAspect();
88     int setSource();
89     int setPosition(int x, int y);
90     int sync();
91     int play();
92     int stop();
93     int pause();
94     int unPause();
95     int fastForward();
96     int unFastForward();
97     int reset();
98     int blank();
99     int signalOn();
100     int signalOff();
101     int attachFrameBuffer(); // What does this do?
102     ULONG timecodeToFrameNumber(ULLONG timecode);
103     ULLONG getCurrentTimestamp();
104     bool displayIFrame(const UCHAR* bulibaver, UINT length);
105
106     virtual bool dtsTimefix(){return false;} //please we need dts time values
107     virtual int getTeletextBufferFaktor(){return 5;};
108
109     // Writing Data to Videodevice
110     virtual void PrepareMediaSample(const MediaPacketList&, UINT samplepos);
111     virtual UINT DeliverMediaSample(UCHAR* bulibaver, UINT* samplepos);
112
113
114         virtual bool supportsh264(){return true;};
115         virtual bool supportsmpeg2(){return mpeg2_supported;};
116
117         int WriteOutTS(const unsigned char *bulibaver,int length, int type);
118         void WriteOutPATPMT();
119
120
121
122         virtual long long SetStartOffset(long long curreftime, bool *rsync);
123         long long SetStartAudioOffset(long long curreftime, bool *rsync);
124         virtual void ResetTimeOffsets();
125
126         bool loadOptionsfromServer(VDR* vdr);
127         bool saveOptionstoServer();
128         bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane);
129         bool handleOptionChanges(Option* option);
130
131
132 #ifdef DEV
133     int test();
134     int test2();
135 #endif
136
137
138
139     static inline OMX_TICKS intToOMXTicks(long long pts) {
140         OMX_TICKS temp;
141         temp.nLowPart=pts;
142         temp.nHighPart=pts>>32;
143         return temp;
144     }
145
146
147
148   private:
149            int EnterIframePlayback();
150            bool iframemode;
151            bool InIframemode() {return iframemode;};
152
153            virtual bool DrainTargetBufferFull();
154
155            UINT DeliverMediaPacket(MediaPacket packet,const UCHAR* bulibaver,UINT *samplepos);
156
157 #define VPE_DECODER_OMX 1
158
159
160
161            bool offsetnotset;
162            bool offsetvideonotset;
163            bool offsetaudionotset;
164            long long startoffset;
165            long long lastrefvideotime;
166            long long lastrefaudiotime;
167           // long long cur_pts;
168            long long lastreftimeOMX;
169            ULLONG lastreftimePTS;
170
171         //   long long playbacktimeoffset; //this is the offset between the media time and system clock
172         //   long long pausetimecode;
173            bool clockpaused;
174
175          /*  static long long GetCurrentSystemTime();
176            static void WaitUntil(long long time);
177            void FrameWaitforDisplay(long long pts);
178            bool FrameSkip(long long pts);
179            bool skipping;
180            void AdjustAudioPTS(long long pts);*/
181
182
183
184
185            static OMX_ERRORTYPE EventHandler_OMX(OMX_IN OMX_HANDLETYPE handle,OMX_IN OMX_PTR appdata,
186            OMX_IN OMX_EVENTTYPE event_type,OMX_IN OMX_U32 data1,
187            OMX_IN OMX_U32 data2,OMX_IN OMX_PTR event_data);
188            static OMX_ERRORTYPE EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
189            static OMX_ERRORTYPE FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
190
191            UINT DeliverMediaPacketOMX(MediaPacket packet,
192                                                      const UCHAR* bulibaver,
193                                                      UINT *samplepos);
194
195            bool detectIFrame(const UCHAR *buffer,unsigned int length);
196
197            int PrepareInputBufsOMX();
198            int DestroyInputBufsOMX();
199
200            void AddOmxEvent(VPE_OMX_EVENT  new_event);
201            void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver);
202
203            int ChangeComponentState(OMX_HANDLETYPE handle,OMX_STATETYPE type);
204            int CommandFinished(OMX_HANDLETYPE handle,OMX_U32 command,OMX_U32 data2);
205            int WaitForEvent(OMX_HANDLETYPE handle,OMX_U32 event,int wait=1000);
206            int EnablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait);
207            int DisablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait=true);
208            int clearEvents();
209            void checkForStalledBuffers();
210
211
212        int setClockExecutingandRunning();
213        int initClock();
214        void destroyClock();
215        int idleClock();
216        int getClockAudioandInit(OMX_HANDLETYPE *p_omx_clock,OMX_U32 *p_omx_clock_output_port);
217        int getClockVideoandInit();
218        void LockClock() {clock_mutex.Lock();};
219        void UnlockClock() {clock_mutex.Unlock();};
220        OMX_ERRORTYPE ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFERHEADERTYPE* buffer);
221        void clockPause();
222        void clockUnpause();
223        bool isClockPaused() {return clockpaused;};
224
225        void interlaceSwitch4Demux();
226
227        Mutex clock_mutex; //clock mutex is now responsible for all omx stuff
228        long long cur_clock_time;
229
230
231
232            OMX_HANDLETYPE omx_vid_dec;
233            OMX_HANDLETYPE omx_vid_sched;
234            OMX_HANDLETYPE omx_vid_deint;
235            OMX_HANDLETYPE omx_vid_rend;
236            OMX_HANDLETYPE omx_clock;
237            int clock_references;
238            bool dodeint; //deinterlacer was activated in omx filtergraph
239            bool first_frame; //handle frame change
240            void FirstFrameFix();
241
242
243            OMX_U32 omx_codec_input_port;
244            OMX_U32 omx_codec_output_port;
245            OMX_U32 omx_deint_input_port;
246            OMX_U32 omx_deint_output_port;
247            OMX_U32 omx_rend_input_port;
248            OMX_U32 omx_shed_input_port;
249            OMX_U32 omx_shed_output_port;
250            OMX_U32 omx_shed_clock_port;
251            OMX_U32 omx_clock_output_port;
252          //  OMX_NALUFORMATSTYPE omx_nalu_format;
253            bool omx_vid_stalled;
254
255
256
257
258
259            int AllocateCodecsOMX();
260            int DeAllocateCodecsOMX();
261            int FlushRenderingPipe();
262
263            vector<OMX_BUFFERHEADERTYPE*> input_bufs_omx_all;
264            list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_free;
265            Mutex input_bufs_omx_mutex;
266            OMX_BUFFERHEADERTYPE* cur_input_buf_omx;
267
268            void PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer);
269
270
271
272            bool omx_running;
273            bool omx_first_frame;
274
275            Mutex omx_event_mutex;
276
277            list<VPE_OMX_EVENT> omx_events;
278
279            bool omx_mpeg2;
280            bool omx_h264;
281            float xpos,ypos;
282            int deinterlace;
283            void updateMode();//called internally to adjust for different parameters
284            void selectVideoMode(int interlaced);
285            UCHAR tvsystem;
286            bool signalon;
287            bool pendingmodechange;
288            bool hdmi;
289            bool mpeg2_supported;
290            int outputinterlaced;
291
292
293
294    bool firstsynched;
295
296     
297    vector<MediaPacket> mediapackets;
298 };
299
300 #endif