Skip to content
Snippets Groups Projects
Commit 86285073 authored by Andreas Traczyk's avatar Andreas Traczyk
Browse files

video call: force set orientation at call start

- sets current device orientation when call state transitions to
  current
- prevents redundant orientation state changes from triggering
  SDP renegotiation

Change-Id: Ie5a61c3dd0629f8db535f18cac27c3437df05131
parent 29e00d81
No related branches found
No related tags found
No related merge requests found
...@@ -95,7 +95,7 @@ class CallViewModel: Stateable, ViewModel { ...@@ -95,7 +95,7 @@ class CallViewModel: Stateable, ViewModel {
return call.state == .over || call.state == .failure return call.state == .over || call.state == .failure
}).map({ hide in }).map({ hide in
if hide { if hide {
self.videoService.setCameraOrientation(orientation: .portrait) self.videoService.setCameraOrientation(orientation: UIDevice.current.orientation)
} }
return hide return hide
}) })
...@@ -281,6 +281,15 @@ class CallViewModel: Stateable, ViewModel { ...@@ -281,6 +281,15 @@ class CallViewModel: Stateable, ViewModel {
self.videoService = injectionBag.videoService self.videoService = injectionBag.videoService
self.audioService = injectionBag.audioService self.audioService = injectionBag.audioService
self.profileService = injectionBag.profileService 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 { static func formattedDurationFrom(interval: Int) -> String {
......
...@@ -54,6 +54,9 @@ class FrameExtractor: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate { ...@@ -54,6 +54,9 @@ class FrameExtractor: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate {
private let quality = AVCaptureSession.Preset.medium private let quality = AVCaptureSession.Preset.medium
private var orientation = AVCaptureVideoOrientation.portrait private var orientation = AVCaptureVideoOrientation.portrait
var getOrientation: AVCaptureVideoOrientation {
get { return orientation }
}
var permissionGranted = Variable<Bool>(false) var permissionGranted = Variable<Bool>(false)
...@@ -89,7 +92,8 @@ class FrameExtractor: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate { ...@@ -89,7 +92,8 @@ class FrameExtractor: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate {
bestRate = frameRates.maxFrameRate bestRate = frameRates.maxFrameRate
} }
} }
if orientation == .portrait || orientation == .portraitUpsideDown { if orientation == .portrait ||
orientation == .portraitUpsideDown {
let devInfo: DeviceInfo = ["format": "BGRA", let devInfo: DeviceInfo = ["format": "BGRA",
"width": String(dimensions.height), "width": String(dimensions.height),
"height": String(dimensions.width), "height": String(dimensions.width),
...@@ -327,11 +331,6 @@ class VideoService: FrameExtractorDelegate { ...@@ -327,11 +331,6 @@ class VideoService: FrameExtractorDelegate {
} }
func setCameraOrientation(orientation: UIDeviceOrientation) { 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 var newOrientation: AVCaptureVideoOrientation
switch orientation { switch orientation {
case .portrait: case .portrait:
...@@ -345,9 +344,18 @@ class VideoService: FrameExtractorDelegate { ...@@ -345,9 +344,18 @@ class VideoService: FrameExtractorDelegate {
default: default:
newOrientation = AVCaptureVideoOrientation.portrait 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) self.camera.rotateCamera(orientation: newOrientation)
.subscribe(onCompleted: { [unowned self] in .subscribe(onCompleted: { [unowned self] in
self.log.debug("new camera orientation: \(orientation)") self.log.debug("new camera orientation isPortrait: \(orientation.isPortrait)")
}, onError: { error in }, onError: { error in
self.log.debug("camera re-orientation error: \(error)") self.log.debug("camera re-orientation error: \(error)")
}).disposed(by: self.disposeBag) }).disposed(by: self.disposeBag)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment