Chromium Code Reviews| Index: media/video/capture/mac/video_capture_device_mac.mm |
| diff --git a/media/video/capture/mac/video_capture_device_mac.mm b/media/video/capture/mac/video_capture_device_mac.mm |
| index 190f53d6a380a01f4c7bbc6be9af5860f2532d51..65103e5e86f5a6b887dacac73e5d9b51f81c6792 100644 |
| --- a/media/video/capture/mac/video_capture_device_mac.mm |
| +++ b/media/video/capture/mac/video_capture_device_mac.mm |
| @@ -20,6 +20,7 @@ |
| #import "media/video/capture/mac/platform_video_capturing_mac.h" |
| #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h" |
| #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" |
| +#include "ui/gfx/size.h" |
| @implementation DeviceNameAndTransportType |
| @@ -94,24 +95,19 @@ typedef struct IOUSBInterfaceDescriptor { |
| UInt8 bUnitID; |
| } IOUSBInterfaceDescriptor; |
| -// TODO(ronghuawu): Replace this with CapabilityList::GetBestMatchedCapability. |
| -void GetBestMatchSupportedResolution(int* width, int* height) { |
| +static void GetBestMatchSupportedResolution(gfx::Size* resolution) { |
| int min_diff = kint32max; |
| - int matched_width = *width; |
| - int matched_height = *height; |
| - int desired_res_area = *width * *height; |
| + const int desired_area = resolution->GetArea(); |
| for (size_t i = 0; i < arraysize(kWellSupportedResolutions); ++i) { |
|
mcasas
2014/10/13 08:18:45
nit: range-based for loop...? ;)
|
| - int area = kWellSupportedResolutions[i]->width * |
| - kWellSupportedResolutions[i]->height; |
| - int diff = std::abs(desired_res_area - area); |
| + const int area = kWellSupportedResolutions[i]->width * |
| + kWellSupportedResolutions[i]->height; |
| + const int diff = std::abs(desired_area - area); |
| if (diff < min_diff) { |
| min_diff = diff; |
| - matched_width = kWellSupportedResolutions[i]->width; |
| - matched_height = kWellSupportedResolutions[i]->height; |
| + resolution->SetSize(kWellSupportedResolutions[i]->width, |
| + kWellSupportedResolutions[i]->height); |
| } |
| } |
| - *width = matched_width; |
| - *height = matched_height; |
| } |
| // Tries to create a user-side device interface for a given USB device. Returns |
| @@ -370,15 +366,13 @@ void VideoCaptureDeviceMac::AllocateAndStart( |
| if (state_ != kIdle) { |
| return; |
| } |
| - int width = params.requested_format.frame_size.width(); |
| - int height = params.requested_format.frame_size.height(); |
| - float frame_rate = params.requested_format.frame_rate; |
| // QTKit API can scale captured frame to any size requested, which would lead |
| // to undesired aspect ratio changes. Try to open the camera with a known |
| // supported format and let the client crop/pad the captured frames. |
| + gfx::Size resolution = params.requested_format.frame_size; |
| if (!AVFoundationGlue::IsAVFoundationSupported()) |
| - GetBestMatchSupportedResolution(&width, &height); |
| + GetBestMatchSupportedResolution(&resolution); |
| client_ = client.Pass(); |
| if (device_name_.capture_api_type() == Name::AVFOUNDATION) |
| @@ -394,13 +388,11 @@ void VideoCaptureDeviceMac::AllocateAndStart( |
| SetErrorState("Could not open capture device."); |
| return; |
| } |
| - if (frame_rate < kMinFrameRate) |
| - frame_rate = kMinFrameRate; |
| - else if (frame_rate > kMaxFrameRate) |
| - frame_rate = kMaxFrameRate; |
| - capture_format_.frame_size.SetSize(width, height); |
| - capture_format_.frame_rate = frame_rate; |
| + capture_format_.frame_size = resolution; |
| + capture_format_.frame_rate = |
| + std::max(kMinFrameRate, |
| + std::min(params.requested_format.frame_rate, kMaxFrameRate)); |
| capture_format_.pixel_format = PIXEL_FORMAT_UYVY; |
| // QTKit: Set the capture resolution only if this is VGA or smaller, otherwise |
| @@ -410,8 +402,8 @@ void VideoCaptureDeviceMac::AllocateAndStart( |
| // latency, because the webcam will need to be reopened if its default |
| // resolution is not HD or VGA. |
| // AVfoundation is configured for all resolutions. |
| - if (AVFoundationGlue::IsAVFoundationSupported() || width <= kVGA.width || |
| - height <= kVGA.height) { |
| + if (AVFoundationGlue::IsAVFoundationSupported() || |
| + resolution.width() <= kVGA.width || resolution.height() <= kVGA.height) { |
| if (!UpdateCaptureResolution()) |
| return; |
| } |