From 22d43f335227c126dcb13e532af2c1f00f9cb18d Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Fri, 17 Nov 2017 15:57:05 +0100 Subject: [PATCH] =?UTF-8?q?iOS:=20Don=E2=80=99t=20change=20video=20rotatio?= =?UTF-8?q?n=20in=20FaceUp=20or=20FaceDown.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, if using the device in landscape and then tilting the phone into FaceUp orientation, the video rotation would reset to portrait. Bug: webrtc:8492 Change-Id: I3e11e3adecabf99249ba3a8d5532291580a93f2e Reviewed-on: https://webrtc-review.googlesource.com/24021 Reviewed-by: Kári Helgason Commit-Queue: Kári Helgason Cr-Commit-Position: refs/heads/master@{#20792} --- .../PeerConnection/RTCCameraVideoCapturer.m | 15 ++++++++------- .../Framework/Classes/UI/RTCCameraPreviewView.m | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCCameraVideoCapturer.m b/sdk/objc/Framework/Classes/PeerConnection/RTCCameraVideoCapturer.m index 17aa6cc42e..86eda60189 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCCameraVideoCapturer.m +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCCameraVideoCapturer.m @@ -37,6 +37,7 @@ const int64_t kNanosecondsPerSecond = 1000000000; BOOL _isRunning; // Will the session be running once all asynchronous operations have been completed? BOOL _willBeRunning; + RTCVideoRotation _rotation; #if TARGET_OS_IPHONE UIDeviceOrientation _orientation; #endif @@ -57,6 +58,7 @@ const int64_t kNanosecondsPerSecond = 1000000000; NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; #if TARGET_OS_IPHONE _orientation = UIDeviceOrientationPortrait; + _rotation = RTCVideoRotation_90; [center addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification @@ -191,7 +193,6 @@ const int64_t kNanosecondsPerSecond = 1000000000; #if TARGET_OS_IPHONE // Default to portrait orientation on iPhone. - RTCVideoRotation rotation = RTCVideoRotation_90; BOOL usingFrontCamera = NO; // Check the image's EXIF for the camera the image came from as the image could have been // delayed as we set alwaysDiscardsLateVideoFrames to NO. @@ -206,16 +207,16 @@ const int64_t kNanosecondsPerSecond = 1000000000; } switch (_orientation) { case UIDeviceOrientationPortrait: - rotation = RTCVideoRotation_90; + _rotation = RTCVideoRotation_90; break; case UIDeviceOrientationPortraitUpsideDown: - rotation = RTCVideoRotation_270; + _rotation = RTCVideoRotation_270; break; case UIDeviceOrientationLandscapeLeft: - rotation = usingFrontCamera ? RTCVideoRotation_180 : RTCVideoRotation_0; + _rotation = usingFrontCamera ? RTCVideoRotation_180 : RTCVideoRotation_0; break; case UIDeviceOrientationLandscapeRight: - rotation = usingFrontCamera ? RTCVideoRotation_0 : RTCVideoRotation_180; + _rotation = usingFrontCamera ? RTCVideoRotation_0 : RTCVideoRotation_180; break; case UIDeviceOrientationFaceUp: case UIDeviceOrientationFaceDown: @@ -225,14 +226,14 @@ const int64_t kNanosecondsPerSecond = 1000000000; } #else // No rotation on Mac. - RTCVideoRotation rotation = RTCVideoRotation_0; + _rotation = RTCVideoRotation_0; #endif RTCCVPixelBuffer *rtcPixelBuffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBuffer]; int64_t timeStampNs = CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) * kNanosecondsPerSecond; RTCVideoFrame *videoFrame = [[RTCVideoFrame alloc] initWithBuffer:rtcPixelBuffer - rotation:rotation + rotation:_rotation timeStampNs:timeStampNs]; [self.delegate capturer:self didCaptureVideoFrame:videoFrame]; } diff --git a/sdk/objc/Framework/Classes/UI/RTCCameraPreviewView.m b/sdk/objc/Framework/Classes/UI/RTCCameraPreviewView.m index 2b31e107a8..492c210af0 100644 --- a/sdk/objc/Framework/Classes/UI/RTCCameraPreviewView.m +++ b/sdk/objc/Framework/Classes/UI/RTCCameraPreviewView.m @@ -90,10 +90,11 @@ } else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft) { previewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft; - } else { + } else if (deviceOrientation == UIInterfaceOrientationPortrait) { previewLayer.connection.videoOrientation = AVCaptureVideoOrientationPortrait; } + // If device orientation switches to FaceUp or FaceDown, don't change video orientation. } }