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

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

Issue 2742383002: Fix AudioEncoderOpus::RecreateEncoderInstance() referring to old config_ (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 Num10msFramesPerPacket() * 10 * bytes_per_millisecond; 441 Num10msFramesPerPacket() * 10 * bytes_per_millisecond;
442 return 2 * approx_encoded_bytes; 442 return 2 * approx_encoded_bytes;
443 } 443 }
444 444
445 // If the given config is OK, recreate the Opus encoder instance with those 445 // If the given config is OK, recreate the Opus encoder instance with those
446 // settings, save the config, and return true. Otherwise, do nothing and return 446 // settings, save the config, and return true. Otherwise, do nothing and return
447 // false. 447 // false.
448 bool AudioEncoderOpus::RecreateEncoderInstance(const Config& config) { 448 bool AudioEncoderOpus::RecreateEncoderInstance(const Config& config) {
449 if (!config.IsOk()) 449 if (!config.IsOk())
450 return false; 450 return false;
451 config_ = config;
elad.alon_webrtc.org 2017/03/13 14:50:31 Saving this for last would make more sense if we h
kwiberg-webrtc 2017/03/14 07:04:35 Acknowledged.
451 if (inst_) 452 if (inst_)
452 RTC_CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_)); 453 RTC_CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_));
453 input_buffer_.clear(); 454 input_buffer_.clear();
454 input_buffer_.reserve(Num10msFramesPerPacket() * SamplesPer10msFrame()); 455 input_buffer_.reserve(Num10msFramesPerPacket() * SamplesPer10msFrame());
elad.alon_webrtc.org 2017/03/13 14:50:32 These functions read from |config_|.
kwiberg-webrtc 2017/03/14 07:04:35 Indeed. It should be harmless, since reserve() onl
455 RTC_CHECK_EQ(0, WebRtcOpus_EncoderCreate(&inst_, config.num_channels, 456 RTC_CHECK_EQ(0, WebRtcOpus_EncoderCreate(&inst_, config.num_channels,
456 config.application)); 457 config.application));
457 RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config.GetBitrateBps())); 458 RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config.GetBitrateBps()));
458 if (config.fec_enabled) { 459 if (config.fec_enabled) {
459 RTC_CHECK_EQ(0, WebRtcOpus_EnableFec(inst_)); 460 RTC_CHECK_EQ(0, WebRtcOpus_EnableFec(inst_));
460 } else { 461 } else {
461 RTC_CHECK_EQ(0, WebRtcOpus_DisableFec(inst_)); 462 RTC_CHECK_EQ(0, WebRtcOpus_DisableFec(inst_));
462 } 463 }
463 RTC_CHECK_EQ( 464 RTC_CHECK_EQ(
464 0, WebRtcOpus_SetMaxPlaybackRate(inst_, config.max_playback_rate_hz)); 465 0, WebRtcOpus_SetMaxPlaybackRate(inst_, config.max_playback_rate_hz));
465 // Use the default complexity if the start bitrate is within the hysteresis 466 // Use the default complexity if the start bitrate is within the hysteresis
466 // window. 467 // window.
467 complexity_ = config.GetNewComplexity().value_or(config.complexity); 468 complexity_ = config.GetNewComplexity().value_or(config.complexity);
468 RTC_CHECK_EQ(0, WebRtcOpus_SetComplexity(inst_, complexity_)); 469 RTC_CHECK_EQ(0, WebRtcOpus_SetComplexity(inst_, complexity_));
469 if (config.dtx_enabled) { 470 if (config.dtx_enabled) {
470 RTC_CHECK_EQ(0, WebRtcOpus_EnableDtx(inst_)); 471 RTC_CHECK_EQ(0, WebRtcOpus_EnableDtx(inst_));
471 } else { 472 } else {
472 RTC_CHECK_EQ(0, WebRtcOpus_DisableDtx(inst_)); 473 RTC_CHECK_EQ(0, WebRtcOpus_DisableDtx(inst_));
473 } 474 }
474 RTC_CHECK_EQ(0, 475 RTC_CHECK_EQ(0,
475 WebRtcOpus_SetPacketLossRate( 476 WebRtcOpus_SetPacketLossRate(
476 inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5))); 477 inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5)));
477 config_ = config;
478 478
479 num_channels_to_encode_ = NumChannels(); 479 num_channels_to_encode_ = NumChannels();
480 next_frame_length_ms_ = config_.frame_size_ms; 480 next_frame_length_ms_ = config_.frame_size_ms;
481 return true; 481 return true;
482 } 482 }
483 483
484 void AudioEncoderOpus::SetFrameLength(int frame_length_ms) { 484 void AudioEncoderOpus::SetFrameLength(int frame_length_ms) {
485 next_frame_length_ms_ = frame_length_ms; 485 next_frame_length_ms_ = frame_length_ms;
486 } 486 }
487 487
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 config_.uplink_bandwidth_update_interval_ms) { 561 config_.uplink_bandwidth_update_interval_ms) {
562 rtc::Optional<float> smoothed_bitrate = bitrate_smoother_->GetAverage(); 562 rtc::Optional<float> smoothed_bitrate = bitrate_smoother_->GetAverage();
563 if (smoothed_bitrate) 563 if (smoothed_bitrate)
564 audio_network_adaptor_->SetUplinkBandwidth(*smoothed_bitrate); 564 audio_network_adaptor_->SetUplinkBandwidth(*smoothed_bitrate);
565 bitrate_smoother_last_update_time_ = rtc::Optional<int64_t>(now_ms); 565 bitrate_smoother_last_update_time_ = rtc::Optional<int64_t>(now_ms);
566 } 566 }
567 } 567 }
568 } 568 }
569 569
570 } // namespace webrtc 570 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698