Move SampleStatsCounter to public API

Bug: None
Change-Id: I8956f6febbb1caf71e951d212d57746fe1ec5eb2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/184506
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32142}
This commit is contained in:
Artem Titov 2020-09-18 18:23:08 +02:00 committed by Commit Bot
parent 979c13f565
commit 9d77762023
25 changed files with 126 additions and 56 deletions

View file

@ -532,6 +532,7 @@ if (rtc_include_tests) {
"api:rtc_api_unittests",
"api/audio/test:audio_api_unittests",
"api/audio_codecs/test:audio_codecs_api_unittests",
"api/numerics:numerics_unittests",
"api/transport:stun_unittest",
"api/video/test:rtc_api_video_unittests",
"api/video_codecs/test:video_codecs_api_unittests",

41
api/numerics/BUILD.gn Normal file
View file

@ -0,0 +1,41 @@
# Copyright (c) 2020 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.
import("../../webrtc.gni")
rtc_library("numerics") {
visibility = [ "*" ]
sources = [
"samples_stats_counter.cc",
"samples_stats_counter.h",
]
deps = [
"..:array_view",
"../../rtc_base:checks",
"../../rtc_base:rtc_numerics",
"../../rtc_base:timeutils",
"../units:timestamp",
]
absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container" ]
}
if (rtc_include_tests) {
rtc_library("numerics_unittests") {
visibility = [ "*" ]
testonly = true
sources = [ "samples_stats_counter_unittest.cc" ]
deps = [
":numerics",
"../../test:test_support",
]
absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container" ]
}
}

6
api/numerics/DEPS Normal file
View file

@ -0,0 +1,6 @@
specific_include_rules = {
# Some internal headers are allowed even in API headers:
"samples_stats_counter\.h": [
"+rtc_base/numerics/running_statistics.h",
]
}

View file

@ -8,8 +8,9 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "rtc_base/numerics/samples_stats_counter.h"
#include "api/numerics/samples_stats_counter.h"
#include <algorithm>
#include <cmath>
#include "absl/algorithm/container.h"

View file

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_NUMERICS_SAMPLES_STATS_COUNTER_H_
#define RTC_BASE_NUMERICS_SAMPLES_STATS_COUNTER_H_
#ifndef API_NUMERICS_SAMPLES_STATS_COUNTER_H_
#define API_NUMERICS_SAMPLES_STATS_COUNTER_H_
#include <vector>
@ -98,7 +98,7 @@ class SamplesStatsCounter {
}
private:
RunningStatistics<double> stats_;
webrtc_impl::RunningStatistics<double> stats_;
std::vector<StatsSample> samples_;
bool sorted_ = false;
};
@ -116,4 +116,4 @@ SamplesStatsCounter operator/(const SamplesStatsCounter& counter, double value);
} // namespace webrtc
#endif // RTC_BASE_NUMERICS_SAMPLES_STATS_COUNTER_H_
#endif // API_NUMERICS_SAMPLES_STATS_COUNTER_H_

View file

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "rtc_base/numerics/samples_stats_counter.h"
#include "api/numerics/samples_stats_counter.h"
#include <math.h>

View file

