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

Side by Side Diff: webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc

Issue 2411613002: Renaming AudioEncoder::SetTargetBitrate and SetProjectedPacketLossRate. (Closed)
Patch Set: Created 4 years, 2 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 unified diff | Download patch
OLDNEW
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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 190 }
191 return RecreateEncoderInstance(conf); 191 return RecreateEncoderInstance(conf);
192 } 192 }
193 193
194 void AudioEncoderOpus::SetMaxPlaybackRate(int frequency_hz) { 194 void AudioEncoderOpus::SetMaxPlaybackRate(int frequency_hz) {
195 auto conf = config_; 195 auto conf = config_;
196 conf.max_playback_rate_hz = frequency_hz; 196 conf.max_playback_rate_hz = frequency_hz;
197 RTC_CHECK(RecreateEncoderInstance(conf)); 197 RTC_CHECK(RecreateEncoderInstance(conf));
198 } 198 }
199 199
200 void AudioEncoderOpus::SetProjectedPacketLossRate(double fraction) {
201 double opt_loss_rate = OptimizePacketLossRate(fraction, packet_loss_rate_);
202 if (packet_loss_rate_ != opt_loss_rate) {
203 packet_loss_rate_ = opt_loss_rate;
204 RTC_CHECK_EQ(
205 0, WebRtcOpus_SetPacketLossRate(
206 inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5)));
207 }
208 }
209
210 void AudioEncoderOpus::SetTargetBitrate(int bits_per_second) {
211 config_.bitrate_bps = rtc::Optional<int>(
212 std::max(std::min(bits_per_second, kMaxBitrateBps), kMinBitrateBps));
213 RTC_DCHECK(config_.IsOk());
214 RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config_.GetBitrateBps()));
215 }
216
217 bool AudioEncoderOpus::EnableAudioNetworkAdaptor( 200 bool AudioEncoderOpus::EnableAudioNetworkAdaptor(
218 const std::string& config_string, 201 const std::string& config_string,
219 const Clock* clock) { 202 const Clock* clock) {
220 audio_network_adaptor_ = audio_network_adaptor_creator_(config_string, clock); 203 audio_network_adaptor_ = audio_network_adaptor_creator_(config_string, clock);
221 return audio_network_adaptor_.get() != nullptr; 204 return audio_network_adaptor_.get() != nullptr;
222 } 205 }
223 206
224 void AudioEncoderOpus::DisableAudioNetworkAdaptor() { 207 void AudioEncoderOpus::DisableAudioNetworkAdaptor() {
225 audio_network_adaptor_.reset(nullptr); 208 audio_network_adaptor_.reset(nullptr);
226 } 209 }
227 210
228 void AudioEncoderOpus::OnReceivedUplinkBandwidth(int uplink_bandwidth_bps) { 211 void AudioEncoderOpus::OnReceivedUplinkBandwidth(int uplink_bandwidth_bps) {
229 if (!audio_network_adaptor_) 212 if (!audio_network_adaptor_)
230 return; 213 return;
231 audio_network_adaptor_->SetUplinkBandwidth(uplink_bandwidth_bps); 214 audio_network_adaptor_->SetUplinkBandwidth(uplink_bandwidth_bps);
232 ApplyAudioNetworkAdaptor(); 215 ApplyAudioNetworkAdaptor();
233 } 216 }
234 217
235 void AudioEncoderOpus::OnReceivedUplinkPacketLossFraction( 218 void AudioEncoderOpus::OnReceivedUplinkPacketLossFraction(
236 float uplink_packet_loss_fraction) { 219 float uplink_packet_loss_fraction) {
237 if (!audio_network_adaptor_) { 220 if (!audio_network_adaptor_)
238 return AudioEncoder::OnReceivedTargetAudioBitrate( 221 SetProjectedPacketLossRate(uplink_packet_loss_fraction);
kwiberg-webrtc 2016/10/20 21:46:23 Shouldn't there be an early retirn here? Or an els
minyue-webrtc 2016/11/08 13:37:24 Yes, it should early return :) This is self-solve
239 uplink_packet_loss_fraction);
240 }
241 audio_network_adaptor_->SetUplinkPacketLossFraction( 222 audio_network_adaptor_->SetUplinkPacketLossFraction(
242 uplink_packet_loss_fraction); 223 uplink_packet_loss_fraction);
243 ApplyAudioNetworkAdaptor(); 224 ApplyAudioNetworkAdaptor();
244 } 225 }
245 226
246 void AudioEncoderOpus::OnReceivedTargetAudioBitrate( 227 void AudioEncoderOpus::OnReceivedTargetAudioBitrate(
247 int target_audio_bitrate_bps) { 228 int target_audio_bitrate_bps) {
248 if (!audio_network_adaptor_) 229 if (!audio_network_adaptor_)
249 return AudioEncoder::OnReceivedTargetAudioBitrate(target_audio_bitrate_bps); 230 return SetTargetBitrate(target_audio_bitrate_bps);
250 audio_network_adaptor_->SetTargetAudioBitrate(target_audio_bitrate_bps); 231 audio_network_adaptor_->SetTargetAudioBitrate(target_audio_bitrate_bps);
251 ApplyAudioNetworkAdaptor(); 232 ApplyAudioNetworkAdaptor();
252 } 233 }
253 234
254 void AudioEncoderOpus::OnReceivedRtt(int rtt_ms) { 235 void AudioEncoderOpus::OnReceivedRtt(int rtt_ms) {
255 if (!audio_network_adaptor_) 236 if (!audio_network_adaptor_)
256 return; 237 return;
257 audio_network_adaptor_->SetRtt(rtt_ms); 238 audio_network_adaptor_->SetRtt(rtt_ms);
258 ApplyAudioNetworkAdaptor(); 239 ApplyAudioNetworkAdaptor();
259 } 240 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 RTC_DCHECK_GT(num_channels_to_encode, 0u); 355 RTC_DCHECK_GT(num_channels_to_encode, 0u);
375 RTC_DCHECK_LE(num_channels_to_encode, config_.num_channels); 356 RTC_DCHECK_LE(num_channels_to_encode, config_.num_channels);
376 357
377 if (num_channels_to_encode_ == num_channels_to_encode) 358 if (num_channels_to_encode_ == num_channels_to_encode)
378 return; 359 return;
379 360
380 RTC_CHECK_EQ(0, WebRtcOpus_SetForceChannels(inst_, num_channels_to_encode)); 361 RTC_CHECK_EQ(0, WebRtcOpus_SetForceChannels(inst_, num_channels_to_encode));
381 num_channels_to_encode_ = num_channels_to_encode; 362 num_channels_to_encode_ = num_channels_to_encode;
382 } 363 }
383 364
365 void AudioEncoderOpus::SetTargetBitrate(int bits_per_second) {
366 config_.bitrate_bps = rtc::Optional<int>(
367 std::max(std::min(bits_per_second, kMaxBitrateBps), kMinBitrateBps));
368 RTC_DCHECK(config_.IsOk());
369 RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config_.GetBitrateBps()));
370 }
371
372 void AudioEncoderOpus::SetProjectedPacketLossRate(double fraction) {
373 double opt_loss_rate = OptimizePacketLossRate(fraction, packet_loss_rate_);
374 if (packet_loss_rate_ != opt_loss_rate) {
375 packet_loss_rate_ = opt_loss_rate;
376 RTC_CHECK_EQ(
377 0, WebRtcOpus_SetPacketLossRate(
378 inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5)));
379 }
380 }
381
384 void AudioEncoderOpus::ApplyAudioNetworkAdaptor() { 382 void AudioEncoderOpus::ApplyAudioNetworkAdaptor() {
385 auto config = audio_network_adaptor_->GetEncoderRuntimeConfig(); 383 auto config = audio_network_adaptor_->GetEncoderRuntimeConfig();
386 // |audio_network_adaptor_| is supposed to be configured to output all 384 // |audio_network_adaptor_| is supposed to be configured to output all
387 // following parameters. 385 // following parameters.
388 RTC_DCHECK(config.bitrate_bps); 386 RTC_DCHECK(config.bitrate_bps);
389 RTC_DCHECK(config.frame_length_ms); 387 RTC_DCHECK(config.frame_length_ms);
390 RTC_DCHECK(config.uplink_packet_loss_fraction); 388 RTC_DCHECK(config.uplink_packet_loss_fraction);
391 RTC_DCHECK(config.enable_fec); 389 RTC_DCHECK(config.enable_fec);
392 RTC_DCHECK(config.enable_dtx); 390 RTC_DCHECK(config.enable_dtx);
393 RTC_DCHECK(config.num_channels); 391 RTC_DCHECK(config.num_channels);
(...skipping 15 matching lines...) Expand all
409 AudioNetworkAdaptorImpl::Config config; 407 AudioNetworkAdaptorImpl::Config config;
410 config.clock = clock; 408 config.clock = clock;
411 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl( 409 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl(
412 config, ControllerManagerImpl::Create( 410 config, ControllerManagerImpl::Create(
413 config_string, NumChannels(), kSupportedFrameLengths, 411 config_string, NumChannels(), kSupportedFrameLengths,
414 num_channels_to_encode_, next_frame_length_ms_, 412 num_channels_to_encode_, next_frame_length_ms_,
415 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock))); 413 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock)));
416 } 414 }
417 415
418 } // namespace webrtc 416 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698