diff options
author | ronghuawu@chromium.org <ronghuawu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-21 09:07:26 +0000 |
---|---|---|
committer | ronghuawu@chromium.org <ronghuawu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-21 09:07:26 +0000 |
commit | 30ac16a839999ab557858f4ce303dcde041b13f1 (patch) | |
tree | dd958d2c8c60752db3c5fa4b1ad6e49ac5b0ea08 /media/video | |
parent | 83ef4701fe42c636f4b56d9039b4102228427bae (diff) | |
download | chromium_src-30ac16a839999ab557858f4ce303dcde041b13f1.zip chromium_src-30ac16a839999ab557858f4ce303dcde041b13f1.tar.gz chromium_src-30ac16a839999ab557858f4ce303dcde041b13f1.tar.bz2 |
* Update the desired aspect ratio in StartCapture call so that later the video
frame can be cropped to meet the requirement if the camera returns a different
resolution than asked for.
* Restrict video capture to a limited set of resolution on Mac
QTKit can scale captured frame to any size requested, which would lead to undesired aspect ratio change.
This patch allows client to request any size for video capture and VideoCaptureDevice will return only supported sizes which will not change aspect ratio.
BUG=170464
TEST= 1) apprtc with minre=640x360&maxre=640x360 on mac 2) a local preview with 640x360
Review URL: https://chromiumcodereview.appspot.com/12545048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189553 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/video')
-rw-r--r-- | media/video/capture/mac/video_capture_device_mac.mm | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/media/video/capture/mac/video_capture_device_mac.mm b/media/video/capture/mac/video_capture_device_mac.mm index 6e74d95..f18eb54 100644 --- a/media/video/capture/mac/video_capture_device_mac.mm +++ b/media/video/capture/mac/video_capture_device_mac.mm @@ -15,6 +15,37 @@ namespace { const int kMinFrameRate = 1; const int kMaxFrameRate = 30; +struct Resolution { + int width; + int height; +}; + +const Resolution kWellSupportedResolutions[] = { + { 320, 240 }, + { 640, 480 }, + { 1280, 720 }, +}; + +// TODO(ronghuawu): Replace this with CapabilityList::GetBestMatchedCapability. +void GetBestMatchSupportedResolution(int* width, int* height) { + int min_diff = kint32max; + int matched_width = *width; + int matched_height = *height; + int desired_res_area = *width * *height; + for (size_t i = 0; i < arraysize(kWellSupportedResolutions); ++i) { + int area = kWellSupportedResolutions[i].width * + kWellSupportedResolutions[i].height; + int diff = std::abs(desired_res_area - area); + if (diff < min_diff) { + min_diff = diff; + matched_width = kWellSupportedResolutions[i].width; + matched_height = kWellSupportedResolutions[i].height; + } + } + *width = matched_width; + *height = matched_height; +} + } namespace media { @@ -59,6 +90,12 @@ void VideoCaptureDeviceMac::Allocate(int width, int height, int frame_rate, if (state_ != kIdle) { return; } + + // QTKit can scale captured frame to any size requested, which would lead to + // undesired aspect ratio change. Tries to open the camera with a natively + // supported format and let the client to crop/pad the captured frames. + GetBestMatchSupportedResolution(&width, &height); + observer_ = observer; NSString* deviceId = [NSString stringWithUTF8String:device_name_.unique_id.c_str()]; |