Skip to content

Commit 4706c04

Browse files
authored
chore: Sleep 1s before capturing max-res to prevent 24MP flakiness (#3982)
Apparently the 48MP+ max resolution capture path is a bit flakey on iOS, as AVFoundation internally prepares it asynchronously - no idea why, but it downgrades to 24MP and so the test fails. However if we call prepareSettings and/or 1s sleep, the it successfully captures 48MP and the test goes green. No idea why or how to fix it, as AVFoundation also documents this as kind of best effort and can silently downgrade...
1 parent bc5e871 commit 4706c04

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

apps/simple-camera/__tests__/visioncamera.photo.harness.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import type {
1515
} from 'react-native-vision-camera'
1616
import { CommonResolutions, VisionCamera } from 'react-native-vision-camera'
1717

18+
const sleep = (ms: number) =>
19+
new Promise<void>((resolve) => setTimeout(resolve, ms))
20+
1821
describe('VisionCamera - Photo', () => {
1922
let factory: CameraDeviceFactory
2023
let backDevice: CameraDevice
@@ -362,13 +365,16 @@ describe('VisionCamera - Photo', () => {
362365
expect(reportedShortEdge).toBe(requestedShortEdge)
363366
expect(reportedLongEdge).toBe(requestedLongEdge)
364367

365-
// Prepare default settings on the Photo Output before capturing.
366-
// This is kinda required for max res capture on iOS as otherwise
367-
// the pipeline is not ready for 48MP+ capture (possibly a race
368-
// condition inside AVFoundation?) and would give us binned (eg 24MP)
368+
// TODO: Figure out why we need prepareSettings + 1s sleep to capture max res????
369+
// Prepare default settings on the Photo Output before capturing,
370+
// and add an artificial 1 second timeout.
371+
// This is for some reason required for max res capture on iOS as
372+
// otherwise the pipeline is not ready for 48MP+ capture (possibly a
373+
// race condition inside AVFoundation?) and would give us binned (eg 24MP)
369374
// photos instead - maybe because it tries to give a photo quickly while
370375
// 48MP is still being warmed up? No idea. Bad DX imo.
371376
await photoOutput.prepareSettings([{}])
377+
await sleep(1000)
372378

373379
const photo = await photoOutput.capturePhoto(
374380
{ flashMode: 'off', enableShutterSound: false },

0 commit comments

Comments
 (0)