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

Unified Diff: media/capture/thread_safe_capture_oracle.cc

Issue 1199593005: Automatic resolution throttling for screen capture pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resolution_chooser_ITEM13
Patch Set: Addressed hubbe's comments, and replaced pessimistic accumulators with simple proving-period logic. REBASE Created 5 years, 6 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/capture/thread_safe_capture_oracle.cc
diff --git a/media/capture/thread_safe_capture_oracle.cc b/media/capture/thread_safe_capture_oracle.cc
index 040e3940c2e9d19d98a72e04fc1caa5653c3e60d..90ffdb248e54f99d98e0d3529bc17c5a0e58bb55 100644
--- a/media/capture/thread_safe_capture_oracle.cc
+++ b/media/capture/thread_safe_capture_oracle.cc
@@ -19,16 +19,26 @@
namespace media {
+namespace {
+
+// The target maximum amount of the buffer pool to utilize. Actual buffer pool
+// utilization is attenuated by this amount before being reported to the
+// VideoCaptureOracle. This value takes into account the maximum number of
+// buffer pool buffers and a desired safety margin.
+const int kTargetMaxPoolUtilizationPercent = 60;
+
+} // namespace
+
ThreadSafeCaptureOracle::ThreadSafeCaptureOracle(
scoped_ptr<VideoCaptureDevice::Client> client,
const VideoCaptureParams& params)
: client_(client.Pass()),
oracle_(base::TimeDelta::FromMicroseconds(
static_cast<int64>(1000000.0 / params.requested_format.frame_rate +
- 0.5 /* to round to nearest int */))),
- params_(params),
- resolution_chooser_(params.requested_format.frame_size,
- params.resolution_change_policy) {}
+ 0.5 /* to round to nearest int */)),
+ params.requested_format.frame_size,
+ params.resolution_change_policy),
+ params_(params) {}
ThreadSafeCaptureOracle::~ThreadSafeCaptureOracle() {}
@@ -46,7 +56,9 @@ bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture(
if (!client_)
return false; // Capture is stopped.
- const gfx::Size visible_size = resolution_chooser_.capture_size();
+ const bool should_capture =
+ oracle_.ObserveEventAndDecideCapture(event, damage_rect, event_time);
+ const gfx::Size visible_size = oracle_.capture_size();
// Always round up the coded size to multiple of 16 pixels.
// See http://crbug.com/402151.
const gfx::Size coded_size((visible_size.width() + 15) & ~15,
@@ -59,13 +71,11 @@ bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture(
? media::PIXEL_FORMAT_I420
: media::PIXEL_FORMAT_ARGB,
params_.requested_format.pixel_storage));
- // TODO(miu): Use current buffer pool utilization to drive automatic video
- // resolution changes. http://crbug.com/156767.
- VLOG(2) << "Current buffer pool utilization is "
- << (client_->GetBufferPoolUtilization() * 100.0) << '%';
-
- const bool should_capture =
- oracle_.ObserveEventAndDecideCapture(event, damage_rect, event_time);
+ // Get the current buffer pool utilization and attenuate it: The utilization
+ // reported to the oracle is in terms of a maximum sustainable amount (not the
+ // absolute maximum).
+ const double attenuated_utilization = client_->GetBufferPoolUtilization() *
+ (100.0 / kTargetMaxPoolUtilizationPercent);
const char* event_name =
(event == VideoCaptureOracle::kTimerPoll ? "poll" :
@@ -79,6 +89,7 @@ bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture(
TRACE_EVENT_SCOPE_THREAD,
"trigger",
event_name);
+ oracle_.RecordWillNotCapture(attenuated_utilization);
return false;
} else if (!should_capture && output_buffer.get()) {
if (event == VideoCaptureOracle::kCompositorUpdate) {
@@ -98,7 +109,7 @@ bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture(
"trigger", event_name);
return false;
}
- int frame_number = oracle_.RecordCapture();
+ const int frame_number = oracle_.RecordCapture(attenuated_utilization);
TRACE_EVENT_ASYNC_BEGIN2("gpu.capture", "Capture", output_buffer.get(),
"frame_number", frame_number,
"trigger", event_name);
@@ -126,15 +137,13 @@ bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture(
gfx::Size ThreadSafeCaptureOracle::GetCaptureSize() const {
base::AutoLock guard(lock_);
- return resolution_chooser_.capture_size();
+ return oracle_.capture_size();
}
void ThreadSafeCaptureOracle::UpdateCaptureSize(const gfx::Size& source_size) {
base::AutoLock guard(lock_);
- resolution_chooser_.SetSourceSize(source_size);
- VLOG(1) << "Source size changed to " << source_size.ToString()
- << " --> Capture size is now "
- << resolution_chooser_.capture_size().ToString();
+ VLOG(1) << "Source size changed to " << source_size.ToString();
+ oracle_.SetSourceSize(source_size);
}
void ThreadSafeCaptureOracle::Stop() {
@@ -194,14 +203,10 @@ void ThreadSafeCaptureOracle::DidConsumeFrame(
// destructor. |metadata| is still valid for read-access at this point.
double utilization = -1.0;
if (metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION,
- &utilization) &&
- utilization >= 0.0) {
- VLOG(2) << "Consumer resource utilization for frame " << frame_number
- << ": " << utilization;
+ &utilization)) {
+ base::AutoLock guard(lock_);
+ oracle_.RecordConsumerFeedback(frame_number, utilization);
}
-
- // TODO(miu): Use |utilization| to drive automatic video resolution changes.
- // http://crbug.com/156767.
}
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698