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::EncodedAudioFrame { | |
kwiberg-webrtc
2016/09/15 12:00:59
final? Good both as documentation and because it s
ossu
2016/09/15 13:07:54
Acknowledged.
| |
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; | |
70 AudioDecoder::ParseResult::ParseResult(ParseResult&& b) = default; | |
71 AudioDecoder::ParseResult::ParseResult(uint32_t timestamp, | |
72 bool primary, | |
73 std::unique_ptr<EncodedAudioFrame> frame) | |
74 : timestamp(timestamp), primary(primary), frame(std::move(frame)) {} | |
75 | |
76 AudioDecoder::ParseResult::~ParseResult() = default; | |
77 | |
78 AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=( | |
79 ParseResult&& b) = default; | |
80 | |
81 std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload( | |
82 rtc::Buffer* payload, | |
83 uint32_t timestamp, | |
84 bool is_primary) { | |
85 std::vector<ParseResult> results; | |
86 std::unique_ptr<EncodedAudioFrame> frame( | |
87 new LegacyFrame(this, payload, is_primary)); | |
88 results.emplace_back(timestamp, is_primary, std::move(frame)); | |
89 return results; | |
90 } | |
91 | |
22 int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len, | 92 int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len, |
23 int sample_rate_hz, size_t max_decoded_bytes, | 93 int sample_rate_hz, size_t max_decoded_bytes, |
24 int16_t* decoded, SpeechType* speech_type) { | 94 int16_t* decoded, SpeechType* speech_type) { |
25 TRACE_EVENT0("webrtc", "AudioDecoder::Decode"); | 95 TRACE_EVENT0("webrtc", "AudioDecoder::Decode"); |
26 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); | 96 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); |
27 int duration = PacketDuration(encoded, encoded_len); | 97 int duration = PacketDuration(encoded, encoded_len); |
28 if (duration >= 0 && | 98 if (duration >= 0 && |
29 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { | 99 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { |
30 return -1; | 100 return -1; |
31 } | 101 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 return kSpeech; | 163 return kSpeech; |
94 case 2: | 164 case 2: |
95 return kComfortNoise; | 165 return kComfortNoise; |
96 default: | 166 default: |
97 assert(false); | 167 assert(false); |
98 return kSpeech; | 168 return kSpeech; |
99 } | 169 } |
100 } | 170 } |
101 | 171 |
102 } // namespace webrtc | 172 } // namespace webrtc |
OLD | NEW |