Skip to content

Commit

Permalink
Merge "[CameraPipe] Forward configAdapter.mapToRequest exception to I…
Browse files Browse the repository at this point in the history
…mageCapture failure" into androidx-main
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed May 17, 2024
2 parents a031c23 + d5a4088 commit e3467d0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class CaptureConfigAdapter @Inject constructor(
CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL
] == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY

/**
* Maps [CaptureConfig] to [Request].
*
* @throws IllegalStateException When CaptureConfig does not have any surface or a CaptureConfig
* surface is not recognized in [UseCaseGraphConfig.surfaceToStreamMap]
*/
@OptIn(ExperimentalGetImage::class)
fun mapToRequest(
captureConfig: CaptureConfig,
Expand All @@ -68,7 +74,7 @@ class CaptureConfigAdapter @Inject constructor(

val streamIdList = surfaces.map {
checkNotNull(useCaseGraphConfig.surfaceToStreamMap[it]) {
"Attempted to issue a capture with an unrecognized surface."
"Attempted to issue a capture with an unrecognized surface: $it"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,46 +404,66 @@ class CapturePipelineImpl @Inject constructor(
}
debug { "CapturePipeline#submitRequestInternal; Submitting $configs with CameraPipe" }
val deferredList = mutableListOf<CompletableDeferred<Void?>>()
val requests = configs.map {
val requests = configs.mapNotNull {
val completeSignal = CompletableDeferred<Void?>().also { deferredList.add(it) }
configAdapter.mapToRequest(
it, requestTemplate, sessionConfigOptions,
listOf(object : Request.Listener {
override fun onAborted(request: Request) {
completeSignal.completeExceptionally(
ImageCaptureException(
ERROR_CAMERA_CLOSED,
"Capture request is cancelled because camera is closed",
null
try {
configAdapter.mapToRequest(
it, requestTemplate, sessionConfigOptions,
listOf(object : Request.Listener {
override fun onAborted(request: Request) {
completeSignal.completeExceptionally(
ImageCaptureException(
ERROR_CAMERA_CLOSED,
"Capture request is cancelled because camera is closed",
null
)
)
)
}

override fun onTotalCaptureResult(
requestMetadata: RequestMetadata,
frameNumber: FrameNumber,
totalCaptureResult: FrameInfo,
) {
completeSignal.complete(null)
}

@SuppressLint("ClassVerificationFailure")
override fun onFailed(
requestMetadata: RequestMetadata,
frameNumber: FrameNumber,
requestFailure: RequestFailure
) {
completeSignal.completeExceptionally(
ImageCaptureException(
ERROR_CAPTURE_FAILED,
"Capture request failed with reason " +
requestFailure.reason,
null
}

override fun onTotalCaptureResult(
requestMetadata: RequestMetadata,
frameNumber: FrameNumber,
totalCaptureResult: FrameInfo,
) {
completeSignal.complete(null)
}

@SuppressLint("ClassVerificationFailure")
override fun onFailed(
requestMetadata: RequestMetadata,
frameNumber: FrameNumber,
requestFailure: RequestFailure
) {
completeSignal.completeExceptionally(
ImageCaptureException(
ERROR_CAPTURE_FAILED,
"Capture request failed with reason " +
requestFailure.reason,
null
)
)
)
}
})
)
}
})
)
} catch (e: IllegalStateException) {
info(e) {
"CapturePipeline#submitRequestInternal: configAdapter.mapToRequest failed!"
}
completeSignal.completeExceptionally(
ImageCaptureException(
ERROR_CAPTURE_FAILED,
"Capture request failed with reason " + e.message,
e
)
)
null
}
}

if (requests.isEmpty()) {
// requests can be empty due to configAdapter.mapToRequest throwing exception, all the
// deferred instances in the list should already be completed exceptionally.
return deferredList
}

threads.sequentialScope.launch {
Expand Down

0 comments on commit e3467d0

Please sign in to comment.