Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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/opus/audio_decoder_opus.h" | 11 #include "webrtc/modules/audio_coding/codecs/opus/audio_decoder_opus.h" |
| 12 | 12 |
| 13 #include <utility> | |
| 14 | |
| 13 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 14 | 16 |
| 15 namespace webrtc { | 17 namespace webrtc { |
| 16 | 18 |
| 19 namespace { | |
| 20 class OpusFrame : public AudioDecoder::EncodedAudioFrame { | |
| 21 public: | |
| 22 OpusFrame(AudioDecoderOpus* decoder, | |
| 23 rtc::Buffer&& payload, | |
| 24 bool is_primary_payload) | |
| 25 : decoder_(decoder), is_primary_payload_(is_primary_payload) { | |
| 26 using std::swap; | |
| 27 swap(this->payload_, payload); | |
|
hlundin-webrtc
2016/09/15 09:33:30
std::move?
ossu
2016/09/15 12:22:53
Acknowledged.
| |
| 28 } | |
| 29 | |
| 30 size_t Duration() const override { | |
| 31 int ret; | |
| 32 if (is_primary_payload_) { | |
| 33 ret = decoder_->PacketDuration(payload_.data(), payload_.size()); | |
| 34 } else { | |
| 35 ret = decoder_->PacketDurationRedundant(payload_.data(), payload_.size()); | |
| 36 } | |
|
kwiberg-webrtc
2016/09/19 11:07:49
const:
const int ret = (is_primary_payload_ ? dec
ossu
2016/09/19 11:41:01
Oh, god, no! I'll be surprised if it works but eve
kwiberg-webrtc
2016/09/19 11:55:16
Hmm, you're right, I don't think it will work. And
hlundin-webrtc
2016/09/19 12:19:13
I'm with ossu: "Oh, God, no!"
ossu
2016/09/19 14:07:33
?: is fine but it's easy to end up with a big, con
| |
| 37 return (ret < 0) ? 0 : static_cast<size_t>(ret); | |
| 38 } | |
| 39 | |
| 40 rtc::Optional<DecodeResult> Decode( | |
| 41 rtc::ArrayView<int16_t> decoded) const override { | |
| 42 AudioDecoder::SpeechType speech_type = AudioDecoder::kSpeech; | |
| 43 int ret; | |
| 44 if (is_primary_payload_) { | |
| 45 ret = decoder_->Decode( | |
| 46 payload_.data(), payload_.size(), decoder_->SampleRateHz(), | |
| 47 decoded.size() * sizeof(int16_t), decoded.data(), &speech_type); | |
| 48 } else { | |
| 49 ret = decoder_->DecodeRedundant( | |
| 50 payload_.data(), payload_.size(), decoder_->SampleRateHz(), | |
| 51 decoded.size() * sizeof(int16_t), decoded.data(), &speech_type); | |
| 52 } | |
|
kwiberg-webrtc
2016/09/19 11:07:49
The same ?: construction can be used to make ret c
kwiberg-webrtc
2016/09/19 11:55:16
No, it won't work for the same reason as above.
| |
| 53 | |
| 54 if (ret < 0) | |
| 55 return rtc::Optional<DecodeResult>(); | |
| 56 | |
| 57 return rtc::Optional<DecodeResult>({static_cast<size_t>(ret), speech_type}); | |
| 58 } | |
| 59 | |
| 60 private: | |
| 61 AudioDecoderOpus* decoder_; | |
|
hlundin-webrtc
2016/09/15 09:33:30
const, const, const
ossu
2016/09/15 12:22:53
Acknowledged. Acknowledged. Acknowledged.
ossu
2016/09/19 11:41:01
Acknowledged.
kwiberg-webrtc
2016/09/19 11:55:16
Acknowledged.
hlundin-webrtc
2016/09/19 12:19:13
Roger that.
kwiberg-webrtc
2016/09/20 09:14:45
Roger, Roger. What's our vector, Victor?
| |
| 62 rtc::Buffer payload_; | |
| 63 bool is_primary_payload_; | |
|
kwiberg-webrtc
2016/09/19 11:07:49
Not sure if this is what Henrik was pointing out,
hlundin-webrtc
2016/09/19 12:19:13
That is why I put three "const" in one comment. I
ossu
2016/09/19 14:07:33
I was only able to get two consts into the decoder
| |
| 64 }; | |
| 65 | |
| 66 } // namespace | |
| 67 | |
| 17 AudioDecoderOpus::AudioDecoderOpus(size_t num_channels) | 68 AudioDecoderOpus::AudioDecoderOpus(size_t num_channels) |
| 18 : channels_(num_channels) { | 69 : channels_(num_channels) { |
| 19 RTC_DCHECK(num_channels == 1 || num_channels == 2); | 70 RTC_DCHECK(num_channels == 1 || num_channels == 2); |
| 20 WebRtcOpus_DecoderCreate(&dec_state_, channels_); | 71 WebRtcOpus_DecoderCreate(&dec_state_, channels_); |
| 21 WebRtcOpus_DecoderInit(dec_state_); | 72 WebRtcOpus_DecoderInit(dec_state_); |
| 22 } | 73 } |
| 23 | 74 |
| 24 AudioDecoderOpus::~AudioDecoderOpus() { | 75 AudioDecoderOpus::~AudioDecoderOpus() { |
| 25 WebRtcOpus_DecoderFree(dec_state_); | 76 WebRtcOpus_DecoderFree(dec_state_); |
| 26 } | 77 } |
| 27 | 78 |
| 79 std::vector<AudioDecoder::ParseResult> AudioDecoderOpus::ParsePayload( | |
| 80 rtc::Buffer* payload, | |
| 81 uint32_t timestamp) { | |
| 82 std::vector<ParseResult> results; | |
| 83 | |
| 84 if (PacketHasFec(payload->data(), payload->size())) { | |
| 85 const int duration = | |
|
hlundin-webrtc
2016/09/15 09:33:29
What if PacketDurationRedundant returns an error (
ossu
2016/09/15 12:22:53
I can't see that it's able to: it will call WebRtc
hlundin-webrtc
2016/09/16 07:51:27
But the method comment for AudioDecoder::PacketDur
ossu
2016/09/19 11:41:01
But it is only used within this implementation, i.
hlundin-webrtc
2016/09/19 12:19:13
You are right. Since this is an internal affair of
ossu
2016/09/19 14:07:33
Acknowledged.
| |
| 86 PacketDurationRedundant(payload->data(), payload->size()); | |
| 87 rtc::Buffer payload_copy(payload->data(), payload->size()); | |
| 88 std::unique_ptr<EncodedAudioFrame> fec_frame( | |
| 89 new OpusFrame(this, std::move(payload_copy), false)); | |
| 90 results.emplace_back(timestamp - duration, 1, std::move(fec_frame)); | |
| 91 } | |
| 92 std::unique_ptr<EncodedAudioFrame> frame( | |
| 93 new OpusFrame(this, std::move(*payload), true)); | |
| 94 results.emplace_back(timestamp, 0, std::move(frame)); | |
| 95 return results; | |
| 96 } | |
| 97 | |
| 28 int AudioDecoderOpus::DecodeInternal(const uint8_t* encoded, | 98 int AudioDecoderOpus::DecodeInternal(const uint8_t* encoded, |
| 29 size_t encoded_len, | 99 size_t encoded_len, |
| 30 int sample_rate_hz, | 100 int sample_rate_hz, |
| 31 int16_t* decoded, | 101 int16_t* decoded, |
| 32 SpeechType* speech_type) { | 102 SpeechType* speech_type) { |
| 33 RTC_DCHECK_EQ(sample_rate_hz, 48000); | 103 RTC_DCHECK_EQ(sample_rate_hz, 48000); |
| 34 int16_t temp_type = 1; // Default is speech. | 104 int16_t temp_type = 1; // Default is speech. |
| 35 int ret = | 105 int ret = |
| 36 WebRtcOpus_Decode(dec_state_, encoded, encoded_len, decoded, &temp_type); | 106 WebRtcOpus_Decode(dec_state_, encoded, encoded_len, decoded, &temp_type); |
| 37 if (ret > 0) | 107 if (ret > 0) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 | 159 |
| 90 int AudioDecoderOpus::SampleRateHz() const { | 160 int AudioDecoderOpus::SampleRateHz() const { |
| 91 return 48000; | 161 return 48000; |
| 92 } | 162 } |
| 93 | 163 |
| 94 size_t AudioDecoderOpus::Channels() const { | 164 size_t AudioDecoderOpus::Channels() const { |
| 95 return channels_; | 165 return channels_; |
| 96 } | 166 } |
| 97 | 167 |
| 98 } // namespace webrtc | 168 } // namespace webrtc |
| OLD | NEW |