MijickCamera/Sources/Internal/Manager/Helpers/Capture Session/CaptureSession+AVCaptureSession.swift

46 lines
1.3 KiB
Swift
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// CaptureSession+AVCaptureSession.swift of MijickCamera
//
// Created by Tomasz Kurylik. Sending from Kraków!
// - Mail: tomasz.kurylik@mijick.com
// - GitHub: https://github.com/FulcrumOne
// - Medium: https://medium.com/@mijick
//
// Copyright ©2024 Mijick. All rights reserved.
import AVKit
extension AVCaptureSession: @unchecked @retroactive Sendable {}
extension AVCaptureSession: CaptureSession {
var deviceInputs: [any CaptureDeviceInput] { inputs as? [any CaptureDeviceInput] ?? [] }
}
// MARK: - METHODS
extension AVCaptureSession {
func stopRunningAndReturnNewInstance() -> any CaptureSession {
self.stopRunning()
return AVCaptureSession()
}
}
extension AVCaptureSession {
func add(input: (any CaptureDeviceInput)?) throws(MCameraError) {
guard let input = input as? AVCaptureDeviceInput else { throw .cannotSetupInput }
if canAddInput(input) { addInput(input) }
}
func remove(input: (any CaptureDeviceInput)?) {
guard let input = input as? AVCaptureDeviceInput else { return }
removeInput(input)
}
}
extension AVCaptureSession {
func add(output: AVCaptureOutput?) throws(MCameraError) {
guard let output else { throw .cannotSetupOutput }
if canAddOutput(output) { addOutput(output) }
}
}