Chromium Code Reviews| Index: content/browser/media/capture/content_video_capture_device_core.cc |
| diff --git a/content/browser/media/capture/content_video_capture_device_core.cc b/content/browser/media/capture/content_video_capture_device_core.cc |
| index 8d44104c1c418f4a3f21d9648b682d4a34ce74d7..8a06da43884697362f1d7c3fb475736cf4be2818 100644 |
| --- a/content/browser/media/capture/content_video_capture_device_core.cc |
| +++ b/content/browser/media/capture/content_video_capture_device_core.cc |
| @@ -49,7 +49,9 @@ ThreadSafeCaptureOracle::ThreadSafeCaptureOracle( |
| oracle_(base::TimeDelta::FromMicroseconds( |
| static_cast<int64>(1000000.0 / params.requested_format.frame_rate + |
| 0.5 /* to round to nearest int */))), |
| - params_(params) {} |
| + params_(params), |
| + resolution_evaluator_(params.requested_format.frame_size, |
| + params.resolution_change_policy) {} |
| ThreadSafeCaptureOracle::~ThreadSafeCaptureOracle() {} |
| @@ -67,9 +69,7 @@ bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture( |
| if (!client_) |
| return false; // Capture is stopped. |
| - if (capture_size_.IsEmpty()) |
| - capture_size_ = max_frame_size(); |
| - const gfx::Size visible_size = capture_size_; |
| + const gfx::Size visible_size = resolution_evaluator_.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, |
| @@ -141,30 +141,15 @@ bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture( |
| gfx::Size ThreadSafeCaptureOracle::GetCaptureSize() const { |
| base::AutoLock guard(lock_); |
| - return capture_size_.IsEmpty() ? max_frame_size() : capture_size_; |
| + return resolution_evaluator_.capture_size(); |
| } |
| void ThreadSafeCaptureOracle::UpdateCaptureSize(const gfx::Size& source_size) { |
| base::AutoLock guard(lock_); |
| - |
| - // Update |capture_size_| based on |source_size| if either: 1) The resolution |
| - // change policy specifies fixed frame sizes and |capture_size_| has not yet |
| - // been set; or 2) The resolution change policy specifies dynamic frame |
| - // sizes. |
| - if (capture_size_.IsEmpty() || params_.resolution_change_policy == |
| - media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT) { |
| - capture_size_ = source_size; |
| - // The capture size should not exceed the maximum frame size. |
| - if (capture_size_.width() > max_frame_size().width() || |
| - capture_size_.height() > max_frame_size().height()) { |
| - capture_size_ = media::ComputeLetterboxRegion( |
| - gfx::Rect(max_frame_size()), capture_size_).size(); |
| - } |
| - // The capture size must be even and not less than the minimum frame size. |
| - capture_size_ = gfx::Size( |
| - std::max(kMinFrameWidth, MakeEven(capture_size_.width())), |
| - std::max(kMinFrameHeight, MakeEven(capture_size_.height()))); |
| - } |
| + resolution_evaluator_.UpdateForNewSourceSize(source_size); |
| + VLOG(1) << "Source size changed to " << source_size.ToString() |
| + << " --> Capture size is now " |
| + << resolution_evaluator_.capture_size().ToString(); |
| } |
| void ThreadSafeCaptureOracle::Stop() { |
| @@ -234,23 +219,15 @@ void ContentVideoCaptureDeviceCore::AllocateAndStart( |
| return; |
| } |
| - if (params.requested_format.frame_size.width() < kMinFrameWidth || |
| - params.requested_format.frame_size.height() < kMinFrameHeight) { |
| - std::string error_msg = |
| - "invalid frame size: " + params.requested_format.frame_size.ToString(); |
| - DVLOG(1) << error_msg; |
| - client->OnError(error_msg); |
| - return; |
| - } |
| - |
| - media::VideoCaptureParams new_params = params; |
| - // Frame dimensions must each be an even integer since the client wants (or |
| - // will convert to) YUV420. |
|
Wez
2015/05/14 01:44:54
Do we need to worry about the I420 even-size limit
miu
2015/05/14 21:12:26
No. As part of this change I realized we were wri
|
| - new_params.requested_format.frame_size.SetSize( |
| - MakeEven(params.requested_format.frame_size.width()), |
| - MakeEven(params.requested_format.frame_size.height())); |
| + if (params.requested_format.frame_size.IsEmpty()) { |
| + std::string error_msg = |
| + "invalid frame size: " + params.requested_format.frame_size.ToString(); |
| + DVLOG(1) << error_msg; |
| + client->OnError(error_msg); |
| + return; |
| + } |
| - oracle_proxy_ = new ThreadSafeCaptureOracle(client.Pass(), new_params); |
| + oracle_proxy_ = new ThreadSafeCaptureOracle(client.Pass(), params); |
| // Starts the capture machine asynchronously. |
| BrowserThread::PostTaskAndReplyWithResult( |
| @@ -259,7 +236,7 @@ void ContentVideoCaptureDeviceCore::AllocateAndStart( |
| base::Bind(&VideoCaptureMachine::Start, |
| base::Unretained(capture_machine_.get()), |
| oracle_proxy_, |
| - new_params), |
| + params), |
| base::Bind(&ContentVideoCaptureDeviceCore::CaptureStarted, AsWeakPtr())); |
| TransitionStateTo(kCapturing); |