kwiberg | cf021e5 | 2015-09-22 13:16:51 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 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 | |
kjellander@webrtc.org | 9592d2a | 2015-11-18 22:07:57 | [diff] [blame] | 11 | #include "webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.h" |
kwiberg | cf021e5 | 2015-09-22 13:16:51 | [diff] [blame] | 12 | |
ossu | 59a0e9e | 2016-09-21 08:57:31 | [diff] [blame] | 13 | #include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h" |
kjellander@webrtc.org | 9592d2a | 2015-11-18 22:07:57 | [diff] [blame] | 14 | #include "webrtc/modules/audio_coding/codecs/g711/g711_interface.h" |
kwiberg | cf021e5 | 2015-09-22 13:16:51 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
| 17 | |
| 18 | void AudioDecoderPcmU::Reset() {} |
| 19 | |
ossu | 59a0e9e | 2016-09-21 08:57:31 | [diff] [blame] | 20 | std::vector<AudioDecoder::ParseResult> AudioDecoderPcmU::ParsePayload( |
| 21 | rtc::Buffer&& payload, |
ossu | 15d1e47 | 2016-09-22 09:06:28 | [diff] [blame] | 22 | uint32_t timestamp) { |
ossu | 59a0e9e | 2016-09-21 08:57:31 | [diff] [blame] | 23 | return LegacyEncodedAudioFrame::SplitBySamples( |
ossu | 15d1e47 | 2016-09-22 09:06:28 | [diff] [blame] | 24 | this, std::move(payload), timestamp, 8 * num_channels_, 8); |
ossu | 59a0e9e | 2016-09-21 08:57:31 | [diff] [blame] | 25 | } |
| 26 | |
kwiberg | 7a441a0 | 2016-05-31 09:46:20 | [diff] [blame] | 27 | int AudioDecoderPcmU::SampleRateHz() const { |
| 28 | return 8000; |
| 29 | } |
| 30 | |
kwiberg | cf021e5 | 2015-09-22 13:16:51 | [diff] [blame] | 31 | size_t AudioDecoderPcmU::Channels() const { |
kwiberg | 2027e77 | 2015-09-22 21:06:29 | [diff] [blame] | 32 | return num_channels_; |
kwiberg | cf021e5 | 2015-09-22 13:16:51 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | int AudioDecoderPcmU::DecodeInternal(const uint8_t* encoded, |
| 36 | size_t encoded_len, |
| 37 | int sample_rate_hz, |
| 38 | int16_t* decoded, |
| 39 | SpeechType* speech_type) { |
kwiberg | 7a441a0 | 2016-05-31 09:46:20 | [diff] [blame] | 40 | RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz); |
kwiberg | cf021e5 | 2015-09-22 13:16:51 | [diff] [blame] | 41 | int16_t temp_type = 1; // Default is speech. |
| 42 | size_t ret = WebRtcG711_DecodeU(encoded, encoded_len, decoded, &temp_type); |
| 43 | *speech_type = ConvertSpeechType(temp_type); |
| 44 | return static_cast<int>(ret); |
| 45 | } |
| 46 | |
| 47 | int AudioDecoderPcmU::PacketDuration(const uint8_t* encoded, |
| 48 | size_t encoded_len) const { |
| 49 | // One encoded byte per sample per channel. |
| 50 | return static_cast<int>(encoded_len / Channels()); |
| 51 | } |
| 52 | |
kwiberg | cf021e5 | 2015-09-22 13:16:51 | [diff] [blame] | 53 | void AudioDecoderPcmA::Reset() {} |
| 54 | |
ossu | 59a0e9e | 2016-09-21 08:57:31 | [diff] [blame] | 55 | std::vector<AudioDecoder::ParseResult> AudioDecoderPcmA::ParsePayload( |
| 56 | rtc::Buffer&& payload, |
ossu | 15d1e47 | 2016-09-22 09:06:28 | [diff] [blame] | 57 | uint32_t timestamp) { |
ossu | 59a0e9e | 2016-09-21 08:57:31 | [diff] [blame] | 58 | return LegacyEncodedAudioFrame::SplitBySamples( |
ossu | 15d1e47 | 2016-09-22 09:06:28 | [diff] [blame] | 59 | this, std::move(payload), timestamp, 8 * num_channels_, 8); |
ossu | 59a0e9e | 2016-09-21 08:57:31 | [diff] [blame] | 60 | } |
| 61 | |
kwiberg | 7a441a0 | 2016-05-31 09:46:20 | [diff] [blame] | 62 | int AudioDecoderPcmA::SampleRateHz() const { |
| 63 | return 8000; |
| 64 | } |
| 65 | |
kwiberg | cf021e5 | 2015-09-22 13:16:51 | [diff] [blame] | 66 | size_t AudioDecoderPcmA::Channels() const { |
kwiberg | 2027e77 | 2015-09-22 21:06:29 | [diff] [blame] | 67 | return num_channels_; |
kwiberg | cf021e5 | 2015-09-22 13:16:51 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | int AudioDecoderPcmA::DecodeInternal(const uint8_t* encoded, |
| 71 | size_t encoded_len, |
| 72 | int sample_rate_hz, |
| 73 | int16_t* decoded, |
| 74 | SpeechType* speech_type) { |
kwiberg | 7a441a0 | 2016-05-31 09:46:20 | [diff] [blame] | 75 | RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz); |
kwiberg | cf021e5 | 2015-09-22 13:16:51 | [diff] [blame] | 76 | int16_t temp_type = 1; // Default is speech. |
| 77 | size_t ret = WebRtcG711_DecodeA(encoded, encoded_len, decoded, &temp_type); |
| 78 | *speech_type = ConvertSpeechType(temp_type); |
| 79 | return static_cast<int>(ret); |
| 80 | } |
| 81 | |
| 82 | int AudioDecoderPcmA::PacketDuration(const uint8_t* encoded, |
| 83 | size_t encoded_len) const { |
| 84 | // One encoded byte per sample per channel. |
| 85 | return static_cast<int>(encoded_len / Channels()); |
| 86 | } |
| 87 | |
kwiberg | cf021e5 | 2015-09-22 13:16:51 | [diff] [blame] | 88 | } // namespace webrtc |