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

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

Issue 2914413002: Revert of Add PeerConnectionInterface::UpdateCallBitrate. (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « webrtc/call/call.h ('k') | webrtc/call/call_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 const uint8_t* packet, 193 const uint8_t* packet,
194 size_t length, 194 size_t length,
195 const PacketTime& packet_time) override; 195 const PacketTime& packet_time) override;
196 196
197 // Implements RecoveredPacketReceiver. 197 // Implements RecoveredPacketReceiver.
198 void OnRecoveredPacket(const uint8_t* packet, size_t length) override; 198 void OnRecoveredPacket(const uint8_t* packet, size_t length) override;
199 199
200 void SetBitrateConfig( 200 void SetBitrateConfig(
201 const webrtc::Call::Config::BitrateConfig& bitrate_config) override; 201 const webrtc::Call::Config::BitrateConfig& bitrate_config) override;
202 202
203 void SetBitrateConfigMask(
204 const webrtc::Call::Config::BitrateConfigMask& bitrate_config) override;
205
206 void SignalChannelNetworkState(MediaType media, NetworkState state) override; 203 void SignalChannelNetworkState(MediaType media, NetworkState state) override;
207 204
208 void OnTransportOverheadChanged(MediaType media, 205 void OnTransportOverheadChanged(MediaType media,
209 int transport_overhead_per_packet) override; 206 int transport_overhead_per_packet) override;
210 207
211 void OnNetworkRouteChanged(const std::string& transport_name, 208 void OnNetworkRouteChanged(const std::string& transport_name,
212 const rtc::NetworkRoute& network_route) override; 209 const rtc::NetworkRoute& network_route) override;
213 210
214 void OnSentPacket(const rtc::SentPacket& sent_packet) override; 211 void OnSentPacket(const rtc::SentPacket& sent_packet) override;
215 212
(...skipping 26 matching lines...) Expand all
242 size_t length, 239 size_t length,
243 const PacketTime* packet_time) 240 const PacketTime* packet_time)
244 SHARED_LOCKS_REQUIRED(receive_crit_); 241 SHARED_LOCKS_REQUIRED(receive_crit_);
245 242
246 void UpdateSendHistograms(int64_t first_sent_packet_ms) 243 void UpdateSendHistograms(int64_t first_sent_packet_ms)
247 EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); 244 EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_);
248 void UpdateReceiveHistograms(); 245 void UpdateReceiveHistograms();
249 void UpdateHistograms(); 246 void UpdateHistograms();
250 void UpdateAggregateNetworkState(); 247 void UpdateAggregateNetworkState();
251 248
252 // Applies update to the BitrateConfig cached in |config_|, restarting
253 // bandwidth estimation from |new_start| if set.
254 void UpdateCurrentBitrateConfig(const rtc::Optional<int>& new_start);
255
256 Clock* const clock_; 249 Clock* const clock_;
257 250
258 const int num_cpu_cores_; 251 const int num_cpu_cores_;
259 const std::unique_ptr<ProcessThread> module_process_thread_; 252 const std::unique_ptr<ProcessThread> module_process_thread_;
260 const std::unique_ptr<ProcessThread> pacer_thread_; 253 const std::unique_ptr<ProcessThread> pacer_thread_;
261 const std::unique_ptr<CallStats> call_stats_; 254 const std::unique_ptr<CallStats> call_stats_;
262 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; 255 const std::unique_ptr<BitrateAllocator> bitrate_allocator_;
263 Call::Config config_; 256 Call::Config config_;
264 rtc::ThreadChecker configuration_thread_checker_; 257 rtc::ThreadChecker configuration_thread_checker_;
265 258
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; 334 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_;
342 ReceiveSideCongestionController receive_side_cc_; 335 ReceiveSideCongestionController receive_side_cc_;
343 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; 336 const std::unique_ptr<SendDelayStats> video_send_delay_stats_;
344 const int64_t start_ms_; 337 const int64_t start_ms_;
345 // TODO(perkj): |worker_queue_| is supposed to replace 338 // TODO(perkj): |worker_queue_| is supposed to replace
346 // |module_process_thread_|. 339 // |module_process_thread_|.
347 // |worker_queue| is defined last to ensure all pending tasks are cancelled 340 // |worker_queue| is defined last to ensure all pending tasks are cancelled
348 // and deleted before any other members. 341 // and deleted before any other members.
349 rtc::TaskQueue worker_queue_; 342 rtc::TaskQueue worker_queue_;
350 343
351 // The config mask set by SetBitrateConfigMask.
352 // 0 <= min <= start <= max
353 Config::BitrateConfigMask bitrate_config_mask_;
354
355 // The config set by SetBitrateConfig.
356 // min >= 0, start != 0, max == -1 || max > 0
357 Config::BitrateConfig base_bitrate_config_;
358
359 RTC_DISALLOW_COPY_AND_ASSIGN(Call); 344 RTC_DISALLOW_COPY_AND_ASSIGN(Call);
360 }; 345 };
361 } // namespace internal 346 } // namespace internal
362 347
363 std::string Call::Stats::ToString(int64_t time_ms) const { 348 std::string Call::Stats::ToString(int64_t time_ms) const {
364 std::stringstream ss; 349 std::stringstream ss;
365 ss << "Call stats: " << time_ms << ", {"; 350 ss << "Call stats: " << time_ms << ", {";
366 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; 351 ss << "send_bw_bps: " << send_bandwidth_bps << ", ";
367 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; 352 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", ";
368 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; 353 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", ";
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 received_audio_bytes_per_second_counter_(clock_, nullptr, true), 389 received_audio_bytes_per_second_counter_(clock_, nullptr, true),
405 received_video_bytes_per_second_counter_(clock_, nullptr, true), 390 received_video_bytes_per_second_counter_(clock_, nullptr, true),
406 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), 391 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true),
407 min_allocated_send_bitrate_bps_(0), 392 min_allocated_send_bitrate_bps_(0),
408 configured_max_padding_bitrate_bps_(0), 393 configured_max_padding_bitrate_bps_(0),
409 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), 394 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true),
410 pacer_bitrate_kbps_counter_(clock_, nullptr, true), 395 pacer_bitrate_kbps_counter_(clock_, nullptr, true),
411 receive_side_cc_(clock_, transport_send->packet_router()), 396 receive_side_cc_(clock_, transport_send->packet_router()),
412 video_send_delay_stats_(new SendDelayStats(clock_)), 397 video_send_delay_stats_(new SendDelayStats(clock_)),
413 start_ms_(clock_->TimeInMilliseconds()), 398 start_ms_(clock_->TimeInMilliseconds()),
414 worker_queue_("call_worker_queue"), 399 worker_queue_("call_worker_queue") {
415 base_bitrate_config_(config.bitrate_config) { 400 RTC_DCHECK_RUN_ON(&configuration_thread_checker_);
416 RTC_DCHECK(&configuration_thread_checker_);
417 RTC_DCHECK(config.event_log != nullptr); 401 RTC_DCHECK(config.event_log != nullptr);
418 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); 402 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0);
419 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, 403 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps,
420 config.bitrate_config.min_bitrate_bps); 404 config.bitrate_config.min_bitrate_bps);
421 if (config.bitrate_config.max_bitrate_bps != -1) { 405 if (config.bitrate_config.max_bitrate_bps != -1) {
422 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, 406 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps,
423 config.bitrate_config.start_bitrate_bps); 407 config.bitrate_config.start_bitrate_bps);
424 } 408 }
425 Trace::CreateTrace(); 409 Trace::CreateTrace();
426 transport_send->send_side_cc()->RegisterNetworkObserver(this); 410 transport_send->send_side_cc()->RegisterNetworkObserver(this);
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; 898 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_;
915 } 899 }
916 return stats; 900 return stats;
917 } 901 }
918 902
919 void Call::SetBitrateConfig( 903 void Call::SetBitrateConfig(
920 const webrtc::Call::Config::BitrateConfig& bitrate_config) { 904 const webrtc::Call::Config::BitrateConfig& bitrate_config) {
921 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); 905 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig");
922 RTC_DCHECK_RUN_ON(&configuration_thread_checker_); 906 RTC_DCHECK_RUN_ON(&configuration_thread_checker_);
923 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); 907 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0);
924 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); 908 if (bitrate_config.max_bitrate_bps != -1)
925 if (bitrate_config.max_bitrate_bps != -1) {
926 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); 909 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0);
927 } 910 if (config_.bitrate_config.min_bitrate_bps ==
928 911 bitrate_config.min_bitrate_bps &&
929 rtc::Optional<int> new_start; 912 (bitrate_config.start_bitrate_bps <= 0 ||
930 // Only update the "start" bitrate if it's set, and different from the old 913 config_.bitrate_config.start_bitrate_bps ==
931 // value. In practice, this value comes from the x-google-start-bitrate codec 914 bitrate_config.start_bitrate_bps) &&
932 // parameter in SDP, and setting the same remote description twice shouldn't 915 config_.bitrate_config.max_bitrate_bps ==
933 // restart bandwidth estimation. 916 bitrate_config.max_bitrate_bps) {
934 if (bitrate_config.start_bitrate_bps != -1 && 917 // Nothing new to set, early abort to avoid encoder reconfigurations.
935 bitrate_config.start_bitrate_bps !=
936 base_bitrate_config_.start_bitrate_bps) {
937 new_start.emplace(bitrate_config.start_bitrate_bps);
938 }
939 base_bitrate_config_ = bitrate_config;
940 UpdateCurrentBitrateConfig(new_start);
941 }
942
943 void Call::SetBitrateConfigMask(
944 const webrtc::Call::Config::BitrateConfigMask& mask) {
945 TRACE_EVENT0("webrtc", "Call::SetBitrateConfigMask");
946 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
947
948 bitrate_config_mask_ = mask;
949 UpdateCurrentBitrateConfig(mask.start_bitrate_bps);
950 }
951
952 namespace {
953
954 static int MinPositive(int a, int b) {
955 if (a <= 0) {
956 return b;
957 }
958 if (b <= 0) {
959 return a;
960 }
961 return std::min(a, b);
962 }
963
964 } // namespace
965
966 void Call::UpdateCurrentBitrateConfig(const rtc::Optional<int>& new_start) {
967 Config::BitrateConfig updated;
968 updated.min_bitrate_bps =
969 std::max(bitrate_config_mask_.min_bitrate_bps.value_or(0),
970 base_bitrate_config_.min_bitrate_bps);
971
972 updated.max_bitrate_bps =
973 MinPositive(bitrate_config_mask_.max_bitrate_bps.value_or(-1),
974 base_bitrate_config_.max_bitrate_bps);
975
976 // If the combined min ends up greater than the combined max, the max takes
977 // priority.
978 if (updated.max_bitrate_bps != -1 &&
979 updated.min_bitrate_bps > updated.max_bitrate_bps) {
980 updated.min_bitrate_bps = updated.max_bitrate_bps;
981 }
982
983 // If there is nothing to update (min/max unchanged, no new bandwidth
984 // estimation start value), return early.
985 if (updated.min_bitrate_bps == config_.bitrate_config.min_bitrate_bps &&
986 updated.max_bitrate_bps == config_.bitrate_config.max_bitrate_bps &&
987 !new_start) {
988 LOG(LS_VERBOSE) << "WebRTC.Call.UpdateCurrentBitrateConfig: "
989 << "nothing to update";
990 return; 918 return;
991 } 919 }
992 920 config_.bitrate_config.min_bitrate_bps = bitrate_config.min_bitrate_bps;
993 if (new_start) { 921 // Start bitrate of -1 means we should keep the old bitrate, which there is
994 // Clamp start by min and max. 922 // no point in remembering for the future.
995 updated.start_bitrate_bps = MinPositive( 923 if (bitrate_config.start_bitrate_bps > 0)
996 std::max(*new_start, updated.min_bitrate_bps), updated.max_bitrate_bps); 924 config_.bitrate_config.start_bitrate_bps = bitrate_config.start_bitrate_bps;
997 } else { 925 config_.bitrate_config.max_bitrate_bps = bitrate_config.max_bitrate_bps;
998 updated.start_bitrate_bps = -1; 926 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0);
999 } 927 transport_send_->send_side_cc()->SetBweBitrates(
1000 928 bitrate_config.min_bitrate_bps, bitrate_config.start_bitrate_bps,
1001 LOG(INFO) << "WebRTC.Call.UpdateCurrentBitrateConfig: " 929 bitrate_config.max_bitrate_bps);
1002 << "calling SetBweBitrates with args (" << updated.min_bitrate_bps
1003 << ", " << updated.start_bitrate_bps << ", "
1004 << updated.max_bitrate_bps << ")";
1005 transport_send_->send_side_cc()->SetBweBitrates(updated.min_bitrate_bps,
1006 updated.start_bitrate_bps,
1007 updated.max_bitrate_bps);
1008 if (!new_start) {
1009 updated.start_bitrate_bps = config_.bitrate_config.start_bitrate_bps;
1010 }
1011 config_.bitrate_config = updated;
1012 } 930 }
1013 931
1014 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { 932 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) {
1015 RTC_DCHECK_RUN_ON(&configuration_thread_checker_); 933 RTC_DCHECK_RUN_ON(&configuration_thread_checker_);
1016 switch (media) { 934 switch (media) {
1017 case MediaType::AUDIO: 935 case MediaType::AUDIO:
1018 audio_network_state_ = state; 936 audio_network_state_ = state;
1019 break; 937 break;
1020 case MediaType::VIDEO: 938 case MediaType::VIDEO:
1021 video_network_state_ = state; 939 video_network_state_ = state;
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { 1309 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) {
1392 receive_side_cc_.OnReceivedPacket( 1310 receive_side_cc_.OnReceivedPacket(
1393 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), 1311 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(),
1394 header); 1312 header);
1395 } 1313 }
1396 } 1314 }
1397 1315
1398 } // namespace internal 1316 } // namespace internal
1399 1317
1400 } // namespace webrtc 1318 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/call/call.h ('k') | webrtc/call/call_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698