fix(camera): verify system preview parameters in isolated code5 probe
This commit is contained in:
@@ -48,6 +48,7 @@ data class DiagnosticReportInfo(
|
||||
val cameraProbeStage: CameraProbeStage=CameraProbeStage.IDLE,
|
||||
val cameraProbeEntryFailure: CameraProbeFailure=CameraProbeFailure.NONE,
|
||||
val cameraProbes: List<CameraProbeResult> = emptyList(),
|
||||
val cameraProbeModes: List<CameraProbeMode> = CameraProbeMode.STANDARD_MODES,
|
||||
val cameraProbeIsolated: Boolean=false,
|
||||
val cameraProbeRunLimitMs: Int=8000,val cameraProbeCloseLimitMs: Int=8000,
|
||||
val cameraProbeExitLimitMs: Int=0,
|
||||
@@ -91,7 +92,9 @@ object DiagnosticReportUpload {
|
||||
.put("result_acks",t.resultAcks).put("result_code",t.resultCode).put("consumer_closed",t.closed)
|
||||
private fun probeReport(info: DiagnosticReportInfo): JSONObject {
|
||||
val rows=JSONArray()
|
||||
info.cameraProbes.take(CameraProbeMode.entries.size).forEach {r->rows.put(JSONObject()
|
||||
val planned=info.cameraProbeModes.distinct().take(CameraProbeMode.entries.size)
|
||||
val results=info.cameraProbes.filter {it.mode in planned}.take(planned.size)
|
||||
results.forEach {r->rows.put(JSONObject()
|
||||
.put("native_operation",r.nativeOperation.name.lowercase()).put("native_call_state",r.nativeCallState.name.lowercase())
|
||||
.put("native_call_started_ms",r.nativeCallStartedMs).put("native_call_returned_ms",r.nativeCallReturnedMs)
|
||||
.put("initial_failure",r.initialFailure.name.lowercase())
|
||||
@@ -103,9 +106,15 @@ object DiagnosticReportUpload {
|
||||
.put("surface_requested_width",r.surfaceRequestedWidth).put("surface_requested_height",r.surfaceRequestedHeight).put("surface_ready_ms",r.surfaceReadyMs)
|
||||
.put("first_exception_operation",r.firstExceptionOperation.name.lowercase()).put("first_exception_kind",r.firstExceptionKind.name.lowercase())
|
||||
.put("session_error_code",r.sessionErrorCode).put("camera_error_code",r.cameraErrorCode)
|
||||
.put("requested_preview_format",r.requestedPreviewFormat).put("requested_fps_min_milli",r.requestedFpsMinMilli).put("requested_fps_max_milli",r.requestedFpsMaxMilli)
|
||||
.put("actual_preview_format",r.actualPreviewFormat).put("actual_fps_min_milli",r.actualFpsMinMilli).put("actual_fps_max_milli",r.actualFpsMaxMilli)
|
||||
.put("actual_preview_frame_rate",r.actualPreviewFrameRate).put("parameter_readback_verified",r.parameterReadbackVerified).put("system_parameters_matched",r.systemParametersMatched)
|
||||
.put("supported_fixed_30_fps",r.supportedFixed30Fps).put("fps_ranges_truncated",r.fpsRangesTruncated)
|
||||
.put("supported_fps_ranges_milli",JSONArray().also {a->r.supportedFpsRangesMilli.take(16).forEach {range ->
|
||||
if(range.size==2) a.put(JSONArray().put(range[0]).put(range[1]))}})
|
||||
.put("surface_valid_before_attach",r.surfaceValidBeforeAttach).put("surface_valid_before_start",r.surfaceValidBeforeStart)
|
||||
.put("surface_creating_at_attach",r.surfaceCreatingAtAttach).put("surface_width",r.surfaceWidth).put("surface_height",r.surfaceHeight)
|
||||
.put("frame_observation",if(r.mode==CameraProbeMode.CAMERA1_DEFAULT_PREVIEW) "not_sampled" else "callback_counted")
|
||||
.put("frame_observation",if(r.mode.legacy && !r.mode.samplesLegacyFrames) "not_sampled" else "callback_counted")
|
||||
.put("mode",r.mode.name.lowercase()).put("failure",r.failure.name.lowercase())
|
||||
.put("started_ms",r.startedMs).put("finished_ms",r.finishedMs).put("bound_ms",r.boundMs)
|
||||
.put("open_ms",r.openMs).put("surface_provided_ms",r.surfaceProvidedMs)
|
||||
@@ -119,7 +128,12 @@ object DiagnosticReportUpload {
|
||||
.put("close_started_ms",r.closeStartedMs).put("close_returned_ms",r.closeReturnedMs)
|
||||
.put("closed_ms",r.closedMs).put("close_confirmed",r.closeConfirmed).put("preview_trace",previewTrace(r.previewTrace)))}
|
||||
return JSONObject().put("stage",info.cameraProbeStage.name.lowercase())
|
||||
.put("entry_failure",info.cameraProbeEntryFailure.name.lowercase()).put("max_tests",CameraProbeMode.entries.size)
|
||||
.put("entry_failure",info.cameraProbeEntryFailure.name.lowercase()).put("max_tests",planned.size)
|
||||
.put("planned_modes",JSONArray().also {a->planned.forEach {a.put(it.name.lowercase())}})
|
||||
.put("result_count",results.size).put("attempted_count",results.count {it.attempted}).put("not_attempted_count",results.count {!it.attempted})
|
||||
.put("system_parameter_finding",systemParameterFinding(results).name.lowercase())
|
||||
.put("profile_source",if(planned.any {it.systemParameters}) "user_adb_report" else "standard_matrix")
|
||||
.put("system_three_streams_reproduced",false).put("universal_third_party_restriction_confirmed",false)
|
||||
.put("process_isolated",info.cameraProbeIsolated)
|
||||
.put("run_limit_ms",info.cameraProbeRunLimitMs).put("close_limit_ms",info.cameraProbeCloseLimitMs)
|
||||
.put("process_exit_limit_ms",info.cameraProbeExitLimitMs).put("availability_limit_ms",info.cameraProbeAvailabilityLimitMs).put("results",rows)
|
||||
|
||||
@@ -124,16 +124,39 @@ class CameraProbeController(private val context: Context,private val owner: Life
|
||||
val camera=nativeCall(run,CameraNativeOperation.OPEN) {Camera.open(id)};run.legacy=camera
|
||||
if(run.retired) return@post
|
||||
val params=nativeCall(run,CameraNativeOperation.GET_PARAMETERS) {camera.parameters}
|
||||
val supportedFps=params.supportedPreviewFpsRange.orEmpty()
|
||||
run.update {it.copy(supportedFpsRangesMilli=supportedFps.take(16).filter {r -> r.size==2 && r[0] in 0..240_000 && r[1] in r[0]..240_000}.map {r -> listOf(r[0],r[1])},
|
||||
fpsRangesTruncated=supportedFps.size>16,supportedFixed30Fps=supportedFps.any {r -> r.size==2 && r[0]==30_000 && r[1]==30_000})}
|
||||
if(run.mode!=CameraProbeMode.CAMERA1_DEFAULT_PREVIEW) {
|
||||
run.update {it.copy(requestedPreviewFormat=ImageFormat.NV21,
|
||||
requestedFpsMinMilli=if(run.mode.systemParameters) 30_000 else -1,
|
||||
requestedFpsMaxMilli=if(run.mode.systemParameters) 30_000 else -1)}
|
||||
failure=CameraProbeFailure.UNSUPPORTED_SIZE
|
||||
check(params.supportedPreviewSizes.any {it.width==run.mode.width && it.height==run.mode.height})
|
||||
failure=CameraProbeFailure.UNSUPPORTED_FORMAT
|
||||
check(ImageFormat.NV21 in params.supportedPreviewFormats)
|
||||
params.setPreviewSize(run.mode.width,run.mode.height);params.previewFormat=ImageFormat.NV21
|
||||
if(run.mode.systemParameters) {
|
||||
failure=CameraProbeFailure.UNSUPPORTED_FPS
|
||||
check(run.result.supportedFixed30Fps)
|
||||
params.setPreviewFpsRange(30_000,30_000)
|
||||
if(params.supportedPreviewFrameRates?.contains(30)==true) params.previewFrameRate=30
|
||||
}
|
||||
failure=CameraProbeFailure.START
|
||||
nativeCall(run,CameraNativeOperation.SET_PARAMETERS) {camera.parameters=params}
|
||||
}
|
||||
val actual=nativeCall(run,CameraNativeOperation.GET_PARAMETERS) {camera.parameters.previewSize}
|
||||
val actualParams=nativeCall(run,CameraNativeOperation.GET_PARAMETERS) {
|
||||
camera.parameters.also {p ->
|
||||
val fps=IntArray(2);p.getPreviewFpsRange(fps)
|
||||
val matched=run.mode.systemParameters && p.previewSize.width==1920 && p.previewSize.height==1080 &&
|
||||
p.previewFormat==ImageFormat.NV21 && fps[0]==30_000 && fps[1]==30_000
|
||||
run.update {it.copy(actualPreviewFormat=p.previewFormat,actualFpsMinMilli=fps[0],actualFpsMaxMilli=fps[1],
|
||||
actualPreviewFrameRate=p.previewFrameRate,parameterReadbackVerified=true,systemParametersMatched=matched)}
|
||||
}
|
||||
}
|
||||
val actual=actualParams.previewSize
|
||||
run.width=actual.width;run.height=actual.height
|
||||
if(run.mode.systemParameters && !run.result.systemParametersMatched) {error(run,CameraProbeFailure.PARAMETER_MISMATCH);return@post}
|
||||
val prepare=prepareLegacySurface
|
||||
if(prepare==null) startLegacyPreview(run,camera,actual)
|
||||
else main.post {
|
||||
@@ -173,7 +196,7 @@ class CameraProbeController(private val context: Context,private val owner: Life
|
||||
surfaceWidth=holder.surfaceFrame.width(),surfaceHeight=holder.surfaceFrame.height())}
|
||||
if(!surfaceReady) {error(run,CameraProbeFailure.SURFACE);return}
|
||||
nativeCall(run,CameraNativeOperation.ATTACH_SURFACE) {camera.setPreviewDisplay(holder)}
|
||||
if(run.mode!=CameraProbeMode.CAMERA1_DEFAULT_PREVIEW) {
|
||||
if(run.mode.samplesLegacyFrames) {
|
||||
val expected=actual.width*actual.height*3/2
|
||||
nativeCall(run,CameraNativeOperation.SET_FRAME_CALLBACK) {
|
||||
camera.setPreviewCallbackWithBuffer {data,c ->
|
||||
@@ -202,7 +225,7 @@ class CameraProbeController(private val context: Context,private val owner: Life
|
||||
}
|
||||
private fun releaseLegacy(run: Run,camera: Camera?) {
|
||||
try {
|
||||
if(run.mode!=CameraProbeMode.CAMERA1_DEFAULT_PREVIEW)
|
||||
if(run.mode.samplesLegacyFrames)
|
||||
nativeCall(run,CameraNativeOperation.CLEAR_FRAME_CALLBACK) {camera?.setPreviewCallbackWithBuffer(null)}
|
||||
nativeCall(run,CameraNativeOperation.CLEAR_ERROR_CALLBACK) {camera?.setErrorCallback(null)}
|
||||
if(run.previewStartRequested) nativeCall(run,CameraNativeOperation.STOP_PREVIEW) {camera?.stopPreview()}
|
||||
@@ -355,7 +378,7 @@ class CameraProbeController(private val context: Context,private val owner: Life
|
||||
// A pure native Preview has no analysis callback by design; visibility is unmeasured.
|
||||
val reason=when {
|
||||
run.result.nativeCallState==CameraNativeCallState.PENDING -> CameraProbeFailure.NATIVE_TIMEOUT
|
||||
!got && run.mode!=CameraProbeMode.CAMERA1_DEFAULT_PREVIEW -> CameraProbeFailure.FRAME_TIMEOUT
|
||||
!got && !(run.mode.legacy && !run.mode.samplesLegacyFrames) -> CameraProbeFailure.FRAME_TIMEOUT
|
||||
else -> null
|
||||
}
|
||||
close(run,reason)
|
||||
|
||||
@@ -3,10 +3,14 @@ package com.gorios.lanvoice.expression
|
||||
/** Fixed bounded metadata; this object never receives pixel contents, face geometry or voice. */
|
||||
enum class CameraProbeMode(val width: Int,val height: Int) {
|
||||
CAMERA1_DEFAULT_PREVIEW(0,0), CAMERA1_640(640,480), CAMERA1_320(320,240), CAMERAX_PREVIEW(640,480),
|
||||
CAMERAX_VISIBLE_DUAL(640,480), CAMERAX_ANALYSIS(640,480), CAMERAX_GL_DUAL(640,480);
|
||||
val legacy get()=this==CAMERA1_DEFAULT_PREVIEW || this==CAMERA1_640 || this==CAMERA1_320
|
||||
CAMERAX_VISIBLE_DUAL(640,480), CAMERAX_ANALYSIS(640,480), CAMERAX_GL_DUAL(640,480),
|
||||
CAMERA1_SYSTEM_1080_PREVIEW(1920,1080), CAMERA1_SYSTEM_1080_CALLBACK(1920,1080);
|
||||
val systemParameters get()=this==CAMERA1_SYSTEM_1080_PREVIEW || this==CAMERA1_SYSTEM_1080_CALLBACK
|
||||
val legacy get()=this==CAMERA1_DEFAULT_PREVIEW || this==CAMERA1_640 || this==CAMERA1_320 || systemParameters
|
||||
val samplesLegacyFrames get()=legacy && this!=CAMERA1_DEFAULT_PREVIEW && this!=CAMERA1_SYSTEM_1080_PREVIEW
|
||||
val analysis get()=this==CAMERAX_VISIBLE_DUAL || this==CAMERAX_ANALYSIS || this==CAMERAX_GL_DUAL
|
||||
val visible get()=legacy || this==CAMERAX_PREVIEW || this==CAMERAX_VISIBLE_DUAL
|
||||
companion object { val STANDARD_MODES=entries.filter { !it.systemParameters } }
|
||||
}
|
||||
enum class CameraNativeOperation { NONE, ENUMERATE, OPEN, GET_PARAMETERS, SET_PARAMETERS, SET_ERROR_CALLBACK,
|
||||
ATTACH_SURFACE, SET_FRAME_CALLBACK, ADD_BUFFERS, START_PREVIEW, CLEAR_FRAME_CALLBACK, CLEAR_ERROR_CALLBACK,
|
||||
@@ -18,13 +22,17 @@ enum class ProbeExceptionKind { NONE, SECURITY, ARGUMENT, STATE, IO, RUNTIME, OT
|
||||
enum class CameraProbeStage { IDLE, RUNNING, CLOSING, DONE, BLOCKED }
|
||||
enum class CameraProbeFailure { NONE, PERMISSION, NO_FRONT, UNSUPPORTED_SIZE, PROVIDER, BIND, OPEN,
|
||||
START, CAMERA_ERROR, SURFACE, NATIVE_TIMEOUT, FRAME_TIMEOUT, CLOSE_TIMEOUT, CANCELLED,
|
||||
WORKER_START_TIMEOUT, WORKER_DIED, PROCESS_EXIT_TIMEOUT, CAMERA_UNAVAILABLE, AVAILABILITY_UNKNOWN, AVAILABILITY_UNSTABLE }
|
||||
WORKER_START_TIMEOUT, WORKER_DIED, PROCESS_EXIT_TIMEOUT, CAMERA_UNAVAILABLE, AVAILABILITY_UNKNOWN, AVAILABILITY_UNSTABLE,
|
||||
UNSUPPORTED_FORMAT, UNSUPPORTED_FPS, PARAMETER_MISMATCH }
|
||||
enum class SystemParameterFinding { NOT_TESTED, INITIALIZATION_FAILED, PARAMETERS_UNSUPPORTED,
|
||||
PARAMETER_READBACK_MISMATCH, PREVIEW_UNMEASURED_CALLBACK_NOT_STARTED, CALLBACK_NOT_COMPLETED,
|
||||
INTERRUPTED, MATCHED_PARAMETERS_NO_CALLBACK, STREAMING_OBSERVED }
|
||||
data class CameraProbeConfig(
|
||||
val modes: List<CameraProbeMode> = CameraProbeMode.entries.toList(),
|
||||
val modes: List<CameraProbeMode> = CameraProbeMode.STANDARD_MODES,
|
||||
val runLimitMs: Long = 8_000, val closeLimitMs: Long = 8_000,
|
||||
) {
|
||||
init {
|
||||
require(modes.isNotEmpty() && modes.size <= 7 && modes.distinct().size == modes.size)
|
||||
require(modes.isNotEmpty() && modes.size <= CameraProbeMode.entries.size && modes.distinct().size == modes.size)
|
||||
require(runLimitMs in 1_000..8_000 && closeLimitMs in 500..8_000)
|
||||
}
|
||||
}
|
||||
@@ -54,8 +62,32 @@ data class CameraProbeResult(val mode: CameraProbeMode,val startedMs: Long,
|
||||
val firstExceptionOperation: CameraNativeOperation=CameraNativeOperation.NONE,
|
||||
val firstExceptionKind: ProbeExceptionKind=ProbeExceptionKind.NONE,
|
||||
val sessionErrorCode: Int=-1,val cameraErrorCode: Int=-1,
|
||||
val requestedPreviewFormat: Int=-1,val requestedFpsMinMilli: Int=-1,val requestedFpsMaxMilli: Int=-1,
|
||||
val actualPreviewFormat: Int=-1,val actualFpsMinMilli: Int=-1,val actualFpsMaxMilli: Int=-1,
|
||||
val actualPreviewFrameRate: Int=-1,val parameterReadbackVerified: Boolean=false,val systemParametersMatched: Boolean=false,
|
||||
val supportedFpsRangesMilli: List<List<Int>> = emptyList(),val fpsRangesTruncated: Boolean=false,
|
||||
val supportedFixed30Fps: Boolean=false,
|
||||
) : java.io.Serializable
|
||||
|
||||
/** A profile failure is evidence about this API/configuration, never a universal third-party ban.
|
||||
* Preview-only pixels are deliberately unmeasured; availability/close do not imply streaming. */
|
||||
fun systemParameterFinding(results: List<CameraProbeResult>): SystemParameterFinding {
|
||||
val rows=results.filter { it.mode.systemParameters }
|
||||
val callback=rows.firstOrNull { it.mode==CameraProbeMode.CAMERA1_SYSTEM_1080_CALLBACK }
|
||||
if(callback?.systemParametersMatched==true && callback.frames>0) return SystemParameterFinding.STREAMING_OBSERVED
|
||||
if(rows.any {it.initialFailure in setOf(CameraProbeFailure.CANCELLED,CameraProbeFailure.PERMISSION)}) return SystemParameterFinding.INTERRUPTED
|
||||
if(callback?.systemParametersMatched==true && callback.boundMs>=0 && callback.attempted && callback.initialFailure==CameraProbeFailure.FRAME_TIMEOUT)
|
||||
return SystemParameterFinding.MATCHED_PARAMETERS_NO_CALLBACK
|
||||
if(rows.any { it.initialFailure==CameraProbeFailure.PARAMETER_MISMATCH }) return SystemParameterFinding.PARAMETER_READBACK_MISMATCH
|
||||
if(rows.any { it.initialFailure in setOf(CameraProbeFailure.UNSUPPORTED_SIZE,CameraProbeFailure.UNSUPPORTED_FORMAT,CameraProbeFailure.UNSUPPORTED_FPS) })
|
||||
return SystemParameterFinding.PARAMETERS_UNSUPPORTED
|
||||
if(callback?.attempted==true && callback.boundMs>=0) return SystemParameterFinding.CALLBACK_NOT_COMPLETED
|
||||
if(rows.any { it.systemParametersMatched && it.boundMs>=0 && it.attempted })
|
||||
return SystemParameterFinding.PREVIEW_UNMEASURED_CALLBACK_NOT_STARTED
|
||||
if(rows.any { it.attempted }) return SystemParameterFinding.INITIALIZATION_FAILED
|
||||
return SystemParameterFinding.NOT_TESTED
|
||||
}
|
||||
|
||||
/** One foreground suite per process at a time. A timed-out close keeps normal camera inhibited. */
|
||||
object CameraProbeStore {
|
||||
@Volatile var inhibitNormal=false
|
||||
|
||||
Reference in New Issue
Block a user