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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 const Config& config, | 174 const Config& config, |
175 AudioNetworkAdaptorCreator&& audio_network_adaptor_creator, | 175 AudioNetworkAdaptorCreator&& audio_network_adaptor_creator, |
176 std::unique_ptr<SmoothingFilter> bitrate_smoother) | 176 std::unique_ptr<SmoothingFilter> bitrate_smoother) |
177 : packet_loss_rate_(0.0), | 177 : packet_loss_rate_(0.0), |
178 inst_(nullptr), | 178 inst_(nullptr), |
179 packet_loss_fraction_smoother_(new PacketLossFractionSmoother( | 179 packet_loss_fraction_smoother_(new PacketLossFractionSmoother( |
180 config.clock)), | 180 config.clock)), |
181 audio_network_adaptor_creator_( | 181 audio_network_adaptor_creator_( |
182 audio_network_adaptor_creator | 182 audio_network_adaptor_creator |
183 ? std::move(audio_network_adaptor_creator) | 183 ? std::move(audio_network_adaptor_creator) |
184 : [this](const std::string& config_string, const Clock* clock) { | 184 : [this](const std::string& config_string, |
| 185 RtcEventLog* event_log, |
| 186 const Clock* clock) { |
185 return DefaultAudioNetworkAdaptorCreator(config_string, | 187 return DefaultAudioNetworkAdaptorCreator(config_string, |
186 clock); | 188 event_log, clock); |
187 }), | 189 }), |
188 bitrate_smoother_(bitrate_smoother | 190 bitrate_smoother_(bitrate_smoother |
189 ? std::move(bitrate_smoother) : std::unique_ptr<SmoothingFilter>( | 191 ? std::move(bitrate_smoother) : std::unique_ptr<SmoothingFilter>( |
190 // We choose 5sec as initial time constant due to empirical data. | 192 // We choose 5sec as initial time constant due to empirical data. |
191 new SmoothingFilterImpl(5000, config.clock))) { | 193 new SmoothingFilterImpl(5000, config.clock))) { |
192 RTC_CHECK(RecreateEncoderInstance(config)); | 194 RTC_CHECK(RecreateEncoderInstance(config)); |
193 } | 195 } |
194 | 196 |
195 AudioEncoderOpus::AudioEncoderOpus(const CodecInst& codec_inst) | 197 AudioEncoderOpus::AudioEncoderOpus(const CodecInst& codec_inst) |
196 : AudioEncoderOpus(CreateConfig(codec_inst), nullptr) {} | 198 : AudioEncoderOpus(CreateConfig(codec_inst), nullptr) {} |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 } | 263 } |
262 | 264 |
263 void AudioEncoderOpus::SetMaxPlaybackRate(int frequency_hz) { | 265 void AudioEncoderOpus::SetMaxPlaybackRate(int frequency_hz) { |
264 auto conf = config_; | 266 auto conf = config_; |
265 conf.max_playback_rate_hz = frequency_hz; | 267 conf.max_playback_rate_hz = frequency_hz; |
266 RTC_CHECK(RecreateEncoderInstance(conf)); | 268 RTC_CHECK(RecreateEncoderInstance(conf)); |
267 } | 269 } |
268 | 270 |
269 bool AudioEncoderOpus::EnableAudioNetworkAdaptor( | 271 bool AudioEncoderOpus::EnableAudioNetworkAdaptor( |
270 const std::string& config_string, | 272 const std::string& config_string, |
| 273 RtcEventLog* event_log, |
271 const Clock* clock) { | 274 const Clock* clock) { |
272 audio_network_adaptor_ = audio_network_adaptor_creator_(config_string, clock); | 275 audio_network_adaptor_ = |
| 276 audio_network_adaptor_creator_(config_string, event_log, clock); |
273 return audio_network_adaptor_.get() != nullptr; | 277 return audio_network_adaptor_.get() != nullptr; |
274 } | 278 } |
275 | 279 |
276 void AudioEncoderOpus::DisableAudioNetworkAdaptor() { | 280 void AudioEncoderOpus::DisableAudioNetworkAdaptor() { |
277 audio_network_adaptor_.reset(nullptr); | 281 audio_network_adaptor_.reset(nullptr); |
278 } | 282 } |
279 | 283 |
280 void AudioEncoderOpus::OnReceivedUplinkPacketLossFraction( | 284 void AudioEncoderOpus::OnReceivedUplinkPacketLossFraction( |
281 float uplink_packet_loss_fraction) { | 285 float uplink_packet_loss_fraction) { |
282 if (!audio_network_adaptor_) { | 286 if (!audio_network_adaptor_) { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 SetProjectedPacketLossRate(*config.uplink_packet_loss_fraction); | 523 SetProjectedPacketLossRate(*config.uplink_packet_loss_fraction); |
520 if (config.enable_dtx) | 524 if (config.enable_dtx) |
521 SetDtx(*config.enable_dtx); | 525 SetDtx(*config.enable_dtx); |
522 if (config.num_channels) | 526 if (config.num_channels) |
523 SetNumChannelsToEncode(*config.num_channels); | 527 SetNumChannelsToEncode(*config.num_channels); |
524 } | 528 } |
525 | 529 |
526 std::unique_ptr<AudioNetworkAdaptor> | 530 std::unique_ptr<AudioNetworkAdaptor> |
527 AudioEncoderOpus::DefaultAudioNetworkAdaptorCreator( | 531 AudioEncoderOpus::DefaultAudioNetworkAdaptorCreator( |
528 const std::string& config_string, | 532 const std::string& config_string, |
| 533 RtcEventLog* event_log, |
529 const Clock* clock) const { | 534 const Clock* clock) const { |
530 AudioNetworkAdaptorImpl::Config config; | 535 AudioNetworkAdaptorImpl::Config config; |
531 config.clock = clock; | 536 config.clock = clock; |
| 537 config.event_log = event_log; |
532 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl( | 538 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl( |
533 config, ControllerManagerImpl::Create( | 539 config, ControllerManagerImpl::Create( |
534 config_string, NumChannels(), supported_frame_lengths_ms(), | 540 config_string, NumChannels(), supported_frame_lengths_ms(), |
535 num_channels_to_encode_, next_frame_length_ms_, | 541 num_channels_to_encode_, next_frame_length_ms_, |
536 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock))); | 542 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock))); |
537 } | 543 } |
538 | 544 |
539 void AudioEncoderOpus::MaybeUpdateUplinkBandwidth() { | 545 void AudioEncoderOpus::MaybeUpdateUplinkBandwidth() { |
540 if (audio_network_adaptor_) { | 546 if (audio_network_adaptor_) { |
541 int64_t now_ms = rtc::TimeMillis(); | 547 int64_t now_ms = rtc::TimeMillis(); |
542 if (!bitrate_smoother_last_update_time_ || | 548 if (!bitrate_smoother_last_update_time_ || |
543 now_ms - *bitrate_smoother_last_update_time_ >= | 549 now_ms - *bitrate_smoother_last_update_time_ >= |
544 config_.uplink_bandwidth_update_interval_ms) { | 550 config_.uplink_bandwidth_update_interval_ms) { |
545 rtc::Optional<float> smoothed_bitrate = bitrate_smoother_->GetAverage(); | 551 rtc::Optional<float> smoothed_bitrate = bitrate_smoother_->GetAverage(); |
546 if (smoothed_bitrate) | 552 if (smoothed_bitrate) |
547 audio_network_adaptor_->SetUplinkBandwidth(*smoothed_bitrate); | 553 audio_network_adaptor_->SetUplinkBandwidth(*smoothed_bitrate); |
548 bitrate_smoother_last_update_time_ = rtc::Optional<int64_t>(now_ms); | 554 bitrate_smoother_last_update_time_ = rtc::Optional<int64_t>(now_ms); |
549 } | 555 } |
550 } | 556 } |
551 } | 557 } |
552 | 558 |
553 } // namespace webrtc | 559 } // namespace webrtc |
OLD | NEW |