diff --git a/.github/workflows/ios-ci.yml b/.github/workflows/ios-ci.yml index 8628a969..7209e7b0 100644 --- a/.github/workflows/ios-ci.yml +++ b/.github/workflows/ios-ci.yml @@ -13,7 +13,7 @@ permissions: jobs: build: name: Build and Test - runs-on: macos-26 + runs-on: xcode-27 steps: - name: Checkout @@ -24,7 +24,7 @@ jobs: - name: Setup Xcode uses: maxim-lobanov/setup-xcode@v1 with: - xcode-version: '26.2' + xcode-version: '27.1' - name: Show Xcode version run: xcodebuild -version @@ -32,16 +32,16 @@ jobs: - name: Show available simulators run: xcrun simctl list devicetypes - # Xcode 26 compilation cache (LLVM CAS). Content-addressed, so stale + # Xcode compilation cache (LLVM CAS), one per Xcode version. Content-addressed, so stale # entries are harmless — restore-keys falls back to the newest cache on # any branch when the exact-sha key misses (i.e. always, except re-runs). - name: Restore compilation cache uses: actions/cache@v4 with: path: ~/compilation-cache - key: cas-ios-${{ github.sha }} + key: cas-ios-xcode27.1-${{ github.sha }} restore-keys: | - cas-ios- + cas-ios-xcode27.1- # TODO: Remove this once we have a way to install CocoaPods # - name: Cache CocoaPods @@ -66,7 +66,7 @@ jobs: xcodebuild \ -workspace RemoteShutter.xcworkspace \ -scheme RemoteCam \ - -destination 'platform=iOS Simulator,OS=26.2,name=iPhone 17' \ + -destination 'platform=iOS Simulator,OS=27.0,name=iPhone 17' \ -configuration Debug \ clean build \ CODE_SIGNING_REQUIRED=NO \ @@ -85,7 +85,7 @@ jobs: xcodebuild \ -workspace RemoteShutter.xcworkspace \ -scheme RemoteCam \ - -destination 'platform=iOS Simulator,OS=26.2,name=iPhone 17' \ + -destination 'platform=iOS Simulator,OS=27.0,name=iPhone 17' \ -configuration Debug \ test \ -enableCodeCoverage YES \ @@ -133,7 +133,7 @@ jobs: build-mac-catalyst: name: Build Mac Catalyst - runs-on: macos-26 + runs-on: xcode-27 steps: - name: Checkout @@ -144,15 +144,15 @@ jobs: - name: Setup Xcode uses: maxim-lobanov/setup-xcode@v1 with: - xcode-version: '26.2' + xcode-version: '27.1' - name: Restore compilation cache uses: actions/cache@v4 with: path: ~/compilation-cache - key: cas-catalyst-${{ github.sha }} + key: cas-catalyst-xcode27.1-${{ github.sha }} restore-keys: | - cas-catalyst- + cas-catalyst-xcode27.1- - name: Build for Mac Catalyst run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ea9dbd80..f478065f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ permissions: jobs: release: name: Build & Upload to App Store - runs-on: macos-26 + runs-on: xcode-27 steps: - uses: actions/checkout@v4 with: @@ -31,7 +31,7 @@ jobs: - uses: maxim-lobanov/setup-xcode@v1 with: - xcode-version: '26.2' + xcode-version: '27.1' - uses: ruby/setup-ruby@v1 with: diff --git a/RemoteCam/CaptureEngine.swift b/RemoteCam/CaptureEngine.swift index 8065ae24..46c112cb 100644 --- a/RemoteCam/CaptureEngine.swift +++ b/RemoteCam/CaptureEngine.swift @@ -1293,7 +1293,7 @@ final class CaptureEngine: NSObject, AVCapturePhotoCaptureDelegate { private func exposureFactsLocked(_ device: AVCaptureDevice) -> ExposureFacts { let format = device.activeFormat return ExposureFacts( - supportsCustom: device.isExposureModeSupported(.custom), + supportsCustom: Self.runsManual(device), minDurationSeconds: CMTimeGetSeconds(format.minExposureDuration), maxDurationSeconds: CMTimeGetSeconds(format.maxExposureDuration), minISO: format.minISO, @@ -1378,11 +1378,55 @@ final class CaptureEngine: NSObject, AVCapturePhotoCaptureDelegate { if CMTimeCompare(duration, format.minExposureDuration) < 0 { duration = format.minExposureDuration } if CMTimeCompare(duration, format.maxExposureDuration) > 0 { duration = format.maxExposureDuration } let safeISO = min(max(iso, format.minISO), format.maxISO) - device.setExposureModeCustom(duration: duration, iso: safeISO, completionHandler: done) + switch Self.manualAperture(for: format) { + case .locked: + device.setExposureModeCustom(duration: duration, iso: safeISO, completionHandler: done) + case .auto: + Self.setManualExposureWithAutoAperture(device, duration: duration, iso: safeISO, completion: done) + case nil: + // Never call a custom mode the format refuses: it raises an + // NSInvalidArgumentException that Swift cannot catch. + debugLog("🌗 EXPOSURE: \(device.localizedName) refuses locked shutter + ISO — staying auto") + exposureIntent = .auto(bias: 0) + completion?() + return + } debugLog("🌗 EXPOSURE: manual \(CMTimeGetSeconds(duration))s ISO \(safeISO) on \(device.localizedName)") } } + /// How Manual (shutter + ISO locked) runs on a format. `.locked` also + /// locks the aperture, the only option before variable-aperture lenses. + /// A variable-aperture lens (iPhone 18 Pro) refuses all three locked but + /// accepts shutter + ISO locked with the aperture left to auto exposure. + /// Nil = the format takes neither, so Manual is not offered. + enum ManualAperture: Equatable { case locked, auto } + + static func manualAperture(for format: AVCaptureDevice.Format) -> ManualAperture? { + if #available(iOS 27.0, macCatalyst 27.0, *) { + let locked = format.supportsExposureModeCustom( + lensAperture: AVCaptureDevice.currentLensAperture, + duration: AVCaptureDevice.currentExposureDuration, iso: AVCaptureDevice.currentISO) + if locked { return .locked } + let autoAperture = format.supportsExposureModeCustom( + lensAperture: AVCaptureDevice.autoLensAperture, + duration: AVCaptureDevice.currentExposureDuration, iso: AVCaptureDevice.currentISO) + return autoAperture ? .auto : nil + } + return .locked + } + + private static func setManualExposureWithAutoAperture( + _ device: AVCaptureDevice, duration: CMTime, iso: Float, completion: ((CMTime) -> Void)? + ) { + if #available(iOS 27.0, macCatalyst 27.0, *) { + device.setExposureModeCustom(lensAperture: AVCaptureDevice.autoLensAperture, + duration: duration, iso: iso, completionHandler: completion) + return + } + completion?(.invalid) + } + /// The lens Manual exposure runs on: the device itself when it accepts /// `.custom`; for a virtual device (which refuses it), a constituent that /// does — the active one while the session runs, else the wide lens. @@ -1392,15 +1436,21 @@ final class CaptureEngine: NSObject, AVCapturePhotoCaptureDelegate { /// used in a RUNNING session, and the first state exchange happens before /// the session starts. private func manualExposureLensLocked(for device: AVCaptureDevice) -> AVCaptureDevice? { - if device.isExposureModeSupported(.custom) { return device } + if Self.runsManual(device) { return device } guard device.isVirtualDevice else { return nil } - if let active = device.activePrimaryConstituent, active.isExposureModeSupported(.custom) { + if let active = device.activePrimaryConstituent, Self.runsManual(active) { return active } - let candidates = device.constituentDevices.filter { $0.isExposureModeSupported(.custom) } + let candidates = device.constituentDevices.filter { Self.runsManual($0) } return candidates.first { $0.deviceType == .builtInWideAngleCamera } ?? candidates.first } + /// The device takes `.custom` and its active format accepts shutter + ISO + /// locked, with the aperture locked or left to auto exposure. + private static func runsManual(_ device: AVCaptureDevice) -> Bool { + device.isExposureModeSupported(.custom) && manualAperture(for: device.activeFormat) != nil + } + /// The physical lens `device` must run on for Manual, or nil when it can /// run Manual itself (or Manual is off). Two entry points act on it — a /// change of intent (`reconcileExposureDeviceLocked`) and a change of @@ -1408,7 +1458,7 @@ final class CaptureEngine: NSObject, AVCapturePhotoCaptureDelegate { /// `swapToDeviceLocked` calls `applyExposureIntentLocked`, so a swap from /// there would recurse. private func manualExposureHopTargetLocked(for device: AVCaptureDevice) -> AVCaptureDevice? { - guard case .manual = exposureIntent, !device.isExposureModeSupported(.custom) else { return nil } + guard case .manual = exposureIntent, !Self.runsManual(device) else { return nil } return manualExposureLensLocked(for: device) } diff --git a/RemoteCamTests/CaptureIntegrationTests.swift b/RemoteCamTests/CaptureIntegrationTests.swift index 0ec2f683..ec6138cf 100644 --- a/RemoteCamTests/CaptureIntegrationTests.swift +++ b/RemoteCamTests/CaptureIntegrationTests.swift @@ -200,7 +200,8 @@ final class CaptureIntegrationTests: XCTestCase { let manual = await rig.gatherCurrentCameraCapabilities() XCTAssertEqual(manual?.exposure?.mode, .manual) XCTAssertEqual(manual?.exposure?.durationSeconds ?? 0, 1.0 / 250, accuracy: 1.0 / 2000) - XCTAssertEqual(manual?.exposure?.iso ?? 0, min(400, before.maxISO), accuracy: 1) + // Within 1%: the iPhone 18 Pro lands 400 as 398.77 (its gain steps). + XCTAssertEqual(manual?.exposure?.iso ?? 0, min(400, before.maxISO), accuracy: min(400, before.maxISO) / 100) XCTAssertEqual(manual?.activeDeviceID, logicalBefore, "a lens hop never leaks into the logical device") print("🌗 probe: manual landed — \(manual?.exposure.map { "\($0)" } ?? "nil") active=\(manual?.activeDeviceID ?? "?")")