Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1114)

Unified Diff: media/video/capture/mac/video_capture_device_mac.mm

Issue 558623002: Video capture: Refactor GetBestMatchedFormat from Win to OS independent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sort pixel formats in order of preference Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
}
« no previous file with comments | « no previous file | media/video/capture/video_capture_device.h » ('j') | media/video/capture/video_capture_device.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698