Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Camera is exclusively lock to react-native-vision-camera on Android #2149

Closed
3 of 5 tasks
sapjunior opened this issue Nov 10, 2023 · 2 comments · Fixed by #2174
Closed
3 of 5 tasks

🐛 Camera is exclusively lock to react-native-vision-camera on Android #2149

sapjunior opened this issue Nov 10, 2023 · 2 comments · Fixed by #2174
Labels
🐛 bug Something isn't working

Comments

@sapjunior
Copy link

sapjunior commented Nov 10, 2023

What's happening?

Hello, we're encountering an issue with react-native-vision-camera. It appears that when the camera is initiated within the app on Android, the library exclusively locks the camera, preventing other libraries (in same react-native-program) that also require camera access from gaining control.

As an example, we are using both react-native-vision-camera and react-native-torch (utilized for opening the flashlight, which camera permissions on Android).

To replicate the issue:

  1. Open the camera using react-native-vision-camera.
  2. Attempt to activate the flashlight using react-native-torch.
    We got this error message "CAMERA_IN_USE (4): setTorchMode:2122: Torch for camera "0" is not available due to an existing camera user" even if the camera modal/screen is dismissed. (https://github.com/ludo/react-native-torch/blob/957db6330a0afd09455e42ce6537e0ca69518e3c/android/src/main/java/com/cubicphuse/RCTTorch/RCTTorchModule.java#L47)

We suspected that this function (

) is not call at all even the screen dismiss/close, which may make the react-native-vision-camera exclusive lock

If we restart application again without calling the Camera screen, the torch function is working properly. So, we think that the problem comes from react-native-vision-camera exclusively lock the Camera

Reproduceable Code

Example camera code from react-native-vision-camera repos with a single function call to react-native-torch

Relevant log output

Error toggling flashlight Error: CAMERA_IN_USE (4): setTorchMode:2122: Torch for camera "0" is not available due to an existing camera user

Camera Device

{
  "sensorOrientation": "landscape-right",
  "hardwareLevel": "full",
  "maxZoom": 8,
  "minZoom": 1,
  "supportsLowLightBoost": false,
  "neutralZoom": 1,
  "physicalDevices": [
    "wide-angle-camera"
  ],
  "supportsFocus": true,
  "supportsRawCapture": true,
  "isMultiCam": false,
  "name": "BACK (0)",
  "hasFlash": true,
  "hasTorch": true,
  "position": "back",
  "id": "0"
}

Device

Multiple Android Devices (SS Note9/Xiaomi Redmi Note9)

VisionCamera Version

3.6.4

Can you reproduce this issue in the VisionCamera Example app?

Yes, I can reproduce the same issue in the Example app here

Additional information

@SocDario
Copy link

Just a question, are you using torch on some component which don't includes camera? If not try to use torch which is provided from vision-camera.

@mrousavy
Copy link
Owner

Hey! I just found out that I really forgot to close and dispose the locked Camera resources, so I just fixed that in this PR: #2174
Now the Camera fully & synchronously closes all resources (CameraSession, CameraDevice, OpenGL context, Video & Photo outputs, Photo Synchronizer) once the view gets removed from the React view hierarchy ("unmounted"), and things like Flash, Torch, NFC, and other Camera components should be working again.

There is still a small issue that causes once Camera component to turn into a blackscreen when navigating back and forth between two Camera components, that's a pretty rare edge case but I will still try to fix that soon when I have some free time.

If you appreciate my time, expertise and dedication to this project, pleas 💖 consider sponsoring me on GitHub 💖 to support the development of this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants