]> git.vomp.tv Git - vompclient.git/blob - videoomx.h
Rename TCP class to TCPOld
[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 #include <condition_variable>
34
35 #include "defines.h"
36 #include "video.h"
37
38
39 #define OMX_SKIP64BIT
40
41 #include <IL/OMX_Core.h>
42 #include <IL/OMX_Types.h>
43 #include <IL/OMX_Component.h>
44 #include <IL/OMX_Broadcom.h>
45
46
47 struct VPE_OMX_EVENT {
48         OMX_IN OMX_HANDLETYPE handle;
49         OMX_IN OMX_PTR appdata;
50     OMX_IN OMX_EVENTTYPE event_type;
51     OMX_IN OMX_U32 data1;
52         OMX_IN OMX_U32 data2;
53         OMX_IN OMX_PTR event_data;
54 };
55
56
57
58
59 class AudioVPE;
60
61 class VideoOMX : public Video
62 {
63   friend class AudioOMX;
64   friend class ImageOMX;
65   public:
66     VideoOMX();
67     virtual ~VideoOMX();
68
69     int init(UCHAR format);
70     int shutdown();
71
72     UCHAR getSupportedFormats() { return COMPOSITERGB | HDMI;};
73     UINT supportedTVsize() { return ASPECT4X3|ASPECT16X9|ASPECT14X9 ;};
74     UCHAR supportedTVFormats() { return NTSC|PAL|PAL_M|NTSC_J;};
75
76     int setFormat(UCHAR format);
77     int setConnection(UCHAR connection);
78     int setAspectRatio(UCHAR aspectRatio, int tparx,int tpary);   // This one does the pin 8 scart widescreen switching
79     int setMode(UCHAR mode);
80     bool setVideoDisplay(VideoDisplay display);
81     int setTVsize(UCHAR size);               // Is the TV a widescreen?
82     UCHAR getTVsize();
83
84     void executePendingModeChanges();
85     int setDefaultAspect();
86     int setSource();
87     int setPosition(int x, int y);
88     int sync();
89     int play();
90     int stop();
91     int pause();
92     int unPause();
93     int fastForward();
94     int unFastForward();
95     int reset();
96     int blank();
97     int signalOn();
98     int signalOff();
99     int attachFrameBuffer(); // What does this do?
100     ULONG timecodeToFrameNumber(ULLONG timecode);
101     ULLONG getCurrentTimestamp();
102     bool displayIFrame(const UCHAR* bulibaver, UINT length);
103
104     virtual bool dtsTimefix(){return false;} //please we need dts time values
105     virtual int getTeletextBufferFaktor(){return 5;};
106
107     // Writing Data to Videodevice
108     virtual void PrepareMediaSample(const MediaPacketList&, UINT samplepos);
109     virtual UINT DeliverMediaSample(UCHAR* bulibaver, UINT* samplepos);
110
111
112         virtual bool supportsh264(){return true;};
113         virtual bool supportsmpeg2(){return mpeg2_supported;};
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            virtual bool DrainTargetBufferFull();
152
153            UINT DeliverMediaPacket(MediaPacket packet,const UCHAR* bulibaver,UINT *samplepos);
154
155 #define VPE_DECODER_OMX 1
156
157
158
159            bool offsetnotset;
160            bool offsetvideonotset;
161            bool offsetaudionotset;
162            long long startoffset;
163            long long lastrefvideotime;
164            long long lastrefaudiotime;
165           // long long cur_pts;
166            long long lastreftimeOMX;
167            ULLONG lastreftimePTS;
168
169         //   long long playbacktimeoffset; //this is the offset between the media time and system clock
170         //   long long pausetimecode;
171            bool clockpaused;
172
173          /*  static long long GetCurrentSystemTime();
174            static void WaitUntil(long long time);
175            void FrameWaitforDisplay(long long pts);
176            bool FrameSkip(long long pts);
177            bool skipping;
178            void AdjustAudioPTS(long long pts);*/
179
180
181
182
183            static OMX_ERRORTYPE EventHandler_OMX(OMX_IN OMX_HANDLETYPE handle,OMX_IN OMX_PTR appdata,
184            OMX_IN OMX_EVENTTYPE event_type,OMX_IN OMX_U32 data1,
185            OMX_IN OMX_U32 data2,OMX_IN OMX_PTR event_data);
186            static OMX_ERRORTYPE EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
187            static OMX_ERRORTYPE FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
188
189            UINT DeliverMediaPacketOMX(MediaPacket packet,
190                                                      const UCHAR* bulibaver,
191                                                      UINT *samplepos);
192
193            bool detectIFrame(const UCHAR *buffer,unsigned int length);
194
195            int PrepareInputBufsOMX();
196            int DestroyInputBufsOMX();
197
198            void AddOmxEvent(VPE_OMX_EVENT  new_event);
199            void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver);
200
201            int ChangeComponentState(OMX_HANDLETYPE handle,OMX_STATETYPE type, bool wait=true);
202            int CommandFinished(OMX_HANDLETYPE handle,OMX_U32 command,OMX_U32 data2);
203            int WaitForEvent(OMX_HANDLETYPE handle,OMX_U32 event,int wait=200);
204            int EnablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait);
205            int DisablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait=true);
206            int clearEvents();
207            int clearEventsForComponent(OMX_HANDLETYPE handle);
208            void checkForStalledBuffers();
209
210
211        int setClockExecutingandRunning();
212        int initClock();
213        void destroyClock();
214        int idleClock();
215        int getClockAudioandInit(OMX_HANDLETYPE *p_omx_clock,OMX_U32 *p_omx_clock_output_port);
216        int getClockVideoandInit();
217        void LockClock() {clock_mutex.lock();};
218        void UnlockClock() {clock_mutex.unlock();};
219        OMX_ERRORTYPE ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFERHEADERTYPE* buffer);
220        void clockPause();
221        void clockUnpause();
222        bool isClockPaused() {return clockpaused;};
223
224        void signalOmx();
225        std::condition_variable omx_event_ready_signal;
226        std::mutex omx_event_ready_signal_mutex;
227
228
229
230        void interlaceSwitch4Demux();
231
232        std::mutex clock_mutex; //clock mutex is now responsible for all omx stuff
233        long long cur_clock_time;
234
235
236
237            OMX_HANDLETYPE omx_vid_dec;
238            OMX_HANDLETYPE omx_vid_sched;
239            OMX_HANDLETYPE omx_vid_deint;
240            OMX_HANDLETYPE omx_vid_rend;
241            OMX_HANDLETYPE omx_clock;
242            int clock_references;
243            bool dodeint; //deinterlacer was activated in omx filtergraph
244            bool first_frame; //handle frame change
245            void FirstFrameFix();
246
247
248            OMX_U32 omx_codec_input_port;
249            OMX_U32 omx_codec_output_port;
250            OMX_U32 omx_deint_input_port;
251            OMX_U32 omx_deint_output_port;
252            OMX_U32 omx_rend_input_port;
253            OMX_U32 omx_shed_input_port;
254            OMX_U32 omx_shed_output_port;
255            OMX_U32 omx_shed_clock_port;
256            OMX_U32 omx_clock_output_port;
257          //  OMX_NALUFORMATSTYPE omx_nalu_format;
258            bool omx_vid_stalled;
259
260
261
262
263
264            int AllocateCodecsOMX();
265            int DeAllocateCodecsOMX();
266            int FlushRenderingPipe();
267
268            std::vector<OMX_BUFFERHEADERTYPE*> input_bufs_omx_all;
269            std::list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_free;
270            std::mutex input_bufs_omx_mutex;
271            OMX_BUFFERHEADERTYPE* cur_input_buf_omx;
272
273            void PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer);
274
275
276
277            bool omx_running;
278            bool omx_first_frame;
279
280            std::mutex omx_event_mutex;
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