]> git.vomp.tv Git - vompclient.git/blob - videoomx.h
Let vomp handle aspect ratio change, better aspect ratio control for HD and SD
[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, 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
85     void executePendingModeChanges();
86     int setDefaultAspect();
87     int setSource();
88     int setPosition(int x, int y);
89     int sync();
90     int play();
91     int stop();
92     int pause();
93     int unPause();
94     int fastForward();
95     int unFastForward();
96     int reset();
97     int blank();
98     int signalOn();
99     int signalOff();
100     int attachFrameBuffer(); // What does this do?
101     ULONG timecodeToFrameNumber(ULLONG timecode);
102     ULLONG getCurrentTimestamp();
103     bool displayIFrame(const UCHAR* bulibaver, UINT length);
104
105     virtual bool dtsTimefix(){return false;} //please we need dts time values
106     virtual int getTeletextBufferFaktor(){return 5;};
107
108     // Writing Data to Videodevice
109     virtual void PrepareMediaSample(const MediaPacketList&, UINT samplepos);
110     virtual UINT DeliverMediaSample(UCHAR* bulibaver, UINT* samplepos);
111
112
113         virtual bool supportsh264(){return true;};
114
115         int WriteOutTS(const unsigned char *bulibaver,int length, int type);
116         void WriteOutPATPMT();
117
118
119
120         virtual long long SetStartOffset(long long curreftime, bool *rsync);
121         long long SetStartAudioOffset(long long curreftime, bool *rsync);
122         virtual void ResetTimeOffsets();
123
124         bool loadOptionsfromServer(VDR* vdr);
125         bool saveOptionstoServer();
126         bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane);
127         bool handleOptionChanges(Option* option);
128
129
130 #ifdef DEV
131     int test();
132     int test2();
133 #endif
134
135
136
137     static inline OMX_TICKS intToOMXTicks(long long pts) {
138         OMX_TICKS temp;
139         temp.nLowPart=pts;
140         temp.nHighPart=pts>>32;
141         return temp;
142     }
143
144
145
146   private:
147            int EnterIframePlayback();
148            bool iframemode;
149            bool InIframemode() {return iframemode;};
150
151            UINT DeliverMediaPacket(MediaPacket packet,const UCHAR* bulibaver,UINT *samplepos);
152
153 #define VPE_DECODER_OMX 1
154
155
156
157            bool offsetnotset;
158            bool offsetvideonotset;
159            bool offsetaudionotset;
160            long long startoffset;
161            long long lastrefvideotime;
162            long long lastrefaudiotime;
163           // long long cur_pts;
164            long long lastreftimeOMX;
165            ULLONG lastreftimePTS;
166
167         //   long long playbacktimeoffset; //this is the offset between the media time and system clock
168         //   long long pausetimecode;
169            bool clockpaused;
170
171          /*  static long long GetCurrentSystemTime();
172            static void WaitUntil(long long time);
173            void FrameWaitforDisplay(long long pts);
174            bool FrameSkip(long long pts);
175            bool skipping;
176            void AdjustAudioPTS(long long pts);*/
177
178
179
180
181            static OMX_ERRORTYPE EventHandler_OMX(OMX_IN OMX_HANDLETYPE handle,OMX_IN OMX_PTR appdata,
182            OMX_IN OMX_EVENTTYPE event_type,OMX_IN OMX_U32 data1,
183            OMX_IN OMX_U32 data2,OMX_IN OMX_PTR event_data);
184            static OMX_ERRORTYPE EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
185            static OMX_ERRORTYPE FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
186
187            UINT DeliverMediaPacketOMX(MediaPacket packet,
188                                                      const UCHAR* bulibaver,
189                                                      UINT *samplepos);
190
191            bool detectIFrame(const UCHAR *buffer,unsigned int length);
192
193            int PrepareInputBufsOMX();
194            int DestroyInputBufsOMX();
195
196            void AddOmxEvent(VPE_OMX_EVENT  new_event);
197            void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver);
198
199            int ChangeComponentState(OMX_HANDLETYPE handle,OMX_STATETYPE type);
200            int CommandFinished(OMX_HANDLETYPE handle,OMX_U32 command,OMX_U32 data2);
201            int WaitForEvent(OMX_HANDLETYPE handle,OMX_U32 event);
202            int EnablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait);
203            int DisablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait=true);
204            int clearEvents();
205
206
207        int setClockExecutingandRunning();
208        int initClock();
209        void destroyClock();
210        int idleClock();
211        int getClockAudioandInit(OMX_HANDLETYPE *p_omx_clock,OMX_U32 *p_omx_clock_output_port);
212        int getClockVideoandInit();
213        void LockClock() {clock_mutex.Lock();};
214        void UnlockClock() {clock_mutex.Unlock();};
215        OMX_ERRORTYPE ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFERHEADERTYPE* buffer);
216        void clockPause();
217        void clockUnpause();
218        bool isClockPaused() {return clockpaused;};
219
220        void interlaceSwitch4Demux();
221
222        Mutex clock_mutex; //clock mutex is now responsible for all omx stuff
223        long long cur_clock_time;
224
225
226
227            OMX_HANDLETYPE omx_vid_dec;
228            OMX_HANDLETYPE omx_vid_sched;
229            OMX_HANDLETYPE omx_vid_deint;
230            OMX_HANDLETYPE omx_vid_rend;
231            OMX_HANDLETYPE omx_clock;
232            int clock_references;
233            bool dodeint; //deinterlacer was activated in omx filtergraph
234            bool deint_first_frame; //handle frame change
235            void DeinterlaceFix();
236
237
238            OMX_U32 omx_codec_input_port;
239            OMX_U32 omx_codec_output_port;
240            OMX_U32 omx_deint_input_port;
241            OMX_U32 omx_deint_output_port;
242            OMX_U32 omx_rend_input_port;
243            OMX_U32 omx_shed_input_port;
244            OMX_U32 omx_shed_output_port;
245            OMX_U32 omx_shed_clock_port;
246            OMX_U32 omx_clock_output_port;
247          //  OMX_NALUFORMATSTYPE omx_nalu_format;
248
249
250
251            int AllocateCodecsOMX();
252            int DeAllocateCodecsOMX();
253            int FlushRenderingPipe();
254
255            vector<OMX_BUFFERHEADERTYPE*> input_bufs_omx_all;
256            list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_free;
257            Mutex input_bufs_omx_mutex;
258            OMX_BUFFERHEADERTYPE* cur_input_buf_omx;
259
260            void PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer);
261
262
263
264            bool omx_running;
265            bool omx_first_frame;
266
267            Mutex omx_event_mutex;
268
269            list<VPE_OMX_EVENT> omx_events;
270
271            bool omx_mpeg2;
272            bool omx_h264;
273            float xpos,ypos;
274            int deinterlace;
275            void updateMode();//called internally to adjust for different parameters
276            void selectVideoMode(int interlaced);
277            UCHAR tvsystem;
278            bool signalon;
279            bool pendingmodechange;
280            bool hdmi;
281            int outputinterlaced;
282
283
284
285    bool firstsynched;
286
287     
288    vector<MediaPacket> mediapackets;
289 };
290
291 #endif