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

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: Reworked packet splitting. Renamed SplitBySamples and AudioCodingUtils. 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 #include <memory>
15 #include <utility>
14 16
15 #include "webrtc/base/array_view.h" 17 #include "webrtc/base/array_view.h"
16 #include "webrtc/base/checks.h" 18 #include "webrtc/base/checks.h"
17 #include "webrtc/base/sanitizer.h" 19 #include "webrtc/base/sanitizer.h"
18 #include "webrtc/base/trace_event.h" 20 #include "webrtc/base/trace_event.h"
21 #include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h"
19 22
20 namespace webrtc { 23 namespace webrtc {
21 24
22 namespace {
23 class LegacyFrame : public AudioDecoder::EncodedAudioFrame {
24 public:
25 LegacyFrame(AudioDecoder* decoder,
26 rtc::Buffer* payload,
27 bool is_primary_payload)
28 : decoder_(decoder),
29 payload_(std::move(*payload)),
30 is_primary_payload_(is_primary_payload) {}
31
32 size_t Duration() const override {
33 int ret;
34 if (is_primary_payload_) {
35 ret = decoder_->PacketDuration(payload_.data(), payload_.size());
36 } else {
37 ret = decoder_->PacketDurationRedundant(payload_.data(), payload_.size());
38 }
39 return (ret < 0) ? 0 : static_cast<size_t>(ret);
40 }
41
42 rtc::Optional<DecodeResult> Decode(
43 rtc::ArrayView<int16_t> decoded) const override {
44 AudioDecoder::SpeechType speech_type = AudioDecoder::kSpeech;
45 int ret;
46 if (is_primary_payload_) {
47 ret = decoder_->Decode(
48 payload_.data(), payload_.size(), decoder_->SampleRateHz(),
49 decoded.size() * sizeof(int16_t), decoded.data(), &speech_type);
50 } else {
51 ret = decoder_->DecodeRedundant(
52 payload_.data(), payload_.size(), decoder_->SampleRateHz(),
53 decoded.size() * sizeof(int16_t), decoded.data(), &speech_type);
54 }
55
56 if (ret < 0)
57 return rtc::Optional<DecodeResult>();
58
59 return rtc::Optional<DecodeResult>({static_cast<size_t>(ret), speech_type});
60 }
61
62 private:
63 AudioDecoder* const decoder_;
64 const rtc::Buffer payload_;
65 const bool is_primary_payload_;
66 };
67 }
68
69 AudioDecoder::ParseResult::ParseResult() = default; 25 AudioDecoder::ParseResult::ParseResult() = default;
70 AudioDecoder::ParseResult::ParseResult(ParseResult&& b) = default; 26 AudioDecoder::ParseResult::ParseResult(ParseResult&& b) = default;
71 AudioDecoder::ParseResult::ParseResult(uint32_t timestamp, 27 AudioDecoder::ParseResult::ParseResult(uint32_t timestamp,
72 bool primary, 28 bool primary,
73 std::unique_ptr<EncodedAudioFrame> frame) 29 std::unique_ptr<EncodedAudioFrame> frame)
74 : timestamp(timestamp), primary(primary), frame(std::move(frame)) {} 30 : timestamp(timestamp), primary(primary), frame(std::move(frame)) {}
75 31
76 AudioDecoder::ParseResult::~ParseResult() = default; 32 AudioDecoder::ParseResult::~ParseResult() = default;
77 33
78 AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=( 34 AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=(
79 ParseResult&& b) = default; 35 ParseResult&& b) = default;
80 36
81 std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload( 37 std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload(
82 rtc::Buffer* payload, 38 rtc::Buffer* payload,
83 uint32_t timestamp, 39 uint32_t timestamp,
84 bool is_primary) { 40 bool is_primary) {
85 std::vector<ParseResult> results; 41 std::vector<ParseResult> results;
86 std::unique_ptr<EncodedAudioFrame> frame( 42 std::unique_ptr<EncodedAudioFrame> frame(
87 new LegacyFrame(this, payload, is_primary)); 43 new LegacyEncodedAudioFrame(this, payload, is_primary));
88 results.emplace_back(timestamp, is_primary, std::move(frame)); 44 results.emplace_back(timestamp, is_primary, std::move(frame));
89 return results; 45 return results;
kwiberg-webrtc 2016/09/15 13:01:24 Won't a construction along these lines work? st
ossu 2016/09/15 14:41:05 Ideally that _should_ work but I can't get it to.
kwiberg-webrtc 2016/09/16 00:48:07 No, they're allowed now. Could it be that we're us
90 } 46 }
91 47
92 int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len, 48 int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len,
93 int sample_rate_hz, size_t max_decoded_bytes, 49 int sample_rate_hz, size_t max_decoded_bytes,
94 int16_t* decoded, SpeechType* speech_type) { 50 int16_t* decoded, SpeechType* speech_type) {
95 TRACE_EVENT0("webrtc", "AudioDecoder::Decode"); 51 TRACE_EVENT0("webrtc", "AudioDecoder::Decode");
96 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); 52 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len));
97 int duration = PacketDuration(encoded, encoded_len); 53 int duration = PacketDuration(encoded, encoded_len);
98 if (duration >= 0 && 54 if (duration >= 0 &&
99 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { 55 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 return kSpeech; 119 return kSpeech;
164 case 2: 120 case 2:
165 return kComfortNoise; 121 return kComfortNoise;
166 default: 122 default:
167 assert(false); 123 assert(false);
168 return kSpeech; 124 return kSpeech;
169 } 125 }
170 } 126 }
171 127
172 } // namespace webrtc 128 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698