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.
27 #include <sys/ioctl.h>
33 //#define USE_LIBRESAMPLE // untested code for future use
36 #include <libavcodec/avcodec.h>
37 #include <libavformat/avformat.h>
38 #ifdef USE_LIBRESAMPLE
39 #include <libavresample/avresample.h>
46 class AudioOMX : public Audio
48 friend class VideoOMX;
53 int init(UCHAR streamType);
56 int setStreamType(UCHAR streamType);
65 int setVolume(int volume);
68 bool supportsAc3() { return true; }
69 bool maysupportAc3(){return true;}
70 bool streamTypeSupported(int streamtype)
73 case 0x11: //AAC LATM packaging
75 case 3: //mpeg 1 layer 1 and 2
84 //Writing Data to Audiodevice
85 virtual void PrepareMediaSample(const MediaPacketList&, UINT samplepos);
86 virtual UINT DeliverMediaSample(UCHAR* buffer, UINT *samplepos);
87 UINT DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer,UINT *samplepos);
89 virtual long long SetStartOffset(long long curreftime, bool *rsync);
90 virtual void ResetTimeOffsets();
92 virtual bool DrainTargetReady() {return omx_running;};
93 virtual bool DrainTargetBufferFull();
96 UCHAR getLastAType() {return lastAType;}
98 bool loadOptionsfromServer(VDR* vdr);
99 bool saveOptionstoServer();
100 bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane);
101 bool handleOptionChanges(Option* option);
118 bool hdmi; // use hdmi as audio output
119 bool passthrough; // use audio passthrough for the current audio type
125 bool canpass_pcm_mch;
129 int prefered_ac3; //0 stereo PCM, 1 passthrough 2 Multichannel PCM
135 static OMX_ERRORTYPE EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
136 static OMX_ERRORTYPE FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
140 unsigned int AdvanceAc3AudioSync(const UCHAR *data,unsigned int size,unsigned int *framesize);
141 unsigned int AdvanceAacLatmAudioSync(const UCHAR *data,unsigned int size,unsigned int *framesize);
142 unsigned int AdvanceMpAudioSync(const UCHAR *data,unsigned int size,unsigned int *framesize);
145 void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver);
147 // OMX_HANDLETYPE omx_aud_dec;
148 OMX_HANDLETYPE omx_aud_rend;
149 OMX_HANDLETYPE omx_clock;
151 //OMX_U32 omx_codec_input_port;
152 //OMX_U32 omx_codec_output_port;
153 OMX_U32 omx_rend_input_port;
154 OMX_U32 omx_rend_clock_port;
155 OMX_U32 omx_clock_output_port;
157 long long lastreftimeOMX;
158 ULLONG lastreftimePTS;
162 int AllocateCodecsOMX();
163 int DeAllocateCodecsOMX();
165 int PrepareInputBufsOMX(bool setportdef);
166 int DestroyInputBufsOMX();
167 int DestroyInputBufsOMXwhilePlaying();
169 int ChangeAudioPortConfig(bool disport);
170 int ChangeAudioDestination();
171 long long correctAudioLatency(long long pts,int addsamples,int srate);
173 vector<OMX_BUFFERHEADERTYPE*> input_bufs_omx_all;
174 list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_free;
175 Mutex input_bufs_omx_mutex;
176 OMX_BUFFERHEADERTYPE* cur_input_buf_omx;
179 bool omx_first_frame;
182 AVCodec *aaclatmcodec_libav;
183 AVCodecContext *aaclatmcodec_context_libav;
184 AVCodec *ac3codec_libav;
185 AVCodecContext *ac3codec_context_libav;
186 AVCodec *mp23codec_libav;
187 AVCodecContext *mp23codec_context_libav;
188 AVPacket incoming_paket_libav;
189 AVFrame *decode_frame_libav;
190 #ifdef USE_LIBRESAMPLE
191 AVAudioResampleContext *resam_con_libav;
193 void getDownMixMatrix(unsigned long long channels,int *left_mat,int *right_mat);
196 UCHAR * decompress_buffer;
197 unsigned int decompress_buffer_size;
198 unsigned int decompress_buffer_filled;
201 unsigned int mp3sameheader;
202 int mp3sameheadercount;
205 int InitDecoderLibAV();
206 void DeinitDecoderLibAV();