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 |
11 #include "webrtc/video/send_statistics_proxy.h" | 11 #include "webrtc/video/send_statistics_proxy.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <cmath> | 14 #include <cmath> |
15 #include <map> | 15 #include <map> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 | |
19 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
20 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 19 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
21 #include "webrtc/system_wrappers/include/metrics.h" | 20 #include "webrtc/system_wrappers/include/metrics.h" |
22 | 21 |
23 namespace webrtc { | 22 namespace webrtc { |
24 namespace { | 23 namespace { |
| 24 const float kEncodeTimeWeigthFactor = 0.5f; |
| 25 |
25 // Used by histograms. Values of entries should not be changed. | 26 // Used by histograms. Values of entries should not be changed. |
26 enum HistogramCodecType { | 27 enum HistogramCodecType { |
27 kVideoUnknown = 0, | 28 kVideoUnknown = 0, |
28 kVideoVp8 = 1, | 29 kVideoVp8 = 1, |
29 kVideoVp9 = 2, | 30 kVideoVp9 = 2, |
30 kVideoH264 = 3, | 31 kVideoH264 = 3, |
31 kVideoMax = 64, | 32 kVideoMax = 64, |
32 }; | 33 }; |
33 | 34 |
34 const char* GetUmaPrefix(VideoEncoderConfig::ContentType content_type) { | 35 const char* GetUmaPrefix(VideoEncoderConfig::ContentType content_type) { |
(...skipping 30 matching lines...) Expand all Loading... |
65 const int SendStatisticsProxy::kStatsTimeoutMs = 5000; | 66 const int SendStatisticsProxy::kStatsTimeoutMs = 5000; |
66 | 67 |
67 SendStatisticsProxy::SendStatisticsProxy( | 68 SendStatisticsProxy::SendStatisticsProxy( |
68 Clock* clock, | 69 Clock* clock, |
69 const VideoSendStream::Config& config, | 70 const VideoSendStream::Config& config, |
70 VideoEncoderConfig::ContentType content_type) | 71 VideoEncoderConfig::ContentType content_type) |
71 : clock_(clock), | 72 : clock_(clock), |
72 config_(config), | 73 config_(config), |
73 content_type_(content_type), | 74 content_type_(content_type), |
74 last_sent_frame_timestamp_(0), | 75 last_sent_frame_timestamp_(0), |
| 76 encode_time_(kEncodeTimeWeigthFactor), |
75 uma_container_(new UmaSamplesContainer(GetUmaPrefix(content_type_))) { | 77 uma_container_(new UmaSamplesContainer(GetUmaPrefix(content_type_))) { |
76 UpdateCodecTypeHistogram(config_.encoder_settings.payload_name); | 78 UpdateCodecTypeHistogram(config_.encoder_settings.payload_name); |
77 } | 79 } |
78 | 80 |
79 SendStatisticsProxy::~SendStatisticsProxy() {} | 81 SendStatisticsProxy::~SendStatisticsProxy() {} |
80 | 82 |
81 SendStatisticsProxy::UmaSamplesContainer::UmaSamplesContainer( | 83 SendStatisticsProxy::UmaSamplesContainer::UmaSamplesContainer( |
82 const char* prefix) | 84 const char* prefix) |
83 : uma_prefix_(prefix), | 85 : uma_prefix_(prefix), |
84 max_sent_width_per_timestamp_(0), | 86 max_sent_width_per_timestamp_(0), |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 163 |
162 void SendStatisticsProxy::OnOutgoingRate(uint32_t framerate, uint32_t bitrate) { | 164 void SendStatisticsProxy::OnOutgoingRate(uint32_t framerate, uint32_t bitrate) { |
163 rtc::CritScope lock(&crit_); | 165 rtc::CritScope lock(&crit_); |
164 stats_.encode_frame_rate = framerate; | 166 stats_.encode_frame_rate = framerate; |
165 stats_.media_bitrate_bps = bitrate; | 167 stats_.media_bitrate_bps = bitrate; |
166 } | 168 } |
167 | 169 |
168 void SendStatisticsProxy::CpuOveruseMetricsUpdated( | 170 void SendStatisticsProxy::CpuOveruseMetricsUpdated( |
169 const CpuOveruseMetrics& metrics) { | 171 const CpuOveruseMetrics& metrics) { |
170 rtc::CritScope lock(&crit_); | 172 rtc::CritScope lock(&crit_); |
171 // TODO(asapersson): Change to use OnEncodedFrame() for avg_encode_time_ms. | |
172 stats_.avg_encode_time_ms = metrics.avg_encode_time_ms; | |
173 stats_.encode_usage_percent = metrics.encode_usage_percent; | 173 stats_.encode_usage_percent = metrics.encode_usage_percent; |
174 } | 174 } |
175 | 175 |
176 void SendStatisticsProxy::OnSuspendChange(bool is_suspended) { | 176 void SendStatisticsProxy::OnSuspendChange(bool is_suspended) { |
177 rtc::CritScope lock(&crit_); | 177 rtc::CritScope lock(&crit_); |
178 stats_.suspended = is_suspended; | 178 stats_.suspended = is_suspended; |
179 } | 179 } |
180 | 180 |
181 VideoSendStream::Stats SendStatisticsProxy::GetStats() { | 181 VideoSendStream::Stats SendStatisticsProxy::GetStats() { |
182 rtc::CritScope lock(&crit_); | 182 rtc::CritScope lock(&crit_); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 void SendStatisticsProxy::OnIncomingFrame(int width, int height) { | 301 void SendStatisticsProxy::OnIncomingFrame(int width, int height) { |
302 rtc::CritScope lock(&crit_); | 302 rtc::CritScope lock(&crit_); |
303 uma_container_->input_frame_rate_tracker_.AddSamples(1); | 303 uma_container_->input_frame_rate_tracker_.AddSamples(1); |
304 uma_container_->input_width_counter_.Add(width); | 304 uma_container_->input_width_counter_.Add(width); |
305 uma_container_->input_height_counter_.Add(height); | 305 uma_container_->input_height_counter_.Add(height); |
306 } | 306 } |
307 | 307 |
308 void SendStatisticsProxy::OnEncodedFrame(int encode_time_ms) { | 308 void SendStatisticsProxy::OnEncodedFrame(int encode_time_ms) { |
309 rtc::CritScope lock(&crit_); | 309 rtc::CritScope lock(&crit_); |
310 uma_container_->encode_time_counter_.Add(encode_time_ms); | 310 uma_container_->encode_time_counter_.Add(encode_time_ms); |
| 311 encode_time_.Apply(1.0f, encode_time_ms); |
| 312 stats_.avg_encode_time_ms = round(encode_time_.filtered()); |
311 } | 313 } |
312 | 314 |
313 void SendStatisticsProxy::RtcpPacketTypesCounterUpdated( | 315 void SendStatisticsProxy::RtcpPacketTypesCounterUpdated( |
314 uint32_t ssrc, | 316 uint32_t ssrc, |
315 const RtcpPacketTypeCounter& packet_counter) { | 317 const RtcpPacketTypeCounter& packet_counter) { |
316 rtc::CritScope lock(&crit_); | 318 rtc::CritScope lock(&crit_); |
317 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 319 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
318 if (stats == nullptr) | 320 if (stats == nullptr) |
319 return; | 321 return; |
320 | 322 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 return Fraction(min_required_samples, 1000.0f); | 410 return Fraction(min_required_samples, 1000.0f); |
409 } | 411 } |
410 | 412 |
411 int SendStatisticsProxy::BoolSampleCounter::Fraction( | 413 int SendStatisticsProxy::BoolSampleCounter::Fraction( |
412 int min_required_samples, float multiplier) const { | 414 int min_required_samples, float multiplier) const { |
413 if (num_samples < min_required_samples || num_samples == 0) | 415 if (num_samples < min_required_samples || num_samples == 0) |
414 return -1; | 416 return -1; |
415 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); | 417 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); |
416 } | 418 } |
417 } // namespace webrtc | 419 } // namespace webrtc |
OLD | NEW |