| Index: webrtc/sdk/objc/Framework/Classes/RTCCameraVideoCapturer.m
|
| diff --git a/webrtc/sdk/objc/Framework/Classes/RTCCameraVideoCapturer.m b/webrtc/sdk/objc/Framework/Classes/RTCCameraVideoCapturer.m
|
| index 16ddc13c9eaba1f5aaf42176a66c5444a4740e3e..de092e6da4ec5bd4837b31154c8751dce990ea13 100644
|
| --- a/webrtc/sdk/objc/Framework/Classes/RTCCameraVideoCapturer.m
|
| +++ b/webrtc/sdk/objc/Framework/Classes/RTCCameraVideoCapturer.m
|
| @@ -27,22 +27,26 @@ static inline BOOL IsMediaSubTypeSupported(FourCharCode mediaSubType) {
|
| }
|
|
|
| @interface RTCCameraVideoCapturer ()<AVCaptureVideoDataOutputSampleBufferDelegate>
|
| -@property(nonatomic, readonly) dispatch_queue_t frameQueue;
|
| +@property(nonatomic, strong) AVCaptureVideoDataOutput *videoDataOutput;
|
| +@property(nonatomic, strong) AVCaptureDevice *currentDevice;
|
| +@property(nonatomic, strong) dispatch_queue_t frameQueue;
|
| +@property(nonatomic, assign) RTCVideoRotation rotation;
|
| +// Will the session be running once all asynchronous operations have been completed?
|
| +@property(nonatomic, assign) BOOL willBeRunning;
|
| +
|
| @end
|
|
|
| @implementation RTCCameraVideoCapturer {
|
| - AVCaptureVideoDataOutput *_videoDataOutput;
|
| - AVCaptureSession *_captureSession;
|
| - AVCaptureDevice *_currentDevice;
|
| - RTCVideoRotation _rotation;
|
| BOOL _hasRetriedOnFatalError;
|
| BOOL _isRunning;
|
| - // Will the session be running once all asynchronous operations have been completed?
|
| - BOOL _willBeRunning;
|
| }
|
|
|
| -@synthesize frameQueue = _frameQueue;
|
| @synthesize captureSession = _captureSession;
|
| +@synthesize currentDevice = _currentDevice;
|
| +@synthesize frameQueue = _frameQueue;
|
| +@synthesize rotation = _rotation;
|
| +@synthesize videoDataOutput = _videoDataOutput;
|
| +@synthesize willBeRunning = _willBeRunning;
|
|
|
| - (instancetype)initWithDelegate:(__weak id<RTCVideoCapturerDelegate>)delegate {
|
| if (self = [super initWithDelegate:delegate]) {
|
| @@ -121,28 +125,10 @@ static inline BOOL IsMediaSubTypeSupported(FourCharCode mediaSubType) {
|
| dispatchAsyncOnType:RTCDispatcherTypeCaptureSession
|
| block:^{
|
| RTCLogInfo("startCaptureWithDevice %@ @ %d fps", format, fps);
|
| -
|
| #if TARGET_OS_IPHONE
|
| [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
|
| #endif
|
| -
|
| - _currentDevice = device;
|
| -
|
| - NSError *error = nil;
|
| - if ([_currentDevice lockForConfiguration:&error]) {
|
| - [self updateDeviceCaptureFormat:format fps:fps];
|
| - } else {
|
| - RTCLogError(@"Failed to lock device %@. Error: %@", _currentDevice,
|
| - error.userInfo);
|
| - return;
|
| - }
|
| -
|
| - [self reconfigureCaptureSessionInput];
|
| - [self updateOrientation];
|
| - [_captureSession startRunning];
|
| -
|
| - [_currentDevice unlockForConfiguration];
|
| - _isRunning = true;
|
| + _isRunning = [self tryStartCaptureWithDevice:device format:format fps:fps];
|
| }];
|
| }
|
|
|
| @@ -360,6 +346,27 @@ static inline BOOL IsMediaSubTypeSupported(FourCharCode mediaSubType) {
|
|
|
| #pragma mark - Private, called inside capture queue
|
|
|
| +- (BOOL)tryStartCaptureWithDevice:(AVCaptureDevice *)device
|
| + format:(AVCaptureDeviceFormat *)format
|
| + fps:(int)fps {
|
| + _currentDevice = device;
|
| +
|
| + NSError *error = nil;
|
| + if ([_currentDevice lockForConfiguration:&error]) {
|
| + [self updateDeviceCaptureFormat:format fps:fps];
|
| + } else {
|
| + RTCLogError(@"Failed to lock device %@. Error: %@", _currentDevice, error.userInfo);
|
| + return NO;
|
| + }
|
| +
|
| + [self reconfigureCaptureSessionInput];
|
| + [self updateOrientation];
|
| + [_captureSession startRunning];
|
| +
|
| + [_currentDevice unlockForConfiguration];
|
| + return YES;
|
| +}
|
| +
|
| - (void)updateDeviceCaptureFormat:(AVCaptureDeviceFormat *)format fps:(int)fps {
|
| @try {
|
| _currentDevice.activeFormat = format;
|
| @@ -392,8 +399,14 @@ static inline BOOL IsMediaSubTypeSupported(FourCharCode mediaSubType) {
|
|
|
| - (void)updateOrientation {
|
| #if TARGET_OS_IPHONE
|
| + [self updateOrientation:[UIDevice currentDevice].orientation];
|
| +#endif
|
| +}
|
| +
|
| +#if TARGET_OS_IPHONE
|
| +- (void)updateOrientation:(UIDeviceOrientation)orientation {
|
| BOOL usingFrontCamera = _currentDevice.position == AVCaptureDevicePositionFront;
|
| - switch ([UIDevice currentDevice].orientation) {
|
| + switch (orientation) {
|
| case UIDeviceOrientationPortrait:
|
| _rotation = RTCVideoRotation_90;
|
| break;
|
| @@ -412,7 +425,7 @@ static inline BOOL IsMediaSubTypeSupported(FourCharCode mediaSubType) {
|
| // Ignore.
|
| break;
|
| }
|
| -#endif
|
| }
|
| +#endif
|
|
|
| @end
|
|
|