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