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

Side by Side Diff: webrtc/call/call.cc

Issue 2793913008: Add PeerConnectionInterface::UpdateCallBitrate. (Closed)
Patch Set: move start DCHECK in SetBitrateConfig with other DCHECKs Created 3 years, 8 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) 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 const uint8_t* packet, 173 const uint8_t* packet,
174 size_t length, 174 size_t length,
175 const PacketTime& packet_time) override; 175 const PacketTime& packet_time) override;
176 176
177 // Implements RecoveredPacketReceiver. 177 // Implements RecoveredPacketReceiver.
178 bool OnRecoveredPacket(const uint8_t* packet, size_t length) override; 178 bool OnRecoveredPacket(const uint8_t* packet, size_t length) override;
179 179
180 void SetBitrateConfig( 180 void SetBitrateConfig(
181 const webrtc::Call::Config::BitrateConfig& bitrate_config) override; 181 const webrtc::Call::Config::BitrateConfig& bitrate_config) override;
182 182
183 void SetBitrateConfigMask(
184 const webrtc::Call::Config::BitrateConfigMask& bitrate_config) override;
185
186 // Updates the BitrateConfig cached in |config_| by combining
187 // |base_bitrate_config_| and |bitrate_config_mask_| and udpates the
Taylor Brandstetter 2017/04/19 01:06:54 Typo, "udpates"
Zach Stein 2017/04/20 20:48:00 Done.
188 // congestion controller if the combined config changed.
189 void UpdateCurrentBitrateConfig();
190
183 void SignalChannelNetworkState(MediaType media, NetworkState state) override; 191 void SignalChannelNetworkState(MediaType media, NetworkState state) override;
184 192
185 void OnTransportOverheadChanged(MediaType media, 193 void OnTransportOverheadChanged(MediaType media,
186 int transport_overhead_per_packet) override; 194 int transport_overhead_per_packet) override;
187 195
188 void OnNetworkRouteChanged(const std::string& transport_name, 196 void OnNetworkRouteChanged(const std::string& transport_name,
189 const rtc::NetworkRoute& network_route) override; 197 const rtc::NetworkRoute& network_route) override;
190 198
191 void OnSentPacket(const rtc::SentPacket& sent_packet) override; 199 void OnSentPacket(const rtc::SentPacket& sent_packet) override;
192 200
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 VieRemb remb_; 322 VieRemb remb_;
315 ReceiveSideCongestionController receive_side_cc_; 323 ReceiveSideCongestionController receive_side_cc_;
316 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; 324 const std::unique_ptr<SendDelayStats> video_send_delay_stats_;
317 const int64_t start_ms_; 325 const int64_t start_ms_;
318 // TODO(perkj): |worker_queue_| is supposed to replace 326 // TODO(perkj): |worker_queue_| is supposed to replace
319 // |module_process_thread_|. 327 // |module_process_thread_|.
320 // |worker_queue| is defined last to ensure all pending tasks are cancelled 328 // |worker_queue| is defined last to ensure all pending tasks are cancelled
321 // and deleted before any other members. 329 // and deleted before any other members.
322 rtc::TaskQueue worker_queue_; 330 rtc::TaskQueue worker_queue_;
323 331
332 // The config mask set by SetBitrateConfigMask.
333 Config::BitrateConfigMask bitrate_config_mask_;
334
335 // The config set by SetBitrateConfig.
336 Config::BitrateConfig base_bitrate_config_;
337
324 RTC_DISALLOW_COPY_AND_ASSIGN(Call); 338 RTC_DISALLOW_COPY_AND_ASSIGN(Call);
325 }; 339 };
326 } // namespace internal 340 } // namespace internal
327 341
328 std::string Call::Stats::ToString(int64_t time_ms) const { 342 std::string Call::Stats::ToString(int64_t time_ms) const {
329 std::stringstream ss; 343 std::stringstream ss;
330 ss << "Call stats: " << time_ms << ", {"; 344 ss << "Call stats: " << time_ms << ", {";
331 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; 345 ss << "send_bw_bps: " << send_bandwidth_bps << ", ";
332 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; 346 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", ";
333 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; 347 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", ";
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), 381 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true),
368 min_allocated_send_bitrate_bps_(0), 382 min_allocated_send_bitrate_bps_(0),
369 configured_max_padding_bitrate_bps_(0), 383 configured_max_padding_bitrate_bps_(0),
370 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), 384 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true),
371 pacer_bitrate_kbps_counter_(clock_, nullptr, true), 385 pacer_bitrate_kbps_counter_(clock_, nullptr, true),
372 transport_send_(std::move(transport_send)), 386 transport_send_(std::move(transport_send)),
373 remb_(clock_), 387 remb_(clock_),
374 receive_side_cc_(clock_, &remb_, transport_send_->packet_router()), 388 receive_side_cc_(clock_, &remb_, transport_send_->packet_router()),
375 video_send_delay_stats_(new SendDelayStats(clock_)), 389 video_send_delay_stats_(new SendDelayStats(clock_)),
376 start_ms_(clock_->TimeInMilliseconds()), 390 start_ms_(clock_->TimeInMilliseconds()),
377 worker_queue_("call_worker_queue") { 391 worker_queue_("call_worker_queue"),
392 base_bitrate_config_(config.bitrate_config) {
378 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 393 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
379 RTC_DCHECK(config.event_log != nullptr); 394 RTC_DCHECK(config.event_log != nullptr);
380 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); 395 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0);
381 RTC_DCHECK_GT(config.bitrate_config.start_bitrate_bps, 396 RTC_DCHECK_GT(config.bitrate_config.start_bitrate_bps,
382 config.bitrate_config.min_bitrate_bps); 397 config.bitrate_config.min_bitrate_bps);
383 if (config.bitrate_config.max_bitrate_bps != -1) { 398 if (config.bitrate_config.max_bitrate_bps != -1) {
384 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, 399 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps,
385 config.bitrate_config.start_bitrate_bps); 400 config.bitrate_config.start_bitrate_bps);
386 } 401 }
387 Trace::CreateTrace(); 402 Trace::CreateTrace();
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 rtc::CritScope cs(&bitrate_crit_); 905 rtc::CritScope cs(&bitrate_crit_);
891 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; 906 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_;
892 } 907 }
893 return stats; 908 return stats;
894 } 909 }
895 910
896 void Call::SetBitrateConfig( 911 void Call::SetBitrateConfig(
897 const webrtc::Call::Config::BitrateConfig& bitrate_config) { 912 const webrtc::Call::Config::BitrateConfig& bitrate_config) {
898 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); 913 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig");
899 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 914 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
915
900 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); 916 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0);
901 if (bitrate_config.max_bitrate_bps != -1) 917 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0);
918 if (bitrate_config.max_bitrate_bps != -1) {
902 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); 919 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0);
903 if (config_.bitrate_config.min_bitrate_bps == 920 }
904 bitrate_config.min_bitrate_bps && 921
905 (bitrate_config.start_bitrate_bps <= 0 || 922 const bool same_min =
906 config_.bitrate_config.start_bitrate_bps == 923 base_bitrate_config_.min_bitrate_bps == bitrate_config.min_bitrate_bps;
907 bitrate_config.start_bitrate_bps) && 924 const bool same_start = base_bitrate_config_.start_bitrate_bps ==
908 config_.bitrate_config.max_bitrate_bps == 925 bitrate_config.start_bitrate_bps;
909 bitrate_config.max_bitrate_bps) { 926 const bool same_max =
927 base_bitrate_config_.max_bitrate_bps == bitrate_config.max_bitrate_bps;
928 if (same_min && (bitrate_config.start_bitrate_bps <= 0 || same_start) &&
929 same_max) {
910 // Nothing new to set, early abort to avoid encoder reconfigurations. 930 // Nothing new to set, early abort to avoid encoder reconfigurations.
911 return; 931 return;
912 } 932 }
913 config_.bitrate_config.min_bitrate_bps = bitrate_config.min_bitrate_bps; 933
934 base_bitrate_config_.min_bitrate_bps = bitrate_config.min_bitrate_bps;
914 // Start bitrate of -1 means we should keep the old bitrate, which there is 935 // Start bitrate of -1 means we should keep the old bitrate, which there is
915 // no point in remembering for the future. 936 // no point in remembering for the future.
916 if (bitrate_config.start_bitrate_bps > 0) 937 if (bitrate_config.start_bitrate_bps > 0) {
917 config_.bitrate_config.start_bitrate_bps = bitrate_config.start_bitrate_bps; 938 base_bitrate_config_.start_bitrate_bps = bitrate_config.start_bitrate_bps;
918 config_.bitrate_config.max_bitrate_bps = bitrate_config.max_bitrate_bps; 939 }
919 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); 940 base_bitrate_config_.max_bitrate_bps = bitrate_config.max_bitrate_bps;
920 transport_send_->send_side_cc()->SetBweBitrates( 941
921 bitrate_config.min_bitrate_bps, bitrate_config.start_bitrate_bps, 942 UpdateCurrentBitrateConfig();
922 bitrate_config.max_bitrate_bps); 943 }
944
945 void Call::SetBitrateConfigMask(
946 const webrtc::Call::Config::BitrateConfigMask& mask) {
947 TRACE_EVENT0("webrtc", "Call::SetBitrateConfigMask");
948 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
949
950 bitrate_config_mask_ = mask;
951
952 UpdateCurrentBitrateConfig();
953 }
954
955 void Call::UpdateCurrentBitrateConfig() {
956 Config::BitrateConfig masked;
957 masked.min_bitrate_bps = bitrate_config_mask_.min_bitrate_bps.value_or(
958 base_bitrate_config_.min_bitrate_bps);
959 masked.start_bitrate_bps = bitrate_config_mask_.start_bitrate_bps.value_or(
960 base_bitrate_config_.start_bitrate_bps);
961
962 const rtc::Optional<int> mask_max = bitrate_config_mask_.max_bitrate_bps;
Taylor Brandstetter 2017/04/19 01:06:54 nit: Can be const ref.
Zach Stein 2017/04/20 20:48:00 Done.
963 const int base_max = base_bitrate_config_.max_bitrate_bps;
964 const bool mask_has_max = static_cast<bool>(mask_max);
965 const bool base_has_max = base_max != -1;
966 if (mask_has_max && base_has_max) {
967 masked.max_bitrate_bps = std::min(*mask_max, base_max);
968 } else if (mask_has_max) {
969 masked.max_bitrate_bps = *mask_max;
970 } else if (base_has_max) {
971 masked.max_bitrate_bps = base_max;
972 } else {
973 masked.max_bitrate_bps = -1;
974 }
Taylor Brandstetter 2017/04/19 01:06:53 nit: I think this code could be simplified. Exampl
Zach Stein 2017/04/20 20:48:00 Didn't know about MinPositive (defined in mediacha
Taylor Brandstetter 2017/04/21 10:14:07 Acknowledged.
975
976 Config::BitrateConfig& current = config_.bitrate_config;
977 if (masked.min_bitrate_bps == current.min_bitrate_bps &&
978 masked.start_bitrate_bps == current.start_bitrate_bps &&
Taylor Brandstetter 2017/04/19 01:06:54 Same comment as before: shouldn't this be checking
Zach Stein 2017/04/20 20:48:00 I was avoiding changing the behavior of SetBitrate
Taylor Brandstetter 2017/04/21 10:14:07 But I believe it does change the behavior of SetBi
979 masked.max_bitrate_bps == current.max_bitrate_bps) {
980 return;
981 }
982
983 RTC_DCHECK_GT(masked.min_bitrate_bps, 0);
984 RTC_DCHECK(masked.start_bitrate_bps <= 0 ||
985 masked.start_bitrate_bps >= masked.min_bitrate_bps);
986 RTC_DCHECK(masked.max_bitrate_bps == -1 ||
987 masked.max_bitrate_bps >= masked.start_bitrate_bps);
988
989 current = masked;
990 transport_send_->send_side_cc()->SetBweBitrates(current.min_bitrate_bps,
991 current.start_bitrate_bps,
992 current.max_bitrate_bps);
923 } 993 }
924 994
925 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { 995 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) {
926 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 996 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
927 switch (media) { 997 switch (media) {
928 case MediaType::AUDIO: 998 case MediaType::AUDIO:
929 audio_network_state_ = state; 999 audio_network_state_ = state;
930 break; 1000 break;
931 case MediaType::VIDEO: 1001 case MediaType::VIDEO:
932 video_network_state_ = state; 1002 video_network_state_ = state;
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { 1395 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) {
1326 receive_side_cc_.OnReceivedPacket( 1396 receive_side_cc_.OnReceivedPacket(
1327 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), 1397 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(),
1328 header); 1398 header);
1329 } 1399 }
1330 } 1400 }
1331 1401
1332 } // namespace internal 1402 } // namespace internal
1333 1403
1334 } // namespace webrtc 1404 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698