Commit 86285073 authored by Andreas Traczyk's avatar Andreas Traczyk

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
......@@ -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 {
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment