Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Camera addCallbackBuffer mechanism works?

Here is the explanation of addCallbackBuffer: http://developer.android.com/reference/android/hardware/Camera.html#addCallbackBuffer(byte[])

I couldnt understand this mechanism and how to use it. We can add one or more buffer. Suppose that we added 10 buffer. is OnPreviewFrame method is called when 10 buffer is filled?

Suppose that a buffer is removed from the buffer queue and OnPreviewFrame is called with that buffer. When we call addCallbackBuffer method with the arrived buffer, is the buffer added to head of the queue and next OnPreviewFrame is called with that buffer?

When we call addCallbackBuffer, how can we get the timestamp of the frame?

Is there any frame drops when we call addCallbackBuffer?

like image 816
Murat Avatar asked Jan 08 '23 23:01

Murat


1 Answers

use setPreviewCallbackWithBuffer and addCallbackBuffer together.

At first, you should call addCallbackBuffer before calling setPreviewCallbackWithBuffer. You can add buffer by calling addCallbackBuffer for 4-5 frames. It depends on your project. How many bytes a frame requires expains here..

Everytime onPreviewFrame is called, buffer added by addCallbackBuffer is used. As long as there is enough buffer added by addCallbackBuffer, onPreviewFrame is called. If there is no buffer left for onPreviewFrame, frames are started to drop and onPreviewFrame is not called.

So you should keep calling addCallbackBuffer during the execution. You can call addCallbackBuffer with the byte array parameter on onPreviewFrame after you process the data. In this way, you always reuse the same buffers.

If there is a point that i missed to explain, please let me know.

like image 89
faraway Avatar answered Jan 18 '23 18:01

faraway