Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions BetterCapture/Service/CameraSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ final class CameraSession {
session = newSession

// Wait for the session to actually be running before returning.
// AVCaptureSession is not Sendable, but we fully configure it on
// the main actor above and then only touch it on `queue` below.
nonisolated(unsafe) let runnable = newSession
let isRunning = await withCheckedContinuation { continuation in
queue.async {
newSession.startRunning()
continuation.resume(returning: newSession.isRunning)
runnable.startRunning()
continuation.resume(returning: runnable.isRunning)
}
}

Expand All @@ -93,8 +96,10 @@ final class CameraSession {
guard let current = session else { return }
session = nil

// See comment in start(deviceID:) for why nonisolated(unsafe) is appropriate.
nonisolated(unsafe) let stoppable = current
queue.async {
current.stopRunning()
stoppable.stopRunning()
}

logger.info("Camera session stopped")
Expand Down
2 changes: 1 addition & 1 deletion BetterCapture/ViewModel/RecorderViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ final class RecorderViewModel {
logger.info("Video size: \(self.videoSize.width)x\(self.videoSize.height)")

// Access security-scoped output directory before writing
settings.startAccessingOutputDirectory()
_ = settings.startAccessingOutputDirectory()

// Setup asset writer
let outputURL = settings.generateOutputURL()
Expand Down
Loading