Commit fc906287 authored by Rafaël Carré's avatar Rafaël Carré
Browse files

* #6629 : correct AudioLayer::notifyincomingCall()

move some code from managerimpl code
parent aa07e16e
......@@ -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();
}
......@@ -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_
......@@ -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
///////////////////////////////////////////////////////////////////////////////
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment