diff --git a/daemon/src/audio/audiolayer.cpp b/daemon/src/audio/audiolayer.cpp index dc19e57380e72e92ecba7d370ac492b6b9c4d6e2..1a2c00aa4f0687c604a1fe3abfb585677bf97a8b 100644 --- a/daemon/src/audio/audiolayer.cpp +++ b/daemon/src/audio/audiolayer.cpp @@ -29,11 +29,11 @@ * as that of the covered work. */ +#include <ctime> #include "audiolayer.h" #include "audioprocessing.h" #include "audio/dcblocker.h" #include "manager.h" -#include <cc++/numbers.h> AudioLayer::AudioLayer (ManagerImpl* manager , int type) : layerType_ (type) @@ -54,14 +54,12 @@ AudioLayer::AudioLayer (ManagerImpl* manager , int type) , dcblocker_ (0) , audiofilter_ (0) , noiseSuppressState_ (false) - , countNotificationTime_ (0) - , time_ (new ost::Time) + , lastNotificationTime_ (0) {} AudioLayer::~AudioLayer () { - delete time_; delete audiofilter_; delete dcblocker_; } @@ -85,17 +83,33 @@ void AudioLayer::putUrgent (void* buffer, int toCopy) urgentRingBuffer_.Put (buffer, toCopy); } +// Notify (with a beep) an incoming call when there is already a call in progress void AudioLayer::notifyincomingCall() { - // Notify (with a beep) an incoming call when there is already a call - if (Manager::instance().incomingCallWaiting()) { - countNotificationTime_ += time_->getSecond(); - int countTimeModulo = countNotificationTime_ % 5000; + if (!Manager::instance().incomingCallWaiting()) + return; - if ((countTimeModulo - countNotificationTime_) < 0) - Manager::instance().notificationIncomingCall(); + time_t now = time(NULL); - countNotificationTime_ = countTimeModulo; - } + // Notify maximum once every 5 seconds + if (difftime(now, lastNotificationTime_) < 5) + return; + + lastNotificationTime_ = now; + + // Enable notification only if more than one call + if (!Manager::instance().hasCurrentCall()) + return; + + Tone tone ("440/160", getSampleRate()); + unsigned int nbSample = tone.getSize(); + SFLDataFormat buf[nbSample]; + tone.getNext (buf, nbSample); + + /* Put the data in the urgent ring buffer */ + Manager::instance().audioLayerMutexLock(); + flushUrgent(); + putUrgent (buf, sizeof buf); + Manager::instance().audioLayerMutexUnlock(); } diff --git a/daemon/src/audio/audiolayer.h b/daemon/src/audio/audiolayer.h index 47a4fc70fa6d20543e9079360e48fbff982cf6d9..4df3af3bcd9d9c01f9c66fd3a76bd9dcf830a783 100644 --- a/daemon/src/audio/audiolayer.h +++ b/daemon/src/audio/audiolayer.h @@ -35,6 +35,7 @@ #define _AUDIO_LAYER_H #include <cc++/thread.h> // for ost::Mutex +#include <sys/time.h> #include "ringbuffer.h" @@ -334,15 +335,11 @@ class AudioLayer bool noiseSuppressState_; + private: /** - * Time counter used to trigger incoming call notification - */ - int countNotificationTime_; - - /** - * Used to get formated system time in order to compute incoming call notification + * Time of the last incoming call notification */ - ost::Time * time_; + time_t lastNotificationTime_; }; #endif // _AUDIO_LAYER_H_ diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 803cca7655b800ec02598eb618aab237a1db4b64..885e34a3a6a336a3fe1bd832f7d6497e18b03a2d 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -1470,7 +1470,7 @@ bool ManagerImpl::playDtmf (char code) // Multi-thread bool ManagerImpl::incomingCallWaiting () { - return (_nbIncomingWaitingCall > 0) ? true : false; + return _nbIncomingWaitingCall > 0; } void ManagerImpl::addWaitingCall (const std::string& id) @@ -1977,34 +1977,6 @@ ManagerImpl::getTelephoneFile () return _audiofile; } -void ManagerImpl::notificationIncomingCall (void) -{ - audioLayerMutexLock(); - - if(_audiodriver == NULL) { - _error("Manager: Error: Audio layer not initialized"); - audioLayerMutexUnlock(); - return; - } - - _debug ("ManagerImpl: Notification incoming call"); - - // Enable notification only if more than one call - if (hasCurrentCall()) { - std::ostringstream frequency; - frequency << "440/" << 160; - Tone tone (frequency.str(), _audiodriver->getSampleRate()); - unsigned int nbSample = tone.getSize(); - SFLDataFormat buf[nbSample]; - tone.getNext (buf, nbSample); - /* Put the data in the urgent ring buffer */ - _audiodriver->flushUrgent(); - _audiodriver->putUrgent (buf, sizeof (SFLDataFormat) * nbSample); - } - - audioLayerMutexUnlock(); -} - /////////////////////////////////////////////////////////////////////////////// // Private functions /////////////////////////////////////////////////////////////////////////////// diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index f523c99d13826dd7f0b2733bb7eabc9efc2760d4..9650d04412f08fbac3df20f34b67b30cf30f3d13 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -878,11 +878,6 @@ class ManagerImpl */ bool incomingCallWaiting (void); - /** - * Notification of incoming call when you are already busy - */ - void notificationIncomingCall (void); - /* * Inline functions to manage speaker volume control * Read by main thread and AudioLayer thread