 Chromium Code Reviews
 Chromium Code Reviews 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
    
  
    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| OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 
| 3 * | 3 * | 
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license | 
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source | 
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found | 
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may | 
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. | 
| 9 */ | 9 */ | 
| 10 | 10 | 
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 return Num10msFramesPerPacket(); | 126 return Num10msFramesPerPacket(); | 
| 127 } | 127 } | 
| 128 | 128 | 
| 129 int AudioEncoderOpus::GetTargetBitrate() const { | 129 int AudioEncoderOpus::GetTargetBitrate() const { | 
| 130 return config_.bitrate_bps; | 130 return config_.bitrate_bps; | 
| 131 } | 131 } | 
| 132 | 132 | 
| 133 AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal( | 133 AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal( | 
| 134 uint32_t rtp_timestamp, | 134 uint32_t rtp_timestamp, | 
| 135 rtc::ArrayView<const int16_t> audio, | 135 rtc::ArrayView<const int16_t> audio, | 
| 136 size_t max_encoded_bytes, | 136 rtc::Buffer* encoded) { | 
| 137 uint8_t* encoded) { | 137 | 
| 138 if (input_buffer_.empty()) | 138 if (input_buffer_.empty()) | 
| 139 first_timestamp_in_buffer_ = rtp_timestamp; | 139 first_timestamp_in_buffer_ = rtp_timestamp; | 
| 140 RTC_DCHECK_EQ(SamplesPer10msFrame(), audio.size()); | 140 | 
| 141 input_buffer_.insert(input_buffer_.end(), audio.cbegin(), audio.cend()); | 141 input_buffer_.insert(input_buffer_.end(), audio.cbegin(), audio.cend()); | 
| 142 if (input_buffer_.size() < | 142 if (input_buffer_.size() < | 
| 143 (Num10msFramesPerPacket() * SamplesPer10msFrame())) { | 143 (Num10msFramesPerPacket() * SamplesPer10msFrame())) { | 
| 144 return EncodedInfo(); | 144 return EncodedInfo(); | 
| 145 } | 145 } | 
| 146 RTC_CHECK_EQ(input_buffer_.size(), | 146 RTC_CHECK_EQ(input_buffer_.size(), | 
| 147 Num10msFramesPerPacket() * SamplesPer10msFrame()); | 147 Num10msFramesPerPacket() * SamplesPer10msFrame()); | 
| 148 int status = WebRtcOpus_Encode( | 148 | 
| 149 inst_, &input_buffer_[0], | 149 size_t max_encoded_bytes = MaxEncodedBytes(); | 
| 
kwiberg-webrtc
2016/02/25 00:29:04
const
 | |
| 150 rtc::CheckedDivExact(input_buffer_.size(), config_.num_channels), | 150 | 
| 151 rtc::saturated_cast<int16_t>(max_encoded_bytes), encoded); | 151 size_t encoded_bytes = | 
| 152 RTC_CHECK_GE(status, 0); // Fails only if fed invalid data. | 152 encoded->AppendData( | 
| 153 max_encoded_bytes, [&] (rtc::ArrayView<uint8_t> encoded) { | |
| 154 int status = WebRtcOpus_Encode( | |
| 155 inst_, &input_buffer_[0], | |
| 156 rtc::CheckedDivExact(input_buffer_.size(), | |
| 157 config_.num_channels), | |
| 158 rtc::saturated_cast<int16_t>(max_encoded_bytes), | |
| 159 encoded.data()); | |
| 160 | |
| 161 RTC_CHECK_GE(status, 0); // Fails only if fed invalid data. | |
| 162 | |
| 163 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.
 | |
| 164 }); | |
| 165 | |
| 153 input_buffer_.clear(); | 166 input_buffer_.clear(); | 
| 154 EncodedInfo info; | 167 EncodedInfo info; | 
| 155 info.encoded_bytes = static_cast<size_t>(status); | 168 info.encoded_bytes = encoded_bytes; | 
| 156 info.encoded_timestamp = first_timestamp_in_buffer_; | 169 info.encoded_timestamp = first_timestamp_in_buffer_; | 
| 157 info.payload_type = config_.payload_type; | 170 info.payload_type = config_.payload_type; | 
| 158 info.send_even_if_empty = true; // Allows Opus to send empty packets. | 171 info.send_even_if_empty = true; // Allows Opus to send empty packets. | 
| 159 info.speech = (status > 0); | 172 info.speech = (encoded_bytes > 0); | 
| 160 return info; | 173 return info; | 
| 161 } | 174 } | 
| 162 | 175 | 
| 163 void AudioEncoderOpus::Reset() { | 176 void AudioEncoderOpus::Reset() { | 
| 164 RTC_CHECK(RecreateEncoderInstance(config_)); | 177 RTC_CHECK(RecreateEncoderInstance(config_)); | 
| 165 } | 178 } | 
| 166 | 179 | 
| 167 bool AudioEncoderOpus::SetFec(bool enable) { | 180 bool AudioEncoderOpus::SetFec(bool enable) { | 
| 168 auto conf = config_; | 181 auto conf = config_; | 
| 169 conf.fec_enabled = enable; | 182 conf.fec_enabled = enable; | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 RTC_CHECK_EQ(0, WebRtcOpus_DisableDtx(inst_)); | 260 RTC_CHECK_EQ(0, WebRtcOpus_DisableDtx(inst_)); | 
| 248 } | 261 } | 
| 249 RTC_CHECK_EQ(0, | 262 RTC_CHECK_EQ(0, | 
| 250 WebRtcOpus_SetPacketLossRate( | 263 WebRtcOpus_SetPacketLossRate( | 
| 251 inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5))); | 264 inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5))); | 
| 252 config_ = config; | 265 config_ = config; | 
| 253 return true; | 266 return true; | 
| 254 } | 267 } | 
| 255 | 268 | 
| 256 } // namespace webrtc | 269 } // namespace webrtc | 
| OLD | NEW |