Skip to content

Commit 729f8a7

Browse files
Merge pull request #2 from baronapp/2022-04-19/upstream-merge
2022 04 19/upstream merge
2 parents 4b88d93 + b1bcbca commit 729f8a7

23 files changed

+2727
-2533
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# README
22

3+
<h1 align="center">Vision Camera</h1>
4+
35
This is a public copy of the repo we're holding onto just to receive emails when the original repo is changed.

android/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ target_include_directories(
6161
${INCLUDE_JSI_CPP} # only on older RN versions
6262
${INCLUDE_JSIDYNAMIC_CPP} # only on older RN versions
6363
# --- Reanimated ---
64+
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/AnimatedSensor"
6465
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/Tools"
6566
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/SpecTools"
6667
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/SharedItems"

android/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,13 @@ dependencies {
246246
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.5.2"
247247
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2"
248248

249-
implementation "androidx.camera:camera-core:1.1.0-alpha12"
250-
implementation "androidx.camera:camera-camera2:1.1.0-alpha12"
251-
implementation "androidx.camera:camera-lifecycle:1.1.0-alpha12"
252-
implementation "androidx.camera:camera-video:1.1.0-alpha12"
249+
implementation "androidx.camera:camera-core:1.1.0-beta02"
250+
implementation "androidx.camera:camera-camera2:1.1.0-beta02"
251+
implementation "androidx.camera:camera-lifecycle:1.1.0-beta02"
252+
implementation "androidx.camera:camera-video:1.1.0-beta02"
253253

254-
implementation "androidx.camera:camera-view:1.0.0-alpha32"
255-
implementation "androidx.camera:camera-extensions:1.0.0-alpha32"
254+
implementation "androidx.camera:camera-view:1.1.0-beta02"
255+
implementation "androidx.camera:camera-extensions:1.1.0-beta02"
256256

257257
implementation "androidx.exifinterface:exifinterface:1.3.3"
258258
}

android/src/main/java/com/mrousavy/camera/CameraView+Focus.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.mrousavy.camera
22

33
import androidx.camera.core.FocusMeteringAction
4-
import androidx.camera.core.SurfaceOrientedMeteringPointFactory
54
import com.facebook.react.bridge.ReadableMap
65
import kotlinx.coroutines.guava.await
6+
import kotlinx.coroutines.withContext
77
import java.util.concurrent.TimeUnit
88

99
suspend fun CameraView.focus(pointMap: ReadableMap) {
@@ -16,8 +16,11 @@ suspend fun CameraView.focus(pointMap: ReadableMap) {
1616
val x = pointMap.getDouble("x") * dpi
1717
val y = pointMap.getDouble("y") * dpi
1818

19-
val factory = SurfaceOrientedMeteringPointFactory(this.width.toFloat(), this.height.toFloat())
20-
val point = factory.createPoint(x.toFloat(), y.toFloat())
19+
// Getting the point from the previewView needs to be run on the UI thread
20+
val point = withContext(coroutineScope.coroutineContext) {
21+
previewView.meteringPointFactory.createPoint(x.toFloat(), y.toFloat());
22+
}
23+
2124
val action = FocusMeteringAction.Builder(point, FocusMeteringAction.FLAG_AF or FocusMeteringAction.FLAG_AE)
2225
.setAutoCancelDuration(5, TimeUnit.SECONDS) // auto-reset after 5 seconds
2326
.build()

android/src/main/java/com/mrousavy/camera/CameraView+RecordVideo.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,30 @@ fun CameraView.startRecording(options: ReadableMap, onRecordCallback: Callback)
8282
})
8383
}
8484

85+
@SuppressLint("RestrictedApi")
86+
fun CameraView.pauseRecording() {
87+
if (videoCapture == null) {
88+
throw CameraNotReadyError()
89+
}
90+
if (activeVideoRecording == null) {
91+
throw NoRecordingInProgressError()
92+
}
93+
94+
activeVideoRecording!!.pause()
95+
}
96+
97+
@SuppressLint("RestrictedApi")
98+
fun CameraView.resumeRecording() {
99+
if (videoCapture == null) {
100+
throw CameraNotReadyError()
101+
}
102+
if (activeVideoRecording == null) {
103+
throw NoRecordingInProgressError()
104+
}
105+
106+
activeVideoRecording!!.resume()
107+
}
108+
85109
@SuppressLint("RestrictedApi")
86110
fun CameraView.stopRecording() {
87111
if (videoCapture == null) {

android/src/main/java/com/mrousavy/camera/CameraView+TakeSnapshot.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ suspend fun CameraView.takeSnapshot(options: ReadableMap): WritableMap = corouti
2222
camera.cameraControl.enableTorch(true).await()
2323
}
2424

25-
val bitmap = this@takeSnapshot.previewView.bitmap ?: throw CameraNotReadyError()
25+
val bitmap = withContext(coroutineScope.coroutineContext) {
26+
previewView.bitmap ?: throw CameraNotReadyError()
27+
}
2628

2729
val quality = if (options.hasKey("quality")) options.getInt("quality") else 100
2830

android/src/main/java/com/mrousavy/camera/CameraView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class CameraView(context: Context, private val frameProcessorThread: ExecutorSer
121121
private val cameraExecutor = Executors.newSingleThreadExecutor()
122122
internal val takePhotoExecutor = Executors.newSingleThreadExecutor()
123123
internal val recordVideoExecutor = Executors.newSingleThreadExecutor()
124-
private var coroutineScope = CoroutineScope(Dispatchers.Main)
124+
internal var coroutineScope = CoroutineScope(Dispatchers.Main)
125125

126126
internal var camera: Camera? = null
127127
internal var imageCapture: ImageCapture? = null

android/src/main/java/com/mrousavy/camera/CameraViewModule.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,24 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase
115115
}
116116
}
117117

