From 7e2889cf84c0346fda8589ae69d56706bad85efd Mon Sep 17 00:00:00 2001 From: Daniel Prado Date: Thu, 25 Jan 2024 14:17:48 -0300 Subject: [PATCH] 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 --- .../java/com/mrousavy/camera/core/VideoPipeline.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/package/android/src/main/java/com/mrousavy/camera/core/VideoPipeline.kt b/package/android/src/main/java/com/mrousavy/camera/core/VideoPipeline.kt index 343397e..47039d5 100644 --- a/package/android/src/main/java/com/mrousavy/camera/core/VideoPipeline.kt +++ b/package/android/src/main/java/com/mrousavy/camera/core/VideoPipeline.kt @@ -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)