Files
openclaw/apps/macos/Sources/OpenClaw/CameraDeviceResolver.swift
Taksh KothariandPeter Steinberger 5c8db67a3b fix(camera): preserve landscape output on external macOS webcams (#116046)
* fix(camera): preserve landscape output on external macOS webcams

After photo-session startup, replace an external camera's portrait format
only with an advertised exact landscape counterpart using the same media
subtype. Preserve built-in, Continuity, already-landscape, and unmatched
formats; keep maxWidth as output-only sizing.

Replace the shared iOS/macOS width-ranking proposal in PR #116046 with this
bounded macOS repair. Add format-contract regressions and document the
best-effort limit. Related: #113068; affected C310 confirmation is pending.

Co-authored-by: Taksh <takshkothari09@gmail.com>

* fix(macos): start connectivity after app admission

Keep passive dashboard, health, and menu reads from implicitly starting endpoint observation and control-channel recovery. AppDelegate already starts the coordinator explicitly after primary-app admission.

* fix(macos): keep Talk phase updates from activating recovery

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-08-27 20:30:38 -07:00

39 lines
1.4 KiB
Swift

import AVFoundation
enum CameraDeviceResolver {
static func availableCameras() -> [AVCaptureDevice] {
let types: [AVCaptureDevice.DeviceType] = [
.builtInWideAngleCamera,
.continuityCamera,
.external,
]
return AVCaptureDevice.DiscoverySession(
deviceTypes: types,
mediaType: .video,
position: .unspecified).devices
}
static func camera(deviceId: String) -> AVCaptureDevice? {
self.availableCameras().first { $0.uniqueID == deviceId }
}
static func landscapePhotoFormatIndex(
deviceType: AVCaptureDevice.DeviceType,
activeFormat: CMFormatDescription,
formats: [CMFormatDescription]) -> Int?
{
let activeSize = CMVideoFormatDescriptionGetDimensions(activeFormat)
guard deviceType == .external, activeSize.width < activeSize.height else {
return nil
}
let subtype = CMFormatDescriptionGetMediaSubType(activeFormat)
// Repair portrait negotiation without choosing a different resolution or encoding.
// Cameras without an exact landscape counterpart keep their negotiated format.
return formats.firstIndex { format in
let size = CMVideoFormatDescriptionGetDimensions(format)
return size.width == activeSize.height && size.height == activeSize.width &&
CMFormatDescriptionGetMediaSubType(format) == subtype
}
}
}