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;};
95 UCHAR getLastAType() {return lastAType;}
97 bool loadOptionsfromServer(VDR* vdr);
98 bool saveOptionstoServer();
99 bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane);
100 bool handleOptionChanges(Option* option);
117 bool hdmi; // use hdmi as audio output
118 bool passthrough; // use audio passthrough for the current audio type
124 bool canpass_pcm_mch;
128 int prefered_ac3; //0 stereo PCM, 1 passthrough 2 Multichannel PCM
134 static OMX_ERRORTYPE EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
135 static OMX_ERRORTYPE FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
139 unsigned int AdvanceAc3AudioSync(const UCHAR *data,unsigned int size,unsigned int *framesize);
140 unsigned int AdvanceAacLatmAudioSync(const UCHAR *data,unsigned int size,unsigned int *framesize);
141 unsigned int AdvanceMpAudioSync(const UCHAR *data,unsigned int size,unsigned int *framesize);
144 void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver);
146 // OMX_HANDLETYPE omx_aud_dec;
147 OMX_HANDLETYPE omx_aud_rend;
148 OMX_HANDLETYPE omx_clock;
150 //OMX_U32 omx_codec_input_port;
151 //OMX_U32 omx_codec_output_port;
152 OMX_U32 omx_rend_input_port;
153 OMX_U32 omx_rend_clock_port;
154 OMX_U32 omx_clock_output_port;
156 long long lastreftimeOMX;
157 ULLONG lastreftimePTS;
161 int AllocateCodecsOMX();
162 int DeAllocateCodecsOMX();
164 int PrepareInputBufsOMX(bool setportdef);
165 int DestroyInputBufsOMX();
166 int DestroyInputBufsOMXwhilePlaying();
168 int ChangeAudioPortConfig(bool disport);
169 int ChangeAudioDestination();
170 long long correctAudioLatency(long long pts,int addsamples,int srate);
172 vector<OMX_BUFFERHEADERTYPE*> input_bufs_omx_all;
173 list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_free;
174 Mutex input_bufs_omx_mutex;
175 OMX_BUFFERHEADERTYPE* cur_input_buf_omx;
178 bool omx_first_frame;
181 AVCodec *aaclatmcodec_libav;
182 AVCodecContext *aaclatmcodec_context_libav;
183 AVCodec *ac3codec_libav;
184 AVCodecContext *ac3codec_context_libav;
185 AVCodec *mp23codec_libav;
186 AVCodecContext *mp23codec_context_libav;
187 AVPacket incoming_paket_libav;
188 AVFrame *decode_frame_libav;
189 #ifdef USE_LIBRESAMPLE
190 AVAudioResampleContext *resam_con_libav;
192 void getDownMixMatrix(unsigned long long channels,int *left_mat,int *right_mat);
195 UCHAR * decompress_buffer;
196 unsigned int decompress_buffer_size;
197 unsigned int decompress_buffer_filled;
201 int InitDecoderLibAV();
202 void DeinitDecoderLibAV();