Skip to content

Commit

Permalink
Log if optimized usecase is used
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Aug 2, 2023
1 parent 3eb7a48 commit 1ff083d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,6 @@ fun supportsOutputType(characteristics: CameraCharacteristics, outputType: Outpu
return false
}

fun getMaxRecordResolution(cameraId: String): Size {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val profiles = CamcorderProfile.getAll(cameraId, CamcorderProfile.QUALITY_HIGH)
val highestProfile = profiles?.videoProfiles?.maxBy { it.width * it.height }
if (highestProfile != null) {
return Size(highestProfile.width, highestProfile.height)
}
}
// fallback: old API
val cameraIdInt = cameraId.toIntOrNull()
val camcorderProfile = if (cameraIdInt != null) {
CamcorderProfile.get(cameraIdInt, CamcorderProfile.QUALITY_HIGH)
} else {
CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)
}
return Size(camcorderProfile.videoFrameWidth, camcorderProfile.videoFrameHeight)
}

fun getMaxPreviewResolution(): Size {
val display = Resources.getSystem().displayMetrics
// According to Android documentation, "PREVIEW" size is always limited to 1920x1080
return Size(1920.coerceAtMost(display.widthPixels), 1080.coerceAtMost(display.widthPixels))
}

fun getMaxMaximumResolution(format: Int, characteristics: CameraCharacteristics): Size {
val config = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)!!
return config.getOutputSizes(format).maxBy { it.width * it.height }
}

suspend fun CameraDevice.createCaptureSession(cameraManager: CameraManager, sessionType: SessionType, outputs: List<SurfaceOutput>, queue: CameraQueues.CameraQueue): CameraCaptureSession {
return suspendCoroutine { continuation ->

Expand All @@ -119,9 +90,6 @@ suspend fun CameraDevice.createCaptureSession(cameraManager: CameraManager, sess
}
}

val recordSize = getMaxRecordResolution(this.id)
val previewSize = getMaxPreviewResolution()

val characteristics = cameraManager.getCameraCharacteristics(this.id)
val hardwareLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)!!
Log.i(CameraView.TAG, "Creating Capture Session on ${parseHardwareLevel(hardwareLevel)} device...")
Expand All @@ -135,6 +103,7 @@ suspend fun CameraDevice.createCaptureSession(cameraManager: CameraManager, sess
if (it.dynamicRangeProfile != null) result.dynamicRangeProfile = it.dynamicRangeProfile
if (supportsOutputType(characteristics, it.outputType)) {
result.streamUseCase = it.outputType.toOutputType()
Log.i(CameraView.TAG, "Using optimized stream use case \"${it.outputType.name}\" (${result.streamUseCase})..")
}
}
return@map result
Expand Down
4 changes: 1 addition & 3 deletions example/src/CameraPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export function CameraPage({ navigation }: Props): React.ReactElement {
if (device != null && format != null) {
console.log(
`Re-rendering camera page with ${isActive ? 'active' : 'inactive'} camera. ` +
`Device: "${device.name}" (${format.photoWidth}x${format.photoHeight} @ ${fps}fps)`,
`Device: "${device.name}" (${format.photoWidth}x${format.photoHeight} photo / ${format.videoWidth}x${format.videoHeight} video @ ${fps}fps)`,
);
} else {
console.log('re-rendering camera page without active camera');
Expand Down Expand Up @@ -224,8 +224,6 @@ export function CameraPage({ navigation }: Props): React.ReactElement {
console.log(frame.timestamp, frame.toString(), frame.pixelFormat);
}, []);

console.log(JSON.stringify(device));

return (
<View style={styles.container}>
{device != null && (
Expand Down

0 comments on commit 1ff083d

Please sign in to comment.