Index: content/browser/renderer_host/media/video_capture_device_impl.cc |
diff --git a/content/browser/renderer_host/media/video_capture_device_impl.cc b/content/browser/renderer_host/media/video_capture_device_impl.cc |
index 54af30f71b461e6ad74bfa760c18c8dcc832cb45..ad9034f2985c83be5610aaea0fa7f0fda50d47e5 100644 |
--- a/content/browser/renderer_host/media/video_capture_device_impl.cc |
+++ b/content/browser/renderer_host/media/video_capture_device_impl.cc |
@@ -44,12 +44,18 @@ void DeleteCaptureMachineOnUIThread( |
ThreadSafeCaptureOracle::ThreadSafeCaptureOracle( |
scoped_ptr<media::VideoCaptureDevice::Client> client, |
scoped_ptr<VideoCaptureOracle> oracle, |
- const gfx::Size& capture_size, |
- int frame_rate) |
+ const media::VideoCaptureParams& params) |
: client_(client.Pass()), |
oracle_(oracle.Pass()), |
- capture_size_(capture_size), |
- frame_rate_(frame_rate) {} |
+ params_(params), |
+ capture_size_updated_(false) { |
+ // Frame dimensions must each be an even integer since the client wants (or |
+ // will convert to) YUV420. |
+ capture_size_ = gfx::Size( |
+ MakeEven(params.requested_format.frame_size.width()), |
+ MakeEven(params.requested_format.frame_size.height())); |
+ frame_rate_ = params.requested_format.frame_rate; |
+} |
ThreadSafeCaptureOracle::~ThreadSafeCaptureOracle() {} |
@@ -122,6 +128,23 @@ bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture( |
return true; |
} |
+void ThreadSafeCaptureOracle::UpdateCaptureSize(const gfx::Size& source_size) { |
+ base::AutoLock guard(lock_); |
+ |
+ // If this is the first call to UpdateCaptureSize(), or the receiver supports |
+ // variable resolution, then determine the capture size by treating the |
+ // requested width and height as maxima. |
+ if (!capture_size_updated_ || params_.allow_resolution_change) { |
+ // The capture resolution should not exceed the source frame size. |
+ // In other words it should downscale the image but not upscale it. |
+ gfx::Size capture_size = params_.requested_format.frame_size; |
+ capture_size.SetToMin(source_size); |
Sergey Ulanov
2013/12/03 02:14:23
SetToMin() doesn't preserve aspect ratio. I think
hshi1
2013/12/03 02:19:36
Done.
|
+ capture_size_ = gfx::Size(MakeEven(capture_size.width()), |
+ MakeEven(capture_size.height())); |
+ capture_size_updated_ = true; |
+ } |
+} |
+ |
void ThreadSafeCaptureOracle::Stop() { |
base::AutoLock guard(lock_); |
client_.reset(); |
@@ -173,13 +196,10 @@ void VideoCaptureDeviceImpl::AllocateAndStart( |
return; |
} |
- // Frame dimensions must each be a positive, even integer, since the client |
- // wants (or will convert to) YUV420. |
- gfx::Size frame_size(MakeEven(params.requested_format.frame_size.width()), |
- MakeEven(params.requested_format.frame_size.height())); |
- if (frame_size.width() < kMinFrameWidth || |
- frame_size.height() < kMinFrameHeight) { |
- DVLOG(1) << "invalid frame size: " << frame_size.ToString(); |
+ if (params.requested_format.frame_size.width() < kMinFrameWidth || |
+ params.requested_format.frame_size.height() < kMinFrameHeight) { |
+ DVLOG(1) << "invalid frame size: " |
+ << params.requested_format.frame_size.ToString(); |
client->OnError(); |
return; |
} |
@@ -193,8 +213,7 @@ void VideoCaptureDeviceImpl::AllocateAndStart( |
oracle_proxy_ = |
new ThreadSafeCaptureOracle(client.Pass(), |
oracle.Pass(), |
- frame_size, |
- params.requested_format.frame_rate); |
+ params); |
// Starts the capture machine asynchronously. |
BrowserThread::PostTaskAndReplyWithResult( |