CameraX Graphic Buffer Allocator failed to allocate (1280x720) layerCount 1 frmat 35 usage 33:3

791 views
Skip to first unread message

Giouri Kilinkaridis

unread,
Feb 11, 2021, 9:00:16 AM2/11/21
to Android CameraX Discussion Group
I am running android on raspberry pi 3 b+ with an external web cam and I wanted to test my object detection app on it,  while it works fine on a smartphone when on the raspberry the camera freezes and reopens every 3 seconds to only show 1 frame and i get the following error:

E/GraphicBufferAllocator: Failed to allocate (1280 x 720) layerCount 1 format 35 usage 33: 3
E/BufferQueueProducer: [ImageReader-1280x720f23m4-3719-0] dequeueBuffer: createGraphicBuffer failed
E/Legacy-CameraDevice-JNI: produceFrame: Failed to dequeue buffer, error Out of memory (-12).
E/Legacy-CameraDevice-JNI: LegacyCameraDevice_nativeProduceFrame: Error while producing frame Out of memory (-12).
E/CameraDeviceGLThread-0: Received exception on GL render thread: 
    java.lang.UnsupportedOperationException: Unknown error -12
        at android.hardware.camera2.legacy.LegacyExceptionUtils.throwOnError(LegacyExceptionUtils.java:77)
        at android.hardware.camera2.legacy.LegacyCameraDevice.produceFrame(LegacyCameraDevice.java:738)
        at android.hardware.camera2.legacy.SurfaceTextureRenderer.drawIntoSurfaces(SurfaceTextureRenderer.java:839)
        at android.hardware.camera2.legacy.GLThreadManager$1.handleMessage(GLThreadManager.java:105)
        at android.os.Handler.dispatchMessage(Handler.java:103)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:67)
I/CameraDeviceState: Legacy camera service transitioning to state ERROR
E/CameraCaptureSession: Session 0: Exception while stopping repeating: 
    android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): The camera device has encountered a serious error
        at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:2535)
        at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1129)
        at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:526)
        at androidx.camera.camera2.internal.SynchronizedCaptureSessionBaseImpl.close(SynchronizedCaptureSessionBaseImpl.java:425)
        at androidx.camera.camera2.internal.SynchronizedCaptureSessionImpl.lambda$close$4$SynchronizedCaptureSessionImpl(SynchronizedCaptureSessionImpl.java:309)
        at androidx.camera.camera2.internal.-$$Lambda$SynchronizedCaptureSessionImpl$FYBJDMhVAN6TATAq887frkFPytI.run(Unknown Source:2)
        at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:230)
        at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
E/RequestThread-0: Timed out while waiting for request to complete.
E/CameraDeviceState: Cannot receive result while in state: 0

can somebody explain what exactly goes wrong please.

Eino-Ville Talvala

unread,
Feb 11, 2021, 11:46:20 AM2/11/21
to Giouri Kilinkaridis, Android CameraX Discussion Group
Well, this seems to be an error in the RPi's graphics system -  it cannot allocate a buffer for camera image data.
The specific error is 'out of memory', but that may just be a generic failure code at this level.

Unfortunately I don't have any specific knowledge of what the memory limits on the RPi are, or if this is just a bug in the Android implementation you're using.


--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/514a9393-3cc2-4b81-ae5c-8050fcd6ef00n%40android.com.

Giouri Kilinkaridis

unread,
Feb 11, 2021, 12:56:09 PM2/11/21
to Android CameraX Discussion Group, Eino-Ville Talvala, Android CameraX Discussion Group, Giouri Kilinkaridis

But if I install the official tensorflow  object detection app for android it runs without problems but they don't use cameraX the use camera2.
For some reason using image analysis to access camera frames creates this problem.  

Giouri Kilinkaridis

unread,
Feb 11, 2021, 12:59:45 PM2/11/21
to Android CameraX Discussion Group, Giouri Kilinkaridis, Eino-Ville Talvala, Android CameraX Discussion Group
Is there any other way to get the frames using cameraX or i will need to rebuild the project ?

Eino-Ville Talvala

unread,
Feb 11, 2021, 1:22:51 PM2/11/21
to Giouri Kilinkaridis, Android CameraX Discussion Group
What settings are you using for https://developer.android.com/reference/kotlin/androidx/camera/core/ImageAnalysis.Builder#setImageQueueDepth(kotlin.Int) and https://developer.android.com/reference/kotlin/androidx/camera/core/ImageAnalysis.Builder#setbackpressurestrategy

If you're using STRATEGY_BLOCK_PRODUCER, it's possible your image queue depth is too large for the device - try reducing the number to the minimum you need. If your image processing can reliably run fast enough, and you don't need to parallelize processing of multiple frames at once, you may be able to just use 1 or 2 frames instead of the default 6.

(That said, 6 buffers shouldn't get allocated unless you are unable to keep up with the frame rate in your analysis, so that's another possible reason for the overflow).

Alternatively, explore using a lower resolution - it's possible the tensorflow sample is using lower resolution outputs, which reduce memory use.

Giouri Kilinkaridis

unread,
Feb 11, 2021, 1:32:40 PM2/11/21
to Android CameraX Discussion Group, Eino-Ville Talvala, Android CameraX Discussion Group, Giouri Kilinkaridis
I am using .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) to keep only the latest incoming frame 

Giouri Kilinkaridis

unread,
Feb 11, 2021, 1:36:52 PM2/11/21
to Android CameraX Discussion Group, Giouri Kilinkaridis, Eino-Ville Talvala, Android CameraX Discussion Group
I will change it to .setImageQueueDepth(1) and try to see the result 

Eino-Ville Talvala

unread,
Feb 11, 2021, 1:47:34 PM2/11/21
to Giouri Kilinkaridis, Android CameraX Discussion Group
In that case, using lower resolutions may help, if it's possible for your use case.  For both preview and analysis.  I'm not aware of any reason why CameraX would use more memory than a camera2 pipeline, fundamentally.   Perhaps the tensorflow sample app does preview based off of the analysis stream, so it has only one output in its camera2 setup, not two.  May be worth looking at its sample code to understand what it does?

That can be done with CameraX, but you'd need to do a lot of your own scaffolding to use the preview use case for both preview and analysis (easiest by piping preview to the GPU via a SurfaceTexture and then using OpenGL ES for analysis and rendering).


Giouri Kilinkaridis

unread,
Feb 11, 2021, 2:07:52 PM2/11/21
to Android CameraX Discussion Group, Eino-Ville Talvala, Android CameraX Discussion Group, Giouri Kilinkaridis
Lowering resolution both at Preview case and Image analysis and setting  setImageQueueDepth(1)  still didn't help.
I am going to check again their example to see what I am missing 
Thank you for helping 

Reply all
Reply to author
Forward
0 new messages