Commit be1d42e6 authored by jpbl's avatar jpbl

Manager is now a singleton

parent 3080724f
......@@ -3054,7 +3054,7 @@ AC_DEFUN([AC_CHECK_COMPILERS],
AC_PROG_CXX
KDE_CHECK_FOR_BAD_COMPILER
dnl KDE_CHECK_FOR_BAD_COMPILER
if test "$GXX" = "yes" || test "$CXX" = "KCC"; then
if test "$kde_use_debug_code" != "no"; then
......
......@@ -35,7 +35,7 @@ AM_DISABLE_LIBRARIES
AC_PROG_LIBTOOL
AC_CHECK_COMPILERS
CXXFLAGS="$CXXFLAGS $USE_EXCEPTIONS "
CXXFLAGS="$CXXFLAGS $USE_EXCEPTIONS"
SFLPHONE_CXXFLAGS=""
......@@ -81,7 +81,10 @@ SFLPHONE_LIBS="$SFLPHONE_LIBS $libosip2_LIBS"
if test $ac_cv_header_eXosip_eXosip_h = no; then
AC_MSG_ERROR([*** missing eXipsip/eXosip.h. You need a working eXosip installation. See http://savannah.nongnu.org/projects/exosip/])
fi
SFLPHONE_LIBS="$SFLPHONE_LIBS -leXosip"
libexosip_LIBS="-leXosip "
SFLPHONE_LIBS="$SFLPHONE_LIBS $libexosip_LIBS"
AC_SUBST(LIBQT)
dnl if test $ac_cv_header_gsm_h = no; then
dnl AC_MSG_ERROR([*** missing gsm.h. You need a working GSM 06.10 lossy speech compression installation. See http://kbs.cs.tu-berlin.de/~jutta/toast.html])
......@@ -109,17 +112,17 @@ AM_CONDITIONAL(MAINTENER_CODE, test x$maintener = xyes)
if test $ac_cv_header_portaudio_h = no; then
AC_MSG_ERROR([*** missing portaudio.h. You need a working PortAudio installation. See http://www.portaudio.com])
fi
SFLPHONE_LIBS="$SFLPHONE_LIBS -lportaudio"
CXXFLAGS="$CXXFLAGS -DAUDIO_PORTAUDIO"
portaudio_LIBS="-lportaudio "
portaudio_CFLAGS="-DAUDIO_PORTAUDIO "
SFLPHONE_LIBS="$SFLPHONE_LIBS $portaudio_LIBS"
SFLPHONE_CXXFLAGS=="$SFLPHONE_CXXFLAGS $portaudio_CFLAGS"
AC_SUBST(portaudio_CFLAGS)
AC_SUBST(portaudio_LIB)
AC_SUBST(SFLPHONE_CXXFLAGS)
AC_SUBST(SFLPHONE_LIBS)
CXXFLAGS="$CXXFLAGS $SFLPHONE_CXXFLAGS"
LIBS="$LIBS $SFLPHONE_LIBS $LIBQT"
dnl AC_CONFIG_FILES(
AC_OUTPUT(
sflphone.spec \
......
......@@ -6,7 +6,6 @@ sflphone_SOURCES = \
configitem.cpp \
configuration.cpp \
configurationtree.cpp \
manager.cpp \
call.cpp \
eventthread.cpp \
error.cpp \
......@@ -15,6 +14,8 @@ sflphone_SOURCES = \
voIPLink.cpp \
sipcall.cpp \
skin.cpp \
managerimpl.cpp \
managerimpl.h \
manager.h \
global.h \
configitem.h \
......@@ -35,12 +36,10 @@ sflphone_SOURCES = \
sflphone_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\"
sflphone_LDFLAGS = $(QT_LDFLAGS) $(X_LDFLAGS)
sflphone_LDADD = gui/libguiframework.la audio/libaudio.la ../stund/libstun.la -lpthread
KDE_CXXFLAGS = $(USE_EXCEPTIONS)
AM_CPPFLAGS = $(QT_INCLUDES) $(X_INCLUDES) -Iaudio/pacpp/include
sflphone_LDFLAGS = $(QT_LDFLAGS) $(X_LDFLAGS)
sflphone_LDADD = gui/libguiframework.la audio/libaudio.la ../stund/libstun.la -lpthread $(LIBQT) $(SFLPHONE_LIBS)
KDE_CXXFLAGS = $(USE_EXCEPTIONS)
AM_CPPFLAGS = $(QT_INCLUDES) $(X_INCLUDES) -Iaudio/pacpp/include $(libccext2_CFLAGS) $(libccgnu2_CFLAGS) $(portaudio_CFLAGS)
......
......@@ -18,6 +18,6 @@ libaudio_la_SOURCES = \
tonegenerator.cpp tonegenerator.h \
ulaw.cpp ulaw.h
AM_CXXFLAGS = -Ipacpp/include/
AM_CXXFLAGS = -Ipacpp/include/ $(libccext2_CFLAGS) $(libccrtp1_CFLAGS) $(portaudio_CFLAGS)
libaudio_la_LIBADD = gsm/libgsm.la pacpp/source/portaudiocpp/libportaudiocpp.la
......@@ -27,12 +27,7 @@
#include <iostream>
#include <string>
#include "portaudio.h"
#include "../global.h"
#include "audiocodec.h"
#include "../configuration.h"
using namespace std;
......
......@@ -24,113 +24,113 @@
#include <string.h>
#include "audiolayer.h"
#include "ringbuffer.h"
#include "../error.h"
#include "../global.h"
#include "../manager.h"
using namespace std;
AudioLayer::AudioLayer (Manager* manager) {
_manager = manager;
initDevice();
_urgentRingBuffer = new RingBuffer(SIZEBUF);
_mainSndRingBuffer = new RingBuffer(SIZEBUF);
_micRingBuffer = new RingBuffer(SIZEBUF);
}
AudioLayer::AudioLayer ()
: _urgentRingBuffer(SIZEBUF)
, _mainSndRingBuffer(SIZEBUF)
, _micRingBuffer(SIZEBUF)
, _stream(NULL)
{}
// Destructor
AudioLayer::~AudioLayer (void)
{
closeStream();
autoSys->terminate();
delete autoSys;
delete _urgentRingBuffer;
delete _mainSndRingBuffer;
delete _micRingBuffer;
closeStream();
}
void
AudioLayer::initDevice (void) {
autoSys = new portaudio::AutoSystem();
autoSys->initialize();
}
void
AudioLayer::closeStream (void) {
AudioLayer::closeStream (void)
{
if(_stream) {
_stream->close();
delete _stream;
}
}
void
AudioLayer::openDevice (int index)
{
// Set up the System:
portaudio::System &sys = portaudio::System::instance();
// Set up the parameters required to open a (Callback)Stream:
portaudio::DirectionSpecificStreamParameters outParams(
sys.deviceByIndex(index), 2, portaudio::INT16, true,
sys.deviceByIndex(index).defaultLowOutputLatency(), NULL);
closeStream();
// Set up the parameters required to open a (Callback)Stream:
portaudio::DirectionSpecificStreamParameters
outParams(portaudio::System::instance().deviceByIndex(index),
2, portaudio::INT16, true,
portaudio::System::instance().deviceByIndex(index).defaultLowOutputLatency(),
NULL);
portaudio::DirectionSpecificStreamParameters inParams(
sys.deviceByIndex(index), 2, portaudio::INT16, true,
sys.deviceByIndex(index).defaultLowInputLatency(), NULL);
portaudio::DirectionSpecificStreamParameters
inParams(portaudio::System::instance().deviceByIndex(index),
2, portaudio::INT16, true,
portaudio::System::instance().deviceByIndex(index).defaultLowInputLatency(),
NULL);
portaudio::StreamParameters const params(inParams, outParams,
SAMPLING_RATE, FRAME_PER_BUFFER, paNoFlag);
portaudio::StreamParameters const params(inParams, outParams,
SAMPLING_RATE, FRAME_PER_BUFFER, paNoFlag);
// Create (and open) a new Stream, using the AudioLayer::audioCallback
_stream = new portaudio::MemFunCallbackStream<AudioLayer>(
params, *this, &AudioLayer::audioCallback);
// Create (and open) a new Stream, using the AudioLayer::audioCallback
_stream = new portaudio::MemFunCallbackStream<AudioLayer>(params,
*this,
&AudioLayer::audioCallback);
}
void
AudioLayer::startStream(void)
{
if (_manager->isDriverLoaded()) {
if (!_stream->isActive()) {
_stream->start();
}
}
if (Manager::instance().isDriverLoaded()) {
if (_stream && !_stream->isActive()) {
_stream->start();
}
}
}
void
AudioLayer::stopStream(void)
{
if (_manager->isDriverLoaded()) {
if (!_stream->isStopped()) {
_stream->stop();
}
}
if (Manager::instance().isDriverLoaded()) {
if (_stream && !_stream->isStopped()) {
_stream->stop();
}
}
}
void
AudioLayer::sleep(int msec)
{
portaudio::System &sys = portaudio::System::instance();
sys.sleep(msec);
portaudio::System::instance().sleep(msec);
}
int
bool
AudioLayer::isStreamActive (void)
{
return _stream->isActive();
if(_stream && _stream->isActive()) {
return true;
}
else {
return false;
}
}
int
bool
AudioLayer::isStreamStopped (void)
{
return _stream->isStopped();
if(_stream && _stream->isStopped()) {
return true;
}
else {
return false;
}
}
int
AudioLayer::audioCallback (const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo *timeInfo,
PaStreamCallbackFlags statusFlags) {
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo *timeInfo,
PaStreamCallbackFlags statusFlags) {
(void) timeInfo;
(void) statusFlags;
......@@ -138,7 +138,7 @@ AudioLayer::audioCallback (const void *inputBuffer, void *outputBuffer,
int16 *out = (int16 *) outputBuffer;
int toGet, toPut, urgentAvail, normalAvail, micAvailPut;
urgentAvail = _urgentRingBuffer->AvailForGet();
urgentAvail = _urgentRingBuffer.AvailForGet();
if (urgentAvail > 0) {
// Urgent data (dtmf, incoming call signal) come first.
if (urgentAvail < (int)framesPerBuffer) {
......@@ -146,24 +146,24 @@ AudioLayer::audioCallback (const void *inputBuffer, void *outputBuffer,
} else {
toGet = framesPerBuffer;
}
_urgentRingBuffer->Get(out, SAMPLES_SIZE(toGet));
_urgentRingBuffer.Get(out, SAMPLES_SIZE(toGet));
// Consume the regular one as well
_mainSndRingBuffer->Discard(SAMPLES_SIZE(toGet));
_mainSndRingBuffer.Discard(SAMPLES_SIZE(toGet));
}
else {
// If nothing urgent, play the regular sound samples
normalAvail = _mainSndRingBuffer->AvailForGet();
normalAvail = _mainSndRingBuffer.AvailForGet();
toGet = (normalAvail < (int)framesPerBuffer) ? normalAvail :
framesPerBuffer;
_mainSndRingBuffer->Get(out, SAMPLES_SIZE(toGet));
_mainSndRingBuffer.Get(out, SAMPLES_SIZE(toGet));
}
// Additionally handle the mike's audio stream
micAvailPut = _micRingBuffer->AvailForPut();
micAvailPut = _micRingBuffer.AvailForPut();
toPut = (micAvailPut <= (int)framesPerBuffer) ? micAvailPut :
framesPerBuffer;
_micRingBuffer->Put(in, SAMPLES_SIZE(toPut));
_micRingBuffer.Put(in, SAMPLES_SIZE(toPut));
return paContinue;
}
......
......@@ -26,6 +26,7 @@
#include "../global.h"
#include "ringbuffer.h"
#define FRAME_PER_BUFFER 160
#define MIC_CHANNELS 2 // 1=mono 2=stereo
......@@ -34,37 +35,35 @@
class RingBuffer;
class Manager;
class AudioLayer {
public:
AudioLayer (Manager*);
AudioLayer();
~AudioLayer (void);
void initDevice (void);
void openDevice (int);
void startStream (void);
void stopStream (void);
void sleep (int);
int isStreamActive (void);
int isStreamStopped (void);
bool isStreamActive (void);
bool isStreamStopped (void);
int audioCallback (const void *, void *, unsigned long,
const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags);
inline RingBuffer* urgentRingBuffer(void) { return _urgentRingBuffer; }
inline RingBuffer* mainSndRingBuffer(void) { return _mainSndRingBuffer; }
inline RingBuffer* micRingBuffer(void) { return _micRingBuffer; }
inline RingBuffer &urgentRingBuffer(void) { return _urgentRingBuffer; }
inline RingBuffer &mainSndRingBuffer(void) { return _mainSndRingBuffer; }
inline RingBuffer &micRingBuffer(void) { return _micRingBuffer; }
private:
void closeStream (void);
Manager* _manager;
RingBuffer* _urgentRingBuffer;
RingBuffer* _mainSndRingBuffer;
RingBuffer* _micRingBuffer;
RingBuffer _urgentRingBuffer;
RingBuffer _mainSndRingBuffer;
RingBuffer _micRingBuffer;
portaudio::MemFunCallbackStream<AudioLayer> *_stream;
portaudio::AutoSystem *autoSys;
portaudio::AutoSystem autoSys;
};
#endif // _AUDIO_LAYER_H_
......
......@@ -24,14 +24,14 @@
#include <iostream>
#include <string>
#include "../global.h"
#include "../manager.h"
#include "audiocodec.h"
#include "audiortp.h"
#include "audiolayer.h"
#include "codecDescriptor.h"
#include "ringbuffer.h"
#include "../configuration.h"
#include "../manager.h"
#include "../global.h"
#include "../user_cfg.h"
#include "../sipcall.h"
#include "../../stund/stun.h"
......@@ -43,9 +43,17 @@ using namespace std;
////////////////////////////////////////////////////////////////////////////////
// AudioRtp
////////////////////////////////////////////////////////////////////////////////
AudioRtp::AudioRtp (Manager *manager) {
_manager = manager;
AudioRtp::AudioRtp () {
string svr;
_RTXThread = NULL;
if (!Manager::instance().useStun() &&
get_config_fields_str(SIGNALISATION, PROXY).empty()) {
svr = get_config_fields_str(SIGNALISATION, PROXY);
} else {
svr = get_config_fields_str(SIGNALISATION, HOST_PART);
}
}
AudioRtp::~AudioRtp (void) {
......@@ -56,18 +64,19 @@ int
AudioRtp::createNewSession (SipCall *ca) {
// Start RTP Send/Receive threads
ca->enable_audio = 1;
if (!_manager->useStun()) {
if (!Manager::instance().useStun()) {
_symetric = false;
} else {
_symetric = true;
}
_RTXThread = new AudioRtpRTX (ca, _manager->getAudioDriver(),
_manager, _symetric);
_RTXThread = new AudioRtpRTX (ca,
Manager::instance().getAudioDriver(),
_symetric);
// Start PortAudio
_manager->getAudioDriver()->micRingBuffer()->flush();
_manager->getAudioDriver()->startStream();
Manager::instance().getAudioDriver()->micRingBuffer().flush();
Manager::instance().getAudioDriver()->startStream();
if (_RTXThread->start() != 0) {
return -1;
......@@ -89,18 +98,18 @@ AudioRtp::closeRtpSession (SipCall *ca) {
}
// Stop portaudio and flush ringbuffer
_manager->getAudioDriver()->stopStream();
_manager->getAudioDriver()->mainSndRingBuffer()->flush();
Manager::instance().getAudioDriver()->stopStream();
Manager::instance().getAudioDriver()->mainSndRingBuffer().flush();
}
}
////////////////////////////////////////////////////////////////////////////////
// AudioRtpRTX Class //
////////////////////////////////////////////////////////////////////////////////
AudioRtpRTX::AudioRtpRTX (SipCall *sipcall, AudioLayer* driver,
Manager *mngr, bool sym) {
AudioRtpRTX::AudioRtpRTX (SipCall *sipcall,
AudioLayer* driver,
bool sym) {
time = new Time();
_manager = mngr;
_ca = sipcall;
_sym =sym;
_audioDevice = driver;
......@@ -197,14 +206,14 @@ AudioRtpRTX::sendSessionFromMic (unsigned char* data_to_send, int16* data_from_m
int k;
int compSize;
if (_manager->getCall(_ca->getId())->isOnMute() or
!_manager->isCurrentId(_ca->getId())) {
if (Manager::instance().getCall(_ca->getId())->isOnMute() or
!Manager::instance().isCurrentId(_ca->getId())) {
// Mute :send 0's over the network.
_manager->getAudioDriver()->micRingBuffer()->Get(data_from_mic,
Manager::instance().getAudioDriver()->micRingBuffer().Get(data_from_mic,
RTP_FRAMES2SEND*2*sizeof(int16));
} else {
// Control volume for micro
int availFromMic = _manager->getAudioDriver()->micRingBuffer()->AvailForGet();
int availFromMic = Manager::instance().getAudioDriver()->micRingBuffer().AvailForGet();
int bytesAvail;
if (availFromMic < (int)RTP_FRAMES2SEND) {
bytesAvail = availFromMic;
......@@ -213,7 +222,7 @@ AudioRtpRTX::sendSessionFromMic (unsigned char* data_to_send, int16* data_from_m
}
// Get bytes from micRingBuffer to data_from_mic
_manager->getAudioDriver()->micRingBuffer()->Get(data_from_mic,
Manager::instance().getAudioDriver()->micRingBuffer().Get(data_from_mic,
SAMPLES_SIZE(bytesAvail));
// control volume and stereo->mono
for (int j = 0; j < RTP_FRAMES2SEND; j++) {
......@@ -272,20 +281,20 @@ AudioRtpRTX::receiveSessionForSpkr (int16* data_for_speakers,
}
// If the current call is the call which is answered
if (_manager->isCurrentId(_ca->getId())) {
if (Manager::instance().isCurrentId(_ca->getId())) {
// Set decoded data to sound device
_manager->getAudioDriver()->mainSndRingBuffer()->Put(data_for_speakers_tmp, SAMPLES_SIZE(RTP_FRAMES2SEND));
Manager::instance().getAudioDriver()->mainSndRingBuffer().Put(data_for_speakers_tmp, SAMPLES_SIZE(RTP_FRAMES2SEND));
}
// Notify (with a bip) an incoming call when there is already a call
countTime += time->getSecond();
if (_manager->getNumberOfCalls() > 0 and _manager->getbRingtone()) {
if (Manager::instance().getNumberOfCalls() > 0 and Manager::instance().getbRingtone()) {
countTime = countTime % 2000;
if (countTime < 10 and countTime > 0) {
_manager->notificationIncomingCall();
Manager::instance().notificationIncomingCall();
}
}
_manager->getAudioDriver()->startStream();
Manager::instance().getAudioDriver()->startStream();
delete cd;
delete adu;
......@@ -326,9 +335,8 @@ AudioRtpRTX::run (void) {
}
while (_ca->enable_audio != -1) {
// Store volume values
micVolume = _manager->getMicroVolume();
spkrVolume = _manager->getSpkrVolume();
micVolume = Manager::instance().getMicroVolume();
spkrVolume = Manager::instance().getSpkrVolume();
////////////////////////////
// Send session
......
......@@ -32,7 +32,6 @@ using namespace ost;
#define SIZEDATA SAMPLES_SIZE(RTP_FRAMES2SEND)
class AudioLayer;
class Manager;
class SipCall;
///////////////////////////////////////////////////////////////////////////////
......@@ -40,7 +39,7 @@ class SipCall;
///////////////////////////////////////////////////////////////////////////////
class AudioRtpRTX : public Thread, public TimerPort {
public:
AudioRtpRTX (SipCall *, AudioLayer*, Manager *, bool);
AudioRtpRTX (SipCall *, AudioLayer*, bool);
~AudioRtpRTX();
Time *time; // For incoming call notification
......@@ -52,7 +51,6 @@ private:
RTPSession* _sessionSend;
RTPSession* _sessionRecv;
SymmetricRTPSession* _session;
Manager* _manager;
bool _sym;
void initAudioRtpSession (void);
......@@ -65,15 +63,14 @@ private:
///////////////////////////////////////////////////////////////////////////////
class AudioRtp {
public:
AudioRtp (Manager *);
~AudioRtp (void);
AudioRtp();
~AudioRtp();
int createNewSession (SipCall *);
void closeRtpSession (SipCall *);
private:
AudioRtpRTX* _RTXThread;
Manager* _manager;
bool _symetric;
};
......
......@@ -95,7 +95,7 @@ DTMFGenerator::~DTMFGenerator() {
void DTMFGenerator::getSamples(int16* buffer, size_t n, unsigned char code) throw(DTMFException) {
size_t i;
if (!buffer) {
throw DTMFException("Invalid parameter value");
throw DTMFException("Invalid parameter value");
}
switch(code) {
......@@ -142,17 +142,15 @@ void DTMFGenerator::getNextSamples(int16* buffer, size_t n) throw(DTMFException)
size_t i;
if (!buffer) {
throw DTMFException("Invalid parameter");
return;
throw DTMFException("Invalid parameter");
}
if (state.sample == 0) {
throw DTMFException("DTMF generator not initialized");
return;
throw DTMFException("DTMF generator not initialized");
}
for(i = 0; i < n; i++) {
buffer[i] = state.sample[(state.offset + i) % SAMPLING_RATE];
buffer[i] = state.sample[(state.offset + i) % SAMPLING_RATE];
}
state.offset = (state.offset + i) % SAMPLING_RATE;
......
......@@ -41,8 +41,7 @@ int AMPLITUDE = 8192;
///////////////////////////////////////////////////////////////////////////////
// ToneThread implementation
///////////////////////////////////////////////////////////////////////////////
ToneThread::ToneThread (Manager *mngr, int16 *buf, int size) : Thread () {
this->mngr = mngr;
ToneThread::ToneThread (int16 *buf, int size) : Thread () {
this->buffer = buf;
this->size = size;
this->buf_ctrl_vol = new int16[size*CHANNELS];
......@@ -56,19 +55,19 @@ void
ToneThread::run (void) {
int k;
int spkrVolume;
while (mngr->getZonetone()) {
spkrVolume = mngr->getSpkrVolume();
while (Manager::instance().getZonetone()) {
spkrVolume = Manager::instance().getSpkrVolume();