blob: 15a2206589efd1b66eff41f3002429354bbbcd9f [file] [log] [blame]
sprang@webrtc.org09315702014-02-07 12:06:29 +00001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/video/receive_statistics_proxy.h"
12
asaperssonf839dcc2015-10-08 00:41:59 -070013#include <cmath>
14
15#include "webrtc/base/checks.h"
Henrik Kjellander2557b862015-11-18 22:00:21 +010016#include "webrtc/modules/video_coding/include/video_codec_interface.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010017#include "webrtc/system_wrappers/include/clock.h"
philipelbe742702016-11-30 01:31:40 -080018#include "webrtc/system_wrappers/include/field_trial.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010019#include "webrtc/system_wrappers/include/metrics.h"
sprang@webrtc.org09315702014-02-07 12:06:29 +000020
21namespace webrtc {
asaperssonde9e5ff2016-11-02 07:14:03 -070022namespace {
23// Periodic time interval for processing samples for |freq_offset_counter_|.
24const int64_t kFreqOffsetProcessIntervalMs = 40000;
25} // namespace
sprang@webrtc.org09315702014-02-07 12:06:29 +000026
sprang0ab8e812016-02-24 01:35:40 -080027ReceiveStatisticsProxy::ReceiveStatisticsProxy(
Tommi733b5472016-06-10 17:58:01 +020028 const VideoReceiveStream::Config* config,
sprang0ab8e812016-02-24 01:35:40 -080029 Clock* clock)
pbos@webrtc.org55707692014-12-19 15:45:03 +000030 : clock_(clock),
Tommi733b5472016-06-10 17:58:01 +020031 config_(*config),
asapersson4374a092016-07-27 00:39:09 -070032 start_ms_(clock->TimeInMilliseconds()),
sprang@webrtc.org09315702014-02-07 12:06:29 +000033 // 1000ms window, scale 1000 for ms to s.
34 decode_fps_estimator_(1000, 1000),
Tim Psiaki63046262015-09-14 10:38:08 -070035 renders_fps_estimator_(1000, 1000),
Honghai Zhang82d78622016-05-06 11:29:15 -070036 render_fps_tracker_(100, 10u),
asaperssonde9e5ff2016-11-02 07:14:03 -070037 render_pixel_tracker_(100, 10u),
asapersson0c43f772016-11-30 01:42:26 -080038 freq_offset_counter_(clock, nullptr, kFreqOffsetProcessIntervalMs),
39 first_report_block_time_ms_(-1) {
Tommi733b5472016-06-10 17:58:01 +020040 stats_.ssrc = config_.rtp.remote_ssrc;
41 for (auto it : config_.rtp.rtx)
sprang0ab8e812016-02-24 01:35:40 -080042 rtx_stats_[it.second.ssrc] = StreamDataCounters();
sprang@webrtc.org09315702014-02-07 12:06:29 +000043}
44
Åsa Persson3c391cb2015-04-27 10:09:49 +020045ReceiveStatisticsProxy::~ReceiveStatisticsProxy() {
46 UpdateHistograms();
47}
48
asaperssond89920b2015-07-22 06:52:00 -070049void ReceiveStatisticsProxy::UpdateHistograms() {
asapersson1d02d3e2016-09-09 22:40:25 -070050 RTC_HISTOGRAM_COUNTS_100000(
asapersson4374a092016-07-27 00:39:09 -070051 "WebRTC.Video.ReceiveStreamLifetimeInSeconds",
52 (clock_->TimeInMilliseconds() - start_ms_) / 1000);
53
asapersson0c43f772016-11-30 01:42:26 -080054 if (first_report_block_time_ms_ != -1 &&
55 ((clock_->TimeInMilliseconds() - first_report_block_time_ms_) / 1000) >=
56 metrics::kMinRunTimeInSeconds) {
57 int fraction_lost = report_block_stats_.FractionLostInPercent();
58 if (fraction_lost != -1) {
59 RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.ReceivedPacketsLostInPercent",
60 fraction_lost);
61 }
Åsa Persson3c391cb2015-04-27 10:09:49 +020062 }
asapersson0c43f772016-11-30 01:42:26 -080063
asapersson6718e972015-07-24 00:20:58 -070064 const int kMinRequiredSamples = 200;
asaperssonf839dcc2015-10-08 00:41:59 -070065 int samples = static_cast<int>(render_fps_tracker_.TotalSampleCount());
66 if (samples > kMinRequiredSamples) {
asapersson1d02d3e2016-09-09 22:40:25 -070067 RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.RenderFramesPerSecond",
68 round(render_fps_tracker_.ComputeTotalRate()));
69 RTC_HISTOGRAM_COUNTS_100000(
asapersson28ba9272016-01-25 05:58:23 -080070 "WebRTC.Video.RenderSqrtPixelsPerSecond",
Tim Psiakiad13d2f2015-11-10 16:34:50 -080071 round(render_pixel_tracker_.ComputeTotalRate()));
asaperssonf839dcc2015-10-08 00:41:59 -070072 }
asaperssond89920b2015-07-22 06:52:00 -070073 int width = render_width_counter_.Avg(kMinRequiredSamples);
74 int height = render_height_counter_.Avg(kMinRequiredSamples);
75 if (width != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -070076 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.ReceivedWidthInPixels", width);
77 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.ReceivedHeightInPixels", height);
asaperssond89920b2015-07-22 06:52:00 -070078 }
asaperssonf8cdd182016-03-15 01:00:47 -070079 int sync_offset_ms = sync_offset_counter_.Avg(kMinRequiredSamples);
pbos35fdb2a2016-05-03 03:32:10 -070080 if (sync_offset_ms != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -070081 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.AVSyncOffsetInMs", sync_offset_ms);
pbos35fdb2a2016-05-03 03:32:10 -070082 }
asaperssonde9e5ff2016-11-02 07:14:03 -070083 AggregatedStats freq_offset_stats = freq_offset_counter_.GetStats();
84 if (freq_offset_stats.num_samples > 0) {
85 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.RtpToNtpFreqOffsetInKhz",
86 freq_offset_stats.average);
asapersson43cb7162016-11-15 08:20:48 -080087 LOG(LS_INFO) << "WebRTC.Video.RtpToNtpFreqOffsetInKhz, "
88 << freq_offset_stats.ToString();
asaperssonde9e5ff2016-11-02 07:14:03 -070089 }
asaperssonf8cdd182016-03-15 01:00:47 -070090
asapersson86b01602015-10-20 23:55:26 -070091 int qp = qp_counters_.vp8.Avg(kMinRequiredSamples);
92 if (qp != -1)
asapersson1d02d3e2016-09-09 22:40:25 -070093 RTC_HISTOGRAM_COUNTS_200("WebRTC.Video.Decoded.Vp8.Qp", qp);
asapersson86b01602015-10-20 23:55:26 -070094
asapersson6718e972015-07-24 00:20:58 -070095 // TODO(asapersson): DecoderTiming() is call periodically (each 1000ms) and
96 // not per frame. Change decode time to include every frame.
97 const int kMinRequiredDecodeSamples = 5;
98 int decode_ms = decode_time_counter_.Avg(kMinRequiredDecodeSamples);
99 if (decode_ms != -1)
asapersson1d02d3e2016-09-09 22:40:25 -0700100 RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.DecodeTimeInMs", decode_ms);
asapersson13c433c2015-10-06 04:08:15 -0700101
philipelbe742702016-11-30 01:31:40 -0800102 if (field_trial::FindFullName("WebRTC-NewVideoJitterBuffer") !=
103 "Enabled") {
104 int jb_delay_ms =
105 jitter_buffer_delay_counter_.Avg(kMinRequiredDecodeSamples);
106 if (jb_delay_ms != -1) {
107 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.JitterBufferDelayInMs",
108 jb_delay_ms);
109 }
asapersson8688a4e2016-04-27 23:42:35 -0700110 }
111 int target_delay_ms = target_delay_counter_.Avg(kMinRequiredDecodeSamples);
112 if (target_delay_ms != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -0700113 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.TargetDelayInMs", target_delay_ms);
asapersson8688a4e2016-04-27 23:42:35 -0700114 }
115 int current_delay_ms = current_delay_counter_.Avg(kMinRequiredDecodeSamples);
116 if (current_delay_ms != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -0700117 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.CurrentDelayInMs",
118 current_delay_ms);
asapersson8688a4e2016-04-27 23:42:35 -0700119 }
asapersson13c433c2015-10-06 04:08:15 -0700120 int delay_ms = delay_counter_.Avg(kMinRequiredDecodeSamples);
121 if (delay_ms != -1)
asapersson1d02d3e2016-09-09 22:40:25 -0700122 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.OnewayDelayInMs", delay_ms);
sprang0ab8e812016-02-24 01:35:40 -0800123
asapersson1490f7a2016-09-23 02:09:46 -0700124 int e2e_delay_ms = e2e_delay_counter_.Avg(kMinRequiredSamples);
125 if (e2e_delay_ms != -1)
126 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.EndToEndDelayInMs", e2e_delay_ms);
127
sprang0ab8e812016-02-24 01:35:40 -0800128 StreamDataCounters rtp = stats_.rtp_stats;
129 StreamDataCounters rtx;
130 for (auto it : rtx_stats_)
131 rtx.Add(it.second);
132 StreamDataCounters rtp_rtx = rtp;
133 rtp_rtx.Add(rtx);
134 int64_t elapsed_sec =
135 rtp_rtx.TimeSinceFirstPacketInMs(clock_->TimeInMilliseconds()) / 1000;
136 if (elapsed_sec > metrics::kMinRunTimeInSeconds) {
asapersson1d02d3e2016-09-09 22:40:25 -0700137 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800138 "WebRTC.Video.BitrateReceivedInKbps",
139 static_cast<int>(rtp_rtx.transmitted.TotalBytes() * 8 / elapsed_sec /
140 1000));
asapersson1d02d3e2016-09-09 22:40:25 -0700141 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800142 "WebRTC.Video.MediaBitrateReceivedInKbps",
143 static_cast<int>(rtp.MediaPayloadBytes() * 8 / elapsed_sec / 1000));
asapersson1d02d3e2016-09-09 22:40:25 -0700144 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800145 "WebRTC.Video.PaddingBitrateReceivedInKbps",
146 static_cast<int>(rtp_rtx.transmitted.padding_bytes * 8 / elapsed_sec /
147 1000));
asapersson1d02d3e2016-09-09 22:40:25 -0700148 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800149 "WebRTC.Video.RetransmittedBitrateReceivedInKbps",
150 static_cast<int>(rtp_rtx.retransmitted.TotalBytes() * 8 / elapsed_sec /
151 1000));
152 if (!rtx_stats_.empty()) {
asapersson1d02d3e2016-09-09 22:40:25 -0700153 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.RtxBitrateReceivedInKbps",
154 static_cast<int>(rtx.transmitted.TotalBytes() *
155 8 / elapsed_sec / 1000));
sprang0ab8e812016-02-24 01:35:40 -0800156 }
brandtrb5f2c3f2016-10-04 23:28:39 -0700157 if (config_.rtp.ulpfec.ulpfec_payload_type != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -0700158 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800159 "WebRTC.Video.FecBitrateReceivedInKbps",
160 static_cast<int>(rtp_rtx.fec.TotalBytes() * 8 / elapsed_sec / 1000));
161 }
sprang07fb9be2016-02-24 07:55:00 -0800162 const RtcpPacketTypeCounter& counters = stats_.rtcp_packet_type_counts;
asapersson1d02d3e2016-09-09 22:40:25 -0700163 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.NackPacketsSentPerMinute",
164 counters.nack_packets * 60 / elapsed_sec);
165 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.FirPacketsSentPerMinute",
166 counters.fir_packets * 60 / elapsed_sec);
167 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.PliPacketsSentPerMinute",
168 counters.pli_packets * 60 / elapsed_sec);
sprang07fb9be2016-02-24 07:55:00 -0800169 if (counters.nack_requests > 0) {
asapersson1d02d3e2016-09-09 22:40:25 -0700170 RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.UniqueNackRequestsSentInPercent",
171 counters.UniqueNackRequestsInPercent());
sprang07fb9be2016-02-24 07:55:00 -0800172 }
sprang0ab8e812016-02-24 01:35:40 -0800173 }
Åsa Persson3c391cb2015-04-27 10:09:49 +0200174}
sprang@webrtc.org09315702014-02-07 12:06:29 +0000175
176VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const {
Peter Boströmf2f82832015-05-01 13:00:41 +0200177 rtc::CritScope lock(&crit_);
pbos@webrtc.org55707692014-12-19 15:45:03 +0000178 return stats_;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000179}
180
pbosf42376c2015-08-28 07:35:32 -0700181void ReceiveStatisticsProxy::OnIncomingPayloadType(int payload_type) {
182 rtc::CritScope lock(&crit_);
183 stats_.current_payload_type = payload_type;
184}
185
Peter Boströmb7d9a972015-12-18 16:01:11 +0100186void ReceiveStatisticsProxy::OnDecoderImplementationName(
187 const char* implementation_name) {
188 rtc::CritScope lock(&crit_);
189 stats_.decoder_implementation_name = implementation_name;
190}
pbosf42376c2015-08-28 07:35:32 -0700191void ReceiveStatisticsProxy::OnIncomingRate(unsigned int framerate,
192 unsigned int bitrate_bps) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200193 rtc::CritScope lock(&crit_);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000194 stats_.network_frame_rate = framerate;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000195 stats_.total_bitrate_bps = bitrate_bps;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000196}
197
pbosf42376c2015-08-28 07:35:32 -0700198void ReceiveStatisticsProxy::OnDecoderTiming(int decode_ms,
199 int max_decode_ms,
200 int current_delay_ms,
201 int target_delay_ms,
202 int jitter_buffer_ms,
203 int min_playout_delay_ms,
asapersson13c433c2015-10-06 04:08:15 -0700204 int render_delay_ms,
205 int64_t rtt_ms) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200206 rtc::CritScope lock(&crit_);
pbos@webrtc.org09c77b92015-02-25 10:42:16 +0000207 stats_.decode_ms = decode_ms;
208 stats_.max_decode_ms = max_decode_ms;
209 stats_.current_delay_ms = current_delay_ms;
210 stats_.target_delay_ms = target_delay_ms;
211 stats_.jitter_buffer_ms = jitter_buffer_ms;
212 stats_.min_playout_delay_ms = min_playout_delay_ms;
213 stats_.render_delay_ms = render_delay_ms;
asapersson6718e972015-07-24 00:20:58 -0700214 decode_time_counter_.Add(decode_ms);
asapersson8688a4e2016-04-27 23:42:35 -0700215 jitter_buffer_delay_counter_.Add(jitter_buffer_ms);
216 target_delay_counter_.Add(target_delay_ms);
217 current_delay_counter_.Add(current_delay_ms);
asaperssona1862882016-04-18 00:41:05 -0700218 // Network delay (rtt/2) + target_delay_ms (jitter delay + decode time +
219 // render delay).
220 delay_counter_.Add(target_delay_ms + rtt_ms / 2);
pbos@webrtc.org98c04b32014-12-18 13:12:52 +0000221}
222
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000223void ReceiveStatisticsProxy::RtcpPacketTypesCounterUpdated(
224 uint32_t ssrc,
225 const RtcpPacketTypeCounter& packet_counter) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200226 rtc::CritScope lock(&crit_);
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000227 if (stats_.ssrc != ssrc)
228 return;
229 stats_.rtcp_packet_type_counts = packet_counter;
230}
231
sprang@webrtc.org09315702014-02-07 12:06:29 +0000232void ReceiveStatisticsProxy::StatisticsUpdated(
233 const webrtc::RtcpStatistics& statistics,
234 uint32_t ssrc) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200235 rtc::CritScope lock(&crit_);
henrikg91d6ede2015-09-17 00:24:34 -0700236 // TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000237 // receive stats from one of them.
238 if (stats_.ssrc != ssrc)
239 return;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000240 stats_.rtcp_stats = statistics;
Åsa Persson3c391cb2015-04-27 10:09:49 +0200241 report_block_stats_.Store(statistics, ssrc, 0);
asapersson0c43f772016-11-30 01:42:26 -0800242
243 if (first_report_block_time_ms_ == -1)
244 first_report_block_time_ms_ = clock_->TimeInMilliseconds();
sprang@webrtc.org09315702014-02-07 12:06:29 +0000245}
246
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000247void ReceiveStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200248 rtc::CritScope lock(&crit_);
henrikg91d6ede2015-09-17 00:24:34 -0700249 // TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000250 // receive stats from one of them.
251 if (stats_.ssrc != ssrc)
252 return;
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000253 stats_.c_name = cname;
254}
255
sprang@webrtc.org09315702014-02-07 12:06:29 +0000256void ReceiveStatisticsProxy::DataCountersUpdated(
257 const webrtc::StreamDataCounters& counters,
258 uint32_t ssrc) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200259 rtc::CritScope lock(&crit_);
sprang0ab8e812016-02-24 01:35:40 -0800260 if (ssrc == stats_.ssrc) {
261 stats_.rtp_stats = counters;
262 } else {
263 auto it = rtx_stats_.find(ssrc);
264 if (it != rtx_stats_.end()) {
265 it->second = counters;
266 } else {
267 RTC_NOTREACHED() << "Unexpected stream ssrc: " << ssrc;
268 }
269 }
sprang@webrtc.org09315702014-02-07 12:06:29 +0000270}
271
272void ReceiveStatisticsProxy::OnDecodedFrame() {
273 uint64_t now = clock_->TimeInMilliseconds();
274
Peter Boströmf2f82832015-05-01 13:00:41 +0200275 rtc::CritScope lock(&crit_);
sakale5ba44e2016-10-26 07:09:24 -0700276 ++stats_.frames_decoded;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000277 decode_fps_estimator_.Update(1, now);
Erik Språng51e60302016-06-10 22:13:21 +0200278 stats_.decode_frame_rate = decode_fps_estimator_.Rate(now).value_or(0);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000279}
280
asapersson1490f7a2016-09-23 02:09:46 -0700281void ReceiveStatisticsProxy::OnRenderedFrame(const VideoFrame& frame) {
282 int width = frame.width();
283 int height = frame.height();
asaperssonf839dcc2015-10-08 00:41:59 -0700284 RTC_DCHECK_GT(width, 0);
285 RTC_DCHECK_GT(height, 0);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000286 uint64_t now = clock_->TimeInMilliseconds();
287
Peter Boströmf2f82832015-05-01 13:00:41 +0200288 rtc::CritScope lock(&crit_);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000289 renders_fps_estimator_.Update(1, now);
Erik Språng51e60302016-06-10 22:13:21 +0200290 stats_.render_frame_rate = renders_fps_estimator_.Rate(now).value_or(0);
asapersson2e5cfcd2016-08-11 08:41:18 -0700291 stats_.width = width;
292 stats_.height = height;
asaperssond89920b2015-07-22 06:52:00 -0700293 render_width_counter_.Add(width);
294 render_height_counter_.Add(height);
Tim Psiaki63046262015-09-14 10:38:08 -0700295 render_fps_tracker_.AddSamples(1);
asaperssonf839dcc2015-10-08 00:41:59 -0700296 render_pixel_tracker_.AddSamples(sqrt(width * height));
asapersson1490f7a2016-09-23 02:09:46 -0700297
298 if (frame.ntp_time_ms() > 0) {
299 int64_t delay_ms = clock_->CurrentNtpInMilliseconds() - frame.ntp_time_ms();
300 if (delay_ms >= 0)
301 e2e_delay_counter_.Add(delay_ms);
302 }
sprang@webrtc.org09315702014-02-07 12:06:29 +0000303}
304
asaperssonde9e5ff2016-11-02 07:14:03 -0700305void ReceiveStatisticsProxy::OnSyncOffsetUpdated(int64_t sync_offset_ms,
306 double estimated_freq_khz) {
asaperssonf8cdd182016-03-15 01:00:47 -0700307 rtc::CritScope lock(&crit_);
308 sync_offset_counter_.Add(std::abs(sync_offset_ms));
309 stats_.sync_offset_ms = sync_offset_ms;
asaperssonde9e5ff2016-11-02 07:14:03 -0700310
311 const double kMaxFreqKhz = 10000.0;
312 int offset_khz = kMaxFreqKhz;
313 // Should not be zero or negative. If so, report max.
314 if (estimated_freq_khz < kMaxFreqKhz && estimated_freq_khz > 0.0)
315 offset_khz = static_cast<int>(std::fabs(estimated_freq_khz - 90.0) + 0.5);
316
317 freq_offset_counter_.Add(offset_khz);
asaperssonf8cdd182016-03-15 01:00:47 -0700318}
319
pbos@webrtc.org55707692014-12-19 15:45:03 +0000320void ReceiveStatisticsProxy::OnReceiveRatesUpdated(uint32_t bitRate,
321 uint32_t frameRate) {
322}
323
324void ReceiveStatisticsProxy::OnFrameCountsUpdated(
325 const FrameCounts& frame_counts) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200326 rtc::CritScope lock(&crit_);
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000327 stats_.frame_counts = frame_counts;
328}
329
pbos@webrtc.org55707692014-12-19 15:45:03 +0000330void ReceiveStatisticsProxy::OnDiscardedPacketsUpdated(int discarded_packets) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200331 rtc::CritScope lock(&crit_);
pbos@webrtc.org55707692014-12-19 15:45:03 +0000332 stats_.discarded_packets = discarded_packets;
333}
334
asapersson86b01602015-10-20 23:55:26 -0700335void ReceiveStatisticsProxy::OnPreDecode(
336 const EncodedImage& encoded_image,
337 const CodecSpecificInfo* codec_specific_info) {
Peter Boström74f6e9e2016-04-04 17:56:10 +0200338 if (!codec_specific_info || encoded_image.qp_ == -1) {
asapersson86b01602015-10-20 23:55:26 -0700339 return;
340 }
341 if (codec_specific_info->codecType == kVideoCodecVP8) {
342 qp_counters_.vp8.Add(encoded_image.qp_);
343 }
344}
345
asaperssond89920b2015-07-22 06:52:00 -0700346void ReceiveStatisticsProxy::SampleCounter::Add(int sample) {
347 sum += sample;
348 ++num_samples;
349}
350
351int ReceiveStatisticsProxy::SampleCounter::Avg(int min_required_samples) const {
352 if (num_samples < min_required_samples || num_samples == 0)
353 return -1;
354 return sum / num_samples;
355}
356
sprang@webrtc.org09315702014-02-07 12:06:29 +0000357} // namespace webrtc