Determing when all buffers played (WASAPI)
-
Friday, April 13, 2012 6:43 PM
In WASAPI shared event driven mode, what is the best way to determine when all buffers have been played?
Is it safe to do:
while(1) { hr = mpClient->GetCurrentPadding(&i); if (FAILED(hr) || i == 0) { break; } }
This is after the rendering loop when I know all my buffers have been sent using GetBuffer/ReleaseBuffer, in a scenario where using Sleep() is not desired.
Thanks.
- Edited by John_78f Friday, April 13, 2012 6:51 PM
All Replies
-
Friday, April 13, 2012 7:09 PMModerator
You can use IAudioClock to see what sample is currently going out of the speakers.
Matthew van Eerde
-
Monday, April 16, 2012 12:39 PM
Thanks for the reply. However, I didn't mention that I am using IMFSourceReader::SetCurrentPosition(), and according to the documentation this is not accurate.
So, given that I have an audio file of 03:18 (198357ms), and I start it at 170000 using SetCurrentPosition(), this:
while(1) { hr = mpClock->GetPosition(&pos, NULL); diff = (double)pos / miClockFreq; diff *= 1000.0f; if (dwTotalLength - dwStartPosition <= diff) { break; } }gets into an infinite loop. diff remains at 26776.66666 recurring, while dwTotalLength - dwStartPosition is obviously 28357. I have assumed that SetCurrentPosition was out by 2 seconds (ish). That's quite a lot of audio.
Given this fact, is my original method better?
Thanks.


