Chromium Code Reviews| Index: webrtc/modules/audio_coding/codecs/audio_decoder.cc |
| diff --git a/webrtc/modules/audio_coding/codecs/audio_decoder.cc b/webrtc/modules/audio_coding/codecs/audio_decoder.cc |
| index 8d4a2bc175ba624bfc518adaf4fcebe9eea8d795..468af72894357ef75559add84781a3b522e117cf 100644 |
| --- a/webrtc/modules/audio_coding/codecs/audio_decoder.cc |
| +++ b/webrtc/modules/audio_coding/codecs/audio_decoder.cc |
| @@ -19,6 +19,78 @@ |
| namespace webrtc { |
| +namespace { |
| +class LegacyFrame : public AudioDecoder::Frame { |
| + public: |
| + LegacyFrame(AudioDecoder* decoder, |
| + rtc::Buffer* payload, |
| + bool is_primary_payload) |
| + : decoder_(decoder), is_primary_payload_(is_primary_payload) { |
| + using std::swap; |
|
hlundin-webrtc
2016/09/09 12:11:49
Why the using statement?
kwiberg-webrtc
2016/09/10 07:34:59
It's the standard idiom for swapping stuff. See e.
hlundin-webrtc
2016/09/12 08:07:11
Acknowledged.
|
| + swap(this->payload_, *payload); |
|
hlundin-webrtc
2016/09/09 12:11:49
#include what you use.
kwiberg-webrtc
2016/09/10 07:34:59
+1
ossu
2016/09/12 10:31:36
Acknowledged.
|
| + } |
|
kwiberg-webrtc
2016/09/10 07:34:59
Why not move *payload to payload_ instead of swapp
ossu
2016/09/12 10:31:36
Hmm. I was thinking of doing this to allow buffer
|
| + |
| + 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()); |
| + } |
| + 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); |
| + } |
| + |
| + if (ret < 0) |
| + return rtc::Optional<DecodeResult>(); |
| + |
| + return rtc::Optional<DecodeResult>({static_cast<size_t>(ret), speech_type}); |
| + } |
| + |
| + private: |
| + AudioDecoder* decoder_; |
|
hlundin-webrtc
2016/09/09 12:11:49
const
|
| + rtc::Buffer payload_; |
| + bool is_primary_payload_; |
|
hlundin-webrtc
2016/09/09 12:11:49
const
kwiberg-webrtc
2016/09/10 07:34:59
All three could be const, right?
ossu
2016/09/12 10:31:36
Acknowledged.
|
| +}; |
| +} |
| + |
| +AudioDecoder::ParseResult::ParseResult() = default; |
| +AudioDecoder::ParseResult::ParseResult(ParseResult&& b) = default; |
| +AudioDecoder::ParseResult::ParseResult(uint32_t timestamp, |
| + bool primary, |
| + std::unique_ptr<Frame> frame) |
| + : timestamp(timestamp), primary(primary), frame(std::move(frame)) {} |
| + |
| +AudioDecoder::ParseResult::~ParseResult() = default; |
| + |
| +AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=( |
| + ParseResult&& b) = default; |
| + |
| +std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload( |
| + rtc::Buffer* payload, |
| + uint32_t timestamp, |
| + bool is_primary) { |
| + std::vector<ParseResult> results; |
| + std::unique_ptr<Frame> frame( |
| + new LegacyFrame(this, payload, is_primary)); |
| + results.emplace_back(timestamp, is_primary, std::move(frame)); |
| + return results; |
| +} |
| + |
| int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len, |
| int sample_rate_hz, size_t max_decoded_bytes, |
| int16_t* decoded, SpeechType* speech_type) { |