Chromium Code Reviews| 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 <CoreMedia/CoreMedia.h> | 7 #import <CoreMedia/CoreMedia.h> |
| 8 #import <CoreVideo/CoreVideo.h> | 8 #import <CoreVideo/CoreVideo.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 setSampleBufferDelegate:self | 244 setSampleBufferDelegate:self |
| 245 queue:dispatch_get_global_queue( | 245 queue:dispatch_get_global_queue( |
| 246 DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; | 246 DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; |
| 247 [captureSession_ addOutput:captureVideoDataOutput_]; | 247 [captureSession_ addOutput:captureVideoDataOutput_]; |
| 248 return YES; | 248 return YES; |
| 249 } | 249 } |
| 250 | 250 |
| 251 - (BOOL)setCaptureHeight:(int)height | 251 - (BOOL)setCaptureHeight:(int)height |
| 252 width:(int)width | 252 width:(int)width |
| 253 frameRate:(float)frameRate { | 253 frameRate:(float)frameRate { |
| 254 // Check if either of VideoCaptureDeviceMac::AllocateAndStart() or | 254 DCHECK(![captureSession_ isRunning] && |
| 255 // VideoCaptureDeviceMac::ReceiveFrame() is calling here, depending on the | 255 main_thread_checker_.CalledOnValidThread()); |
| 256 // running state. VCDM::ReceiveFrame() calls here to change aspect ratio. | |
| 257 DCHECK((![captureSession_ isRunning] && | |
| 258 main_thread_checker_.CalledOnValidThread()) || | |
| 259 callback_thread_checker_.CalledOnValidThread()); | |
| 260 | 256 |
| 261 frameWidth_ = width; | 257 frameWidth_ = width; |
| 262 frameHeight_ = height; | 258 frameHeight_ = height; |
| 263 frameRate_ = frameRate; | 259 frameRate_ = frameRate; |
| 264 | 260 |
| 265 FourCharCode best_fourcc = kCVPixelFormatType_422YpCbCr8; | 261 FourCharCode best_fourcc = kCVPixelFormatType_422YpCbCr8; |
| 266 const bool prefer_mjpeg = | 262 const bool prefer_mjpeg = |
| 267 width > kMjpegWidthThreshold || height > kMjpegHeightThreshold; | 263 width > kMjpegWidthThreshold || height > kMjpegHeightThreshold; |
| 268 for (CrAVCaptureDeviceFormat* format in captureDevice_.formats) { | 264 for (CrAVCaptureDeviceFormat* format in captureDevice_.formats) { |
| 269 const FourCharCode fourcc = | 265 const FourCharCode fourcc = |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 - (void)stopCapture { | 339 - (void)stopCapture { |
| 344 DCHECK(main_thread_checker_.CalledOnValidThread()); | 340 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 345 if ([captureSession_ isRunning]) | 341 if ([captureSession_ isRunning]) |
| 346 [captureSession_ stopRunning]; // Synchronous. | 342 [captureSession_ stopRunning]; // Synchronous. |
| 347 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 343 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 348 } | 344 } |
| 349 | 345 |
| 350 #pragma mark Private methods | 346 #pragma mark Private methods |
| 351 | 347 |
| 352 // |captureOutput| is called by the capture device to deliver a new frame. | 348 // |captureOutput| is called by the capture device to deliver a new frame. |
| 349 // AVFoundation calls from a number of threads, depending on, at least, if | |
| 350 // Chrome is on foreground or background. | |
| 353 - (void)captureOutput:(CrAVCaptureOutput*)captureOutput | 351 - (void)captureOutput:(CrAVCaptureOutput*)captureOutput |
| 354 didOutputSampleBuffer:(CoreMediaGlue::CMSampleBufferRef)sampleBuffer | 352 didOutputSampleBuffer:(CoreMediaGlue::CMSampleBufferRef)sampleBuffer |
| 355 fromConnection:(CrAVCaptureConnection*)connection { | 353 fromConnection:(CrAVCaptureConnection*)connection { |
| 356 // AVFoundation calls from a number of threads, depending on, at least, if | |
| 357 // Chrome is on foreground or background. Sample the actual thread here. | |
| 358 callback_thread_checker_.DetachFromThread(); | |
| 359 CHECK(callback_thread_checker_.CalledOnValidThread()); | |
| 360 | 354 |
|
Robert Sesek
2016/04/01 18:56:09
nit: remove extra blank line
mcasas
2016/04/01 22:08:17
Done.
| |
| 361 const CoreMediaGlue::CMFormatDescriptionRef formatDescription = | 355 const CoreMediaGlue::CMFormatDescriptionRef formatDescription = |
| 362 CoreMediaGlue::CMSampleBufferGetFormatDescription(sampleBuffer); | 356 CoreMediaGlue::CMSampleBufferGetFormatDescription(sampleBuffer); |
| 363 const FourCharCode fourcc = | 357 const FourCharCode fourcc = |
| 364 CoreMediaGlue::CMFormatDescriptionGetMediaSubType(formatDescription); | 358 CoreMediaGlue::CMFormatDescriptionGetMediaSubType(formatDescription); |
| 365 const CoreMediaGlue::CMVideoDimensions dimensions = | 359 const CoreMediaGlue::CMVideoDimensions dimensions = |
| 366 CoreMediaGlue::CMVideoFormatDescriptionGetDimensions(formatDescription); | 360 CoreMediaGlue::CMVideoFormatDescriptionGetDimensions(formatDescription); |
| 367 const media::VideoCaptureFormat captureFormat( | 361 const media::VideoCaptureFormat captureFormat( |
| 368 gfx::Size(dimensions.width, dimensions.height), frameRate_, | 362 gfx::Size(dimensions.width, dimensions.height), frameRate_, |
| 369 FourCCToChromiumPixelFormat(fourcc)); | 363 FourCCToChromiumPixelFormat(fourcc)); |
| 370 | 364 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 } | 421 } |
| 428 | 422 |
| 429 - (void)sendErrorString:(NSString*)error { | 423 - (void)sendErrorString:(NSString*)error { |
| 430 DLOG(ERROR) << [error UTF8String]; | 424 DLOG(ERROR) << [error UTF8String]; |
| 431 base::AutoLock lock(lock_); | 425 base::AutoLock lock(lock_); |
| 432 if (frameReceiver_) | 426 if (frameReceiver_) |
| 433 frameReceiver_->ReceiveError(FROM_HERE, [error UTF8String]); | 427 frameReceiver_->ReceiveError(FROM_HERE, [error UTF8String]); |
| 434 } | 428 } |
| 435 | 429 |
| 436 @end | 430 @end |
| OLD | NEW |