Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Unified Diff: webrtc/video/stats_counter.cc

Issue 2536613002: Use RateAccCounter for sent bitrate stats. Reports average of periodically computed stats over a ca… (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/video/stats_counter.h ('k') | webrtc/video/stats_counter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/video/stats_counter.cc
diff --git a/webrtc/video/stats_counter.cc b/webrtc/video/stats_counter.cc
index 86dedd9e4f7709fb0208d14507ba5dfd3f265f35..da7a70690b52c42927be997e321bee80bae9e816 100644
--- a/webrtc/video/stats_counter.cc
+++ b/webrtc/video/stats_counter.cc
@@ -88,10 +88,14 @@ class Samples {
samples_[stream_id].Add(sample);
++total_count_;
}
- void Set(int sample, uint32_t stream_id) {
+ void Set(int64_t sample, uint32_t stream_id) {
samples_[stream_id].Set(sample);
++total_count_;
}
+ void SetLast(int64_t sample, uint32_t stream_id) {
+ samples_[stream_id].SetLast(sample);
+ }
+ int64_t GetLast(uint32_t stream_id) { return samples_[stream_id].GetLast(); }
int64_t Count() const { return total_count_; }
bool Empty() const { return total_count_ == 0; }
@@ -138,10 +142,12 @@ class Samples {
++count_;
max_ = std::max(sample, max_);
}
- void Set(int sample) {
+ void Set(int64_t sample) {
sum_ = sample;
++count_;
}
+ void SetLast(int64_t sample) { last_sum_ = sample; }
+ int64_t GetLast() const { return last_sum_; }
void Reset() {
if (count_ > 0)
last_sum_ = sum_;
@@ -172,7 +178,9 @@ StatsCounter::StatsCounter(Clock* clock,
clock_(clock),
observer_(observer),
last_process_time_ms_(-1),
- paused_(false) {
+ paused_(false),
+ pause_time_ms_(-1),
+ min_pause_time_ms_(0) {
RTC_DCHECK_GT(process_intervals_ms_, 0);
}
@@ -188,10 +196,22 @@ AggregatedStats StatsCounter::ProcessAndGetStats() {
return aggregated_counter_->ComputeStats();
}
+void StatsCounter::ProcessAndPauseForDuration(int64_t min_pause_time_ms) {
+ ProcessAndPause();
+ min_pause_time_ms_ = min_pause_time_ms;
+}
+
void StatsCounter::ProcessAndPause() {
if (HasSample())
TryProcess();
paused_ = true;
+ pause_time_ms_ = clock_->TimeInMilliseconds();
+}
+
+void StatsCounter::ProcessAndStopPause() {
+ if (HasSample())
+ TryProcess();
+ Resume();
}
bool StatsCounter::HasSample() const {
@@ -215,16 +235,25 @@ bool StatsCounter::TimeToProcess(int* elapsed_intervals) {
return true;
}
-void StatsCounter::Set(int sample, uint32_t stream_id) {
+void StatsCounter::Add(int sample) {
TryProcess();
- samples_->Set(sample, stream_id);
- paused_ = false;
+ samples_->Add(sample, kStreamId0);
+ ResumeIfMinTimePassed();
}
-void StatsCounter::Add(int sample) {
+void StatsCounter::Set(int64_t sample, uint32_t stream_id) {
+ if (paused_ && sample == samples_->GetLast(stream_id)) {
+ // Do not add same sample while paused (will reset pause).
+ return;
+ }
TryProcess();
- samples_->Add(sample, kStreamId0);
- paused_ = false;
+ samples_->Set(sample, stream_id);
+ ResumeIfMinTimePassed();
+}
+
+void StatsCounter::SetLast(int64_t sample, uint32_t stream_id) {
+ RTC_DCHECK(!HasSample()) << "Should be set before first sample is added.";
+ samples_->SetLast(sample, stream_id);
}
// Reports periodically computed metric.
@@ -265,6 +294,17 @@ void StatsCounter::TryProcess() {
bool StatsCounter::IncludeEmptyIntervals() const {
return include_empty_intervals_ && !paused_ && !aggregated_counter_->Empty();
}
+void StatsCounter::ResumeIfMinTimePassed() {
+ if (paused_ &&
+ (clock_->TimeInMilliseconds() - pause_time_ms_) >= min_pause_time_ms_) {
+ Resume();
+ }
+}
+
+void StatsCounter::Resume() {
+ paused_ = false;
+ min_pause_time_ms_ = 0;
+}
// StatsCounter sub-classes.
AvgCounter::AvgCounter(Clock* clock,
@@ -398,10 +438,14 @@ RateAccCounter::RateAccCounter(Clock* clock,
include_empty_intervals,
observer) {}
-void RateAccCounter::Set(int sample, uint32_t stream_id) {
+void RateAccCounter::Set(int64_t sample, uint32_t stream_id) {
StatsCounter::Set(sample, stream_id);
}
+void RateAccCounter::SetLast(int64_t sample, uint32_t stream_id) {
+ StatsCounter::SetLast(sample, stream_id);
+}
+
bool RateAccCounter::GetMetric(int* metric) const {
int64_t diff = samples_->Diff();
if (diff < 0 || (!include_empty_intervals_ && diff == 0))
« no previous file with comments | « webrtc/video/stats_counter.h ('k') | webrtc/video/stats_counter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698