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

Side by Side Diff: webrtc/modules/audio_coding/codecs/audio_decoder.cc

Issue 2326003002: Moved codec-specific audio packet splitting into decoders. (Closed)
Patch Set: 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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/audio_decoder.h" 11 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 14
15 #include "webrtc/base/array_view.h" 15 #include "webrtc/base/array_view.h"
16 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/base/sanitizer.h" 17 #include "webrtc/base/sanitizer.h"
18 #include "webrtc/base/trace_event.h" 18 #include "webrtc/base/trace_event.h"
19 19
20 namespace webrtc { 20 namespace webrtc {
21 21
22 namespace { 22 namespace {
23 class LegacyFrame : public AudioDecoder::Frame { 23 class LegacyFrame : public AudioDecoder::Frame {
24 public: 24 public:
25 LegacyFrame(AudioDecoder* decoder, 25 LegacyFrame(AudioDecoder* decoder,
26 rtc::Buffer* payload, 26 rtc::Buffer&& payload,
27 bool is_primary_payload) 27 bool is_primary_payload)
28 : decoder_(decoder), is_primary_payload_(is_primary_payload) { 28 : decoder_(decoder), is_primary_payload_(is_primary_payload) {
29 using std::swap; 29 using std::swap;
30 swap(this->payload_, *payload); 30 swap(this->payload_, payload);
31 } 31 }
32 32
33 size_t Duration() const override { 33 size_t Duration() const override {
34 int ret; 34 int ret;
35 if (is_primary_payload_) { 35 if (is_primary_payload_) {
36 ret = decoder_->PacketDuration(payload_.data(), payload_.size()); 36 ret = decoder_->PacketDuration(payload_.data(), payload_.size());
37 } else { 37 } else {
38 ret = decoder_->PacketDurationRedundant(payload_.data(), 38 ret = decoder_->PacketDurationRedundant(payload_.data(),
39 payload_.size()); 39 payload_.size());
40 } 40 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 AudioDecoder::ParseResult::~ParseResult() = default; 78 AudioDecoder::ParseResult::~ParseResult() = default;
79 79
80 AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=( 80 AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=(
81 ParseResult&& b) = default; 81 ParseResult&& b) = default;
82 82
83 std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload( 83 std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload(
84 rtc::Buffer* payload, 84 rtc::Buffer* payload,
85 uint32_t timestamp, 85 uint32_t timestamp,
86 bool is_primary) { 86 bool is_primary) {
87 std::vector<ParseResult> results; 87 std::vector<ParseResult> results;
88 std::unique_ptr<Frame> frame( 88 std::vector<PacketSplit> splits = SplitPacket(*payload);
89 new LegacyFrame(this, payload, is_primary)); 89
90 results.emplace_back(timestamp, is_primary, std::move(frame)); 90 // Just take the payload if we don't have to split.
91 if (splits.size() == 1 &&
92 splits[0].byte_offset == 0 &&
93 splits[0].num_bytes == payload->size() &&
94 splits[0].timestamp_offset == 0) {
95 std::unique_ptr<Frame> frame(
96 new LegacyFrame(this, std::move(*payload), is_primary));
97 results.emplace_back(timestamp + splits[0].timestamp_offset, is_primary,
98 std::move(frame));
99 } else {
100 for (const auto& split : splits) {
101 RTC_CHECK(split.byte_offset + split.num_bytes <= payload->size());
hlundin-webrtc 2016/09/09 12:52:52 RTC_CHECK_LE
ossu 2016/09/12 11:26:37 Acknowledged.
102 rtc::Buffer new_payload(payload->data() + split.byte_offset,
103 split.num_bytes);
104 std::unique_ptr<Frame> frame(
105 new LegacyFrame(this, std::move(new_payload), is_primary));
106 results.emplace_back(timestamp + split.timestamp_offset, is_primary,
107 std::move(frame));
108 }
109 }
kwiberg-webrtc 2016/09/12 02:11:01 If you processed the pieces in the reverse order,
ossu 2016/09/12 11:26:37 It doesn't really matter which of the packets get
kwiberg-webrtc 2016/09/13 12:23:37 Well, if the first one gets it, you won't have to
110
91 return results; 111 return results;
92 } 112 }
93 113
94 int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len, 114 int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len,
95 int sample_rate_hz, size_t max_decoded_bytes, 115 int sample_rate_hz, size_t max_decoded_bytes,
96 int16_t* decoded, SpeechType* speech_type) { 116 int16_t* decoded, SpeechType* speech_type) {
97 TRACE_EVENT0("webrtc", "AudioDecoder::Decode"); 117 TRACE_EVENT0("webrtc", "AudioDecoder::Decode");
98 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); 118 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len));
99 int duration = PacketDuration(encoded, encoded_len); 119 int duration = PacketDuration(encoded, encoded_len);
100 if (duration >= 0 && 120 if (duration >= 0 &&
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 154 }
135 155
136 int AudioDecoder::IncomingPacket(const uint8_t* payload, 156 int AudioDecoder::IncomingPacket(const uint8_t* payload,
137 size_t payload_len, 157 size_t payload_len,
138 uint16_t rtp_sequence_number, 158 uint16_t rtp_sequence_number,
139 uint32_t rtp_timestamp, 159 uint32_t rtp_timestamp,
140 uint32_t arrival_timestamp) { 160 uint32_t arrival_timestamp) {
141 return 0; 161 return 0;
142 } 162 }
143 163
164 std::vector<AudioDecoder::PacketSplit> AudioDecoder::SplitPacket(
165 rtc::ArrayView<const uint8_t> payload) const {
166 return {PacketSplit{0, payload.size(), 0}};
167 }
168
144 int AudioDecoder::ErrorCode() { return 0; } 169 int AudioDecoder::ErrorCode() { return 0; }
145 170
146 int AudioDecoder::PacketDuration(const uint8_t* encoded, 171 int AudioDecoder::PacketDuration(const uint8_t* encoded,
147 size_t encoded_len) const { 172 size_t encoded_len) const {
148 return kNotImplemented; 173 return kNotImplemented;
149 } 174 }
150 175
151 int AudioDecoder::PacketDurationRedundant(const uint8_t* encoded, 176 int AudioDecoder::PacketDurationRedundant(const uint8_t* encoded,
152 size_t encoded_len) const { 177 size_t encoded_len) const {
153 return kNotImplemented; 178 return kNotImplemented;
(...skipping 11 matching lines...) Expand all
165 return kSpeech; 190 return kSpeech;
166 case 2: 191 case 2:
167 return kComfortNoise; 192 return kComfortNoise;
168 default: 193 default:
169 assert(false); 194 assert(false);
170 return kSpeech; 195 return kSpeech;
171 } 196 }
172 } 197 }
173 198
174 } // namespace webrtc 199 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698