Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 const uint8_t* packet, | 135 const uint8_t* packet, |
| 136 size_t length, | 136 size_t length, |
| 137 const PacketTime& packet_time) override; | 137 const PacketTime& packet_time) override; |
| 138 | 138 |
| 139 // Implements RecoveredPacketReceiver. | 139 // Implements RecoveredPacketReceiver. |
| 140 bool OnRecoveredPacket(const uint8_t* packet, size_t length) override; | 140 bool OnRecoveredPacket(const uint8_t* packet, size_t length) override; |
| 141 | 141 |
| 142 void SetBitrateConfig( | 142 void SetBitrateConfig( |
| 143 const webrtc::Call::Config::BitrateConfig& bitrate_config) override; | 143 const webrtc::Call::Config::BitrateConfig& bitrate_config) override; |
| 144 | 144 |
| 145 void SetBitrateConfigMask( | |
| 146 const webrtc::Call::Config::BitrateConfigMask& bitrate_config) override; | |
| 147 | |
| 145 void SignalChannelNetworkState(MediaType media, NetworkState state) override; | 148 void SignalChannelNetworkState(MediaType media, NetworkState state) override; |
| 146 | 149 |
| 147 void OnTransportOverheadChanged(MediaType media, | 150 void OnTransportOverheadChanged(MediaType media, |
| 148 int transport_overhead_per_packet) override; | 151 int transport_overhead_per_packet) override; |
| 149 | 152 |
| 150 void OnNetworkRouteChanged(const std::string& transport_name, | 153 void OnNetworkRouteChanged(const std::string& transport_name, |
| 151 const rtc::NetworkRoute& network_route) override; | 154 const rtc::NetworkRoute& network_route) override; |
| 152 | 155 |
| 153 void OnSentPacket(const rtc::SentPacket& sent_packet) override; | 156 void OnSentPacket(const rtc::SentPacket& sent_packet) override; |
| 154 | 157 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 181 size_t length, | 184 size_t length, |
| 182 const PacketTime& packet_time) | 185 const PacketTime& packet_time) |
| 183 SHARED_LOCKS_REQUIRED(receive_crit_); | 186 SHARED_LOCKS_REQUIRED(receive_crit_); |
| 184 | 187 |
| 185 void UpdateSendHistograms(int64_t first_sent_packet_ms) | 188 void UpdateSendHistograms(int64_t first_sent_packet_ms) |
| 186 EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); | 189 EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); |
| 187 void UpdateReceiveHistograms(); | 190 void UpdateReceiveHistograms(); |
| 188 void UpdateHistograms(); | 191 void UpdateHistograms(); |
| 189 void UpdateAggregateNetworkState(); | 192 void UpdateAggregateNetworkState(); |
| 190 | 193 |
| 194 // These values only get set if there is actually something to change. | |
| 195 struct BitrateUpdate { | |
| 196 rtc::Optional<int> min_bitrate_bps; | |
| 197 rtc::Optional<int> start_bitrate_bps; | |
| 198 rtc::Optional<int> max_bitrate_bps; | |
| 199 }; | |
| 200 | |
| 201 // Applies update to the BitrateConfig cached in |config_| and updates the | |
| 202 // congestion controller if update is not empty. | |
| 203 void UpdateCurrentBitrateConfig(const BitrateUpdate& update); | |
| 204 | |
| 191 Clock* const clock_; | 205 Clock* const clock_; |
| 192 | 206 |
| 193 const int num_cpu_cores_; | 207 const int num_cpu_cores_; |
| 194 const std::unique_ptr<ProcessThread> module_process_thread_; | 208 const std::unique_ptr<ProcessThread> module_process_thread_; |
| 195 const std::unique_ptr<ProcessThread> pacer_thread_; | 209 const std::unique_ptr<ProcessThread> pacer_thread_; |
| 196 const std::unique_ptr<CallStats> call_stats_; | 210 const std::unique_ptr<CallStats> call_stats_; |
| 197 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; | 211 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; |
| 198 Call::Config config_; | 212 Call::Config config_; |
| 199 rtc::ThreadChecker configuration_thread_checker_; | 213 rtc::ThreadChecker configuration_thread_checker_; |
| 200 | 214 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; | 289 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; |
| 276 ReceiveSideCongestionController receive_side_cc_; | 290 ReceiveSideCongestionController receive_side_cc_; |
| 277 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; | 291 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; |
| 278 const int64_t start_ms_; | 292 const int64_t start_ms_; |
| 279 // TODO(perkj): |worker_queue_| is supposed to replace | 293 // TODO(perkj): |worker_queue_| is supposed to replace |
| 280 // |module_process_thread_|. | 294 // |module_process_thread_|. |
| 281 // |worker_queue| is defined last to ensure all pending tasks are cancelled | 295 // |worker_queue| is defined last to ensure all pending tasks are cancelled |
| 282 // and deleted before any other members. | 296 // and deleted before any other members. |
| 283 rtc::TaskQueue worker_queue_; | 297 rtc::TaskQueue worker_queue_; |
| 284 | 298 |
| 299 // The config mask set by SetBitrateConfigMask. | |
| 300 // 0 <= min <= start <= max | |
| 301 Config::BitrateConfigMask bitrate_config_mask_; | |
| 302 | |
| 303 // The config set by SetBitrateConfig. | |
| 304 // min >= 0, start != 0, max == -1 || max > 0 | |
| 305 Config::BitrateConfig base_bitrate_config_; | |
| 306 | |
| 285 RTC_DISALLOW_COPY_AND_ASSIGN(Call); | 307 RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
| 286 }; | 308 }; |
| 287 } // namespace internal | 309 } // namespace internal |
| 288 | 310 |
| 289 std::string Call::Stats::ToString(int64_t time_ms) const { | 311 std::string Call::Stats::ToString(int64_t time_ms) const { |
| 290 std::stringstream ss; | 312 std::stringstream ss; |
| 291 ss << "Call stats: " << time_ms << ", {"; | 313 ss << "Call stats: " << time_ms << ", {"; |
| 292 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; | 314 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; |
| 293 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; | 315 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; |
| 294 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; | 316 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 received_audio_bytes_per_second_counter_(clock_, nullptr, true), | 352 received_audio_bytes_per_second_counter_(clock_, nullptr, true), |
| 331 received_video_bytes_per_second_counter_(clock_, nullptr, true), | 353 received_video_bytes_per_second_counter_(clock_, nullptr, true), |
| 332 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), | 354 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), |
| 333 min_allocated_send_bitrate_bps_(0), | 355 min_allocated_send_bitrate_bps_(0), |
| 334 configured_max_padding_bitrate_bps_(0), | 356 configured_max_padding_bitrate_bps_(0), |
| 335 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), | 357 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), |
| 336 pacer_bitrate_kbps_counter_(clock_, nullptr, true), | 358 pacer_bitrate_kbps_counter_(clock_, nullptr, true), |
| 337 receive_side_cc_(clock_, transport_send->packet_router()), | 359 receive_side_cc_(clock_, transport_send->packet_router()), |
| 338 video_send_delay_stats_(new SendDelayStats(clock_)), | 360 video_send_delay_stats_(new SendDelayStats(clock_)), |
| 339 start_ms_(clock_->TimeInMilliseconds()), | 361 start_ms_(clock_->TimeInMilliseconds()), |
| 340 worker_queue_("call_worker_queue") { | 362 worker_queue_("call_worker_queue"), |
| 363 base_bitrate_config_(config.bitrate_config) { | |
| 341 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 364 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 342 RTC_DCHECK(config.event_log != nullptr); | 365 RTC_DCHECK(config.event_log != nullptr); |
| 343 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); | 366 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
| 344 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, | 367 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, |
| 345 config.bitrate_config.min_bitrate_bps); | 368 config.bitrate_config.min_bitrate_bps); |
| 346 if (config.bitrate_config.max_bitrate_bps != -1) { | 369 if (config.bitrate_config.max_bitrate_bps != -1) { |
| 347 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, | 370 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, |
| 348 config.bitrate_config.start_bitrate_bps); | 371 config.bitrate_config.start_bitrate_bps); |
| 349 } | 372 } |
| 350 Trace::CreateTrace(); | 373 Trace::CreateTrace(); |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 855 rtc::CritScope cs(&bitrate_crit_); | 878 rtc::CritScope cs(&bitrate_crit_); |
| 856 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; | 879 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; |
| 857 } | 880 } |
| 858 return stats; | 881 return stats; |
| 859 } | 882 } |
| 860 | 883 |
| 861 void Call::SetBitrateConfig( | 884 void Call::SetBitrateConfig( |
| 862 const webrtc::Call::Config::BitrateConfig& bitrate_config) { | 885 const webrtc::Call::Config::BitrateConfig& bitrate_config) { |
| 863 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); | 886 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); |
| 864 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 887 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 888 | |
| 865 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); | 889 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); |
| 866 if (bitrate_config.max_bitrate_bps != -1) | 890 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); |
| 891 if (bitrate_config.max_bitrate_bps != -1) { | |
| 867 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); | 892 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); |
| 868 if (config_.bitrate_config.min_bitrate_bps == | 893 } |
| 869 bitrate_config.min_bitrate_bps && | 894 |
| 870 (bitrate_config.start_bitrate_bps <= 0 || | 895 BitrateUpdate update; |
| 871 config_.bitrate_config.start_bitrate_bps == | 896 |
| 872 bitrate_config.start_bitrate_bps) && | 897 const int min = bitrate_config.min_bitrate_bps; |
| 873 config_.bitrate_config.max_bitrate_bps == | 898 if (min != base_bitrate_config_.min_bitrate_bps) { |
| 874 bitrate_config.max_bitrate_bps) { | 899 base_bitrate_config_.min_bitrate_bps = min; |
| 875 // Nothing new to set, early abort to avoid encoder reconfigurations. | 900 if (!bitrate_config_mask_.min_bitrate_bps || |
| 901 min > *bitrate_config_mask_.min_bitrate_bps) { | |
|
Taylor Brandstetter
2017/05/11 04:16:15
The code would be simpler if instead of "see if co
Zach Stein
2017/05/11 21:43:09
For c->SetBitrateConfig(1,2,3); c->SetBitrateConfi
| |
| 902 update.min_bitrate_bps = rtc::Optional<int>(min); | |
| 903 } | |
| 904 } | |
| 905 | |
| 906 const int start = bitrate_config.start_bitrate_bps; | |
| 907 if (start != -1) { | |
| 908 base_bitrate_config_.start_bitrate_bps = start; | |
| 909 // TODO(zstein): Do we only want to update if the start rate changed here? | |
|
Taylor Brandstetter
2017/05/11 04:16:15
Yes; there should be a test for that too.
Zach Stein
2017/05/11 21:43:09
Done.
Test is in this other CL (the 2 Elides test
| |
| 910 update.start_bitrate_bps = rtc::Optional<int>(start); | |
| 911 } | |
| 912 const int max = bitrate_config.max_bitrate_bps; | |
| 913 if (max != -1 && max != base_bitrate_config_.max_bitrate_bps) { | |
| 914 base_bitrate_config_.max_bitrate_bps = max; | |
| 915 if (!bitrate_config_mask_.max_bitrate_bps || | |
| 916 max < *bitrate_config_mask_.max_bitrate_bps) { | |
| 917 update.max_bitrate_bps = rtc::Optional<int>(max); | |
| 918 } | |
| 919 } | |
| 920 | |
| 921 UpdateCurrentBitrateConfig(update); | |
| 922 } | |
| 923 | |
| 924 void Call::SetBitrateConfigMask( | |
| 925 const webrtc::Call::Config::BitrateConfigMask& mask) { | |
| 926 TRACE_EVENT0("webrtc", "Call::SetBitrateConfigMask"); | |
| 927 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | |
| 928 | |
| 929 bitrate_config_mask_ = mask; | |
| 930 BitrateUpdate update; | |
| 931 | |
| 932 if (mask.min_bitrate_bps && | |
| 933 *mask.min_bitrate_bps > base_bitrate_config_.min_bitrate_bps) { | |
| 934 update.min_bitrate_bps = mask.min_bitrate_bps; | |
| 935 } | |
| 936 update.start_bitrate_bps = mask.start_bitrate_bps; | |
| 937 if (mask.max_bitrate_bps && | |
| 938 (base_bitrate_config_.max_bitrate_bps == -1 || | |
| 939 *mask.max_bitrate_bps < base_bitrate_config_.max_bitrate_bps)) { | |
| 940 update.max_bitrate_bps = mask.max_bitrate_bps; | |
| 941 } | |
| 942 | |
| 943 UpdateCurrentBitrateConfig(update); | |
| 944 } | |
| 945 | |
| 946 void Call::UpdateCurrentBitrateConfig(const BitrateUpdate& update) { | |
| 947 if (!update.min_bitrate_bps && !update.start_bitrate_bps && | |
| 948 !update.max_bitrate_bps) { | |
|
Taylor Brandstetter
2017/05/11 04:16:15
Getting into more corner-casey territory, but you
Zach Stein
2017/05/11 21:43:09
Maybe that is enough of an edge case that we don't
| |
| 949 // Nothing to update. | |
| 876 return; | 950 return; |
| 877 } | 951 } |
| 878 config_.bitrate_config.min_bitrate_bps = bitrate_config.min_bitrate_bps; | 952 |
| 879 // Start bitrate of -1 means we should keep the old bitrate, which there is | 953 Config::BitrateConfig updated; |
| 880 // no point in remembering for the future. | 954 const Config::BitrateConfig& current = config_.bitrate_config; |
| 881 if (bitrate_config.start_bitrate_bps > 0) | 955 updated.min_bitrate_bps = |
| 882 config_.bitrate_config.start_bitrate_bps = bitrate_config.start_bitrate_bps; | 956 update.min_bitrate_bps.value_or(current.min_bitrate_bps); |
| 883 config_.bitrate_config.max_bitrate_bps = bitrate_config.max_bitrate_bps; | 957 updated.start_bitrate_bps = |
| 884 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); | 958 update.start_bitrate_bps.value_or(current.start_bitrate_bps); |
| 959 updated.max_bitrate_bps = | |
| 960 update.max_bitrate_bps.value_or(current.max_bitrate_bps); | |
| 961 | |
| 962 // TODO(zstein): This clamp logic is different than send_side_cc's (moves min | |
| 963 // instead of max, allows start to be greather than min) - check that it is a | |
| 964 // sensible difference. | |
| 965 | |
| 966 // Clamp min under max and start under max and above min. | |
| 967 if (updated.max_bitrate_bps != -1) { | |
| 968 updated.min_bitrate_bps = | |
| 969 std::min(updated.min_bitrate_bps, updated.max_bitrate_bps); | |
| 970 } | |
| 971 updated.start_bitrate_bps = | |
| 972 cricket::MinPositive(updated.start_bitrate_bps, updated.max_bitrate_bps); | |
| 973 updated.start_bitrate_bps = | |
| 974 std::max(updated.start_bitrate_bps, updated.min_bitrate_bps); | |
| 975 | |
| 885 transport_send_->send_side_cc()->SetBweBitrates( | 976 transport_send_->send_side_cc()->SetBweBitrates( |
| 886 bitrate_config.min_bitrate_bps, bitrate_config.start_bitrate_bps, | 977 updated.min_bitrate_bps, |
| 887 bitrate_config.max_bitrate_bps); | 978 update.start_bitrate_bps ? updated.start_bitrate_bps : -1, |
| 979 updated.max_bitrate_bps); | |
| 980 config_.bitrate_config = updated; | |
| 888 } | 981 } |
| 889 | 982 |
| 890 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { | 983 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { |
| 891 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 984 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 892 switch (media) { | 985 switch (media) { |
| 893 case MediaType::AUDIO: | 986 case MediaType::AUDIO: |
| 894 audio_network_state_ = state; | 987 audio_network_state_ = state; |
| 895 break; | 988 break; |
| 896 case MediaType::VIDEO: | 989 case MediaType::VIDEO: |
| 897 video_network_state_ = state; | 990 video_network_state_ = state; |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1288 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { | 1381 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { |
| 1289 receive_side_cc_.OnReceivedPacket( | 1382 receive_side_cc_.OnReceivedPacket( |
| 1290 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), | 1383 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), |
| 1291 header); | 1384 header); |
| 1292 } | 1385 } |
| 1293 } | 1386 } |
| 1294 | 1387 |
| 1295 } // namespace internal | 1388 } // namespace internal |
| 1296 | 1389 |
| 1297 } // namespace webrtc | 1390 } // namespace webrtc |
| OLD | NEW |