blob: ded510a55e77dafee3fa9f217c3311d2224daf32 [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);
80 }
asaperssonf8cdd182016-03-15 01:00:47 -070081
asapersson86b01602015-10-20 23:55:26 -070082 int qp = qp_counters_.vp8.Avg(kMinRequiredSamples);
83 if (qp != -1)
asapersson1d02d3e2016-09-09 22:40:25 -070084 RTC_HISTOGRAM_COUNTS_200("WebRTC.Video.Decoded.Vp8.Qp", qp);
asapersson86b01602015-10-20 23:55:26 -070085
asapersson6718e972015-07-24 00:20:58 -070086 // TODO(asapersson): DecoderTiming() is call periodically (each 1000ms) and
87 // not per frame. Change decode time to include every frame.
88 const int kMinRequiredDecodeSamples = 5;
89 int decode_ms = decode_time_counter_.Avg(kMinRequiredDecodeSamples);
90 if (decode_ms != -1)
asapersson1d02d3e2016-09-09 22:40:25 -070091 RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.DecodeTimeInMs", decode_ms);
asapersson13c433c2015-10-06 04:08:15 -070092
asapersson8688a4e2016-04-27 23:42:35 -070093 int jb_delay_ms = jitter_buffer_delay_counter_.Avg(kMinRequiredDecodeSamples);
94 if (jb_delay_ms != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -070095 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.JitterBufferDelayInMs",
96 jb_delay_ms);
asapersson8688a4e2016-04-27 23:42:35 -070097 }
98 int target_delay_ms = target_delay_counter_.Avg(kMinRequiredDecodeSamples);
99 if (target_delay_ms != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -0700100 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.TargetDelayInMs", target_delay_ms);
asapersson8688a4e2016-04-27 23:42:35 -0700101 }
102 int current_delay_ms = current_delay_counter_.Avg(kMinRequiredDecodeSamples);
103 if (current_delay_ms != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -0700104 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.CurrentDelayInMs",
105 current_delay_ms);
asapersson8688a4e2016-04-27 23:42:35 -0700106 }
asapersson13c433c2015-10-06 04:08:15 -0700107 int delay_ms = delay_counter_.Avg(kMinRequiredDecodeSamples);
108 if (delay_ms != -1)
asapersson1d02d3e2016-09-09 22:40:25 -0700109 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.OnewayDelayInMs", delay_ms);
sprang0ab8e812016-02-24 01:35:40 -0800110
asapersson1490f7a2016-09-23 02:09:46 -0700111 int e2e_delay_ms = e2e_delay_counter_.Avg(kMinRequiredSamples);
112 if (e2e_delay_ms != -1)
113 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.EndToEndDelayInMs", e2e_delay_ms);
114
sprang0ab8e812016-02-24 01:35:40 -0800115 StreamDataCounters rtp = stats_.rtp_stats;
116 StreamDataCounters rtx;
117 for (auto it : rtx_stats_)
118 rtx.Add(it.second);
119 StreamDataCounters rtp_rtx = rtp;
120 rtp_rtx.Add(rtx);
121 int64_t elapsed_sec =
122 rtp_rtx.TimeSinceFirstPacketInMs(clock_->TimeInMilliseconds()) / 1000;
123 if (elapsed_sec > metrics::kMinRunTimeInSeconds) {
asapersson1d02d3e2016-09-09 22:40:25 -0700124 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800125 "WebRTC.Video.BitrateReceivedInKbps",
126 static_cast<int>(rtp_rtx.transmitted.TotalBytes() * 8 / elapsed_sec /
127 1000));
asapersson1d02d3e2016-09-09 22:40:25 -0700128 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800129 "WebRTC.Video.MediaBitrateReceivedInKbps",
130 static_cast<int>(rtp.MediaPayloadBytes() * 8 / elapsed_sec / 1000));
asapersson1d02d3e2016-09-09 22:40:25 -0700131 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800132 "WebRTC.Video.PaddingBitrateReceivedInKbps",
133 static_cast<int>(rtp_rtx.transmitted.padding_bytes * 8 / elapsed_sec /
134 1000));
asapersson1d02d3e2016-09-09 22:40:25 -0700135 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800136 "WebRTC.Video.RetransmittedBitrateReceivedInKbps",
137 static_cast<int>(rtp_rtx.retransmitted.TotalBytes() * 8 / elapsed_sec /
138 1000));
139 if (!rtx_stats_.empty()) {
asapersson1d02d3e2016-09-09 22:40:25 -0700140 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.RtxBitrateReceivedInKbps",
141 static_cast<int>(rtx.transmitted.TotalBytes() *
142 8 / elapsed_sec / 1000));
sprang0ab8e812016-02-24 01:35:40 -0800143 }
brandtrb5f2c3f2016-10-04 23:28:39 -0700144 if (config_.rtp.ulpfec.ulpfec_payload_type != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -0700145 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800146 "WebRTC.Video.FecBitrateReceivedInKbps",
147 static_cast<int>(rtp_rtx.fec.TotalBytes() * 8 / elapsed_sec / 1000));
148 }
sprang07fb9be2016-02-24 07:55:00 -0800149 const RtcpPacketTypeCounter& counters = stats_.rtcp_packet_type_counts;
asapersson1d02d3e2016-09-09 22:40:25 -0700150 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.NackPacketsSentPerMinute",
151 counters.nack_packets * 60 / elapsed_sec);
152 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.FirPacketsSentPerMinute",
153 counters.fir_packets * 60 / elapsed_sec);
154 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.PliPacketsSentPerMinute",
155 counters.pli_packets * 60 / elapsed_sec);
sprang07fb9be2016-02-24 07:55:00 -0800156 if (counters.nack_requests > 0) {
asapersson1d02d3e2016-09-09 22:40:25 -0700157 RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.UniqueNackRequestsSentInPercent",
158 counters.UniqueNackRequestsInPercent());
sprang07fb9be2016-02-24 07:55:00 -0800159 }
sprang0ab8e812016-02-24 01:35:40 -0800160 }
Åsa Persson3c391cb2015-04-27 10:09:49 +0200161}
sprang@webrtc.org09315702014-02-07 12:06:29 +0000162
163VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const {
Peter Boströmf2f82832015-05-01 13:00:41 +0200164 rtc::CritScope lock(&crit_);
pbos@webrtc.org55707692014-12-19 15:45:03 +0000165 return stats_;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000166}
167
pbosf42376c2015-08-28 07:35:32 -0700168void ReceiveStatisticsProxy::OnIncomingPayloadType(int payload_type) {
169 rtc::CritScope lock(&crit_);
170 stats_.current_payload_type = payload_type;
171}
172
Peter Boströmb7d9a972015-12-18 16:01:11 +0100173void ReceiveStatisticsProxy::OnDecoderImplementationName(
174 const char* implementation_name) {
175 rtc::CritScope lock(&crit_);
176 stats_.decoder_implementation_name = implementation_name;
177}
pbosf42376c2015-08-28 07:35:32 -0700178void ReceiveStatisticsProxy::OnIncomingRate(unsigned int framerate,
179 unsigned int bitrate_bps) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200180 rtc::CritScope lock(&crit_);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000181 stats_.network_frame_rate = framerate;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000182 stats_.total_bitrate_bps = bitrate_bps;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000183}
184
pbosf42376c2015-08-28 07:35:32 -0700185void ReceiveStatisticsProxy::OnDecoderTiming(int decode_ms,
186 int max_decode_ms,
187 int current_delay_ms,
188 int target_delay_ms,
189 int jitter_buffer_ms,
190 int min_playout_delay_ms,
asapersson13c433c2015-10-06 04:08:15 -0700191 int render_delay_ms,
192 int64_t rtt_ms) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200193 rtc::CritScope lock(&crit_);
pbos@webrtc.org09c77b92015-02-25 10:42:16 +0000194 stats_.decode_ms = decode_ms;
195 stats_.max_decode_ms = max_decode_ms;
196 stats_.current_delay_ms = current_delay_ms;
197 stats_.target_delay_ms = target_delay_ms;
198 stats_.jitter_buffer_ms = jitter_buffer_ms;
199 stats_.min_playout_delay_ms = min_playout_delay_ms;
200 stats_.render_delay_ms = render_delay_ms;
asapersson6718e972015-07-24 00:20:58 -0700201 decode_time_counter_.Add(decode_ms);
asapersson8688a4e2016-04-27 23:42:35 -0700202 jitter_buffer_delay_counter_.Add(jitter_buffer_ms);
203 target_delay_counter_.Add(target_delay_ms);
204 current_delay_counter_.Add(current_delay_ms);
asaperssona1862882016-04-18 00:41:05 -0700205 // Network delay (rtt/2) + target_delay_ms (jitter delay + decode time +
206 // render delay).
207 delay_counter_.Add(target_delay_ms + rtt_ms / 2);
pbos@webrtc.org98c04b32014-12-18 13:12:52 +0000208}
209
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000210void ReceiveStatisticsProxy::RtcpPacketTypesCounterUpdated(
211 uint32_t ssrc,
212 const RtcpPacketTypeCounter& packet_counter) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200213 rtc::CritScope lock(&crit_);
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000214 if (stats_.ssrc != ssrc)
215 return;
216 stats_.rtcp_packet_type_counts = packet_counter;
217}
218
sprang@webrtc.org09315702014-02-07 12:06:29 +0000219void ReceiveStatisticsProxy::StatisticsUpdated(
220 const webrtc::RtcpStatistics& statistics,
221 uint32_t ssrc) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200222 rtc::CritScope lock(&crit_);
henrikg91d6ede2015-09-17 00:24:34 -0700223 // TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000224 // receive stats from one of them.
225 if (stats_.ssrc != ssrc)
226 return;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000227 stats_.rtcp_stats = statistics;
Åsa Persson3c391cb2015-04-27 10:09:49 +0200228 report_block_stats_.Store(statistics, ssrc, 0);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000229}
230
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000231void ReceiveStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200232 rtc::CritScope lock(&crit_);
henrikg91d6ede2015-09-17 00:24:34 -0700233 // TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000234 // receive stats from one of them.
235 if (stats_.ssrc != ssrc)
236 return;
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000237 stats_.c_name = cname;
238}
239
sprang@webrtc.org09315702014-02-07 12:06:29 +0000240void ReceiveStatisticsProxy::DataCountersUpdated(
241 const webrtc::StreamDataCounters& counters,
242 uint32_t ssrc) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200243 rtc::CritScope lock(&crit_);
sprang0ab8e812016-02-24 01:35:40 -0800244 if (ssrc == stats_.ssrc) {
245 stats_.rtp_stats = counters;
246 } else {
247 auto it = rtx_stats_.find(ssrc);
248 if (it != rtx_stats_.end()) {
249 it->second = counters;
250 } else {
251 RTC_NOTREACHED() << "Unexpected stream ssrc: " << ssrc;
252 }
253 }
sprang@webrtc.org09315702014-02-07 12:06:29 +0000254}
255
256void ReceiveStatisticsProxy::OnDecodedFrame() {
257 uint64_t now = clock_->TimeInMilliseconds();
258
Peter Boströmf2f82832015-05-01 13:00:41 +0200259 rtc::CritScope lock(&crit_);
sakale5ba44e2016-10-26 07:09:24 -0700260 ++stats_.frames_decoded;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000261 decode_fps_estimator_.Update(1, now);
Erik Språng51e60302016-06-10 22:13:21 +0200262 stats_.decode_frame_rate = decode_fps_estimator_.Rate(now).value_or(0);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000263}
264
asapersson1490f7a2016-09-23 02:09:46 -0700265void ReceiveStatisticsProxy::OnRenderedFrame(const VideoFrame& frame) {
266 int width = frame.width();
267 int height = frame.height();
asaperssonf839dcc2015-10-08 00:41:59 -0700268 RTC_DCHECK_GT(width, 0);
269 RTC_DCHECK_GT(height, 0);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000270 uint64_t now = clock_->TimeInMilliseconds();
271
Peter Boströmf2f82832015-05-01 13:00:41 +0200272 rtc::CritScope lock(&crit_);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000273 renders_fps_estimator_.Update(1, now);
Erik Språng51e60302016-06-10 22:13:21 +0200274 stats_.render_frame_rate = renders_fps_estimator_.Rate(now).value_or(0);
asapersson2e5cfcd2016-08-11 08:41:18 -0700275 stats_.width = width;
276 stats_.height = height;
asaperssond89920b2015-07-22 06:52:00 -0700277 render_width_counter_.Add(width);
278 render_height_counter_.Add(height);
Tim Psiaki63046262015-09-14 10:38:08 -0700279 render_fps_tracker_.AddSamples(1);
asaperssonf839dcc2015-10-08 00:41:59 -0700280 render_pixel_tracker_.AddSamples(sqrt(width * height));
asapersson1490f7a2016-09-23 02:09:46 -0700281
282 if (frame.ntp_time_ms() > 0) {
283 int64_t delay_ms = clock_->CurrentNtpInMilliseconds() - frame.ntp_time_ms();
284 if (delay_ms >= 0)
285 e2e_delay_counter_.Add(delay_ms);
286 }
sprang@webrtc.org09315702014-02-07 12:06:29 +0000287}
288
asaperssonde9e5ff2016-11-02 07:14:03 -0700289void ReceiveStatisticsProxy::OnSyncOffsetUpdated(int64_t sync_offset_ms,
290 double estimated_freq_khz) {
asaperssonf8cdd182016-03-15 01:00:47 -0700291 rtc::CritScope lock(&crit_);
292 sync_offset_counter_.Add(std::abs(sync_offset_ms));
293 stats_.sync_offset_ms = sync_offset_ms;
asaperssonde9e5ff2016-11-02 07:14:03 -0700294
295 const double kMaxFreqKhz = 10000.0;
296 int offset_khz = kMaxFreqKhz;
297 // Should not be zero or negative. If so, report max.
298 if (estimated_freq_khz < kMaxFreqKhz && estimated_freq_khz > 0.0)
299 offset_khz = static_cast<int>(std::fabs(estimated_freq_khz - 90.0) + 0.5);
300
301 freq_offset_counter_.Add(offset_khz);
asaperssonf8cdd182016-03-15 01:00:47 -0700302}
303
pbos@webrtc.org55707692014-12-19 15:45:03 +0000304void ReceiveStatisticsProxy::OnReceiveRatesUpdated(uint32_t bitRate,
305 uint32_t frameRate) {
306}
307
308void ReceiveStatisticsProxy::OnFrameCountsUpdated(
309 const FrameCounts& frame_counts) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200310 rtc::CritScope lock(&crit_);
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000311 stats_.frame_counts = frame_counts;
312}
313
pbos@webrtc.org55707692014-12-19 15:45:03 +0000314void ReceiveStatisticsProxy::OnDiscardedPacketsUpdated(int discarded_packets) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200315 rtc::CritScope lock(&crit_);
pbos@webrtc.org55707692014-12-19 15:45:03 +0000316 stats_.discarded_packets = discarded_packets;
317}
318
asapersson86b01602015-10-20 23:55:26 -0700319void ReceiveStatisticsProxy::OnPreDecode(
320 const EncodedImage& encoded_image,
321 const CodecSpecificInfo* codec_specific_info) {
Peter Boström74f6e9e2016-04-04 17:56:10 +0200322 if (!codec_specific_info || encoded_image.qp_ == -1) {
asapersson86b01602015-10-20 23:55:26 -0700323 return;
324 }
325 if (codec_specific_info->codecType == kVideoCodecVP8) {
326 qp_counters_.vp8.Add(encoded_image.qp_);
327 }
328}
329
asaperssond89920b2015-07-22 06:52:00 -0700330void ReceiveStatisticsProxy::SampleCounter::Add(int sample) {
331 sum += sample;
332 ++num_samples;
333}
334
335int ReceiveStatisticsProxy::SampleCounter::Avg(int min_required_samples) const {
336 if (num_samples < min_required_samples || num_samples == 0)
337 return -1;
338 return sum / num_samples;
339}
340
sprang@webrtc.org09315702014-02-07 12:06:29 +0000341} // namespace webrtc