henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 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 | #include "webrtc/modules/audio_coding/neteq4/interface/audio_decoder.h" |
| 12 | |
| 13 | #include <assert.h> |
| 14 | |
| 15 | #include "webrtc/modules/audio_coding/neteq4/audio_decoder_impl.h" |
| 16 | |
| 17 | namespace webrtc { |
| 18 | |
pbos@webrtc.org | 2d1a55c | 2013-07-31 15:54:00 +0000 | [diff] [blame] | 19 | int AudioDecoder::DecodeRedundant(const uint8_t* encoded, |
| 20 | size_t encoded_len, |
| 21 | int16_t* decoded, |
| 22 | SpeechType* speech_type) { |
| 23 | return Decode(encoded, encoded_len, decoded, speech_type); |
| 24 | } |
| 25 | |
| 26 | bool AudioDecoder::HasDecodePlc() const { return false; } |
| 27 | |
| 28 | int AudioDecoder::DecodePlc(int num_frames, int16_t* decoded) { return -1; } |
| 29 | |
| 30 | int AudioDecoder::IncomingPacket(const uint8_t* payload, |
| 31 | size_t payload_len, |
| 32 | uint16_t rtp_sequence_number, |
| 33 | uint32_t rtp_timestamp, |
| 34 | uint32_t arrival_timestamp) { |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | int AudioDecoder::ErrorCode() { return 0; } |
| 39 | |
| 40 | int AudioDecoder::PacketDuration(const uint8_t* encoded, size_t encoded_len) { |
| 41 | return kNotImplemented; |
| 42 | } |
| 43 | |
| 44 | NetEqDecoder AudioDecoder::codec_type() const { return codec_type_; } |
| 45 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 46 | bool AudioDecoder::CodecSupported(NetEqDecoder codec_type) { |
| 47 | switch (codec_type) { |
| 48 | case kDecoderPCMu: |
| 49 | case kDecoderPCMa: |
| 50 | case kDecoderPCMu_2ch: |
| 51 | case kDecoderPCMa_2ch: |
| 52 | #ifdef WEBRTC_CODEC_ILBC |
| 53 | case kDecoderILBC: |
| 54 | #endif |
| 55 | #if defined(WEBRTC_CODEC_ISACFX) || defined(WEBRTC_CODEC_ISAC) |
| 56 | case kDecoderISAC: |
| 57 | #endif |
| 58 | #ifdef WEBRTC_CODEC_ISAC |
| 59 | case kDecoderISACswb: |
henrik.lundin@webrtc.org | ac59dba | 2013-01-31 09:55:24 +0000 | [diff] [blame] | 60 | case kDecoderISACfb: |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 61 | #endif |
| 62 | #ifdef WEBRTC_CODEC_PCM16 |
| 63 | case kDecoderPCM16B: |
| 64 | case kDecoderPCM16Bwb: |
| 65 | case kDecoderPCM16Bswb32kHz: |
| 66 | case kDecoderPCM16Bswb48kHz: |
| 67 | case kDecoderPCM16B_2ch: |
| 68 | case kDecoderPCM16Bwb_2ch: |
| 69 | case kDecoderPCM16Bswb32kHz_2ch: |
| 70 | case kDecoderPCM16Bswb48kHz_2ch: |
| 71 | case kDecoderPCM16B_5ch: |
| 72 | #endif |
| 73 | #ifdef WEBRTC_CODEC_G722 |
| 74 | case kDecoderG722: |
henrik.lundin@webrtc.org | aaad613 | 2013-02-01 11:49:28 +0000 | [diff] [blame] | 75 | case kDecoderG722_2ch: |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 76 | #endif |
turaj@webrtc.org | 6ad6a07 | 2013-09-30 20:07:39 +0000 | [diff] [blame] | 77 | #ifdef WEBRTC_CODEC_CELT |
| 78 | case kDecoderCELT_32: |
| 79 | case kDecoderCELT_32_2ch: |
| 80 | #endif |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 81 | #ifdef WEBRTC_CODEC_OPUS |
| 82 | case kDecoderOpus: |
| 83 | case kDecoderOpus_2ch: |
| 84 | #endif |
| 85 | case kDecoderRED: |
| 86 | case kDecoderAVT: |
| 87 | case kDecoderCNGnb: |
| 88 | case kDecoderCNGwb: |
| 89 | case kDecoderCNGswb32kHz: |
| 90 | case kDecoderCNGswb48kHz: |
| 91 | case kDecoderArbitrary: { |
| 92 | return true; |
| 93 | } |
| 94 | default: { |
| 95 | return false; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | int AudioDecoder::CodecSampleRateHz(NetEqDecoder codec_type) { |
| 101 | switch (codec_type) { |
| 102 | case kDecoderPCMu: |
| 103 | case kDecoderPCMa: |
| 104 | case kDecoderPCMu_2ch: |
| 105 | case kDecoderPCMa_2ch: |
| 106 | #ifdef WEBRTC_CODEC_ILBC |
| 107 | case kDecoderILBC: |
| 108 | #endif |
| 109 | #ifdef WEBRTC_CODEC_PCM16 |
| 110 | case kDecoderPCM16B: |
| 111 | case kDecoderPCM16B_2ch: |
| 112 | case kDecoderPCM16B_5ch: |
| 113 | #endif |
| 114 | case kDecoderCNGnb: { |
| 115 | return 8000; |
| 116 | } |
| 117 | #if defined(WEBRTC_CODEC_ISACFX) || defined(WEBRTC_CODEC_ISAC) |
| 118 | case kDecoderISAC: |
| 119 | #endif |
| 120 | #ifdef WEBRTC_CODEC_PCM16 |
| 121 | case kDecoderPCM16Bwb: |
| 122 | case kDecoderPCM16Bwb_2ch: |
| 123 | #endif |
| 124 | #ifdef WEBRTC_CODEC_G722 |
| 125 | case kDecoderG722: |
henrik.lundin@webrtc.org | aaad613 | 2013-02-01 11:49:28 +0000 | [diff] [blame] | 126 | case kDecoderG722_2ch: |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 127 | #endif |
| 128 | case kDecoderCNGwb: { |
| 129 | return 16000; |
| 130 | } |
| 131 | #ifdef WEBRTC_CODEC_ISAC |
| 132 | case kDecoderISACswb: |
henrik.lundin@webrtc.org | ac59dba | 2013-01-31 09:55:24 +0000 | [diff] [blame] | 133 | case kDecoderISACfb: |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 134 | #endif |
| 135 | #ifdef WEBRTC_CODEC_PCM16 |
| 136 | case kDecoderPCM16Bswb32kHz: |
| 137 | case kDecoderPCM16Bswb32kHz_2ch: |
| 138 | #endif |
turaj@webrtc.org | 6ad6a07 | 2013-09-30 20:07:39 +0000 | [diff] [blame] | 139 | #ifdef WEBRTC_CODEC_CELT |
| 140 | case kDecoderCELT_32: |
| 141 | case kDecoderCELT_32_2ch: |
| 142 | #endif |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 143 | case kDecoderCNGswb32kHz: { |
| 144 | return 32000; |
| 145 | } |
| 146 | #ifdef WEBRTC_CODEC_PCM16 |
| 147 | case kDecoderPCM16Bswb48kHz: |
| 148 | case kDecoderPCM16Bswb48kHz_2ch: { |
| 149 | return 48000; |
| 150 | } |
| 151 | #endif |
| 152 | #ifdef WEBRTC_CODEC_OPUS |
| 153 | case kDecoderOpus: |
| 154 | case kDecoderOpus_2ch: { |
| 155 | return 32000; |
| 156 | } |
| 157 | #endif |
| 158 | case kDecoderCNGswb48kHz: { |
| 159 | // TODO(tlegrand): Remove limitation once ACM has full 48 kHz support. |
| 160 | return 32000; |
| 161 | } |
| 162 | default: { |
| 163 | return -1; // Undefined sample rate. |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | AudioDecoder* AudioDecoder::CreateAudioDecoder(NetEqDecoder codec_type) { |
| 169 | if (!CodecSupported(codec_type)) { |
| 170 | return NULL; |
| 171 | } |
| 172 | switch (codec_type) { |
| 173 | case kDecoderPCMu: |
| 174 | return new AudioDecoderPcmU; |
| 175 | case kDecoderPCMa: |
| 176 | return new AudioDecoderPcmA; |
| 177 | case kDecoderPCMu_2ch: |
| 178 | return new AudioDecoderPcmUMultiCh(2); |
| 179 | case kDecoderPCMa_2ch: |
| 180 | return new AudioDecoderPcmAMultiCh(2); |
| 181 | #ifdef WEBRTC_CODEC_ILBC |
| 182 | case kDecoderILBC: |
| 183 | return new AudioDecoderIlbc; |
| 184 | #endif |
| 185 | #if defined(WEBRTC_CODEC_ISACFX) |
| 186 | case kDecoderISAC: |
| 187 | return new AudioDecoderIsacFix; |
| 188 | #elif defined(WEBRTC_CODEC_ISAC) |
| 189 | case kDecoderISAC: |
| 190 | return new AudioDecoderIsac; |
| 191 | #endif |
| 192 | #ifdef WEBRTC_CODEC_ISAC |
| 193 | case kDecoderISACswb: |
| 194 | return new AudioDecoderIsacSwb; |
henrik.lundin@webrtc.org | ac59dba | 2013-01-31 09:55:24 +0000 | [diff] [blame] | 195 | case kDecoderISACfb: |
| 196 | return new AudioDecoderIsacFb; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 197 | #endif |
| 198 | #ifdef WEBRTC_CODEC_PCM16 |
| 199 | case kDecoderPCM16B: |
| 200 | case kDecoderPCM16Bwb: |
| 201 | case kDecoderPCM16Bswb32kHz: |
| 202 | case kDecoderPCM16Bswb48kHz: |
| 203 | return new AudioDecoderPcm16B(codec_type); |
| 204 | case kDecoderPCM16B_2ch: |
| 205 | case kDecoderPCM16Bwb_2ch: |
| 206 | case kDecoderPCM16Bswb32kHz_2ch: |
| 207 | case kDecoderPCM16Bswb48kHz_2ch: |
| 208 | case kDecoderPCM16B_5ch: |
| 209 | return new AudioDecoderPcm16BMultiCh(codec_type); |
| 210 | #endif |
| 211 | #ifdef WEBRTC_CODEC_G722 |
| 212 | case kDecoderG722: |
| 213 | return new AudioDecoderG722; |
turaj@webrtc.org | 4b1cd5c | 2013-03-27 20:42:48 +0000 | [diff] [blame] | 214 | case kDecoderG722_2ch: |
| 215 | return new AudioDecoderG722Stereo; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 216 | #endif |
turaj@webrtc.org | 6ad6a07 | 2013-09-30 20:07:39 +0000 | [diff] [blame] | 217 | #ifdef WEBRTC_CODEC_CELT |
| 218 | case kDecoderCELT_32: |
| 219 | case kDecoderCELT_32_2ch: |
| 220 | return new AudioDecoderCelt(codec_type); |
| 221 | #endif |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 222 | #ifdef WEBRTC_CODEC_OPUS |
| 223 | case kDecoderOpus: |
| 224 | case kDecoderOpus_2ch: |
| 225 | return new AudioDecoderOpus(codec_type); |
| 226 | #endif |
| 227 | case kDecoderCNGnb: |
| 228 | case kDecoderCNGwb: |
| 229 | case kDecoderCNGswb32kHz: |
| 230 | case kDecoderCNGswb48kHz: |
| 231 | return new AudioDecoderCng(codec_type); |
| 232 | case kDecoderRED: |
| 233 | case kDecoderAVT: |
| 234 | case kDecoderArbitrary: |
| 235 | default: { |
| 236 | return NULL; |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | AudioDecoder::SpeechType AudioDecoder::ConvertSpeechType(int16_t type) { |
| 242 | switch (type) { |
| 243 | case 0: // TODO(hlundin): Both iSAC and Opus return 0 for speech. |
| 244 | case 1: |
| 245 | return kSpeech; |
| 246 | case 2: |
| 247 | return kComfortNoise; |
| 248 | default: |
| 249 | assert(false); |
| 250 | return kSpeech; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | } // namespace webrtc |