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