OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_420YpCbCr8BiPlanarFu
llRange) | 354 kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_420YpCbCr8BiPlanarFu
llRange) |
355 }; | 355 }; |
356 videoDataOutput.alwaysDiscardsLateVideoFrames = NO; | 356 videoDataOutput.alwaysDiscardsLateVideoFrames = NO; |
357 [videoDataOutput setSampleBufferDelegate:self queue:self.frameQueue]; | 357 [videoDataOutput setSampleBufferDelegate:self queue:self.frameQueue]; |
358 _videoDataOutput = videoDataOutput; | 358 _videoDataOutput = videoDataOutput; |
359 } | 359 } |
360 | 360 |
361 #pragma mark - Private, called inside capture queue | 361 #pragma mark - Private, called inside capture queue |
362 | 362 |
363 - (void)updateDeviceCaptureFormat:(AVCaptureDeviceFormat *)format fps:(int)fps { | 363 - (void)updateDeviceCaptureFormat:(AVCaptureDeviceFormat *)format fps:(int)fps { |
| 364 NSAssert([RTCDispatcher isOnQueueForType:RTCDispatcherTypeCaptureSession], |
| 365 @"updateDeviceCaptureFormat must be called on the capture queue."); |
364 @try { | 366 @try { |
365 _currentDevice.activeFormat = format; | 367 _currentDevice.activeFormat = format; |
366 _currentDevice.activeVideoMinFrameDuration = CMTimeMake(1, fps); | 368 _currentDevice.activeVideoMinFrameDuration = CMTimeMake(1, fps); |
367 } @catch (NSException *exception) { | 369 } @catch (NSException *exception) { |
368 RTCLogError(@"Failed to set active format!\n User info:%@", exception.userIn
fo); | 370 RTCLogError(@"Failed to set active format!\n User info:%@", exception.userIn
fo); |
369 return; | 371 return; |
370 } | 372 } |
371 } | 373 } |
372 | 374 |
373 - (void)reconfigureCaptureSessionInput { | 375 - (void)reconfigureCaptureSessionInput { |
| 376 NSAssert([RTCDispatcher isOnQueueForType:RTCDispatcherTypeCaptureSession], |
| 377 @"reconfigureCaptureSessionInput must be called on the capture queue.
"); |
374 NSError *error = nil; | 378 NSError *error = nil; |
375 AVCaptureDeviceInput *input = | 379 AVCaptureDeviceInput *input = |
376 [AVCaptureDeviceInput deviceInputWithDevice:_currentDevice error:&error]; | 380 [AVCaptureDeviceInput deviceInputWithDevice:_currentDevice error:&error]; |
377 if (!input) { | 381 if (!input) { |
378 RTCLogError(@"Failed to create front camera input: %@", error.localizedDescr
iption); | 382 RTCLogError(@"Failed to create front camera input: %@", error.localizedDescr
iption); |
379 return; | 383 return; |
380 } | 384 } |
381 for (AVCaptureDeviceInput *oldInput in [_captureSession.inputs copy]) { | 385 for (AVCaptureDeviceInput *oldInput in [_captureSession.inputs copy]) { |
382 [_captureSession removeInput:oldInput]; | 386 [_captureSession removeInput:oldInput]; |
383 } | 387 } |
384 if ([_captureSession canAddInput:input]) { | 388 if ([_captureSession canAddInput:input]) { |
385 [_captureSession addInput:input]; | 389 [_captureSession addInput:input]; |
386 } else { | 390 } else { |
387 RTCLogError(@"Cannot add camera as an input to the session."); | 391 RTCLogError(@"Cannot add camera as an input to the session."); |
388 return; | 392 return; |
389 } | 393 } |
390 } | 394 } |
391 | 395 |
392 - (void)updateOrientation { | 396 - (void)updateOrientation { |
| 397 NSAssert([RTCDispatcher isOnQueueForType:RTCDispatcherTypeCaptureSession], |
| 398 @"updateOrientation must be called on the capture queue."); |
393 #if TARGET_OS_IPHONE | 399 #if TARGET_OS_IPHONE |
394 BOOL usingFrontCamera = _currentDevice.position == AVCaptureDevicePositionFron
t; | 400 BOOL usingFrontCamera = _currentDevice.position == AVCaptureDevicePositionFron
t; |
395 switch ([UIDevice currentDevice].orientation) { | 401 switch ([UIDevice currentDevice].orientation) { |
396 case UIDeviceOrientationPortrait: | 402 case UIDeviceOrientationPortrait: |
397 _rotation = RTCVideoRotation_90; | 403 _rotation = RTCVideoRotation_90; |
398 break; | 404 break; |
399 case UIDeviceOrientationPortraitUpsideDown: | 405 case UIDeviceOrientationPortraitUpsideDown: |
400 _rotation = RTCVideoRotation_270; | 406 _rotation = RTCVideoRotation_270; |
401 break; | 407 break; |
402 case UIDeviceOrientationLandscapeLeft: | 408 case UIDeviceOrientationLandscapeLeft: |
403 _rotation = usingFrontCamera ? RTCVideoRotation_180 : RTCVideoRotation_0; | 409 _rotation = usingFrontCamera ? RTCVideoRotation_180 : RTCVideoRotation_0; |
404 break; | 410 break; |
405 case UIDeviceOrientationLandscapeRight: | 411 case UIDeviceOrientationLandscapeRight: |
406 _rotation = usingFrontCamera ? RTCVideoRotation_0 : RTCVideoRotation_180; | 412 _rotation = usingFrontCamera ? RTCVideoRotation_0 : RTCVideoRotation_180; |
407 break; | 413 break; |
408 case UIDeviceOrientationFaceUp: | 414 case UIDeviceOrientationFaceUp: |
409 case UIDeviceOrientationFaceDown: | 415 case UIDeviceOrientationFaceDown: |
410 case UIDeviceOrientationUnknown: | 416 case UIDeviceOrientationUnknown: |
411 // Ignore. | 417 // Ignore. |
412 break; | 418 break; |
413 } | 419 } |
414 #endif | 420 #endif |
415 } | 421 } |
416 | 422 |
417 @end | 423 @end |
OLD | NEW |