2 Copyright 2004-2005 Chris Tallon 2009,2012 Marten Richter
\r
4 This file is part of VOMP.
\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
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
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
31 #include <sys/ioctl.h>
\r
39 #include "defines.h"
\r
41 #include "threadsystem.h"
\r
44 #include <IL/OMX_Core.h>
\r
45 #include <IL/OMX_Types.h>
\r
46 #include <IL/OMX_Component.h>
\r
47 #include <IL/OMX_Broadcom.h>
\r
50 struct VPE_OMX_EVENT {
\r
51 OMX_IN OMX_HANDLETYPE handle;
\r
52 OMX_IN OMX_PTR appdata;
\r
53 OMX_IN OMX_EVENTTYPE event_type;
\r
54 OMX_IN OMX_U32 data1;
\r
55 OMX_IN OMX_U32 data2;
\r
56 OMX_IN OMX_PTR event_data;
\r
64 class VideoOMX : public Video, public Thread_TYPE
\r
66 friend class AudioOMX;
\r
69 virtual ~VideoOMX();
\r
71 int init(UCHAR format);
\r
74 int setFormat(UCHAR format);
\r
75 int setConnection(UCHAR connection);
\r
76 int setAspectRatio(UCHAR aspectRatio); // This one does the pin 8 scart widescreen switching
\r
77 int setMode(UCHAR mode);
\r
78 int setTVsize(UCHAR size); // Is the TV a widescreen?
\r
79 int setDefaultAspect();
\r
81 int setPosition(int x, int y);
\r
88 int unFastForward();
\r
93 int attachFrameBuffer(); // What does this do?
\r
94 ULONG timecodeToFrameNumber(ULLONG timecode);
\r
95 ULLONG getCurrentTimestamp();
\r
96 bool displayIFrame(const UCHAR* bulibaver, UINT length);
\r
98 virtual bool dtsTimefix(){return true;} //please we need dts time values
\r
99 virtual int getTeletextBufferFaktor(){return 5;};
\r
101 // Writing Data to Videodevice
\r
102 virtual void PrepareMediaSample(const MediaPacketList&, UINT samplepos);
\r
103 virtual UINT DeliverMediaSample(UCHAR* bulibaver, UINT* samplepos);
\r
106 virtual bool supportsh264(){return true;};
\r
108 int WriteOutTS(const unsigned char *bulibaver,int length, int type);
\r
109 void WriteOutPATPMT();
\r
113 virtual long long SetStartOffset(long long curreftime, bool *rsync);
\r
114 long long SetStartAudioOffset(long long curreftime, bool *rsync);
\r
115 virtual void ResetTimeOffsets();
\r
123 int initUsingOSDObjects();
\r
124 int shutdownUsingOSDObjects() {return shutdown();};
\r
129 int EnterIframePlayback();
\r
131 bool InIframemode() {return iframemode;};
\r
133 UINT DeliverMediaPacket(MediaPacket packet,const UCHAR* bulibaver,UINT *samplepos);
\r
135 #define VPE_DECODER_OMX 1
\r
140 bool offsetvideonotset;
\r
141 bool offsetaudionotset;
\r
142 long long startoffset;
\r
143 long long lastrefvideotime;
\r
144 long long lastrefaudiotime;
\r
145 OMX_TICKS lastreftimeOMX;
\r
146 ULLONG lastreftimePTS;
\r
148 long long playbacktimeoffset; //this is the offset between the media time and system clock
\r
149 long long pausetimecode;
\r
152 static long long GetCurrentSystemTime();
\r
153 static void WaitUntil(long long time);
\r
154 void FrameWaitforDisplay(long long pts);
\r
155 bool FrameSkip(long long pts);
\r
157 void AdjustAudioPTS(long long pts);
\r
162 static OMX_ERRORTYPE EventHandler_OMX(OMX_IN OMX_HANDLETYPE handle,OMX_IN OMX_PTR appdata,
\r
163 OMX_IN OMX_EVENTTYPE event_type,OMX_IN OMX_U32 data1,
\r
164 OMX_IN OMX_U32 data2,OMX_IN OMX_PTR event_data);
\r
165 static OMX_ERRORTYPE EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
\r
166 static OMX_ERRORTYPE FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
\r
168 UINT DeliverMediaPacketOMX(MediaPacket packet,
\r
169 const UCHAR* bulibaver,
\r
172 int PrepareInputBufsOMX();
\r
173 int DestroyInputBufsOMX();
\r
175 void AddOmxEvent(VPE_OMX_EVENT new_event);
\r
176 void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver);
\r
178 int ChangeComponentState(OMX_HANDLETYPE handle,OMX_STATETYPE type);
\r
179 int CommandFinished(OMX_HANDLETYPE handle,OMX_U32 command,OMX_U32 data2);
\r
180 int EnablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait);
\r
181 int DisablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait=true);
\r
184 int setClockExecutingandRunning();
\r
186 void destroyClock();
\r
188 int getClockAudioandInit(OMX_HANDLETYPE *p_omx_clock,OMX_U32 *p_omx_clock_output_port);
\r
189 int getClockVideoandInit();
\r
190 void LockClock() {clock_mutex.Lock();};
\r
191 void UnlockClock() {clock_mutex.Unlock();};
\r
192 OMX_ERRORTYPE ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFERHEADERTYPE* buffer);
\r
194 void clockUnpause();
\r
196 Mutex clock_mutex; //clock mutex is now responsible for all omx stuff
\r
200 OMX_HANDLETYPE omx_vid_dec;
\r
201 OMX_HANDLETYPE omx_vid_sched;
\r
202 OMX_HANDLETYPE omx_vid_rend;
\r
203 OMX_HANDLETYPE omx_clock;
\r
204 int clock_references;
\r
207 OMX_U32 omx_codec_input_port;
\r
208 OMX_U32 omx_codec_output_port;
\r
209 OMX_U32 omx_rend_input_port;
\r
210 OMX_U32 omx_shed_input_port;
\r
211 OMX_U32 omx_shed_output_port;
\r
212 OMX_U32 omx_shed_clock_port;
\r
213 OMX_U32 omx_clock_output_port;
\r
214 // OMX_NALUFORMATSTYPE omx_nalu_format;
\r
218 int AllocateCodecsOMX();
\r
219 int DeAllocateCodecsOMX();
\r
221 vector<OMX_BUFFERHEADERTYPE*> input_bufs_omx_all;
\r
222 list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_free;
\r
223 list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_present;
\r
224 list<long long> input_time_present;
\r
225 Mutex input_bufs_omx_mutex;
\r
226 OMX_BUFFERHEADERTYPE* cur_input_buf_omx;
\r
228 void PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer, long long time);
\r
229 void threadMethod();
\r
230 void threadPostStopCleanup();
\r
234 bool omx_first_frame;
\r
236 Mutex omx_event_mutex;
\r
238 list<VPE_OMX_EVENT> omx_events;
\r
248 MediaPacket mediapacket;
\r