]> git.vomp.tv Git - vompclient.git/blob - audioomx.h
Compile fix for MVP re: location change of hmsf
[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
34 extern "C" {
35 #include <libavcodec/avcodec.h>
36 #include <libavformat/avformat.h>
37 #include <libavresample/avresample.h>
38 }
39
40
41
42
43 class AudioOMX : public Audio
44 {
45   friend class VideoOMX;
46   public:
47     AudioOMX();
48     virtual ~AudioOMX();
49
50     int init(UCHAR streamType);
51     int shutdown();
52
53     int setStreamType(UCHAR streamType);
54     int setChannel();
55     int setSource();
56     int sync();
57     int play();
58     int stop();
59     int pause();
60     int unPause();
61     int reset();
62     int setVolume(int volume);
63     int mute();
64     int unMute();
65     bool supportsAc3() { return true; }
66     bool maysupportAc3(){return true;}
67     bool streamTypeSupported(int streamtype)
68     {
69         switch (streamtype) {
70         case 0x11: //AAC LATM packaging
71         case 0x6A://ac3
72         case 3: //mpeg 1 layer 1 and 2
73         case 4:
74                 return true;
75         default:
76                 return false;
77         };
78     }
79
80
81     //Writing Data to Audiodevice
82     virtual void PrepareMediaSample(const MediaPacketList&, UINT samplepos);
83     virtual UINT DeliverMediaSample(UCHAR* buffer, UINT *samplepos);
84     UINT DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer,UINT *samplepos);
85
86     virtual long long SetStartOffset(long long curreftime, bool *rsync);
87     virtual void ResetTimeOffsets();
88
89     virtual bool DrainTargetReady() {return omx_running;};
90     virtual bool DrainTargetBufferFull();
91
92
93         UCHAR getLastAType() {return lastAType;}
94
95         bool loadOptionsfromServer(VDR* vdr);
96         bool saveOptionstoServer();
97         bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane);
98         bool handleOptionChanges(Option* option);
99
100
101 #ifdef DEV
102     int test();
103 #endif
104
105   private:
106     int initAllParams();
107     UCHAR streamType;
108         UCHAR lastAType;
109         bool firstsynched;
110
111     MediaPacket packet;
112     UINT packetpos;
113
114
115     bool hdmi; // use hdmi as audio output
116     bool passthrough; // use audio passthrough for the current audio type
117
118     bool canpass_aac;
119     bool canpass_ac3;
120     bool canpass_mp2;
121     bool canpass_mp3;
122     bool canpass_pcm_mch;
123
124
125     int prefered_aac;
126     int prefered_ac3; //0 stereo PCM, 1 passthrough 2 Multichannel PCM
127     int prefered_mp2;
128     int prefered_mp3;
129
130
131
132     static OMX_ERRORTYPE EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
133         static OMX_ERRORTYPE FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);
134
135
136
137         unsigned int AdvanceAc3AudioSync(const UCHAR *data,unsigned int size,unsigned int *framesize);
138         unsigned int AdvanceAacLatmAudioSync(const UCHAR *data,unsigned int size,unsigned int *framesize);
139         unsigned int AdvanceMpAudioSync(const UCHAR *data,unsigned int size,unsigned int *framesize);
140
141
142     void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver);
143
144    // OMX_HANDLETYPE omx_aud_dec;
145         OMX_HANDLETYPE omx_aud_rend;
146         OMX_HANDLETYPE omx_clock;
147
148         //OMX_U32 omx_codec_input_port;
149         //OMX_U32 omx_codec_output_port;
150         OMX_U32 omx_rend_input_port;
151         OMX_U32 omx_rend_clock_port;
152         OMX_U32 omx_clock_output_port;
153
154         long long lastreftimeOMX;
155     ULLONG lastreftimePTS;
156
157
158
159         int AllocateCodecsOMX();
160         int DeAllocateCodecsOMX();
161
162         int PrepareInputBufsOMX(bool setportdef);
163         int DestroyInputBufsOMX();
164         int DestroyInputBufsOMXwhilePlaying();
165
166         int ChangeAudioPortConfig(bool disport);
167         int ChangeAudioDestination();
168         long long correctAudioLatency(long long pts,int addsamples,int srate);
169
170         vector<OMX_BUFFERHEADERTYPE*> input_bufs_omx_all;
171         list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_free;
172         Mutex input_bufs_omx_mutex;
173         OMX_BUFFERHEADERTYPE* cur_input_buf_omx;
174
175     bool omx_running;
176     bool omx_first_frame;
177     Mutex libav_mutex;
178
179     AVCodec *aaclatmcodec_libav;
180     AVCodecContext *aaclatmcodec_context_libav;
181         AVCodec *ac3codec_libav;
182         AVCodecContext *ac3codec_context_libav;
183         AVCodec *mp23codec_libav;
184     AVCodecContext *mp23codec_context_libav;
185     AVPacket incoming_paket_libav;
186     AVFrame *decode_frame_libav;
187     AVAudioResampleContext *resam_con_libav;
188
189
190     UCHAR * decompress_buffer;
191     unsigned int decompress_buffer_size;
192     unsigned int decompress_buffer_filled;
193     bool lsync;
194
195     unsigned int mp3sameheader;
196     int mp3sameheadercount;
197
198
199          int InitDecoderLibAV();
200          void DeinitDecoderLibAV();
201
202     char L_VPE_OMX_AUDIO_REND[128];
203
204 };
205
206 #endif