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

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

Issue 2888303005: Add PeerConnectionInterface::UpdateCallBitrate. (Closed)
Patch Set: Add a missing test from Taylor's last CR. Created 3 years, 7 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 const uint8_t* packet, 136 const uint8_t* packet,
137 size_t length, 137 size_t length,
138 const PacketTime& packet_time) override; 138 const PacketTime& packet_time) override;
139 139
140 // Implements RecoveredPacketReceiver. 140 // Implements RecoveredPacketReceiver.
141 void OnRecoveredPacket(const uint8_t* packet, size_t length) override; 141 void OnRecoveredPacket(const uint8_t* packet, size_t length) override;
142 142
143 void SetBitrateConfig( 143 void SetBitrateConfig(
144 const webrtc::Call::Config::BitrateConfig& bitrate_config) override; 144 const webrtc::Call::Config::BitrateConfig& bitrate_config) override;
145 145
146 void SetBitrateConfigMask(
147 const webrtc::Call::Config::BitrateConfigMask& bitrate_config) override;
148
146 void SignalChannelNetworkState(MediaType media, NetworkState state) override; 149 void SignalChannelNetworkState(MediaType media, NetworkState state) override;
147 150
148 void OnTransportOverheadChanged(MediaType media, 151 void OnTransportOverheadChanged(MediaType media,
149 int transport_overhead_per_packet) override; 152 int transport_overhead_per_packet) override;
150 153
151 void OnNetworkRouteChanged(const std::string& transport_name, 154 void OnNetworkRouteChanged(const std::string& transport_name,
152 const rtc::NetworkRoute& network_route) override; 155 const rtc::NetworkRoute& network_route) override;
153 156
154 void OnSentPacket(const rtc::SentPacket& sent_packet) override; 157 void OnSentPacket(const rtc::SentPacket& sent_packet) override;
155 158
(...skipping 26 matching lines...) Expand all
182 size_t length, 185 size_t length,
183 const PacketTime* packet_time) 186 const PacketTime* packet_time)
184 SHARED_LOCKS_REQUIRED(receive_crit_); 187 SHARED_LOCKS_REQUIRED(receive_crit_);
185 188
186 void UpdateSendHistograms(int64_t first_sent_packet_ms) 189 void UpdateSendHistograms(int64_t first_sent_packet_ms)
187 EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); 190 EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_);
188 void UpdateReceiveHistograms(); 191 void UpdateReceiveHistograms();
189 void UpdateHistograms(); 192 void UpdateHistograms();
190 void UpdateAggregateNetworkState(); 193 void UpdateAggregateNetworkState();
191 194
195 // Applies update to the BitrateConfig cached in |config_|, restarting
196 // bandwidth estimation from |new_start| if set.
197 void UpdateCurrentBitrateConfig(const rtc::Optional<int>& new_start);
198
192 Clock* const clock_; 199 Clock* const clock_;
193 200
194 const int num_cpu_cores_; 201 const int num_cpu_cores_;
195 const std::unique_ptr<ProcessThread> module_process_thread_; 202 const std::unique_ptr<ProcessThread> module_process_thread_;
196 const std::unique_ptr<ProcessThread> pacer_thread_; 203 const std::unique_ptr<ProcessThread> pacer_thread_;
197 const std::unique_ptr<CallStats> call_stats_; 204 const std::unique_ptr<CallStats> call_stats_;
198 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; 205 const std::unique_ptr<BitrateAllocator> bitrate_allocator_;
199 Call::Config config_; 206 Call::Config config_;
200 rtc::ThreadChecker configuration_thread_checker_; 207 rtc::ThreadChecker configuration_thread_checker_;
201 208
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; 279 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_;
273 ReceiveSideCongestionController receive_side_cc_; 280 ReceiveSideCongestionController receive_side_cc_;
274 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; 281 const std::unique_ptr<SendDelayStats> video_send_delay_stats_;
275 const int64_t start_ms_; 282 const int64_t start_ms_;
276 // TODO(perkj): |worker_queue_| is supposed to replace 283 // TODO(perkj): |worker_queue_| is supposed to replace
277 // |module_process_thread_|. 284 // |module_process_thread_|.
278 // |worker_queue| is defined last to ensure all pending tasks are cancelled 285 // |worker_queue| is defined last to ensure all pending tasks are cancelled
279 // and deleted before any other members. 286 // and deleted before any other members.
280 rtc::TaskQueue worker_queue_; 287 rtc::TaskQueue worker_queue_;
281 288
289 // The config mask set by SetBitrateConfigMask.
290 // 0 <= min <= start <= max
291 Config::BitrateConfigMask bitrate_config_mask_;
292
293 // The config set by SetBitrateConfig.
294 // min >= 0, start != 0, max == -1 || max > 0
295 Config::BitrateConfig base_bitrate_config_;
296
282 RTC_DISALLOW_COPY_AND_ASSIGN(Call); 297 RTC_DISALLOW_COPY_AND_ASSIGN(Call);
283 }; 298 };
284 } // namespace internal 299 } // namespace internal
285 300
286 std::string Call::Stats::ToString(int64_t time_ms) const { 301 std::string Call::Stats::ToString(int64_t time_ms) const {
287 std::stringstream ss; 302 std::stringstream ss;
288 ss << "Call stats: " << time_ms << ", {"; 303 ss << "Call stats: " << time_ms << ", {";
289 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; 304 ss << "send_bw_bps: " << send_bandwidth_bps << ", ";
290 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; 305 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", ";
291 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; 306 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", ";
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 received_audio_bytes_per_second_counter_(clock_, nullptr, true), 342 received_audio_bytes_per_second_counter_(clock_, nullptr, true),
328 received_video_bytes_per_second_counter_(clock_, nullptr, true), 343 received_video_bytes_per_second_counter_(clock_, nullptr, true),
329 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), 344 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true),
330 min_allocated_send_bitrate_bps_(0), 345 min_allocated_send_bitrate_bps_(0),
331 configured_max_padding_bitrate_bps_(0), 346 configured_max_padding_bitrate_bps_(0),
332 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), 347 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true),
333 pacer_bitrate_kbps_counter_(clock_, nullptr, true), 348 pacer_bitrate_kbps_counter_(clock_, nullptr, true),
334 receive_side_cc_(clock_, transport_send->packet_router()), 349 receive_side_cc_(clock_, transport_send->packet_router()),
335 video_send_delay_stats_(new SendDelayStats(clock_)), 350 video_send_delay_stats_(new SendDelayStats(clock_)),
336 start_ms_(clock_->TimeInMilliseconds()), 351 start_ms_(clock_->TimeInMilliseconds()),
337 worker_queue_("call_worker_queue") { 352 worker_queue_("call_worker_queue"),
353 base_bitrate_config_(config.bitrate_config) {
338 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 354 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
339 RTC_DCHECK(config.event_log != nullptr); 355 RTC_DCHECK(config.event_log != nullptr);
340 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); 356 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0);
341 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, 357 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps,
342 config.bitrate_config.min_bitrate_bps); 358 config.bitrate_config.min_bitrate_bps);
343 if (config.bitrate_config.max_bitrate_bps != -1) { 359 if (config.bitrate_config.max_bitrate_bps != -1) {
344 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, 360 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps,
345 config.bitrate_config.start_bitrate_bps); 361 config.bitrate_config.start_bitrate_bps);
346 } 362 }
347 Trace::CreateTrace(); 363 Trace::CreateTrace();
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 rtc::CritScope cs(&bitrate_crit_); 836 rtc::CritScope cs(&bitrate_crit_);
821 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; 837 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_;
822 } 838 }
823 return stats; 839 return stats;
824 } 840 }
825 841
826 void Call::SetBitrateConfig( 842 void Call::SetBitrateConfig(
827 const webrtc::Call::Config::BitrateConfig& bitrate_config) { 843 const webrtc::Call::Config::BitrateConfig& bitrate_config) {
828 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); 844 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig");
829 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 845 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
846
830 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); 847 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0);
831 if (bitrate_config.max_bitrate_bps != -1) 848 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0);
849 if (bitrate_config.max_bitrate_bps != -1) {
832 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); 850 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0);
833 if (config_.bitrate_config.min_bitrate_bps == 851 }
834 bitrate_config.min_bitrate_bps && 852
835 (bitrate_config.start_bitrate_bps <= 0 || 853 rtc::Optional<int> new_start;
836 config_.bitrate_config.start_bitrate_bps == 854 // Only update the "start" bitrate if it's set, and different from the old
837 bitrate_config.start_bitrate_bps) && 855 // value. In practice, this value comes from the x-google-start-bitrate-codec
Taylor Brandstetter 2017/05/25 15:33:52 nit: Remove hyphen between "bitrate" and "codec"
Zach Stein 2017/05/25 20:26:31 Done.
838 config_.bitrate_config.max_bitrate_bps == 856 // parameter in SDP, and setting the same remote description twice shouldn't
839 bitrate_config.max_bitrate_bps) { 857 // restart bandwidth estimation.
840 // Nothing new to set, early abort to avoid encoder reconfigurations. 858 if (bitrate_config.start_bitrate_bps != -1 &&
859 bitrate_config.start_bitrate_bps !=
860 base_bitrate_config_.start_bitrate_bps) {
861 new_start.emplace(bitrate_config.start_bitrate_bps);
862 }
863 base_bitrate_config_ = bitrate_config;
864 UpdateCurrentBitrateConfig(new_start);
865 }
866
867 void Call::SetBitrateConfigMask(
868 const webrtc::Call::Config::BitrateConfigMask& mask) {
869 TRACE_EVENT0("webrtc", "Call::SetBitrateConfigMask");
870 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
871
872 bitrate_config_mask_ = mask;
873 UpdateCurrentBitrateConfig(mask.start_bitrate_bps);
874 }
875
876 void Call::UpdateCurrentBitrateConfig(const rtc::Optional<int>& new_start) {
877 Config::BitrateConfig updated;
878 updated.min_bitrate_bps =
879 std::max(bitrate_config_mask_.min_bitrate_bps.value_or(0),
880 base_bitrate_config_.min_bitrate_bps);
881
882 updated.max_bitrate_bps =
883 cricket::MinPositive(bitrate_config_mask_.max_bitrate_bps.value_or(-1),
884 base_bitrate_config_.max_bitrate_bps);
885
886 // If the combined min ends up greater than the combined max, the max takes
887 // priority.
888 if (updated.max_bitrate_bps != -1 &&
889 updated.min_bitrate_bps > updated.max_bitrate_bps) {
890 updated.min_bitrate_bps = updated.max_bitrate_bps;
891 }
892
893 // If these's nothing to update (min/max unchanged, no new bandwidth
894 // estimation start value), return early.
895 if (updated.min_bitrate_bps == config_.bitrate_config.min_bitrate_bps &&
896 updated.max_bitrate_bps == config_.bitrate_config.max_bitrate_bps &&
897 !new_start) {
898 LOG(LS_VERBOSE) << "WebRTC.Call.UpdateCurrentBitrateConfig: "
899 << "nothing to update";
841 return; 900 return;
842 } 901 }
843 config_.bitrate_config.min_bitrate_bps = bitrate_config.min_bitrate_bps; 902
844 // Start bitrate of -1 means we should keep the old bitrate, which there is 903 if (new_start) {
845 // no point in remembering for the future. 904 // Clamp start by min and max.
846 if (bitrate_config.start_bitrate_bps > 0) 905 updated.start_bitrate_bps = cricket::MinPositive(
847 config_.bitrate_config.start_bitrate_bps = bitrate_config.start_bitrate_bps; 906 std::max(*new_start, updated.min_bitrate_bps), updated.max_bitrate_bps);
848 config_.bitrate_config.max_bitrate_bps = bitrate_config.max_bitrate_bps; 907 } else {
849 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); 908 updated.start_bitrate_bps = -1;
850 transport_send_->send_side_cc()->SetBweBitrates( 909 }
851 bitrate_config.min_bitrate_bps, bitrate_config.start_bitrate_bps, 910
852 bitrate_config.max_bitrate_bps); 911 LOG(INFO) << "WebRTC.Call.UpdateCurrentBitrateConfig: "
912 << "calling SetBweBitrates with args (" << updated.min_bitrate_bps
913 << ", " << updated.start_bitrate_bps << ", "
914 << updated.max_bitrate_bps << ")";
915 transport_send_->send_side_cc()->SetBweBitrates(updated.min_bitrate_bps,
916 updated.start_bitrate_bps,
917 updated.max_bitrate_bps);
918 config_.bitrate_config = updated;
853 } 919 }
854 920
855 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { 921 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) {
856 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 922 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
857 switch (media) { 923 switch (media) {
858 case MediaType::AUDIO: 924 case MediaType::AUDIO:
859 audio_network_state_ = state; 925 audio_network_state_ = state;
860 break; 926 break;
861 case MediaType::VIDEO: 927 case MediaType::VIDEO:
862 video_network_state_ = state; 928 video_network_state_ = state;
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { 1298 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) {
1233 receive_side_cc_.OnReceivedPacket( 1299 receive_side_cc_.OnReceivedPacket(
1234 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), 1300 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(),
1235 header); 1301 header);
1236 } 1302 }
1237 } 1303 }
1238 1304
1239 } // namespace internal 1305 } // namespace internal
1240 1306
1241 } // namespace webrtc 1307 } // namespace webrtc
OLDNEW
« webrtc/call/call.h ('K') | « 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