react-native-vision-camera/docs/docs/guides
Marc Rousavy 30b56153db
feat: Sync Frame Processors (plus runAsync and runAtTargetFps) (#1472)
Before, Frame Processors ran on a separate Thread.

After, Frame Processors run fully synchronous and always at the same FPS as the Camera.

Two new functions have been introduced:

* `runAtTargetFps(fps: number, func: () => void)`: Runs the given code as often as the given `fps`, effectively throttling it's calls.
* `runAsync(frame: Frame, func: () => void)`: Runs the given function on a separate Thread for Frame Processing. A strong reference to the Frame is held as long as the function takes to execute.

You can use `runAtTargetFps` to throttle calls to a specific API (e.g. if your Camera is running at 60 FPS, but you only want to run face detection at ~25 FPS, use `runAtTargetFps(25, ...)`.)

You can use `runAsync` to run a heavy algorithm asynchronous, so that the Camera is not blocked while your algorithm runs. This is useful if your main sync processor draws something, and your async processor is doing some image analysis on the side. 

You can also combine both functions.

Examples:

```js
const frameProcessor = useFrameProcessor((frame) => {
  'worklet'
  console.log("I'm running at 60 FPS!")
}, [])
```

```js
const frameProcessor = useFrameProcessor((frame) => {
  'worklet'
  console.log("I'm running at 60 FPS!")

  runAtTargetFps(10, () => {
    'worklet'
    console.log("I'm running at 10 FPS!")
  })
}, [])
```



```js
const frameProcessor = useFrameProcessor((frame) => {
  'worklet'
  console.log("I'm running at 60 FPS!")

  runAsync(frame, () => {
    'worklet'
    console.log("I'm running on another Thread, I can block for longer!")
  })
}, [])
```

```js
const frameProcessor = useFrameProcessor((frame) => {
  'worklet'
  console.log("I'm running at 60 FPS!")

  runAtTargetFps(10, () => {
    'worklet'
    runAsync(frame, () => {
      'worklet'
      console.log("I'm running on another Thread at 10 FPS, I can block for longer!")
    })
  })
}, [])
```
2023-02-15 16:47:09 +01:00
..
CAPTURING.mdx chore: Upgrade a whole lotta dependencies (#436) 2021-09-22 13:58:59 +02:00
DEVICES.mdx docs: Fix small typo (#473) 2021-10-02 15:07:32 +02:00
ERRORS.mdx docs: Fix typo in ERRORS (#1160) 2022-07-25 13:26:18 +02:00
FOCUSING.mdx chore: Upgrade a whole lotta dependencies (#436) 2021-09-22 13:58:59 +02:00
FORMATS.mdx Update FORMATS.mdx 2021-09-09 22:01:52 +02:00
FRAME_PROCESSOR_CREATE_FINAL.mdx feat: Replace Reanimated with RN Worklets (#1468) 2023-02-13 15:22:45 +01:00
FRAME_PROCESSOR_CREATE_PLUGIN_ANDROID.mdx feat: Replace Reanimated with RN Worklets (#1468) 2023-02-13 15:22:45 +01:00
FRAME_PROCESSOR_CREATE_PLUGIN_IOS.mdx feat: Replace Reanimated with RN Worklets (#1468) 2023-02-13 15:22:45 +01:00
FRAME_PROCESSOR_PLUGIN_LIST.mdx feat: Replace Reanimated with RN Worklets (#1468) 2023-02-13 15:22:45 +01:00
FRAME_PROCESSORS_CREATE_OVERVIEW.mdx feat: Replace Reanimated with RN Worklets (#1468) 2023-02-13 15:22:45 +01:00
FRAME_PROCESSORS.mdx feat: Sync Frame Processors (plus runAsync and runAtTargetFps) (#1472) 2023-02-15 16:47:09 +01:00
LIFECYCLE.mdx chore: Move to /mrousavy/ (#224) 2021-06-21 22:42:46 +02:00
MOCKING.mdx docs: 📄 Add mocking section to docs (#1061) 2022-05-27 11:34:54 +02:00
SETUP.mdx feat: Replace Reanimated with RN Worklets (#1468) 2023-02-13 15:22:45 +01:00
TODO.md feat: Replace Reanimated with RN Worklets (#1468) 2023-02-13 15:22:45 +01:00
TROUBLESHOOTING.mdx chore: Upgrade to RN 71 (#1465) 2023-02-09 11:52:41 +01:00
ZOOMING.mdx docs: Update Zooming code link (#661) 2021-12-30 10:10:15 +01:00