summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxjz <xjz@chromium.org>2016-01-07 13:56:12 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-07 21:57:17 +0000
commitf671b176ec61dbccfbb7f1230f0b27a3b4f2845f (patch)
treeca2f5ac6d0551e6596cbff8e01db758674795e18
parent0cad1f4cc187083f997c91f117529ba3ff5b191a (diff)
downloadchromium_src-f671b176ec61dbccfbb7f1230f0b27a3b4f2845f.zip
chromium_src-f671b176ec61dbccfbb7f1230f0b27a3b4f2845f.tar.gz
chromium_src-f671b176ec61dbccfbb7f1230f0b27a3b4f2845f.tar.bz2
Modify FeedbackSignalAccumulator to work with both TimeTicks and
TimeDelta types. BUG=573280 Review URL: https://codereview.chromium.org/1557173003 Cr-Commit-Position: refs/heads/master@{#368166}
-rw-r--r--media/capture/content/feedback_signal_accumulator.cc25
-rw-r--r--media/capture/content/feedback_signal_accumulator.h29
-rw-r--r--media/capture/content/feedback_signal_accumulator_unittest.cc4
-rw-r--r--media/capture/content/video_capture_oracle.cc5
-rw-r--r--media/capture/content/video_capture_oracle.h6
-rw-r--r--media/cast/sender/vp8_encoder.cc15
-rw-r--r--media/cast/sender/vp8_encoder.h4
7 files changed, 48 insertions, 40 deletions
diff --git a/media/capture/content/feedback_signal_accumulator.cc b/media/capture/content/feedback_signal_accumulator.cc
index 896c23a..ba0e08e 100644
--- a/media/capture/content/feedback_signal_accumulator.cc
+++ b/media/capture/content/feedback_signal_accumulator.cc
@@ -1,6 +1,8 @@
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#ifndef MEDIA_CAPTURE_FEEDBACK_SIGNAL_ACCUMULATOR_CC_
+#define MEDIA_CAPTURE_FEEDBACK_SIGNAL_ACCUMULATOR_CC_
#include "media/capture/content/feedback_signal_accumulator.h"
@@ -9,21 +11,24 @@
namespace media {
-FeedbackSignalAccumulator::FeedbackSignalAccumulator(base::TimeDelta half_life)
- : half_life_(half_life) {
+template <typename TimeType>
+FeedbackSignalAccumulator<TimeType>::FeedbackSignalAccumulator(
+ base::TimeDelta half_life)
+ : half_life_(half_life), average_(NAN) {
DCHECK(half_life_ > base::TimeDelta());
}
-void FeedbackSignalAccumulator::Reset(double starting_value,
- base::TimeTicks timestamp) {
- DCHECK(!timestamp.is_null());
+template <typename TimeType>
+void FeedbackSignalAccumulator<TimeType>::Reset(double starting_value,
+ TimeType timestamp) {
average_ = update_value_ = prior_average_ = starting_value;
reset_time_ = update_time_ = prior_update_time_ = timestamp;
}
-bool FeedbackSignalAccumulator::Update(double value,
- base::TimeTicks timestamp) {
- DCHECK(!reset_time_.is_null());
+template <typename TimeType>
+bool FeedbackSignalAccumulator<TimeType>::Update(double value,
+ TimeType timestamp) {
+ DCHECK(!std::isnan(average_)) << "Reset() must be called once.";
if (timestamp < update_time_) {
return false; // Not in chronological order.
@@ -53,4 +58,8 @@ bool FeedbackSignalAccumulator::Update(double value,
return true;
}
+template class MEDIA_EXPORT FeedbackSignalAccumulator<base::TimeDelta>;
+template class MEDIA_EXPORT FeedbackSignalAccumulator<base::TimeTicks>;
} // namespace media
+
+#endif // MEDIA_CAPTURE_FEEDBACK_SIGNAL_ACCUMULATOR_CC_
diff --git a/media/capture/content/feedback_signal_accumulator.h b/media/capture/content/feedback_signal_accumulator.h
index 3905d58..08a11e9 100644
--- a/media/capture/content/feedback_signal_accumulator.h
+++ b/media/capture/content/feedback_signal_accumulator.h
@@ -23,7 +23,11 @@ namespace media {
//
// Usage note: Reset() must be called at least once before the first call to
// Update().
-class MEDIA_EXPORT FeedbackSignalAccumulator {
+//
+// This template class supports data points that are timestamped using either
+// |base::TimeDelta| or |base::TimeTicks|.
+template <typename TimeType>
+class FeedbackSignalAccumulator {
public:
// |half_life| is the amount of time that must pass between two data points to
// move the accumulated average value halfway in-between. Example: If
@@ -31,13 +35,11 @@ class MEDIA_EXPORT FeedbackSignalAccumulator {
// Update(1.0, t=1s) will result in an accumulated average value of 0.5.
explicit FeedbackSignalAccumulator(base::TimeDelta half_life);
- // TODO(xjz): Change time type used by Reset() and Update() methods to
- // TimeDelta instead of TimeTicks. https://crbug.com/573280.
-
// Erase all memory of historical values, re-starting with the given
// |starting_value|.
- void Reset(double starting_value, base::TimeTicks timestamp);
- base::TimeTicks reset_time() const { return reset_time_; }
+ void Reset(double starting_value, TimeType timestamp);
+
+ TimeType reset_time() const { return reset_time_; }
// Apply the given |value|, which was observed at the given |timestamp|, to
// the accumulated average. If the timestamp is in chronological order, the
@@ -45,8 +47,9 @@ class MEDIA_EXPORT FeedbackSignalAccumulator {
// effect and false is returned. If there are two or more updates at the same
// |timestamp|, only the one with the greatest value will be accounted for
// (see class comments for elaboration).
- bool Update(double value, base::TimeTicks timestamp);
- base::TimeTicks update_time() const { return update_time_; }
+ bool Update(double value, TimeType timestamp);
+
+ TimeType update_time() const { return update_time_; }
// Returns the current accumulated average value.
double current() const { return average_; }
@@ -57,12 +60,12 @@ class MEDIA_EXPORT FeedbackSignalAccumulator {
// accumulated average.
const base::TimeDelta half_life_;
- base::TimeTicks reset_time_; // |timestamp| passed in last call to Reset().
- double average_; // Current accumulated average.
- double update_value_; // Latest |value| accepted by Update().
- base::TimeTicks update_time_; // Latest |timestamp| accepted by Update().
+ TimeType reset_time_; // |timestamp| passed in last call to Reset().
+ double average_; // Current accumulated average.
+ double update_value_; // Latest |value| accepted by Update().
+ TimeType update_time_; // Latest |timestamp| accepted by Update().
double prior_average_; // Accumulated average before last call to Update().
- base::TimeTicks prior_update_time_; // |timestamp| in prior call to Update().
+ TimeType prior_update_time_; // |timestamp| in prior call to Update().
};
} // namespace media
diff --git a/media/capture/content/feedback_signal_accumulator_unittest.cc b/media/capture/content/feedback_signal_accumulator_unittest.cc
index 9d0f925..c8ee7f7 100644
--- a/media/capture/content/feedback_signal_accumulator_unittest.cc
+++ b/media/capture/content/feedback_signal_accumulator_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "media/capture/content/feedback_signal_accumulator.h"
+#include "media/capture/content/feedback_signal_accumulator.cc"
#include "testing/gtest/include/gtest/gtest.h"
@@ -19,7 +19,7 @@ class FeedbackSignalAccumulatorTest : public ::testing::Test {
protected:
const base::TimeDelta half_life_;
- FeedbackSignalAccumulator acc_;
+ FeedbackSignalAccumulator<base::TimeTicks> acc_;
base::TimeTicks t_;
};
diff --git a/media/capture/content/video_capture_oracle.cc b/media/capture/content/video_capture_oracle.cc
index 461200d..920c00cc4 100644
--- a/media/capture/content/video_capture_oracle.cc
+++ b/media/capture/content/video_capture_oracle.cc
@@ -85,8 +85,9 @@ base::TimeTicks JustAfter(base::TimeTicks t) {
// Returns true if updates have been accumulated by |accumulator| for a
// sufficient amount of time and the latest update was fairly recent, relative
// to |now|.
-bool HasSufficientRecentFeedback(const FeedbackSignalAccumulator& accumulator,
- base::TimeTicks now) {
+bool HasSufficientRecentFeedback(
+ const FeedbackSignalAccumulator<base::TimeTicks>& accumulator,
+ base::TimeTicks now) {
const base::TimeDelta amount_of_history =
accumulator.update_time() - accumulator.reset_time();
return (amount_of_history.InMicroseconds() >= kMinSizeChangePeriodMicros) &&
diff --git a/media/capture/content/video_capture_oracle.h b/media/capture/content/video_capture_oracle.h
index 6a23973..9f2f173 100644
--- a/media/capture/content/video_capture_oracle.h
+++ b/media/capture/content/video_capture_oracle.h
@@ -11,7 +11,7 @@
#include "media/base/media_export.h"
#include "media/capture/content/animated_content_sampler.h"
#include "media/capture/content/capture_resolution_chooser.h"
-#include "media/capture/content/feedback_signal_accumulator.h"
+#include "media/capture/content/feedback_signal_accumulator.cc"
#include "media/capture/content/smooth_event_sampler.h"
#include "ui/gfx/geometry/rect.h"
@@ -182,13 +182,13 @@ class MEDIA_EXPORT VideoCaptureOracle {
base::TimeTicks frame_timestamps_[kMaxFrameTimestamps];
// Recent average buffer pool utilization for capture.
- FeedbackSignalAccumulator buffer_pool_utilization_;
+ FeedbackSignalAccumulator<base::TimeTicks> buffer_pool_utilization_;
// Estimated maximum frame area that currently can be handled by the consumer,
// in number of pixels per frame. This is used to adjust the capture size up
// or down to a data volume the consumer can handle. Note that some consumers
// do not provide feedback, and the analysis logic should account for that.
- FeedbackSignalAccumulator estimated_capable_area_;
+ FeedbackSignalAccumulator<base::TimeTicks> estimated_capable_area_;
// The time of the first analysis which concluded the end-to-end system was
// under-utilized. If null, the system is not currently under-utilized. This
diff --git a/media/cast/sender/vp8_encoder.cc b/media/cast/sender/vp8_encoder.cc
index a9a4547..07798ff 100644
--- a/media/cast/sender/vp8_encoder.cc
+++ b/media/cast/sender/vp8_encoder.cc
@@ -50,7 +50,8 @@ const double kEquivalentEncodingSpeedStepPerQpStep = 1 / 20.0;
const int kHighestEncodingSpeed = 12;
const int kLowestEncodingSpeed = 6;
-bool HasSufficientFeedback(const FeedbackSignalAccumulator& accumulator) {
+bool HasSufficientFeedback(
+ const FeedbackSignalAccumulator<base::TimeDelta>& accumulator) {
const base::TimeDelta amount_of_history =
accumulator.update_time() - accumulator.reset_time();
return amount_of_history.InMicroseconds() >= 250000; // 0.25 second.
@@ -331,15 +332,8 @@ void Vp8Encoder::Encode(const scoped_refptr<media::VideoFrame>& video_frame,
if (encoded_frame->dependency == EncodedFrame::KEY) {
key_frame_requested_ = false;
}
-
- // This is not a true system clock value, but a "hack" needed in order to use
- // FeedbackSignalAccumulator.
- const base::TimeTicks current_time = base::TimeTicks() +
- base::TimeDelta::FromMilliseconds(10) +
- video_frame->timestamp();
-
if (encoded_frame->dependency == EncodedFrame::KEY) {
- encoding_speed_acc_.Reset(kHighestEncodingSpeed, current_time);
+ encoding_speed_acc_.Reset(kHighestEncodingSpeed, video_frame->timestamp());
} else {
// Equivalent encoding speed considering both cpu_used setting and
// quantizer.
@@ -350,7 +344,8 @@ void Vp8Encoder::Encode(const scoped_refptr<media::VideoFrame>& video_frame,
double adjusted_encoding_speed = actual_encoding_speed *
encoded_frame->deadline_utilization /
kTargetDeadlineUtilization;
- encoding_speed_acc_.Update(adjusted_encoding_speed, current_time);
+ encoding_speed_acc_.Update(adjusted_encoding_speed,
+ video_frame->timestamp());
}
if (HasSufficientFeedback(encoding_speed_acc_)) {
diff --git a/media/cast/sender/vp8_encoder.h b/media/cast/sender/vp8_encoder.h
index ef80a69..8a2a2b2 100644
--- a/media/cast/sender/vp8_encoder.h
+++ b/media/cast/sender/vp8_encoder.h
@@ -10,7 +10,7 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread_checker.h"
-#include "media/capture/content/feedback_signal_accumulator.h"
+#include "media/capture/content/feedback_signal_accumulator.cc"
#include "media/cast/cast_config.h"
#include "media/cast/sender/software_video_encoder.h"
#include "third_party/libvpx_new/source/libvpx/vpx/vpx_encoder.h"
@@ -80,7 +80,7 @@ class Vp8Encoder : public SoftwareVideoEncoder {
bool has_seen_zero_length_encoded_frame_;
// The accumulator (time averaging) of the encoding speed.
- FeedbackSignalAccumulator encoding_speed_acc_;
+ FeedbackSignalAccumulator<base::TimeDelta> encoding_speed_acc_;
// The higher the speed, the less CPU usage, and the lower quality.
int encoding_speed_;