react-native-vision-camera/example/package.json
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

51 lines
1.9 KiB
JSON

{
"name": "react-native-vision-camera-example",
"description": "Example app for react-native-vision-camera",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"setup": "cd ios && bundle install",
"pods": "cd ios && bundle exec pod install",
"lint": "eslint .",
"lint-ci": "yarn lint -f ../node_modules/@firmnav/eslint-github-actions-formatter/dist/formatter.js",
"typescript": "tsc --noEmit"
},
"dependencies": {
"@react-native-camera-roll/camera-roll": "^5.2.3",
"@react-native-community/blur": "^4.3.0",
"@react-native-community/slider": "^4.4.2",
"@react-navigation/native": "^6.1.3",
"@react-navigation/native-stack": "^6.9.9",
"react": "^18.2.0",
"react-native": "^0.71.3",
"react-native-gesture-handler": "^2.9.0",
"react-native-pressable-opacity": "^1.0.10",
"react-native-reanimated": "https://github.com/software-mansion/react-native-reanimated#6cf9713a44ec61318bbb12c311f79c08eda95d10",
"react-native-safe-area-context": "^4.5.0",
"react-native-screens": "^3.19.0",
"react-native-static-safe-area-insets": "^2.2.0",
"react-native-vector-icons": "^9.2.0",
"react-native-video": "^5.2.1",
"react-native-worklets": "https://github.com/chrfalch/react-native-worklets#15d52dd"
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/runtime": "^7.20.13",
"@react-native-community/eslint-config": "^3.2.0",
"@react-native-community/eslint-plugin": "^1.3.0",
"@types/react": "^18.0.27",
"@types/react-native": "^0.71.2",
"@types/react-native-vector-icons": "^6.4.13",
"@types/react-native-video": "^5.0.14",
"babel-plugin-module-resolver": "^5.0.0",
"eslint": "^8.33.0",
"metro-config": "^0.75.0",
"metro-react-native-babel-preset": "^0.75.0",
"prettier": "^2.8.4",
"typescript": "^4.9.5"
}
}