Chromium Code Reviews| Index: webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm |
| diff --git a/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm b/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm |
| index 0d510fb26d899fe44160dbf9fa84997fd456620e..677d8749f652b59308ebee8d51ba1e05a308c6d4 100644 |
| --- a/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm |
| +++ b/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm |
| @@ -12,7 +12,9 @@ |
| #import <AVFoundation/AVFoundation.h> |
| #import <Foundation/Foundation.h> |
| +#if TARGET_OS_IPHONE |
| #import <UIKit/UIKit.h> |
| +#endif |
| #import "RTCDispatcher+Private.h" |
| #import "WebRTC/RTCLogging.h" |
| @@ -88,6 +90,7 @@ - (instancetype)initWithCapturer:(webrtc::AVFoundationVideoCapturer *)capturer { |
| return nil; |
| } |
| NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; |
| +#if TARGET_OS_IPHONE |
| [center addObserver:self |
| selector:@selector(deviceOrientationDidChange:) |
| name:UIDeviceOrientationDidChangeNotification |
| @@ -100,6 +103,7 @@ - (instancetype)initWithCapturer:(webrtc::AVFoundationVideoCapturer *)capturer { |
| selector:@selector(handleCaptureSessionInterruptionEnded:) |
| name:AVCaptureSessionInterruptionEndedNotification |
| object:_captureSession]; |
| +#endif |
| [center addObserver:self |
| selector:@selector(handleCaptureSessionRuntimeError:) |
| name:AVCaptureSessionRuntimeErrorNotification |
| @@ -188,7 +192,9 @@ - (void)start { |
| block:^{ |
| _orientationHasChanged = NO; |
| [self updateOrientation]; |
| +#if TARGET_OS_IPHONE |
| [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; |
| +#endif |
| AVCaptureSession *captureSession = self.captureSession; |
| [captureSession startRunning]; |
| }]; |
| @@ -207,12 +213,15 @@ - (void)stop { |
| block:^{ |
| [_videoDataOutput setSampleBufferDelegate:nil queue:nullptr]; |
| [_captureSession stopRunning]; |
| +#if TARGET_OS_IPHONE |
| [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; |
| +#endif |
| }]; |
| } |
| #pragma mark iOS notifications |
| +#if TARGET_OS_IPHONE |
| - (void)deviceOrientationDidChange:(NSNotification *)notification { |
| [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession |
| block:^{ |
| @@ -220,6 +229,7 @@ - (void)deviceOrientationDidChange:(NSNotification *)notification { |
| [self updateOrientation]; |
| }]; |
| } |
| +#endif |
| #pragma mark AVCaptureVideoDataOutputSampleBufferDelegate |
| @@ -273,16 +283,21 @@ - (void)handleCaptureSessionInterruptionEnded:(NSNotification *)notification { |
| } |
| - (void)handleCaptureSessionRuntimeError:(NSNotification *)notification { |
| - NSError *error = notification.userInfo[AVCaptureSessionErrorKey]; |
| + NSError *error = |
| + [notification.userInfo objectForKey: AVCaptureSessionErrorKey]; |
|
tkchin_webrtc
2016/06/08 21:35:55
nit: indent, and no space after :
it should be 6
|
| RTCLogError(@"Capture session runtime error: %@", error.localizedDescription); |
| [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession |
| block:^{ |
| +#if TARGET_OS_IPHONE |
| if (error.code == AVErrorMediaServicesWereReset) { |
| [self handleNonFatalError]; |
| } else { |
| [self handleFatalError]; |
| } |
| +#else |
| + [self handleFatalError]; |
| +#endif |
| }]; |
| } |
| @@ -402,8 +417,13 @@ - (AVCaptureDevice *)videoCaptureDeviceForPosition: |
| - (AVCaptureDeviceInput *)frontCameraInput { |
| if (!_frontCameraInput) { |
| +#if TARGET_OS_IPHONE |
| AVCaptureDevice *frontCameraDevice = |
| [self videoCaptureDeviceForPosition:AVCaptureDevicePositionFront]; |
| +#else |
| + AVCaptureDevice *frontCameraDevice = |
| + [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo];; |
| +#endif |
| if (!frontCameraDevice) { |
| RTCLogWarning(@"Failed to find front capture device."); |
| return nil; |
| @@ -453,6 +473,7 @@ - (void)updateOrientation { |
| return; |
| } |
| AVCaptureVideoOrientation orientation = AVCaptureVideoOrientationPortrait; |
|
tkchin_webrtc
2016/06/08 21:35:55
Technically this shouldn't get called at all, but
|
| +#if TARGET_OS_IPHONE |
| switch ([UIDevice currentDevice].orientation) { |
| case UIDeviceOrientationPortrait: |
| orientation = AVCaptureVideoOrientationPortrait; |
| @@ -474,6 +495,7 @@ - (void)updateOrientation { |
| } |
| return; |
| } |
| +#endif |
| connection.videoOrientation = orientation; |
| } |