Skip to content

Commit

Permalink
fix(lib): fix orientation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Feb 12, 2024
1 parent 35330a1 commit 1834b74
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions Sources/ApiVideoLiveStream/ApiVideoLiveStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,9 @@ public class ApiVideoLiveStream {
self.rtmpStream.frameRate = videoConfig.fps
self.rtmpStream.sessionPreset = AVCaptureSession.Preset.high

let width = self.rtmpStream.videoOrientation.isLandscape ? videoConfig.resolution.width : videoConfig
.resolution.height
let height = self.rtmpStream.videoOrientation.isLandscape ? videoConfig.resolution.height : videoConfig
.resolution.width
let resolution = videoConfig.resolution
let width = self.rtmpStream.videoOrientation.isLandscape ? max(resolution.width, resolution.height) : min(resolution.width, resolution.height)
let height = self.rtmpStream.videoOrientation.isLandscape ? min(resolution.width, resolution.height) : max(resolution.width, resolution.height)

self.rtmpStream.videoSettings = VideoCodecSettings(
videoSize: CGSize(width: width, height: height),
Expand Down Expand Up @@ -441,15 +440,14 @@ public class ApiVideoLiveStream {
self.rtmpStream.lockQueue.async {
self.rtmpStream.videoOrientation = orientation

let videoSize = self.rtmpStream.videoSettings.videoSize
self.rtmpStream.videoSettings.videoSize = CGSize(
width:
self.rtmpStream.videoOrientation.isLandscape ?
videoSize.width : videoSize.height,
height:
self.rtmpStream.videoOrientation.isLandscape ?
videoSize.height : videoSize.width
)
let currentVideoSize = self.rtmpStream.videoSettings.videoSize
var newVideoSize: CGSize
if self.rtmpStream.videoOrientation.isLandscape {
newVideoSize = CGSize(width: max(currentVideoSize.width, currentVideoSize.height), height: min(currentVideoSize.width, currentVideoSize.height))
} else {
newVideoSize = CGSize(width: min(currentVideoSize.width, currentVideoSize.height), height: max(currentVideoSize.width, currentVideoSize.height))
}
self.rtmpStream.videoSettings.videoSize = newVideoSize
}
}
#endif
Expand Down

0 comments on commit 1834b74

Please sign in to comment.