diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index e8a72c7824..7a03b3bfb5 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -444,6 +444,7 @@ rtc_source_set("rtc_base_approved_generic") { deps += [ "..:webrtc_common", "../api:array_view", + "//third_party/abseil-cpp/absl/memory:memory", "//third_party/abseil-cpp/absl/types:optional", ] diff --git a/rtc_base/rate_statistics.cc b/rtc_base/rate_statistics.cc index 9b1ff8fc9a..bb506aa7f4 100644 --- a/rtc_base/rate_statistics.cc +++ b/rtc_base/rate_statistics.cc @@ -12,6 +12,7 @@ #include +#include "absl/memory/memory.h" #include "rtc_base/checks.h" namespace webrtc { @@ -26,6 +27,21 @@ RateStatistics::RateStatistics(int64_t window_size_ms, float scale) max_window_size_ms_(window_size_ms), current_window_size_ms_(max_window_size_ms_) {} +RateStatistics::RateStatistics(const RateStatistics& other) + : accumulated_count_(other.accumulated_count_), + num_samples_(other.num_samples_), + oldest_time_(other.oldest_time_), + oldest_index_(other.oldest_index_), + scale_(other.scale_), + max_window_size_ms_(other.max_window_size_ms_), + current_window_size_ms_(other.current_window_size_ms_) { + buckets_ = absl::make_unique(other.max_window_size_ms_); + std::copy(other.buckets_.get(), + other.buckets_.get() + other.max_window_size_ms_, buckets_.get()); +} + +RateStatistics::RateStatistics(RateStatistics&& other) = default; + RateStatistics::~RateStatistics() {} void RateStatistics::Reset() { diff --git a/rtc_base/rate_statistics.h b/rtc_base/rate_statistics.h index 89bfddfa55..68035c9a68 100644 --- a/rtc_base/rate_statistics.h +++ b/rtc_base/rate_statistics.h @@ -27,6 +27,11 @@ class RateStatistics { // scale = coefficient to convert counts/ms to desired unit // ex: kBpsScale (8000) for bits/s if count represents bytes. RateStatistics(int64_t max_window_size_ms, float scale); + + RateStatistics(const RateStatistics& other); + + RateStatistics(RateStatistics&& other); + ~RateStatistics(); // Reset instance to original state.