2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_DECODER_IMPL_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_DECODER_IMPL_H_
16 #ifndef AUDIO_DECODER_UNITTEST
17 // If this is compiled as a part of the audio_deoder_unittest, the codec
18 // selection is made in the gypi file instead of in engine_configurations.h.
19 #include "webrtc/engine_configurations.h"
21 #include "webrtc/base/constructormagic.h"
22 #include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h"
23 #ifdef WEBRTC_CODEC_G722
24 #include "webrtc/modules/audio_coding/codecs/g722/include/g722_interface.h"
26 #ifdef WEBRTC_CODEC_ILBC
27 #include "webrtc/modules/audio_coding/codecs/ilbc/interface/ilbc.h"
29 #ifdef WEBRTC_CODEC_ISACFX
30 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h"
32 #ifdef WEBRTC_CODEC_ISAC
33 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h"
35 #ifdef WEBRTC_CODEC_OPUS
36 #include "webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h"
38 #include "webrtc/modules/audio_coding/neteq/interface/audio_decoder.h"
39 #include "webrtc/typedefs.h"
43 class AudioDecoderPcmU : public AudioDecoder {
46 virtual int Decode(const uint8_t* encoded, size_t encoded_len,
47 int16_t* decoded, SpeechType* speech_type);
48 virtual int Init() { return 0; }
49 virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len);
52 DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmU);
55 class AudioDecoderPcmA : public AudioDecoder {
58 virtual int Decode(const uint8_t* encoded, size_t encoded_len,
59 int16_t* decoded, SpeechType* speech_type);
60 virtual int Init() { return 0; }
61 virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len);
64 DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmA);
67 class AudioDecoderPcmUMultiCh : public AudioDecoderPcmU {
69 explicit AudioDecoderPcmUMultiCh(size_t channels) : AudioDecoderPcmU() {
75 DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmUMultiCh);
78 class AudioDecoderPcmAMultiCh : public AudioDecoderPcmA {
80 explicit AudioDecoderPcmAMultiCh(size_t channels) : AudioDecoderPcmA() {
86 DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmAMultiCh);
89 #ifdef WEBRTC_CODEC_PCM16
90 // This class handles all four types (i.e., sample rates) of PCM16B codecs.
91 // The type is specified in the constructor parameter |type|.
92 class AudioDecoderPcm16B : public AudioDecoder {
95 virtual int Decode(const uint8_t* encoded, size_t encoded_len,
96 int16_t* decoded, SpeechType* speech_type);
97 virtual int Init() { return 0; }
98 virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len);
101 DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcm16B);
104 // This class handles all four types (i.e., sample rates) of PCM16B codecs.
105 // The type is specified in the constructor parameter |type|, and the number
106 // of channels is derived from the type.
107 class AudioDecoderPcm16BMultiCh : public AudioDecoderPcm16B {
109 explicit AudioDecoderPcm16BMultiCh(int num_channels);
112 DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcm16BMultiCh);
116 #ifdef WEBRTC_CODEC_ILBC
117 class AudioDecoderIlbc : public AudioDecoder {
120 virtual ~AudioDecoderIlbc();
121 virtual int Decode(const uint8_t* encoded, size_t encoded_len,
122 int16_t* decoded, SpeechType* speech_type);
123 virtual bool HasDecodePlc() const { return true; }
124 virtual int DecodePlc(int num_frames, int16_t* decoded);
128 iLBC_decinst_t* dec_state_;
129 DISALLOW_COPY_AND_ASSIGN(AudioDecoderIlbc);
133 #ifdef WEBRTC_CODEC_ISAC
134 class AudioDecoderIsac : public AudioDecoder {
136 explicit AudioDecoderIsac(int decode_sample_rate_hz);
137 virtual ~AudioDecoderIsac();
138 virtual int Decode(const uint8_t* encoded, size_t encoded_len,
139 int16_t* decoded, SpeechType* speech_type);
140 virtual int DecodeRedundant(const uint8_t* encoded, size_t encoded_len,
141 int16_t* decoded, SpeechType* speech_type);
142 virtual bool HasDecodePlc() const { return true; }
143 virtual int DecodePlc(int num_frames, int16_t* decoded);
145 virtual int IncomingPacket(const uint8_t* payload,
147 uint16_t rtp_sequence_number,
148 uint32_t rtp_timestamp,
149 uint32_t arrival_timestamp);
150 virtual int ErrorCode();
153 ISACStruct* isac_state_;
154 DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsac);
158 #ifdef WEBRTC_CODEC_ISACFX
159 class AudioDecoderIsacFix : public AudioDecoder {
161 AudioDecoderIsacFix();
162 virtual ~AudioDecoderIsacFix();
163 virtual int Decode(const uint8_t* encoded, size_t encoded_len,
164 int16_t* decoded, SpeechType* speech_type);
166 virtual int IncomingPacket(const uint8_t* payload,
168 uint16_t rtp_sequence_number,
169 uint32_t rtp_timestamp,
170 uint32_t arrival_timestamp);
171 virtual int ErrorCode();
174 ISACFIX_MainStruct* isac_state_;
175 DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsacFix);
179 #ifdef WEBRTC_CODEC_G722
180 class AudioDecoderG722 : public AudioDecoder {
183 virtual ~AudioDecoderG722();
184 virtual int Decode(const uint8_t* encoded, size_t encoded_len,
185 int16_t* decoded, SpeechType* speech_type);
186 virtual bool HasDecodePlc() const { return false; }
188 virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len);
191 G722DecInst* dec_state_;
192 DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722);
195 class AudioDecoderG722Stereo : public AudioDecoder {
197 AudioDecoderG722Stereo();
198 virtual ~AudioDecoderG722Stereo();
199 virtual int Decode(const uint8_t* encoded, size_t encoded_len,
200 int16_t* decoded, SpeechType* speech_type);
204 // Splits the stereo-interleaved payload in |encoded| into separate payloads
205 // for left and right channels. The separated payloads are written to
206 // |encoded_deinterleaved|, which must hold at least |encoded_len| samples.
207 // The left channel starts at offset 0, while the right channel starts at
208 // offset encoded_len / 2 into |encoded_deinterleaved|.
209 void SplitStereoPacket(const uint8_t* encoded, size_t encoded_len,
210 uint8_t* encoded_deinterleaved);
212 G722DecInst* dec_state_left_;
213 G722DecInst* dec_state_right_;
215 DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722Stereo);
219 #ifdef WEBRTC_CODEC_CELT
220 class AudioDecoderCelt : public AudioDecoder {
222 explicit AudioDecoderCelt(int num_channels);
223 virtual ~AudioDecoderCelt();
225 virtual int Decode(const uint8_t* encoded, size_t encoded_len,
226 int16_t* decoded, SpeechType* speech_type);
228 virtual bool HasDecodePlc() const;
229 virtual int DecodePlc(int num_frames, int16_t* decoded);
232 DISALLOW_COPY_AND_ASSIGN(AudioDecoderCelt);
236 #ifdef WEBRTC_CODEC_OPUS
237 class AudioDecoderOpus : public AudioDecoder {
239 explicit AudioDecoderOpus(int num_channels);
240 virtual ~AudioDecoderOpus();
241 virtual int Decode(const uint8_t* encoded, size_t encoded_len,
242 int16_t* decoded, SpeechType* speech_type);
243 virtual int DecodeRedundant(const uint8_t* encoded, size_t encoded_len,
244 int16_t* decoded, SpeechType* speech_type);
246 virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len);
247 virtual int PacketDurationRedundant(const uint8_t* encoded,
248 size_t encoded_len) const;
249 virtual bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const;
252 OpusDecInst* dec_state_;
253 DISALLOW_COPY_AND_ASSIGN(AudioDecoderOpus);
257 // AudioDecoderCng is a special type of AudioDecoder. It inherits from
258 // AudioDecoder just to fit in the DecoderDatabase. None of the class methods
259 // should be used, except constructor, destructor, and accessors.
260 // TODO(hlundin): Consider the possibility to create a super-class to
261 // AudioDecoder that is stored in DecoderDatabase. Then AudioDecoder and a
262 // specific CngDecoder class could both inherit from that class.
263 class AudioDecoderCng : public AudioDecoder {
265 explicit AudioDecoderCng();
266 virtual ~AudioDecoderCng();
267 virtual int Decode(const uint8_t* encoded, size_t encoded_len,
268 int16_t* decoded, SpeechType* speech_type) { return -1; }
270 virtual int IncomingPacket(const uint8_t* payload,
272 uint16_t rtp_sequence_number,
273 uint32_t rtp_timestamp,
274 uint32_t arrival_timestamp) { return -1; }
276 virtual CNG_dec_inst* CngDecoderInstance() OVERRIDE { return dec_state_; }
279 CNG_dec_inst* dec_state_;
280 DISALLOW_COPY_AND_ASSIGN(AudioDecoderCng);
283 } // namespace webrtc
284 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_DECODER_IMPL_H_