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

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

Issue 2303763002: Use RateCounter for received bitrate stats. (Closed)
Patch Set: fix warning 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/stats_counter.h » ('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 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); 170 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_);
170 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); 171 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_);
171 172
172 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; 173 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_;
173 174
174 std::unique_ptr<webrtc::RtcEventLog> event_log_; 175 std::unique_ptr<webrtc::RtcEventLog> event_log_;
175 176
176 // The following members are only accessed (exclusively) from one thread and 177 // The following members are only accessed (exclusively) from one thread and
177 // from the destructor, and therefore doesn't need any explicit 178 // from the destructor, and therefore doesn't need any explicit
178 // synchronization. 179 // synchronization.
179 int64_t received_video_bytes_;
180 int64_t received_audio_bytes_;
181 int64_t received_rtcp_bytes_;
182 int64_t first_rtp_packet_received_ms_;
183 int64_t last_rtp_packet_received_ms_;
184 int64_t first_packet_sent_ms_; 180 int64_t first_packet_sent_ms_;
181 RateCounter received_bytes_per_second_counter_;
182 RateCounter received_audio_bytes_per_second_counter_;
183 RateCounter received_video_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_); 189 int64_t estimated_send_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_);
190 int64_t pacer_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_); 191 uint32_t min_allocated_send_bitrate_bps_ GUARDED_BY(&bitrate_crit_);
192 int64_t num_bitrate_updates_ 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_); 193 uint32_t configured_max_padding_bitrate_bps_ GUARDED_BY(&bitrate_crit_);
194 194
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 module_process_thread_(ProcessThread::Create("ModuleProcessThread")), 232 module_process_thread_(ProcessThread::Create("ModuleProcessThread")),
233 pacer_thread_(ProcessThread::Create("PacerThread")), 233 pacer_thread_(ProcessThread::Create("PacerThread")),
234 call_stats_(new CallStats(clock_)), 234 call_stats_(new CallStats(clock_)),
235 bitrate_allocator_(new BitrateAllocator(this)), 235 bitrate_allocator_(new BitrateAllocator(this)),
236 config_(config), 236 config_(config),
237 audio_network_state_(kNetworkUp), 237 audio_network_state_(kNetworkUp),
238 video_network_state_(kNetworkUp), 238 video_network_state_(kNetworkUp),
239 receive_crit_(RWLockWrapper::CreateRWLock()), 239 receive_crit_(RWLockWrapper::CreateRWLock()),
240 send_crit_(RWLockWrapper::CreateRWLock()), 240 send_crit_(RWLockWrapper::CreateRWLock()),
241 event_log_(RtcEventLog::Create(webrtc::Clock::GetRealTimeClock())), 241 event_log_(RtcEventLog::Create(webrtc::Clock::GetRealTimeClock())),
242 received_video_bytes_(0),
243 received_audio_bytes_(0),
244 received_rtcp_bytes_(0),
245 first_rtp_packet_received_ms_(-1),
246 last_rtp_packet_received_ms_(-1),
247 first_packet_sent_ms_(-1), 242 first_packet_sent_ms_(-1),
243 received_bytes_per_second_counter_(clock_, nullptr, true),
244 received_audio_bytes_per_second_counter_(clock_, nullptr, true),
245 received_video_bytes_per_second_counter_(clock_, nullptr, true),
246 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true),
248 estimated_send_bitrate_sum_kbits_(0), 247 estimated_send_bitrate_sum_kbits_(0),
249 pacer_bitrate_sum_kbits_(0), 248 pacer_bitrate_sum_kbits_(0),
250 min_allocated_send_bitrate_bps_(0), 249 min_allocated_send_bitrate_bps_(0),
251 num_bitrate_updates_(0), 250 num_bitrate_updates_(0),
252 configured_max_padding_bitrate_bps_(0), 251 configured_max_padding_bitrate_bps_(0),
253 remb_(clock_), 252 remb_(clock_),
254 congestion_controller_( 253 congestion_controller_(
255 new CongestionController(clock_, this, &remb_, event_log_.get())), 254 new CongestionController(clock_, this, &remb_, event_log_.get())),
256 video_send_delay_stats_(new SendDelayStats(clock_)), 255 video_send_delay_stats_(new SendDelayStats(clock_)),
257 start_ms_(clock_->TimeInMilliseconds()), 256 start_ms_(clock_->TimeInMilliseconds()),
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.EstimatedSendBitrateInKbps", 333 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.EstimatedSendBitrateInKbps",
335 send_bitrate_kbps); 334 send_bitrate_kbps);
336 } 335 }
337 if (pacer_bitrate_kbps > 0) { 336 if (pacer_bitrate_kbps > 0) {
338 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.PacerBitrateInKbps", 337 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.PacerBitrateInKbps",
339 pacer_bitrate_kbps); 338 pacer_bitrate_kbps);
340 } 339 }
341 } 340 }
342 341
343 void Call::UpdateReceiveHistograms() { 342 void Call::UpdateReceiveHistograms() {
344 if (first_rtp_packet_received_ms_ == -1) 343 const int kMinRequiredPeriodicSamples = 5;
345 return; 344 AggregatedStats video_bytes_per_sec =
346 int64_t elapsed_sec = 345 received_video_bytes_per_second_counter_.GetStats();
347 (last_rtp_packet_received_ms_ - first_rtp_packet_received_ms_) / 1000; 346 if (video_bytes_per_sec.num_samples > kMinRequiredPeriodicSamples) {
348 if (elapsed_sec < metrics::kMinRunTimeInSeconds)
349 return;
350 int audio_bitrate_kbps = received_audio_bytes_ * 8 / elapsed_sec / 1000;
351 int video_bitrate_kbps = received_video_bytes_ * 8 / elapsed_sec / 1000;
352 int rtcp_bitrate_bps = received_rtcp_bytes_ * 8 / elapsed_sec;
353 if (video_bitrate_kbps > 0) {
354 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.VideoBitrateReceivedInKbps", 347 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.VideoBitrateReceivedInKbps",
355 video_bitrate_kbps); 348 video_bytes_per_sec.average * 8 / 1000);
356 } 349 }
357 if (audio_bitrate_kbps > 0) { 350 AggregatedStats audio_bytes_per_sec =
351 received_audio_bytes_per_second_counter_.GetStats();
352 if (audio_bytes_per_sec.num_samples > kMinRequiredPeriodicSamples) {
358 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.AudioBitrateReceivedInKbps", 353 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.AudioBitrateReceivedInKbps",
359 audio_bitrate_kbps); 354 audio_bytes_per_sec.average * 8 / 1000);
360 } 355 }
361 if (rtcp_bitrate_bps > 0) { 356 AggregatedStats rtcp_bytes_per_sec =
357 received_rtcp_bytes_per_second_counter_.GetStats();
358 if (rtcp_bytes_per_sec.num_samples > kMinRequiredPeriodicSamples) {
362 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.RtcpBitrateReceivedInBps", 359 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.RtcpBitrateReceivedInBps",
363 rtcp_bitrate_bps); 360 rtcp_bytes_per_sec.average * 8);
364 } 361 }
365 RTC_LOGGED_HISTOGRAM_COUNTS_100000( 362 AggregatedStats recv_bytes_per_sec =
366 "WebRTC.Call.BitrateReceivedInKbps", 363 received_bytes_per_second_counter_.GetStats();
367 audio_bitrate_kbps + video_bitrate_kbps + rtcp_bitrate_bps / 1000); 364 if (recv_bytes_per_sec.num_samples > kMinRequiredPeriodicSamples) {
365 RTC_LOGGED_HISTOGRAM_COUNTS_100000("WebRTC.Call.BitrateReceivedInKbps",
366 recv_bytes_per_sec.average * 8 / 1000);
367 }
368 } 368 }
369 369
370 PacketReceiver* Call::Receiver() { 370 PacketReceiver* Call::Receiver() {
371 // TODO(solenberg): Some test cases in EndToEndTest use this from a different 371 // TODO(solenberg): Some test cases in EndToEndTest use this from a different
372 // thread. Re-enable once that is fixed. 372 // thread. Re-enable once that is fixed.
373 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 373 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
374 return this; 374 return this;
375 } 375 }
376 376
377 webrtc::AudioSendStream* Call::CreateAudioSendStream( 377 webrtc::AudioSendStream* Call::CreateAudioSendStream(
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 } 836 }
837 } 837 }
838 838
839 PacketReceiver::DeliveryStatus Call::DeliverRtcp(MediaType media_type, 839 PacketReceiver::DeliveryStatus Call::DeliverRtcp(MediaType media_type,
840 const uint8_t* packet, 840 const uint8_t* packet,
841 size_t length) { 841 size_t length) {
842 TRACE_EVENT0("webrtc", "Call::DeliverRtcp"); 842 TRACE_EVENT0("webrtc", "Call::DeliverRtcp");
843 // TODO(pbos): Make sure it's a valid packet. 843 // TODO(pbos): Make sure it's a valid packet.
844 // Return DELIVERY_UNKNOWN_SSRC if it can be determined that 844 // Return DELIVERY_UNKNOWN_SSRC if it can be determined that
845 // there's no receiver of the packet. 845 // there's no receiver of the packet.
846 received_rtcp_bytes_ += length; 846 if (received_bytes_per_second_counter_.HasSample()) {
847 // First RTP packet has been received.
848 received_bytes_per_second_counter_.Add(static_cast<int>(length));
849 received_rtcp_bytes_per_second_counter_.Add(static_cast<int>(length));
850 }
847 bool rtcp_delivered = false; 851 bool rtcp_delivered = false;
848 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { 852 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) {
849 ReadLockScoped read_lock(*receive_crit_); 853 ReadLockScoped read_lock(*receive_crit_);
850 for (VideoReceiveStream* stream : video_receive_streams_) { 854 for (VideoReceiveStream* stream : video_receive_streams_) {
851 if (stream->DeliverRtcp(packet, length)) 855 if (stream->DeliverRtcp(packet, length))
852 rtcp_delivered = true; 856 rtcp_delivered = true;
853 } 857 }
854 } 858 }
855 if (media_type == MediaType::ANY || media_type == MediaType::AUDIO) { 859 if (media_type == MediaType::ANY || media_type == MediaType::AUDIO) {
856 ReadLockScoped read_lock(*receive_crit_); 860 ReadLockScoped read_lock(*receive_crit_);
(...skipping 25 matching lines...) Expand all
882 886
883 PacketReceiver::DeliveryStatus Call::DeliverRtp(MediaType media_type, 887 PacketReceiver::DeliveryStatus Call::DeliverRtp(MediaType media_type,
884 const uint8_t* packet, 888 const uint8_t* packet,
885 size_t length, 889 size_t length,
886 const PacketTime& packet_time) { 890 const PacketTime& packet_time) {
887 TRACE_EVENT0("webrtc", "Call::DeliverRtp"); 891 TRACE_EVENT0("webrtc", "Call::DeliverRtp");
888 // Minimum RTP header size. 892 // Minimum RTP header size.
889 if (length < 12) 893 if (length < 12)
890 return DELIVERY_PACKET_ERROR; 894 return DELIVERY_PACKET_ERROR;
891 895
892 last_rtp_packet_received_ms_ = clock_->TimeInMilliseconds();
893 if (first_rtp_packet_received_ms_ == -1)
894 first_rtp_packet_received_ms_ = last_rtp_packet_received_ms_;
895
896 uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]); 896 uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]);
897 ReadLockScoped read_lock(*receive_crit_); 897 ReadLockScoped read_lock(*receive_crit_);
898 if (media_type == MediaType::ANY || media_type == MediaType::AUDIO) { 898 if (media_type == MediaType::ANY || media_type == MediaType::AUDIO) {
899 auto it = audio_receive_ssrcs_.find(ssrc); 899 auto it = audio_receive_ssrcs_.find(ssrc);
900 if (it != audio_receive_ssrcs_.end()) { 900 if (it != audio_receive_ssrcs_.end()) {
901 received_audio_bytes_ += length; 901 received_bytes_per_second_counter_.Add(static_cast<int>(length));
902 received_audio_bytes_per_second_counter_.Add(static_cast<int>(length));
902 auto status = it->second->DeliverRtp(packet, length, packet_time) 903 auto status = it->second->DeliverRtp(packet, length, packet_time)
903 ? DELIVERY_OK 904 ? DELIVERY_OK
904 : DELIVERY_PACKET_ERROR; 905 : DELIVERY_PACKET_ERROR;
905 if (status == DELIVERY_OK) 906 if (status == DELIVERY_OK)
906 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); 907 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length);
907 return status; 908 return status;
908 } 909 }
909 } 910 }
910 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { 911 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) {
911 auto it = video_receive_ssrcs_.find(ssrc); 912 auto it = video_receive_ssrcs_.find(ssrc);
912 if (it != video_receive_ssrcs_.end()) { 913 if (it != video_receive_ssrcs_.end()) {
913 received_video_bytes_ += length; 914 received_bytes_per_second_counter_.Add(static_cast<int>(length));
915 received_video_bytes_per_second_counter_.Add(static_cast<int>(length));
914 auto status = it->second->DeliverRtp(packet, length, packet_time) 916 auto status = it->second->DeliverRtp(packet, length, packet_time)
915 ? DELIVERY_OK 917 ? DELIVERY_OK
916 : DELIVERY_PACKET_ERROR; 918 : DELIVERY_PACKET_ERROR;
917 if (status == DELIVERY_OK) 919 if (status == DELIVERY_OK)
918 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); 920 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length);
919 return status; 921 return status;
920 } 922 }
921 } 923 }
922 return DELIVERY_UNKNOWN_SSRC; 924 return DELIVERY_UNKNOWN_SSRC;
923 } 925 }
924 926
925 PacketReceiver::DeliveryStatus Call::DeliverPacket( 927 PacketReceiver::DeliveryStatus Call::DeliverPacket(
926 MediaType media_type, 928 MediaType media_type,
927 const uint8_t* packet, 929 const uint8_t* packet,
928 size_t length, 930 size_t length,
929 const PacketTime& packet_time) { 931 const PacketTime& packet_time) {
930 // TODO(solenberg): Tests call this function on a network thread, libjingle 932 // TODO(solenberg): Tests call this function on a network thread, libjingle
931 // calls on the worker thread. We should move towards always using a network 933 // calls on the worker thread. We should move towards always using a network
932 // thread. Then this check can be enabled. 934 // thread. Then this check can be enabled.
933 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); 935 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread());
934 if (RtpHeaderParser::IsRtcp(packet, length)) 936 if (RtpHeaderParser::IsRtcp(packet, length))
935 return DeliverRtcp(media_type, packet, length); 937 return DeliverRtcp(media_type, packet, length);
936 938
937 return DeliverRtp(media_type, packet, length, packet_time); 939 return DeliverRtp(media_type, packet, length, packet_time);
938 } 940 }
939 941
940 } // namespace internal 942 } // namespace internal
941 } // namespace webrtc 943 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/video/stats_counter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698