diff --git a/Ring/Ring/Calls/CallViewModel.swift b/Ring/Ring/Calls/CallViewModel.swift index 55664bdace0577d8120408a326bf7542b863a52c..ddfabe25598e27f8add359dddf35c5c46d615a10 100644 --- a/Ring/Ring/Calls/CallViewModel.swift +++ b/Ring/Ring/Calls/CallViewModel.swift @@ -95,7 +95,7 @@ class CallViewModel: Stateable, ViewModel { return call.state == .over || call.state == .failure }).map({ hide in if hide { - self.videoService.setCameraOrientation(orientation: .portrait) + self.videoService.setCameraOrientation(orientation: UIDevice.current.orientation) } return hide }) @@ -281,6 +281,15 @@ class CallViewModel: Stateable, ViewModel { self.videoService = injectionBag.videoService self.audioService = injectionBag.audioService self.profileService = injectionBag.profileService + + callService.currentCall.filter({ [weak self] call in + return call.callId == self?.call?.callId + }).map({ call in + return call.state == .current + }).subscribe(onNext: { _ in + self.videoService.setCameraOrientation(orientation: UIDevice.current.orientation) + }).disposed(by: self.disposeBag) + } static func formattedDurationFrom(interval: Int) -> String { diff --git a/Ring/Ring/Services/VideoService.swift b/Ring/Ring/Services/VideoService.swift index 5a463508295a8a9513c67a2176a188d7a937449d..63938d7401796b2813eb7a4ed442e78de5819061 100644 --- a/Ring/Ring/Services/VideoService.swift +++ b/Ring/Ring/Services/VideoService.swift @@ -54,6 +54,9 @@ class FrameExtractor: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate { private let quality = AVCaptureSession.Preset.medium private var orientation = AVCaptureVideoOrientation.portrait + var getOrientation: AVCaptureVideoOrientation { + get { return orientation } + } var permissionGranted = Variable<Bool>(false) @@ -89,7 +92,8 @@ class FrameExtractor: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate { bestRate = frameRates.maxFrameRate } } - if orientation == .portrait || orientation == .portraitUpsideDown { + if orientation == .portrait || + orientation == .portraitUpsideDown { let devInfo: DeviceInfo = ["format": "BGRA", "width": String(dimensions.height), "height": String(dimensions.width), @@ -327,11 +331,6 @@ class VideoService: FrameExtractorDelegate { } func setCameraOrientation(orientation: UIDeviceOrientation) { - self.blockOutgoingFrame = true - let deviceName: String = - (orientation == .landscapeLeft || orientation == .landscapeRight) ? - self.camera.nameLandscape : self.camera.namePortrait - self.switchInput(toDevice: self.camera.nameCamera + deviceName) var newOrientation: AVCaptureVideoOrientation switch orientation { case .portrait: @@ -345,9 +344,18 @@ class VideoService: FrameExtractorDelegate { default: newOrientation = AVCaptureVideoOrientation.portrait } + if newOrientation == camera.getOrientation { + self.log.warning("no orientation change required") + return + } + self.blockOutgoingFrame = true + let deviceName: String = + (orientation == .landscapeLeft || orientation == .landscapeRight) ? + self.camera.nameLandscape : self.camera.namePortrait + self.switchInput(toDevice: self.camera.nameCamera + deviceName) self.camera.rotateCamera(orientation: newOrientation) .subscribe(onCompleted: { [unowned self] in - self.log.debug("new camera orientation: \(orientation)") + self.log.debug("new camera orientation isPortrait: \(orientation.isPortrait)") }, onError: { error in self.log.debug("camera re-orientation error: \(error)") }).disposed(by: self.disposeBag)