Index: webrtc/modules/audio_coding/codecs/opus/audio_decoder_opus.cc |
diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_decoder_opus.cc b/webrtc/modules/audio_coding/codecs/opus/audio_decoder_opus.cc |
index 42abd0a0d604d0875d614f39748687a548ace19e..a31c9b07aed1f69e06762b04422a7591215b0ad4 100644 |
--- a/webrtc/modules/audio_coding/codecs/opus/audio_decoder_opus.cc |
+++ b/webrtc/modules/audio_coding/codecs/opus/audio_decoder_opus.cc |
@@ -10,10 +10,61 @@ |
#include "webrtc/modules/audio_coding/codecs/opus/audio_decoder_opus.h" |
+#include <utility> |
+ |
#include "webrtc/base/checks.h" |
namespace webrtc { |
+namespace { |
+class OpusFrame : public AudioDecoder::EncodedAudioFrame { |
+ public: |
+ OpusFrame(AudioDecoderOpus* decoder, |
+ rtc::Buffer&& payload, |
+ bool is_primary_payload) |
+ : decoder_(decoder), is_primary_payload_(is_primary_payload) { |
+ using std::swap; |
+ swap(this->payload_, payload); |
hlundin-webrtc
2016/09/15 09:33:30
std::move?
ossu
2016/09/15 12:22:53
Acknowledged.
|
+ } |
+ |
+ size_t Duration() const override { |
+ int ret; |
+ if (is_primary_payload_) { |
+ ret = decoder_->PacketDuration(payload_.data(), payload_.size()); |
+ } else { |
+ ret = decoder_->PacketDurationRedundant(payload_.data(), payload_.size()); |
+ } |
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
|
+ return (ret < 0) ? 0 : static_cast<size_t>(ret); |
+ } |
+ |
+ rtc::Optional<DecodeResult> Decode( |
+ rtc::ArrayView<int16_t> decoded) const override { |
+ AudioDecoder::SpeechType speech_type = AudioDecoder::kSpeech; |
+ int ret; |
+ if (is_primary_payload_) { |
+ ret = decoder_->Decode( |
+ payload_.data(), payload_.size(), decoder_->SampleRateHz(), |
+ decoded.size() * sizeof(int16_t), decoded.data(), &speech_type); |
+ } else { |
+ ret = decoder_->DecodeRedundant( |
+ payload_.data(), payload_.size(), decoder_->SampleRateHz(), |
+ decoded.size() * sizeof(int16_t), decoded.data(), &speech_type); |
+ } |
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.
|
+ |
+ if (ret < 0) |
+ return rtc::Optional<DecodeResult>(); |
+ |
+ return rtc::Optional<DecodeResult>({static_cast<size_t>(ret), speech_type}); |
+ } |
+ |
+ private: |
+ 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?
|
+ rtc::Buffer payload_; |
+ 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
|
+}; |
+ |
+} // namespace |
+ |
AudioDecoderOpus::AudioDecoderOpus(size_t num_channels) |
: channels_(num_channels) { |
RTC_DCHECK(num_channels == 1 || num_channels == 2); |
@@ -25,6 +76,25 @@ AudioDecoderOpus::~AudioDecoderOpus() { |
WebRtcOpus_DecoderFree(dec_state_); |
} |
+std::vector<AudioDecoder::ParseResult> AudioDecoderOpus::ParsePayload( |
+ rtc::Buffer* payload, |
+ uint32_t timestamp) { |
+ std::vector<ParseResult> results; |
+ |
+ if (PacketHasFec(payload->data(), payload->size())) { |
+ 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.
|
+ PacketDurationRedundant(payload->data(), payload->size()); |
+ rtc::Buffer payload_copy(payload->data(), payload->size()); |
+ std::unique_ptr<EncodedAudioFrame> fec_frame( |
+ new OpusFrame(this, std::move(payload_copy), false)); |
+ results.emplace_back(timestamp - duration, 1, std::move(fec_frame)); |
+ } |
+ std::unique_ptr<EncodedAudioFrame> frame( |
+ new OpusFrame(this, std::move(*payload), true)); |
+ results.emplace_back(timestamp, 0, std::move(frame)); |
+ return results; |
+} |
+ |
int AudioDecoderOpus::DecodeInternal(const uint8_t* encoded, |
size_t encoded_len, |
int sample_rate_hz, |