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