Skip to content

Commit

Permalink
Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
YuAo committed Mar 15, 2022
1 parent 109320e commit 7097d03
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions Sources/VideoIO/Camera.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// File.swift
//
//
//
// Created by Yu Ao on 2019/12/18.
//
Expand Down Expand Up @@ -132,14 +132,42 @@ public class Camera {
}
}

public func removeVideoCaptureDevice() {
public func switchToVideoCaptureDevice(_ device: AVCaptureDevice) throws {
guard device.hasMediaType(.video) else {
throw Error.noRequiredMediaTypeFoundOnDevice
}

let newVideoDeviceInput = try AVCaptureDeviceInput(device: device)
self.captureSession.beginConfiguration()
if let currentVideoDeviceInput = self.videoDeviceInput {
self.captureSession.removeInput(currentVideoDeviceInput)
}
if self.captureSession.canAddInput(newVideoDeviceInput) {
self.captureSession.addInput(newVideoDeviceInput)
self.videoDeviceInput = newVideoDeviceInput
} else {
self.captureSession.commitConfiguration()
throw Error.cannotAddInput
}

if let connection = self.videoCaptureConnection {
self.configurator.videoConnectionConfigurator(self, connection)
}
self.captureSession.commitConfiguration()

try device.lockForConfiguration()
self.configurator.videoDeviceConfigurator(self, device)
device.unlockForConfiguration()
}

public func removeVideoCaptureDevice() {
self.captureSession.beginConfiguration()

if let currentVideoDeviceInput = self.videoDeviceInput {
self.captureSession.removeInput(currentVideoDeviceInput)
self.videoDeviceInput = nil
}

self.captureSession.commitConfiguration()
}

Expand Down Expand Up @@ -386,4 +414,3 @@ public class Camera {
@available(macOS, unavailable)
internal var audioQueueCaptureSession: AudioQueueCaptureSession?
}

0 comments on commit 7097d03

Please sign in to comment.