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 5de1b3b6173eeac946b28f636ed27094b32c9efd..e76ea5ea3b715a7e70e8b8d797755c32cc05b340 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, |
@@ -55,13 +67,11 @@ bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture( |
scoped_ptr<VideoCaptureDevice::Client::Buffer> output_buffer( |
client_->ReserveOutputBuffer(params_.requested_format.pixel_format, |
coded_size)); |
- // 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() / |
hubbe
2015/06/23 20:04:30
Multiplication is potentially faster than division
miu
2015/06/25 20:48:59
Eliminated one of the divisions. If C++11 constex
|
+ (kTargetMaxPoolUtilizationPercent / 100.0); |
const char* event_name = |
(event == VideoCaptureOracle::kTimerPoll ? "poll" : |
@@ -75,6 +85,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) { |
@@ -94,7 +105,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); |
@@ -122,15 +133,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,10 +203,10 @@ void ThreadSafeCaptureOracle::DidConsumeFrame( |
utilization >= 0.0) { |
VLOG(2) << "Consumer resource utilization for frame " << frame_number |
<< ": " << utilization; |
- } |
- // TODO(miu): Use |utilization| to drive automatic video resolution changes. |
- // http://crbug.com/156767. |
+ base::AutoLock guard(lock_); |
+ oracle_.RecordConsumerFeedback(frame_number, utilization); |
+ } |
} |
} // namespace media |