fix: Fix maxImages have been acquired error in Frame Processor (#2430)

* fix: maxImages when frameprocessor error

* fix: Use `try`/`finally` for safety

---------

Co-authored-by: Marc Rousavy <me@mrousavy.com>
This commit is contained in:
Daniel Prado 2024-01-25 14:17:48 -03:00 committed by GitHub
parent 4041ee8cbd
commit 7e2889cf84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -110,20 +110,22 @@ class VideoPipeline(
Log.i(TAG, "ImageReader::onImageAvailable!")
val image = reader.acquireNextImage() ?: return@setOnImageAvailableListener
// TODO: Get correct orientation and isMirrored
val frame = Frame(image, image.timestamp, Orientation.PORTRAIT, isMirrored)
frame.incrementRefCount()
try {
// TODO: Get correct orientation and isMirrored
val frame = Frame(image, image.timestamp, Orientation.PORTRAIT, isMirrored)
frame.incrementRefCount()
frameProcessor?.call(frame)
if (hasOutputs) {
// If we have outputs (e.g. a RecordingSession), pass the frame along to the OpenGL pipeline
imageWriter!!.queueInputImage(image)
}
frame.decrementRefCount()
} catch (e: Throwable) {
Log.e(TAG, "Failed to call Frame Processor!", e)
Log.e(TAG, "FrameProcessor/ImageReader pipeline threw an error!", e)
throw e
} finally {
frame.decrementRefCount()
}
}, CameraQueues.videoQueue.handler)