feat: Split videoHdr and photoHdr into two settings (#2161)

* feat: Split `videoHdr` and `photoHdr` into two settings

* fix: Rename all `hdr`

* fix: Fix HDR on Android

* Update CameraDeviceDetails.kt

* Update CameraDeviceDetails.kt

* fix: Correctly configure `pixelFormat` AFTER `format`

* Update CameraSession+Configuration.swift

* fix: Also after format changed
This commit is contained in:
Marc Rousavy
2023-11-15 18:33:12 +01:00
committed by GitHub
parent 75fd924899
commit c5dfb6c247
26 changed files with 129 additions and 88 deletions

View File

@@ -70,7 +70,8 @@ class CameraView(context: Context) :
var format: ReadableMap? = null
var fps: Int? = null
var videoStabilizationMode: VideoStabilizationMode? = null
var hdr: Boolean? = null // nullable bool
var videoHdr = false
var photoHdr = false
var lowLightBoost: Boolean? = null // nullable bool
// other props
@@ -177,6 +178,10 @@ class CameraView(context: Context) :
// Orientation
config.orientation = orientation
// HDR
config.videoHdr = videoHdr
config.photoHdr = photoHdr
// Format
val format = format
if (format != null) {
@@ -188,7 +193,6 @@ class CameraView(context: Context) :
// Side-Props
config.fps = fps
config.enableLowLightBoost = lowLightBoost ?: false
config.enableHdr = hdr ?: false
config.torch = torch
// Zoom

View File

@@ -107,9 +107,14 @@ class CameraViewManager : ViewGroupManager<CameraView>() {
view.fps = if (fps > 0) fps else null
}
@ReactProp(name = "hdr")
fun setHdr(view: CameraView, hdr: Boolean?) {
view.hdr = hdr
@ReactProp(name = "photoHdr", defaultBoolean = false)
fun setPhotoHdr(view: CameraView, photoHdr: Boolean) {
view.photoHdr = photoHdr
}
@ReactProp(name = "videoHdr", defaultBoolean = false)
fun setVideoHdr(view: CameraView, videoHdr: Boolean) {
view.videoHdr = videoHdr
}
@ReactProp(name = "lowLightBoost")
@@ -117,7 +122,7 @@ class CameraViewManager : ViewGroupManager<CameraView>() {
view.lowLightBoost = lowLightBoost
}
@ReactProp(name = "isActive")
@ReactProp(name = "isActive", defaultBoolean = false)
fun setIsActive(view: CameraView, isActive: Boolean) {
view.isActive = isActive
}

View File

@@ -17,7 +17,10 @@ data class CameraConfiguration(
var photo: Output<Photo> = Output.Disabled.create(),
var video: Output<Video> = Output.Disabled.create(),
var codeScanner: Output<CodeScanner> = Output.Disabled.create(),
var enableHdr: Boolean = false,
// HDR
var videoHdr: Boolean = false,
var photoHdr: Boolean = false,
// Orientation
var orientation: Orientation = Orientation.PORTRAIT,
@@ -87,7 +90,7 @@ data class CameraConfiguration(
val outputsChanged = deviceChanged || // input device
left?.photo != right.photo || left.video != right.video || left.codeScanner != right.codeScanner ||
left.preview != right.preview || // outputs
left.enableHdr != right.enableHdr || left.format != right.format // props that affect the outputs (hdr, format, ..)
left.videoHdr != right.videoHdr || left.photoHdr != right.photoHdr || left.format != right.format // props that affect the outputs
val sidePropsChanged = outputsChanged || // depend on outputs
left?.torch != right.torch || left.enableLowLightBoost != right.enableLowLightBoost || left.fps != right.fps ||

View File

@@ -4,7 +4,6 @@ import android.graphics.ImageFormat
import android.hardware.camera2.CameraCharacteristics
import android.hardware.camera2.CameraManager
import android.hardware.camera2.CameraMetadata
import android.hardware.camera2.params.DynamicRangeProfiles
import android.os.Build
import android.util.Range
import android.util.Size
@@ -90,10 +89,8 @@ class CameraDeviceDetails(private val cameraManager: CameraManager, private val
private fun getHasVideoHdr(): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (capabilities.contains(CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_DYNAMIC_RANGE_TEN_BIT)) {
val availableProfiles = characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES)
?: DynamicRangeProfiles(LongArray(0))
return availableProfiles.supportedProfiles.contains(DynamicRangeProfiles.HLG10) ||
availableProfiles.supportedProfiles.contains(DynamicRangeProfiles.HDR10)
val recommendedHdrProfile = characteristics.get(CameraCharacteristics.REQUEST_RECOMMENDED_TEN_BIT_DYNAMIC_RANGE_PROFILE)
return recommendedHdrProfile != null
}
}
return false
@@ -181,8 +178,8 @@ class CameraDeviceDetails(private val cameraManager: CameraManager, private val
map.putInt("maxFps", fpsRange.upper)
map.putDouble("maxZoom", maxZoom)
map.putDouble("fieldOfView", getMaxFieldOfView())
map.putBoolean("supportsVideoHDR", supportsVideoHdr)
map.putBoolean("supportsPhotoHDR", supportsPhotoHdr)
map.putBoolean("supportsVideoHdr", supportsVideoHdr)
map.putBoolean("supportsPhotoHdr", supportsPhotoHdr)
map.putBoolean("supportsDepthCapture", supportsDepthCapture)
map.putString("autoFocusSystem", AutoFocusSystem.CONTRAST_DETECTION.unionValue)
map.putArray("videoStabilizationModes", createStabilizationModes())

View File

@@ -285,7 +285,7 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
val image = reader.acquireLatestImage()
onPhotoCaptured(image)
}, CameraQueues.cameraQueue.handler)
val output = PhotoOutput(imageReader, configuration.enableHdr)
val output = PhotoOutput(imageReader, configuration.photoHdr)
outputs.add(output.toOutputConfiguration(characteristics))
photoOutput = output
}
@@ -305,7 +305,7 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
isSelfie,
video.config.enableFrameProcessor
)
val output = VideoPipelineOutput(videoPipeline, configuration.enableHdr)
val output = VideoPipelineOutput(videoPipeline, configuration.videoHdr)
outputs.add(output.toOutputConfiguration(characteristics))
videoOutput = output
}
@@ -327,7 +327,7 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
preview.config.surface,
size,
SurfaceOutput.OutputType.PREVIEW,
configuration.enableHdr
configuration.videoHdr
)
outputs.add(output.toOutputConfiguration(characteristics))
previewOutput = output
@@ -398,7 +398,7 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
if (fps != null) {
if (!CAN_DO_60_FPS) {
// If we can't do 60 FPS, we clamp it to 30 FPS - that's always supported.
fps = Math.min(30, fps)
fps = 30.coerceAtMost(fps)
}
captureRequest.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, Range(fps, fps))
}
@@ -427,7 +427,7 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
// Set HDR
// TODO: Check if that value is even supported
if (config.enableHdr) {
if (config.videoHdr) {
captureRequest.set(CaptureRequest.CONTROL_SCENE_MODE, CaptureRequest.CONTROL_SCENE_MODE_HDR)
} else if (config.enableLowLightBoost) {
captureRequest.set(CaptureRequest.CONTROL_SCENE_MODE, CaptureRequest.CONTROL_SCENE_MODE_NIGHT)

View File

@@ -17,8 +17,8 @@ data class CameraDeviceFormat(
val maxZoom: Double,
val videoStabilizationModes: List<VideoStabilizationMode>,
val autoFocusSystem: AutoFocusSystem,
val supportsVideoHDR: Boolean,
val supportsPhotoHDR: Boolean,
val supportsVideoHdr: Boolean,
val supportsPhotoHdr: Boolean,
val pixelFormats: List<PixelFormat>,
val supportsDepthCapture: Boolean
) {
@@ -50,8 +50,8 @@ data class CameraDeviceFormat(
value.getDouble("maxZoom"),
videoStabilizationModes,
autoFocusSystem,
value.getBoolean("supportsVideoHDR"),
value.getBoolean("supportsPhotoHDR"),
value.getBoolean("supportsVideoHdr"),
value.getBoolean("supportsPhotoHdr"),
pixelFormats,
value.getBoolean("supportsDepthCapture")
)