[Portaudio] PortAudio and ffmpeg

Andrew Udvare audvare at gmail.com
Thu Mar 3 17:12:04 EST 2011

I have posted this to ffmpeg mailing list as well.

I am just a tiny bit confused about how the loop should work in my audio 
decoding example I'm trying to make:

I am using ffmpeg to read audio and PortAudio to play. At the moment, the 
audio sounds completely wrong. And, since PortAudio runs its callback in a 
different thread, without a call to Pa_Sleep() the application exits 

I have pasted code here: http://paste.pocoo.org/show/347705/
This is heavily based on code at http://dranger.com/ffmpeg/tutorial03.html

Basically I see it as such:
Start PortAudio as normal (Pa_OpenStream, Pa_StartStream)
Callback is done in different thread as per standard PortAudio behaviour
Fill AVPacket list in my data packet queue structure over and over until audio 
file is complete
While loop should quit on its own when there is no more to decode
Pa_StopStream and terminate PortAudio and the application

I'm wondering if the call to Pa_Sleep or similar will be necessary to keep the 
application alive in this case? If so, what values would be safe to use? Some 
MP3s I have tried have given very odd and untrustworthy duration values.


More information about the Portaudio mailing list