| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/audio_coding/codecs/g722/audio_decoder_g722.h" | 11 #include "webrtc/modules/audio_coding/codecs/g722/audio_decoder_g722.h" |
| 12 | 12 |
| 13 #include <string.h> | 13 #include <string.h> |
| 14 | 14 |
| 15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h" | 16 #include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h" |
| 17 #include "webrtc/modules/audio_coding/codecs/g722/g722_interface.h" | 17 #include "webrtc/modules/audio_coding/codecs/g722/g722_interface.h" |
| 18 | 18 |
| 19 namespace webrtc { | 19 namespace webrtc { |
| 20 | 20 |
| 21 AudioDecoderG722::AudioDecoderG722() { | 21 AudioDecoderG722Impl::AudioDecoderG722Impl() { |
| 22 WebRtcG722_CreateDecoder(&dec_state_); | 22 WebRtcG722_CreateDecoder(&dec_state_); |
| 23 WebRtcG722_DecoderInit(dec_state_); | 23 WebRtcG722_DecoderInit(dec_state_); |
| 24 } | 24 } |
| 25 | 25 |
| 26 AudioDecoderG722::~AudioDecoderG722() { | 26 AudioDecoderG722Impl::~AudioDecoderG722Impl() { |
| 27 WebRtcG722_FreeDecoder(dec_state_); | 27 WebRtcG722_FreeDecoder(dec_state_); |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool AudioDecoderG722::HasDecodePlc() const { | 30 bool AudioDecoderG722Impl::HasDecodePlc() const { |
| 31 return false; | 31 return false; |
| 32 } | 32 } |
| 33 | 33 |
| 34 int AudioDecoderG722::DecodeInternal(const uint8_t* encoded, | 34 int AudioDecoderG722Impl::DecodeInternal(const uint8_t* encoded, |
| 35 size_t encoded_len, | 35 size_t encoded_len, |
| 36 int sample_rate_hz, | 36 int sample_rate_hz, |
| 37 int16_t* decoded, | 37 int16_t* decoded, |
| 38 SpeechType* speech_type) { | 38 SpeechType* speech_type) { |
| 39 RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz); | 39 RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz); |
| 40 int16_t temp_type = 1; // Default is speech. | 40 int16_t temp_type = 1; // Default is speech. |
| 41 size_t ret = | 41 size_t ret = |
| 42 WebRtcG722_Decode(dec_state_, encoded, encoded_len, decoded, &temp_type); | 42 WebRtcG722_Decode(dec_state_, encoded, encoded_len, decoded, &temp_type); |
| 43 *speech_type = ConvertSpeechType(temp_type); | 43 *speech_type = ConvertSpeechType(temp_type); |
| 44 return static_cast<int>(ret); | 44 return static_cast<int>(ret); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void AudioDecoderG722::Reset() { | 47 void AudioDecoderG722Impl::Reset() { |
| 48 WebRtcG722_DecoderInit(dec_state_); | 48 WebRtcG722_DecoderInit(dec_state_); |
| 49 } | 49 } |
| 50 | 50 |
| 51 std::vector<AudioDecoder::ParseResult> AudioDecoderG722::ParsePayload( | 51 std::vector<AudioDecoder::ParseResult> AudioDecoderG722Impl::ParsePayload( |
| 52 rtc::Buffer&& payload, | 52 rtc::Buffer&& payload, |
| 53 uint32_t timestamp) { | 53 uint32_t timestamp) { |
| 54 return LegacyEncodedAudioFrame::SplitBySamples(this, std::move(payload), | 54 return LegacyEncodedAudioFrame::SplitBySamples(this, std::move(payload), |
| 55 timestamp, 8, 16); | 55 timestamp, 8, 16); |
| 56 } | 56 } |
| 57 | 57 |
| 58 int AudioDecoderG722::PacketDuration(const uint8_t* encoded, | 58 int AudioDecoderG722Impl::PacketDuration(const uint8_t* encoded, |
| 59 size_t encoded_len) const { | 59 size_t encoded_len) const { |
| 60 // 1/2 encoded byte per sample per channel. | 60 // 1/2 encoded byte per sample per channel. |
| 61 return static_cast<int>(2 * encoded_len / Channels()); | 61 return static_cast<int>(2 * encoded_len / Channels()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 int AudioDecoderG722::SampleRateHz() const { | 64 int AudioDecoderG722Impl::SampleRateHz() const { |
| 65 return 16000; | 65 return 16000; |
| 66 } | 66 } |
| 67 | 67 |
| 68 size_t AudioDecoderG722::Channels() const { | 68 size_t AudioDecoderG722Impl::Channels() const { |
| 69 return 1; | 69 return 1; |
| 70 } | 70 } |
| 71 | 71 |
| 72 AudioDecoderG722Stereo::AudioDecoderG722Stereo() { | 72 AudioDecoderG722Stereo::AudioDecoderG722Stereo() { |
| 73 WebRtcG722_CreateDecoder(&dec_state_left_); | 73 WebRtcG722_CreateDecoder(&dec_state_left_); |
| 74 WebRtcG722_CreateDecoder(&dec_state_right_); | 74 WebRtcG722_CreateDecoder(&dec_state_right_); |
| 75 WebRtcG722_DecoderInit(dec_state_left_); | 75 WebRtcG722_DecoderInit(dec_state_left_); |
| 76 WebRtcG722_DecoderInit(dec_state_right_); | 76 WebRtcG722_DecoderInit(dec_state_right_); |
| 77 } | 77 } |
| 78 | 78 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // where N is the total number of samples. | 152 // where N is the total number of samples. |
| 153 for (size_t i = 0; i < encoded_len / 2; i++) { | 153 for (size_t i = 0; i < encoded_len / 2; i++) { |
| 154 uint8_t right_byte = encoded_deinterleaved[i + 1]; | 154 uint8_t right_byte = encoded_deinterleaved[i + 1]; |
| 155 memmove(&encoded_deinterleaved[i + 1], &encoded_deinterleaved[i + 2], | 155 memmove(&encoded_deinterleaved[i + 1], &encoded_deinterleaved[i + 2], |
| 156 encoded_len - i - 2); | 156 encoded_len - i - 2); |
| 157 encoded_deinterleaved[encoded_len - 1] = right_byte; | 157 encoded_deinterleaved[encoded_len - 1] = right_byte; |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 | 160 |
| 161 } // namespace webrtc | 161 } // namespace webrtc |
| OLD | NEW |