Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / audio_coding / neteq / audio_decoder_impl.h
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/codecs/cng/include/webrtc_cng.h"
23 #ifdef WEBRTC_CODEC_G722
24 #include "webrtc/modules/audio_coding/codecs/g722/include/g722_interface.h"
25 #endif
26 #ifdef WEBRTC_CODEC_ILBC
27 #include "webrtc/modules/audio_coding/codecs/ilbc/interface/ilbc.h"
28 #endif
29 #ifdef WEBRTC_CODEC_ISACFX
30 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h"
31 #endif
32 #ifdef WEBRTC_CODEC_ISAC
33 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h"
34 #endif
35 #ifdef WEBRTC_CODEC_OPUS
36 #include "webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h"
37 #endif
38 #include "webrtc/modules/audio_coding/neteq/interface/audio_decoder.h"
39 #include "webrtc/typedefs.h"
40
41 namespace webrtc {
42
43 class AudioDecoderPcmU : public AudioDecoder {
44  public:
45   AudioDecoderPcmU() {}
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);
50
51  private:
52   DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmU);
53 };
54
55 class AudioDecoderPcmA : public AudioDecoder {
56  public:
57   AudioDecoderPcmA() {}
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);
62
63  private:
64   DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmA);
65 };
66
67 class AudioDecoderPcmUMultiCh : public AudioDecoderPcmU {
68  public:
69   explicit AudioDecoderPcmUMultiCh(size_t channels) : AudioDecoderPcmU() {
70     assert(channels > 0);
71     channels_ = channels;
72   }
73
74  private:
75   DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmUMultiCh);
76 };
77
78 class AudioDecoderPcmAMultiCh : public AudioDecoderPcmA {
79  public:
80   explicit AudioDecoderPcmAMultiCh(size_t channels) : AudioDecoderPcmA() {
81     assert(channels > 0);
82     channels_ = channels;
83   }
84
85  private:
86   DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmAMultiCh);
87 };
88
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 {
93  public:
94   AudioDecoderPcm16B();
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);
99
100  private:
101   DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcm16B);
102 };
103
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 {
108  public:
109   explicit AudioDecoderPcm16BMultiCh(int num_channels);
110
111  private:
112   DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcm16BMultiCh);
113 };
114 #endif
115
116 #ifdef WEBRTC_CODEC_ILBC
117 class AudioDecoderIlbc : public AudioDecoder {
118  public:
119   AudioDecoderIlbc();
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);
125   virtual int Init();
126
127  private:
128   iLBC_decinst_t* dec_state_;
129   DISALLOW_COPY_AND_ASSIGN(AudioDecoderIlbc);
130 };
131 #endif
132
133 #ifdef WEBRTC_CODEC_ISAC
134 class AudioDecoderIsac : public AudioDecoder {
135  public:
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);
144   virtual int Init();
145   virtual int IncomingPacket(const uint8_t* payload,
146                              size_t payload_len,
147                              uint16_t rtp_sequence_number,
148                              uint32_t rtp_timestamp,
149                              uint32_t arrival_timestamp);
150   virtual int ErrorCode();
151
152  private:
153   ISACStruct* isac_state_;
154   DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsac);
155 };
156 #endif
157
158 #ifdef WEBRTC_CODEC_ISACFX
159 class AudioDecoderIsacFix : public AudioDecoder {
160  public:
161   AudioDecoderIsacFix();
162   virtual ~AudioDecoderIsacFix();
163   virtual int Decode(const uint8_t* encoded, size_t encoded_len,
164                      int16_t* decoded, SpeechType* speech_type);
165   virtual int Init();
166   virtual int IncomingPacket(const uint8_t* payload,
167                              size_t payload_len,
168                              uint16_t rtp_sequence_number,
169                              uint32_t rtp_timestamp,
170                              uint32_t arrival_timestamp);
171   virtual int ErrorCode();
172
173  private:
174   ISACFIX_MainStruct* isac_state_;
175   DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsacFix);
176 };
177 #endif
178
179 #ifdef WEBRTC_CODEC_G722
180 class AudioDecoderG722 : public AudioDecoder {
181  public:
182   AudioDecoderG722();
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; }
187   virtual int Init();
188   virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len);
189
190  private:
191   G722DecInst* dec_state_;
192   DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722);
193 };
194
195 class AudioDecoderG722Stereo : public AudioDecoder {
196  public:
197   AudioDecoderG722Stereo();
198   virtual ~AudioDecoderG722Stereo();
199   virtual int Decode(const uint8_t* encoded, size_t encoded_len,
200                      int16_t* decoded, SpeechType* speech_type);
201   virtual int Init();
202
203  private:
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);
211
212   G722DecInst* dec_state_left_;
213   G722DecInst* dec_state_right_;
214
215   DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722Stereo);
216 };
217 #endif
218
219 #ifdef WEBRTC_CODEC_CELT
220 class AudioDecoderCelt : public AudioDecoder {
221  public:
222   explicit AudioDecoderCelt(int num_channels);
223   virtual ~AudioDecoderCelt();
224
225   virtual int Decode(const uint8_t* encoded, size_t encoded_len,
226                      int16_t* decoded, SpeechType* speech_type);
227   virtual int Init();
228   virtual bool HasDecodePlc() const;
229   virtual int DecodePlc(int num_frames, int16_t* decoded);
230
231  private:
232   DISALLOW_COPY_AND_ASSIGN(AudioDecoderCelt);
233 };
234 #endif
235
236 #ifdef WEBRTC_CODEC_OPUS
237 class AudioDecoderOpus : public AudioDecoder {
238  public:
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);
245   virtual int Init();
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;
250
251  private:
252   OpusDecInst* dec_state_;
253   DISALLOW_COPY_AND_ASSIGN(AudioDecoderOpus);
254 };
255 #endif
256
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 {
264  public:
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; }
269   virtual int Init();
270   virtual int IncomingPacket(const uint8_t* payload,
271                              size_t payload_len,
272                              uint16_t rtp_sequence_number,
273                              uint32_t rtp_timestamp,
274                              uint32_t arrival_timestamp) { return -1; }
275
276   virtual CNG_dec_inst* CngDecoderInstance() OVERRIDE { return dec_state_; }
277
278  private:
279   CNG_dec_inst* dec_state_;
280   DISALLOW_COPY_AND_ASSIGN(AudioDecoderCng);
281 };
282
283 }  // namespace webrtc
284 #endif  // WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_DECODER_IMPL_H_