Open source CapCut alternative.
TypeScript
fix(ios): the watch picture follows a camera flip and moves faster
David Lecd1a4dbbfcb6
diff --git a/apps/ios/Donkey/Controllers/CameraController.swift b/apps/ios/Donkey/Controllers/CameraController.swiftindex 9df9b625..ca32c453 100644--- a/apps/ios/Donkey/Controllers/CameraController.swift+++ b/apps/ios/Donkey/Controllers/CameraController.swift@@ -150,9 +150,11 @@ private nonisolated final class CaptureEngine: NSObject, AVCaptureFileOutputRecoprivate let previewContext = CIContext()/// Frames a second the preview offers. The link to the watch gates the/// rate below this on its own.- private static let previewFrameRate: Double = 8- /// The long side of a preview frame in pixels: a watch screen's worth.- private static let previewLongSide: CGFloat = 272+ private static let previewFrameRate: Double = 10+ /// The long side of a preview frame in pixels. The link to the watch is+ /// Bluetooth most of the time, so a frame is kept to a few kilobytes:+ /// enough to frame a shot, small enough to arrive as it happens.+ private static let previewLongSide: CGFloat = 200private var videoInput: AVCaptureDeviceInput?private var facing: CameraFacing = .frontprivate var settings = CameraSettings()@@ -311,7 +313,7 @@ private nonisolated final class CaptureEngine: NSObject, AVCaptureFileOutputRecolet data = previewContext.jpegRepresentation(of: small,colorSpace: colorSpace,- options: [CIImageRepresentationOption(rawValue: kCGImageDestinationLossyCompressionQuality as String): 0.5]+ options: [CIImageRepresentationOption(rawValue: kCGImageDestinationLossyCompressionQuality as String): 0.4]) else { return }previewSink(data)}diff --git a/apps/ios/Donkey/Controllers/WatchLinkController.swift b/apps/ios/Donkey/Controllers/WatchLinkController.swiftindex 61bfcb8f..994d8961 100644--- a/apps/ios/Donkey/Controllers/WatchLinkController.swift+++ b/apps/ios/Donkey/Controllers/WatchLinkController.swift@@ -17,8 +17,8 @@ final class WatchLinkController: NSObject, WCSessionDelegate {/// A record command waiting on the camera to come up, and when it lapses:/// a take nobody is expecting any more must never start on its own.private var pendingRecordUntil: Date?- /// Frames on the wire the watch has not acknowledged. The link carries- /// one at a time, so a slow link drops frames at the source.+ /// Frames on the wire the watch has not acknowledged. Two ride at once+ /// so the link stays busy, and a slow link drops frames at the source.private nonisolated let framesInFlight = Mutex(0)init(app: AppModel, camera: CameraModel, cameraController: CameraController) {@@ -36,6 +36,7 @@ final class WatchLinkController: NSObject, WCSessionDelegate {withObservationTracking {_ = camera.recordingStartedAt_ = camera.availability+ _ = camera.facing} onChange: {Task { @MainActor [weak self] inguard let self else { return }@@ -48,6 +49,7 @@ final class WatchLinkController: NSObject, WCSessionDelegate {private var state: CameraRemoteState {CameraRemoteState(isCameraOpen: camera.availability == .running,+ facing: camera.facing,recordingElapsed: camera.recordingStartedAt.map { Date.now.timeIntervalSince($0) })}@@ -95,7 +97,7 @@ final class WatchLinkController: NSObject, WCSessionDelegate {let session = WCSession.defaultguard session.isReachable else { return }let claimed = framesInFlight.withLock { count in- guard count < 1 else { return false }+ guard count < 2 else { return false }count += 1return true}diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraRemote.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraRemote.swiftindex b1b6dd04..d984bd2a 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraRemote.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraRemote.swift@@ -8,11 +8,15 @@ import Foundationnonisolated public struct CameraRemoteState: Codable, Equatable, Sendable {/// True while the phone's camera is on screen and running.public var isCameraOpen: Bool+ /// Which camera the picture comes from. A change means the last frame+ /// the watch holds is of the other camera.+ public var facing: CameraFacing/// Seconds into the take, or nil when the camera is not recording.public var recordingElapsed: TimeInterval?- public init(isCameraOpen: Bool = false, recordingElapsed: TimeInterval? = nil) {+ public init(isCameraOpen: Bool = false, facing: CameraFacing = .front, recordingElapsed: TimeInterval? = nil) {self.isCameraOpen = isCameraOpen+ self.facing = facingself.recordingElapsed = recordingElapsed}diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraSettings.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraSettings.swiftindex ce03b5f6..3ab789a6 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraSettings.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraSettings.swift@@ -37,7 +37,7 @@ nonisolated public struct CameraSettings: Equatable, Codable, Sendable {}}-nonisolated public enum CameraFacing: Sendable, Equatable {+nonisolated public enum CameraFacing: String, Codable, Sendable, Equatable {case front, backpublic var flipped: CameraFacing { self == .front ? .back : .front }