OLD | NEW |
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/capture/video/mac/video_capture_device_avfoundation_mac.h" | 5 #import "media/capture/video/mac/video_capture_device_avfoundation_mac.h" |
6 | 6 |
7 #import <AVFoundation/AVFoundation.h> | 7 #import <AVFoundation/AVFoundation.h> |
8 #import <CoreMedia/CoreMedia.h> | 8 #import <CoreMedia/CoreMedia.h> |
9 #import <CoreVideo/CoreVideo.h> | 9 #import <CoreVideo/CoreVideo.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 captureDevice_ = nil; | 254 captureDevice_ = nil; |
255 [self sendErrorString: | 255 [self sendErrorString: |
256 [NSString stringWithFormat: | 256 [NSString stringWithFormat: |
257 @"Could not create video capture input (%@): %@", | 257 @"Could not create video capture input (%@): %@", |
258 [error localizedDescription], | 258 [error localizedDescription], |
259 [error localizedFailureReason]]]; | 259 [error localizedFailureReason]]]; |
260 return NO; | 260 return NO; |
261 } | 261 } |
262 [captureSession_ addInput:captureDeviceInput_]; | 262 [captureSession_ addInput:captureDeviceInput_]; |
263 | 263 |
| 264 // Create and plug the still image capture output. This should happen in |
| 265 // advance of the actual picture to allow for the 3A to stabilize. |
| 266 stillImageOutput_.reset([[AVCaptureStillImageOutput alloc] init]); |
| 267 if (stillImageOutput_ && [captureSession_ canAddOutput:stillImageOutput_]) |
| 268 [captureSession_ addOutput:stillImageOutput_]; |
| 269 |
264 // Create a new data output for video. The data output is configured to | 270 // Create a new data output for video. The data output is configured to |
265 // discard late frames by default. | 271 // discard late frames by default. |
266 captureVideoDataOutput_.reset([[AVCaptureVideoDataOutput alloc] init]); | 272 captureVideoDataOutput_.reset([[AVCaptureVideoDataOutput alloc] init]); |
267 if (!captureVideoDataOutput_) { | 273 if (!captureVideoDataOutput_) { |
268 [captureSession_ removeInput:captureDeviceInput_]; | 274 [captureSession_ removeInput:captureDeviceInput_]; |
269 [self sendErrorString:[NSString stringWithUTF8String: | 275 [self sendErrorString:[NSString stringWithUTF8String: |
270 "Could not create video data output."]]; | 276 "Could not create video data output."]]; |
271 return NO; | 277 return NO; |
272 } | 278 } |
273 [captureVideoDataOutput_ setAlwaysDiscardsLateVideoFrames:true]; | 279 [captureVideoDataOutput_ setAlwaysDiscardsLateVideoFrames:true]; |
274 [captureVideoDataOutput_ | 280 [captureVideoDataOutput_ |
275 setSampleBufferDelegate:self | 281 setSampleBufferDelegate:self |
276 queue:dispatch_get_global_queue( | 282 queue:dispatch_get_global_queue( |
277 DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; | 283 DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; |
278 [captureSession_ addOutput:captureVideoDataOutput_]; | 284 [captureSession_ addOutput:captureVideoDataOutput_]; |
279 | 285 |
280 // Create and plug the still image capture output. This should happen in | |
281 // advance of the actual picture to allow for the 3A to stabilize. | |
282 stillImageOutput_.reset([[AVCaptureStillImageOutput alloc] init]); | |
283 if (stillImageOutput_ && [captureSession_ canAddOutput:stillImageOutput_]) | |
284 [captureSession_ addOutput:stillImageOutput_]; | |
285 | |
286 return YES; | 286 return YES; |
287 } | 287 } |
288 | 288 |
289 - (BOOL)setCaptureHeight:(int)height | 289 - (BOOL)setCaptureHeight:(int)height |
290 width:(int)width | 290 width:(int)width |
291 frameRate:(float)frameRate { | 291 frameRate:(float)frameRate { |
292 DCHECK(![captureSession_ isRunning] && | 292 DCHECK(![captureSession_ isRunning] && |
293 main_thread_checker_.CalledOnValidThread()); | 293 main_thread_checker_.CalledOnValidThread()); |
294 | 294 |
295 frameWidth_ = width; | 295 frameWidth_ = width; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 } | 490 } |
491 | 491 |
492 - (void)sendErrorString:(NSString*)error { | 492 - (void)sendErrorString:(NSString*)error { |
493 DLOG(ERROR) << [error UTF8String]; | 493 DLOG(ERROR) << [error UTF8String]; |
494 base::AutoLock lock(lock_); | 494 base::AutoLock lock(lock_); |
495 if (frameReceiver_) | 495 if (frameReceiver_) |
496 frameReceiver_->ReceiveError(FROM_HERE, [error UTF8String]); | 496 frameReceiver_->ReceiveError(FROM_HERE, [error UTF8String]); |
497 } | 497 } |
498 | 498 |
499 @end | 499 @end |
OLD | NEW |