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 size_t byte_offset; | 85 size_t byte_offset; |
85 uint32_t timestamp_offset; | 86 uint32_t timestamp_offset; |
86 for (byte_offset = 0, timestamp_offset = 0; | 87 for (byte_offset = 0, timestamp_offset = 0; |
87 byte_offset < payload.size(); | 88 byte_offset < payload.size(); |
88 byte_offset += bytes_per_frame, | 89 byte_offset += bytes_per_frame, |
89 timestamp_offset += timestamps_per_frame) { | 90 timestamp_offset += timestamps_per_frame) { |
90 rtc::Buffer new_payload(payload.data() + byte_offset, bytes_per_frame); | |
91 std::unique_ptr<EncodedAudioFrame> frame(new LegacyEncodedAudioFrame( | 91 std::unique_ptr<EncodedAudioFrame> frame(new LegacyEncodedAudioFrame( |
92 this, std::move(new_payload), is_primary)); | 92 this, rtc::Buffer(payload.data() + byte_offset, bytes_per_frame))); |
93 results.emplace_back(timestamp + timestamp_offset, is_primary, | 93 results.emplace_back(timestamp + timestamp_offset, 0, std::move(frame)); |
94 std::move(frame)); | |
95 } | 94 } |
96 } | 95 } |
97 | 96 |
98 return results; | 97 return results; |
99 } | 98 } |
100 | 99 |
101 int AudioDecoderIlbc::SampleRateHz() const { | 100 int AudioDecoderIlbc::SampleRateHz() const { |
102 return 8000; | 101 return 8000; |
103 } | 102 } |
104 | 103 |
105 size_t AudioDecoderIlbc::Channels() const { | 104 size_t AudioDecoderIlbc::Channels() const { |
106 return 1; | 105 return 1; |
107 } | 106 } |
108 | 107 |
109 } // namespace webrtc | 108 } // namespace webrtc |
OLD | NEW |