Author Topic: Sound API - Thread contention on THREAD_SYNC monitor during preload  (Read 71 times)

Offline MadMartian

  • bit
  • Posts: 2
    • View Profile
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?

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3476
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Sound API - Thread contention on THREAD_SYNC monitor during preload
« Reply #1 on: December 04, 2017, 02:10:33 PM »
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.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted