如果我将一个用于记录的缓冲区排入缓冲区队列 - 是否有办法知道该缓冲区何时实际已满,以便我可以使用它?
同样,有没有办法知道缓冲区何时播放?
对于上下文: 我正在修改名为“native-audio”的 NDK 示例。 它使用 SLAndroidSimpleBufferQueueItf 进行播放,并评论说,对于我想做的流记录,也应该使用这样的队列。 现在我想知道,因为根据我记得在某处读到的内容,不能保证在下一次调用录音回调时缓冲区已经被填充(或者在播放回调中播放,就此而言) - 人们怎么知道什么时候缓冲区已被使用? 肯定有办法,否则这一切就有点没用了? ^^
最佳答案
对于记录,如果您使用 IBufferQueue_RegisterCallback
注册一个 slBufferQueueCallback
,您应该在缓冲区已填满时获得回调。
另见 this discussion在 android-ndk 列表中:
If I understand well, the recorder will call back each time a buffer in the queue is filled in, and these buffers are filled in in the order that they are enqueued. But the callback does not seem to expose a pointer to the corresponding filled buffer. So what would be the way to retreive this? A sample code in the OpenSL ES specs shows an example for playback with a struct passed in as context of the callback to keep track of these, is that the way to do?
...
Right. This is a known deficiency in the OpenSL ES 1.0.1 spec. OpenSL ES 1.1 adds an explicit parameter to identify the buffer, but Android is currently based on the 1.0.1 spec. A workaround is to maintain an index yourself to indicate which buffer is being completed.
关于Android NDK、OpenSL ES - 知道缓冲区何时被填满,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13955397/