Chromium Code Reviews| 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> | |
| 14 | |
| 13 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" | 
| 14 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" | 
| 15 #include "webrtc/modules/audio_coding/codecs/ilbc/ilbc.h" | 17 #include "webrtc/modules/audio_coding/codecs/ilbc/ilbc.h" | 
| 16 #include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h" | 18 #include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h" | 
| 17 | 19 | 
| 18 namespace webrtc { | 20 namespace webrtc { | 
| 19 | 21 | 
| 20 AudioDecoderIlbc::AudioDecoderIlbc() { | 22 AudioDecoderIlbc::AudioDecoderIlbc() { | 
| 21 WebRtcIlbcfix_DecoderCreate(&dec_state_); | 23 WebRtcIlbcfix_DecoderCreate(&dec_state_); | 
| 22 WebRtcIlbcfix_Decoderinit30Ms(dec_state_); | 24 WebRtcIlbcfix_Decoderinit30Ms(dec_state_); | 
| (...skipping 23 matching lines...) Expand all Loading... | |
| 46 size_t AudioDecoderIlbc::DecodePlc(size_t num_frames, int16_t* decoded) { | 48 size_t AudioDecoderIlbc::DecodePlc(size_t num_frames, int16_t* decoded) { | 
| 47 return WebRtcIlbcfix_NetEqPlc(dec_state_, decoded, num_frames); | 49 return WebRtcIlbcfix_NetEqPlc(dec_state_, decoded, num_frames); | 
| 48 } | 50 } | 
| 49 | 51 | 
| 50 void AudioDecoderIlbc::Reset() { | 52 void AudioDecoderIlbc::Reset() { | 
| 51 WebRtcIlbcfix_Decoderinit30Ms(dec_state_); | 53 WebRtcIlbcfix_Decoderinit30Ms(dec_state_); | 
| 52 } | 54 } | 
| 53 | 55 | 
| 54 std::vector<AudioDecoder::ParseResult> AudioDecoderIlbc::ParsePayload( | 56 std::vector<AudioDecoder::ParseResult> AudioDecoderIlbc::ParsePayload( | 
| 55 rtc::Buffer&& payload, | 57 rtc::Buffer&& payload, | 
| 56 uint32_t timestamp, | 58 uint32_t timestamp) { | 
| 57 bool is_primary) { | |
| 58 std::vector<ParseResult> results; | 59 std::vector<ParseResult> results; | 
| 59 size_t bytes_per_frame; | 60 size_t bytes_per_frame; | 
| 60 int timestamps_per_frame; | 61 int timestamps_per_frame; | 
| 61 if (payload.size() >= 950) { | 62 if (payload.size() >= 950) { | 
| 62 LOG(LS_WARNING) << "AudioDecoderIlbc::ParsePayload: Payload too large"; | 63 LOG(LS_WARNING) << "AudioDecoderIlbc::ParsePayload: Payload too large"; | 
| 63 return results; | 64 return results; | 
| 64 } | 65 } | 
| 65 if (payload.size() % 38 == 0) { | 66 if (payload.size() % 38 == 0) { | 
| 66 // 20 ms frames. | 67 // 20 ms frames. | 
| 67 bytes_per_frame = 38; | 68 bytes_per_frame = 38; | 
| 68 timestamps_per_frame = 160; | 69 timestamps_per_frame = 160; | 
| 69 } else if (payload.size() % 50 == 0) { | 70 } else if (payload.size() % 50 == 0) { | 
| 70 // 30 ms frames. | 71 // 30 ms frames. | 
| 71 bytes_per_frame = 50; | 72 bytes_per_frame = 50; | 
| 72 timestamps_per_frame = 240; | 73 timestamps_per_frame = 240; | 
| 73 } else { | 74 } else { | 
| 74 LOG(LS_WARNING) << "AudioDecoderIlbc::ParsePayload: Invalid payload"; | 75 LOG(LS_WARNING) << "AudioDecoderIlbc::ParsePayload: Invalid payload"; | 
| 75 return results; | 76 return results; | 
| 76 } | 77 } | 
| 77 | 78 | 
| 78 RTC_DCHECK_EQ(0u, payload.size() % bytes_per_frame); | 79 RTC_DCHECK_EQ(0u, payload.size() % bytes_per_frame); | 
| 79 if (payload.size() == bytes_per_frame) { | 80 if (payload.size() == bytes_per_frame) { | 
| 80 std::unique_ptr<EncodedAudioFrame> frame( | 81 std::unique_ptr<EncodedAudioFrame> frame( | 
| 81 new LegacyEncodedAudioFrame(this, std::move(payload), is_primary)); | 82 new LegacyEncodedAudioFrame(this, std::move(payload))); | 
| 82 results.emplace_back(timestamp, is_primary, std::move(frame)); | 83 results.emplace_back(timestamp, 0, std::move(frame)); | 
| 83 } else { | 84 } else { | 
| 84 for (size_t byte_offset = 0, timestamp_offset = 0; | 85 for (size_t byte_offset = 0, timestamp_offset = 0; | 
| 85 byte_offset < payload.size(); | 86 byte_offset < payload.size(); | 
| 86 byte_offset += bytes_per_frame, | 87 byte_offset += bytes_per_frame, | 
| 87 timestamp_offset += timestamps_per_frame) { | 88 timestamp_offset += timestamps_per_frame) { | 
| 88 rtc::Buffer new_payload(payload.data() + byte_offset, bytes_per_frame); | 89 rtc::Buffer new_payload(payload.data() + byte_offset, bytes_per_frame); | 
| 89 std::unique_ptr<EncodedAudioFrame> frame(new LegacyEncodedAudioFrame( | 90 std::unique_ptr<EncodedAudioFrame> frame( | 
| 90 this, std::move(new_payload), is_primary)); | 91 new LegacyEncodedAudioFrame(this, std::move(new_payload))); | 
| 
 
kwiberg-webrtc
2016/09/20 09:14:45
Arguably, new_payload doesn't have to be a named v
 
ossu
2016/09/20 13:51:56
Acknowledged.
 
 | |
| 91 results.emplace_back(timestamp + timestamp_offset, is_primary, | 92 results.emplace_back(timestamp + timestamp_offset, 0, std::move(frame)); | 
| 92 std::move(frame)); | |
| 93 } | 93 } | 
| 94 } | 94 } | 
| 95 | 95 | 
| 96 return results; | 96 return results; | 
| 97 } | 97 } | 
| 98 | 98 | 
| 99 int AudioDecoderIlbc::SampleRateHz() const { | 99 int AudioDecoderIlbc::SampleRateHz() const { | 
| 100 return 8000; | 100 return 8000; | 
| 101 } | 101 } | 
| 102 | 102 | 
| 103 size_t AudioDecoderIlbc::Channels() const { | 103 size_t AudioDecoderIlbc::Channels() const { | 
| 104 return 1; | 104 return 1; | 
| 105 } | 105 } | 
| 106 | 106 | 
| 107 } // namespace webrtc | 107 } // namespace webrtc | 
| OLD | NEW |