From 24f77fb2247ccefa58ce840d28f3c743ed3ef196 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 3 Oct 2023 12:03:20 +0200 Subject: [PATCH] fix: Use simple wide-angle device if no options are passed (#1909) --- package/example/src/CameraPage.tsx | 19 ++++++++----------- package/src/devices/getCameraDevice.ts | 7 +++++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/package/example/src/CameraPage.tsx b/package/example/src/CameraPage.tsx index 502b76b..cc44fee 100644 --- a/package/example/src/CameraPage.tsx +++ b/package/example/src/CameraPage.tsx @@ -45,9 +45,7 @@ export function CameraPage({ navigation }: Props): React.ReactElement { const [enableNightMode, setEnableNightMode] = useState(false) // camera format settings - const device = useCameraDevice(cameraPosition, { - physicalDevices: ['ultra-wide-angle-camera', 'wide-angle-camera', 'telephoto-camera'], - }) + const device = useCameraDevice(cameraPosition) const [targetFps, setTargetFps] = useState(60) @@ -148,14 +146,13 @@ export function CameraPage({ navigation }: Props): React.ReactElement { }) //#endregion - if (device != null && format != null) { - console.log( - `Re-rendering camera page with ${isActive ? 'active' : 'inactive'} camera. ` + - `Device: "${device.name}" (${format.photoWidth}x${format.photoHeight} photo / ${format.videoWidth}x${format.videoHeight} video @ ${fps}fps)`, - ) - } else { - console.log('re-rendering camera page without active camera') - } + useEffect(() => { + const f = + format != null + ? `(${format.photoWidth}x${format.photoHeight} photo / ${format.videoWidth}x${format.videoHeight}@${format.maxFps} video @ ${fps}fps)` + : undefined + console.log(`Camera: ${device?.name} | Format: ${f}`) + }, [device?.name, format, fps]) const frameProcessor = useFrameProcessor((frame) => { 'worklet' diff --git a/package/src/devices/getCameraDevice.ts b/package/src/devices/getCameraDevice.ts index d92aab3..0b59d94 100644 --- a/package/src/devices/getCameraDevice.ts +++ b/package/src/devices/getCameraDevice.ts @@ -54,8 +54,11 @@ export function getCameraDevice(devices: CameraDevice[], position: CameraPositio if (!explicitlyWantsNonWideAngle) { // prefer wide-angle-camera as a default - if (bestDevice.physicalDevices.includes('wide-angle-camera')) leftPoints += 1 - if (device.physicalDevices.includes('wide-angle-camera')) rightPoints += 1 + if (bestDevice.physicalDevices.includes('wide-angle-camera')) leftPoints += 2 + if (device.physicalDevices.includes('wide-angle-camera')) rightPoints += 2 + // if we have more than one device, we rank it lower. we only want a simple camera + if (bestDevice.physicalDevices.length > device.physicalDevices.length) leftPoints -= 1 + if (device.physicalDevices.length > bestDevice.physicalDevices.length) rightPoints -= 1 } // compare devices. two possible scenarios: