blob: b15ef682a1d587d46634e0a74ceb73fe9a533b67 [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"
Henrik Kjellander98f53512015-10-28 18:17:40 +010018#include "webrtc/system_wrappers/include/metrics.h"
sprang@webrtc.org09315702014-02-07 12:06:29 +000019
20namespace webrtc {
asaperssonde9e5ff2016-11-02 07:14:03 -070021namespace {
22// Periodic time interval for processing samples for |freq_offset_counter_|.
23const int64_t kFreqOffsetProcessIntervalMs = 40000;
24} // namespace
sprang@webrtc.org09315702014-02-07 12:06:29 +000025
sprang0ab8e812016-02-24 01:35:40 -080026ReceiveStatisticsProxy::ReceiveStatisticsProxy(
Tommi733b5472016-06-10 17:58:01 +020027 const VideoReceiveStream::Config* config,
sprang0ab8e812016-02-24 01:35:40 -080028 Clock* clock)
pbos@webrtc.org55707692014-12-19 15:45:03 +000029 : clock_(clock),
Tommi733b5472016-06-10 17:58:01 +020030 config_(*config),
asapersson4374a092016-07-27 00:39:09 -070031 start_ms_(clock->TimeInMilliseconds()),
sprang@webrtc.org09315702014-02-07 12:06:29 +000032 // 1000ms window, scale 1000 for ms to s.
33 decode_fps_estimator_(1000, 1000),
Tim Psiaki63046262015-09-14 10:38:08 -070034 renders_fps_estimator_(1000, 1000),
Honghai Zhang82d78622016-05-06 11:29:15 -070035 render_fps_tracker_(100, 10u),
asaperssonde9e5ff2016-11-02 07:14:03 -070036 render_pixel_tracker_(100, 10u),
37 freq_offset_counter_(clock, nullptr, kFreqOffsetProcessIntervalMs) {
Tommi733b5472016-06-10 17:58:01 +020038 stats_.ssrc = config_.rtp.remote_ssrc;
39 for (auto it : config_.rtp.rtx)
sprang0ab8e812016-02-24 01:35:40 -080040 rtx_stats_[it.second.ssrc] = StreamDataCounters();
sprang@webrtc.org09315702014-02-07 12:06:29 +000041}
42
Åsa Persson3c391cb2015-04-27 10:09:49 +020043ReceiveStatisticsProxy::~ReceiveStatisticsProxy() {
44 UpdateHistograms();
45}
46
asaperssond89920b2015-07-22 06:52:00 -070047void ReceiveStatisticsProxy::UpdateHistograms() {
asapersson1d02d3e2016-09-09 22:40:25 -070048 RTC_HISTOGRAM_COUNTS_100000(
asapersson4374a092016-07-27 00:39:09 -070049 "WebRTC.Video.ReceiveStreamLifetimeInSeconds",
50 (clock_->TimeInMilliseconds() - start_ms_) / 1000);
51
asaperssond89920b2015-07-22 06:52:00 -070052 int fraction_lost = report_block_stats_.FractionLostInPercent();
Åsa Persson3c391cb2015-04-27 10:09:49 +020053 if (fraction_lost != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -070054 RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.ReceivedPacketsLostInPercent",
55 fraction_lost);
Åsa Persson3c391cb2015-04-27 10:09:49 +020056 }
asapersson6718e972015-07-24 00:20:58 -070057 const int kMinRequiredSamples = 200;
asaperssonf839dcc2015-10-08 00:41:59 -070058 int samples = static_cast<int>(render_fps_tracker_.TotalSampleCount());
59 if (samples > kMinRequiredSamples) {
asapersson1d02d3e2016-09-09 22:40:25 -070060 RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.RenderFramesPerSecond",
61 round(render_fps_tracker_.ComputeTotalRate()));
62 RTC_HISTOGRAM_COUNTS_100000(
asapersson28ba9272016-01-25 05:58:23 -080063 "WebRTC.Video.RenderSqrtPixelsPerSecond",
Tim Psiakiad13d2f2015-11-10 16:34:50 -080064 round(render_pixel_tracker_.ComputeTotalRate()));
asaperssonf839dcc2015-10-08 00:41:59 -070065 }
asaperssond89920b2015-07-22 06:52:00 -070066 int width = render_width_counter_.Avg(kMinRequiredSamples);
67 int height = render_height_counter_.Avg(kMinRequiredSamples);
68 if (width != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -070069 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.ReceivedWidthInPixels", width);
70 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.ReceivedHeightInPixels", height);
asaperssond89920b2015-07-22 06:52:00 -070071 }
asaperssonf8cdd182016-03-15 01:00:47 -070072 int sync_offset_ms = sync_offset_counter_.Avg(kMinRequiredSamples);
pbos35fdb2a2016-05-03 03:32:10 -070073 if (sync_offset_ms != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -070074 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.AVSyncOffsetInMs", sync_offset_ms);
pbos35fdb2a2016-05-03 03:32:10 -070075 }
asaperssonde9e5ff2016-11-02 07:14:03 -070076 AggregatedStats freq_offset_stats = freq_offset_counter_.GetStats();
77 if (freq_offset_stats.num_samples > 0) {
78 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.RtpToNtpFreqOffsetInKhz",
79 freq_offset_stats.average);
asapersson43cb7162016-11-15 08:20:48 -080080 LOG(LS_INFO) << "WebRTC.Video.RtpToNtpFreqOffsetInKhz, "
81 << freq_offset_stats.ToString();
asaperssonde9e5ff2016-11-02 07:14:03 -070082 }
asaperssonf8cdd182016-03-15 01:00:47 -070083
asapersson86b01602015-10-20 23:55:26 -070084 int qp = qp_counters_.vp8.Avg(kMinRequiredSamples);
85 if (qp != -1)
asapersson1d02d3e2016-09-09 22:40:25 -070086 RTC_HISTOGRAM_COUNTS_200("WebRTC.Video.Decoded.Vp8.Qp", qp);
asapersson86b01602015-10-20 23:55:26 -070087
asapersson6718e972015-07-24 00:20:58 -070088 // TODO(asapersson): DecoderTiming() is call periodically (each 1000ms) and
89 // not per frame. Change decode time to include every frame.
90 const int kMinRequiredDecodeSamples = 5;
91 int decode_ms = decode_time_counter_.Avg(kMinRequiredDecodeSamples);
92 if (decode_ms != -1)
asapersson1d02d3e2016-09-09 22:40:25 -070093 RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.DecodeTimeInMs", decode_ms);
asapersson13c433c2015-10-06 04:08:15 -070094
asapersson8688a4e2016-04-27 23:42:35 -070095 int jb_delay_ms = jitter_buffer_delay_counter_.Avg(kMinRequiredDecodeSamples);
96 if (jb_delay_ms != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -070097 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.JitterBufferDelayInMs",
98 jb_delay_ms);
asapersson8688a4e2016-04-27 23:42:35 -070099 }
100 int target_delay_ms = target_delay_counter_.Avg(kMinRequiredDecodeSamples);
101 if (target_delay_ms != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -0700102 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.TargetDelayInMs", target_delay_ms);
asapersson8688a4e2016-04-27 23:42:35 -0700103 }
104 int current_delay_ms = current_delay_counter_.Avg(kMinRequiredDecodeSamples);
105 if (current_delay_ms != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -0700106 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.CurrentDelayInMs",
107 current_delay_ms);
asapersson8688a4e2016-04-27 23:42:35 -0700108 }
asapersson13c433c2015-10-06 04:08:15 -0700109 int delay_ms = delay_counter_.Avg(kMinRequiredDecodeSamples);
110 if (delay_ms != -1)
asapersson1d02d3e2016-09-09 22:40:25 -0700111 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.OnewayDelayInMs", delay_ms);
sprang0ab8e812016-02-24 01:35:40 -0800112
asapersson1490f7a2016-09-23 02:09:46 -0700113 int e2e_delay_ms = e2e_delay_counter_.Avg(kMinRequiredSamples);
114 if (e2e_delay_ms != -1)
115 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.EndToEndDelayInMs", e2e_delay_ms);
116
sprang0ab8e812016-02-24 01:35:40 -0800117 StreamDataCounters rtp = stats_.rtp_stats;
118 StreamDataCounters rtx;
119 for (auto it : rtx_stats_)
120 rtx.Add(it.second);
121 StreamDataCounters rtp_rtx = rtp;
122 rtp_rtx.Add(rtx);
123 int64_t elapsed_sec =
124 rtp_rtx.TimeSinceFirstPacketInMs(clock_->TimeInMilliseconds()) / 1000;
125 if (elapsed_sec > metrics::kMinRunTimeInSeconds) {
asapersson1d02d3e2016-09-09 22:40:25 -0700126 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800127 "WebRTC.Video.BitrateReceivedInKbps",
128 static_cast<int>(rtp_rtx.transmitted.TotalBytes() * 8 / elapsed_sec /
129 1000));
asapersson1d02d3e2016-09-09 22:40:25 -0700130 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800131 "WebRTC.Video.MediaBitrateReceivedInKbps",
132 static_cast<int>(rtp.MediaPayloadBytes() * 8 / elapsed_sec / 1000));
asapersson1d02d3e2016-09-09 22:40:25 -0700133 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800134 "WebRTC.Video.PaddingBitrateReceivedInKbps",
135 static_cast<int>(rtp_rtx.transmitted.padding_bytes * 8 / elapsed_sec /
136 1000));
asapersson1d02d3e2016-09-09 22:40:25 -0700137 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800138 "WebRTC.Video.RetransmittedBitrateReceivedInKbps",
139 static_cast<int>(rtp_rtx.retransmitted.TotalBytes() * 8 / elapsed_sec /
140 1000));
141 if (!rtx_stats_.empty()) {
asapersson1d02d3e2016-09-09 22:40:25 -0700142 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.RtxBitrateReceivedInKbps",
143 static_cast<int>(rtx.transmitted.TotalBytes() *
144 8 / elapsed_sec / 1000));
sprang0ab8e812016-02-24 01:35:40 -0800145 }
brandtrb5f2c3f2016-10-04 23:28:39 -0700146 if (config_.rtp.ulpfec.ulpfec_payload_type != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -0700147 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800148 "WebRTC.Video.FecBitrateReceivedInKbps",
149 static_cast<int>(rtp_rtx.fec.TotalBytes() * 8 / elapsed_sec / 1000));
150 }
sprang07fb9be2016-02-24 07:55:00 -0800151 const RtcpPacketTypeCounter& counters = stats_.rtcp_packet_type_counts;
asapersson1d02d3e2016-09-09 22:40:25 -0700152 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.NackPacketsSentPerMinute",
153 counters.nack_packets * 60 / elapsed_sec);
154 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.FirPacketsSentPerMinute",
155 counters.fir_packets * 60 / elapsed_sec);
156 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.PliPacketsSentPerMinute",
157 counters.pli_packets * 60 / elapsed_sec);
sprang07fb9be2016-02-24 07:55:00 -0800158 if (counters.nack_requests > 0) {
asapersson1d02d3e2016-09-09 22:40:25 -0700159 RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.UniqueNackRequestsSentInPercent",
160 counters.UniqueNackRequestsInPercent());
sprang07fb9be2016-02-24 07:55:00 -0800161 }
sprang0ab8e812016-02-24 01:35:40 -0800162 }
Åsa Persson3c391cb2015-04-27 10:09:49 +0200163}
sprang@webrtc.org09315702014-02-07 12:06:29 +0000164
165VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const {
Peter Boströmf2f82832015-05-01 13:00:41 +0200166 rtc::CritScope lock(&crit_);
pbos@webrtc.org55707692014-12-19 15:45:03 +0000167 return stats_;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000168}
169
pbosf42376c2015-08-28 07:35:32 -0700170void ReceiveStatisticsProxy::OnIncomingPayloadType(int payload_type) {
171 rtc::CritScope lock(&crit_);
172 stats_.current_payload_type = payload_type;
173}
174
Peter Boströmb7d9a972015-12-18 16:01:11 +0100175void ReceiveStatisticsProxy::OnDecoderImplementationName(
176 const char* implementation_name) {
177 rtc::CritScope lock(&crit_);
178 stats_.decoder_implementation_name = implementation_name;
179}
pbosf42376c2015-08-28 07:35:32 -0700180void ReceiveStatisticsProxy::OnIncomingRate(unsigned int framerate,
181 unsigned int bitrate_bps) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200182 rtc::CritScope lock(&crit_);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000183 stats_.network_frame_rate = framerate;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000184 stats_.total_bitrate_bps = bitrate_bps;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000185}
186
pbosf42376c2015-08-28 07:35:32 -0700187void ReceiveStatisticsProxy::OnDecoderTiming(int decode_ms,
188 int max_decode_ms,
189 int current_delay_ms,
190 int target_delay_ms,
191 int jitter_buffer_ms,
192 int min_playout_delay_ms,
asapersson13c433c2015-10-06 04:08:15 -0700193 int render_delay_ms,
194 int64_t rtt_ms) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200195 rtc::CritScope lock(&crit_);
pbos@webrtc.org09c77b92015-02-25 10:42:16 +0000196 stats_.decode_ms = decode_ms;
197 stats_.max_decode_ms = max_decode_ms;
198 stats_.current_delay_ms = current_delay_ms;
199 stats_.target_delay_ms = target_delay_ms;
200 stats_.jitter_buffer_ms = jitter_buffer_ms;
201 stats_.min_playout_delay_ms = min_playout_delay_ms;
202 stats_.render_delay_ms = render_delay_ms;
asapersson6718e972015-07-24 00:20:58 -0700203 decode_time_counter_.Add(decode_ms);
asapersson8688a4e2016-04-27 23:42:35 -0700204 jitter_buffer_delay_counter_.Add(jitter_buffer_ms);
205 target_delay_counter_.Add(target_delay_ms);
206 current_delay_counter_.Add(current_delay_ms);
asaperssona1862882016-04-18 00:41:05 -0700207 // Network delay (rtt/2) + target_delay_ms (jitter delay + decode time +
208 // render delay).
209 delay_counter_.Add(target_delay_ms + rtt_ms / 2);
pbos@webrtc.org98c04b32014-12-18 13:12:52 +0000210}
211
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000212void ReceiveStatisticsProxy::RtcpPacketTypesCounterUpdated(
213 uint32_t ssrc,
214 const RtcpPacketTypeCounter& packet_counter) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200215 rtc::CritScope lock(&crit_);
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000216 if (stats_.ssrc != ssrc)
217 return;
218 stats_.rtcp_packet_type_counts = packet_counter;
219}
220
sprang@webrtc.org09315702014-02-07 12:06:29 +0000221void ReceiveStatisticsProxy::StatisticsUpdated(
222 const webrtc::RtcpStatistics& statistics,
223 uint32_t ssrc) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200224 rtc::CritScope lock(&crit_);
henrikg91d6ede2015-09-17 00:24:34 -0700225 // TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000226 // receive stats from one of them.
227 if (stats_.ssrc != ssrc)
228 return;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000229 stats_.rtcp_stats = statistics;
Åsa Persson3c391cb2015-04-27 10:09:49 +0200230 report_block_stats_.Store(statistics, ssrc, 0);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000231}
232
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000233void ReceiveStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200234 rtc::CritScope lock(&crit_);
henrikg91d6ede2015-09-17 00:24:34 -0700235 // TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000236 // receive stats from one of them.
237 if (stats_.ssrc != ssrc)
238 return;
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000239 stats_.c_name = cname;
240}
241
sprang@webrtc.org09315702014-02-07 12:06:29 +0000242void ReceiveStatisticsProxy::DataCountersUpdated(
243 const webrtc::StreamDataCounters& counters,
244 uint32_t ssrc) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200245 rtc::CritScope lock(&crit_);
sprang0ab8e812016-02-24 01:35:40 -0800246 if (ssrc == stats_.ssrc) {
247 stats_.rtp_stats = counters;
248 } else {
249 auto it = rtx_stats_.find(ssrc);
250 if (it != rtx_stats_.end()) {
251 it->second = counters;
252 } else {
253 RTC_NOTREACHED() << "Unexpected stream ssrc: " << ssrc;
254 }
255 }
sprang@webrtc.org09315702014-02-07 12:06:29 +0000256}
257
258void ReceiveStatisticsProxy::OnDecodedFrame() {
259 uint64_t now = clock_->TimeInMilliseconds();
260
Peter Boströmf2f82832015-05-01 13:00:41 +0200261 rtc::CritScope lock(&crit_);
sakale5ba44e2016-10-26 07:09:24 -0700262 ++stats_.frames_decoded;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000263 decode_fps_estimator_.Update(1, now);
Erik Språng51e60302016-06-10 22:13:21 +0200264 stats_.decode_frame_rate = decode_fps_estimator_.Rate(now).value_or(0);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000265}
266
asapersson1490f7a2016-09-23 02:09:46 -0700267void ReceiveStatisticsProxy::OnRenderedFrame(const VideoFrame& frame) {
268 int width = frame.width();
269 int height = frame.height();
asaperssonf839dcc2015-10-08 00:41:59 -0700270 RTC_DCHECK_GT(width, 0);
271 RTC_DCHECK_GT(height, 0);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000272 uint64_t now = clock_->TimeInMilliseconds();
273
Peter Boströmf2f82832015-05-01 13:00:41 +0200274 rtc::CritScope lock(&crit_);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000275 renders_fps_estimator_.Update(1, now);
Erik Språng51e60302016-06-10 22:13:21 +0200276 stats_.render_frame_rate = renders_fps_estimator_.Rate(now).value_or(0);
asapersson2e5cfcd2016-08-11 08:41:18 -0700277 stats_.width = width;
278 stats_.height = height;
asaperssond89920b2015-07-22 06:52:00 -0700279 render_width_counter_.Add(width);
280 render_height_counter_.Add(height);
Tim Psiaki63046262015-09-14 10:38:08 -0700281 render_fps_tracker_.AddSamples(1);
asaperssonf839dcc2015-10-08 00:41:59 -0700282 render_pixel_tracker_.AddSamples(sqrt(width * height));
asapersson1490f7a2016-09-23 02:09:46 -0700283
284 if (frame.ntp_time_ms() > 0) {
285 int64_t delay_ms = clock_->CurrentNtpInMilliseconds() - frame.ntp_time_ms();
286 if (delay_ms >= 0)
287 e2e_delay_counter_.Add(delay_ms);
288 }
sprang@webrtc.org09315702014-02-07 12:06:29 +0000289}
290
asaperssonde9e5ff2016-11-02 07:14:03 -0700291void ReceiveStatisticsProxy::OnSyncOffsetUpdated(int64_t sync_offset_ms,
292 double estimated_freq_khz) {
asaperssonf8cdd182016-03-15 01:00:47 -0700293 rtc::CritScope lock(&crit_);
294 sync_offset_counter_.Add(std::abs(sync_offset_ms));
295 stats_.sync_offset_ms = sync_offset_ms;
asaperssonde9e5ff2016-11-02 07:14:03 -0700296
297 const double kMaxFreqKhz = 10000.0;
298 int offset_khz = kMaxFreqKhz;
299 // Should not be zero or negative. If so, report max.
300 if (estimated_freq_khz < kMaxFreqKhz && estimated_freq_khz > 0.0)
301 offset_khz = static_cast<int>(std::fabs(estimated_freq_khz - 90.0) + 0.5);
302
303 freq_offset_counter_.Add(offset_khz);
asaperssonf8cdd182016-03-15 01:00:47 -0700304}
305
pbos@webrtc.org55707692014-12-19 15:45:03 +0000306void ReceiveStatisticsProxy::OnReceiveRatesUpdated(uint32_t bitRate,
307 uint32_t frameRate) {
308}
309
310void ReceiveStatisticsProxy::OnFrameCountsUpdated(
311 const FrameCounts& frame_counts) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200312 rtc::CritScope lock(&crit_);
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000313 stats_.frame_counts = frame_counts;
314}
315
pbos@webrtc.org55707692014-12-19 15:45:03 +0000316void ReceiveStatisticsProxy::OnDiscardedPacketsUpdated(int discarded_packets) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200317 rtc::CritScope lock(&crit_);
pbos@webrtc.org55707692014-12-19 15:45:03 +0000318 stats_.discarded_packets = discarded_packets;
319}
320
asapersson86b01602015-10-20 23:55:26 -0700321void ReceiveStatisticsProxy::OnPreDecode(
322 const EncodedImage& encoded_image,
323 const CodecSpecificInfo* codec_specific_info) {
Peter Boström74f6e9e2016-04-04 17:56:10 +0200324 if (!codec_specific_info || encoded_image.qp_ == -1) {
asapersson86b01602015-10-20 23:55:26 -0700325 return;
326 }
327 if (codec_specific_info->codecType == kVideoCodecVP8) {
328 qp_counters_.vp8.Add(encoded_image.qp_);
329 }
330}
331
asaperssond89920b2015-07-22 06:52:00 -0700332void ReceiveStatisticsProxy::SampleCounter::Add(int sample) {
333 sum += sample;
334 ++num_samples;
335}
336
337int ReceiveStatisticsProxy::SampleCounter::Avg(int min_required_samples) const {
338 if (num_samples < min_required_samples || num_samples == 0)
339 return -1;
340 return sum / num_samples;
341}
342
sprang@webrtc.org09315702014-02-07 12:06:29 +0000343} // namespace webrtc