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.
32 #include <sys/ioctl.h>
43 #include "threadsystem.h"
49 #include <IL/OMX_Core.h>
50 #include <IL/OMX_Types.h>
51 #include <IL/OMX_Component.h>
52 #include <IL/OMX_Broadcom.h>
55 struct VPE_OMX_EVENT {
56 OMX_IN OMX_HANDLETYPE handle;
57 OMX_IN OMX_PTR appdata;
58 OMX_IN OMX_EVENTTYPE event_type;
61 OMX_IN OMX_PTR event_data;
69 class VideoOMX : public Video
71 friend class AudioOMX;
72 friend class ImageOMX;
77 int init(UCHAR format);
80 UCHAR getSupportedFormats() { return COMPOSITERGB | HDMI;};
81 UINT supportedTVsize() { return ASPECT4X3|ASPECT16X9|ASPECT14X9 ;};
82 UCHAR supportedTVFormats() { return NTSC|PAL|PAL_M|NTSC_J;};
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 int setTVsize(UCHAR size); // Is the TV a widescreen?
91 void executePendingModeChanges();
92 int setDefaultAspect();
94 int setPosition(int x, int y);
106 int attachFrameBuffer(); // What does this do?
107 ULONG timecodeToFrameNumber(ULLONG timecode);
108 ULLONG getCurrentTimestamp();
109 bool displayIFrame(const UCHAR* bulibaver, UINT length);
111 virtual bool dtsTimefix(){return false;} //please we need dts time values
112 virtual int getTeletextBufferFaktor(){return 5;};
114 // Writing Data to Videodevice
115 virtual void PrepareMediaSample(const MediaPacketList&, UINT samplepos);
116 virtual UINT DeliverMediaSample(UCHAR* bulibaver, UINT* samplepos);
119 virtual bool supportsh264(){return true;};
120 virtual bool supportsmpeg2(){return mpeg2_supported;};
122 int WriteOutTS(const unsigned char *bulibaver,int length, int type);
123 void WriteOutPATPMT();
127 virtual long long SetStartOffset(long long curreftime, bool *rsync);
128 long long SetStartAudioOffset(long long curreftime, bool *rsync);
129 virtual void ResetTimeOffsets();
131 bool loadOptionsfromServer(VDR* vdr);
132 bool saveOptionstoServer();
133 bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane);
134 bool handleOptionChanges(Option* option);
144 static inline OMX_TICKS intToOMXTicks(long long pts) {
147 temp.nHighPart=pts>>32;
154 int EnterIframePlayback();
156 bool InIframemode() {return iframemode;};
158 virtual bool DrainTargetBufferFull();
160 UINT DeliverMediaPacket(MediaPacket packet,const UCHAR* bulibaver,UINT *samplepos);
162 #define VPE_DECODER_OMX 1
167 bool offsetvideonotset;
168 bool offsetaudionotset;
169 long long startoffset;
170 long long lastrefvideotime;
171 long long lastrefaudiotime;
172 // long long cur_pts;
173 long long lastreftimeOMX;
174 ULLONG lastreftimePTS;
176 // long long playbacktimeoffset; //this is the offset between the media time and system clock
177 // long long pausetimecode;
180 /* static long long GetCurrentSystemTime();
181 static void WaitUntil(long long time);
182 void FrameWaitforDisplay(long long pts);
183 bool FrameSkip(long long pts);
185 void AdjustAudioPTS(long long pts);*/
190 static OMX_ERRORTYPE EventHandler_OMX(OMX_IN OMX_HANDLETYPE handle,OMX_IN OMX_PTR appdata,
191 OMX_IN OMX_EVENTTYPE event_type,OMX_IN OMX_U32 data1,
192 OMX_IN OMX_U32 data2,OMX_IN OMX_PTR event_data);
193 static OMX_ERRORTYPE EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
194 static OMX_ERRORTYPE FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
196 UINT DeliverMediaPacketOMX(MediaPacket packet,
197 const UCHAR* bulibaver,
200 bool detectIFrame(const UCHAR *buffer,unsigned int length);
202 int PrepareInputBufsOMX();
203 int DestroyInputBufsOMX();
205 void AddOmxEvent(VPE_OMX_EVENT new_event);
206 void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver);
208 int ChangeComponentState(OMX_HANDLETYPE handle,OMX_STATETYPE type, bool wait=true);
209 int CommandFinished(OMX_HANDLETYPE handle,OMX_U32 command,OMX_U32 data2);
210 int WaitForEvent(OMX_HANDLETYPE handle,OMX_U32 event,int wait=200);
211 int EnablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait);
212 int DisablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait=true);
214 int clearEventsForComponent(OMX_HANDLETYPE handle);
215 void checkForStalledBuffers();
218 int setClockExecutingandRunning();
222 int getClockAudioandInit(OMX_HANDLETYPE *p_omx_clock,OMX_U32 *p_omx_clock_output_port);
223 int getClockVideoandInit();
224 void LockClock() {clock_mutex.Lock();};
225 void UnlockClock() {clock_mutex.Unlock();};
226 OMX_ERRORTYPE ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFERHEADERTYPE* buffer);
229 bool isClockPaused() {return clockpaused;};
231 void signalOmx() {omx_event_ready_signal.signal();};
233 void interlaceSwitch4Demux();
235 Mutex clock_mutex; //clock mutex is now responsible for all omx stuff
236 long long cur_clock_time;
240 OMX_HANDLETYPE omx_vid_dec;
241 OMX_HANDLETYPE omx_vid_sched;
242 OMX_HANDLETYPE omx_vid_deint;
243 OMX_HANDLETYPE omx_vid_rend;
244 OMX_HANDLETYPE omx_clock;
245 int clock_references;
246 bool dodeint; //deinterlacer was activated in omx filtergraph
247 bool first_frame; //handle frame change
248 void FirstFrameFix();
251 OMX_U32 omx_codec_input_port;
252 OMX_U32 omx_codec_output_port;
253 OMX_U32 omx_deint_input_port;
254 OMX_U32 omx_deint_output_port;
255 OMX_U32 omx_rend_input_port;
256 OMX_U32 omx_shed_input_port;
257 OMX_U32 omx_shed_output_port;
258 OMX_U32 omx_shed_clock_port;
259 OMX_U32 omx_clock_output_port;
260 // OMX_NALUFORMATSTYPE omx_nalu_format;
261 bool omx_vid_stalled;
267 int AllocateCodecsOMX();
268 int DeAllocateCodecsOMX();
269 int FlushRenderingPipe();
271 vector<OMX_BUFFERHEADERTYPE*> input_bufs_omx_all;
272 list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_free;
273 Mutex input_bufs_omx_mutex;
274 OMX_BUFFERHEADERTYPE* cur_input_buf_omx;
276 void PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer);
281 bool omx_first_frame;
283 Mutex omx_event_mutex;
284 Signal omx_event_ready_signal;
286 list<VPE_OMX_EVENT> omx_events;
292 void updateMode();//called internally to adjust for different parameters
293 void selectVideoMode(int interlaced);
296 bool pendingmodechange;
298 bool mpeg2_supported;
299 int outputinterlaced;
306 vector<MediaPacket> mediapackets;