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 |
11 #include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h" | 11 #include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <iterator> | 14 #include <iterator> |
15 #include <utility> | 15 #include <utility> |
16 | 16 |
17 #include "webrtc/base/arraysize.h" | 17 #include "webrtc/base/arraysize.h" |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
20 #include "webrtc/base/numerics/exp_filter.h" | 20 #include "webrtc/base/numerics/exp_filter.h" |
21 #include "webrtc/base/protobuf_utils.h" | 21 #include "webrtc/base/protobuf_utils.h" |
22 #include "webrtc/base/safe_conversions.h" | 22 #include "webrtc/base/safe_conversions.h" |
| 23 #include "webrtc/base/safe_minmax.h" |
23 #include "webrtc/base/string_to_number.h" | 24 #include "webrtc/base/string_to_number.h" |
24 #include "webrtc/base/timeutils.h" | 25 #include "webrtc/base/timeutils.h" |
25 #include "webrtc/common_types.h" | 26 #include "webrtc/common_types.h" |
26 #include "webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adapto
r_impl.h" | 27 #include "webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adapto
r_impl.h" |
27 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h
" | 28 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h
" |
28 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" | 29 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" |
29 #include "webrtc/system_wrappers/include/field_trial.h" | 30 #include "webrtc/system_wrappers/include/field_trial.h" |
30 | 31 |
31 namespace webrtc { | 32 namespace webrtc { |
32 | 33 |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 float opt_loss_rate = OptimizePacketLossRate(fraction, packet_loss_rate_); | 684 float opt_loss_rate = OptimizePacketLossRate(fraction, packet_loss_rate_); |
684 if (packet_loss_rate_ != opt_loss_rate) { | 685 if (packet_loss_rate_ != opt_loss_rate) { |
685 packet_loss_rate_ = opt_loss_rate; | 686 packet_loss_rate_ = opt_loss_rate; |
686 RTC_CHECK_EQ( | 687 RTC_CHECK_EQ( |
687 0, WebRtcOpus_SetPacketLossRate( | 688 0, WebRtcOpus_SetPacketLossRate( |
688 inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5))); | 689 inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5))); |
689 } | 690 } |
690 } | 691 } |
691 | 692 |
692 void AudioEncoderOpus::SetTargetBitrate(int bits_per_second) { | 693 void AudioEncoderOpus::SetTargetBitrate(int bits_per_second) { |
693 config_.bitrate_bps = rtc::Optional<int>(std::max( | 694 config_.bitrate_bps = rtc::Optional<int>(rtc::SafeClamp<int>( |
694 std::min(bits_per_second, kOpusMaxBitrateBps), kOpusMinBitrateBps)); | 695 kOpusMinBitrateBps, kOpusMaxBitrateBps, bits_per_second)); |
695 RTC_DCHECK(config_.IsOk()); | 696 RTC_DCHECK(config_.IsOk()); |
696 RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config_.GetBitrateBps())); | 697 RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config_.GetBitrateBps())); |
697 const auto new_complexity = config_.GetNewComplexity(); | 698 const auto new_complexity = config_.GetNewComplexity(); |
698 if (new_complexity && complexity_ != *new_complexity) { | 699 if (new_complexity && complexity_ != *new_complexity) { |
699 complexity_ = *new_complexity; | 700 complexity_ = *new_complexity; |
700 RTC_CHECK_EQ(0, WebRtcOpus_SetComplexity(inst_, complexity_)); | 701 RTC_CHECK_EQ(0, WebRtcOpus_SetComplexity(inst_, complexity_)); |
701 } | 702 } |
702 } | 703 } |
703 | 704 |
704 void AudioEncoderOpus::ApplyAudioNetworkAdaptor() { | 705 void AudioEncoderOpus::ApplyAudioNetworkAdaptor() { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 config_.uplink_bandwidth_update_interval_ms) { | 743 config_.uplink_bandwidth_update_interval_ms) { |
743 rtc::Optional<float> smoothed_bitrate = bitrate_smoother_->GetAverage(); | 744 rtc::Optional<float> smoothed_bitrate = bitrate_smoother_->GetAverage(); |
744 if (smoothed_bitrate) | 745 if (smoothed_bitrate) |
745 audio_network_adaptor_->SetUplinkBandwidth(*smoothed_bitrate); | 746 audio_network_adaptor_->SetUplinkBandwidth(*smoothed_bitrate); |
746 bitrate_smoother_last_update_time_ = rtc::Optional<int64_t>(now_ms); | 747 bitrate_smoother_last_update_time_ = rtc::Optional<int64_t>(now_ms); |
747 } | 748 } |
748 } | 749 } |
749 } | 750 } |
750 | 751 |
751 } // namespace webrtc | 752 } // namespace webrtc |
OLD | NEW |