简体   繁体   English

Android摄像头获取队列的回调缓冲区长度

[英]Android camera get queue's length of callback buffer

How to know the current amount of callbacks in the queue? 如何知道队列中当前的回调量?

Sometimes the count drops to 1 callback and I only get 2 frames per second. 有时计数降至1回调,我每秒只得到2帧。

Setup: 设定:

private void setupCallback(int bufferSize)
{
    mCamera.setPreviewCallbackWithBuffer(this);
    for (int i = 0; i <= NUM_BUFFERS; ++i)
    {
        byte[] cameraBuffer = new byte[bufferSize];
        mCamera.addCallbackBuffer(cameraBuffer);
    }
}

@Override
public void onPreviewFrame(byte[] data, Camera camera)
{
    processFrame(data);
    camera.addCallbackBuffer(data);
}

Log says: 日志说:

D/Camera-JNI: Using callback buffer from queue of length 4 D / Camera-JNI:使用长度为4的队列中的回调缓冲区

But sometimes with the same code it says: 但有时用相同的代码说:

D/Camera-JNI: Using callback buffer from queue of length 1 D / Camera-JNI:使用长度为1的队列中的回调缓冲区

How can I know that something went wrong and resetup those buffers? 我怎么知道出错了并重置那些缓冲区?

There's no way to do this in the Android API. 在Android API中无法做到这一点。 You can move processFrame to another thread so that onPreviewFrame is essentially non-blocking. 您可以将processFrame移动到另一个线程,以便onPreviewFrame基本上是非阻塞的。 This way bulk of the queue will be within your process and you'll be able to keep track of it. 这样,大部分队列都将在您的流程中,您将能够跟踪它。

You should also note that onPreviewFrame is called on the same thread on which you called Camera.open() . 您还应该注意onPreviewFrame是在您调用Camera.open()的同一个线程上调用的。 If that thread is busy doing something, the onPreviewFrame will not be called and the corresponding buffer will drop out of the buffer pool. 如果该线程忙于执行某些操作,则不会调用onPreviewFrame ,并且相应的缓冲区将从缓冲池中退出。 For this reason, I recommend that you have a dedicated thread for handling the Camera . 因此,我建议您使用专用线程来处理Camera

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM