Skip to content
Snippets Groups Projects
Commit 2535e7d5 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

The main thread synchronizes the ringtone thread

parent 331f1abd
No related branches found
No related tags found
No related merge requests found
......@@ -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) ;
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment