blob: 7d5fbc0a7cd6edc924792434e3befef03adca46c [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),
38 freq_offset_counter_(clock, nullptr, kFreqOffsetProcessIntervalMs) {
Tommi733b5472016-06-10 17:58:01 +020039 stats_.ssrc = config_.rtp.remote_ssrc;
40 for (auto it : config_.rtp.rtx)
sprang0ab8e812016-02-24 01:35:40 -080041 rtx_stats_[it.second.ssrc] = StreamDataCounters();
sprang@webrtc.org09315702014-02-07 12:06:29 +000042}
43
Åsa Persson3c391cb2015-04-27 10:09:49 +020044ReceiveStatisticsProxy::~ReceiveStatisticsProxy() {
45 UpdateHistograms();
46}
47
asaperssond89920b2015-07-22 06:52:00 -070048void ReceiveStatisticsProxy::UpdateHistograms() {
asapersson1d02d3e2016-09-09 22:40:25 -070049 RTC_HISTOGRAM_COUNTS_100000(
asapersson4374a092016-07-27 00:39:09 -070050 "WebRTC.Video.ReceiveStreamLifetimeInSeconds",
51 (clock_->TimeInMilliseconds() - start_ms_) / 1000);
52
asaperssond89920b2015-07-22 06:52:00 -070053 int fraction_lost = report_block_stats_.FractionLostInPercent();
Åsa Persson3c391cb2015-04-27 10:09:49 +020054 if (fraction_lost != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -070055 RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.ReceivedPacketsLostInPercent",
56 fraction_lost);
Åsa Persson3c391cb2015-04-27 10:09:49 +020057 }
asapersson6718e972015-07-24 00:20:58 -070058 const int kMinRequiredSamples = 200;
asaperssonf839dcc2015-10-08 00:41:59 -070059 int samples = static_cast<int>(render_fps_tracker_.TotalSampleCount());
60 if (samples > kMinRequiredSamples) {
asapersson1d02d3e2016-09-09 22:40:25 -070061 RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.RenderFramesPerSecond",
62 round(render_fps_tracker_.ComputeTotalRate()));
63 RTC_HISTOGRAM_COUNTS_100000(
asapersson28ba9272016-01-25 05:58:23 -080064 "WebRTC.Video.RenderSqrtPixelsPerSecond",
Tim Psiakiad13d2f2015-11-10 16:34:50 -080065 round(render_pixel_tracker_.ComputeTotalRate()));
asaperssonf839dcc2015-10-08 00:41:59 -070066 }
asaperssond89920b2015-07-22 06:52:00 -070067 int width = render_width_counter_.Avg(kMinRequiredSamples);
68 int height = render_height_counter_.Avg(kMinRequiredSamples);
69 if (width != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -070070 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.ReceivedWidthInPixels", width);
71 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.ReceivedHeightInPixels", height);
asaperssond89920b2015-07-22 06:52:00 -070072 }
asaperssonf8cdd182016-03-15 01:00:47 -070073 int sync_offset_ms = sync_offset_counter_.Avg(kMinRequiredSamples);
pbos35fdb2a2016-05-03 03:32:10 -070074 if (sync_offset_ms != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -070075 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.AVSyncOffsetInMs", sync_offset_ms);
pbos35fdb2a2016-05-03 03:32:10 -070076 }
asaperssonde9e5ff2016-11-02 07:14:03 -070077 AggregatedStats freq_offset_stats = freq_offset_counter_.GetStats();
78 if (freq_offset_stats.num_samples > 0) {
79 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.RtpToNtpFreqOffsetInKhz",
80 freq_offset_stats.average);
asapersson43cb7162016-11-15 08:20:48 -080081 LOG(LS_INFO) << "WebRTC.Video.RtpToNtpFreqOffsetInKhz, "
82 << freq_offset_stats.ToString();
asaperssonde9e5ff2016-11-02 07:14:03 -070083 }
asaperssonf8cdd182016-03-15 01:00:47 -070084
asapersson86b01602015-10-20 23:55:26 -070085 int qp = qp_counters_.vp8.Avg(kMinRequiredSamples);
86 if (qp != -1)
asapersson1d02d3e2016-09-09 22:40:25 -070087 RTC_HISTOGRAM_COUNTS_200("WebRTC.Video.Decoded.Vp8.Qp", qp);
asapersson86b01602015-10-20 23:55:26 -070088
asapersson6718e972015-07-24 00:20:58 -070089 // TODO(asapersson): DecoderTiming() is call periodically (each 1000ms) and
90 // not per frame. Change decode time to include every frame.
91 const int kMinRequiredDecodeSamples = 5;
92 int decode_ms = decode_time_counter_.Avg(kMinRequiredDecodeSamples);
93 if (decode_ms != -1)
asapersson1d02d3e2016-09-09 22:40:25 -070094 RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.DecodeTimeInMs", decode_ms);
asapersson13c433c2015-10-06 04:08:15 -070095
philipelbe742702016-11-30 01:31:40 -080096 if (field_trial::FindFullName("WebRTC-NewVideoJitterBuffer") !=
97 "Enabled") {
98 int jb_delay_ms =
99 jitter_buffer_delay_counter_.Avg(kMinRequiredDecodeSamples);
100 if (jb_delay_ms != -1) {
101 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.JitterBufferDelayInMs",
102 jb_delay_ms);
103 }
asapersson8688a4e2016-04-27 23:42:35 -0700104 }
105 int target_delay_ms = target_delay_counter_.Avg(kMinRequiredDecodeSamples);
106 if (target_delay_ms != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -0700107 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.TargetDelayInMs", target_delay_ms);
asapersson8688a4e2016-04-27 23:42:35 -0700108 }
109 int current_delay_ms = current_delay_counter_.Avg(kMinRequiredDecodeSamples);
110 if (current_delay_ms != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -0700111 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.CurrentDelayInMs",
112 current_delay_ms);
asapersson8688a4e2016-04-27 23:42:35 -0700113 }
asapersson13c433c2015-10-06 04:08:15 -0700114 int delay_ms = delay_counter_.Avg(kMinRequiredDecodeSamples);
115 if (delay_ms != -1)
asapersson1d02d3e2016-09-09 22:40:25 -0700116 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.OnewayDelayInMs", delay_ms);
sprang0ab8e812016-02-24 01:35:40 -0800117
asapersson1490f7a2016-09-23 02:09:46 -0700118 int e2e_delay_ms = e2e_delay_counter_.Avg(kMinRequiredSamples);
119 if (e2e_delay_ms != -1)
120 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.EndToEndDelayInMs", e2e_delay_ms);
121
sprang0ab8e812016-02-24 01:35:40 -0800122 StreamDataCounters rtp = stats_.rtp_stats;
123 StreamDataCounters rtx;
124 for (auto it : rtx_stats_)
125 rtx.Add(it.second);
126 StreamDataCounters rtp_rtx = rtp;
127 rtp_rtx.Add(rtx);
128 int64_t elapsed_sec =
129 rtp_rtx.TimeSinceFirstPacketInMs(clock_->TimeInMilliseconds()) / 1000;
130 if (elapsed_sec > metrics::kMinRunTimeInSeconds) {
asapersson1d02d3e2016-09-09 22:40:25 -0700131 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800132 "WebRTC.Video.BitrateReceivedInKbps",
133 static_cast<int>(rtp_rtx.transmitted.TotalBytes() * 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.MediaBitrateReceivedInKbps",
137 static_cast<int>(rtp.MediaPayloadBytes() * 8 / elapsed_sec / 1000));
asapersson1d02d3e2016-09-09 22:40:25 -0700138 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800139 "WebRTC.Video.PaddingBitrateReceivedInKbps",
140 static_cast<int>(rtp_rtx.transmitted.padding_bytes * 8 / elapsed_sec /
141 1000));
asapersson1d02d3e2016-09-09 22:40:25 -0700142 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800143 "WebRTC.Video.RetransmittedBitrateReceivedInKbps",
144 static_cast<int>(rtp_rtx.retransmitted.TotalBytes() * 8 / elapsed_sec /
145 1000));
146 if (!rtx_stats_.empty()) {
asapersson1d02d3e2016-09-09 22:40:25 -0700147 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.RtxBitrateReceivedInKbps",
148 static_cast<int>(rtx.transmitted.TotalBytes() *
149 8 / elapsed_sec / 1000));
sprang0ab8e812016-02-24 01:35:40 -0800150 }
brandtrb5f2c3f2016-10-04 23:28:39 -0700151 if (config_.rtp.ulpfec.ulpfec_payload_type != -1) {
asapersson1d02d3e2016-09-09 22:40:25 -0700152 RTC_HISTOGRAM_COUNTS_10000(
sprang0ab8e812016-02-24 01:35:40 -0800153 "WebRTC.Video.FecBitrateReceivedInKbps",
154 static_cast<int>(rtp_rtx.fec.TotalBytes() * 8 / elapsed_sec / 1000));
155 }
sprang07fb9be2016-02-24 07:55:00 -0800156 const RtcpPacketTypeCounter& counters = stats_.rtcp_packet_type_counts;
asapersson1d02d3e2016-09-09 22:40:25 -0700157 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.NackPacketsSentPerMinute",
158 counters.nack_packets * 60 / elapsed_sec);
159 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.FirPacketsSentPerMinute",
160 counters.fir_packets * 60 / elapsed_sec);
161 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.PliPacketsSentPerMinute",
162 counters.pli_packets * 60 / elapsed_sec);
sprang07fb9be2016-02-24 07:55:00 -0800163 if (counters.nack_requests > 0) {
asapersson1d02d3e2016-09-09 22:40:25 -0700164 RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.UniqueNackRequestsSentInPercent",
165 counters.UniqueNackRequestsInPercent());
sprang07fb9be2016-02-24 07:55:00 -0800166 }
sprang0ab8e812016-02-24 01:35:40 -0800167 }
Åsa Persson3c391cb2015-04-27 10:09:49 +0200168}
sprang@webrtc.org09315702014-02-07 12:06:29 +0000169
170VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const {
Peter Boströmf2f82832015-05-01 13:00:41 +0200171 rtc::CritScope lock(&crit_);
pbos@webrtc.org55707692014-12-19 15:45:03 +0000172 return stats_;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000173}
174
pbosf42376c2015-08-28 07:35:32 -0700175void ReceiveStatisticsProxy::OnIncomingPayloadType(int payload_type) {
176 rtc::CritScope lock(&crit_);
177 stats_.current_payload_type = payload_type;
178}
179
Peter Boströmb7d9a972015-12-18 16:01:11 +0100180void ReceiveStatisticsProxy::OnDecoderImplementationName(
181 const char* implementation_name) {
182 rtc::CritScope lock(&crit_);
183 stats_.decoder_implementation_name = implementation_name;
184}
pbosf42376c2015-08-28 07:35:32 -0700185void ReceiveStatisticsProxy::OnIncomingRate(unsigned int framerate,
186 unsigned int bitrate_bps) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200187 rtc::CritScope lock(&crit_);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000188 stats_.network_frame_rate = framerate;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000189 stats_.total_bitrate_bps = bitrate_bps;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000190}
191
pbosf42376c2015-08-28 07:35:32 -0700192void ReceiveStatisticsProxy::OnDecoderTiming(int decode_ms,
193 int max_decode_ms,
194 int current_delay_ms,
195 int target_delay_ms,
196 int jitter_buffer_ms,
197 int min_playout_delay_ms,
asapersson13c433c2015-10-06 04:08:15 -0700198 int render_delay_ms,
199 int64_t rtt_ms) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200200 rtc::CritScope lock(&crit_);
pbos@webrtc.org09c77b92015-02-25 10:42:16 +0000201 stats_.decode_ms = decode_ms;
202 stats_.max_decode_ms = max_decode_ms;
203 stats_.current_delay_ms = current_delay_ms;
204 stats_.target_delay_ms = target_delay_ms;
205 stats_.jitter_buffer_ms = jitter_buffer_ms;
206 stats_.min_playout_delay_ms = min_playout_delay_ms;
207 stats_.render_delay_ms = render_delay_ms;
asapersson6718e972015-07-24 00:20:58 -0700208 decode_time_counter_.Add(decode_ms);
asapersson8688a4e2016-04-27 23:42:35 -0700209 jitter_buffer_delay_counter_.Add(jitter_buffer_ms);
210 target_delay_counter_.Add(target_delay_ms);
211 current_delay_counter_.Add(current_delay_ms);
asaperssona1862882016-04-18 00:41:05 -0700212 // Network delay (rtt/2) + target_delay_ms (jitter delay + decode time +
213 // render delay).
214 delay_counter_.Add(target_delay_ms + rtt_ms / 2);
pbos@webrtc.org98c04b32014-12-18 13:12:52 +0000215}
216
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000217void ReceiveStatisticsProxy::RtcpPacketTypesCounterUpdated(
218 uint32_t ssrc,
219 const RtcpPacketTypeCounter& packet_counter) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200220 rtc::CritScope lock(&crit_);
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000221 if (stats_.ssrc != ssrc)
222 return;
223 stats_.rtcp_packet_type_counts = packet_counter;
224}
225
sprang@webrtc.org09315702014-02-07 12:06:29 +0000226void ReceiveStatisticsProxy::StatisticsUpdated(
227 const webrtc::RtcpStatistics& statistics,
228 uint32_t ssrc) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200229 rtc::CritScope lock(&crit_);
henrikg91d6ede2015-09-17 00:24:34 -0700230 // TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000231 // receive stats from one of them.
232 if (stats_.ssrc != ssrc)
233 return;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000234 stats_.rtcp_stats = statistics;
Åsa Persson3c391cb2015-04-27 10:09:49 +0200235 report_block_stats_.Store(statistics, ssrc, 0);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000236}
237
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000238void ReceiveStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200239 rtc::CritScope lock(&crit_);
henrikg91d6ede2015-09-17 00:24:34 -0700240 // TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000241 // receive stats from one of them.
242 if (stats_.ssrc != ssrc)
243 return;
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000244 stats_.c_name = cname;
245}
246
sprang@webrtc.org09315702014-02-07 12:06:29 +0000247void ReceiveStatisticsProxy::DataCountersUpdated(
248 const webrtc::StreamDataCounters& counters,
249 uint32_t ssrc) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200250 rtc::CritScope lock(&crit_);
sprang0ab8e812016-02-24 01:35:40 -0800251 if (ssrc == stats_.ssrc) {
252 stats_.rtp_stats = counters;
253 } else {
254 auto it = rtx_stats_.find(ssrc);
255 if (it != rtx_stats_.end()) {
256 it->second = counters;
257 } else {
258 RTC_NOTREACHED() << "Unexpected stream ssrc: " << ssrc;
259 }
260 }
sprang@webrtc.org09315702014-02-07 12:06:29 +0000261}
262
263void ReceiveStatisticsProxy::OnDecodedFrame() {
264 uint64_t now = clock_->TimeInMilliseconds();
265
Peter Boströmf2f82832015-05-01 13:00:41 +0200266 rtc::CritScope lock(&crit_);
sakale5ba44e2016-10-26 07:09:24 -0700267 ++stats_.frames_decoded;
sprang@webrtc.org09315702014-02-07 12:06:29 +0000268 decode_fps_estimator_.Update(1, now);
Erik Språng51e60302016-06-10 22:13:21 +0200269 stats_.decode_frame_rate = decode_fps_estimator_.Rate(now).value_or(0);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000270}
271
asapersson1490f7a2016-09-23 02:09:46 -0700272void ReceiveStatisticsProxy::OnRenderedFrame(const VideoFrame& frame) {
273 int width = frame.width();
274 int height = frame.height();
asaperssonf839dcc2015-10-08 00:41:59 -0700275 RTC_DCHECK_GT(width, 0);
276 RTC_DCHECK_GT(height, 0);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000277 uint64_t now = clock_->TimeInMilliseconds();
278
Peter Boströmf2f82832015-05-01 13:00:41 +0200279 rtc::CritScope lock(&crit_);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000280 renders_fps_estimator_.Update(1, now);
Erik Språng51e60302016-06-10 22:13:21 +0200281 stats_.render_frame_rate = renders_fps_estimator_.Rate(now).value_or(0);
asapersson2e5cfcd2016-08-11 08:41:18 -0700282 stats_.width = width;
283 stats_.height = height;
asaperssond89920b2015-07-22 06:52:00 -0700284 render_width_counter_.Add(width);
285 render_height_counter_.Add(height);
Tim Psiaki63046262015-09-14 10:38:08 -0700286 render_fps_tracker_.AddSamples(1);
asaperssonf839dcc2015-10-08 00:41:59 -0700287 render_pixel_tracker_.AddSamples(sqrt(width * height));
asapersson1490f7a2016-09-23 02:09:46 -0700288
289 if (frame.ntp_time_ms() > 0) {
290 int64_t delay_ms = clock_->CurrentNtpInMilliseconds() - frame.ntp_time_ms();
291 if (delay_ms >= 0)
292 e2e_delay_counter_.Add(delay_ms);
293 }
sprang@webrtc.org09315702014-02-07 12:06:29 +0000294}
295
asaperssonde9e5ff2016-11-02 07:14:03 -0700296void ReceiveStatisticsProxy::OnSyncOffsetUpdated(int64_t sync_offset_ms,
297 double estimated_freq_khz) {
asaperssonf8cdd182016-03-15 01:00:47 -0700298 rtc::CritScope lock(&crit_);
299 sync_offset_counter_.Add(std::abs(sync_offset_ms));
300 stats_.sync_offset_ms = sync_offset_ms;
asaperssonde9e5ff2016-11-02 07:14:03 -0700301
302 const double kMaxFreqKhz = 10000.0;
303 int offset_khz = kMaxFreqKhz;
304 // Should not be zero or negative. If so, report max.
305 if (estimated_freq_khz < kMaxFreqKhz && estimated_freq_khz > 0.0)
306 offset_khz = static_cast<int>(std::fabs(estimated_freq_khz - 90.0) + 0.5);
307
308 freq_offset_counter_.Add(offset_khz);
asaperssonf8cdd182016-03-15 01:00:47 -0700309}
310
pbos@webrtc.org55707692014-12-19 15:45:03 +0000311void ReceiveStatisticsProxy::OnReceiveRatesUpdated(uint32_t bitRate,
312 uint32_t frameRate) {
313}
314
315void ReceiveStatisticsProxy::OnFrameCountsUpdated(
316 const FrameCounts& frame_counts) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200317 rtc::CritScope lock(&crit_);
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000318 stats_.frame_counts = frame_counts;
319}
320
pbos@webrtc.org55707692014-12-19 15:45:03 +0000321void ReceiveStatisticsProxy::OnDiscardedPacketsUpdated(int discarded_packets) {
Peter Boströmf2f82832015-05-01 13:00:41 +0200322 rtc::CritScope lock(&crit_);
pbos@webrtc.org55707692014-12-19 15:45:03 +0000323 stats_.discarded_packets = discarded_packets;
324}
325
asapersson86b01602015-10-20 23:55:26 -0700326void ReceiveStatisticsProxy::OnPreDecode(
327 const EncodedImage& encoded_image,
328 const CodecSpecificInfo* codec_specific_info) {
Peter Boström74f6e9e2016-04-04 17:56:10 +0200329 if (!codec_specific_info || encoded_image.qp_ == -1) {
asapersson86b01602015-10-20 23:55:26 -0700330 return;
331 }
332 if (codec_specific_info->codecType == kVideoCodecVP8) {
333 qp_counters_.vp8.Add(encoded_image.qp_);
334 }
335}
336
asaperssond89920b2015-07-22 06:52:00 -0700337void ReceiveStatisticsProxy::SampleCounter::Add(int sample) {
338 sum += sample;
339 ++num_samples;
340}
341
342int ReceiveStatisticsProxy::SampleCounter::Avg(int min_required_samples) const {
343 if (num_samples < min_required_samples || num_samples == 0)
344 return -1;
345 return sum / num_samples;
346}
347
sprang@webrtc.org09315702014-02-07 12:06:29 +0000348} // namespace webrtc