feat: Support setting videoStabilizationMode
(#2160)
* feat: Support setting `videoStabilizationMode` * fix: Use `outputs` * Format * Set Video Stabilization Mode
This commit is contained in:
@@ -22,6 +22,9 @@ class CameraConfiguration {
|
||||
var video: OutputConfiguration<Video> = .disabled
|
||||
var codeScanner: OutputConfiguration<CodeScanner> = .disabled
|
||||
|
||||
// Video Stabilization
|
||||
var videoStabilizationMode: VideoStabilizationMode = .off
|
||||
|
||||
// Orientation
|
||||
var orientation: Orientation = .portrait
|
||||
|
||||
@@ -49,6 +52,7 @@ class CameraConfiguration {
|
||||
photo = other.photo
|
||||
video = other.video
|
||||
codeScanner = other.codeScanner
|
||||
videoStabilizationMode = other.videoStabilizationMode
|
||||
orientation = other.orientation
|
||||
format = other.format
|
||||
fps = other.fps
|
||||
@@ -67,6 +71,7 @@ class CameraConfiguration {
|
||||
struct Difference {
|
||||
let inputChanged: Bool
|
||||
let outputsChanged: Bool
|
||||
let videoStabilizationChanged: Bool
|
||||
let orientationChanged: Bool
|
||||
let formatChanged: Bool
|
||||
let sidePropsChanged: Bool
|
||||
@@ -80,7 +85,7 @@ class CameraConfiguration {
|
||||
[`inputChanged`, `outputsChanged`, `orientationChanged`]
|
||||
*/
|
||||
var isSessionConfigurationDirty: Bool {
|
||||
return inputChanged || outputsChanged || orientationChanged
|
||||
return inputChanged || outputsChanged || videoStabilizationChanged || orientationChanged
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,6 +101,8 @@ class CameraConfiguration {
|
||||
inputChanged = left?.cameraId != right.cameraId
|
||||
// photo, video, codeScanner
|
||||
outputsChanged = inputChanged || left?.photo != right.photo || left?.video != right.video || left?.codeScanner != right.codeScanner
|
||||
// videoStabilizationMode
|
||||
videoStabilizationChanged = outputsChanged || left?.videoStabilizationMode != right.videoStabilizationMode
|
||||
// orientation
|
||||
orientationChanged = outputsChanged || left?.orientation != right.orientation
|
||||
// format (depends on cameraId)
|
||||
|
@@ -154,6 +154,17 @@ extension CameraSession {
|
||||
ReactLogger.log(level: .info, message: "Successfully configured all outputs!")
|
||||
}
|
||||
|
||||
// pragma MARK: Video Stabilization
|
||||
func configureVideoStabilization(configuration: CameraConfiguration) {
|
||||
captureSession.outputs.forEach { output in
|
||||
output.connections.forEach { connection in
|
||||
if connection.isVideoStabilizationSupported {
|
||||
connection.preferredVideoStabilizationMode = configuration.videoStabilizationMode.toAVCaptureVideoStabilizationMode()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pragma MARK: Orientation
|
||||
|
||||
func configureOrientation(configuration: CameraConfiguration) {
|
||||
|
@@ -123,7 +123,11 @@ class CameraSession: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate, AVC
|
||||
if difference.outputsChanged {
|
||||
try self.configureOutputs(configuration: config)
|
||||
}
|
||||
// 3. Update output orientation
|
||||
// 3. Update Video Stabilization
|
||||
if difference.videoStabilizationChanged {
|
||||
try self.configureVideoStabilization(configuration: config)
|
||||
}
|
||||
// 4. Update output orientation
|
||||
if difference.orientationChanged {
|
||||
self.configureOrientation(configuration: config)
|
||||
}
|
||||
|
Reference in New Issue
Block a user