Chromium Code Reviews| 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/api/audio_codec/audio_decoder.h" |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
|
the sun
2017/02/02 21:02:29
We should use DCHECK here.
But perhaps it is bett
kwiberg-webrtc
2017/02/03 09:50:11
Yes, exactly. I'm (mostly) just moving this file,
| |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <utility> | 15 #include <utility> |
| 16 | 16 |
| 17 #include "webrtc/base/array_view.h" | 17 #include "webrtc/base/array_view.h" |
| 18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/sanitizer.h" | 19 #include "webrtc/base/sanitizer.h" |
| 20 #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" | |
| 22 | 21 |
| 23 namespace webrtc { | 22 namespace webrtc { |
| 24 | 23 |
| 24 namespace { | |
| 25 | |
| 26 class EncFrame final : public AudioDecoder::EncodedAudioFrame { | |
|
ossu
2017/02/01 15:05:26
Please pick a better name, even if it's just tempo
kwiberg-webrtc
2017/02/01 20:15:02
Will "EncodedFrame" do? That's what it is, and wha
ossu
2017/02/06 12:54:16
No, I don't think that expresses what this is, rea
kwiberg-webrtc
2017/02/06 14:19:36
OK, I'll pick a name like that. Maybe OldStyle* or
ossu
2017/02/06 14:44:06
Legacy might clash (at least mentally) with the ot
| |
| 27 public: | |
| 28 EncFrame(AudioDecoder* decoder, rtc::Buffer&& payload) | |
| 29 : decoder_(decoder), payload_(std::move(payload)) {} | |
| 30 | |
| 31 size_t Duration() const override { | |
| 32 const int ret = decoder_->PacketDuration(payload_.data(), payload_.size()); | |
| 33 return ret < 0 ? 0 : static_cast<size_t>(ret); | |
| 34 } | |
| 35 | |
| 36 rtc::Optional<DecodeResult> Decode( | |
| 37 rtc::ArrayView<int16_t> decoded) const override { | |
| 38 auto speech_type = AudioDecoder::kSpeech; | |
| 39 const int ret = decoder_->Decode( | |
| 40 payload_.data(), payload_.size(), decoder_->SampleRateHz(), | |
| 41 decoded.size() * sizeof(int16_t), decoded.data(), &speech_type); | |
| 42 return ret < 0 ? rtc::Optional<DecodeResult>() | |
| 43 : rtc::Optional<DecodeResult>( | |
| 44 {static_cast<size_t>(ret), speech_type}); | |
| 45 } | |
| 46 | |
| 47 private: | |
| 48 AudioDecoder* const decoder_; | |
|
the sun
2017/02/02 21:02:29
So does the decoder own all its frames, so they ar
kwiberg-webrtc
2017/02/03 09:50:11
The docs for ParsePayload, which returns these, sa
ossu
2017/02/06 12:54:16
I'd argue that is unreasonable to have a frame out
| |
| 49 const rtc::Buffer payload_; | |
| 50 }; | |
| 51 | |
| 52 } // namespace | |
| 53 | |
| 25 AudioDecoder::ParseResult::ParseResult() = default; | 54 AudioDecoder::ParseResult::ParseResult() = default; |
| 26 AudioDecoder::ParseResult::ParseResult(ParseResult&& b) = default; | 55 AudioDecoder::ParseResult::ParseResult(ParseResult&& b) = default; |
| 27 AudioDecoder::ParseResult::ParseResult(uint32_t timestamp, | 56 AudioDecoder::ParseResult::ParseResult(uint32_t timestamp, |
| 28 int priority, | 57 int priority, |
| 29 std::unique_ptr<EncodedAudioFrame> frame) | 58 std::unique_ptr<EncodedAudioFrame> frame) |
| 30 : timestamp(timestamp), priority(priority), frame(std::move(frame)) { | 59 : timestamp(timestamp), priority(priority), frame(std::move(frame)) { |
| 31 RTC_DCHECK_GE(priority, 0); | 60 RTC_DCHECK_GE(priority, 0); |
| 32 } | 61 } |
| 33 | 62 |
| 34 AudioDecoder::ParseResult::~ParseResult() = default; | 63 AudioDecoder::ParseResult::~ParseResult() = default; |
| 35 | 64 |
| 36 AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=( | 65 AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=( |
| 37 ParseResult&& b) = default; | 66 ParseResult&& b) = default; |
| 38 | 67 |
| 39 std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload( | 68 std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload( |
| 40 rtc::Buffer&& payload, | 69 rtc::Buffer&& payload, |
| 41 uint32_t timestamp) { | 70 uint32_t timestamp) { |
| 42 std::vector<ParseResult> results; | 71 std::vector<ParseResult> results; |
| 43 std::unique_ptr<EncodedAudioFrame> frame( | 72 std::unique_ptr<EncodedAudioFrame> frame( |
| 44 new LegacyEncodedAudioFrame(this, std::move(payload))); | 73 new EncFrame(this, std::move(payload))); |
| 45 results.emplace_back(timestamp, 0, std::move(frame)); | 74 results.emplace_back(timestamp, 0, std::move(frame)); |
| 46 return results; | 75 return results; |
| 47 } | 76 } |
| 48 | 77 |
| 49 int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len, | 78 int AudioDecoder::Decode(const uint8_t* encoded, |
| 50 int sample_rate_hz, size_t max_decoded_bytes, | 79 size_t encoded_len, |
| 51 int16_t* decoded, SpeechType* speech_type) { | 80 int sample_rate_hz, |
| 81 size_t max_decoded_bytes, | |
| 82 int16_t* decoded, | |
| 83 SpeechType* speech_type) { | |
| 52 TRACE_EVENT0("webrtc", "AudioDecoder::Decode"); | 84 TRACE_EVENT0("webrtc", "AudioDecoder::Decode"); |
| 53 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); | 85 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); |
| 54 int duration = PacketDuration(encoded, encoded_len); | 86 int duration = PacketDuration(encoded, encoded_len); |
| 55 if (duration >= 0 && | 87 if (duration >= 0 && |
| 56 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { | 88 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { |
| 57 return -1; | 89 return -1; |
| 58 } | 90 } |
| 59 return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded, | 91 return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded, |
| 60 speech_type); | 92 speech_type); |
| 61 } | 93 } |
| 62 | 94 |
| 63 int AudioDecoder::DecodeRedundant(const uint8_t* encoded, size_t encoded_len, | 95 int AudioDecoder::DecodeRedundant(const uint8_t* encoded, |
| 64 int sample_rate_hz, size_t max_decoded_bytes, | 96 size_t encoded_len, |
| 65 int16_t* decoded, SpeechType* speech_type) { | 97 int sample_rate_hz, |
| 98 size_t max_decoded_bytes, | |
| 99 int16_t* decoded, | |
| 100 SpeechType* speech_type) { | |
| 66 TRACE_EVENT0("webrtc", "AudioDecoder::DecodeRedundant"); | 101 TRACE_EVENT0("webrtc", "AudioDecoder::DecodeRedundant"); |
| 67 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); | 102 rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); |
| 68 int duration = PacketDurationRedundant(encoded, encoded_len); | 103 int duration = PacketDurationRedundant(encoded, encoded_len); |
| 69 if (duration >= 0 && | 104 if (duration >= 0 && |
| 70 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { | 105 duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { |
| 71 return -1; | 106 return -1; |
| 72 } | 107 } |
| 73 return DecodeRedundantInternal(encoded, encoded_len, sample_rate_hz, decoded, | 108 return DecodeRedundantInternal(encoded, encoded_len, sample_rate_hz, decoded, |
| 74 speech_type); | 109 speech_type); |
| 75 } | 110 } |
| 76 | 111 |
| 77 int AudioDecoder::DecodeRedundantInternal(const uint8_t* encoded, | 112 int AudioDecoder::DecodeRedundantInternal(const uint8_t* encoded, |
| 78 size_t encoded_len, | 113 size_t encoded_len, |
| 79 int sample_rate_hz, int16_t* decoded, | 114 int sample_rate_hz, |
| 115 int16_t* decoded, | |
| 80 SpeechType* speech_type) { | 116 SpeechType* speech_type) { |
| 81 return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded, | 117 return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded, |
| 82 speech_type); | 118 speech_type); |
| 83 } | 119 } |
| 84 | 120 |
| 85 bool AudioDecoder::HasDecodePlc() const { return false; } | 121 bool AudioDecoder::HasDecodePlc() const { |
| 122 return false; | |
| 123 } | |
| 86 | 124 |
| 87 size_t AudioDecoder::DecodePlc(size_t num_frames, int16_t* decoded) { | 125 size_t AudioDecoder::DecodePlc(size_t num_frames, int16_t* decoded) { |
| 88 return 0; | 126 return 0; |
| 89 } | 127 } |
| 90 | 128 |
| 91 int AudioDecoder::IncomingPacket(const uint8_t* payload, | 129 int AudioDecoder::IncomingPacket(const uint8_t* payload, |
| 92 size_t payload_len, | 130 size_t payload_len, |
| 93 uint16_t rtp_sequence_number, | 131 uint16_t rtp_sequence_number, |
| 94 uint32_t rtp_timestamp, | 132 uint32_t rtp_timestamp, |
| 95 uint32_t arrival_timestamp) { | 133 uint32_t arrival_timestamp) { |
| 96 return 0; | 134 return 0; |
|
the sun
2017/02/02 21:02:29
Remove as many default implementations of overrida
kwiberg-webrtc
2017/02/03 09:50:11
I agree. But not in this CL.
| |
| 97 } | 135 } |
| 98 | 136 |
| 99 int AudioDecoder::ErrorCode() { return 0; } | 137 int AudioDecoder::ErrorCode() { |
| 138 return 0; | |
| 139 } | |
| 100 | 140 |
| 101 int AudioDecoder::PacketDuration(const uint8_t* encoded, | 141 int AudioDecoder::PacketDuration(const uint8_t* encoded, |
| 102 size_t encoded_len) const { | 142 size_t encoded_len) const { |
| 103 return kNotImplemented; | 143 return kNotImplemented; |
| 104 } | 144 } |
| 105 | 145 |
| 106 int AudioDecoder::PacketDurationRedundant(const uint8_t* encoded, | 146 int AudioDecoder::PacketDurationRedundant(const uint8_t* encoded, |
| 107 size_t encoded_len) const { | 147 size_t encoded_len) const { |
| 108 return kNotImplemented; | 148 return kNotImplemented; |
| 109 } | 149 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 120 return kSpeech; | 160 return kSpeech; |
| 121 case 2: | 161 case 2: |
| 122 return kComfortNoise; | 162 return kComfortNoise; |
| 123 default: | 163 default: |
| 124 assert(false); | 164 assert(false); |
| 125 return kSpeech; | 165 return kSpeech; |
| 126 } | 166 } |
| 127 } | 167 } |
| 128 | 168 |
| 129 } // namespace webrtc | 169 } // namespace webrtc |
| OLD | NEW |