feat: Separate usecases (decouple microphone, video, photo) (#168)
* Add props * add props (iOS) * Add use-cases conditionally * Update CameraView+RecordVideo.swift * Update RecordingSession.swift * reconfigure on change * Throw correct errors * Check for audio permission * Move `#if` outward * Throw appropriate errors * Update CameraView+RecordVideo.swift * fix Splashscreen * Dynamic filePath * Fix video extension * add `avci` and `m4v` file types * Fix RecordVideo errors * Fix audio setup * Enable `photo`, `video` and `audio` * Check for `video={true}` in frameProcessor * format * Remove unused DispatchQueue * Update docs * Add `supportsPhotoAndVideoCapture` * Fix view manager * Fix error not being propagated * Catch normal errors too * Update DEVICES.mdx * Update CAPTURING.mdx * Update classdocs
This commit is contained in:
@@ -358,6 +358,13 @@ export class Camera extends React.PureComponent<CameraProps> {
|
||||
this.assertFrameProcessorsEnabled();
|
||||
// frameProcessor argument changed. Update native to reflect the change.
|
||||
if (this.props.frameProcessor != null) {
|
||||
if (this.props.video !== true) {
|
||||
throw new CameraCaptureError(
|
||||
'capture/video-not-enabled',
|
||||
'Video capture is disabled! Pass `video={true}` to enable frame processors.',
|
||||
);
|
||||
}
|
||||
|
||||
// 1. Spawn threaded JSI Runtime (if not already done)
|
||||
// 2. Add video data output to Camera stream (if not already done)
|
||||
// 3. Workletize the frameProcessor and prepare it for being called with frames
|
||||
|
@@ -250,6 +250,28 @@ export interface CameraDevice {
|
||||
* See [the Camera Formats documentation](https://cuvent.github.io/react-native-vision-camera/docs/guides/formats) for more information about Camera Formats.
|
||||
*/
|
||||
formats: CameraDeviceFormat[];
|
||||
/**
|
||||
* Whether this camera device supports enabling photo and video capture at the same time.
|
||||
*
|
||||
* * On **iOS** devices this value is always `true`.
|
||||
* * On newer **Android** devices this value is always `true`.
|
||||
* * On older **Android** devices this value is `true` if the device's hardware level is `LIMITED` and above, `false` otherwise. (`LEGACY`) (See [this table](https://developer.android.com/reference/android/hardware/camera2/CameraDevice#regular-capture))
|
||||
*
|
||||
* If the device does not allow enabling `photo` and `video` capture at the same time, you might want to fall back to **snapshot capture** (See ["Taking Snapshots"](https://cuvent.github.io/react-native-vision-camera/docs/guides/capturing#taking-snapshots)) instead:
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const captureMode = device.supportsPhotoAndVideoCapture ? "photo" : "snapshot"
|
||||
* return (
|
||||
* <Camera
|
||||
* photo={captureMode === "photo"}
|
||||
* video={true}
|
||||
* audio={true}
|
||||
* />
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
supportsPhotoAndVideoCapture: boolean;
|
||||
/**
|
||||
* Whether this camera device supports low light boost.
|
||||
*/
|
||||
|
@@ -37,6 +37,8 @@ export type CaptureError =
|
||||
| 'capture/invalid-photo-codec'
|
||||
| 'capture/not-bound-error'
|
||||
| 'capture/capture-type-not-supported'
|
||||
| 'capture/video-not-enabled'
|
||||
| 'capture/photo-not-enabled'
|
||||
| 'capture/unknown';
|
||||
export type SystemError = 'system/no-camera-manager';
|
||||
export type UnknownError = 'unknown/unknown';
|
||||
|
@@ -34,6 +34,22 @@ export interface CameraProps extends ViewProps {
|
||||
*/
|
||||
isActive: boolean;
|
||||
|
||||
//#region Use-cases
|
||||
/**
|
||||
* * Enables **photo capture** with the `takePhoto` function (see ["Taking Photos"](https://cuvent.github.io/react-native-vision-camera/docs/guides/capturing#taking-photos))
|
||||
*/
|
||||
photo?: boolean;
|
||||
/**
|
||||
* * Enables **video capture** with the `startRecording` function (see ["Recording Videos"](https://cuvent.github.io/react-native-vision-camera/docs/guides/capturing/#recording-videos))
|
||||
* * Enables **frame processing** (see ["Frame Processors"](https://cuvent.github.io/react-native-vision-camera/docs/guides/frame-processors))
|
||||
*/
|
||||
video?: boolean;
|
||||
/**
|
||||
* * Enables **audio capture** for video recordings (see ["Recording Videos"](https://cuvent.github.io/react-native-vision-camera/docs/guides/capturing/#recording-videos))
|
||||
*/
|
||||
audio?: boolean;
|
||||
//#endregion
|
||||
|
||||
//#region Common Props (torch, zoom)
|
||||
/**
|
||||
* Set the current torch mode.
|
||||
|
@@ -2,10 +2,6 @@
|
||||
* A single frame, as seen by the camera.
|
||||
*/
|
||||
export interface Frame {
|
||||
/**
|
||||
* The raw pixel buffer.
|
||||
*/
|
||||
buffer: unknown[];
|
||||
/**
|
||||
* Whether the underlying buffer is still valid or not. The buffer will be released after the frame processor returns.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user