2 Copyright 2004-2005 Chris Tallon 2009,2012 Marten Richter
4 This file is part of VOMP.
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.
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.
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.
31 #include <sys/ioctl.h>
41 #include "threadsystem.h"
45 #include <IL/OMX_Core.h>
46 #include <IL/OMX_Types.h>
47 #include <IL/OMX_Component.h>
48 #include <IL/OMX_Broadcom.h>
51 struct VPE_OMX_EVENT {
52 OMX_IN OMX_HANDLETYPE handle;
53 OMX_IN OMX_PTR appdata;
54 OMX_IN OMX_EVENTTYPE event_type;
57 OMX_IN OMX_PTR event_data;
65 class VideoOMX : public Video
67 friend class AudioOMX;
72 int init(UCHAR format);
75 UCHAR getSupportedFormats() { return COMPOSITERGB | HDMI;};
76 UINT supportedTVsize() { return ASPECT4X3|ASPECT16X9|ASPECT14X9 ;};
77 UCHAR supportedTVFormats() { return NTSC|PAL|PAL_M|NTSC_J;};
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?
86 void executePendingModeChanges();
87 int setDefaultAspect();
89 int setPosition(int x, int y);
101 int attachFrameBuffer(); // What does this do?
102 ULONG timecodeToFrameNumber(ULLONG timecode);
103 ULLONG getCurrentTimestamp();
104 bool displayIFrame(const UCHAR* bulibaver, UINT length);
106 virtual bool dtsTimefix(){return false;} //please we need dts time values
107 virtual int getTeletextBufferFaktor(){return 5;};
109 // Writing Data to Videodevice
110 virtual void PrepareMediaSample(const MediaPacketList&, UINT samplepos);
111 virtual UINT DeliverMediaSample(UCHAR* bulibaver, UINT* samplepos);
114 virtual bool supportsh264(){return true;};
115 virtual bool supportsmpeg2(){return mpeg2_supported;};
117 int WriteOutTS(const unsigned char *bulibaver,int length, int type);
118 void WriteOutPATPMT();
122 virtual long long SetStartOffset(long long curreftime, bool *rsync);
123 long long SetStartAudioOffset(long long curreftime, bool *rsync);
124 virtual void ResetTimeOffsets();
126 bool loadOptionsfromServer(VDR* vdr);
127 bool saveOptionstoServer();
128 bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane);
129 bool handleOptionChanges(Option* option);
139 static inline OMX_TICKS intToOMXTicks(long long pts) {
142 temp.nHighPart=pts>>32;
149 int EnterIframePlayback();
151 bool InIframemode() {return iframemode;};
153 UINT DeliverMediaPacket(MediaPacket packet,const UCHAR* bulibaver,UINT *samplepos);
155 #define VPE_DECODER_OMX 1
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;
169 // long long playbacktimeoffset; //this is the offset between the media time and system clock
170 // long long pausetimecode;
173 /* static long long GetCurrentSystemTime();
174 static void WaitUntil(long long time);
175 void FrameWaitforDisplay(long long pts);
176 bool FrameSkip(long long pts);
178 void AdjustAudioPTS(long long pts);*/
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);
189 UINT DeliverMediaPacketOMX(MediaPacket packet,
190 const UCHAR* bulibaver,
193 bool detectIFrame(const UCHAR *buffer,unsigned int length);
195 int PrepareInputBufsOMX();
196 int DestroyInputBufsOMX();
198 void AddOmxEvent(VPE_OMX_EVENT new_event);
199 void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver);
201 int ChangeComponentState(OMX_HANDLETYPE handle,OMX_STATETYPE type);
202 int CommandFinished(OMX_HANDLETYPE handle,OMX_U32 command,OMX_U32 data2);
203 int WaitForEvent(OMX_HANDLETYPE handle,OMX_U32 event);
204 int EnablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait);
205 int DisablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait=true);
209 int setClockExecutingandRunning();
213 int getClockAudioandInit(OMX_HANDLETYPE *p_omx_clock,OMX_U32 *p_omx_clock_output_port);
214 int getClockVideoandInit();
215 void LockClock() {clock_mutex.Lock();};
216 void UnlockClock() {clock_mutex.Unlock();};
217 OMX_ERRORTYPE ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFERHEADERTYPE* buffer);
220 bool isClockPaused() {return clockpaused;};
222 void interlaceSwitch4Demux();
224 Mutex clock_mutex; //clock mutex is now responsible for all omx stuff
225 long long cur_clock_time;
229 OMX_HANDLETYPE omx_vid_dec;
230 OMX_HANDLETYPE omx_vid_sched;
231 OMX_HANDLETYPE omx_vid_deint;
232 OMX_HANDLETYPE omx_vid_rend;
233 OMX_HANDLETYPE omx_clock;
234 int clock_references;
235 bool dodeint; //deinterlacer was activated in omx filtergraph
236 bool first_frame; //handle frame change
237 void FirstFrameFix();
240 OMX_U32 omx_codec_input_port;
241 OMX_U32 omx_codec_output_port;
242 OMX_U32 omx_deint_input_port;
243 OMX_U32 omx_deint_output_port;
244 OMX_U32 omx_rend_input_port;
245 OMX_U32 omx_shed_input_port;
246 OMX_U32 omx_shed_output_port;
247 OMX_U32 omx_shed_clock_port;
248 OMX_U32 omx_clock_output_port;
249 // OMX_NALUFORMATSTYPE omx_nalu_format;
253 int AllocateCodecsOMX();
254 int DeAllocateCodecsOMX();
255 int FlushRenderingPipe();
257 vector<OMX_BUFFERHEADERTYPE*> input_bufs_omx_all;
258 list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_free;
259 Mutex input_bufs_omx_mutex;
260 OMX_BUFFERHEADERTYPE* cur_input_buf_omx;
262 void PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer);
267 bool omx_first_frame;
269 Mutex omx_event_mutex;
271 list<VPE_OMX_EVENT> omx_events;
277 void updateMode();//called internally to adjust for different parameters
278 void selectVideoMode(int interlaced);
281 bool pendingmodechange;
283 bool mpeg2_supported;
284 int outputinterlaced;
291 vector<MediaPacket> mediapackets;