OLD | NEW |
---|---|
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 { | |
23 class LegacyFrame : public AudioDecoder::Frame { | |
24 public: | |
25 LegacyFrame(AudioDecoder* decoder, | |
26 rtc::Buffer* payload, | |
27 bool is_primary_payload) | |
28 : decoder_(decoder), is_primary_payload_(is_primary_payload) { | |
29 using std::swap; | |
hlundin-webrtc
2016/09/09 12:11:49
Why the using statement?
kwiberg-webrtc
2016/09/10 07:34:59
It's the standard idiom for swapping stuff. See e.
hlundin-webrtc
2016/09/12 08:07:11
Acknowledged.
| |
30 swap(this->payload_, *payload); | |
hlundin-webrtc
2016/09/09 12:11:49
#include what you use.
kwiberg-webrtc
2016/09/10 07:34:59
+1
ossu
2016/09/12 10:31:36
Acknowledged.
| |
31 } | |
kwiberg-webrtc
2016/09/10 07:34:59
Why not move *payload to payload_ instead of swapp
ossu
2016/09/12 10:31:36
Hmm. I was thinking of doing this to allow buffer
| |
32 | |
33 size_t Duration() const override { | |
34 int ret; | |
35 if (is_primary_payload_) { | |
36 ret = decoder_->PacketDuration(payload_.data(), payload_.size()); | |
37 } else { | |
38 ret = decoder_->PacketDurationRedundant(payload_.data(), | |
39 payload_.size()); | |
40 } | |
41 return (ret < 0) ? 0 : static_cast<size_t>(ret); | |
42 } | |
43 | |
44 rtc::Optional<DecodeResult> Decode( | |
45 rtc::ArrayView<int16_t> decoded) const override { | |
46 AudioDecoder::SpeechType speech_type = AudioDecoder::kSpeech; | |
47 int ret; | |
48 if (is_primary_payload_) { | |
49 ret = decoder_->Decode( | |
50 payload_.data(), payload_.size(), decoder_->SampleRateHz(), | |
51 decoded.size() * sizeof(int16_t), decoded.data(), &speech_type); | |
52 } else { | |
53 ret = decoder_->DecodeRedundant( | |
54 payload_.data(), payload_.size(), decoder_->SampleRateHz(), | |
55 decoded.size() * sizeof(int16_t), decoded.data(), &speech_type); | |
56 } | |
57 | |
58 if (ret < 0) | |
59 return rtc::Optional<DecodeResult>(); | |
60 | |
61 return rtc::Optional<DecodeResult>({static_cast<size_t>(ret), speech_type}); | |
62 } | |
63 | |
64 private: | |
65 AudioDecoder* decoder_; | |
hlundin-webrtc
2016/09/09 12:11:49
const
| |
66 rtc::Buffer payload_; | |
67 bool is_primary_payload_; | |
hlundin-webrtc
2016/09/09 12:11:49
const
kwiberg-webrtc
2016/09/10 07:34:59
All three could be const, right?
ossu
2016/09/12 10:31:36
Acknowledged.
| |
68 }; | |
69 } | |
70 | |
71 AudioDecoder::ParseResult::ParseResult() = default; | |
72 AudioDecoder::ParseResult::ParseResult(ParseResult&& b) = default; | |
73 AudioDecoder::ParseResult::ParseResult(uint32_t timestamp, | |
74 bool primary, | |
75 std::unique_ptr<Frame> frame) | |
76 : timestamp(timestamp), primary(primary), frame(std::move(frame)) {} | |
77 | |
78 AudioDecoder::ParseResult::~ParseResult() = default; | |
79 | |
80 AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=( | |
81 ParseResult&& b) = default; | |
82 | |
83 std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload( | |
84 rtc::Buffer* payload, | |
85 uint32_t timestamp, | |
86 bool is_primary) { | |
87 std::vector<ParseResult> results; | |
88 std::unique_ptr<Frame> frame( | |
89 new LegacyFrame(this, payload, is_primary)); | |
90 results.emplace_back(timestamp, is_primary, std::move(frame)); | |
91 return results; | |
92 } | |
93 | |
22 int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len, | 94 int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len, |
23 int sample_rate_hz, size_t max_decoded_bytes, | 95 int sample_rate_hz, size_t max_decoded_bytes, |
24 int16_t* decoded, SpeechType* speech_type) { | 96 int16_t* decoded, SpeechType* speech_type) { |
25 TRACE_EVENT0("webrtc", "AudioDecoder::Decode"); | 97 TRACE_EVENT0("webrtc", "AudioDecoder::Decode"); |
26 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); | 98 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); |
27 int duration = PacketDuration(encoded, encoded_len); | 99 int duration = PacketDuration(encoded, encoded_len); |
28 if (duration >= 0 && | 100 if (duration >= 0 && |
29 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { | 101 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { |
30 return -1; | 102 return -1; |
31 } | 103 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 return kSpeech; | 165 return kSpeech; |
94 case 2: | 166 case 2: |
95 return kComfortNoise; | 167 return kComfortNoise; |
96 default: | 168 default: |
97 assert(false); | 169 assert(false); |
98 return kSpeech; | 170 return kSpeech; |
99 } | 171 } |
100 } | 172 } |
101 | 173 |
102 } // namespace webrtc | 174 } // namespace webrtc |
OLD | NEW |