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 "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 #include "webrtc/base/logging.h" | |
14 #include "webrtc/modules/audio_coding/codecs/ilbc/ilbc.h" | 15 #include "webrtc/modules/audio_coding/codecs/ilbc/ilbc.h" |
16 #include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h" | |
15 | 17 |
16 namespace webrtc { | 18 namespace webrtc { |
17 | 19 |
18 AudioDecoderIlbc::AudioDecoderIlbc() { | 20 AudioDecoderIlbc::AudioDecoderIlbc() { |
19 WebRtcIlbcfix_DecoderCreate(&dec_state_); | 21 WebRtcIlbcfix_DecoderCreate(&dec_state_); |
20 WebRtcIlbcfix_Decoderinit30Ms(dec_state_); | 22 WebRtcIlbcfix_Decoderinit30Ms(dec_state_); |
21 } | 23 } |
22 | 24 |
23 AudioDecoderIlbc::~AudioDecoderIlbc() { | 25 AudioDecoderIlbc::~AudioDecoderIlbc() { |
24 WebRtcIlbcfix_DecoderFree(dec_state_); | 26 WebRtcIlbcfix_DecoderFree(dec_state_); |
(...skipping 17 matching lines...) Expand all Loading... | |
42 } | 44 } |
43 | 45 |
44 size_t AudioDecoderIlbc::DecodePlc(size_t num_frames, int16_t* decoded) { | 46 size_t AudioDecoderIlbc::DecodePlc(size_t num_frames, int16_t* decoded) { |
45 return WebRtcIlbcfix_NetEqPlc(dec_state_, decoded, num_frames); | 47 return WebRtcIlbcfix_NetEqPlc(dec_state_, decoded, num_frames); |
46 } | 48 } |
47 | 49 |
48 void AudioDecoderIlbc::Reset() { | 50 void AudioDecoderIlbc::Reset() { |
49 WebRtcIlbcfix_Decoderinit30Ms(dec_state_); | 51 WebRtcIlbcfix_Decoderinit30Ms(dec_state_); |
50 } | 52 } |
51 | 53 |
54 std::vector<AudioDecoder::ParseResult> AudioDecoderIlbc::ParsePayload( | |
55 rtc::Buffer* payload, | |
56 uint32_t timestamp, | |
57 bool is_primary) { | |
58 std::vector<ParseResult> results; | |
59 size_t bytes_per_frame; | |
60 int timestamps_per_frame; | |
61 if (payload->size() >= 950) { | |
62 LOG(LS_WARNING) << "AudioDecoderIlbc::SplitPacket: Payload too large"; | |
ossu
2016/09/13 14:25:55
This comment should say ParsePayload and not Split
| |
63 return results; | |
64 } | |
65 if (payload->size() % 38 == 0) { | |
66 // 20 ms frames. | |
67 bytes_per_frame = 38; | |
68 timestamps_per_frame = 160; | |
69 } else if (payload->size() % 50 == 0) { | |
70 // 30 ms frames. | |
71 bytes_per_frame = 50; | |
72 timestamps_per_frame = 240; | |
73 } else { | |
74 LOG(LS_WARNING) << "AudioDecoderIlbc::SplitPacket: Invalid payload"; | |
ossu
2016/09/13 14:25:55
This comment should say ParsePayload and not Split
| |
75 return results; | |
76 } | |
77 | |
78 RTC_DCHECK(payload->size() % bytes_per_frame == 0); | |
hlundin-webrtc
2016/09/15 08:49:14
RTC_DCHECK_EQ
ossu
2016/09/15 08:58:11
I did that initially, but the RTC_DHECK_EQ macro b
hlundin-webrtc
2016/09/15 09:43:38
I hate it when that happens, but I prefer the nice
kwiberg-webrtc
2016/09/15 13:01:25
+1. It's annoying, but since a "u" suffix will sol
| |
79 if (payload->size() == bytes_per_frame) { | |
80 std::unique_ptr<EncodedAudioFrame> frame( | |
81 new LegacyEncodedAudioFrame(this, payload, is_primary)); | |
82 results.emplace_back(timestamp, is_primary, std::move(frame)); | |
83 } else { | |
84 for (size_t byte_offset = 0, timestamp_offset = 0; | |
85 byte_offset < payload->size(); | |
86 byte_offset += bytes_per_frame, | |
87 timestamp_offset += timestamps_per_frame) { | |
88 rtc::Buffer new_payload(payload->data() + byte_offset, bytes_per_frame); | |
89 std::unique_ptr<EncodedAudioFrame> frame( | |
90 new LegacyEncodedAudioFrame(this, &new_payload, is_primary)); | |
91 results.emplace_back(timestamp + timestamp_offset, is_primary, | |
92 std::move(frame)); | |
93 } | |
94 } | |
95 | |
96 return results; | |
97 } | |
98 | |
52 int AudioDecoderIlbc::SampleRateHz() const { | 99 int AudioDecoderIlbc::SampleRateHz() const { |
53 return 8000; | 100 return 8000; |
54 } | 101 } |
55 | 102 |
56 size_t AudioDecoderIlbc::Channels() const { | 103 size_t AudioDecoderIlbc::Channels() const { |
57 return 1; | 104 return 1; |
58 } | 105 } |
59 | 106 |
60 } // namespace webrtc | 107 } // namespace webrtc |
OLD | NEW |