| 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/ilbc/audio_decoder_ilbc.h" | 11 #include "webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.h" |
| 12 | 12 |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
| 17 #include "webrtc/modules/audio_coding/codecs/ilbc/ilbc.h" | 17 #include "webrtc/modules/audio_coding/codecs/ilbc/ilbc.h" |
| 18 #include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h" | 18 #include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h" |
| 19 | 19 |
| 20 namespace webrtc { | 20 namespace webrtc { |
| 21 | 21 |
| 22 AudioDecoderIlbc::AudioDecoderIlbc() { | 22 AudioDecoderIlbcImpl::AudioDecoderIlbcImpl() { |
| 23 WebRtcIlbcfix_DecoderCreate(&dec_state_); | 23 WebRtcIlbcfix_DecoderCreate(&dec_state_); |
| 24 WebRtcIlbcfix_Decoderinit30Ms(dec_state_); | 24 WebRtcIlbcfix_Decoderinit30Ms(dec_state_); |
| 25 } | 25 } |
| 26 | 26 |
| 27 AudioDecoderIlbc::~AudioDecoderIlbc() { | 27 AudioDecoderIlbcImpl::~AudioDecoderIlbcImpl() { |
| 28 WebRtcIlbcfix_DecoderFree(dec_state_); | 28 WebRtcIlbcfix_DecoderFree(dec_state_); |
| 29 } | 29 } |
| 30 | 30 |
| 31 bool AudioDecoderIlbc::HasDecodePlc() const { | 31 bool AudioDecoderIlbcImpl::HasDecodePlc() const { |
| 32 return true; | 32 return true; |
| 33 } | 33 } |
| 34 | 34 |
| 35 int AudioDecoderIlbc::DecodeInternal(const uint8_t* encoded, | 35 int AudioDecoderIlbcImpl::DecodeInternal(const uint8_t* encoded, |
| 36 size_t encoded_len, | 36 size_t encoded_len, |
| 37 int sample_rate_hz, | 37 int sample_rate_hz, |
| 38 int16_t* decoded, | 38 int16_t* decoded, |
| 39 SpeechType* speech_type) { | 39 SpeechType* speech_type) { |
| 40 RTC_DCHECK_EQ(sample_rate_hz, 8000); | 40 RTC_DCHECK_EQ(sample_rate_hz, 8000); |
| 41 int16_t temp_type = 1; // Default is speech. | 41 int16_t temp_type = 1; // Default is speech. |
| 42 int ret = WebRtcIlbcfix_Decode(dec_state_, encoded, encoded_len, decoded, | 42 int ret = WebRtcIlbcfix_Decode(dec_state_, encoded, encoded_len, decoded, |
| 43 &temp_type); | 43 &temp_type); |
| 44 *speech_type = ConvertSpeechType(temp_type); | 44 *speech_type = ConvertSpeechType(temp_type); |
| 45 return ret; | 45 return ret; |
| 46 } | 46 } |
| 47 | 47 |
| 48 size_t AudioDecoderIlbc::DecodePlc(size_t num_frames, int16_t* decoded) { | 48 size_t AudioDecoderIlbcImpl::DecodePlc(size_t num_frames, int16_t* decoded) { |
| 49 return WebRtcIlbcfix_NetEqPlc(dec_state_, decoded, num_frames); | 49 return WebRtcIlbcfix_NetEqPlc(dec_state_, decoded, num_frames); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void AudioDecoderIlbc::Reset() { | 52 void AudioDecoderIlbcImpl::Reset() { |
| 53 WebRtcIlbcfix_Decoderinit30Ms(dec_state_); | 53 WebRtcIlbcfix_Decoderinit30Ms(dec_state_); |
| 54 } | 54 } |
| 55 | 55 |
| 56 std::vector<AudioDecoder::ParseResult> AudioDecoderIlbc::ParsePayload( | 56 std::vector<AudioDecoder::ParseResult> AudioDecoderIlbcImpl::ParsePayload( |
| 57 rtc::Buffer&& payload, | 57 rtc::Buffer&& payload, |
| 58 uint32_t timestamp) { | 58 uint32_t timestamp) { |
| 59 std::vector<ParseResult> results; | 59 std::vector<ParseResult> results; |
| 60 size_t bytes_per_frame; | 60 size_t bytes_per_frame; |
| 61 int timestamps_per_frame; | 61 int timestamps_per_frame; |
| 62 if (payload.size() >= 950) { | 62 if (payload.size() >= 950) { |
| 63 LOG(LS_WARNING) << "AudioDecoderIlbc::ParsePayload: Payload too large"; | 63 LOG(LS_WARNING) << "AudioDecoderIlbcImpl::ParsePayload: Payload too large"; |
| 64 return results; | 64 return results; |
| 65 } | 65 } |
| 66 if (payload.size() % 38 == 0) { | 66 if (payload.size() % 38 == 0) { |
| 67 // 20 ms frames. | 67 // 20 ms frames. |
| 68 bytes_per_frame = 38; | 68 bytes_per_frame = 38; |
| 69 timestamps_per_frame = 160; | 69 timestamps_per_frame = 160; |
| 70 } else if (payload.size() % 50 == 0) { | 70 } else if (payload.size() % 50 == 0) { |
| 71 // 30 ms frames. | 71 // 30 ms frames. |
| 72 bytes_per_frame = 50; | 72 bytes_per_frame = 50; |
| 73 timestamps_per_frame = 240; | 73 timestamps_per_frame = 240; |
| 74 } else { | 74 } else { |
| 75 LOG(LS_WARNING) << "AudioDecoderIlbc::ParsePayload: Invalid payload"; | 75 LOG(LS_WARNING) << "AudioDecoderIlbcImpl::ParsePayload: Invalid payload"; |
| 76 return results; | 76 return results; |
| 77 } | 77 } |
| 78 | 78 |
| 79 RTC_DCHECK_EQ(0, payload.size() % bytes_per_frame); | 79 RTC_DCHECK_EQ(0, payload.size() % bytes_per_frame); |
| 80 if (payload.size() == bytes_per_frame) { | 80 if (payload.size() == bytes_per_frame) { |
| 81 std::unique_ptr<EncodedAudioFrame> frame( | 81 std::unique_ptr<EncodedAudioFrame> frame( |
| 82 new LegacyEncodedAudioFrame(this, std::move(payload))); | 82 new LegacyEncodedAudioFrame(this, std::move(payload))); |
| 83 results.emplace_back(timestamp, 0, std::move(frame)); | 83 results.emplace_back(timestamp, 0, std::move(frame)); |
| 84 } else { | 84 } else { |
| 85 size_t byte_offset; | 85 size_t byte_offset; |
| 86 uint32_t timestamp_offset; | 86 uint32_t timestamp_offset; |
| 87 for (byte_offset = 0, timestamp_offset = 0; | 87 for (byte_offset = 0, timestamp_offset = 0; |
| 88 byte_offset < payload.size(); | 88 byte_offset < payload.size(); |
| 89 byte_offset += bytes_per_frame, | 89 byte_offset += bytes_per_frame, |
| 90 timestamp_offset += timestamps_per_frame) { | 90 timestamp_offset += timestamps_per_frame) { |
| 91 std::unique_ptr<EncodedAudioFrame> frame(new LegacyEncodedAudioFrame( | 91 std::unique_ptr<EncodedAudioFrame> frame(new LegacyEncodedAudioFrame( |
| 92 this, rtc::Buffer(payload.data() + byte_offset, bytes_per_frame))); | 92 this, rtc::Buffer(payload.data() + byte_offset, bytes_per_frame))); |
| 93 results.emplace_back(timestamp + timestamp_offset, 0, std::move(frame)); | 93 results.emplace_back(timestamp + timestamp_offset, 0, std::move(frame)); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 return results; | 97 return results; |
| 98 } | 98 } |
| 99 | 99 |
| 100 int AudioDecoderIlbc::SampleRateHz() const { | 100 int AudioDecoderIlbcImpl::SampleRateHz() const { |
| 101 return 8000; | 101 return 8000; |
| 102 } | 102 } |
| 103 | 103 |
| 104 size_t AudioDecoderIlbc::Channels() const { | 104 size_t AudioDecoderIlbcImpl::Channels() const { |
| 105 return 1; | 105 return 1; |
| 106 } | 106 } |
| 107 | 107 |
| 108 } // namespace webrtc | 108 } // namespace webrtc |
| OLD | NEW |