kwiberg@webrtc.org | e04a93b | 2014-12-09 10:12:53 +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/codecs/audio_decoder.h" |
| 12 | |
| 13 | #include <assert.h> |
| 14 | |
| 15 | #include "webrtc/base/checks.h" |
| 16 | |
| 17 | namespace webrtc { |
| 18 | |
minyue@webrtc.org | 7f7d7e3 | 2015-03-16 12:30:37 +0000 | [diff] [blame] | 19 | int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len, |
| 20 | int sample_rate_hz, size_t max_decoded_bytes, |
| 21 | int16_t* decoded, SpeechType* speech_type) { |
| 22 | int duration = PacketDuration(encoded, encoded_len); |
Minyue | 323b132 | 2015-05-25 13:49:37 +0200 | [diff] [blame] | 23 | if (duration >= 0 && |
| 24 | duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { |
minyue@webrtc.org | 7f7d7e3 | 2015-03-16 12:30:37 +0000 | [diff] [blame] | 25 | return -1; |
| 26 | } |
| 27 | return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded, |
| 28 | speech_type); |
| 29 | } |
| 30 | |
| 31 | int AudioDecoder::DecodeRedundant(const uint8_t* encoded, size_t encoded_len, |
| 32 | int sample_rate_hz, size_t max_decoded_bytes, |
| 33 | int16_t* decoded, SpeechType* speech_type) { |
| 34 | int duration = PacketDurationRedundant(encoded, encoded_len); |
Minyue | 323b132 | 2015-05-25 13:49:37 +0200 | [diff] [blame] | 35 | if (duration >= 0 && |
| 36 | duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { |
minyue@webrtc.org | 7f7d7e3 | 2015-03-16 12:30:37 +0000 | [diff] [blame] | 37 | return -1; |
| 38 | } |
| 39 | return DecodeRedundantInternal(encoded, encoded_len, sample_rate_hz, decoded, |
| 40 | speech_type); |
| 41 | } |
| 42 | |
| 43 | int AudioDecoder::DecodeInternal(const uint8_t* encoded, size_t encoded_len, |
| 44 | int sample_rate_hz, int16_t* decoded, |
| 45 | SpeechType* speech_type) { |
| 46 | return kNotImplemented; |
| 47 | } |
| 48 | |
| 49 | int AudioDecoder::DecodeRedundantInternal(const uint8_t* encoded, |
| 50 | size_t encoded_len, |
| 51 | int sample_rate_hz, int16_t* decoded, |
| 52 | SpeechType* speech_type) { |
| 53 | return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded, |
| 54 | speech_type); |
kwiberg@webrtc.org | e04a93b | 2014-12-09 10:12:53 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | bool AudioDecoder::HasDecodePlc() const { return false; } |
| 58 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame^] | 59 | size_t AudioDecoder::DecodePlc(size_t num_frames, int16_t* decoded) { |
| 60 | return 0; |
| 61 | } |
kwiberg@webrtc.org | e04a93b | 2014-12-09 10:12:53 +0000 | [diff] [blame] | 62 | |
| 63 | int AudioDecoder::IncomingPacket(const uint8_t* payload, |
| 64 | size_t payload_len, |
| 65 | uint16_t rtp_sequence_number, |
| 66 | uint32_t rtp_timestamp, |
| 67 | uint32_t arrival_timestamp) { |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | int AudioDecoder::ErrorCode() { return 0; } |
| 72 | |
minyue@webrtc.org | a8cc344 | 2015-02-13 14:01:54 +0000 | [diff] [blame] | 73 | int AudioDecoder::PacketDuration(const uint8_t* encoded, |
| 74 | size_t encoded_len) const { |
kwiberg@webrtc.org | e04a93b | 2014-12-09 10:12:53 +0000 | [diff] [blame] | 75 | return kNotImplemented; |
| 76 | } |
| 77 | |
| 78 | int AudioDecoder::PacketDurationRedundant(const uint8_t* encoded, |
| 79 | size_t encoded_len) const { |
| 80 | return kNotImplemented; |
| 81 | } |
| 82 | |
| 83 | bool AudioDecoder::PacketHasFec(const uint8_t* encoded, |
| 84 | size_t encoded_len) const { |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | CNG_dec_inst* AudioDecoder::CngDecoderInstance() { |
| 89 | FATAL() << "Not a CNG decoder"; |
| 90 | return NULL; |
| 91 | } |
| 92 | |
| 93 | AudioDecoder::SpeechType AudioDecoder::ConvertSpeechType(int16_t type) { |
| 94 | switch (type) { |
| 95 | case 0: // TODO(hlundin): Both iSAC and Opus return 0 for speech. |
| 96 | case 1: |
| 97 | return kSpeech; |
| 98 | case 2: |
| 99 | return kComfortNoise; |
| 100 | default: |
| 101 | assert(false); |
| 102 | return kSpeech; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | } // namespace webrtc |