118+
@ReactMethod
119+
fun pauseRecording(viewTag: Int, promise: Promise) {
120+
withPromise(promise) {
121+
val view = findCameraView(viewTag)
122+
view.pauseRecording()
123+
return@withPromise null
124+
}
125+
}
126+
127+
@ReactMethod
128+
fun resumeRecording(viewTag: Int, promise: Promise) {
129+
withPromise(promise) {
130+
val view = findCameraView(viewTag)
131+
view.resumeRecording()
132+
return@withPromise null
133+
}
134+
}
135+
118136
@ReactMethod
119137
fun stopRecording(viewTag: Int, promise: Promise) {
120138
withPromise(promise) {

android/src/main/java/com/mrousavy/camera/frameprocessor/FrameProcessorRuntimeManager.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.facebook.jni.HybridData
66
import com.facebook.proguard.annotations.DoNotStrip
77
import com.facebook.react.bridge.ReactApplicationContext
88
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
9+
import com.facebook.react.uimanager.UIManagerHelper
910
import com.mrousavy.camera.CameraView
1011
import com.mrousavy.camera.ViewNotFoundError
1112
import java.lang.ref.WeakReference
@@ -60,7 +61,8 @@ class FrameProcessorRuntimeManager(context: ReactApplicationContext, frameProces
6061
@Keep
6162
fun findCameraViewById(viewId: Int): CameraView {
6263
Log.d(TAG, "Finding view $viewId...")
63-
val view = mContext?.get()?.currentActivity?.findViewById<CameraView>(viewId)
64+
val ctx = mContext?.get()
65+
val view = if (ctx != null) UIManagerHelper.getUIManager(ctx, viewId)?.resolveView(viewId) as CameraView? else null
6466
Log.d(TAG, if (view != null) "Found view $viewId!" else "Couldn't find view $viewId!")
6567
return view ?: throw ViewNotFoundError(viewId)
6668
}

docs/docs/guides/FRAME_PROCESSOR_PLUGIN_LIST.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ You have to restart metro-bundler for changes in the `babel.config.js` file to t
2525
* [mrousavy/**vision-camera-image-labeler**](https://github.com/mrousavy/vision-camera-image-labeler): A plugin to label images using MLKit Vision Image Labeler.
2626
* [mrousavy/**vision-camera-resize-plugin**](https://github.com/mrousavy/vision-camera-resize-plugin): A plugin for fast frame resizing to optimize execution speed of expensive AI algorithms.
2727
* [rodgomesc/**vision-camera-face-detector**](https://github.com/rodgomesc/vision-camera-face-detector): A plugin to detect faces using MLKit Vision Face Detector.
28-
* [rodgomesc/**vision-camera-ocr**](https://github.com/rodgomesc/vision-camera-ocr): A plugin to recognize text in any Latin-based character set using MLKit Text Recognition.
2928
* [rodgomesc/**vision-camera-qrcode-scanner**](https://github.com/rodgomesc/vision-camera-qrcode-scanner): A plugin to read barcodes using MLKit Vision QrCode Scanning
3029
* [mrousavy/**Colorwaver**](https://github.com/mrousavy/Colorwaver): An app (+ plugin) to detect color palettes in the real world.
3130
* [xulihang/**vision-camera-dynamsoft-barcode-reader**](https://github.com/xulihang/vision-camera-dynamsoft-barcode-reader): A plugin to read barcodes using Dynamsoft Barcode Reader.
31+
* [aarongrider/**vision-camera-ocr**](https://github.com/aarongrider/vision-camera-ocr): A plugin to detect text in real time using MLKit Text Detector (OCR).
32+
3233

3334

3435

0 commit comments

Comments
 (0)