Async Frame Processing

Processing Frames asynchronously, freeing up work from the main Camera pipeline

Frame Processors run fully synchronously, on the Camera Thread. If your Frame Processor cannot keep up with the Camera's frame rate, you can move your processing logic to an asynchronous runner instead.

The Async Runner

To create an AsyncRunner use useAsyncRunner():

const asyncRunner = useAsyncRunner()
const asyncRunner = createAsyncRunner()

Then, schedule work on the AsyncRunner's Thread:

const asyncRunner = useAsyncRunner()
const frameOutput = useFrameOutput({
  onFrame(frame) {
    'worklet'
    const wasHandled = asyncRunner.runAsync(() => {
      'worklet'
      doSomeHeavyProcessing(frame)
      // Async task finished - dispose the Frame now.
      frame.dispose()
    })
    if (!wasHandled) {
      // `asyncRunner` is busy - drop this Frame!
      frame.dispose()
    }
  }
})

If the AsyncRunner is currently busy, it will immediately return false and not schedule the work. In this case, you must drop the Frame inside your onFrame(...) callback via dispose().

If the AsyncRunner can pick up the work, it will return true and you can dispose the Frame later, inside the async method's body.

On this page