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, see <https://www.gnu.org/licenses/>.
26 #include <sys/ioctl.h>
31 #include <libavcodec/avcodec.h>
32 #include <libavformat/avformat.h>
33 #include <libswresample/swresample.h>
40 class AudioOMX : public Audio
42 friend class VideoOMX;
48 int init(u1 streamType);
51 int setStreamType(u1 streamType);
60 int setVolume(int volume);
63 bool supportsAc3() { return true; }
64 bool maysupportAc3() {return true;}
65 bool streamTypeSupported(int streamtype)
69 case 0x11: //AAC LATM packaging
71 case 3: //mpeg 1 layer 1 and 2
80 //Writing Data to Audiodevice
81 virtual void PrepareMediaSample(const MediaPacketList&, u4 samplepos);
82 virtual u4 DeliverMediaSample(u1* buffer, u4* samplepos);
83 u4 DeliverMediaPacket(MediaPacket packet, const u1* buffer, u4* samplepos);
85 virtual long long SetStartOffset(long long curreftime, bool* rsync);
86 virtual void ResetTimeOffsets();
88 virtual bool DrainTargetReady() {return omx_running;};
89 virtual bool DrainTargetBufferFull();
91 u1 getLastAType() {return lastAType;}
93 bool loadOptionsFromServer(VDR* vdr);
94 bool saveOptionstoServer();
95 bool addOptionsToPanes(int panenumber, Options* options, WOptionPane* pane);
96 bool handleOptionChanges(Option* option);
111 bool hdmi; // use hdmi as audio output
112 bool passthrough; // use audio passthrough for the current audio type
118 bool canpass_pcm_mch;
121 int prefered_ac3; //0 stereo PCM, 1 passthrough 2 Multichannel PCM
126 static OMX_ERRORTYPE EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata, OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
127 static OMX_ERRORTYPE FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata, OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
130 unsigned int AdvanceAc3AudioSync(const u1* data, unsigned int size, unsigned int* framesize);
131 unsigned int AdvanceAacLatmAudioSync(const u1* data, unsigned int size, unsigned int* framesize);
132 unsigned int AdvanceMpAudioSync(const u1* data, unsigned int size, unsigned int* framesize);
134 void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver);
136 // OMX_HANDLETYPE omx_aud_dec;
137 OMX_HANDLETYPE omx_aud_rend;
138 OMX_HANDLETYPE omx_clock;
140 //OMX_U32 omx_codec_input_port;
141 //OMX_U32 omx_codec_output_port;
142 OMX_U32 omx_rend_input_port;
143 OMX_U32 omx_rend_clock_port;
144 OMX_U32 omx_clock_output_port;
146 long long lastreftimeOMX;
150 int AllocateCodecsOMX();
151 int DeAllocateCodecsOMX();
153 int PrepareInputBufsOMX(bool setportdef);
154 int DestroyInputBufsOMX();
155 int DestroyInputBufsOMXwhilePlaying();
157 int ChangeAudioPortConfig(bool disport);
158 int ChangeAudioDestination();
159 long long correctAudioLatency(long long pts, int addsamples, int srate);
161 std::vector<OMX_BUFFERHEADERTYPE*> input_bufs_omx_all;
162 std::list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_free;
163 std::mutex input_bufs_omx_mutex;
164 OMX_BUFFERHEADERTYPE* cur_input_buf_omx;
167 bool omx_first_frame;
168 std::mutex libav_mutex;
170 AVCodec* aaclatmcodec_libav;
171 AVCodecContext* aaclatmcodec_context_libav;
172 AVCodec* ac3codec_libav;
173 AVCodecContext* ac3codec_context_libav;
174 AVCodec* mp23codec_libav;
175 AVCodecContext* mp23codec_context_libav;
176 AVPacket incoming_paket_libav;
177 AVFrame* decode_frame_libav;
178 SwrContext* resam_con_libav;
181 u1* decompress_buffer;
182 unsigned int decompress_buffer_size;
183 unsigned int decompress_buffer_filled;
186 unsigned int mp3sameheader;
187 int mp3sameheadercount;
190 int InitDecoderLibAV();
191 void DeinitDecoderLibAV();
193 char L_VPE_OMX_AUDIO_REND[128];
195 int badMinimumFunction(u4 a, int b);
197 int DO_NOT_USE(AVCodecContext* avctx, AVFrame* frame, int* got_frame_ptr, const AVPacket* avpkt);