3

If I enqueue a buffer for recording into the buffer queue - is there a way of knowing when that buffer was actually filled, so I can use it ?

Likewise, is there a way of knowing when a buffer was played?

For context: I'm tinkering with the NDK example called "native-audio". It uses the SLAndroidSimpleBufferQueueItf for playing, and comments that, for stream recording, which I want to do, such a queue should also be used. Now I'm wondering, since from what I remember reading somewhere, it's not guaranteed that a buffer has been filled upon the next call of the recording callback (or played in the playing callback, for that matter) - how would one know when a buffer has been used? There surely must be some way, since otherwise all this would be a bit useless? ^^

user1847129
  • 1,010
  • 2
  • 9
  • 21

1 Answers1

4

For recording, if you register an slBufferQueueCallback with IBufferQueue_RegisterCallback you should get callbacks when a buffer has been filled.

Also see this discussion on the android-ndk list:

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.

Michael
  • 57,169
  • 9
  • 80
  • 125