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

Side by Side Diff: media/video/capture/mac/video_capture_device_avfoundation_mac.mm

Issue 258783007: Mac AVFoundation: Allow use of all camera's supported resolutions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bemasc@ nit Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h" 5 #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h"
6 6
7 #import <CoreVideo/CoreVideo.h> 7 #import <CoreVideo/CoreVideo.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // VideoCaptureDeviceMac::ReceiveFrame() is calling here, depending on the 168 // VideoCaptureDeviceMac::ReceiveFrame() is calling here, depending on the
169 // running state. VCDM::ReceiveFrame() calls here to change aspect ratio. 169 // running state. VCDM::ReceiveFrame() calls here to change aspect ratio.
170 DCHECK((![captureSession_ isRunning] && 170 DCHECK((![captureSession_ isRunning] &&
171 main_thread_checker_.CalledOnValidThread()) || 171 main_thread_checker_.CalledOnValidThread()) ||
172 callback_thread_checker_.CalledOnValidThread()); 172 callback_thread_checker_.CalledOnValidThread());
173 173
174 frameWidth_ = width; 174 frameWidth_ = width;
175 frameHeight_ = height; 175 frameHeight_ = height;
176 frameRate_ = frameRate; 176 frameRate_ = frameRate;
177 177
178 // Identify the sessionPreset that corresponds to the desired resolution. 178 // The capture output has to be configured, despite Mac documentation
179 NSString* sessionPreset; 179 // detailing that setting the sessionPreset would be enough. The reason for
180 if (width == 1280 && height == 720 && [captureSession_ canSetSessionPreset: 180 // this mismatch is probably because most of the AVFoundation docs are written
181 AVFoundationGlue::AVCaptureSessionPreset1280x720()]) { 181 // for iOS and not for MacOsX. AVVideoScalingModeKey() refers to letterboxing
182 sessionPreset = AVFoundationGlue::AVCaptureSessionPreset1280x720(); 182 // yes/no and preserve aspect ratio yes/no when scaling. Currently we set
183 } else if (width == 640 && height == 480 && [captureSession_ 183 // cropping and preservation.
184 canSetSessionPreset:
185 AVFoundationGlue::AVCaptureSessionPreset640x480()]) {
186 sessionPreset = AVFoundationGlue::AVCaptureSessionPreset640x480();
187 } else if (width == 320 && height == 240 && [captureSession_
188 canSetSessionPreset:
189 AVFoundationGlue::AVCaptureSessionPreset320x240()]) {
190 sessionPreset = AVFoundationGlue::AVCaptureSessionPreset320x240();
191 } else {
192 DLOG(ERROR) << "Unsupported resolution (" << width << "x" << height << ")";
193 return NO;
194 }
195 [captureSession_ setSessionPreset:sessionPreset];
196
197 // Check that our capture Device can be used with the current preset.
198 if (![captureDevice_ supportsAVCaptureSessionPreset:
199 [captureSession_ sessionPreset]]){
200 DLOG(ERROR) << "Video capture device does not support current preset";
201 return NO;
202 }
203
204 // Despite all Mac documentation detailing that setting the sessionPreset is
205 // enough, that is not the case for, at least, the MacBook Air built-in
206 // FaceTime HD Camera, and the capture output has to be configured as well.
207 // The reason for this mismatch is probably because most of the AVFoundation
208 // docs are written for iOS and not for MacOsX.
209 // AVVideoScalingModeKey() refers to letterboxing yes/no and preserve aspect
210 // ratio yes/no when scaling. Currently we set cropping and preservation.
211 NSDictionary* videoSettingsDictionary = @{ 184 NSDictionary* videoSettingsDictionary = @{
212 (id)kCVPixelBufferWidthKey : @(width), 185 (id)kCVPixelBufferWidthKey : @(width),
213 (id)kCVPixelBufferHeightKey : @(height), 186 (id)kCVPixelBufferHeightKey : @(height),
214 (id)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_422YpCbCr8), 187 (id)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_422YpCbCr8),
215 AVFoundationGlue::AVVideoScalingModeKey() : 188 AVFoundationGlue::AVVideoScalingModeKey() :
216 AVFoundationGlue::AVVideoScalingModeResizeAspectFill() 189 AVFoundationGlue::AVVideoScalingModeResizeAspectFill()
217 }; 190 };
218 [captureVideoDataOutput_ setVideoSettings:videoSettingsDictionary]; 191 [captureVideoDataOutput_ setVideoSettings:videoSettingsDictionary];
219 192
220 CrAVCaptureConnection* captureConnection = [captureVideoDataOutput_ 193 CrAVCaptureConnection* captureConnection = [captureVideoDataOutput_
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 [NSString stringWithFormat:@"%@: %@", 274 [NSString stringWithFormat:@"%@: %@",
302 [error localizedDescription], 275 [error localizedDescription],
303 [error localizedFailureReason]]; 276 [error localizedFailureReason]];
304 277
305 base::AutoLock lock(lock_); 278 base::AutoLock lock(lock_);
306 if (frameReceiver_) 279 if (frameReceiver_)
307 frameReceiver_->ReceiveError([str_error UTF8String]); 280 frameReceiver_->ReceiveError([str_error UTF8String]);
308 } 281 }
309 282
310 @end 283 @end
OLDNEW
« no previous file with comments | « media/video/capture/mac/avfoundation_glue.mm ('k') | media/video/capture/mac/video_capture_device_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698