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