-
-
Notifications
You must be signed in to change notification settings - Fork 172
Description
Camera device not fully released after stop_stream() on macOS - Firefox cannot detect release
Description
When using the AVFoundation backend on macOS, the camera hardware is not properly released after calling stop_stream(). While most applications (Chrome, Safari, other browsers) correctly detect that the camera is available, Firefox specifically cannot access the camera until the Rust process exits.
This indicates that stop_stream() is not properly releasing the camera at the OS level.
Environment
- OS: macOS
- Nokhwa version: 0.10.10
- Backend: AVFoundation
- Rust version: 1.83+
Steps to Reproduce
- Start a Rust application using nokhwa camera
- Call
camera.open_stream() - Call
camera.stop_stream()anddrop(camera) - Try to access the camera from Firefox (e.g., webrtc.github.io/samples)
Expected behavior: Firefox should immediately detect the camera is available.
Actual behavior:
- ✅ The same Rust process can restart and reuse the camera
- ✅ Chrome, Safari, other browsers can access the camera
- ❌ Firefox cannot access the camera
- ✅ After Rust process exits, Firefox can access the camera
Why This Matters
Firefox appears to be more strict about camera ownership detection than other browsers. The fact that Firefox CAN access the
5B4A
camera immediately after the process exits (but NOT after stop_stream()) proves that stop_stream() is not properly releasing the camera at the OS/system level.
Investigation
After stop_stream() and Drop, the AVFoundation objects have high retain counts:
AVCaptureDevice: retainCount = 12 → 11 (after release)AVCaptureDeviceInput: retainCount = 7 → 6 (after release)AVCaptureSession: retainCount = 2 → 1 (after release)AVCaptureVideoDataOutput: retainCount = 3 → 2 (after release)
The retain counts remain > 0, meaning the objects are still alive and the camera may still be marked as "in use" by the process at some system level that Firefox checks.
Impact
Users cannot:
- Immediately switch to Firefox for web calls
They must force-quit the Rust app for Firefox to work.