What can I do when the BufferQueue has been abandoned?

60,199

What you're doing is essentially what's written in the TextureView docs, so it should work.

The error message means that the "producer" side of the BufferQueue (the camera) grabbed a buffer, and is now trying to un-grab it (via cancelBuffer()). However, the "consumer" side (the SurfaceTexture) has gone away. Because the "consumer" side owns the queue, the BufferQueue is considered abandoned, and no further operations are possible.

This sounds like it's just a timing issue -- the producer is trying to do operations after the SurfaceTexture has been destroyed. Which doesn't make sense, because you're shutting the producer down in onSurfaceTextureDestroyed(), and the ST doesn't get released unless and until that callback returns true. (It might be interesting to add log messages at the start and end of the callback method, and see if the "abandoned" complaint happens before or after them. Use logcat -v threadtime to see the thread IDs.)

So I'm not really sure why this is happening. The good news is that it should not adversely affect your application -- the producer will correctly determine that the consumer has gone away, and will complain but not crash. So it's noisy but not explody.

Out of curiosity, do you see messages like this from your device if you run "Live camera (TextureView)" in Grafika? That activity is straight out of the TextureView docs, and I don't see any complaints when I run it on my device.

(Additional information about SurfaceTexture and BufferQueue can be found here.)

Share:
60,199
user2426316
Author by

user2426316

Updated on February 08, 2020

Comments

  • user2426316
    user2426316 about 4 years

    I am using a texture view to show the preview of the camera in my android app. What I noticed, however, is that every time my app gets paused, I am getting this error:

    03-18 18:23:44.315: W/BufferQueue(19582): [unnamed-19582-20] cancelBuffer: BufferQueue has been abandoned!
    

    Can someone tell me what's going on here? When my app pauses all I do is deinitialize everything like this from onSurfaceTextureDestroyed()

     public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
        mCamera.setPreviewCallback(null);
        mCamera.stopPreview();
        mCamera.release();
        return true;
    }
    
  • user2426316
    user2426316 about 10 years
    That was really helpful! I also figured the reason for my problem: the texture view that holds the camera preview got removed from the layout (by a call to removeView()) way to early. And therefore the the error showed up.
  • user2426316
    user2426316 about 10 years
    The bottom line of all this is: When you encounter this message make sure that your preview is alive as long as your camera is capturing/ as long as stopCamera was not called
  • learner
    learner over 8 years
    Any ideas how to solve this problem for playing videos? stackoverflow.com/questions/33288303/…
  • Yash
    Yash over 4 years
    @fadden 5 years down the line, and you helped me!
  • Bitz Trail
    Bitz Trail over 4 years
    I got this error in my google camera mod APK ,which happens each time after taking HDR enhanced shots and this are sorting by editing smali files how can i solve this issue in a modified Google cam APK
  • HB.
    HB. over 4 years
    In my case, I'm decoding a video and displaying it on a Surface. If the video is playing and I press the back button, I get this message. I assume this is happening because the encoder still holds buffers by the time the surface is destroyed. As fadden said, it's a timing issue. I just ignore the message.
  • HB.
    HB. over 4 years
    I can't edit my previous comment. I soon learned the ignoring it, as I mentioned above, is not wise. Let me explain - I release buffers in a thread and display it on my SurfaceTexture like this Decoder.releaseOutputBuffer(bufferIndex, true);. When the surface is destroyed and Decoder.releaseOutputBuffer(bufferIndex, true); is called, it will throw an IllegalArgumentException since there is no surface to display the buffer to. Instead, once onSurfaceTextureDestroyed is called, releaseOutputBuffer should no longer be called.
  • G.N.SRIDHAR
    G.N.SRIDHAR about 4 years
    you give very useful information. Here I close the camera in onPause() method. so that Bufferqueue error came, after i close the camera in onDestory(), error gone. works fine. Appreciate one.