0

I'm working with Android Camera2 API and get this after getting a set of photos from camera on my smartphone with Android version 6.0 (API 23):

2020-04-09 20:36:58.556 260-9342/? E/Camera3-Stream: getBuffer: wait for output buffer return timed out after 3000ms
2020-04-09 20:36:58.556 260-9342/? E/Camera3-Device: RequestThread: Can't get output buffer, skipping request: Connection timed out

After this errors the camera blocks, images stop sending and I need to reopen CameraDevice for getting a new set of images.

I'm using a BackgroundHandler to process getting camera images in a BackgroundThread. Then I create additional BackgroundThread to process every image with OpenCV library functions. But, I have only one working additional BackgroundThread at the the same time. (Some images I'm leaving out and create a new thread only if there are no another similar thread.)

For getting images I'm use CameraCaptureSession with setRepeatingRequest function. And also I making a clone of each image buffer before I processing it. So, my question is why the errors are happened and how to overcome it?

Egor Richman
  • 559
  • 3
  • 13

1 Answers1

2

Are you calling Image.close() after you're done reading each buffer?

There are only a fixed number of buffers in your ImageReader, and if you don't return Images to the queue (by closing them), you'll eventually stall the capture pipeline.

If you just drop all references to an Image, it'll eventually be garbage-collected and returned to the queue, but this may take longer than you expect, so manually closing it is more reliable.

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47
  • So, I find a little bug with your advice, thank you for this. But when I put Image.close() method call after image buffer copying the same story repeats. After nearly 20 seconds camera blocks again. It's not elegant solution to call CameraCaptureSession.close() after each capture request (if use CameraCaptureSession.capture()). Maybe there is more efficient way to clear the image buffers? – Egor Richman Apr 10 '20 at 04:24
  • Also, me there are way to avoid blocking with calling CameraCaptureSession.abortCaptures() before call of CameraCaptureSession.capture(), but it is tricky variant and it not helps to get images in higher rates (4 FPS for example are already not working on my device). – Egor Richman Apr 10 '20 at 04:48
  • 1
    Then there's some other issue going on - it's not expected that the camera blocks after only a few seconds. I don't know why you're calling abortCaptures(), but it is expected to block until the camera pipeline is cleared, and there's no way to change that. – Eddy Talvala Apr 13 '20 at 18:14