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
22 changes: 11 additions & 11 deletions .github/workflows/ios-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions:
jobs:
build:
name: Build and Test
runs-on: macos-26
runs-on: xcode-27

steps:
- name: Checkout
Expand All @@ -24,24 +24,24 @@ 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

- 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
Expand All @@ -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 \
Expand All @@ -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 \
Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:

build-mac-catalyst:
name: Build Mac Catalyst
runs-on: macos-26
runs-on: xcode-27

steps:
- name: Checkout
Expand All @@ -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: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ permissions:
jobs:
release:
name: Build & Upload to App Store
runs-on: macos-26
runs-on: xcode-27
steps:
- uses: actions/checkout@v4
with:
lfs: true

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '26.2'
xcode-version: '27.1'

- uses: ruby/setup-ruby@v1
with:
Expand Down
62 changes: 56 additions & 6 deletions RemoteCam/CaptureEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -1392,23 +1436,29 @@ 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
/// device (`selectLogicalDeviceLocked`). Re-apply sites never swap:
/// `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)
}

Expand Down
3 changes: 2 additions & 1 deletion RemoteCamTests/CaptureIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? "?")")

Expand Down
Loading