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 #include <memory> |
| 15 #include <utility> |
14 | 16 |
15 #include <utility> | 17 #include <utility> |
16 | 18 |
17 #include "webrtc/base/array_view.h" | 19 #include "webrtc/base/array_view.h" |
18 #include "webrtc/base/checks.h" | 20 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/sanitizer.h" | 21 #include "webrtc/base/sanitizer.h" |
20 #include "webrtc/base/trace_event.h" | 22 #include "webrtc/base/trace_event.h" |
| 23 #include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h" |
21 | 24 |
22 namespace webrtc { | 25 namespace webrtc { |
23 | 26 |
24 namespace { | |
25 class LegacyFrame final : public AudioDecoder::EncodedAudioFrame { | |
26 public: | |
27 LegacyFrame(AudioDecoder* decoder, | |
28 rtc::Buffer&& payload, | |
29 bool is_primary_payload) | |
30 : decoder_(decoder), | |
31 payload_(std::move(payload)), | |
32 is_primary_payload_(is_primary_payload) {} | |
33 | |
34 size_t Duration() const override { | |
35 int ret; | |
36 if (is_primary_payload_) { | |
37 ret = decoder_->PacketDuration(payload_.data(), payload_.size()); | |
38 } else { | |
39 ret = decoder_->PacketDurationRedundant(payload_.data(), 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* const decoder_; | |
66 const rtc::Buffer payload_; | |
67 const bool is_primary_payload_; | |
68 }; | |
69 } // namespace | |
70 | |
71 AudioDecoder::ParseResult::ParseResult() = default; | 27 AudioDecoder::ParseResult::ParseResult() = default; |
72 AudioDecoder::ParseResult::ParseResult(ParseResult&& b) = default; | 28 AudioDecoder::ParseResult::ParseResult(ParseResult&& b) = default; |
73 AudioDecoder::ParseResult::ParseResult(uint32_t timestamp, | 29 AudioDecoder::ParseResult::ParseResult(uint32_t timestamp, |
74 bool primary, | 30 bool primary, |
75 std::unique_ptr<EncodedAudioFrame> frame) | 31 std::unique_ptr<EncodedAudioFrame> frame) |
76 : timestamp(timestamp), primary(primary), frame(std::move(frame)) {} | 32 : timestamp(timestamp), primary(primary), frame(std::move(frame)) {} |
77 | 33 |
78 AudioDecoder::ParseResult::~ParseResult() = default; | 34 AudioDecoder::ParseResult::~ParseResult() = default; |
79 | 35 |
80 AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=( | 36 AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=( |
81 ParseResult&& b) = default; | 37 ParseResult&& b) = default; |
82 | 38 |
83 std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload( | 39 std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload( |
84 rtc::Buffer&& payload, | 40 rtc::Buffer&& payload, |
85 uint32_t timestamp, | 41 uint32_t timestamp, |
86 bool is_primary) { | 42 bool is_primary) { |
87 std::vector<ParseResult> results; | 43 std::vector<ParseResult> results; |
88 std::unique_ptr<EncodedAudioFrame> frame( | 44 std::unique_ptr<EncodedAudioFrame> frame( |
89 new LegacyFrame(this, std::move(payload), is_primary)); | 45 new LegacyEncodedAudioFrame(this, std::move(payload), is_primary)); |
90 results.emplace_back(timestamp, is_primary, std::move(frame)); | 46 results.emplace_back(timestamp, is_primary, std::move(frame)); |
91 return results; | 47 return results; |
92 } | 48 } |
93 | 49 |
94 int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len, | 50 int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len, |
95 int sample_rate_hz, size_t max_decoded_bytes, | 51 int sample_rate_hz, size_t max_decoded_bytes, |
96 int16_t* decoded, SpeechType* speech_type) { | 52 int16_t* decoded, SpeechType* speech_type) { |
97 TRACE_EVENT0("webrtc", "AudioDecoder::Decode"); | 53 TRACE_EVENT0("webrtc", "AudioDecoder::Decode"); |
98 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); | 54 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); |
99 int duration = PacketDuration(encoded, encoded_len); | 55 int duration = PacketDuration(encoded, encoded_len); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 return kSpeech; | 121 return kSpeech; |
166 case 2: | 122 case 2: |
167 return kComfortNoise; | 123 return kComfortNoise; |
168 default: | 124 default: |
169 assert(false); | 125 assert(false); |
170 return kSpeech; | 126 return kSpeech; |
171 } | 127 } |
172 } | 128 } |
173 | 129 |
174 } // namespace webrtc | 130 } // namespace webrtc |
OLD | NEW |