diff --git a/src/audio/alsalayer.cpp b/src/audio/alsalayer.cpp index 3488126f67cdd8dcec7c6aef56da0a4cfe3f4073..9a77daaf59c7a83f37f524f5630e45fda6888c1f 100644 --- a/src/audio/alsalayer.cpp +++ b/src/audio/alsalayer.cpp @@ -158,11 +158,11 @@ AlsaLayer::stopStream(void) void* ringtoneThreadEntry( void *ptr ) { - //while( ringtone_thread_is_running ) - //{ + while( ringtone_thread_is_running ) + { ( ( AlsaLayer *) ptr) -> playTones(); //sleep(0.1); - //} + } /* pthread_mutex_lock(&mut); while( ((AlsaLayer*)ptr)->_manager->getTelephoneTone() == NULL ) @@ -227,8 +227,6 @@ AlsaLayer::putUrgent(void* buffer, int toCopy) { int nbBytes = 0; - pthread_mutex_lock(&mut); - if ( _PlaybackHandle ){ //fillHWBuffer(); int a = _urgentBuffer.AvailForPut(); @@ -237,14 +235,18 @@ AlsaLayer::putUrgent(void* buffer, int toCopy) } else { nbBytes = _urgentBuffer.Put( buffer , a , _defaultVolume ) ; } - _debug("Wake up the ringtone thread\n"); - pthread_cond_broadcast(&cond); } - pthread_mutex_unlock(&mut); return nbBytes; } +void AlsaLayer::trigger_thread(void) +{ + _debug("Wake up the ringtone thread\n"); + pthread_cond_broadcast(&cond); +} + + int AlsaLayer::canGetMic() { @@ -298,13 +300,12 @@ AlsaLayer::playTones( void ) int maxBytes; pthread_mutex_lock(&mut); - while(!_manager -> getTelephoneTone() && !_manager->getTelephoneFile()) + while(!_manager-> getTelephoneTone() && !_manager->getTelephoneFile()) { _debug("Make the ringtone thread wait\n"); pthread_cond_wait(&cond, &mut); } - //frames = _periodSize ; frames = 940 ; maxBytes = frames * sizeof(SFLDataFormat) ; diff --git a/src/audio/alsalayer.h b/src/audio/alsalayer.h index a63b1f14ccb2fa1a82964f9bb8f7776afc15bf73..8d7aceafe4c2f15287753459d9234d1437c987cd 100644 --- a/src/audio/alsalayer.h +++ b/src/audio/alsalayer.h @@ -48,6 +48,8 @@ class AlsaLayer : public AudioLayer { */ ~AlsaLayer(void); + void trigger_thread(void); + void closeLayer( void ); /** @@ -211,8 +213,6 @@ class AlsaLayer : public AudioLayer { void playTones( void ); - - private: // Copy Constructor diff --git a/src/audio/audiolayer.h b/src/audio/audiolayer.h index 44a4d4d15f8c30c8644b48e42383c417d6a23ecf..62883100aa8b27511a1ca387ab7d8ceda0f59a05 100644 --- a/src/audio/audiolayer.h +++ b/src/audio/audiolayer.h @@ -86,6 +86,8 @@ class AudioLayer { virtual void closeLayer( void ) = 0; + virtual void trigger_thread(void)=0; + /** * Check if no devices are opened, otherwise close them. * Then open the specified devices by calling the private functions open_device diff --git a/src/audio/pulselayer.h b/src/audio/pulselayer.h index bcdf055163d978982dc3166ba221b3afc1e5403d..24a98478b0ccbc251ca70c4df2d2fb0964d3bdfb 100644 --- a/src/audio/pulselayer.h +++ b/src/audio/pulselayer.h @@ -36,6 +36,8 @@ class PulseLayer : public AudioLayer { void closeLayer( void ); + void trigger_thread(void){} + /** * Check if no devices are opened, otherwise close them. * Then open the specified devices by calling the private functions open_device diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index ab0f97ff7d588c5ed014647983ea0de8aa8db0cb..31564bae3a9e3845adfb5dd756cca63944a6a72d 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -865,6 +865,7 @@ ManagerImpl::congestion () { void ManagerImpl::ringback () { playATone(Tone::TONE_RINGTONE); + getAudioDriver()->trigger_thread(); } /** @@ -892,17 +893,19 @@ ManagerImpl::ringtone() bool loadFile = _audiofile.loadFile(ringchoice, codecForTone , sampleRate); _toneMutex.leaveMutex(); if (loadFile) { - _toneMutex.enterMutex(); - _audiofile.start(); - _toneMutex.leaveMutex(); - if(CHECK_INTERFACE( layer, ALSA )){ - int size = _audiofile.getSize(); - SFLDataFormat output[ size ]; - _audiofile.getNext(output, size , 100); - audiolayer->putUrgent( output , size );} - else{ - audiolayer->startStream(); - } + _toneMutex.enterMutex(); + _audiofile.start(); + _toneMutex.leaveMutex(); + if(CHECK_INTERFACE( layer, ALSA )){ + int size = _audiofile.getSize(); + SFLDataFormat output[ size ]; + _audiofile.getNext(output, size , 100); + audiolayer->putUrgent( output , size ); + audiolayer->trigger_thread(); + } + else{ + audiolayer->startStream(); + } } else { ringback(); }