How flyskywhy/react-native-uvc-camera works
Project type and purpose
• This is an open-source React Native plugin module (“react-native-uvc-camera”) targeting Android.
• Its purpose is to expose UVC (USB Video Class) camera capture and recording functionality to a React Native app by wrapping native Android/NDK libraries (UVCCamera, libuvccamera, libusb, libuvc, libjpeg-turbo, RapidJSON) behind the React Native bridge.
Top-level components (modules)
• JS Layer (src/*.js, index.js) – the React Native component and API surface.
• Android Java Module (“android”) – React Package, CameraViewManager, RCTCameraModule, UVC camera support (Camera1, Camera2, CameraUvc).
• Shared Java helper library (“usbCameraCommon”) – media encoders, muxers, UVCCamera handlers, view widgets.
• Native C/C++ Library (“libuvccamera”) – JNI wrappers, UVCCamera pipelines, integration of libusb/libuvc/libjpeg-turbo/RapidJSON.
• Example/Test Apps (usbCameraTest*, usbCameraTest0…usbCameraTest8) – sample Android apps illustrating use cases and test harnesses.
Key interactions and data flow
a. React Native JS Component
• Calls native methods via React Native Bridge (RCTBridgeModule).
b. Android Java Module
• Exposes methods & events (takePicture, startPreview, onBarCodeRead, etc.) to JS.
• Manages lifecycle of CameraView (CameraViewManager, RNCameraView).
• Delegates camera startup/stop to UVCCamera APIs.
c. Shared Java Library (usbCameraCommon)
• Handles USB device enumeration, permission requests, UVC camera control (UVCCameraHandler).
• Manages media encoding (MediaVideoEncoder, MediaAudioEncoder) and muxing (MediaMuxerWrapper).
d. JNI / Native Layer (libuvccamera)
• Provides native entrypoints (ndkBuild) to compile UVCCamera & its dependencies.
• Implements buffered pipelines (PreviewPipeline, CallbackPipeline, SQLiteBufferedPipeline) for frame processing.
• Integrates libusb for device communication, libuvc for UVC protocols, libjpeg-turbo for JPEG encoding, RapidJSON for JSON config/diagnostics.
e. Android USB Stack & Hardware
• The Android OS USB manager grants access to UVC device nodes.
• libusb communicates with USB endpoints; libuvc implements UVC control & streaming.
• Frames pass through C++ pipelines back to Java via JNI callbacks, then to JS events.
Architectural patterns & design principles
• Layered architecture: UI (JS) → Bridge → Java API → JNI → Native C/C++ → OS/Hardware.
• Separation of concerns:
• JS layer purely UI & API calls, no native details.
• Java layer handles Android lifecycle, permissions, basic camera control.
• Shared library isolates encoding & view abstractions.
• Native C/C++ layer focuses on device protocols & high-performance pipeline.
• Plugin pattern: Gradle multi-project with Android modules plugged into host application.
• JNI boundary clearly defined: thin Java wrappers invoking ndkBuild-compiled libs.