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..1f68e154ce3671abf43101fe823773ef43107141 100644 |
--- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc |
+++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc |
@@ -130,36 +130,6 @@ int AudioEncoderOpus::GetTargetBitrate() const { |
return config_.bitrate_bps; |
} |
-AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal( |
- uint32_t rtp_timestamp, |
- rtc::ArrayView<const int16_t> audio, |
- size_t max_encoded_bytes, |
- uint8_t* 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())) { |
- return EncodedInfo(); |
- } |
- 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. |
- input_buffer_.clear(); |
- EncodedInfo info; |
- info.encoded_bytes = static_cast<size_t>(status); |
- 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); |
- return info; |
-} |
- |
void AudioEncoderOpus::Reset() { |
RTC_CHECK(RecreateEncoderInstance(config_)); |
} |
@@ -212,6 +182,47 @@ void AudioEncoderOpus::SetTargetBitrate(int bits_per_second) { |
RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config_.bitrate_bps)); |
} |
+AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal( |
+ uint32_t rtp_timestamp, |
+ rtc::ArrayView<const int16_t> audio, |
+ rtc::Buffer* encoded) { |
+ |
+ if (input_buffer_.empty()) |
+ first_timestamp_in_buffer_ = rtp_timestamp; |
+ |
+ input_buffer_.insert(input_buffer_.end(), audio.cbegin(), audio.cend()); |
+ if (input_buffer_.size() < |
+ (Num10msFramesPerPacket() * SamplesPer10msFrame())) { |
+ return EncodedInfo(); |
+ } |
+ RTC_CHECK_EQ(input_buffer_.size(), |
+ Num10msFramesPerPacket() * SamplesPer10msFrame()); |
+ |
+ const size_t max_encoded_bytes = MaxEncodedBytes(); |
+ EncodedInfo info; |
+ info.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 static_cast<size_t>(status); |
+ }); |
+ input_buffer_.clear(); |
+ |
+ 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 = (info.encoded_bytes > 0); |
+ return info; |
+} |
+ |
size_t AudioEncoderOpus::Num10msFramesPerPacket() const { |
return static_cast<size_t>(rtc::CheckedDivExact(config_.frame_size_ms, 10)); |
} |