Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Unified Diff: webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc

Issue 1725143003: Changed AudioEncoder::Encode to take an rtc::Buffer* instead of uint8_t* and a maximum size. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added more fixes for override hiding in AudioEncoder implementations. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc
diff --git a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc
index 464655c511d349bb5bd2c74c21a15386c607059c..ab699cae79d6e1062c26e2948f1035f78613cda8 100644
--- a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc
+++ b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc
@@ -100,10 +100,7 @@ int AudioEncoderCng::GetTargetBitrate() const {
AudioEncoder::EncodedInfo AudioEncoderCng::EncodeInternal(
uint32_t rtp_timestamp,
rtc::ArrayView<const int16_t> audio,
- size_t max_encoded_bytes,
- uint8_t* encoded) {
- RTC_CHECK_GE(max_encoded_bytes,
- static_cast<size_t>(num_cng_coefficients_ + 1));
+ rtc::Buffer* encoded) {
const size_t samples_per_10ms_frame = SamplesPer10msFrame();
RTC_CHECK_EQ(speech_buffer_.size(),
rtp_timestamps_.size() * samples_per_10ms_frame);
@@ -145,12 +142,12 @@ AudioEncoder::EncodedInfo AudioEncoderCng::EncodeInternal(
EncodedInfo info;
switch (activity) {
case Vad::kPassive: {
- info = EncodePassive(frames_to_encode, max_encoded_bytes, encoded);
+ info = EncodePassive(frames_to_encode, encoded);
last_frame_active_ = false;
break;
}
case Vad::kActive: {
- info = EncodeActive(frames_to_encode, max_encoded_bytes, encoded);
+ info = EncodeActive(frames_to_encode, encoded);
last_frame_active_ = true;
break;
}
@@ -204,31 +201,37 @@ void AudioEncoderCng::SetTargetBitrate(int bits_per_second) {
AudioEncoder::EncodedInfo AudioEncoderCng::EncodePassive(
size_t frames_to_encode,
- size_t max_encoded_bytes,
- uint8_t* encoded) {
+ rtc::Buffer* encoded) {
bool force_sid = last_frame_active_;
bool output_produced = false;
const size_t samples_per_10ms_frame = SamplesPer10msFrame();
- RTC_CHECK_GE(max_encoded_bytes, frames_to_encode * samples_per_10ms_frame);
+ const size_t bytes_to_encode = frames_to_encode * samples_per_10ms_frame;
AudioEncoder::EncodedInfo info;
- for (size_t i = 0; i < frames_to_encode; ++i) {
- // It's important not to pass &info.encoded_bytes directly to
- // WebRtcCng_Encode(), since later loop iterations may return zero in that
- // value, in which case we don't want to overwrite any value from an earlier
- // iteration.
- size_t encoded_bytes_tmp = 0;
- RTC_CHECK_GE(WebRtcCng_Encode(cng_inst_.get(),
- &speech_buffer_[i * samples_per_10ms_frame],
- samples_per_10ms_frame, encoded,
- &encoded_bytes_tmp, force_sid),
- 0);
- if (encoded_bytes_tmp > 0) {
- RTC_CHECK(!output_produced);
- info.encoded_bytes = encoded_bytes_tmp;
- output_produced = true;
- force_sid = false;
- }
- }
+
+ encoded->AppendData(bytes_to_encode, [&] (rtc::ArrayView<uint8_t> encoded) {
The Sun (google.com) 2016/03/01 21:06:15 FYI: Chromium C++11 style guide says to not use de
ossu 2016/03/02 08:39:42 Well yes, and no. It says don't use it, referring
kwiberg-webrtc 2016/03/02 09:40:24 Yes. The Google style guide used to blanket ban de
+ for (size_t i = 0; i < frames_to_encode; ++i) {
+ // It's important not to pass &info.encoded_bytes directly to
+ // WebRtcCng_Encode(), since later loop iterations may return zero in
+ // that value, in which case we don't want to overwrite any value from
+ // an earlier iteration.
+ size_t encoded_bytes_tmp = 0;
+ RTC_CHECK_GE(
+ WebRtcCng_Encode(cng_inst_.get(),
+ &speech_buffer_[i * samples_per_10ms_frame],
+ samples_per_10ms_frame, encoded.data(),
+ &encoded_bytes_tmp, force_sid),
+ 0);
+ if (encoded_bytes_tmp > 0) {
+ RTC_CHECK(!output_produced);
+ info.encoded_bytes = encoded_bytes_tmp;
+ output_produced = true;
+ force_sid = false;
+ }
+ }
+
+ return info.encoded_bytes;
+ });
+
info.encoded_timestamp = rtp_timestamps_.front();
info.payload_type = cng_payload_type_;
info.send_even_if_empty = true;
@@ -238,8 +241,7 @@ AudioEncoder::EncodedInfo AudioEncoderCng::EncodePassive(
AudioEncoder::EncodedInfo AudioEncoderCng::EncodeActive(
size_t frames_to_encode,
- size_t max_encoded_bytes,
- uint8_t* encoded) {
+ rtc::Buffer* encoded) {
const size_t samples_per_10ms_frame = SamplesPer10msFrame();
AudioEncoder::EncodedInfo info;
for (size_t i = 0; i < frames_to_encode; ++i) {
@@ -248,7 +250,7 @@ AudioEncoder::EncodedInfo AudioEncoderCng::EncodeActive(
rtc::ArrayView<const int16_t>(
&speech_buffer_[i * samples_per_10ms_frame],
samples_per_10ms_frame),
- max_encoded_bytes, encoded);
+ encoded);
if (i + 1 == frames_to_encode) {
RTC_CHECK_GT(info.encoded_bytes, 0u) << "Encoder didn't deliver data.";
} else {

Powered by Google App Engine
This is Rietveld 408576698