Commit Graph

59 Commits

Author SHA1 Message Date
Marc Rousavy
8d65d1d53c
fix: Fix physical devices detection on Android (#2073)
* fix: Fix physical devices detection on Android

* Update useCameraDevices.ts
2023-10-24 15:42:44 +02:00
Marc Rousavy
8a5dfd6ac6
fix: Fix physicalDevices DeviceType computation on Android (#2072)
* fix: Fix device type calculation on Android

* fix: Type safety for deviceTypes

* fix: Update docs
2023-10-24 14:27:47 +02:00
Marc Rousavy
5b1e5f3c9d
fix: Skip if no Preview Output is attached 2023-10-24 13:58:57 +02:00
Marc Rousavy
0bc3ee12bf
Send onInitialized event only if device changed 2023-10-24 11:59:22 +02:00
Marc Rousavy
de0d6cda5d
feat: Implement atomically single-lock core/ library on Android (#2049)
* feat: Create base for `CameraConfiguration` diff

* Fix

* Write three configure methods

* Build?

* MOre

* Update CameraView+RecordVideo.kt

* Fix errors

* Update CameraDeviceDetails.kt

* Update CameraSession.kt

* Auto-resize Preview View

* More

* Make it work? idk

* Format

* Call `configure` under mutex, and change isActive

* fix: Make Outputs comparable

* fix: Make CodeScanner comparable

* Format

* fix: Update outputs after reconfiguring

* Update CameraPage.tsx

* fix: Close CaptureSession before
2023-10-24 11:19:03 +02:00
Marc Rousavy
217461ff5d
feat: Make Frame Processors work on API <29 (#2041) 2023-10-19 11:47:30 +02:00
Marc Rousavy
07027d8010
fix: Rename getFrameProcessorPlugin to initFrameProcessorPlugin (#2038)
* fix: Rename `getFrameProcessorPlugin` to `initFrameProcessorPlugin`

* fix: Make nullable, add comments

* Format

* Update FrameProcessorPlugin.java

* Update FrameProcessorPlugin.h

* fix: Fix dead links

* Call super constructor

* Update ExampleFrameProcessorPlugin.java

* fix: Init calls
2023-10-19 11:19:47 +02:00
Mateusz Mędrek
a291642c53
feat: Reintroduce Macros for Frame Processor Plugin registration (#2027)
in VisionCamera v1 & v2 there were two ObjC macros that were helping
in creation/registration of Frame Processors, but these were removed with
v3

This PR reintroduces such macros, which will not only make FP development
easier, but also it will also fix issues people had with registration of
Swift Frame Processors (+load vs +initialize issues)

Docs were also updated to reflect that the macros should be used to
correctly initialize and register ObjC/Swift Frame Processors
2023-10-19 10:35:14 +02:00
Marc Rousavy
9573ae19cb
fix: Remove unneeded kotlin-android-extensions dependency (#2034) 2023-10-18 18:22:34 +02:00
Marc Rousavy
e845dc8397
Update .gitattributes 2023-10-18 11:30:01 +02:00
Marc Rousavy
4e1a1fd68b
fix: Rename parsers/ to types/ (#2021)
chore: Rename `parsers/` to `types/`
2023-10-17 11:49:04 +02:00
Marc Rousavy
2af965d1ad
fix: Log in FrameProcessorPluginRegistry (#2012)
* fix: Log when adding Frame Processor Plugin

* fix: Also log on Android

* Add logs in get as well

* fix: Fix string concat on Android
2023-10-16 17:51:18 +02:00
Marc Rousavy
5e20f9c8fa
chore: Rename CodeScanner to CodeScannerOptions in native (#2010)
* chore: Rename `CodeScanner` to `CodeScannerOptions` on native

* chore: Rename `CodeScanner` on iOS

* fix: Unwrap `options`

* Format
2023-10-16 16:56:39 +02:00
Marc Rousavy
e8ae11e30b
fix: Fix CodeScanner stalling on Android (#2009) 2023-10-16 16:28:51 +02:00
Marc Rousavy
e8df7148fa
fix: Run CodeScanner on default queue, fix stalling (#2002)
* fix: Run CodeScanner on default queue, fix stalling

* fix: Use `MAX_IMAGES` of 3
2023-10-14 13:30:21 +02:00
Marc Rousavy
fab5bdc0cd
fix: Fix PreviewView overflowing on Android (#2001)
* fix: Run `addView` on UI Thread

* fix: Fix overflow of PreviewView
2023-10-14 13:17:05 +02:00
Marc Rousavy
cd0b413706
feat: New Core/ library (#1975)
Moves everything Camera related into `core/` / `Core/` so that it is better encapsulated from React Native.

Benefits:

1. Code is much better organized. Should be easier for collaborators now, and cleaner codebase for me.
2. Locking is fully atomically as you can now only configure the session through a lock/Mutex which is batch-overridable
    * On iOS, this makes Camera startup time **MUCH** faster, I measured speedups from **1.5 seconds** to only **240 milliseconds** since we only lock/commit once! 🚀 
    * On Android, this fixes a few out-of-sync/concurrency issues like "Capture Request contains unconfigured Input/Output Surface!" since it is now a single lock-operation! 💪 
3. It is easier to integrate VisionCamera outside of React Native (e.g. Native iOS Apps, NativeScript, Flutter, etc)

With this PR, VisionCamera V3 is up to **7x** faster than V2
2023-10-13 18:33:20 +02:00
Marc Rousavy
18e69269d4
fix: Catch errors in CaptureSession configuration 2023-10-10 19:18:54 +02:00
Marc Rousavy
727fb39f01
fix: Close previous Outputs to free memory 2023-10-10 19:17:36 +02:00
Marc Rousavy
10a44d5b79
fix: Also close outputs in destroy() 2023-10-10 19:10:42 +02:00
Marc Rousavy
bccd73d704
Revert "fix: Close CameraSession in onDetachedFromWindow() (#1962)"
This reverts commit 02726d47f7.
2023-10-10 19:06:06 +02:00
Vahid Hasani
02726d47f7
fix: Close CameraSession in onDetachedFromWindow() (#1962)
* Close camera session in onDetachedFromWindow

* Remove cache folder

---------

Co-authored-by: Marc Rousavy <me@mrousavy.com>
2023-10-10 19:01:54 +02:00
Marc Rousavy
18b30cd073
fix: Always call CaptureSession fully synchronously under Mutex (#1972)
* fix: Always call `CaptureSession` fully synchronously under Mutex

* Update CameraView.kt

* chore: Format
2023-10-10 18:51:46 +02:00
Marc Rousavy
915ef331d3
feat: Extract CodeScannerPipeline & fix stalling (#1971)
* chore: Extract CodeScannerPipeline

* chore: Format

* Update CodeScannerPipeline.kt
2023-10-10 18:51:36 +02:00
Erwan LE PRADO
9d71990570
feat: Activate Torch Mode on Android (#1932) 2023-10-06 14:28:57 +02:00
Marc Rousavy
4cbe8324d5
chore: Replace ' with " 2023-10-06 13:04:34 +02:00
Marc Rousavy
59699929f4 fix: Use minSdkVersion of 26 again 2023-10-05 10:56:30 +02:00
Marc Rousavy
c9795ce767
fix: Fix clean build error (#1924)
Fixes https://github.com/mrousavy/react-native-vision-camera/issues/1915
2023-10-05 10:46:33 +02:00
Marc Rousavy
6640b72a00
feat: Code Scanner API (#1912)
* feat: CodeScanner JS API

* feat: iOS

* Use guard

* Format

* feat: Android base

* fix: Attach Surfaces

* Use isBusy var

* fix: Use separate Queue

* feat: Finish iOS types

* feat: Implement all other code types on Android

* fix: Call JS event

* fix: Pass codetypes on Android

* fix: iOS use Preview coordinate system

* docs: Add comments

* chore: Format code

* Update CameraView+AVCaptureSession.swift

* docs: Add Code Scanner docs

* docs: Update

* feat: Use lazily downloaded model on Android

* Revert changes in CameraPage

* Format

* fix: Fix empty QR codes

* Update README.md
2023-10-04 12:53:52 +02:00
Marc Rousavy
2c08e5ae78 fix: Also clean VisionCamera build cache 2023-10-04 11:11:12 +02:00
Marc Rousavy
4fc8cd2e01 fix: Clean C++ CMake cache (.cxx/) on clean 2023-10-04 11:06:39 +02:00
Marc Rousavy
9a777ba240 fix: Only use supported PixelFormats 2023-10-03 14:05:23 +02:00
Marc Rousavy
224bffd4dc fix: Use dynamic video format 2023-10-03 13:59:19 +02:00
Marc Rousavy
324e269173
fix: Set minSdkVersion to 23 (#1911)
* fix: Set `minSdkVersion` to 21

* sorry I meant 23
2023-10-03 13:52:42 +02:00
Marc Rousavy
8d90dcc476
fix: Make HardwareBuffers compile optionally (opt-out in minSdkVersion <26) (#1910)
* fix: Make HardwareBuffers compile optionally

* chore: Format C++ code

* fix: Fix if
2023-10-03 13:18:41 +02:00
Marc Rousavy
83c0cdb030
fix: Fix CamcorderProfile get crash on Samsung devices (#1907) 2023-10-03 12:04:03 +02:00
Marc Rousavy
be3d802267 chore: Remove unused ImageWriter 2023-09-30 13:01:56 +02:00
Marc Rousavy
2430058cae fix: Fix redeclaration build error on Android 2023-09-30 10:51:32 +02:00
Marc Rousavy
85564d6d02
fix: Remove unused Error codes (#1887)
* fix: Remove unused Errors

* Errors.kt -> CameraError.kt

* fix: remove .system
2023-09-29 21:54:35 +02:00
Marc Rousavy
cf1952d8f7
feat: Use AHardwareBuffer* for frame.toArrayBuffer() (#1888)
* feat: Route images through `ImageWriter` into OpenGL pipeline

* fix: Use RGB format

* fix: Every device supports YUV, RGB and NATIVE

* Update VideoPipeline.kt

* log format

* Plug ImageReader between OpenGL pipeline

* Call Frame Processor

* Format

* Remove logs

* feat: Use `HardwareBuffer` for `toArrayBuffer()`

* Format
2023-09-29 21:54:04 +02:00
Marc Rousavy
954b44810b
feat: Route images through ImageWriter into OpenGL pipeline (#1874)
* feat: Route images through `ImageWriter` into OpenGL pipeline

* fix: Use RGB format

* fix: Every device supports YUV, RGB and NATIVE

* Update VideoPipeline.kt

* log format

* Plug ImageReader between OpenGL pipeline

* Call Frame Processor

* Format

* Remove logs
2023-09-29 21:52:19 +02:00
Marc Rousavy
a1fbba8d66 chore: Fix formatting 2023-09-29 19:42:28 +02:00
Touch Marine
fb812a6618
fix: Incorrect zoom on Android < 11 (#1878)
* fix: Incorrect zoom on Android < 11

Fixes #1865

* Clamp zoom on Android

Some unclamped zoom values crash. For example, zoom={0.5} crashes
(tested on Android 9).

* Extract zoom into an extension (Android)

* Update package/android/src/main/java/com/mrousavy/camera/extensions/CaptureRequest+setZoom.kt

---------

Co-authored-by: Marc Rousavy <marcrousavy@hotmail.com>
2023-09-29 19:41:37 +02:00
Marc Rousavy
902dc634a4
feat: Add customizable Video Bit Rate (videoBitRate) (#1882)
* feat: Add `videoBitRate` option to `RecordVideoOptions`

* feat: Implement `videoBitRate` on iOS

* feat: Implement `videoBitRate` on Android

* chore: Format

* docs: Separate recording and photo docs

* docs: Fix links

* docs: Add docs about bitrate and quality

* docs: Add blob

* fix: Don't use inline style for CI

* fix: Correctly log default bitRate

* fix: Fix typo

* fix: Calculate default bit-rate on Android depending on resolution

* Update RecordingSession.kt
2023-09-29 15:27:09 +02:00
Marc Rousavy
2d66d5893c
docs: New V3 docs for new API (#1842)
* docs: New V3 docs for new API

* fix: Prefer Wide-Angle unless explicitly opted-out

* docs: Update DEVICES

* Finish Devices docs

* Switch links

* Revert "Switch links"

This reverts commit 06f196ae0e67787cbd5768e125be6d0a3cb5bbc9.

* docs: New LIFECYCLE

* docs: New CAPTURING docs

* Update Worklets links

* docs: Update TROUBLESHOOTING and ZOOMING

* fix: Update `getAvailableCameraDevices()` usages

* docs: Update FORMATS

* Update Errors.kt

* docs: Fix broken links

* docs: Update references to old hooks

* docs: Create Frame Processor Tips

* docs: Auto-dark mode

* fix: Fix FPS filter

* feat: Add `'max'` flag to format filter

* fix: Use loop

* fix: Fix bug in `getCameraFormat`

* fix: Find best aspect ratio as well

* fix: Switch between formats on FPS change

* Update FRAME_PROCESSOR_PLUGIN_LIST.mdx

* Add FPS graph explanation

* feat: Support HDR filter

* docs: Add HDR docs

* docs: Add Video Stabilization

* docs: Update Skia docs

* Skia links

* Add Skia labels

* Update SKIA_FRAME_PROCESSORS.mdx

* docs: Add Performance

* Update some wording

* Update headers / and zoom

* Add examples for devices

* fix highlights

* fix: Expose `Frame`

* docs: Update FP docs

* Update links

* Update FRAME_PROCESSOR_CREATE_PLUGIN_IOS.mdx
2023-09-25 12:57:03 +02:00
Marc Rousavy
3169444697
feat: Implement resizeMode prop for iOS (#1838)
* feat: Implement `resizeMode` prop for iOS

- `"cover"`: Keep aspect ratio, but fill entire parent view (centered).
- `"contain"`: Keep aspect ratio, but make sure the entire content is visible even if it introduces additional blank areas (centered).

* chore: Update prop docs

* Update CameraProps.ts

* Lint & Format
2023-09-23 10:14:27 +02:00
Maxime
c0b80b342b
feat: Respect format's aspect ratio in Preview and add resizeMode prop (#1817)
* feat(preview): respect format's aspect ratio

* fix: code guidelines and previewSize in PreviewView

* feat: add resizeMode 'cover' and 'contain' on Android
2023-09-22 17:32:34 +02:00
Marc Rousavy
9add0eb571
feat: Use C++ OpenGL GPU VideoPipeline again (#1836)
1. Reverts 4e96eb77e0 (PR #1789) to bring the C++ OpenGL GPU Pipeline back.
2. Fixes the "initHybrid JNI not found" error by loading the native JNI/C++ library in `VideoPipeline.kt`.

This PR has two downsides:

1. `pixelFormat="yuv"` does not work on Android. OpenGL only works in RGB
2. OpenGL rendering is fast, but it has an overhead. I think for Camera -> Video Recording we shouldn't be using an entire OpenGL rendering pipeline.

The original plan was to use something similar to how it works on iOS by just passing GPU buffers around, but the android.media APIs just aren't as advanced yet. `ImageReader`/`ImageWriter` is way too buggy and doesn't really work with `MediaRecorder`/`MediaCodec`.

This sucks, I hope in the future we can use something like `AHardwareBuffer`s.
2023-09-22 17:22:31 +02:00
Marc Rousavy
aafffa60f6 fix: Fix exposing userPreferredCameraDevice on Android 2023-09-21 17:02:15 +02:00
Marc Rousavy
cf4882b152
feat: Add support for LiDAR, TrueDepth, External (USB) and Continuity Camera Devices (iOS 17) (#1824)
* feat: Add support for LiDAR, TrueDepth, External (USB) and Continuity Camera Devices (iOS 17)

* Rename `devices` -> `physicalDevices`

* fix: Comment out iOS 17 cameras for now

* fix: Move `supportsDepthCapture` to `format`

* fix: Fall back to `wide-angle-camera` for any unknown types

* Update CameraPage.tsx

* `descriptor` -> `physicalDeviceDescriptor`

* Update CameraDevice.ts

* Format

* feat: Expose `userPreferredCameraDevice`

Uses the new iOS 17 API where the user can prefer a default device, otherwise fall back to the first device of the available ones

* fix: Expose as property

* Add TODO comments

* fix: Format code

* fix: Compile below Swift 5.9
2023-09-21 16:29:46 +02:00