| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // to be owned by an instance of AVFoundationVideoCapturer. The reason for this | 71 // to be owned by an instance of AVFoundationVideoCapturer. The reason for this |
| 72 // because other webrtc objects own cricket::VideoCapturer, which is not | 72 // because other webrtc objects own cricket::VideoCapturer, which is not |
| 73 // ref counted. To prevent bad behavior we do not expose this class directly. | 73 // ref counted. To prevent bad behavior we do not expose this class directly. |
| 74 @interface RTCAVFoundationVideoCapturerInternal : NSObject | 74 @interface RTCAVFoundationVideoCapturerInternal : NSObject |
| 75 <AVCaptureVideoDataOutputSampleBufferDelegate> | 75 <AVCaptureVideoDataOutputSampleBufferDelegate> |
| 76 | 76 |
| 77 @property(nonatomic, readonly) AVCaptureSession *captureSession; | 77 @property(nonatomic, readonly) AVCaptureSession *captureSession; |
| 78 @property(nonatomic, readonly) dispatch_queue_t frameQueue; | 78 @property(nonatomic, readonly) dispatch_queue_t frameQueue; |
| 79 @property(nonatomic, readonly) BOOL canUseBackCamera; | 79 @property(nonatomic, readonly) BOOL canUseBackCamera; |
| 80 @property(nonatomic, assign) BOOL useBackCamera; // Defaults to NO. | 80 @property(nonatomic, assign) BOOL useBackCamera; // Defaults to NO. |
| 81 @property(nonatomic, assign) BOOL isRunning; // Whether the capture session is
running. | 81 @property(atomic, assign) BOOL isRunning; // Whether the capture session is run
ning. |
| 82 @property(atomic, assign) BOOL hasStarted; // Whether we have an unmatched star
t. | 82 @property(atomic, assign) BOOL hasStarted; // Whether we have an unmatched star
t. |
| 83 | 83 |
| 84 // We keep a pointer back to AVFoundationVideoCapturer to make callbacks on it | 84 // We keep a pointer back to AVFoundationVideoCapturer to make callbacks on it |
| 85 // when we receive frames. This is safe because this object should be owned by | 85 // when we receive frames. This is safe because this object should be owned by |
| 86 // it. | 86 // it. |
| 87 - (instancetype)initWithCapturer:(webrtc::AVFoundationVideoCapturer *)capturer; | 87 - (instancetype)initWithCapturer:(webrtc::AVFoundationVideoCapturer *)capturer; |
| 88 - (AVCaptureDevice *)getActiveCaptureDevice; | 88 - (AVCaptureDevice *)getActiveCaptureDevice; |
| 89 | 89 |
| 90 // Starts and stops the capture session asynchronously. We cannot do this | 90 // Starts and stops the capture session asynchronously. We cannot do this |
| 91 // synchronously without blocking a WebRTC thread. | 91 // synchronously without blocking a WebRTC thread. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 104 webrtc::VideoRotation _rotation; | 104 webrtc::VideoRotation _rotation; |
| 105 BOOL _hasRetriedOnFatalError; | 105 BOOL _hasRetriedOnFatalError; |
| 106 BOOL _isRunning; | 106 BOOL _isRunning; |
| 107 BOOL _hasStarted; | 107 BOOL _hasStarted; |
| 108 rtc::CriticalSection _crit; | 108 rtc::CriticalSection _crit; |
| 109 } | 109 } |
| 110 | 110 |
| 111 @synthesize captureSession = _captureSession; | 111 @synthesize captureSession = _captureSession; |
| 112 @synthesize frameQueue = _frameQueue; | 112 @synthesize frameQueue = _frameQueue; |
| 113 @synthesize useBackCamera = _useBackCamera; | 113 @synthesize useBackCamera = _useBackCamera; |
| 114 |
| 115 @synthesize isRunning = _isRunning; |
| 114 @synthesize hasStarted = _hasStarted; | 116 @synthesize hasStarted = _hasStarted; |
| 115 | 117 |
| 116 // This is called from the thread that creates the video source, which is likely | 118 // This is called from the thread that creates the video source, which is likely |
| 117 // the main thread. | 119 // the main thread. |
| 118 - (instancetype)initWithCapturer:(webrtc::AVFoundationVideoCapturer *)capturer { | 120 - (instancetype)initWithCapturer:(webrtc::AVFoundationVideoCapturer *)capturer { |
| 119 RTC_DCHECK(capturer); | 121 RTC_DCHECK(capturer); |
| 120 if (self = [super init]) { | 122 if (self = [super init]) { |
| 121 _capturer = capturer; | 123 _capturer = capturer; |
| 122 // Create the capture session and all relevant inputs and outputs. We need | 124 // Create the capture session and all relevant inputs and outputs. We need |
| 123 // to do this in init because the application may want the capture session | 125 // to do this in init because the application may want the capture session |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 } | 212 } |
| 211 @synchronized(self) { | 213 @synchronized(self) { |
| 212 if (_useBackCamera == useBackCamera) { | 214 if (_useBackCamera == useBackCamera) { |
| 213 return; | 215 return; |
| 214 } | 216 } |
| 215 _useBackCamera = useBackCamera; | 217 _useBackCamera = useBackCamera; |
| 216 [self updateSessionInputForUseBackCamera:useBackCamera]; | 218 [self updateSessionInputForUseBackCamera:useBackCamera]; |
| 217 } | 219 } |
| 218 } | 220 } |
| 219 | 221 |
| 220 - (BOOL)isRunning { | |
| 221 rtc::CritScope cs(&_crit); | |
| 222 return _isRunning; | |
| 223 } | |
| 224 | |
| 225 - (void)setIsRunning:(BOOL)isRunning { | |
| 226 rtc::CritScope cs(&_crit); | |
| 227 _isRunning = isRunning; | |
| 228 } | |
| 229 | |
| 230 // Called from WebRTC thread. | 222 // Called from WebRTC thread. |
| 231 - (void)start { | 223 - (void)start { |
| 232 if (self.hasStarted) { | 224 if (self.hasStarted) { |
| 233 return; | 225 return; |
| 234 } | 226 } |
| 235 self.hasStarted = YES; | 227 self.hasStarted = YES; |
| 236 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession | 228 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession |
| 237 block:^{ | 229 block:^{ |
| 238 #if TARGET_OS_IPHONE | 230 #if TARGET_OS_IPHONE |
| 239 // Default to portrait orientation on iPhone. This will be reset in | 231 // Default to portrait orientation on iPhone. This will be reset in |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 [self handleFatalError]; | 339 [self handleFatalError]; |
| 348 } | 340 } |
| 349 #else | 341 #else |
| 350 [self handleFatalError]; | 342 [self handleFatalError]; |
| 351 #endif | 343 #endif |
| 352 }]; | 344 }]; |
| 353 } | 345 } |
| 354 | 346 |
| 355 - (void)handleCaptureSessionDidStartRunning:(NSNotification *)notification { | 347 - (void)handleCaptureSessionDidStartRunning:(NSNotification *)notification { |
| 356 RTCLog(@"Capture session started."); | 348 RTCLog(@"Capture session started."); |
| 349 |
| 357 self.isRunning = YES; | 350 self.isRunning = YES; |
| 358 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession | 351 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession |
| 359 block:^{ | 352 block:^{ |
| 360 // If we successfully restarted after an unknown error, allow future | 353 // If we successfully restarted after an unknown error, allow future |
| 361 // retries on fatal errors. | 354 // retries on fatal errors. |
| 362 _hasRetriedOnFatalError = NO; | 355 _hasRetriedOnFatalError = NO; |
| 363 }]; | 356 }]; |
| 364 } | 357 } |
| 365 | 358 |
| 366 - (void)handleCaptureSessionDidStopRunning:(NSNotification *)notification { | 359 - (void)handleCaptureSessionDidStopRunning:(NSNotification *)notification { |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 buffer = rotated_buffer; | 749 buffer = rotated_buffer; |
| 757 } | 750 } |
| 758 } | 751 } |
| 759 | 752 |
| 760 OnFrame(cricket::WebRtcVideoFrame(buffer, rotation, | 753 OnFrame(cricket::WebRtcVideoFrame(buffer, rotation, |
| 761 translated_camera_time_us, 0), | 754 translated_camera_time_us, 0), |
| 762 captured_width, captured_height); | 755 captured_width, captured_height); |
| 763 } | 756 } |
| 764 | 757 |
| 765 } // namespace webrtc | 758 } // namespace webrtc |
| OLD | NEW |