Commit a8d026b7 authored by mcasas@chromium.org's avatar mcasas@chromium.org

Mac AVFoundation: Allow use of all camera's supported resolutions.

Historically, QTKit had the camera resolutions limited to QVGA/VGA/HD
due to some internal rescaling not respecting aspect ratio in those
systems. AVFoundation has not shown such problems, to the best
of the author's knowledge, and the limited resolutions prevent 
using all the camera's capabilities. This CL enables the use of all
resolutions listed by the camera as supported.

QTKit implementation remains untouched.

Tested: Locally using C910 and Facetime HD alternatively. This CL
solves the attached bugs 367668, 367670.

[1] https://code.google.com/p/chromium/codesearch#chromium/src/media/video/capture/mac/video_capture_device_mac.mm&sq=package:chromium&l=189

BUG=288562, 367668, 367670

Review URL: https://codereview.chromium.org/258783007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266845 0039d316-1c4b-4281-b951-d872f2087c98
parent fa032883
...@@ -41,9 +41,6 @@ class MEDIA_EXPORT AVFoundationGlue { ...@@ -41,9 +41,6 @@ class MEDIA_EXPORT AVFoundationGlue {
static NSString* AVCaptureSessionRuntimeErrorNotification(); static NSString* AVCaptureSessionRuntimeErrorNotification();
static NSString* AVCaptureSessionDidStopRunningNotification(); static NSString* AVCaptureSessionDidStopRunningNotification();
static NSString* AVCaptureSessionErrorKey(); static NSString* AVCaptureSessionErrorKey();
static NSString* AVCaptureSessionPreset320x240();
static NSString* AVCaptureSessionPreset640x480();
static NSString* AVCaptureSessionPreset1280x720();
// Originally from AVVideoSettings.h but in global namespace. // Originally from AVVideoSettings.h but in global namespace.
static NSString* AVVideoScalingModeKey(); static NSString* AVVideoScalingModeKey();
...@@ -64,7 +61,6 @@ MEDIA_EXPORT ...@@ -64,7 +61,6 @@ MEDIA_EXPORT
- (NSString*)uniqueID; - (NSString*)uniqueID;
- (NSString*)localizedName; - (NSString*)localizedName;
- (BOOL)isSuspended; - (BOOL)isSuspended;
- (BOOL)supportsAVCaptureSessionPreset:(NSString*)preset;
- (NSArray*)formats; - (NSArray*)formats;
@end @end
...@@ -99,9 +95,6 @@ MEDIA_EXPORT ...@@ -99,9 +95,6 @@ MEDIA_EXPORT
@interface CrAVCaptureSession : NSObject @interface CrAVCaptureSession : NSObject
- (void)release; - (void)release;
- (BOOL)canSetSessionPreset:(NSString*)preset;
- (void)setSessionPreset:(NSString*)preset;
- (NSString*)sessionPreset;
- (void)addInput:(CrAVCaptureInput*)input; - (void)addInput:(CrAVCaptureInput*)input;
- (void)removeInput:(CrAVCaptureInput*)input; - (void)removeInput:(CrAVCaptureInput*)input;
- (void)addOutput:(CrAVCaptureOutput*)output; - (void)addOutput:(CrAVCaptureOutput*)output;
......
...@@ -45,9 +45,6 @@ class AVFoundationInternal { ...@@ -45,9 +45,6 @@ class AVFoundationInternal {
{&AVCaptureSessionDidStopRunningNotification_, {&AVCaptureSessionDidStopRunningNotification_,
"AVCaptureSessionDidStopRunningNotification"}, "AVCaptureSessionDidStopRunningNotification"},
{&AVCaptureSessionErrorKey_, "AVCaptureSessionErrorKey"}, {&AVCaptureSessionErrorKey_, "AVCaptureSessionErrorKey"},
{&AVCaptureSessionPreset320x240_, "AVCaptureSessionPreset320x240"},
{&AVCaptureSessionPreset640x480_, "AVCaptureSessionPreset640x480"},
{&AVCaptureSessionPreset1280x720_, "AVCaptureSessionPreset1280x720"},
{&AVVideoScalingModeKey_, "AVVideoScalingModeKey"}, {&AVVideoScalingModeKey_, "AVVideoScalingModeKey"},
{&AVVideoScalingModeResizeAspectFill_, {&AVVideoScalingModeResizeAspectFill_,
"AVVideoScalingModeResizeAspectFill"}, "AVVideoScalingModeResizeAspectFill"},
...@@ -80,15 +77,6 @@ class AVFoundationInternal { ...@@ -80,15 +77,6 @@ class AVFoundationInternal {
NSString* AVCaptureSessionErrorKey() const { NSString* AVCaptureSessionErrorKey() const {
return AVCaptureSessionErrorKey_; return AVCaptureSessionErrorKey_;
} }
NSString* AVCaptureSessionPreset320x240() const {
return AVCaptureSessionPreset320x240_;
}
NSString* AVCaptureSessionPreset640x480() const {
return AVCaptureSessionPreset640x480_;
}
NSString* AVCaptureSessionPreset1280x720() const {
return AVCaptureSessionPreset1280x720_;
}
NSString* AVVideoScalingModeKey() const { return AVVideoScalingModeKey_; } NSString* AVVideoScalingModeKey() const { return AVVideoScalingModeKey_; }
NSString* AVVideoScalingModeResizeAspectFill() const { NSString* AVVideoScalingModeResizeAspectFill() const {
return AVVideoScalingModeResizeAspectFill_; return AVVideoScalingModeResizeAspectFill_;
...@@ -106,9 +94,6 @@ class AVFoundationInternal { ...@@ -106,9 +94,6 @@ class AVFoundationInternal {
NSString* AVCaptureSessionRuntimeErrorNotification_; NSString* AVCaptureSessionRuntimeErrorNotification_;
NSString* AVCaptureSessionDidStopRunningNotification_; NSString* AVCaptureSessionDidStopRunningNotification_;
NSString* AVCaptureSessionErrorKey_; NSString* AVCaptureSessionErrorKey_;
NSString* AVCaptureSessionPreset320x240_;
NSString* AVCaptureSessionPreset640x480_;
NSString* AVCaptureSessionPreset1280x720_;
NSString* AVVideoScalingModeKey_; NSString* AVVideoScalingModeKey_;
NSString* AVVideoScalingModeResizeAspectFill_; NSString* AVVideoScalingModeResizeAspectFill_;
...@@ -173,18 +158,6 @@ NSString* AVFoundationGlue::AVCaptureSessionErrorKey() { ...@@ -173,18 +158,6 @@ NSString* AVFoundationGlue::AVCaptureSessionErrorKey() {
return g_avfoundation_handle.Get().AVCaptureSessionErrorKey(); return g_avfoundation_handle.Get().AVCaptureSessionErrorKey();
} }
NSString* AVFoundationGlue::AVCaptureSessionPreset320x240() {
return g_avfoundation_handle.Get().AVCaptureSessionPreset320x240();
}
NSString* AVFoundationGlue::AVCaptureSessionPreset640x480() {
return g_avfoundation_handle.Get().AVCaptureSessionPreset640x480();
}
NSString* AVFoundationGlue::AVCaptureSessionPreset1280x720() {
return g_avfoundation_handle.Get().AVCaptureSessionPreset1280x720();
}
NSString* AVFoundationGlue::AVVideoScalingModeKey() { NSString* AVFoundationGlue::AVVideoScalingModeKey() {
return g_avfoundation_handle.Get().AVVideoScalingModeKey(); return g_avfoundation_handle.Get().AVVideoScalingModeKey();
} }
......
...@@ -175,39 +175,12 @@ ...@@ -175,39 +175,12 @@
frameHeight_ = height; frameHeight_ = height;
frameRate_ = frameRate; frameRate_ = frameRate;
// Identify the sessionPreset that corresponds to the desired resolution. // The capture output has to be configured, despite Mac documentation
NSString* sessionPreset; // detailing that setting the sessionPreset would be enough. The reason for
if (width == 1280 && height == 720 && [captureSession_ canSetSessionPreset: // this mismatch is probably because most of the AVFoundation docs are written
AVFoundationGlue::AVCaptureSessionPreset1280x720()]) { // for iOS and not for MacOsX. AVVideoScalingModeKey() refers to letterboxing
sessionPreset = AVFoundationGlue::AVCaptureSessionPreset1280x720(); // yes/no and preserve aspect ratio yes/no when scaling. Currently we set
} else if (width == 640 && height == 480 && [captureSession_ // cropping and preservation.
canSetSessionPreset:
AVFoundationGlue::AVCaptureSessionPreset640x480()]) {
sessionPreset = AVFoundationGlue::AVCaptureSessionPreset640x480();
} else if (width == 320 && height == 240 && [captureSession_
canSetSessionPreset:
AVFoundationGlue::AVCaptureSessionPreset320x240()]) {
sessionPreset = AVFoundationGlue::AVCaptureSessionPreset320x240();
} else {
DLOG(ERROR) << "Unsupported resolution (" << width << "x" << height << ")";
return NO;
}
[captureSession_ setSessionPreset:sessionPreset];
// Check that our capture Device can be used with the current preset.
if (![captureDevice_ supportsAVCaptureSessionPreset:
[captureSession_ sessionPreset]]){
DLOG(ERROR) << "Video capture device does not support current preset";
return NO;
}
// Despite all Mac documentation detailing that setting the sessionPreset is
// enough, that is not the case for, at least, the MacBook Air built-in
// FaceTime HD Camera, and the capture output has to be configured as well.
// The reason for this mismatch is probably because most of the AVFoundation
// docs are written for iOS and not for MacOsX.
// AVVideoScalingModeKey() refers to letterboxing yes/no and preserve aspect
// ratio yes/no when scaling. Currently we set cropping and preservation.
NSDictionary* videoSettingsDictionary = @{ NSDictionary* videoSettingsDictionary = @{
(id)kCVPixelBufferWidthKey : @(width), (id)kCVPixelBufferWidthKey : @(width),
(id)kCVPixelBufferHeightKey : @(height), (id)kCVPixelBufferHeightKey : @(height),
......
...@@ -190,7 +190,8 @@ void VideoCaptureDeviceMac::AllocateAndStart( ...@@ -190,7 +190,8 @@ void VideoCaptureDeviceMac::AllocateAndStart(
// QTKit API can scale captured frame to any size requested, which would lead // 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 // to undesired aspect ratio changes. Try to open the camera with a known
// supported format and let the client crop/pad the captured frames. // supported format and let the client crop/pad the captured frames.
GetBestMatchSupportedResolution(&width, &height); if (!AVFoundationGlue::IsAVFoundationSupported())
GetBestMatchSupportedResolution(&width, &height);
client_ = client.Pass(); client_ = client.Pass();
NSString* deviceId = NSString* deviceId =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment