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