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