Move SampleCounter from ReceiveStatisticsProxy to rtc_base/numerics

This class will be used in upcoming VideoQualiyObserver.

Bug: none
Change-Id: I7d79a6caf3040a3f707ed8700842dea1de81e0a6
Reviewed-on: https://webrtc-review.googlesource.com/77724
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23343}
This commit is contained in:
Ilya Nikolaevskiy
2018-05-22 10:54:30 +02:00
committed by Commit Bot
parent 6dc82e8f8b
commit 0beed5d69f
6 changed files with 261 additions and 119 deletions

View File

@ -417,6 +417,8 @@ rtc_source_set("rtc_base_approved_generic") {
"numerics/histogram_percentile_counter.h", "numerics/histogram_percentile_counter.h",
"numerics/mod_ops.h", "numerics/mod_ops.h",
"numerics/moving_max_counter.h", "numerics/moving_max_counter.h",
"numerics/sample_counter.cc",
"numerics/sample_counter.h",
"onetimeevent.h", "onetimeevent.h",
"pathutils.cc", "pathutils.cc",
"pathutils.h", "pathutils.h",
@ -1140,6 +1142,7 @@ if (rtc_include_tests) {
"numerics/moving_max_counter_unittest.cc", "numerics/moving_max_counter_unittest.cc",
"numerics/safe_compare_unittest.cc", "numerics/safe_compare_unittest.cc",
"numerics/safe_minmax_unittest.cc", "numerics/safe_minmax_unittest.cc",
"numerics/sample_counter_unittest.cc",
"onetimeevent_unittest.cc", "onetimeevent_unittest.cc",
"pathutils_unittest.cc", "pathutils_unittest.cc",
"platform_file_unittest.cc", "platform_file_unittest.cc",

View File

@ -0,0 +1,82 @@
/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <limits>
#include "rtc_base/checks.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/numerics/sample_counter.h"
namespace rtc {
SampleCounter::SampleCounter() = default;
SampleCounter::~SampleCounter() = default;
void SampleCounter::Add(int sample) {
if (sum_ > 0) {
RTC_DCHECK_LE(sample, std::numeric_limits<int64_t>::max() - sum_);
} else {
RTC_DCHECK_GE(sample, std::numeric_limits<int64_t>::min() - sum_);
}
sum_ += sample;
// Prevent overflow in squaring.
RTC_DCHECK_GT(sample, std::numeric_limits<int32_t>::min());
RTC_DCHECK_LE(int64_t{sample} * sample,
std::numeric_limits<int64_t>::max() - sum_squared_);
sum_squared_ += int64_t{sample} * sample;
++num_samples_;
if (!max_ || sample > *max_) {
max_ = sample;
}
}
void SampleCounter::Add(const SampleCounter& other) {
if (sum_ > 0) {
RTC_DCHECK_LE(other.sum_, std::numeric_limits<int64_t>::max() - sum_);
} else {
RTC_DCHECK_GE(other.sum_, std::numeric_limits<int64_t>::min() - sum_);
}
sum_ += other.sum_;
RTC_DCHECK_LE(other.sum_squared_,
std::numeric_limits<int64_t>::max() - sum_squared_);
sum_squared_ += other.sum_squared_;
RTC_DCHECK_LE(other.num_samples_,
std::numeric_limits<int64_t>::max() - num_samples_);
num_samples_ += other.num_samples_;
if (other.max_ && (!max_ || *max_ < *other.max_))
max_ = other.max_;
}
rtc::Optional<int> SampleCounter::Avg(int64_t min_required_samples) const {
RTC_DCHECK_GT(min_required_samples, 0);
if (num_samples_ < min_required_samples)
return rtc::nullopt;
return rtc::dchecked_cast<int>(sum_ / num_samples_);
}
rtc::Optional<int64_t> SampleCounter::Variance(
int64_t min_required_samples) const {
RTC_DCHECK_GT(min_required_samples, 0);
if (num_samples_ < min_required_samples)
return rtc::nullopt;
// E[(x-mean)^2] = E[x^2] - mean^2
int64_t mean = sum_ / num_samples_;
return sum_squared_ / num_samples_ - mean * mean;
}
rtc::Optional<int> SampleCounter::Max() const {
return max_;
}
void SampleCounter::Reset() {
*this = {};
}
} // namespace rtc

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_NUMERICS_SAMPLE_COUNTER_H_
#define RTC_BASE_NUMERICS_SAMPLE_COUNTER_H_
#include "api/optional.h"
namespace rtc {
// Simple utility class for counting basic statistics (max./avg./variance) on
// stream of samples.
class SampleCounter {
public:
SampleCounter();
~SampleCounter();
void Add(int sample);
rtc::Optional<int> Avg(int64_t min_required_samples) const;
rtc::Optional<int64_t> Variance(int64_t min_required_samples) const;
rtc::Optional<int> Max() const;
void Reset();
// Adds all the samples from the |other| SampleCounter as if they were all
// individually added using |Add(int)| method.
void Add(const SampleCounter& other);
private:
int64_t sum_ = 0;
int64_t sum_squared_ = 0;
int64_t num_samples_ = 0;
rtc::Optional<int> max_;
};
} // namespace rtc
#endif // RTC_BASE_NUMERICS_SAMPLE_COUNTER_H_

View File

@ -0,0 +1,53 @@
/*
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "rtc_base/numerics/sample_counter.h"
#include <utility>
#include <vector>
#include "test/gmock.h"
#include "test/gtest.h"
using testing::Eq;
namespace rtc {
TEST(SampleCounterTest, ProcessesNoSamples) {
constexpr int kMinSamples = 1;
SampleCounter counter;
EXPECT_THAT(counter.Avg(kMinSamples), Eq(rtc::nullopt));
EXPECT_THAT(counter.Avg(kMinSamples), Eq(rtc::nullopt));
EXPECT_THAT(counter.Max(), Eq(rtc::nullopt));
}
TEST(SampleCounterTest, NotEnoughSamples) {
constexpr int kMinSamples = 6;
SampleCounter counter;
for (int value : {1, 2, 3, 4, 5}) {
counter.Add(value);
}
EXPECT_THAT(counter.Avg(kMinSamples), Eq(rtc::nullopt));
EXPECT_THAT(counter.Avg(kMinSamples), Eq(rtc::nullopt));
EXPECT_THAT(counter.Max(), Eq(5));
}
TEST(SampleCounterTest, EnoughSamples) {
constexpr int kMinSamples = 5;
SampleCounter counter;
for (int value : {1, 2, 3, 4, 5}) {
counter.Add(value);
}
EXPECT_THAT(counter.Avg(kMinSamples), Eq(3));
EXPECT_THAT(counter.Variance(kMinSamples), Eq(2));
EXPECT_THAT(counter.Max(), Eq(5));
}
} // namespace rtc

View File

@ -190,10 +190,12 @@ void ReceiveStatisticsProxy::UpdateHistograms() {
round(render_pixel_tracker_.ComputeTotalRate())); round(render_pixel_tracker_.ComputeTotalRate()));
} }
int sync_offset_ms = sync_offset_counter_.Avg(kMinRequiredSamples); rtc::Optional<int> sync_offset_ms =
if (sync_offset_ms != -1) { sync_offset_counter_.Avg(kMinRequiredSamples);
RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.AVSyncOffsetInMs", sync_offset_ms); if (sync_offset_ms) {
log_stream << "WebRTC.Video.AVSyncOffsetInMs " << sync_offset_ms << '\n'; RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.AVSyncOffsetInMs",
*sync_offset_ms);
log_stream << "WebRTC.Video.AVSyncOffsetInMs " << *sync_offset_ms << '\n';
} }
AggregatedStats freq_offset_stats = freq_offset_counter_.GetStats(); AggregatedStats freq_offset_stats = freq_offset_counter_.GetStats();
if (freq_offset_stats.num_samples > 0) { if (freq_offset_stats.num_samples > 0) {
@ -215,37 +217,41 @@ void ReceiveStatisticsProxy::UpdateHistograms() {
<< key_frames_permille << '\n'; << key_frames_permille << '\n';
} }
int qp = qp_counters_.vp8.Avg(kMinRequiredSamples); rtc::Optional<int> qp = qp_counters_.vp8.Avg(kMinRequiredSamples);
if (qp != -1) { if (qp) {
RTC_HISTOGRAM_COUNTS_200("WebRTC.Video.Decoded.Vp8.Qp", qp); RTC_HISTOGRAM_COUNTS_200("WebRTC.Video.Decoded.Vp8.Qp", *qp);
log_stream << "WebRTC.Video.Decoded.Vp8.Qp " << qp << '\n'; log_stream << "WebRTC.Video.Decoded.Vp8.Qp " << *qp << '\n';
} }
int decode_ms = decode_time_counter_.Avg(kMinRequiredSamples); rtc::Optional<int> decode_ms = decode_time_counter_.Avg(kMinRequiredSamples);
if (decode_ms != -1) { if (decode_ms) {
RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.DecodeTimeInMs", decode_ms); RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.DecodeTimeInMs", *decode_ms);
log_stream << "WebRTC.Video.DecodeTimeInMs " << decode_ms << '\n'; log_stream << "WebRTC.Video.DecodeTimeInMs " << *decode_ms << '\n';
} }
int jb_delay_ms = jitter_buffer_delay_counter_.Avg(kMinRequiredSamples); rtc::Optional<int> jb_delay_ms =
if (jb_delay_ms != -1) { jitter_buffer_delay_counter_.Avg(kMinRequiredSamples);
if (jb_delay_ms) {
RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.JitterBufferDelayInMs", RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.JitterBufferDelayInMs",
jb_delay_ms); *jb_delay_ms);
log_stream << "WebRTC.Video.JitterBufferDelayInMs " << jb_delay_ms << '\n'; log_stream << "WebRTC.Video.JitterBufferDelayInMs " << *jb_delay_ms << '\n';
} }
int target_delay_ms = target_delay_counter_.Avg(kMinRequiredSamples); rtc::Optional<int> target_delay_ms =
if (target_delay_ms != -1) { target_delay_counter_.Avg(kMinRequiredSamples);
RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.TargetDelayInMs", target_delay_ms); if (target_delay_ms) {
log_stream << "WebRTC.Video.TargetDelayInMs " << target_delay_ms << '\n'; RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.TargetDelayInMs",
*target_delay_ms);
log_stream << "WebRTC.Video.TargetDelayInMs " << *target_delay_ms << '\n';
} }
int current_delay_ms = current_delay_counter_.Avg(kMinRequiredSamples); rtc::Optional<int> current_delay_ms =
if (current_delay_ms != -1) { current_delay_counter_.Avg(kMinRequiredSamples);
if (current_delay_ms) {
RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.CurrentDelayInMs", RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.CurrentDelayInMs",
current_delay_ms); *current_delay_ms);
log_stream << "WebRTC.Video.CurrentDelayInMs " << current_delay_ms << '\n'; log_stream << "WebRTC.Video.CurrentDelayInMs " << *current_delay_ms << '\n';
} }
int delay_ms = delay_counter_.Avg(kMinRequiredSamples); rtc::Optional<int> delay_ms = delay_counter_.Avg(kMinRequiredSamples);
if (delay_ms != -1) if (delay_ms)
RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.OnewayDelayInMs", delay_ms); RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.OnewayDelayInMs", *delay_ms);
// Aggregate content_specific_stats_ by removing experiment or simulcast // Aggregate content_specific_stats_ by removing experiment or simulcast
// information; // information;
@ -289,36 +295,38 @@ void ReceiveStatisticsProxy::UpdateHistograms() {
RTC_DCHECK(videocontenttypehelpers::GetExperimentId(content_type) == 0 || RTC_DCHECK(videocontenttypehelpers::GetExperimentId(content_type) == 0 ||
videocontenttypehelpers::GetSimulcastId(content_type) == 0); videocontenttypehelpers::GetSimulcastId(content_type) == 0);
int e2e_delay_ms = stats.e2e_delay_counter.Avg(kMinRequiredSamples); rtc::Optional<int> e2e_delay_ms =
if (e2e_delay_ms != -1) { stats.e2e_delay_counter.Avg(kMinRequiredSamples);
if (e2e_delay_ms) {
RTC_HISTOGRAM_COUNTS_SPARSE_10000( RTC_HISTOGRAM_COUNTS_SPARSE_10000(
uma_prefix + ".EndToEndDelayInMs" + uma_suffix, e2e_delay_ms); uma_prefix + ".EndToEndDelayInMs" + uma_suffix, *e2e_delay_ms);
log_stream << uma_prefix << ".EndToEndDelayInMs" << uma_suffix << " " log_stream << uma_prefix << ".EndToEndDelayInMs" << uma_suffix << " "
<< e2e_delay_ms << '\n'; << *e2e_delay_ms << '\n';
} }
int e2e_delay_max_ms = stats.e2e_delay_counter.Max(); rtc::Optional<int> e2e_delay_max_ms = stats.e2e_delay_counter.Max();
if (e2e_delay_max_ms != -1 && e2e_delay_ms != -1) { if (e2e_delay_max_ms && e2e_delay_ms) {
RTC_HISTOGRAM_COUNTS_SPARSE_100000( RTC_HISTOGRAM_COUNTS_SPARSE_100000(
uma_prefix + ".EndToEndDelayMaxInMs" + uma_suffix, e2e_delay_max_ms); uma_prefix + ".EndToEndDelayMaxInMs" + uma_suffix, *e2e_delay_max_ms);
log_stream << uma_prefix << ".EndToEndDelayMaxInMs" << uma_suffix << " " log_stream << uma_prefix << ".EndToEndDelayMaxInMs" << uma_suffix << " "
<< e2e_delay_max_ms << '\n'; << *e2e_delay_max_ms << '\n';
} }
int interframe_delay_ms = rtc::Optional<int> interframe_delay_ms =
stats.interframe_delay_counter.Avg(kMinRequiredSamples); stats.interframe_delay_counter.Avg(kMinRequiredSamples);
if (interframe_delay_ms != -1) { if (interframe_delay_ms) {
RTC_HISTOGRAM_COUNTS_SPARSE_10000( RTC_HISTOGRAM_COUNTS_SPARSE_10000(
uma_prefix + ".InterframeDelayInMs" + uma_suffix, uma_prefix + ".InterframeDelayInMs" + uma_suffix,
interframe_delay_ms); *interframe_delay_ms);
log_stream << uma_prefix << ".InterframeDelayInMs" << uma_suffix << " " log_stream << uma_prefix << ".InterframeDelayInMs" << uma_suffix << " "
<< interframe_delay_ms << '\n'; << *interframe_delay_ms << '\n';
} }
int interframe_delay_max_ms = stats.interframe_delay_counter.Max(); rtc::Optional<int> interframe_delay_max_ms =
if (interframe_delay_max_ms != -1 && interframe_delay_ms != -1) { stats.interframe_delay_counter.Max();
if (interframe_delay_max_ms && interframe_delay_ms) {
RTC_HISTOGRAM_COUNTS_SPARSE_10000( RTC_HISTOGRAM_COUNTS_SPARSE_10000(
uma_prefix + ".InterframeDelayMaxInMs" + uma_suffix, uma_prefix + ".InterframeDelayMaxInMs" + uma_suffix,
interframe_delay_max_ms); *interframe_delay_max_ms);
log_stream << uma_prefix << ".InterframeDelayMaxInMs" << uma_suffix << " " log_stream << uma_prefix << ".InterframeDelayMaxInMs" << uma_suffix << " "
<< interframe_delay_max_ms << '\n'; << *interframe_delay_max_ms << '\n';
} }
rtc::Optional<uint32_t> interframe_delay_95p_ms = rtc::Optional<uint32_t> interframe_delay_95p_ms =
@ -331,20 +339,20 @@ void ReceiveStatisticsProxy::UpdateHistograms() {
<< uma_suffix << " " << *interframe_delay_95p_ms << '\n'; << uma_suffix << " " << *interframe_delay_95p_ms << '\n';
} }
int width = stats.received_width.Avg(kMinRequiredSamples); rtc::Optional<int> width = stats.received_width.Avg(kMinRequiredSamples);
if (width != -1) { if (width) {
RTC_HISTOGRAM_COUNTS_SPARSE_10000( RTC_HISTOGRAM_COUNTS_SPARSE_10000(
uma_prefix + ".ReceivedWidthInPixels" + uma_suffix, width); uma_prefix + ".ReceivedWidthInPixels" + uma_suffix, *width);
log_stream << uma_prefix << ".ReceivedWidthInPixels" << uma_suffix << " " log_stream << uma_prefix << ".ReceivedWidthInPixels" << uma_suffix << " "
<< width << '\n'; << *width << '\n';
} }
int height = stats.received_height.Avg(kMinRequiredSamples); rtc::Optional<int> height = stats.received_height.Avg(kMinRequiredSamples);
if (height != -1) { if (height) {
RTC_HISTOGRAM_COUNTS_SPARSE_10000( RTC_HISTOGRAM_COUNTS_SPARSE_10000(
uma_prefix + ".ReceivedHeightInPixels" + uma_suffix, height); uma_prefix + ".ReceivedHeightInPixels" + uma_suffix, *height);
log_stream << uma_prefix << ".ReceivedHeightInPixels" << uma_suffix << " " log_stream << uma_prefix << ".ReceivedHeightInPixels" << uma_suffix << " "
<< height << '\n'; << *height << '\n';
} }
if (content_type != VideoContentType::UNSPECIFIED) { if (content_type != VideoContentType::UNSPECIFIED) {
@ -374,12 +382,12 @@ void ReceiveStatisticsProxy::UpdateHistograms() {
<< " " << key_frames_permille << '\n'; << " " << key_frames_permille << '\n';
} }
int qp = stats.qp_counter.Avg(kMinRequiredSamples); rtc::Optional<int> qp = stats.qp_counter.Avg(kMinRequiredSamples);
if (qp != -1) { if (qp) {
RTC_HISTOGRAM_COUNTS_SPARSE_200( RTC_HISTOGRAM_COUNTS_SPARSE_200(
uma_prefix + ".Decoded.Vp8.Qp" + uma_suffix, qp); uma_prefix + ".Decoded.Vp8.Qp" + uma_suffix, *qp);
log_stream << uma_prefix << ".Decoded.Vp8.Qp" << uma_suffix << " " << qp log_stream << uma_prefix << ".Decoded.Vp8.Qp" << uma_suffix << " "
<< '\n'; << *qp << '\n';
} }
} }
} }
@ -469,7 +477,7 @@ void ReceiveStatisticsProxy::QualitySample() {
double fps = double fps =
render_fps_tracker_.ComputeRateForInterval(now - last_sample_time_); render_fps_tracker_.ComputeRateForInterval(now - last_sample_time_);
int qp = qp_sample_.Avg(1); rtc::Optional<int> qp = qp_sample_.Avg(1);
bool prev_fps_bad = !fps_threshold_.IsHigh().value_or(true); bool prev_fps_bad = !fps_threshold_.IsHigh().value_or(true);
bool prev_qp_bad = qp_threshold_.IsHigh().value_or(false); bool prev_qp_bad = qp_threshold_.IsHigh().value_or(false);
@ -477,8 +485,8 @@ void ReceiveStatisticsProxy::QualitySample() {
bool prev_any_bad = prev_fps_bad || prev_qp_bad || prev_variance_bad; bool prev_any_bad = prev_fps_bad || prev_qp_bad || prev_variance_bad;
fps_threshold_.AddMeasurement(static_cast<int>(fps)); fps_threshold_.AddMeasurement(static_cast<int>(fps));
if (qp != -1) if (qp)
qp_threshold_.AddMeasurement(qp); qp_threshold_.AddMeasurement(*qp);
rtc::Optional<double> fps_variance_opt = fps_threshold_.CalculateVariance(); rtc::Optional<double> fps_variance_opt = fps_threshold_.CalculateVariance();
double fps_variance = fps_variance_opt.value_or(0); double fps_variance = fps_variance_opt.value_or(0);
if (fps_variance_opt) { if (fps_variance_opt) {
@ -516,7 +524,7 @@ void ReceiveStatisticsProxy::QualitySample() {
RTC_LOG(LS_VERBOSE) << "SAMPLE: sample_length: " << (now - last_sample_time_) RTC_LOG(LS_VERBOSE) << "SAMPLE: sample_length: " << (now - last_sample_time_)
<< " fps: " << fps << " fps_bad: " << fps_bad << " fps: " << fps << " fps_bad: " << fps_bad
<< " qp: " << qp << " qp_bad: " << qp_bad << " qp: " << qp.value_or(-1) << " qp_bad: " << qp_bad
<< " variance_bad: " << variance_bad << " variance_bad: " << variance_bad
<< " fps_variance: " << fps_variance; << " fps_variance: " << fps_variance;
@ -816,38 +824,6 @@ void ReceiveStatisticsProxy::OnStreamInactive() {
last_decoded_frame_time_ms_.reset(); last_decoded_frame_time_ms_.reset();
} }
void ReceiveStatisticsProxy::SampleCounter::Add(int sample) {
sum += sample;
++num_samples;
if (!max || sample > *max) {
max.emplace(sample);
}
}
void ReceiveStatisticsProxy::SampleCounter::Add(const SampleCounter& other) {
sum += other.sum;
num_samples += other.num_samples;
if (other.max && (!max || *max < *other.max))
max = other.max;
}
int ReceiveStatisticsProxy::SampleCounter::Avg(
int64_t min_required_samples) const {
if (num_samples < min_required_samples || num_samples == 0)
return -1;
return static_cast<int>(sum / num_samples);
}
int ReceiveStatisticsProxy::SampleCounter::Max() const {
return max.value_or(-1);
}
void ReceiveStatisticsProxy::SampleCounter::Reset() {
num_samples = 0;
sum = 0;
max.reset();
}
void ReceiveStatisticsProxy::OnRttUpdate(int64_t avg_rtt_ms, void ReceiveStatisticsProxy::OnRttUpdate(int64_t avg_rtt_ms,
int64_t max_rtt_ms) { int64_t max_rtt_ms) {
rtc::CritScope lock(&crit_); rtc::CritScope lock(&crit_);

View File

@ -23,6 +23,7 @@
#include "rtc_base/criticalsection.h" #include "rtc_base/criticalsection.h"
#include "rtc_base/numerics/histogram_percentile_counter.h" #include "rtc_base/numerics/histogram_percentile_counter.h"
#include "rtc_base/numerics/moving_max_counter.h" #include "rtc_base/numerics/moving_max_counter.h"
#include "rtc_base/numerics/sample_counter.h"
#include "rtc_base/rate_statistics.h" #include "rtc_base/rate_statistics.h"
#include "rtc_base/ratetracker.h" #include "rtc_base/ratetracker.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
@ -103,22 +104,8 @@ class ReceiveStatisticsProxy : public VCMReceiveStatisticsCallback,
void DecoderThreadStopped(); void DecoderThreadStopped();
private: private:
struct SampleCounter {
SampleCounter() : sum(0), num_samples(0) {}
void Add(int sample);
int Avg(int64_t min_required_samples) const;
int Max() const;
void Reset();
void Add(const SampleCounter& other);
private:
int64_t sum;
int64_t num_samples;
rtc::Optional<int> max;
};
struct QpCounters { struct QpCounters {
SampleCounter vp8; rtc::SampleCounter vp8;
}; };
struct ContentSpecificStats { struct ContentSpecificStats {
@ -126,13 +113,13 @@ class ReceiveStatisticsProxy : public VCMReceiveStatisticsCallback,
void Add(const ContentSpecificStats& other); void Add(const ContentSpecificStats& other);
SampleCounter e2e_delay_counter; rtc::SampleCounter e2e_delay_counter;
SampleCounter interframe_delay_counter; rtc::SampleCounter interframe_delay_counter;
int64_t flow_duration_ms = 0; int64_t flow_duration_ms = 0;
int64_t total_media_bytes = 0; int64_t total_media_bytes = 0;
SampleCounter received_width; rtc::SampleCounter received_width;
SampleCounter received_height; rtc::SampleCounter received_height;
SampleCounter qp_counter; rtc::SampleCounter qp_counter;
FrameCounts frame_counts; FrameCounts frame_counts;
rtc::HistogramPercentileCounter interframe_delay_percentiles; rtc::HistogramPercentileCounter interframe_delay_percentiles;
}; };
@ -161,7 +148,7 @@ class ReceiveStatisticsProxy : public VCMReceiveStatisticsCallback,
QualityThreshold fps_threshold_ RTC_GUARDED_BY(crit_); QualityThreshold fps_threshold_ RTC_GUARDED_BY(crit_);
QualityThreshold qp_threshold_ RTC_GUARDED_BY(crit_); QualityThreshold qp_threshold_ RTC_GUARDED_BY(crit_);
QualityThreshold variance_threshold_ RTC_GUARDED_BY(crit_); QualityThreshold variance_threshold_ RTC_GUARDED_BY(crit_);
SampleCounter qp_sample_ RTC_GUARDED_BY(crit_); rtc::SampleCounter qp_sample_ RTC_GUARDED_BY(crit_);
int num_bad_states_ RTC_GUARDED_BY(crit_); int num_bad_states_ RTC_GUARDED_BY(crit_);
int num_certain_states_ RTC_GUARDED_BY(crit_); int num_certain_states_ RTC_GUARDED_BY(crit_);
mutable VideoReceiveStream::Stats stats_ RTC_GUARDED_BY(crit_); mutable VideoReceiveStream::Stats stats_ RTC_GUARDED_BY(crit_);
@ -170,12 +157,12 @@ class ReceiveStatisticsProxy : public VCMReceiveStatisticsCallback,
rtc::RateTracker render_fps_tracker_ RTC_GUARDED_BY(crit_); rtc::RateTracker render_fps_tracker_ RTC_GUARDED_BY(crit_);
rtc::RateTracker render_pixel_tracker_ RTC_GUARDED_BY(crit_); rtc::RateTracker render_pixel_tracker_ RTC_GUARDED_BY(crit_);
rtc::RateTracker total_byte_tracker_ RTC_GUARDED_BY(crit_); rtc::RateTracker total_byte_tracker_ RTC_GUARDED_BY(crit_);
SampleCounter sync_offset_counter_ RTC_GUARDED_BY(crit_); rtc::SampleCounter sync_offset_counter_ RTC_GUARDED_BY(crit_);
SampleCounter decode_time_counter_ RTC_GUARDED_BY(crit_); rtc::SampleCounter decode_time_counter_ RTC_GUARDED_BY(crit_);
SampleCounter jitter_buffer_delay_counter_ RTC_GUARDED_BY(crit_); rtc::SampleCounter jitter_buffer_delay_counter_ RTC_GUARDED_BY(crit_);
SampleCounter target_delay_counter_ RTC_GUARDED_BY(crit_); rtc::SampleCounter target_delay_counter_ RTC_GUARDED_BY(crit_);
SampleCounter current_delay_counter_ RTC_GUARDED_BY(crit_); rtc::SampleCounter current_delay_counter_ RTC_GUARDED_BY(crit_);
SampleCounter delay_counter_ RTC_GUARDED_BY(crit_); rtc::SampleCounter delay_counter_ RTC_GUARDED_BY(crit_);
mutable rtc::MovingMaxCounter<int> interframe_delay_max_moving_ mutable rtc::MovingMaxCounter<int> interframe_delay_max_moving_
RTC_GUARDED_BY(crit_); RTC_GUARDED_BY(crit_);
std::map<VideoContentType, ContentSpecificStats> content_specific_stats_ std::map<VideoContentType, ContentSpecificStats> content_specific_stats_