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

Unified Diff: media/cast/logging/receiver_time_offset_estimator_impl.cc

Issue 482383005: Cast logging: Additional stats for getStats() API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@REAL-NEW-MASTER
Patch Set: Rebase Created 6 years, 4 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
Index: media/cast/logging/receiver_time_offset_estimator_impl.cc
diff --git a/media/cast/logging/receiver_time_offset_estimator_impl.cc b/media/cast/logging/receiver_time_offset_estimator_impl.cc
index 44d5eb0b3d731e954ecb32d7f393de374704c784..950b3671ae8b1f3efa3519abb23c8e1271c4a744 100644
--- a/media/cast/logging/receiver_time_offset_estimator_impl.cc
+++ b/media/cast/logging/receiver_time_offset_estimator_impl.cc
@@ -6,6 +6,7 @@
#include <utility>
#include "base/logging.h"
+#include "base/time/tick_clock.h"
#include "media/cast/logging/receiver_time_offset_estimator_impl.h"
namespace media {
@@ -15,8 +16,13 @@ namespace cast {
// the entry gets removed from the map.
const size_t kMaxEventTimesMapSize = 100;
-ReceiverTimeOffsetEstimatorImpl::ReceiverTimeOffsetEstimatorImpl()
- : bounded_(false) {}
+ReceiverTimeOffsetEstimatorImpl::ReceiverTimeOffsetEstimatorImpl(
+ base::TickClock* clock)
+ : bounded_(false),
+ clock_(clock),
+ offset_bounds_valid_(false),
+ last_reset_time_(clock_->NowTicks()) {
+}
ReceiverTimeOffsetEstimatorImpl::~ReceiverTimeOffsetEstimatorImpl() {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -93,8 +99,8 @@ bool ReceiverTimeOffsetEstimatorImpl::GetReceiverOffsetBounds(
if (!bounded_)
return false;
- *lower_bound = offset_lower_bound_;
- *upper_bound = offset_upper_bound_;
+ *lower_bound = prev_offset_lower_bound_;
+ *upper_bound = prev_offset_upper_bound_;
return true;
}
@@ -109,7 +115,7 @@ void ReceiverTimeOffsetEstimatorImpl::UpdateOffsetBounds(
base::TimeDelta lower_bound = event.event_b_time - event.event_c_time;
base::TimeDelta upper_bound = event.event_b_time - event.event_a_time;
- if (bounded_) {
+ if (offset_bounds_valid_) {
lower_bound = std::max(lower_bound, offset_lower_bound_);
upper_bound = std::min(upper_bound, offset_upper_bound_);
}
@@ -122,6 +128,22 @@ void ReceiverTimeOffsetEstimatorImpl::UpdateOffsetBounds(
offset_lower_bound_ = lower_bound;
offset_upper_bound_ = upper_bound;
+ offset_bounds_valid_ = true;
+ if (!bounded_ ||
+ offset_upper_bound_ - offset_lower_bound_ <
+ base::TimeDelta::FromMilliseconds(20)) {
+ prev_offset_lower_bound_ = offset_lower_bound_;
+ prev_offset_upper_bound_ = offset_upper_bound_;
+ }
+
+ base::TimeTicks now = clock_->NowTicks();
+ if (now - last_reset_time_ > base::TimeDelta::FromSeconds(20)) {
+ last_reset_time_ = now;
+ offset_lower_bound_ = base::TimeDelta();
+ offset_upper_bound_ = base::TimeDelta();
+ offset_bounds_valid_ = false;
+ }
+
bounded_ = true;
}

Powered by Google App Engine
This is Rietveld 408576698