fix: Use simple wide-angle device if no options are passed (#1909)

This commit is contained in:
Marc Rousavy 2023-10-03 12:03:20 +02:00 committed by GitHub
parent bdd81cf2fb
commit 24f77fb224
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 13 deletions

View File

@ -45,9 +45,7 @@ export function CameraPage({ navigation }: Props): React.ReactElement {
const [enableNightMode, setEnableNightMode] = useState(false) const [enableNightMode, setEnableNightMode] = useState(false)
// camera format settings // camera format settings
const device = useCameraDevice(cameraPosition, { const device = useCameraDevice(cameraPosition)
physicalDevices: ['ultra-wide-angle-camera', 'wide-angle-camera', 'telephoto-camera'],
})
const [targetFps, setTargetFps] = useState(60) const [targetFps, setTargetFps] = useState(60)
@ -148,14 +146,13 @@ export function CameraPage({ navigation }: Props): React.ReactElement {
}) })
//#endregion //#endregion
if (device != null && format != null) { useEffect(() => {
console.log( const f =
`Re-rendering camera page with ${isActive ? 'active' : 'inactive'} camera. ` + format != null
`Device: "${device.name}" (${format.photoWidth}x${format.photoHeight} photo / ${format.videoWidth}x${format.videoHeight} video @ ${fps}fps)`, ? `(${format.photoWidth}x${format.photoHeight} photo / ${format.videoWidth}x${format.videoHeight}@${format.maxFps} video @ ${fps}fps)`
) : undefined
} else { console.log(`Camera: ${device?.name} | Format: ${f}`)
console.log('re-rendering camera page without active camera') }, [device?.name, format, fps])
}
const frameProcessor = useFrameProcessor((frame) => { const frameProcessor = useFrameProcessor((frame) => {
'worklet' 'worklet'

View File

@ -54,8 +54,11 @@ export function getCameraDevice(devices: CameraDevice[], position: CameraPositio
if (!explicitlyWantsNonWideAngle) { if (!explicitlyWantsNonWideAngle) {
// prefer wide-angle-camera as a default // prefer wide-angle-camera as a default
if (bestDevice.physicalDevices.includes('wide-angle-camera')) leftPoints += 1 if (bestDevice.physicalDevices.includes('wide-angle-camera')) leftPoints += 2
if (device.physicalDevices.includes('wide-angle-camera')) rightPoints += 1 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: // compare devices. two possible scenarios: