From: Pierre O. <dr...@dr...> - 2003-08-22 16:30:46
|
I've tracked down a pretty serious sync. bug in the audio system. The problem manifests itself as a freeze of the user interface when changing the volume (including muting). I searched around and realized I wasn't the only one who had run in to this. No one seemed to have found either the cause or a solution to it however. I have (partially) solved both ;) The cause of it all is the mutex handling access to the audio driver. Writing of new data to the sound card however keeps this mutex locked more or less indefinetly (sp?). From the code it seems this shouldn't happen (since the writing routine locks the mutex, writes the data and then unlocks it again). But from my experience with multi-threaded programming I'm guessing that the audio thread has time to do another loop during its time slice and ends up inside the lock again. The solution, of course, is to make sure that the system switches thread outside the lock. To do this I've successfully tested adding a usleep(1) after the mutex is unlocked. This should put the writing thread in a sleeping state and the scheduler should take care of the volume changing thread instead. I'm not 100% familiar with the process schedulers on all supported systems but this should work on any platform. I might have gone overboard with the description here but I figured you guys wouldn't want to include changes you don't fully understand. In short. To solve the problem add a: usleep(1); after: pthread_mutex_lock( &this->driver_lock ); result = this->driver->write (this->driver, out_buf->mem, ut_buf->num_frames ); pthread_mutex_unlock( &this->driver_lock ); in ao_loop in src/xine-engine/audio_out.c of xine-lib If you have any questions please cc them to my email aswell since I'm not following this mailing too much... It would be nice if this made it into the next release. If not then you might need to add something in the FAQ about it. I was ready to give up on xine for a while and it seems the other people who have encountered this bug have done just that. Rgds Pierre Ossman |