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

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

Issue 2307913002: Update AvgCounter to have the ability to include last period metric for subsequent intervals withou… (Closed)
Patch Set: Created 4 years, 3 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 | « no previous file | webrtc/video/send_delay_stats.cc » ('j') | webrtc/video/stats_counter.cc » ('J')
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 25 matching lines...) Expand all
36 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 36 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
37 #include "webrtc/modules/utility/include/process_thread.h" 37 #include "webrtc/modules/utility/include/process_thread.h"
38 #include "webrtc/system_wrappers/include/clock.h" 38 #include "webrtc/system_wrappers/include/clock.h"
39 #include "webrtc/system_wrappers/include/cpu_info.h" 39 #include "webrtc/system_wrappers/include/cpu_info.h"
40 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 40 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
41 #include "webrtc/system_wrappers/include/metrics.h" 41 #include "webrtc/system_wrappers/include/metrics.h"
42 #include "webrtc/system_wrappers/include/rw_lock_wrapper.h" 42 #include "webrtc/system_wrappers/include/rw_lock_wrapper.h"
43 #include "webrtc/system_wrappers/include/trace.h" 43 #include "webrtc/system_wrappers/include/trace.h"
44 #include "webrtc/video/call_stats.h" 44 #include "webrtc/video/call_stats.h"
45 #include "webrtc/video/send_delay_stats.h" 45 #include "webrtc/video/send_delay_stats.h"
46 #include "webrtc/video/stats_counter.h"
46 #include "webrtc/video/video_receive_stream.h" 47 #include "webrtc/video/video_receive_stream.h"
47 #include "webrtc/video/video_send_stream.h" 48 #include "webrtc/video/video_send_stream.h"
48 #include "webrtc/video/vie_remb.h" 49 #include "webrtc/video/vie_remb.h"
49 #include "webrtc/voice_engine/include/voe_codec.h" 50 #include "webrtc/voice_engine/include/voe_codec.h"
50 51
51 namespace webrtc { 52 namespace webrtc {
52 53
53 const int Call::Config::kDefaultStartBitrateBps = 300000; 54 const int Call::Config::kDefaultStartBitrateBps = 300000;
54 55
55 namespace internal { 56 namespace internal {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 int64_t received_video_bytes_; 180 int64_t received_video_bytes_;
180 int64_t received_audio_bytes_; 181 int64_t received_audio_bytes_;
181 int64_t received_rtcp_bytes_; 182 int64_t received_rtcp_bytes_;
182 int64_t first_rtp_packet_received_ms_; 183 int64_t first_rtp_packet_received_ms_;
183 int64_t last_rtp_packet_received_ms_; 184 int64_t last_rtp_packet_received_ms_;
184 int64_t first_packet_sent_ms_; 185 int64_t first_packet_sent_ms_;
185 186
186 // TODO(holmer): Remove this lock once BitrateController no longer calls 187 // TODO(holmer): Remove this lock once BitrateController no longer calls
187 // OnNetworkChanged from multiple threads. 188 // OnNetworkChanged from multiple threads.
188 rtc::CriticalSection bitrate_crit_; 189 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_); 190 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_); 191 uint32_t configured_max_padding_bitrate_bps_ GUARDED_BY(&bitrate_crit_);
192 AvgCounter estimated_send_bitrate_kbps_counter_ GUARDED_BY(&bitrate_crit_);
193 AvgCounter pacer_bitrate_kbps_counter_ GUARDED_BY(&bitrate_crit_);
194 194
195 std::map<std::string, rtc::NetworkRoute> network_routes_; 195 std::map<std::string, rtc::NetworkRoute> network_routes_;
196 196
197 VieRemb remb_; 197 VieRemb remb_;
198 const std::unique_ptr<CongestionController> congestion_controller_; 198 const std::unique_ptr<CongestionController> congestion_controller_;
199 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; 199 const std::unique_ptr<SendDelayStats> video_send_delay_stats_;
200 const int64_t start_ms_; 200 const int64_t start_ms_;
201 201
202 RTC_DISALLOW_COPY_AND_ASSIGN(Call); 202 RTC_DISALLOW_COPY_AND_ASSIGN(Call);
203 }; 203 };
(...skipping 29 matching lines...) Expand all
233 video_network_state_(kNetworkUp), 233 video_network_state_(kNetworkUp),
234 receive_crit_(RWLockWrapper::CreateRWLock()), 234 receive_crit_(RWLockWrapper::CreateRWLock()),
235 send_crit_(RWLockWrapper::CreateRWLock()), 235 send_crit_(RWLockWrapper::CreateRWLock()),
236 event_log_(RtcEventLog::Create(webrtc::Clock::GetRealTimeClock())), 236 event_log_(RtcEventLog::Create(webrtc::Clock::GetRealTimeClock())),
237 received_video_bytes_(0), 237 received_video_bytes_(0),
238 received_audio_bytes_(0), 238 received_audio_bytes_(0),
239 received_rtcp_bytes_(0), 239 received_rtcp_bytes_(0),
240 first_rtp_packet_received_ms_(-1), 240 first_rtp_packet_received_ms_(-1),
241 last_rtp_packet_received_ms_(-1), 241 last_rtp_packet_received_ms_(-1),
242 first_packet_sent_ms_(-1), 242 first_packet_sent_ms_(-1),
243 estimated_send_bitrate_sum_kbits_(0),
244 pacer_bitrate_sum_kbits_(0),
245 min_allocated_send_bitrate_bps_(0), 243 min_allocated_send_bitrate_bps_(0),
246 num_bitrate_updates_(0),
247 configured_max_padding_bitrate_bps_(0), 244 configured_max_padding_bitrate_bps_(0),
245 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true),
246 pacer_bitrate_kbps_counter_(clock_, nullptr, true),
248 remb_(clock_), 247 remb_(clock_),
249 congestion_controller_( 248 congestion_controller_(
250 new CongestionController(clock_, this, &remb_, event_log_.get())), 249 new CongestionController(clock_, this, &remb_, event_log_.get())),
251 video_send_delay_stats_(new SendDelayStats(clock_)), 250 video_send_delay_stats_(new SendDelayStats(clock_)),
252 start_ms_(clock_->TimeInMilliseconds()) { 251 start_ms_(clock_->TimeInMilliseconds()) {
253 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 252 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
254 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); 253 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0);
255 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, 254 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps,
256 config.bitrate_config.min_bitrate_bps); 255 config.bitrate_config.min_bitrate_bps);
257 if (config.bitrate_config.max_bitrate_bps != -1) { 256 if (config.bitrate_config.max_bitrate_bps != -1) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 Trace::ReturnTrace(); 303 Trace::ReturnTrace();
305 } 304 }
306 305
307 void Call::UpdateHistograms() { 306 void Call::UpdateHistograms() {
308 RTC_LOGGED_HISTOGRAM_COUNTS_100000( 307 RTC_LOGGED_HISTOGRAM_COUNTS_100000(
309 "WebRTC.Call.LifetimeInSeconds", 308 "WebRTC.Call.LifetimeInSeconds",
310 (clock_->TimeInMilliseconds() - start_ms_) / 1000); 309 (clock_->TimeInMilliseconds() - start_ms_) / 1000);
311 } 310 }
312 311
313 void Call::UpdateSendHistograms() { 312 void Call::UpdateSendHistograms() {
314 if (num_bitrate_updates_ == 0 || first_packet_sent_ms_ == -1) 313 if (first_packet_sent_ms_ == -1)
315 return; 314 return;
316 int64_t elapsed_sec = 315 int64_t elapsed_sec =
317 (clock_->TimeInMilliseconds() - first_packet_sent_ms_) / 1000; 316 (clock_->TimeInMilliseconds() - first_packet_sent_ms_) / 1000;
318 if (elapsed_sec < metrics::kMinRunTimeInSeconds) 317 if (elapsed_sec < metrics::kMinRunTimeInSeconds)
319 return; 318 return;
320 int send_bitrate_kbps = 319 const int kMinRequiredPeriodicSamples = 5;
321 estimated_send_bitrate_sum_kbits_ / num_bitrate_updates_; 320 AggregatedStats send_bitrate_stats =
322 int pacer_bitrate_kbps = pacer_bitrate_sum_kbits_ / num_bitrate_updates_; 321 estimated_send_bitrate_kbps_counter_.ProcessAndGetStats();
323 if (send_bitrate_kbps > 0) { 322 if (send_bitrate_stats.num_samples >= kMinRequiredPeriodicSamples) {
324 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.EstimatedSendBitrateInKbps", 323 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.EstimatedSendBitrateInKbps",
325 send_bitrate_kbps); 324 send_bitrate_stats.average);
326 } 325 }
327 if (pacer_bitrate_kbps > 0) { 326 AggregatedStats pacer_bitrate_stats =
327 pacer_bitrate_kbps_counter_.ProcessAndGetStats();
328 if (pacer_bitrate_stats.num_samples >= kMinRequiredPeriodicSamples) {
328 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.PacerBitrateInKbps", 329 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.PacerBitrateInKbps",
329 pacer_bitrate_kbps); 330 pacer_bitrate_stats.average);
330 } 331 }
331 } 332 }
332 333
333 void Call::UpdateReceiveHistograms() { 334 void Call::UpdateReceiveHistograms() {
334 if (first_rtp_packet_received_ms_ == -1) 335 if (first_rtp_packet_received_ms_ == -1)
335 return; 336 return;
336 int64_t elapsed_sec = 337 int64_t elapsed_sec =
337 (last_rtp_packet_received_ms_ - first_rtp_packet_received_ms_) / 1000; 338 (last_rtp_packet_received_ms_ - first_rtp_packet_received_ms_) / 1000;
338 if (elapsed_sec < metrics::kMinRunTimeInSeconds) 339 if (elapsed_sec < metrics::kMinRunTimeInSeconds)
339 return; 340 return;
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 video_send_delay_stats_->OnSentPacket(sent_packet.packet_id, 726 video_send_delay_stats_->OnSentPacket(sent_packet.packet_id,
726 clock_->TimeInMilliseconds()); 727 clock_->TimeInMilliseconds());
727 congestion_controller_->OnSentPacket(sent_packet); 728 congestion_controller_->OnSentPacket(sent_packet);
728 } 729 }
729 730
730 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, 731 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss,
731 int64_t rtt_ms) { 732 int64_t rtt_ms) {
732 bitrate_allocator_->OnNetworkChanged(target_bitrate_bps, fraction_loss, 733 bitrate_allocator_->OnNetworkChanged(target_bitrate_bps, fraction_loss,
733 rtt_ms); 734 rtt_ms);
734 735
735 // Ignore updates where the bitrate is zero because the aggregate network 736 // Ignore updates if bitrate is zero (the aggregate network state is down).
736 // state is down. 737 if (target_bitrate_bps == 0) {
737 if (target_bitrate_bps > 0) {
738 {
739 ReadLockScoped read_lock(*send_crit_);
740 // Do not update the stats if we are not sending video.
741 if (video_send_streams_.empty())
742 return;
743 }
744 rtc::CritScope lock(&bitrate_crit_); 738 rtc::CritScope lock(&bitrate_crit_);
745 // We only update these stats if we have send streams, and assume that 739 estimated_send_bitrate_kbps_counter_.ProcessAndPause();
746 // OnNetworkChanged is called roughly with a fixed frequency. 740 pacer_bitrate_kbps_counter_.ProcessAndPause();
747 estimated_send_bitrate_sum_kbits_ += target_bitrate_bps / 1000; 741 return;
748 // Pacer bitrate might be higher than bitrate estimate if enforcing min
749 // bitrate.
750 uint32_t pacer_bitrate_bps =
751 std::max(target_bitrate_bps, min_allocated_send_bitrate_bps_);
752 pacer_bitrate_sum_kbits_ += pacer_bitrate_bps / 1000;
753 ++num_bitrate_updates_;
754 } 742 }
743
744 bool sending_video;
745 {
746 ReadLockScoped read_lock(*send_crit_);
747 sending_video = !video_send_streams_.empty();
748 }
749
750 rtc::CritScope lock(&bitrate_crit_);
751 if (!sending_video) {
752 // Do not update the stats if we are not sending video.
753 estimated_send_bitrate_kbps_counter_.ProcessAndPause();
754 pacer_bitrate_kbps_counter_.ProcessAndPause();
755 return;
756 }
757 estimated_send_bitrate_kbps_counter_.Add(target_bitrate_bps / 1000);
758 // Pacer bitrate may be higher than bitrate estimate if enforcing min bitrate.
759 uint32_t pacer_bitrate_bps =
760 std::max(target_bitrate_bps, min_allocated_send_bitrate_bps_);
761 pacer_bitrate_kbps_counter_.Add(pacer_bitrate_bps / 1000);
755 } 762 }
756 763
757 void Call::OnAllocationLimitsChanged(uint32_t min_send_bitrate_bps, 764 void Call::OnAllocationLimitsChanged(uint32_t min_send_bitrate_bps,
758 uint32_t max_padding_bitrate_bps) { 765 uint32_t max_padding_bitrate_bps) {
759 congestion_controller_->SetAllocatedSendBitrateLimits( 766 congestion_controller_->SetAllocatedSendBitrateLimits(
760 min_send_bitrate_bps, max_padding_bitrate_bps); 767 min_send_bitrate_bps, max_padding_bitrate_bps);
761 rtc::CritScope lock(&bitrate_crit_); 768 rtc::CritScope lock(&bitrate_crit_);
762 min_allocated_send_bitrate_bps_ = min_send_bitrate_bps; 769 min_allocated_send_bitrate_bps_ = min_send_bitrate_bps;
763 configured_max_padding_bitrate_bps_ = max_padding_bitrate_bps; 770 configured_max_padding_bitrate_bps_ = max_padding_bitrate_bps;
764 } 771 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 // thread. Then this check can be enabled. 914 // thread. Then this check can be enabled.
908 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); 915 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread());
909 if (RtpHeaderParser::IsRtcp(packet, length)) 916 if (RtpHeaderParser::IsRtcp(packet, length))
910 return DeliverRtcp(media_type, packet, length); 917 return DeliverRtcp(media_type, packet, length);
911 918
912 return DeliverRtp(media_type, packet, length, packet_time); 919 return DeliverRtp(media_type, packet, length, packet_time);
913 } 920 }
914 921
915 } // namespace internal 922 } // namespace internal
916 } // namespace webrtc 923 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/video/send_delay_stats.cc » ('j') | webrtc/video/stats_counter.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698