@ -789,6 +789,7 @@ if (rtc_include_tests) {
]
deps = [
"../../api:videocodec_test_fixture_api",
"../../api/numerics",
"../../rtc_base:checks",
"../../rtc_base:rtc_numerics",
"../../rtc_base:stringutils",

View file

@ -179,20 +179,20 @@ VideoStatistics VideoCodecTestStatsImpl::SliceAndCalcVideoStatistic(
VideoStatistics video_stat;
float buffer_level_bits = 0.0f;
RunningStatistics<float> buffer_level_sec;
webrtc_impl::RunningStatistics<float> buffer_level_sec;
RunningStatistics<size_t> key_frame_size_bytes;
RunningStatistics<size_t> delta_frame_size_bytes;
webrtc_impl::RunningStatistics<size_t> key_frame_size_bytes;
webrtc_impl::RunningStatistics<size_t> delta_frame_size_bytes;
RunningStatistics<size_t> frame_encoding_time_us;
RunningStatistics<size_t> frame_decoding_time_us;
webrtc_impl::RunningStatistics<size_t> frame_encoding_time_us;
webrtc_impl::RunningStatistics<size_t> frame_decoding_time_us;
RunningStatistics<float> psnr_y;
RunningStatistics<float> psnr_u;
RunningStatistics<float> psnr_v;
RunningStatistics<float> psnr;
RunningStatistics<float> ssim;
RunningStatistics<int> qp;
webrtc_impl::RunningStatistics<float> psnr_y;
webrtc_impl::RunningStatistics<float> psnr_u;
webrtc_impl::RunningStatistics<float> psnr_v;
webrtc_impl::RunningStatistics<float> psnr;
webrtc_impl::RunningStatistics<float> ssim;
webrtc_impl::RunningStatistics<int> qp;
size_t rtp_timestamp_first_frame = 0;
size_t rtp_timestamp_prev_frame = 0;
@ -329,10 +329,10 @@ VideoStatistics VideoCodecTestStatsImpl::SliceAndCalcVideoStatistic(
? 1000000.0f / mean_decode_time_us
: std::numeric_limits<float>::max();
auto MaxDelaySec =
[target_bitrate_kbps](const RunningStatistics<size_t>& stats) {
return 8 * stats.GetMax().value_or(0) / 1000 / target_bitrate_kbps;
};
auto MaxDelaySec = [target_bitrate_kbps](
const webrtc_impl::RunningStatistics<size_t>& stats) {
return 8 * stats.GetMax().value_or(0) / 1000 / target_bitrate_kbps;
};
video_stat.avg_delay_sec = buffer_level_sec.GetMean().value_or(0);
video_stat.max_key_frame_delay_sec = MaxDelaySec(key_frame_size_bytes);

View file

@ -204,8 +204,8 @@ rtc_library("platform_thread") {
visibility = [
":rtc_base_approved",
":rtc_task_queue_libevent",
":rtc_task_queue_win",
":rtc_task_queue_stdlib",
":rtc_task_queue_win",
"synchronization:mutex",
"synchronization:sequence_checker",
]
@ -587,8 +587,6 @@ rtc_library("rtc_numerics") {
sources = [
"numerics/event_based_exponential_moving_average.cc",
"numerics/event_based_exponential_moving_average.h",
"numerics/event_rate_counter.cc",
"numerics/event_rate_counter.h",
"numerics/exp_filter.cc",
"numerics/exp_filter.h",
"numerics/math_utils.h",
@ -597,25 +595,30 @@ rtc_library("rtc_numerics") {
"numerics/moving_median_filter.h",
"numerics/percentile_filter.h",
"numerics/running_statistics.h",
"numerics/sample_stats.cc",
"numerics/sample_stats.h",
"numerics/samples_stats_counter.cc",
"numerics/samples_stats_counter.h",
"numerics/sequence_number_util.h",
]
deps = [
":checks",
":macromagic",
":rtc_base_approved",
":safe_compare",
"../api:array_view",
]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
}
rtc_library("rtc_stats_counters") {
sources = [
"numerics/event_rate_counter.cc",
"numerics/event_rate_counter.h",
"numerics/sample_stats.cc",
"numerics/sample_stats.h",
]
deps = [
"../api/numerics",
"../api/units:data_rate",
"../api/units:time_delta",
"../api/units:timestamp",
]
absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/types:optional",
]
absl_deps = []
}
config("rtc_json_suppressions") {
@ -804,6 +807,7 @@ rtc_library("rtc_base") {
"../api:array_view",
"../api:function_view",
"../api:scoped_refptr",
"../api/numerics",
"../api/task_queue",
"../system_wrappers:field_trial",
"network:sent_packet",
@ -942,7 +946,6 @@ rtc_library("rtc_base") {
"callback.h",
"log_sinks.cc",
"log_sinks.h",
"numerics/math_utils.h",
"rolling_accumulator.h",
"ssl_roots.h",
]
@ -1270,6 +1273,7 @@ if (rtc_include_tests) {
":rtc_base",
":rtc_base_approved",
":rtc_base_tests_utils",
":rtc_numerics",
":rtc_task_queue",
":safe_compare",
":safe_minmax",
@ -1278,6 +1282,7 @@ if (rtc_include_tests) {
":testclient",
"../api:array_view",
"../api:scoped_refptr",
"../api/numerics",
"../api/units:time_delta",
"../system_wrappers",
"../test:fileutils",
@ -1351,7 +1356,6 @@ if (rtc_include_tests) {
"numerics/moving_median_filter_unittest.cc",
"numerics/percentile_filter_unittest.cc",
"numerics/running_statistics_unittest.cc",
"numerics/samples_stats_counter_unittest.cc",
"numerics/sequence_number_util_unittest.cc",
]
deps = [

View file

@ -8,14 +8,16 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_NUMERICS_MATH_UTILS_H_
#define RTC_BASE_NUMERICS_MATH_UTILS_H_
#ifndef API_NUMERICS_MATH_UTILS_H_
#define API_NUMERICS_MATH_UTILS_H_
#include <limits>
#include <type_traits>
#include "rtc_base/checks.h"
namespace webrtc {
namespace webrtc_impl {
// Given two numbers |x| and |y| such that x >= y, computes the difference
// x - y without causing undefined behavior due to signed overflow.
template <typename T>
@ -67,4 +69,7 @@ constexpr T minus_infinity_or_min() {
return std::numeric_limits<T>::min();
}
#endif // RTC_BASE_NUMERICS_MATH_UTILS_H_
} // namespace webrtc_impl
} // namespace webrtc
#endif // API_NUMERICS_MATH_UTILS_H_

View file

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_NUMERICS_RUNNING_STATISTICS_H_
#define RTC_BASE_NUMERICS_RUNNING_STATISTICS_H_
#ifndef API_NUMERICS_RUNNING_STATISTICS_H_
#define API_NUMERICS_RUNNING_STATISTICS_H_
#include <algorithm>
#include <cmath>
@ -20,6 +20,7 @@
#include "rtc_base/numerics/math_utils.h"
namespace webrtc {
namespace webrtc_impl {
// tl;dr: Robust and efficient online computation of statistics,
// using Welford's method for variance. [1]
@ -154,6 +155,7 @@ class RunningStatistics {
double cumul_ = 0; // Variance * size_, sometimes noted m2.
};
} // namespace webrtc_impl
} // namespace webrtc
#endif // RTC_BASE_NUMERICS_RUNNING_STATISTICS_H_
#endif // API_NUMERICS_RUNNING_STATISTICS_H_

View file

@ -21,6 +21,7 @@
// Tests were copied from samples_stats_counter_unittest.cc.
namespace webrtc {
namespace webrtc_impl {
namespace {
RunningStatistics<double> CreateStatsFilledWithIntsFrom1ToN(int n) {
@ -55,8 +56,6 @@ class RunningStatisticsTest : public ::testing::TestWithParam<int> {};
constexpr int SIZE_FOR_MERGE = 5;
} // namespace
TEST(RunningStatistics, FullSimpleTest) {
auto stats = CreateStatsFilledWithIntsFrom1ToN(100);
@ -192,4 +191,6 @@ INSTANTIATE_TEST_SUITE_P(RunningStatisticsTests,
RunningStatisticsTest,
::testing::Range(0, SIZE_FOR_MERGE + 1));
} // namespace
} // namespace webrtc_impl
} // namespace webrtc

View file

@ -10,10 +10,10 @@
#ifndef RTC_BASE_NUMERICS_SAMPLE_STATS_H_
#define RTC_BASE_NUMERICS_SAMPLE_STATS_H_
#include "api/numerics/samples_stats_counter.h"
#include "api/units/data_rate.h"
#include "api/units/time_delta.h"
#include "api/units/timestamp.h"
#include "rtc_base/numerics/samples_stats_counter.h"
namespace webrtc {
template <typename T>

View file

@ -120,7 +120,7 @@ void BucketTestSignedInterval(unsigned int bucket_count,
ASSERT_GE(high, low);
ASSERT_GE(bucket_count, 2u);
uint32_t interval = unsigned_difference<int32_t>(high, low) + 1;
uint32_t interval = webrtc_impl::unsigned_difference<int32_t>(high, low) + 1;
uint32_t numbers_per_bucket;
if (interval == 0) {
// The computation high - low + 1 should be 2^32 but overflowed
@ -136,7 +136,8 @@ void BucketTestSignedInterval(unsigned int bucket_count,
int32_t sample = prng->Rand(low, high);
EXPECT_LE(low, sample);
EXPECT_GE(high, sample);
buckets[unsigned_difference<int32_t>(sample, low) / numbers_per_bucket]++;
buckets[webrtc_impl::unsigned_difference<int32_t>(sample, low) /
numbers_per_bucket]++;
}
for (unsigned int i = 0; i < bucket_count; i++) {

View file

@ -40,7 +40,7 @@ class RollingAccumulator {
size_t count() const { return static_cast<size_t>(stats_.Size()); }
void Reset() {
stats_ = webrtc::RunningStatistics<T>();
stats_ = webrtc::webrtc_impl::RunningStatistics<T>();
next_index_ = 0U;
max_ = T();
max_stale_ = false;
@ -129,7 +129,7 @@ class RollingAccumulator {
double ComputeVariance() const { return stats_.GetVariance().value_or(0); }
private:
webrtc::RunningStatistics<T> stats_;
webrtc::webrtc_impl::RunningStatistics<T> stats_;
size_t next_index_;
mutable T max_;
mutable bool max_stale_;

View file

@ -35,8 +35,8 @@ group("test") {
rtc_library("frame_generator_impl") {
visibility = [
"../api:create_frame_generator",
":*",
"../api:create_frame_generator",
]
testonly = true
sources = [
@ -246,6 +246,7 @@ rtc_library("perf_test") {
]
deps = [
"../api:array_view",
"../api/numerics",
"../rtc_base:checks",
"../rtc_base:criticalsection",
"../rtc_base:logging",

View file

@ -567,6 +567,7 @@ if (!build_with_chromium) {
"../../../api:rtc_stats_api",
"../../../api:stats_observer_interface",
"../../../api:track_id_stream_info_map",
"../../../api/numerics",
"../../../api/units:time_delta",
"../../../api/units:timestamp",
"../../../rtc_base:criticalsection",
@ -610,6 +611,7 @@ if (!build_with_chromium) {
"../../../api:peer_connection_quality_test_fixture_api",
"../../../api:rtc_stats_api",
"../../../api:track_id_stream_info_map",
"../../../api/numerics",
"../../../api/units:data_rate",
"../../../api/units:data_size",
"../../../api/units:time_delta",
@ -635,6 +637,7 @@ if (!build_with_chromium) {
"../..:perf_test",
"../../../api:array_view",
"../../../api:video_quality_analyzer_api",
"../../../api/numerics",
"../../../api/units:time_delta",
"../../../api/units:timestamp",
"../../../api/video:encoded_image",
@ -717,6 +720,7 @@ if (!build_with_chromium) {
"../../../api:peer_connection_quality_test_fixture_api",
"../../../api:rtc_stats_api",
"../../../api:track_id_stream_info_map",
"../../../api/numerics",
"../../../api/units:timestamp",
"../../../rtc_base:criticalsection",
"../../../rtc_base:rtc_event",

View file

@ -15,10 +15,10 @@
#include <string>
#include "absl/strings/string_view.h"
#include "api/numerics/samples_stats_counter.h"
#include "api/test/audio_quality_analyzer_interface.h"
#include "api/test/track_id_stream_info_map.h"
#include "api/units/time_delta.h"
#include "rtc_base/numerics/samples_stats_counter.h"
#include "rtc_base/synchronization/mutex.h"
#include "test/testsupport/perf_test.h"

View file

@ -20,12 +20,12 @@
#include <vector>
#include "api/array_view.h"
#include "api/numerics/samples_stats_counter.h"
#include "api/test/video_quality_analyzer_interface.h"
#include "api/units/timestamp.h"
#include "api/video/encoded_image.h"
#include "api/video/video_frame.h"
#include "rtc_base/event.h"
#include "rtc_base/numerics/samples_stats_counter.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/synchronization/mutex.h"
#include "system_wrappers/include/clock.h"

View file

@ -15,11 +15,11 @@
#include <string>
#include "absl/strings/string_view.h"
#include "api/numerics/samples_stats_counter.h"
#include "api/test/peerconnection_quality_test_fixture.h"
#include "api/test/track_id_stream_info_map.h"
#include "api/units/data_size.h"
#include "api/units/timestamp.h"
#include "rtc_base/numerics/samples_stats_counter.h"
#include "rtc_base/synchronization/mutex.h"
#include "test/testsupport/perf_test.h"

View file

@ -16,10 +16,10 @@
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/numerics/samples_stats_counter.h"
#include "api/test/peerconnection_quality_test_fixture.h"
#include "api/test/track_id_stream_info_map.h"
#include "api/units/timestamp.h"
#include "rtc_base/numerics/samples_stats_counter.h"
#include "rtc_base/synchronization/mutex.h"
#include "test/testsupport/perf_test.h"

View file

@ -130,6 +130,7 @@ if (rtc_include_tests) {
"../../rtc_base:rtc_base_approved",
"../../rtc_base:rtc_base_tests_utils",
"../../rtc_base:rtc_numerics",
"../../rtc_base:rtc_stats_counters",
"../../rtc_base:rtc_task_queue",
"../../rtc_base:safe_minmax",
"../../rtc_base:task_queue_for_test",

View file

@ -16,7 +16,7 @@
#include <vector>
#include "api/array_view.h"
#include "rtc_base/numerics/samples_stats_counter.h"
#include "api/numerics/samples_stats_counter.h"
namespace webrtc {
namespace test {

View file

@ -298,6 +298,7 @@ if (rtc_include_tests) {
"../api:rtc_event_log_output_file",
"../api:test_dependency_factory",
"../api:video_quality_test_fixture_api",
"../api/numerics",
"../api/rtc_event_log:rtc_event_log_factory",
"../api/task_queue",
"../api/task_queue:default_task_queue_factory",

View file

@ -35,7 +35,7 @@ class VideoAnalyzer : public PacketReceiver,
public Transport,
public rtc::VideoSinkInterface<VideoFrame> {
public:
using Statistics = RunningStatistics<double>;
using Statistics = webrtc_impl::RunningStatistics<double>;
VideoAnalyzer(test::LayerFilteringTransport* transport,
const std::string& test_label,