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