react-native-vision-camera/ios/Frame Processor
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
..
Frame.h feat: native Frame type to provide Orientation (#186) 2021-06-09 10:57:05 +02:00
Frame.m feat: native Frame type to provide Orientation (#186) 2021-06-09 10:57:05 +02:00
FrameHostObject.h feat: Sync Frame Processors (plus runAsync and runAtTargetFps) (#1472) 2023-02-15 16:47:09 +01:00
FrameHostObject.mm feat: Sync Frame Processors (plus runAsync and runAtTargetFps) (#1472) 2023-02-15 16:47:09 +01:00
FrameProcessorCallback.h feat: native Frame type to provide Orientation (#186) 2021-06-09 10:57:05 +02:00
FrameProcessorPlugin.h feat: Replace Reanimated with RN Worklets (#1468) 2023-02-13 15:22:45 +01:00
FrameProcessorPluginRegistry.h fix: Re-install FP plugins on bundle reload (#684) 2021-12-30 11:38:54 +01:00
FrameProcessorPluginRegistry.mm fix: Re-install FP plugins on bundle reload (#684) 2021-12-30 11:38:54 +01:00
FrameProcessorRuntimeManager.h feat: Replace Reanimated with RN Worklets (#1468) 2023-02-13 15:22:45 +01:00
FrameProcessorRuntimeManager.mm feat: Sync Frame Processors (plus runAsync and runAtTargetFps) (#1472) 2023-02-15 16:47:09 +01:00
FrameProcessorUtils.h feat: Replace Reanimated with RN Worklets (#1468) 2023-02-13 15:22:45 +01:00
FrameProcessorUtils.mm feat: Sync Frame Processors (plus runAsync and runAtTargetFps) (#1472) 2023-02-15 16:47:09 +01:00