Chromium Code Reviews| Index: webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc |
| diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc |
| index 707d6c24884683ce00b5fb849ebd91f0406c1b51..dd9d64dd3994a11063d7e5480753a46e3a0080c4 100644 |
| --- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc |
| +++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc |
| @@ -133,11 +133,11 @@ int AudioEncoderOpus::GetTargetBitrate() const { |
| AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal( |
| uint32_t rtp_timestamp, |
| rtc::ArrayView<const int16_t> audio, |
| - size_t max_encoded_bytes, |
| - uint8_t* encoded) { |
| + rtc::Buffer* encoded) { |
| + |
| if (input_buffer_.empty()) |
| first_timestamp_in_buffer_ = rtp_timestamp; |
| - RTC_DCHECK_EQ(SamplesPer10msFrame(), audio.size()); |
| + |
| input_buffer_.insert(input_buffer_.end(), audio.cbegin(), audio.cend()); |
| if (input_buffer_.size() < |
| (Num10msFramesPerPacket() * SamplesPer10msFrame())) { |
| @@ -145,18 +145,31 @@ AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal( |
| } |
| RTC_CHECK_EQ(input_buffer_.size(), |
| Num10msFramesPerPacket() * SamplesPer10msFrame()); |
| - int status = WebRtcOpus_Encode( |
| - inst_, &input_buffer_[0], |
| - rtc::CheckedDivExact(input_buffer_.size(), config_.num_channels), |
| - rtc::saturated_cast<int16_t>(max_encoded_bytes), encoded); |
| - RTC_CHECK_GE(status, 0); // Fails only if fed invalid data. |
| + |
| + size_t max_encoded_bytes = MaxEncodedBytes(); |
|
kwiberg-webrtc
2016/02/25 00:29:04
const
|
| + |
| + size_t encoded_bytes = |
| + encoded->AppendData( |
| + max_encoded_bytes, [&] (rtc::ArrayView<uint8_t> encoded) { |
| + int status = WebRtcOpus_Encode( |
| + inst_, &input_buffer_[0], |
| + rtc::CheckedDivExact(input_buffer_.size(), |
| + config_.num_channels), |
| + rtc::saturated_cast<int16_t>(max_encoded_bytes), |
| + encoded.data()); |
| + |
| + RTC_CHECK_GE(status, 0); // Fails only if fed invalid data. |
| + |
| + return (status >= 0) ? static_cast<size_t>(status) : 0; |
|
kwiberg-webrtc
2016/02/25 00:29:04
Just static_cast<size_t>(status) because of the CH
ossu
2016/02/25 10:39:51
Acknowledged.
|
| + }); |
| + |
| input_buffer_.clear(); |
| EncodedInfo info; |
| - info.encoded_bytes = static_cast<size_t>(status); |
| + info.encoded_bytes = encoded_bytes; |
| info.encoded_timestamp = first_timestamp_in_buffer_; |
| info.payload_type = config_.payload_type; |
| info.send_even_if_empty = true; // Allows Opus to send empty packets. |
| - info.speech = (status > 0); |
| + info.speech = (encoded_bytes > 0); |
| return info; |
| } |