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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | |
203 void SignalChannelNetworkState(MediaType media, NetworkState state) override; | 206 void SignalChannelNetworkState(MediaType media, NetworkState state) override; |
204 | 207 |
205 void OnTransportOverheadChanged(MediaType media, | 208 void OnTransportOverheadChanged(MediaType media, |
206 int transport_overhead_per_packet) override; | 209 int transport_overhead_per_packet) override; |
207 | 210 |
208 void OnNetworkRouteChanged(const std::string& transport_name, | 211 void OnNetworkRouteChanged(const std::string& transport_name, |
209 const rtc::NetworkRoute& network_route) override; | 212 const rtc::NetworkRoute& network_route) override; |
210 | 213 |
211 void OnSentPacket(const rtc::SentPacket& sent_packet) override; | 214 void OnSentPacket(const rtc::SentPacket& sent_packet) override; |
212 | 215 |
(...skipping 26 matching lines...) Expand all Loading... | |
239 size_t length, | 242 size_t length, |
240 const PacketTime* packet_time) | 243 const PacketTime* packet_time) |
241 SHARED_LOCKS_REQUIRED(receive_crit_); | 244 SHARED_LOCKS_REQUIRED(receive_crit_); |
242 | 245 |
243 void UpdateSendHistograms(int64_t first_sent_packet_ms) | 246 void UpdateSendHistograms(int64_t first_sent_packet_ms) |
244 EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); | 247 EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); |
245 void UpdateReceiveHistograms(); | 248 void UpdateReceiveHistograms(); |
246 void UpdateHistograms(); | 249 void UpdateHistograms(); |
247 void UpdateAggregateNetworkState(); | 250 void UpdateAggregateNetworkState(); |
248 | 251 |
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 | |
249 Clock* const clock_; | 256 Clock* const clock_; |
250 | 257 |
251 const int num_cpu_cores_; | 258 const int num_cpu_cores_; |
252 const std::unique_ptr<ProcessThread> module_process_thread_; | 259 const std::unique_ptr<ProcessThread> module_process_thread_; |
253 const std::unique_ptr<ProcessThread> pacer_thread_; | 260 const std::unique_ptr<ProcessThread> pacer_thread_; |
254 const std::unique_ptr<CallStats> call_stats_; | 261 const std::unique_ptr<CallStats> call_stats_; |
255 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; | 262 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; |
256 Call::Config config_; | 263 Call::Config config_; |
257 rtc::ThreadChecker configuration_thread_checker_; | 264 rtc::ThreadChecker configuration_thread_checker_; |
258 | 265 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; | 341 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; |
335 ReceiveSideCongestionController receive_side_cc_; | 342 ReceiveSideCongestionController receive_side_cc_; |
336 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; | 343 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; |
337 const int64_t start_ms_; | 344 const int64_t start_ms_; |
338 // TODO(perkj): |worker_queue_| is supposed to replace | 345 // TODO(perkj): |worker_queue_| is supposed to replace |
339 // |module_process_thread_|. | 346 // |module_process_thread_|. |
340 // |worker_queue| is defined last to ensure all pending tasks are cancelled | 347 // |worker_queue| is defined last to ensure all pending tasks are cancelled |
341 // and deleted before any other members. | 348 // and deleted before any other members. |
342 rtc::TaskQueue worker_queue_; | 349 rtc::TaskQueue worker_queue_; |
343 | 350 |
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 | |
344 RTC_DISALLOW_COPY_AND_ASSIGN(Call); | 359 RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
345 }; | 360 }; |
346 } // namespace internal | 361 } // namespace internal |
347 | 362 |
348 std::string Call::Stats::ToString(int64_t time_ms) const { | 363 std::string Call::Stats::ToString(int64_t time_ms) const { |
349 std::stringstream ss; | 364 std::stringstream ss; |
350 ss << "Call stats: " << time_ms << ", {"; | 365 ss << "Call stats: " << time_ms << ", {"; |
351 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; | 366 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; |
352 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; | 367 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; |
353 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; | 368 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 received_audio_bytes_per_second_counter_(clock_, nullptr, true), | 404 received_audio_bytes_per_second_counter_(clock_, nullptr, true), |
390 received_video_bytes_per_second_counter_(clock_, nullptr, true), | 405 received_video_bytes_per_second_counter_(clock_, nullptr, true), |
391 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), | 406 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), |
392 min_allocated_send_bitrate_bps_(0), | 407 min_allocated_send_bitrate_bps_(0), |
393 configured_max_padding_bitrate_bps_(0), | 408 configured_max_padding_bitrate_bps_(0), |
394 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), | 409 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), |
395 pacer_bitrate_kbps_counter_(clock_, nullptr, true), | 410 pacer_bitrate_kbps_counter_(clock_, nullptr, true), |
396 receive_side_cc_(clock_, transport_send->packet_router()), | 411 receive_side_cc_(clock_, transport_send->packet_router()), |
397 video_send_delay_stats_(new SendDelayStats(clock_)), | 412 video_send_delay_stats_(new SendDelayStats(clock_)), |
398 start_ms_(clock_->TimeInMilliseconds()), | 413 start_ms_(clock_->TimeInMilliseconds()), |
399 worker_queue_("call_worker_queue") { | 414 worker_queue_("call_worker_queue"), |
400 RTC_DCHECK_RUN_ON(&configuration_thread_checker_); | 415 base_bitrate_config_(config.bitrate_config) { |
416 RTC_DCHECK(&configuration_thread_checker_); | |
401 RTC_DCHECK(config.event_log != nullptr); | 417 RTC_DCHECK(config.event_log != nullptr); |
402 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); | 418 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
403 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, | 419 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, |
404 config.bitrate_config.min_bitrate_bps); | 420 config.bitrate_config.min_bitrate_bps); |
405 if (config.bitrate_config.max_bitrate_bps != -1) { | 421 if (config.bitrate_config.max_bitrate_bps != -1) { |
406 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, | 422 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, |
407 config.bitrate_config.start_bitrate_bps); | 423 config.bitrate_config.start_bitrate_bps); |
408 } | 424 } |
409 Trace::CreateTrace(); | 425 Trace::CreateTrace(); |
410 transport_send->send_side_cc()->RegisterNetworkObserver(this); | 426 transport_send->send_side_cc()->RegisterNetworkObserver(this); |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
898 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; | 914 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; |
899 } | 915 } |
900 return stats; | 916 return stats; |
901 } | 917 } |
902 | 918 |
903 void Call::SetBitrateConfig( | 919 void Call::SetBitrateConfig( |
904 const webrtc::Call::Config::BitrateConfig& bitrate_config) { | 920 const webrtc::Call::Config::BitrateConfig& bitrate_config) { |
905 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); | 921 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); |
906 RTC_DCHECK_RUN_ON(&configuration_thread_checker_); | 922 RTC_DCHECK_RUN_ON(&configuration_thread_checker_); |
907 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); | 923 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); |
908 if (bitrate_config.max_bitrate_bps != -1) | 924 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); |
925 if (bitrate_config.max_bitrate_bps != -1) { | |
909 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); | 926 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); |
910 if (config_.bitrate_config.min_bitrate_bps == | 927 } |
911 bitrate_config.min_bitrate_bps && | 928 |
912 (bitrate_config.start_bitrate_bps <= 0 || | 929 rtc::Optional<int> new_start; |
913 config_.bitrate_config.start_bitrate_bps == | 930 // Only update the "start" bitrate if it's set, and different from the old |
914 bitrate_config.start_bitrate_bps) && | 931 // value. In practice, this value comes from the x-google-start-bitrate codec |
915 config_.bitrate_config.max_bitrate_bps == | 932 // parameter in SDP, and setting the same remote description twice shouldn't |
916 bitrate_config.max_bitrate_bps) { | 933 // restart bandwidth estimation. |
917 // Nothing new to set, early abort to avoid encoder reconfigurations. | 934 if (bitrate_config.start_bitrate_bps != -1 && |
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; | |
tommi
2017/08/17 07:32:52
Here, |b| is not guaranteed to be positive.
would
kwiberg-webrtc
2017/08/17 09:49:26
Hmm. Your suggestion is the same as
std::max(0,
| |
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"; | |
918 return; | 990 return; |
919 } | 991 } |
920 config_.bitrate_config.min_bitrate_bps = bitrate_config.min_bitrate_bps; | 992 |
921 // Start bitrate of -1 means we should keep the old bitrate, which there is | 993 if (new_start) { |
922 // no point in remembering for the future. | 994 // Clamp start by min and max. |
923 if (bitrate_config.start_bitrate_bps > 0) | 995 updated.start_bitrate_bps = MinPositive( |
924 config_.bitrate_config.start_bitrate_bps = bitrate_config.start_bitrate_bps; | 996 std::max(*new_start, updated.min_bitrate_bps), updated.max_bitrate_bps); |
925 config_.bitrate_config.max_bitrate_bps = bitrate_config.max_bitrate_bps; | 997 } else { |
926 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); | 998 updated.start_bitrate_bps = -1; |
927 transport_send_->send_side_cc()->SetBweBitrates( | 999 } |
928 bitrate_config.min_bitrate_bps, bitrate_config.start_bitrate_bps, | 1000 |
929 bitrate_config.max_bitrate_bps); | 1001 LOG(INFO) << "WebRTC.Call.UpdateCurrentBitrateConfig: " |
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; | |
930 } | 1012 } |
931 | 1013 |
932 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { | 1014 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { |
933 RTC_DCHECK_RUN_ON(&configuration_thread_checker_); | 1015 RTC_DCHECK_RUN_ON(&configuration_thread_checker_); |
934 switch (media) { | 1016 switch (media) { |
935 case MediaType::AUDIO: | 1017 case MediaType::AUDIO: |
936 audio_network_state_ = state; | 1018 audio_network_state_ = state; |
937 break; | 1019 break; |
938 case MediaType::VIDEO: | 1020 case MediaType::VIDEO: |
939 video_network_state_ = state; | 1021 video_network_state_ = state; |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1309 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { | 1391 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { |
1310 receive_side_cc_.OnReceivedPacket( | 1392 receive_side_cc_.OnReceivedPacket( |
1311 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), | 1393 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), |
1312 header); | 1394 header); |
1313 } | 1395 } |
1314 } | 1396 } |
1315 | 1397 |
1316 } // namespace internal | 1398 } // namespace internal |
1317 | 1399 |
1318 } // namespace webrtc | 1400 } // namespace webrtc |
OLD | NEW |