Chromium Code Reviews| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 // synchronization. | 179 // synchronization. |
| 180 int64_t first_packet_sent_ms_; | 180 int64_t first_packet_sent_ms_; |
| 181 RateCounter received_bytes_per_second_counter_; | 181 RateCounter received_bytes_per_second_counter_; |
| 182 RateCounter received_audio_bytes_per_second_counter_; | 182 RateCounter received_audio_bytes_per_second_counter_; |
| 183 RateCounter received_video_bytes_per_second_counter_; | 183 RateCounter received_video_bytes_per_second_counter_; |
| 184 RateCounter received_rtcp_bytes_per_second_counter_; | 184 RateCounter received_rtcp_bytes_per_second_counter_; |
| 185 | 185 |
| 186 // TODO(holmer): Remove this lock once BitrateController no longer calls | 186 // TODO(holmer): Remove this lock once BitrateController no longer calls |
| 187 // OnNetworkChanged from multiple threads. | 187 // OnNetworkChanged from multiple threads. |
| 188 rtc::CriticalSection bitrate_crit_; | 188 rtc::CriticalSection bitrate_crit_; |
| 189 int64_t estimated_send_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_); | |
| 190 int64_t pacer_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_); | |
| 191 uint32_t min_allocated_send_bitrate_bps_ GUARDED_BY(&bitrate_crit_); | 189 uint32_t min_allocated_send_bitrate_bps_ GUARDED_BY(&bitrate_crit_); |
| 192 int64_t num_bitrate_updates_ GUARDED_BY(&bitrate_crit_); | |
| 193 uint32_t configured_max_padding_bitrate_bps_ GUARDED_BY(&bitrate_crit_); | 190 uint32_t configured_max_padding_bitrate_bps_ GUARDED_BY(&bitrate_crit_); |
| 191 AvgCounter estimated_send_bitrate_kbps_counter_ GUARDED_BY(&bitrate_crit_); | |
| 192 AvgCounter pacer_bitrate_kbps_counter_ GUARDED_BY(&bitrate_crit_); | |
| 194 | 193 |
| 195 std::map<std::string, rtc::NetworkRoute> network_routes_; | 194 std::map<std::string, rtc::NetworkRoute> network_routes_; |
| 196 | 195 |
| 197 VieRemb remb_; | 196 VieRemb remb_; |
| 198 const std::unique_ptr<CongestionController> congestion_controller_; | 197 const std::unique_ptr<CongestionController> congestion_controller_; |
| 199 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; | 198 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; |
| 200 const int64_t start_ms_; | 199 const int64_t start_ms_; |
| 201 // TODO(perkj): |worker_queue_| is supposed to replace | 200 // TODO(perkj): |worker_queue_| is supposed to replace |
| 202 // |module_process_thread_|. | 201 // |module_process_thread_|. |
| 203 // |worker_queue| is defined last to ensure all pending tasks are cancelled | 202 // |worker_queue| is defined last to ensure all pending tasks are cancelled |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 audio_network_state_(kNetworkUp), | 236 audio_network_state_(kNetworkUp), |
| 238 video_network_state_(kNetworkUp), | 237 video_network_state_(kNetworkUp), |
| 239 receive_crit_(RWLockWrapper::CreateRWLock()), | 238 receive_crit_(RWLockWrapper::CreateRWLock()), |
| 240 send_crit_(RWLockWrapper::CreateRWLock()), | 239 send_crit_(RWLockWrapper::CreateRWLock()), |
| 241 event_log_(RtcEventLog::Create(webrtc::Clock::GetRealTimeClock())), | 240 event_log_(RtcEventLog::Create(webrtc::Clock::GetRealTimeClock())), |
| 242 first_packet_sent_ms_(-1), | 241 first_packet_sent_ms_(-1), |
| 243 received_bytes_per_second_counter_(clock_, nullptr, true), | 242 received_bytes_per_second_counter_(clock_, nullptr, true), |
| 244 received_audio_bytes_per_second_counter_(clock_, nullptr, true), | 243 received_audio_bytes_per_second_counter_(clock_, nullptr, true), |
| 245 received_video_bytes_per_second_counter_(clock_, nullptr, true), | 244 received_video_bytes_per_second_counter_(clock_, nullptr, true), |
| 246 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), | 245 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), |
| 247 estimated_send_bitrate_sum_kbits_(0), | |
| 248 pacer_bitrate_sum_kbits_(0), | |
| 249 min_allocated_send_bitrate_bps_(0), | 246 min_allocated_send_bitrate_bps_(0), |
| 250 num_bitrate_updates_(0), | |
| 251 configured_max_padding_bitrate_bps_(0), | 247 configured_max_padding_bitrate_bps_(0), |
| 248 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), | |
| 249 pacer_bitrate_kbps_counter_(clock_, nullptr, true), | |
| 252 remb_(clock_), | 250 remb_(clock_), |
| 253 congestion_controller_( | 251 congestion_controller_( |
| 254 new CongestionController(clock_, this, &remb_, event_log_.get())), | 252 new CongestionController(clock_, this, &remb_, event_log_.get())), |
| 255 video_send_delay_stats_(new SendDelayStats(clock_)), | 253 video_send_delay_stats_(new SendDelayStats(clock_)), |
| 256 start_ms_(clock_->TimeInMilliseconds()), | 254 start_ms_(clock_->TimeInMilliseconds()), |
| 257 worker_queue_("call_worker_queue") { | 255 worker_queue_("call_worker_queue") { |
| 258 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 256 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 259 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); | 257 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
| 260 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, | 258 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, |
| 261 config.bitrate_config.min_bitrate_bps); | 259 config.bitrate_config.min_bitrate_bps); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 Trace::ReturnTrace(); | 311 Trace::ReturnTrace(); |
| 314 } | 312 } |
| 315 | 313 |
| 316 void Call::UpdateHistograms() { | 314 void Call::UpdateHistograms() { |
| 317 RTC_LOGGED_HISTOGRAM_COUNTS_100000( | 315 RTC_LOGGED_HISTOGRAM_COUNTS_100000( |
| 318 "WebRTC.Call.LifetimeInSeconds", | 316 "WebRTC.Call.LifetimeInSeconds", |
| 319 (clock_->TimeInMilliseconds() - start_ms_) / 1000); | 317 (clock_->TimeInMilliseconds() - start_ms_) / 1000); |
| 320 } | 318 } |
| 321 | 319 |
| 322 void Call::UpdateSendHistograms() { | 320 void Call::UpdateSendHistograms() { |
| 323 if (num_bitrate_updates_ == 0 || first_packet_sent_ms_ == -1) | 321 if (first_packet_sent_ms_ == -1) |
| 324 return; | 322 return; |
| 325 int64_t elapsed_sec = | 323 int64_t elapsed_sec = |
| 326 (clock_->TimeInMilliseconds() - first_packet_sent_ms_) / 1000; | 324 (clock_->TimeInMilliseconds() - first_packet_sent_ms_) / 1000; |
| 327 if (elapsed_sec < metrics::kMinRunTimeInSeconds) | 325 if (elapsed_sec < metrics::kMinRunTimeInSeconds) |
| 328 return; | 326 return; |
| 329 int send_bitrate_kbps = | 327 const int kMinRequiredPeriodicSamples = 5; |
| 330 estimated_send_bitrate_sum_kbits_ / num_bitrate_updates_; | 328 AggregatedStats send_bitrate_stats = |
| 331 int pacer_bitrate_kbps = pacer_bitrate_sum_kbits_ / num_bitrate_updates_; | 329 estimated_send_bitrate_kbps_counter_.ProcessAndGetStats(); |
| 332 if (send_bitrate_kbps > 0) { | 330 if (send_bitrate_stats.num_samples > kMinRequiredPeriodicSamples) { |
| 333 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.EstimatedSendBitrateInKbps", | 331 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.EstimatedSendBitrateInKbps", |
| 334 send_bitrate_kbps); | 332 send_bitrate_stats.average); |
| 335 } | 333 } |
| 336 if (pacer_bitrate_kbps > 0) { | 334 AggregatedStats pacer_bitrate_stats = |
| 335 pacer_bitrate_kbps_counter_.ProcessAndGetStats(); | |
| 336 if (pacer_bitrate_stats.num_samples > kMinRequiredPeriodicSamples) { | |
| 337 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.PacerBitrateInKbps", | 337 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.PacerBitrateInKbps", |
| 338 pacer_bitrate_kbps); | 338 pacer_bitrate_stats.average); |
| 339 } | 339 } |
| 340 } | 340 } |
| 341 | 341 |
| 342 void Call::UpdateReceiveHistograms() { | 342 void Call::UpdateReceiveHistograms() { |
| 343 const int kMinRequiredPeriodicSamples = 5; | 343 const int kMinRequiredPeriodicSamples = 5; |
| 344 AggregatedStats video_bytes_per_sec = | 344 AggregatedStats video_bytes_per_sec = |
| 345 received_video_bytes_per_second_counter_.GetStats(); | 345 received_video_bytes_per_second_counter_.GetStats(); |
| 346 if (video_bytes_per_sec.num_samples > kMinRequiredPeriodicSamples) { | 346 if (video_bytes_per_sec.num_samples > kMinRequiredPeriodicSamples) { |
| 347 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.VideoBitrateReceivedInKbps", | 347 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.VideoBitrateReceivedInKbps", |
| 348 video_bytes_per_sec.average * 8 / 1000); | 348 video_bytes_per_sec.average * 8 / 1000); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 750 if (!worker_queue_.IsCurrent()) { | 750 if (!worker_queue_.IsCurrent()) { |
| 751 worker_queue_.PostTask([this, target_bitrate_bps, fraction_loss, rtt_ms] { | 751 worker_queue_.PostTask([this, target_bitrate_bps, fraction_loss, rtt_ms] { |
| 752 OnNetworkChanged(target_bitrate_bps, fraction_loss, rtt_ms); | 752 OnNetworkChanged(target_bitrate_bps, fraction_loss, rtt_ms); |
| 753 }); | 753 }); |
| 754 return; | 754 return; |
| 755 } | 755 } |
| 756 RTC_DCHECK_RUN_ON(&worker_queue_); | 756 RTC_DCHECK_RUN_ON(&worker_queue_); |
| 757 bitrate_allocator_->OnNetworkChanged(target_bitrate_bps, fraction_loss, | 757 bitrate_allocator_->OnNetworkChanged(target_bitrate_bps, fraction_loss, |
| 758 rtt_ms); | 758 rtt_ms); |
| 759 | 759 |
| 760 // Ignore updates where the bitrate is zero because the aggregate network | 760 // Ignore updates if bitrate is zero (the aggregate network state is down). |
| 761 // state is down. | 761 if (target_bitrate_bps == 0) { |
| 762 if (target_bitrate_bps > 0) { | |
| 763 { | |
| 764 ReadLockScoped read_lock(*send_crit_); | |
| 765 // Do not update the stats if we are not sending video. | |
| 766 if (video_send_streams_.empty()) | |
| 767 return; | |
| 768 } | |
| 769 rtc::CritScope lock(&bitrate_crit_); | 762 rtc::CritScope lock(&bitrate_crit_); |
|
perkj_webrtc
2016/09/10 07:12:54
is this lock still needed?
| |
| 770 // We only update these stats if we have send streams, and assume that | 763 estimated_send_bitrate_kbps_counter_.ProcessAndPause(); |
| 771 // OnNetworkChanged is called roughly with a fixed frequency. | 764 pacer_bitrate_kbps_counter_.ProcessAndPause(); |
| 772 estimated_send_bitrate_sum_kbits_ += target_bitrate_bps / 1000; | 765 return; |
| 773 // Pacer bitrate might be higher than bitrate estimate if enforcing min | |
| 774 // bitrate. | |
| 775 uint32_t pacer_bitrate_bps = | |
| 776 std::max(target_bitrate_bps, min_allocated_send_bitrate_bps_); | |
| 777 pacer_bitrate_sum_kbits_ += pacer_bitrate_bps / 1000; | |
| 778 ++num_bitrate_updates_; | |
| 779 } | 766 } |
| 767 | |
| 768 bool sending_video; | |
|
perkj_webrtc
2016/09/10 07:12:54
dito- lock needed?
| |
| 769 { | |
| 770 ReadLockScoped read_lock(*send_crit_); | |
| 771 sending_video = !video_send_streams_.empty(); | |
| 772 } | |
| 773 | |
| 774 rtc::CritScope lock(&bitrate_crit_); | |
|
perkj_webrtc
2016/09/10 07:12:54
and this?
| |
| 775 if (!sending_video) { | |
| 776 // Do not update the stats if we are not sending video. | |
| 777 estimated_send_bitrate_kbps_counter_.ProcessAndPause(); | |
| 778 pacer_bitrate_kbps_counter_.ProcessAndPause(); | |
| 779 return; | |
| 780 } | |
| 781 estimated_send_bitrate_kbps_counter_.Add(target_bitrate_bps / 1000); | |
| 782 // Pacer bitrate may be higher than bitrate estimate if enforcing min bitrate. | |
| 783 uint32_t pacer_bitrate_bps = | |
| 784 std::max(target_bitrate_bps, min_allocated_send_bitrate_bps_); | |
| 785 pacer_bitrate_kbps_counter_.Add(pacer_bitrate_bps / 1000); | |
| 780 } | 786 } |
| 781 | 787 |
| 782 void Call::OnAllocationLimitsChanged(uint32_t min_send_bitrate_bps, | 788 void Call::OnAllocationLimitsChanged(uint32_t min_send_bitrate_bps, |
| 783 uint32_t max_padding_bitrate_bps) { | 789 uint32_t max_padding_bitrate_bps) { |
| 784 congestion_controller_->SetAllocatedSendBitrateLimits( | 790 congestion_controller_->SetAllocatedSendBitrateLimits( |
| 785 min_send_bitrate_bps, max_padding_bitrate_bps); | 791 min_send_bitrate_bps, max_padding_bitrate_bps); |
| 786 rtc::CritScope lock(&bitrate_crit_); | 792 rtc::CritScope lock(&bitrate_crit_); |
| 787 min_allocated_send_bitrate_bps_ = min_send_bitrate_bps; | 793 min_allocated_send_bitrate_bps_ = min_send_bitrate_bps; |
| 788 configured_max_padding_bitrate_bps_ = max_padding_bitrate_bps; | 794 configured_max_padding_bitrate_bps_ = max_padding_bitrate_bps; |
| 789 } | 795 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 934 // thread. Then this check can be enabled. | 940 // thread. Then this check can be enabled. |
| 935 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); | 941 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); |
| 936 if (RtpHeaderParser::IsRtcp(packet, length)) | 942 if (RtpHeaderParser::IsRtcp(packet, length)) |
| 937 return DeliverRtcp(media_type, packet, length); | 943 return DeliverRtcp(media_type, packet, length); |
| 938 | 944 |
| 939 return DeliverRtp(media_type, packet, length, packet_time); | 945 return DeliverRtp(media_type, packet, length, packet_time); |
| 940 } | 946 } |
| 941 | 947 |
| 942 } // namespace internal | 948 } // namespace internal |
| 943 } // namespace webrtc | 949 } // namespace webrtc |
| OLD | NEW |