Chromium Code Reviews| 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. |
| 92 - (void)start; | 92 - (void)start; |
| 93 - (void)stop; | 93 - (void)stop; |
| 94 | 94 |
| 95 @end | 95 @end |
| 96 | 96 |
| 97 @implementation RTCAVFoundationVideoCapturerInternal { | 97 @implementation RTCAVFoundationVideoCapturerInternal { |
| 98 // Keep pointers to inputs for convenience. | 98 // Keep pointers to inputs for convenience. |
| 99 AVCaptureDeviceInput *_frontCameraInput; | 99 AVCaptureDeviceInput *_frontCameraInput; |
| 100 AVCaptureDeviceInput *_backCameraInput; | 100 AVCaptureDeviceInput *_backCameraInput; |
| 101 AVCaptureVideoDataOutput *_videoDataOutput; | 101 AVCaptureVideoDataOutput *_videoDataOutput; |
| 102 // The cricket::VideoCapturer that owns this class. Should never be NULL. | 102 // The cricket::VideoCapturer that owns this class. Should never be NULL. |
| 103 webrtc::AVFoundationVideoCapturer *_capturer; | 103 webrtc::AVFoundationVideoCapturer *_capturer; |
| 104 webrtc::VideoRotation _rotation; | 104 webrtc::VideoRotation _rotation; |
| 105 BOOL _hasRetriedOnFatalError; | 105 BOOL _hasRetriedOnFatalError; |
| 106 BOOL _isRunning; | |
| 107 BOOL _hasStarted; | 106 BOOL _hasStarted; |
| 108 rtc::CriticalSection _crit; | 107 rtc::CriticalSection _crit; |
| 109 } | 108 } |
| 110 | 109 |
| 111 @synthesize captureSession = _captureSession; | 110 @synthesize captureSession = _captureSession; |
| 112 @synthesize frameQueue = _frameQueue; | 111 @synthesize frameQueue = _frameQueue; |
| 113 @synthesize useBackCamera = _useBackCamera; | 112 @synthesize useBackCamera = _useBackCamera; |
| 114 @synthesize hasStarted = _hasStarted; | 113 @synthesize hasStarted = _hasStarted; |
|
magjed_webrtc
2016/09/28 13:56:36
So this @synthesize step isn't needed? Maybe remov
tkchin_webrtc
2016/09/28 14:17:37
The approach we've gone in this codebase is to exp
daniela-webrtc
2016/09/28 14:38:42
Can you elaborate a bit on this part? Wouldn't the
| |
| 115 | 114 |
| 116 // This is called from the thread that creates the video source, which is likely | 115 // This is called from the thread that creates the video source, which is likely |
| 117 // the main thread. | 116 // the main thread. |
| 118 - (instancetype)initWithCapturer:(webrtc::AVFoundationVideoCapturer *)capturer { | 117 - (instancetype)initWithCapturer:(webrtc::AVFoundationVideoCapturer *)capturer { |
| 119 RTC_DCHECK(capturer); | 118 RTC_DCHECK(capturer); |
| 120 if (self = [super init]) { | 119 if (self = [super init]) { |
| 121 _capturer = capturer; | 120 _capturer = capturer; |
| 122 // Create the capture session and all relevant inputs and outputs. We need | 121 // 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 | 122 // to do this in init because the application may want the capture session |
| 124 // before we start the capturer for e.g. AVCapturePreviewLayer. All objects | 123 // before we start the capturer for e.g. AVCapturePreviewLayer. All objects |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 } | 209 } |
| 211 @synchronized(self) { | 210 @synchronized(self) { |
| 212 if (_useBackCamera == useBackCamera) { | 211 if (_useBackCamera == useBackCamera) { |
| 213 return; | 212 return; |
| 214 } | 213 } |
| 215 _useBackCamera = useBackCamera; | 214 _useBackCamera = useBackCamera; |
| 216 [self updateSessionInputForUseBackCamera:useBackCamera]; | 215 [self updateSessionInputForUseBackCamera:useBackCamera]; |
| 217 } | 216 } |
| 218 } | 217 } |
| 219 | 218 |
| 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. | 219 // Called from WebRTC thread. |
| 231 - (void)start { | 220 - (void)start { |
| 232 if (self.hasStarted) { | 221 if (self.hasStarted) { |
| 233 return; | 222 return; |
| 234 } | 223 } |
| 235 self.hasStarted = YES; | 224 self.hasStarted = YES; |
| 236 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession | 225 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession |
| 237 block:^{ | 226 block:^{ |
| 238 #if TARGET_OS_IPHONE | 227 #if TARGET_OS_IPHONE |
| 239 // Default to portrait orientation on iPhone. This will be reset in | 228 // 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]; | 336 [self handleFatalError]; |
| 348 } | 337 } |
| 349 #else | 338 #else |
| 350 [self handleFatalError]; | 339 [self handleFatalError]; |
| 351 #endif | 340 #endif |
| 352 }]; | 341 }]; |
| 353 } | 342 } |
| 354 | 343 |
| 355 - (void)handleCaptureSessionDidStartRunning:(NSNotification *)notification { | 344 - (void)handleCaptureSessionDidStartRunning:(NSNotification *)notification { |
| 356 RTCLog(@"Capture session started."); | 345 RTCLog(@"Capture session started."); |
| 346 | |
| 357 self.isRunning = YES; | 347 self.isRunning = YES; |
| 358 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession | 348 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession |
| 359 block:^{ | 349 block:^{ |
| 360 // If we successfully restarted after an unknown error, allow future | 350 // If we successfully restarted after an unknown error, allow future |
| 361 // retries on fatal errors. | 351 // retries on fatal errors. |
| 362 _hasRetriedOnFatalError = NO; | 352 _hasRetriedOnFatalError = NO; |
| 363 }]; | 353 }]; |
| 364 } | 354 } |
| 365 | 355 |
| 366 - (void)handleCaptureSessionDidStopRunning:(NSNotification *)notification { | 356 - (void)handleCaptureSessionDidStopRunning:(NSNotification *)notification { |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 756 buffer = rotated_buffer; | 746 buffer = rotated_buffer; |
| 757 } | 747 } |
| 758 } | 748 } |
| 759 | 749 |
| 760 OnFrame(cricket::WebRtcVideoFrame(buffer, rotation, | 750 OnFrame(cricket::WebRtcVideoFrame(buffer, rotation, |
| 761 translated_camera_time_us, 0), | 751 translated_camera_time_us, 0), |
| 762 captured_width, captured_height); | 752 captured_width, captured_height); |
| 763 } | 753 } |
| 764 | 754 |
| 765 } // namespace webrtc | 755 } // namespace webrtc |
| OLD | NEW |