]> git.vomp.tv Git - vompclient.git/blob - audioomx.h
b6b01e06f3daf2df69015e752ab6a5b080fba2b1
[vompclient.git] / audioomx.h
1 /*
2     Copyright 2004-2005 Chris Tallon, 2009,2012 Marten Richter
3
4     This file is part of VOMP.
5
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.
10
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.
15
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.
19 */
20
21 #ifndef AUDIOOMX_H
22 #define AUDIOOMX_H
23
24 #include <stdio.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <sys/ioctl.h>
28
29 #include "defines.h"
30 #include "audio.h"
31 #include "videoomx.h"
32
33 //#define USE_LIBRESAMPLE // untested code for future use
34
35 extern "C" {
36 #include <libavcodec/avcodec.h>
37 #include <libavformat/avformat.h>
38 #ifdef USE_LIBRESAMPLE
39 #include <libavresample/avresample.h>
40 #endif
41 }
42
43
44
45
46 class AudioOMX : public Audio
47 {
48   friend class VideoOMX;
49   public:
50     AudioOMX();
51     virtual ~AudioOMX();
52
53     int init(UCHAR streamType);
54     int shutdown();
55
56     int setStreamType(UCHAR streamType);
57     int setChannel();
58     int setSource();
59     int sync();
60     int play();
61     int stop();
62     int pause();
63     int unPause();
64     int reset();
65     int setVolume(int volume);
66     int mute();
67     int unMute();
68     bool supportsAc3() { return true; }
69     bool maysupportAc3(){return true;}
70     bool streamTypeSupported(int streamtype)
71     {
72         switch (streamtype) {
73         case 0x11: //AAC LATM packaging
74         case 0x6A://ac3
75         case 3: //mpeg 1 layer 1 and 2
76         case 4:
77                 return true;
78         default:
79                 return false;
80         };
81     }
82
83
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);
88
89     virtual long long SetStartOffset(long long curreftime, bool *rsync);
90     virtual void ResetTimeOffsets();
91
92     virtual bool DrainTargetReady() {return omx_running;};
93     virtual bool DrainTargetBufferFull();
94
95
96         UCHAR getLastAType() {return lastAType;}
97
98         bool loadOptionsfromServer(VDR* vdr);
99         bool saveOptionstoServer();
100         bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane);
101         bool handleOptionChanges(Option* option);
102
103
104 #ifdef DEV
105     int test();
106 #endif
107
108   private:
109     int initAllParams();
110     UCHAR streamType;
111         UCHAR lastAType;
112         bool firstsynched;
113
114     MediaPacket packet;
115     UINT packetpos;
116
117
118     bool hdmi; // use hdmi as audio output
119     bool passthrough; // use audio passthrough for the current audio type
120
121     bool canpass_aac;
122     bool canpass_ac3;
123     bool canpass_mp2;
124     bool canpass_mp3;
125     bool canpass_pcm_mch;
126
127
128     int prefered_aac;
129     int prefered_ac3; //0 stereo PCM, 1 passthrough 2 Multichannel PCM
130     int prefered_mp2;
131     int prefered_mp3;
132
133
134
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);
137
138
139
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);
143
144
145     void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver);
146
147    // OMX_HANDLETYPE omx_aud_dec;
148         OMX_HANDLETYPE omx_aud_rend;
149         OMX_HANDLETYPE omx_clock;
150
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;
156
157         long long lastreftimeOMX;
158     ULLONG lastreftimePTS;
159
160
161
162         int AllocateCodecsOMX();
163         int DeAllocateCodecsOMX();
164
165         int PrepareInputBufsOMX(bool setportdef);
166         int DestroyInputBufsOMX();
167         int DestroyInputBufsOMXwhilePlaying();
168
169         int ChangeAudioPortConfig(bool disport);
170         int ChangeAudioDestination();
171         long long correctAudioLatency(long long pts,int addsamples,int srate);
172
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;
177
178     bool omx_running;
179     bool omx_first_frame;
180     Mutex libav_mutex;
181
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;
192 #else
193     void getDownMixMatrix(unsigned long long channels,int *left_mat,int *right_mat);
194 #endif
195
196     UCHAR * decompress_buffer;
197     unsigned int decompress_buffer_size;
198     unsigned int decompress_buffer_filled;
199     bool lsync;
200
201     unsigned int mp3sameheader;
202     int mp3sameheadercount;
203
204
205          int InitDecoderLibAV();
206          void DeinitDecoderLibAV();
207
208 };
209
210 #endif