fix: Throw not-compatible-with-outputs error when adding both CodeScannerPipeline and VideoPipeline (#2411)

* fix: Throw `not-compatible-with-outputs` error when adding CodeScanner and Video

* Format
This commit is contained in:
Marc Rousavy 2024-01-18 10:40:15 +01:00 committed by GitHub
parent ba576054c3
commit e21a1c2110
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -119,6 +119,13 @@ class CodeTypeNotSupportedError(codeType: String) :
"code-type-not-supported", "code-type-not-supported",
"The codeType \"$codeType\" is not supported by the Code Scanner!" "The codeType \"$codeType\" is not supported by the Code Scanner!"
) )
class CodeScannerTooManyOutputsError :
CameraError(
"code-scanner",
"not-compatible-with-outputs",
"CodeScanner can only be enabled when both video and frameProcessor are disabled! " +
"Use a Frame Processor Plugin for code scanning instead."
)
class ViewNotFoundError(viewId: Int) : class ViewNotFoundError(viewId: Int) :
CameraError("system", "view-not-found", "The given view (ID $viewId) was not found in the view manager.") CameraError("system", "view-not-found", "The given view (ID $viewId) was not found in the view manager.")

View File

@ -414,6 +414,12 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
// CodeScanner Output // CodeScanner Output
val codeScanner = configuration.codeScanner as? CameraConfiguration.Output.Enabled<CameraConfiguration.CodeScanner> val codeScanner = configuration.codeScanner as? CameraConfiguration.Output.Enabled<CameraConfiguration.CodeScanner>
if (codeScanner != null) { if (codeScanner != null) {
if (video != null) {
// CodeScanner and VideoPipeline are two repeating streams - they cannot be both added.
// In this case, the user should use a Frame Processor Plugin for code scanning instead.
throw CodeScannerTooManyOutputsError()
}
val imageFormat = ImageFormat.YUV_420_888 val imageFormat = ImageFormat.YUV_420_888
val sizes = characteristics.getVideoSizes(cameraDevice.id, imageFormat) val sizes = characteristics.getVideoSizes(cameraDevice.id, imageFormat)
val size = sizes.closestToOrMax(Size(1280, 720)) val size = sizes.closestToOrMax(Size(1280, 720))