General > Other Support

Sound API - Thread contention on THREAD_SYNC monitor during preload


I have a scenario of problems that I do not know how to resolve or work-around.  From my vantage point this is unavoidable but I would like to check and see if I'm missing how to correctly use the sound API.

I have written an adapter ICodec "MPEGCodec" that streams MPEG audio from Internet radio stations.  During the ICodec's initialize phase I am initiating the connection and querying the header for meta-data.  This always takes a few seconds to complete.  If in the main thread I call any of the sound system commands, the thread blocks.  I found out that the codec preload thread has the THREAD_SYNC monitor locked and the command functions also wait on this monitor.  Since this is my UI thread it effectively freezes the game for a few seconds.  So it looks like if I don't want my UI to freeze-up momentarily then I have to avoid calling sound system functions until the stream has finished preloading.

Is there something I am missing? is there a better way to handle this?  Should I be using a thread other than the main UI thread for querying the sound system?

Yes, in hind sight I should have used callbacks more extensively.  I would suggest that you spin off a new thread for these queries, and have it do a callback when it completes.


[0] Message Index

Go to full version