chore(deps): upgrade camerax (#257)
* Upgrade CameraX to alpha6 * Upgrade CameraX extensions to alpha26 * `init` -> `getInstance` * Use new Extensions API * Update CameraView.kt * use new ExtensionsManager API in `getAvailableCameraDevices()` * fix cpplint errors
This commit is contained in:
parent
aa9132b527
commit
1e64215d37
@ -234,11 +234,11 @@ dependencies {
|
|||||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.5.0"
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.5.0"
|
||||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0"
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0"
|
||||||
|
|
||||||
implementation "androidx.camera:camera-core:1.1.0-alpha05"
|
implementation "androidx.camera:camera-core:1.1.0-alpha06"
|
||||||
implementation "androidx.camera:camera-camera2:1.1.0-alpha05"
|
implementation "androidx.camera:camera-camera2:1.1.0-alpha06"
|
||||||
implementation "androidx.camera:camera-lifecycle:1.1.0-alpha05"
|
implementation "androidx.camera:camera-lifecycle:1.1.0-alpha06"
|
||||||
implementation "androidx.camera:camera-extensions:1.0.0-alpha25"
|
implementation "androidx.camera:camera-extensions:1.0.0-alpha26"
|
||||||
implementation "androidx.camera:camera-view:1.0.0-alpha25"
|
implementation "androidx.camera:camera-view:1.0.0-alpha26"
|
||||||
implementation "androidx.exifinterface:exifinterface:1.3.2"
|
implementation "androidx.exifinterface:exifinterface:1.3.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ struct JImageProxy : public facebook::jni::JavaClass<JImageProxy> {
|
|||||||
int getPlaneCount();
|
int getPlaneCount();
|
||||||
int getBytesPerRow();
|
int getBytesPerRow();
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace vision
|
} // namespace vision
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <fbjni/fbjni.h>
|
#include <fbjni/fbjni.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "JImageProxy.h"
|
#include "JImageProxy.h"
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ class JSI_EXPORT JImageProxyHostObject : public jsi::HostObject {
|
|||||||
private:
|
private:
|
||||||
static auto constexpr TAG = "VisionCamera";
|
static auto constexpr TAG = "VisionCamera";
|
||||||
|
|
||||||
void assertIsFrameStrong(jsi::Runtime& runtime, const std::string& accessedPropName);
|
void assertIsFrameStrong(jsi::Runtime& runtime, const std::string& accessedPropName); // NOLINT(runtime/references)
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace vision
|
} // namespace vision
|
||||||
|
@ -13,10 +13,7 @@ import android.widget.FrameLayout
|
|||||||
import androidx.camera.camera2.interop.Camera2Interop
|
import androidx.camera.camera2.interop.Camera2Interop
|
||||||
import androidx.camera.core.*
|
import androidx.camera.core.*
|
||||||
import androidx.camera.core.impl.*
|
import androidx.camera.core.impl.*
|
||||||
import androidx.camera.extensions.HdrImageCaptureExtender
|
import androidx.camera.extensions.*
|
||||||
import androidx.camera.extensions.HdrPreviewExtender
|
|
||||||
import androidx.camera.extensions.NightImageCaptureExtender
|
|
||||||
import androidx.camera.extensions.NightPreviewExtender
|
|
||||||
import androidx.camera.lifecycle.ProcessCameraProvider
|
import androidx.camera.lifecycle.ProcessCameraProvider
|
||||||
import androidx.camera.view.PreviewView
|
import androidx.camera.view.PreviewView
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
@ -102,6 +99,7 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
|
|||||||
internal var imageCapture: ImageCapture? = null
|
internal var imageCapture: ImageCapture? = null
|
||||||
internal var videoCapture: VideoCapture? = null
|
internal var videoCapture: VideoCapture? = null
|
||||||
internal var imageAnalysis: ImageAnalysis? = null
|
internal var imageAnalysis: ImageAnalysis? = null
|
||||||
|
private var extensionsManager: ExtensionsManager? = null
|
||||||
|
|
||||||
private val scaleGestureListener: ScaleGestureDetector.SimpleOnScaleGestureListener
|
private val scaleGestureListener: ScaleGestureDetector.SimpleOnScaleGestureListener
|
||||||
private val scaleGestureDetector: ScaleGestureDetector
|
private val scaleGestureDetector: ScaleGestureDetector
|
||||||
@ -303,7 +301,21 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
|
|||||||
// Used to bind the lifecycle of cameras to the lifecycle owner
|
// Used to bind the lifecycle of cameras to the lifecycle owner
|
||||||
val cameraProvider = ProcessCameraProvider.getInstance(reactContext).await()
|
val cameraProvider = ProcessCameraProvider.getInstance(reactContext).await()
|
||||||
|
|
||||||
val cameraSelector = CameraSelector.Builder().byID(cameraId!!).build()
|
var cameraSelector = CameraSelector.Builder().byID(cameraId!!).build()
|
||||||
|
|
||||||
|
val tryEnableExtension: (suspend (extension: Int) -> Unit) = lambda@ { extension ->
|
||||||
|
if (extensionsManager == null) {
|
||||||
|
Log.i(TAG, "Initializing ExtensionsManager...")
|
||||||
|
extensionsManager = ExtensionsManager.getInstance(context).await()
|
||||||
|
}
|
||||||
|
if (extensionsManager!!.isExtensionAvailable(cameraProvider, cameraSelector, extension)) {
|
||||||
|
Log.i(TAG, "Enabling extension $extension...")
|
||||||
|
cameraSelector = extensionsManager!!.getExtensionEnabledCameraSelector(cameraProvider, cameraSelector, extension)
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Extension $extension is not available for the given Camera!")
|
||||||
|
throw HdrNotContainedInFormatError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val rotation = previewView.display.rotation
|
val rotation = previewView.display.rotation
|
||||||
|
|
||||||
@ -349,38 +361,11 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
|
|||||||
throw FpsNotContainedInFormatError(fps)
|
throw FpsNotContainedInFormatError(fps)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hdr?.let { hdr ->
|
if (hdr == true) {
|
||||||
// Enable HDR scene mode if set
|
tryEnableExtension(ExtensionMode.HDR)
|
||||||
if (hdr) {
|
|
||||||
val imageExtension = HdrImageCaptureExtender.create(imageCaptureBuilder)
|
|
||||||
val previewExtension = HdrPreviewExtender.create(previewBuilder)
|
|
||||||
val isExtensionAvailable = imageExtension.isExtensionAvailable(cameraSelector) &&
|
|
||||||
previewExtension.isExtensionAvailable(cameraSelector)
|
|
||||||
if (isExtensionAvailable) {
|
|
||||||
Log.i(TAG, "Enabling native HDR extension...")
|
|
||||||
imageExtension.enableExtension(cameraSelector)
|
|
||||||
previewExtension.enableExtension(cameraSelector)
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "Native HDR vendor extension not available!")
|
|
||||||
throw HdrNotContainedInFormatError()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
lowLightBoost?.let { lowLightBoost ->
|
if (lowLightBoost == true) {
|
||||||
if (lowLightBoost) {
|
tryEnableExtension(ExtensionMode.NIGHT)
|
||||||
val imageExtension = NightImageCaptureExtender.create(imageCaptureBuilder)
|
|
||||||
val previewExtension = NightPreviewExtender.create(previewBuilder)
|
|
||||||
val isExtensionAvailable = imageExtension.isExtensionAvailable(cameraSelector) &&
|
|
||||||
previewExtension.isExtensionAvailable(cameraSelector)
|
|
||||||
if (isExtensionAvailable) {
|
|
||||||
Log.i(TAG, "Enabling native night-mode extension...")
|
|
||||||
imageExtension.enableExtension(cameraSelector)
|
|
||||||
previewExtension.enableExtension(cameraSelector)
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "Native night-mode vendor extension not available!")
|
|
||||||
throw LowLightBoostNotContainedInFormatError()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,10 +8,8 @@ import android.hardware.camera2.CameraManager
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.camera.core.CameraSelector
|
import androidx.camera.core.CameraSelector
|
||||||
import androidx.camera.core.ImageCapture
|
import androidx.camera.extensions.ExtensionMode
|
||||||
import androidx.camera.extensions.ExtensionsManager
|
import androidx.camera.extensions.ExtensionsManager
|
||||||
import androidx.camera.extensions.HdrImageCaptureExtender
|
|
||||||
import androidx.camera.extensions.NightImageCaptureExtender
|
|
||||||
import androidx.camera.lifecycle.ProcessCameraProvider
|
import androidx.camera.lifecycle.ProcessCameraProvider
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import com.facebook.react.bridge.*
|
import com.facebook.react.bridge.*
|
||||||
@ -127,8 +125,8 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase
|
|||||||
val startTime = System.currentTimeMillis()
|
val startTime = System.currentTimeMillis()
|
||||||
GlobalScope.launch(Dispatchers.Main) {
|
GlobalScope.launch(Dispatchers.Main) {
|
||||||
withPromise(promise) {
|
withPromise(promise) {
|
||||||
// I need to init those because the HDR/Night Mode Extension expects them to be initialized
|
val extensionsManager = ExtensionsManager.getInstance(reactApplicationContext).await()
|
||||||
ExtensionsManager.init(reactApplicationContext).await()
|
val cameraProvider = ProcessCameraProvider.getInstance(reactApplicationContext).await()
|
||||||
ProcessCameraProvider.getInstance(reactApplicationContext).await()
|
ProcessCameraProvider.getInstance(reactApplicationContext).await()
|
||||||
|
|
||||||
val manager = reactApplicationContext.getSystemService(Context.CAMERA_SERVICE) as? CameraManager
|
val manager = reactApplicationContext.getSystemService(Context.CAMERA_SERVICE) as? CameraManager
|
||||||
@ -138,8 +136,6 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase
|
|||||||
|
|
||||||
manager.cameraIdList.forEach loop@{ id ->
|
manager.cameraIdList.forEach loop@{ id ->
|
||||||
val cameraSelector = CameraSelector.Builder().byID(id).build()
|
val cameraSelector = CameraSelector.Builder().byID(id).build()
|
||||||
// TODO: ImageCapture.Builder - I'm not setting the target resolution, does that matter?
|
|
||||||
val imageCaptureBuilder = ImageCapture.Builder()
|
|
||||||
|
|
||||||
val characteristics = manager.getCameraCharacteristics(id)
|
val characteristics = manager.getCameraCharacteristics(id)
|
||||||
val hardwareLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)!!
|
val hardwareLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)!!
|
||||||
@ -166,10 +162,8 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase
|
|||||||
else null
|
else null
|
||||||
val fpsRanges = characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES)!!
|
val fpsRanges = characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES)!!
|
||||||
|
|
||||||
val hdrExtension = HdrImageCaptureExtender.create(imageCaptureBuilder)
|
val supportsHdr = extensionsManager.isExtensionAvailable(cameraProvider, cameraSelector, ExtensionMode.HDR)
|
||||||
val supportsHdr = hdrExtension.isExtensionAvailable(cameraSelector)
|
val supportsLowLightBoost = extensionsManager.isExtensionAvailable(cameraProvider, cameraSelector, ExtensionMode.NIGHT)
|
||||||
val nightExtension = NightImageCaptureExtender.create(imageCaptureBuilder)
|
|
||||||
val supportsLowLightBoost = nightExtension.isExtensionAvailable(cameraSelector)
|
|
||||||
// see https://developer.android.com/reference/android/hardware/camera2/CameraDevice#regular-capture
|
// see https://developer.android.com/reference/android/hardware/camera2/CameraDevice#regular-capture
|
||||||
val supportsParallelVideoProcessing = hardwareLevel != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY && hardwareLevel != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED
|
val supportsParallelVideoProcessing = hardwareLevel != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY && hardwareLevel != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user