]> git.vomp.tv Git - vompclient.git/blob - src/audioomx.h
Formatting
[vompclient.git] / src / 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, see <https://www.gnu.org/licenses/>.
18 */
19
20 #ifndef AUDIOOMX_H
21 #define AUDIOOMX_H
22
23 #include <stdio.h>
24 #include <unistd.h>
25 #include <fcntl.h>
26 #include <sys/ioctl.h>
27 #include <mutex>
28
29 extern "C"
30 {
31   #include <libavcodec/avcodec.h>
32   #include <libavformat/avformat.h>
33   #include <libswresample/swresample.h>
34 }
35
36 #include "defines.h"
37 #include "audio.h"
38 #include "videoomx.h"
39
40 class AudioOMX : public Audio
41 {
42   friend class VideoOMX;
43
44   public:
45     AudioOMX();
46     virtual ~AudioOMX();
47
48     int init(u1 streamType);
49     int shutdown();
50
51     int setStreamType(u1 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       {
69         case 0x11: //AAC LATM packaging
70         case 0x6A://ac3
71         case 3: //mpeg 1 layer 1 and 2
72         case 4:
73           return true;
74
75         default:
76           return false;
77       };
78     }
79
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);
84
85     virtual long long SetStartOffset(long long curreftime, bool* rsync);
86     virtual void ResetTimeOffsets();
87
88     virtual bool DrainTargetReady() {return omx_running;};
89     virtual bool DrainTargetBufferFull();
90
91     u1 getLastAType() {return lastAType;}
92
93     bool loadOptionsFromServer(VDR* vdr);
94     bool saveOptionstoServer();
95     bool addOptionsToPanes(int panenumber, Options* options, WOptionPane* pane);
96     bool handleOptionChanges(Option* option);
97
98 #ifdef DEV
99     int test();
100 #endif
101
102   private:
103     int initAllParams();
104     u1 streamType;
105     u1 lastAType;
106     bool firstsynched;
107
108     MediaPacket packet;
109     u4 packetpos;
110
111     bool hdmi; // use hdmi as audio output
112     bool passthrough; // use audio passthrough for the current audio type
113
114     bool canpass_aac;
115     bool canpass_ac3;
116     bool canpass_mp2;
117     bool canpass_mp3;
118     bool canpass_pcm_mch;
119
120     int prefered_aac;
121     int prefered_ac3; //0 stereo PCM, 1 passthrough 2 Multichannel PCM
122     int prefered_mp2;
123     int prefered_mp3;
124
125
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);
128
129
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);
133
134     void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver);
135
136     // OMX_HANDLETYPE omx_aud_dec;
137     OMX_HANDLETYPE omx_aud_rend;
138     OMX_HANDLETYPE omx_clock;
139
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;
145
146     long long lastreftimeOMX;
147     u8 lastreftimePTS;
148
149
150     int AllocateCodecsOMX();
151     int DeAllocateCodecsOMX();
152
153     int PrepareInputBufsOMX(bool setportdef);
154     int DestroyInputBufsOMX();
155     int DestroyInputBufsOMXwhilePlaying();
156
157     int ChangeAudioPortConfig(bool disport);
158     int ChangeAudioDestination();
159     long long correctAudioLatency(long long pts, int addsamples, int srate);
160
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;
165
166     bool omx_running;
167     bool omx_first_frame;
168     std::mutex libav_mutex;
169
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;
179
180
181     u1* decompress_buffer;
182     unsigned int decompress_buffer_size;
183     unsigned int decompress_buffer_filled;
184     bool lsync;
185
186     unsigned int mp3sameheader;
187     int mp3sameheadercount;
188
189
190     int InitDecoderLibAV();
191     void DeinitDecoderLibAV();
192
193     char L_VPE_OMX_AUDIO_REND[128];
194
195     int badMinimumFunction(u4 a, int b);
196
197     int DO_NOT_USE(AVCodecContext* avctx, AVFrame* frame, int* got_frame_ptr, const AVPacket* avpkt);
198 };
199
200 #endif