• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
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.
9  */
10 
11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_DECODER_IMPL_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_DECODER_IMPL_H_
13 
14 #include <assert.h>
15 
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"
20 #endif
21 #include "webrtc/base/constructormagic.h"
22 #include "webrtc/modules/audio_coding/neteq/interface/audio_decoder.h"
23 #include "webrtc/typedefs.h"
24 
25 namespace webrtc {
26 
27 class AudioDecoderPcmU : public AudioDecoder {
28  public:
AudioDecoderPcmU()29   AudioDecoderPcmU() : AudioDecoder(kDecoderPCMu) {}
30   virtual int Decode(const uint8_t* encoded, size_t encoded_len,
31                      int16_t* decoded, SpeechType* speech_type);
Init()32   virtual int Init() { return 0; }
33   virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len);
34 
35  private:
36   DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmU);
37 };
38 
39 class AudioDecoderPcmA : public AudioDecoder {
40  public:
AudioDecoderPcmA()41   AudioDecoderPcmA() : AudioDecoder(kDecoderPCMa) {}
42   virtual int Decode(const uint8_t* encoded, size_t encoded_len,
43                      int16_t* decoded, SpeechType* speech_type);
Init()44   virtual int Init() { return 0; }
45   virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len);
46 
47  private:
48   DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmA);
49 };
50 
51 class AudioDecoderPcmUMultiCh : public AudioDecoderPcmU {
52  public:
AudioDecoderPcmUMultiCh(size_t channels)53   explicit AudioDecoderPcmUMultiCh(size_t channels) : AudioDecoderPcmU() {
54     assert(channels > 0);
55     channels_ = channels;
56   }
57 
58  private:
59   DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmUMultiCh);
60 };
61 
62 class AudioDecoderPcmAMultiCh : public AudioDecoderPcmA {
63  public:
AudioDecoderPcmAMultiCh(size_t channels)64   explicit AudioDecoderPcmAMultiCh(size_t channels) : AudioDecoderPcmA() {
65     assert(channels > 0);
66     channels_ = channels;
67   }
68 
69  private:
70   DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmAMultiCh);
71 };
72 
73 #ifdef WEBRTC_CODEC_PCM16
74 // This class handles all four types (i.e., sample rates) of PCM16B codecs.
75 // The type is specified in the constructor parameter |type|.
76 class AudioDecoderPcm16B : public AudioDecoder {
77  public:
78   explicit AudioDecoderPcm16B(enum NetEqDecoder type);
79   virtual int Decode(const uint8_t* encoded, size_t encoded_len,
80                      int16_t* decoded, SpeechType* speech_type);
Init()81   virtual int Init() { return 0; }
82   virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len);
83 
84  private:
85   DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcm16B);
86 };
87 
88 // This class handles all four types (i.e., sample rates) of PCM16B codecs.
89 // The type is specified in the constructor parameter |type|, and the number
90 // of channels is derived from the type.
91 class AudioDecoderPcm16BMultiCh : public AudioDecoderPcm16B {
92  public:
93   explicit AudioDecoderPcm16BMultiCh(enum NetEqDecoder type);
94 
95  private:
96   DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcm16BMultiCh);
97 };
98 #endif
99 
100 #ifdef WEBRTC_CODEC_ILBC
101 class AudioDecoderIlbc : public AudioDecoder {
102  public:
103   AudioDecoderIlbc();
104   virtual ~AudioDecoderIlbc();
105   virtual int Decode(const uint8_t* encoded, size_t encoded_len,
106                      int16_t* decoded, SpeechType* speech_type);
HasDecodePlc()107   virtual bool HasDecodePlc() const { return true; }
108   virtual int DecodePlc(int num_frames, int16_t* decoded);
109   virtual int Init();
110 
111  private:
112   DISALLOW_COPY_AND_ASSIGN(AudioDecoderIlbc);
113 };
114 #endif
115 
116 #ifdef WEBRTC_CODEC_ISAC
117 class AudioDecoderIsac : public AudioDecoder {
118  public:
119   AudioDecoderIsac();
120   virtual ~AudioDecoderIsac();
121   virtual int Decode(const uint8_t* encoded, size_t encoded_len,
122                      int16_t* decoded, SpeechType* speech_type);
123   virtual int DecodeRedundant(const uint8_t* encoded, size_t encoded_len,
124                               int16_t* decoded, SpeechType* speech_type);
HasDecodePlc()125   virtual bool HasDecodePlc() const { return true; }
126   virtual int DecodePlc(int num_frames, int16_t* decoded);
127   virtual int Init();
128   virtual int IncomingPacket(const uint8_t* payload,
129                              size_t payload_len,
130                              uint16_t rtp_sequence_number,
131                              uint32_t rtp_timestamp,
132                              uint32_t arrival_timestamp);
133   virtual int ErrorCode();
134 
135  private:
136   DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsac);
137 };
138 
139 class AudioDecoderIsacSwb : public AudioDecoderIsac {
140  public:
141   AudioDecoderIsacSwb();
142 
143  private:
144   DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsacSwb);
145 };
146 
147 class AudioDecoderIsacFb : public AudioDecoderIsacSwb {
148  public:
149   AudioDecoderIsacFb();
150 
151  private:
152   DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsacFb);
153 };
154 #endif
155 
156 #ifdef WEBRTC_CODEC_ISACFX
157 class AudioDecoderIsacFix : public AudioDecoder {
158  public:
159   AudioDecoderIsacFix();
160   virtual ~AudioDecoderIsacFix();
161   virtual int Decode(const uint8_t* encoded, size_t encoded_len,
162                      int16_t* decoded, SpeechType* speech_type);
163   virtual int Init();
164   virtual int IncomingPacket(const uint8_t* payload,
165                              size_t payload_len,
166                              uint16_t rtp_sequence_number,
167                              uint32_t rtp_timestamp,
168                              uint32_t arrival_timestamp);
169   virtual int ErrorCode();
170 
171  private:
172   DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsacFix);
173 };
174 #endif
175 
176 #ifdef WEBRTC_CODEC_G722
177 class AudioDecoderG722 : public AudioDecoder {
178  public:
179   AudioDecoderG722();
180   virtual ~AudioDecoderG722();
181   virtual int Decode(const uint8_t* encoded, size_t encoded_len,
182                      int16_t* decoded, SpeechType* speech_type);
HasDecodePlc()183   virtual bool HasDecodePlc() const { return false; }
184   virtual int Init();
185   virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len);
186 
187  private:
188   DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722);
189 };
190 
191 class AudioDecoderG722Stereo : public AudioDecoderG722 {
192  public:
193   AudioDecoderG722Stereo();
194   virtual ~AudioDecoderG722Stereo();
195   virtual int Decode(const uint8_t* encoded, size_t encoded_len,
196                      int16_t* decoded, SpeechType* speech_type);
197   virtual int Init();
198 
199  private:
200   // Splits the stereo-interleaved payload in |encoded| into separate payloads
201   // for left and right channels. The separated payloads are written to
202   // |encoded_deinterleaved|, which must hold at least |encoded_len| samples.
203   // The left channel starts at offset 0, while the right channel starts at
204   // offset encoded_len / 2 into |encoded_deinterleaved|.
205   void SplitStereoPacket(const uint8_t* encoded, size_t encoded_len,
206                          uint8_t* encoded_deinterleaved);
207 
208   void* const state_left_;
209   void* state_right_;
210 
211   DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722Stereo);
212 };
213 #endif
214 
215 #ifdef WEBRTC_CODEC_CELT
216 class AudioDecoderCelt : public AudioDecoder {
217  public:
218   explicit AudioDecoderCelt(enum NetEqDecoder type);
219   virtual ~AudioDecoderCelt();
220 
221   virtual int Decode(const uint8_t* encoded, size_t encoded_len,
222                      int16_t* decoded, SpeechType* speech_type);
223   virtual int Init();
224   virtual bool HasDecodePlc() const;
225   virtual int DecodePlc(int num_frames, int16_t* decoded);
226 
227  private:
228   DISALLOW_COPY_AND_ASSIGN(AudioDecoderCelt);
229 };
230 #endif
231 
232 #ifdef WEBRTC_CODEC_OPUS
233 class AudioDecoderOpus : public AudioDecoder {
234  public:
235   explicit AudioDecoderOpus(enum NetEqDecoder type);
236   virtual ~AudioDecoderOpus();
237   virtual int Decode(const uint8_t* encoded, size_t encoded_len,
238                      int16_t* decoded, SpeechType* speech_type);
239   virtual int DecodeRedundant(const uint8_t* encoded, size_t encoded_len,
240                               int16_t* decoded, SpeechType* speech_type);
241   virtual int Init();
242   virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len);
243   virtual int PacketDurationRedundant(const uint8_t* encoded,
244                                       size_t encoded_len) const;
245   virtual bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const;
246 
247  private:
248   DISALLOW_COPY_AND_ASSIGN(AudioDecoderOpus);
249 };
250 #endif
251 
252 // AudioDecoderCng is a special type of AudioDecoder. It inherits from
253 // AudioDecoder just to fit in the DecoderDatabase. None of the class methods
254 // should be used, except constructor, destructor, and accessors.
255 // TODO(hlundin): Consider the possibility to create a super-class to
256 // AudioDecoder that is stored in DecoderDatabase. Then AudioDecoder and a
257 // specific CngDecoder class could both inherit from that class.
258 class AudioDecoderCng : public AudioDecoder {
259  public:
260   explicit AudioDecoderCng(enum NetEqDecoder type);
261   virtual ~AudioDecoderCng();
Decode(const uint8_t * encoded,size_t encoded_len,int16_t * decoded,SpeechType * speech_type)262   virtual int Decode(const uint8_t* encoded, size_t encoded_len,
263                      int16_t* decoded, SpeechType* speech_type) { return -1; }
264   virtual int Init();
IncomingPacket(const uint8_t * payload,size_t payload_len,uint16_t rtp_sequence_number,uint32_t rtp_timestamp,uint32_t arrival_timestamp)265   virtual int IncomingPacket(const uint8_t* payload,
266                              size_t payload_len,
267                              uint16_t rtp_sequence_number,
268                              uint32_t rtp_timestamp,
269                              uint32_t arrival_timestamp) { return -1; }
270 
271  private:
272   DISALLOW_COPY_AND_ASSIGN(AudioDecoderCng);
273 };
274 
275 }  // namespace webrtc
276 #endif  // WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_DECODER_IMPL_H_
277