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

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

Issue 2793913008: Add PeerConnectionInterface::UpdateCallBitrate. (Closed)
Patch Set: add a todo about de-duplicating bitrate mask structs 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 cached |masked_bitrate_config_| struct and updates the
187 // congestion controller if the masked config changed.
188 void UpdateMaskedBitrateConfig();
189
183 void SignalChannelNetworkState(MediaType media, NetworkState state) override; 190 void SignalChannelNetworkState(MediaType media, NetworkState state) override;
184 191
185 void OnTransportOverheadChanged(MediaType media, 192 void OnTransportOverheadChanged(MediaType media,
186 int transport_overhead_per_packet) override; 193 int transport_overhead_per_packet) override;
187 194
188 void OnNetworkRouteChanged(const std::string& transport_name, 195 void OnNetworkRouteChanged(const std::string& transport_name,
189 const rtc::NetworkRoute& network_route) override; 196 const rtc::NetworkRoute& network_route) override;
190 197
191 void OnSentPacket(const rtc::SentPacket& sent_packet) override; 198 void OnSentPacket(const rtc::SentPacket& sent_packet) override;
192 199
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 VieRemb remb_; 321 VieRemb remb_;
315 ReceiveSideCongestionController receive_side_cc_; 322 ReceiveSideCongestionController receive_side_cc_;
316 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; 323 const std::unique_ptr<SendDelayStats> video_send_delay_stats_;
317 const int64_t start_ms_; 324 const int64_t start_ms_;
318 // TODO(perkj): |worker_queue_| is supposed to replace 325 // TODO(perkj): |worker_queue_| is supposed to replace
319 // |module_process_thread_|. 326 // |module_process_thread_|.
320 // |worker_queue| is defined last to ensure all pending tasks are cancelled 327 // |worker_queue| is defined last to ensure all pending tasks are cancelled
321 // and deleted before any other members. 328 // and deleted before any other members.
322 rtc::TaskQueue worker_queue_; 329 rtc::TaskQueue worker_queue_;
323 330
331 // The mask is kept so it can be re-applied if SetBitrateConfig is called.
332 Config::BitrateConfigMask bitrate_config_mask_;
333
334 // This is the BitrateConfig given to the congestion controller. We cache it
335 // here to avoid resets in the congestion controller when nothing has actually
336 // changed.
337 Config::BitrateConfig masked_bitrate_config_;
338
324 RTC_DISALLOW_COPY_AND_ASSIGN(Call); 339 RTC_DISALLOW_COPY_AND_ASSIGN(Call);
325 }; 340 };
326 } // namespace internal 341 } // namespace internal
327 342
328 std::string Call::Stats::ToString(int64_t time_ms) const { 343 std::string Call::Stats::ToString(int64_t time_ms) const {
329 std::stringstream ss; 344 std::stringstream ss;
330 ss << "Call stats: " << time_ms << ", {"; 345 ss << "Call stats: " << time_ms << ", {";
331 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; 346 ss << "send_bw_bps: " << send_bandwidth_bps << ", ";
332 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; 347 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", ";
333 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; 348 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), 382 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true),
368 min_allocated_send_bitrate_bps_(0), 383 min_allocated_send_bitrate_bps_(0),
369 configured_max_padding_bitrate_bps_(0), 384 configured_max_padding_bitrate_bps_(0),
370 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), 385 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true),
371 pacer_bitrate_kbps_counter_(clock_, nullptr, true), 386 pacer_bitrate_kbps_counter_(clock_, nullptr, true),
372 transport_send_(std::move(transport_send)), 387 transport_send_(std::move(transport_send)),
373 remb_(clock_), 388 remb_(clock_),
374 receive_side_cc_(clock_, &remb_, transport_send_->packet_router()), 389 receive_side_cc_(clock_, &remb_, transport_send_->packet_router()),
375 video_send_delay_stats_(new SendDelayStats(clock_)), 390 video_send_delay_stats_(new SendDelayStats(clock_)),
376 start_ms_(clock_->TimeInMilliseconds()), 391 start_ms_(clock_->TimeInMilliseconds()),
377 worker_queue_("call_worker_queue") { 392 worker_queue_("call_worker_queue"),
393 masked_bitrate_config_(config.bitrate_config) {
378 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 394 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
379 RTC_DCHECK(config.event_log != nullptr); 395 RTC_DCHECK(config.event_log != nullptr);
380 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); 396 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0);
381 RTC_DCHECK_GT(config.bitrate_config.start_bitrate_bps, 397 RTC_DCHECK_GT(config.bitrate_config.start_bitrate_bps,
382 config.bitrate_config.min_bitrate_bps); 398 config.bitrate_config.min_bitrate_bps);
383 if (config.bitrate_config.max_bitrate_bps != -1) { 399 if (config.bitrate_config.max_bitrate_bps != -1) {
384 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, 400 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps,
385 config.bitrate_config.start_bitrate_bps); 401 config.bitrate_config.start_bitrate_bps);
386 } 402 }
387 Trace::CreateTrace(); 403 Trace::CreateTrace();
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 rtc::CritScope cs(&bitrate_crit_); 906 rtc::CritScope cs(&bitrate_crit_);
891 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; 907 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_;
892 } 908 }
893 return stats; 909 return stats;
894 } 910 }
895 911
896 void Call::SetBitrateConfig( 912 void Call::SetBitrateConfig(
897 const webrtc::Call::Config::BitrateConfig& bitrate_config) { 913 const webrtc::Call::Config::BitrateConfig& bitrate_config) {
898 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); 914 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig");
899 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 915 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
916
900 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); 917 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0);
901 if (bitrate_config.max_bitrate_bps != -1) 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);
920
903 if (config_.bitrate_config.min_bitrate_bps == 921 if (config_.bitrate_config.min_bitrate_bps ==
904 bitrate_config.min_bitrate_bps && 922 bitrate_config.min_bitrate_bps &&
905 (bitrate_config.start_bitrate_bps <= 0 || 923 (bitrate_config.start_bitrate_bps <= 0 ||
906 config_.bitrate_config.start_bitrate_bps == 924 config_.bitrate_config.start_bitrate_bps ==
907 bitrate_config.start_bitrate_bps) && 925 bitrate_config.start_bitrate_bps) &&
908 config_.bitrate_config.max_bitrate_bps == 926 config_.bitrate_config.max_bitrate_bps ==
909 bitrate_config.max_bitrate_bps) { 927 bitrate_config.max_bitrate_bps) {
910 // Nothing new to set, early abort to avoid encoder reconfigurations. 928 // Nothing new to set, early abort to avoid encoder reconfigurations.
911 return; 929 return;
912 } 930 }
931
913 config_.bitrate_config.min_bitrate_bps = bitrate_config.min_bitrate_bps; 932 config_.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 933 // Start bitrate of -1 means we should keep the old bitrate, which there is
915 // no point in remembering for the future. 934 // no point in remembering for the future.
916 if (bitrate_config.start_bitrate_bps > 0) 935 if (bitrate_config.start_bitrate_bps > 0)
917 config_.bitrate_config.start_bitrate_bps = bitrate_config.start_bitrate_bps; 936 config_.bitrate_config.start_bitrate_bps = bitrate_config.start_bitrate_bps;
918 config_.bitrate_config.max_bitrate_bps = bitrate_config.max_bitrate_bps; 937 config_.bitrate_config.max_bitrate_bps = bitrate_config.max_bitrate_bps;
938
919 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); 939 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0);
920 transport_send_->send_side_cc()->SetBweBitrates( 940
921 bitrate_config.min_bitrate_bps, bitrate_config.start_bitrate_bps, 941 UpdateMaskedBitrateConfig();
942 }
943
944 void Call::SetBitrateConfigMask(
945 const webrtc::Call::Config::BitrateConfigMask& mask) {
946 TRACE_EVENT0("webrtc", "Call::UpdateBitrateConfig");
947 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
948
949 const bool has_min = static_cast<bool>(mask.min_bitrate_bps);
950 const bool has_start = static_cast<bool>(mask.start_bitrate_bps);
951 const bool has_max = static_cast<bool>(mask.max_bitrate_bps);
952 if (has_min) {
953 RTC_DCHECK_GE(*mask.min_bitrate_bps, 0);
Taylor Brandstetter 2017/04/12 01:33:41 In general we don't assert as a result of bad inpu
Zach Stein 2017/04/18 22:54:50 Done.
954 }
955 if (has_start) {
956 RTC_DCHECK_GE(*mask.start_bitrate_bps, has_min ? *mask.min_bitrate_bps : 0);
957 }
958 if (has_max) {
959 RTC_DCHECK_GE(*mask.max_bitrate_bps,
960 has_start ? *mask.start_bitrate_bps
961 : (has_min ? *mask.min_bitrate_bps : 0));
962 }
963
964 bitrate_config_mask_ = mask;
965
966 UpdateMaskedBitrateConfig();
967 }
968
969 void Call::UpdateMaskedBitrateConfig() {
970 Config::BitrateConfig new_masked;
971 const Config::BitrateConfig& bitrate_config = config_.bitrate_config;
Taylor Brandstetter 2017/04/12 01:33:42 It seems unintuitive that config_.bitrate_config i
Zach Stein 2017/04/18 22:54:50 Done.
972
973 new_masked.min_bitrate_bps = bitrate_config_mask_.min_bitrate_bps.value_or(
974 bitrate_config.min_bitrate_bps);
975 new_masked.start_bitrate_bps =
976 bitrate_config_mask_.start_bitrate_bps.value_or(
977 bitrate_config.start_bitrate_bps);
978 new_masked.max_bitrate_bps = bitrate_config_mask_.max_bitrate_bps.value_or(
922 bitrate_config.max_bitrate_bps); 979 bitrate_config.max_bitrate_bps);
Taylor Brandstetter 2017/04/12 01:33:42 I'm not sure the "mask" should completely override
Zach Stein 2017/04/13 00:26:36 We don't know that bitrate_config.max_bitrate_bps
Taylor Brandstetter 2017/04/13 22:16:13 The codec params also come from SDP (from "a=fmtp"
Zach Stein 2017/04/18 22:54:50 I didn't realize that the codec params also came f
980
981 if (new_masked.min_bitrate_bps != masked_bitrate_config_.min_bitrate_bps ||
982 new_masked.start_bitrate_bps !=
983 masked_bitrate_config_.start_bitrate_bps ||
Taylor Brandstetter 2017/04/12 01:33:42 Should this be the same condition as in SetBitrate
Zach Stein 2017/04/18 22:54:50 Done.
984 new_masked.max_bitrate_bps != masked_bitrate_config_.max_bitrate_bps) {
985 RTC_DCHECK_GT(new_masked.min_bitrate_bps, 0);
986 RTC_DCHECK_GT(new_masked.start_bitrate_bps, new_masked.min_bitrate_bps);
987 RTC_DCHECK(new_masked.max_bitrate_bps == -1 ||
988 new_masked.max_bitrate_bps > new_masked.start_bitrate_bps);
989
990 masked_bitrate_config_ = new_masked;
991 transport_send_->send_side_cc()->SetBweBitrates(
992 masked_bitrate_config_.min_bitrate_bps,
993 masked_bitrate_config_.start_bitrate_bps,
994 masked_bitrate_config_.max_bitrate_bps);
995 }
923 } 996 }
924 997
925 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { 998 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) {
926 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 999 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
927 switch (media) { 1000 switch (media) {
928 case MediaType::AUDIO: 1001 case MediaType::AUDIO:
929 audio_network_state_ = state; 1002 audio_network_state_ = state;
930 break; 1003 break;
931 case MediaType::VIDEO: 1004 case MediaType::VIDEO:
932 video_network_state_ = state; 1005 video_network_state_ = state;
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { 1398 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) {
1326 receive_side_cc_.OnReceivedPacket( 1399 receive_side_cc_.OnReceivedPacket(
1327 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), 1400 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(),
1328 header); 1401 header);
1329 } 1402 }
1330 } 1403 }
1331 1404
1332 } // namespace internal 1405 } // namespace internal
1333 1406
1334 } // namespace webrtc 1407 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698