Android 当 BufferQueue 被放弃时,我能做什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22486762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:03:18  来源:igfitidea点击:

What can I do when the BufferQueue has been abandoned?

androidandroid-camerasurfaceviewtextureview

提问by user2426316

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:

我正在使用纹理视图在我的 android 应用程序中显示相机的预览。然而,我注意到的是,每次我的应用程序暂停时,我都会收到此错误:

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()

有人能告诉我这里发生了什么吗?当我的应用程序暂停时,我所做的就是从onSurfaceTextureDestroyed()

 public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
    mCamera.setPreviewCallback(null);
    mCamera.stopPreview();
    mCamera.release();
    return true;
}

回答by fadden

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

您所做的基本上是在TextureView docs 中编写的内容,因此它应该可以工作。

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 BufferQueueis considered abandoned, and no further operations are possible.

错误消息意味着BufferQueue(相机)的“生产者”端抓取了一个缓冲区,现在正试图取消抓取它(通过cancelBuffer())。然而,“消费者”方面(the SurfaceTexture)已经消失。由于“消费者”方拥有队列,因此BufferQueue被视为已放弃,并且无法进行进一步的操作。

This sounds like it's just a timing issue -- the producer is trying to do operations after the SurfaceTexturehas 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 threadtimeto see the thread IDs.)

这听起来只是一个时间问题——生产者正试图SurfaceTexture在销毁后进行操作。这是没有意义的,因为您正在关闭生产者onSurfaceTextureDestroyed(),并且除非回调返回,否则 ST 不会被释放true。(在回调方法的开始和结束处添加日志消息可能会很有趣,并查看“被遗弃”的投诉发生在它们之前还是之后。logcat -v threadtime用于查看线程 ID。)

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 TextureViewdocs, and I don't see any complaints when I run it on my device.

出于好奇,如果您在Grafika 中运行“Live camera (TextureView)”,您是否会从您的设备中看到这样的消息?该活动直接来自TextureView文档,当我在我的设备上运行它时,我没有看到任何抱怨。

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

(可以在此处找到有关 SurfaceTexture 和 BufferQueue 的其他信息。)