Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.cc

Issue 2326003002: Moved codec-specific audio packet splitting into decoders. (Closed)
Patch Set: Fixed types in packet splitting (size_t vs. uint32_t) Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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::ParsePayload: Payload too large";
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::ParsePayload: Invalid payload";
75 return results;
76 }
77
78 RTC_DCHECK_EQ(0u, payload.size() % bytes_per_frame);
79 if (payload.size() == bytes_per_frame) {
80 std::unique_ptr<EncodedAudioFrame> frame(
81 new LegacyEncodedAudioFrame(this, std::move(payload), is_primary));
82 results.emplace_back(timestamp, is_primary, std::move(frame));
83 } else {
84 size_t byte_offset;
85 uint32_t timestamp_offset;
86 for (byte_offset = 0, timestamp_offset = 0;
87 byte_offset < payload.size();
88 byte_offset += bytes_per_frame,
89 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(
92 this, std::move(new_payload), is_primary));
93 results.emplace_back(timestamp + timestamp_offset, is_primary,
94 std::move(frame));
95 }
96 }
97
98 return results;
99 }
100
52 int AudioDecoderIlbc::SampleRateHz() const { 101 int AudioDecoderIlbc::SampleRateHz() const {
53 return 8000; 102 return 8000;
54 } 103 }
55 104
56 size_t AudioDecoderIlbc::Channels() const { 105 size_t AudioDecoderIlbc::Channels() const {
57 return 1; 106 return 1;
58 } 107 }
59 108
60 } // namespace webrtc 109 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.h ('k') | webrtc/modules/audio_coding/codecs/ilbc/ilbc_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698