]> git.vomp.tv Git - vompclient.git/blob - audioomx.h
Preparations for dynamic mode switching
[vompclient.git] / audioomx.h
1 /*\r
2     Copyright 2004-2005 Chris Tallon, 2009,2012 Marten Richter\r
3 \r
4     This file is part of VOMP.\r
5 \r
6     VOMP is free software; you can redistribute it and/or modify\r
7     it under the terms of the GNU General Public License as published by\r
8     the Free Software Foundation; either version 2 of the License, or\r
9     (at your option) any later version.\r
10 \r
11     VOMP is distributed in the hope that it will be useful,\r
12     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14     GNU General Public License for more details.\r
15 \r
16     You should have received a copy of the GNU General Public License\r
17     along with VOMP; if not, write to the Free Software\r
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
19 */\r
20 \r
21 #ifndef AUDIOOMX_H\r
22 #define AUDIOOMX_H\r
23 \r
24 #include <stdio.h>\r
25 #include <unistd.h>\r
26 #include <fcntl.h>\r
27 #include <sys/ioctl.h>\r
28 \r
29 #include "defines.h"\r
30 #include "audio.h"\r
31 #include "videoomx.h"\r
32 \r
33 extern "C" {\r
34 #include <libavcodec/avcodec.h>\r
35 #include <libavformat/avformat.h>\r
36 }\r
37 \r
38 \r
39 \r
40 \r
41 class AudioOMX : public Audio\r
42 {\r
43   friend class VideoOMX;\r
44   public:\r
45     AudioOMX();\r
46     virtual ~AudioOMX();\r
47 \r
48     int init(UCHAR streamType);\r
49     int shutdown();\r
50 \r
51     int setStreamType(UCHAR streamType);\r
52     int setChannel();\r
53     int setSource();\r
54     int sync();\r
55     int play();\r
56     int stop();\r
57     int pause();\r
58     int unPause();\r
59     int reset();\r
60     int setVolume(int volume);\r
61     int mute();\r
62     int unMute();\r
63     bool supportsAc3() { return true; }\r
64     bool maysupportAc3(){return true;}\r
65     bool streamTypeSupported(int streamtype)\r
66     {\r
67         switch (streamtype) {\r
68         case 0x11: //AAC LATM packaging\r
69         case 0x6A://ac3\r
70         case 3: //mpeg 1 layer 1 and 2\r
71         case 4:\r
72                 return true;\r
73         default:\r
74                 return false;\r
75         };\r
76     }\r
77 \r
78 \r
79     //Writing Data to Audiodevice\r
80     virtual void PrepareMediaSample(const MediaPacketList&, UINT samplepos);\r
81     virtual UINT DeliverMediaSample(UCHAR* buffer, UINT *samplepos);\r
82     UINT DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer,UINT *samplepos);\r
83 \r
84     virtual long long SetStartOffset(long long curreftime, bool *rsync);\r
85     virtual void ResetTimeOffsets();\r
86 \r
87     virtual bool DrainTargetReady() {return omx_running;};\r
88 \r
89 \r
90         UCHAR getLastAType() {return lastAType;}\r
91 \r
92         bool loadOptionsfromServer(VDR* vdr);\r
93         bool saveOptionstoServer();\r
94         bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane);\r
95         bool handleOptionChanges(Option* option);\r
96 \r
97 \r
98 #ifdef DEV\r
99     int test();\r
100 #endif\r
101 \r
102   private:\r
103     int initAllParams();\r
104     UCHAR streamType;\r
105         UCHAR lastAType;\r
106         bool firstsynched;\r
107 \r
108     MediaPacket packet;\r
109     UINT packetpos;\r
110 \r
111         bool paused;\r
112 \r
113     bool hdmi; // use hdmi as audio output\r
114     bool passthrough; // use audio passthrough for the current audio type\r
115 \r
116     bool canpass_aac;\r
117     bool canpass_ac3;\r
118     bool canpass_mp2;\r
119     bool canpass_mp3;\r
120     bool canpass_pcm_mch;\r
121 \r
122 \r
123     int prefered_aac;\r
124     int prefered_ac3; //0 stereo PCM, 1 passthrough 2 Multichannel PCM\r
125     int prefered_mp2;\r
126     int prefered_mp3;\r
127 \r
128 \r
129 \r
130     static OMX_ERRORTYPE EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);\r
131         static OMX_ERRORTYPE FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver);\r
132 \r
133 \r
134 \r
135         unsigned int AdvanceAc3AudioSync(const UCHAR *data,unsigned int size,unsigned int *framesize);\r
136         unsigned int AdvanceAacLatmAudioSync(const UCHAR *data,unsigned int size,unsigned int *framesize);\r
137         unsigned int AdvanceMpAudioSync(const UCHAR *data,unsigned int size,unsigned int *framesize);\r
138 \r
139 \r
140     void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver);\r
141 \r
142    // OMX_HANDLETYPE omx_aud_dec;\r
143         OMX_HANDLETYPE omx_aud_rend;\r
144         OMX_HANDLETYPE omx_clock;\r
145 \r
146         //OMX_U32 omx_codec_input_port;\r
147         //OMX_U32 omx_codec_output_port;\r
148         OMX_U32 omx_rend_input_port;\r
149         OMX_U32 omx_rend_clock_port;\r
150         OMX_U32 omx_clock_output_port;\r
151 \r
152         long long lastreftimeOMX;\r
153     ULLONG lastreftimePTS;\r
154 \r
155 \r
156 \r
157         int AllocateCodecsOMX();\r
158         int DeAllocateCodecsOMX();\r
159 \r
160         int PrepareInputBufsOMX(bool setportdef);\r
161         int DestroyInputBufsOMX();\r
162         int DestroyInputBufsOMXwhilePlaying();\r
163 \r
164         int ChangeAudioPortConfig(bool disport);\r
165         int ChangeAudioDestination();\r
166         long long correctAudioLatency(long long pts,int addsamples,int srate);\r
167 \r
168         vector<OMX_BUFFERHEADERTYPE*> input_bufs_omx_all;\r
169         list<OMX_BUFFERHEADERTYPE*> input_bufs_omx_free;\r
170         Mutex input_bufs_omx_mutex;\r
171         OMX_BUFFERHEADERTYPE* cur_input_buf_omx;\r
172 \r
173     bool omx_running;\r
174     bool omx_first_frame;\r
175     Mutex libav_mutex;\r
176 \r
177     AVCodec *aaclatmcodec_libav;\r
178     AVCodecContext *aaclatmcodec_context_libav;\r
179         AVCodec *ac3codec_libav;\r
180         AVCodecContext *ac3codec_context_libav;\r
181         AVCodec *mp23codec_libav;\r
182     AVCodecContext *mp23codec_context_libav;\r
183     AVPacket incoming_paket_libav;\r
184     AVFrame *decode_frame_libav;\r
185 \r
186     UCHAR * decompress_buffer;\r
187     unsigned int decompress_buffer_size;\r
188     unsigned int decompress_buffer_filled;\r
189     bool lsync;\r
190 \r
191 \r
192          int InitDecoderLibAV();\r
193          void DeinitDecoderLibAV();\r
194 \r
195 };\r
196 \r
197 #endif\r