diff --git a/src/audio/audiolayer.cpp b/src/audio/audiolayer.cpp index 4ce00c8d03a770e4756dc0eb27898a757dcb6ad7..34c6bf3782d913ad5faf1969157bbcc652e34990 100644 --- a/src/audio/audiolayer.cpp +++ b/src/audio/audiolayer.cpp @@ -194,7 +194,7 @@ AudioLayer::audioCallback (const void *inputBuffer, void *outputBuffer, // AvailForGet tell the number of chars inside the buffer // framePerBuffer are the number of int16 for one channel (left) // so we divise by short/char * 2 channels - int NBCHARFORTWOINT16 = sizeof(int16)/sizeof(char) * CHANNELS; + int NBCHARFORTWOINT16 = sizeof(int16)/sizeof(unsigned char) * CHANNELS; urgentAvail = _urgentRingBuffer.AvailForGet() / NBCHARFORTWOINT16; if (urgentAvail > 0) { // Urgent data (dtmf, incoming call signal) come first. @@ -209,11 +209,13 @@ AudioLayer::audioCallback (const void *inputBuffer, void *outputBuffer, normalAvail = _mainSndRingBuffer.AvailForGet() / NBCHARFORTWOINT16; toGet = (normalAvail < (int)framesPerBuffer) ? normalAvail : framesPerBuffer; - //_debug("mainsndringbuffer.get: %d vs %d : %d\n", normalAvail, (int)framesPerBuffer, toGet); - if (toGet) { + // _debug("mainsndringbuffer.get: %d vs %d : %d\n", normalAvail, (int)framesPerBuffer, toGet); + // fprintf(stderr, "%p:%d:%d:%ud\t",out,toGet*NBCHARFORTWOINT16,normalAvail,framesPerBuffer); + if (toGet) { _mainSndRingBuffer.Get(out, toGet*NBCHARFORTWOINT16, _manager.getSpkrVolume()); } else { toGet = framesPerBuffer * NBCHARFORTWOINT16; + //fprintf(stderr, "put zero... %d (in bytes)\n", toGet); _mainSndRingBuffer.PutZero(toGet); _mainSndRingBuffer.Get(out, toGet, 100); } @@ -224,6 +226,7 @@ AudioLayer::audioCallback (const void *inputBuffer, void *outputBuffer, micAvailPut = _micRingBuffer.AvailForPut(); toPut = (micAvailPut <= (int)framesPerBuffer) ? micAvailPut : framesPerBuffer; _micRingBuffer.Put(in, SAMPLES_SIZE(toPut), micVolume ); + //fprintf(stderr, "|mic:%p|", in); return paContinue; } diff --git a/src/audio/tonegenerator.cpp b/src/audio/tonegenerator.cpp index 7852741e6f488c9285478df2b9074d08257d5ab8..b22283d3c526fec4de6325960f7d21700ddace91 100644 --- a/src/audio/tonegenerator.cpp +++ b/src/audio/tonegenerator.cpp @@ -40,7 +40,7 @@ ToneThread::ToneThread (int16 *buf, int size) : ost::Thread () { this->buffer = buf; this->_size = size; // channels is 2 (global.h) - this->buf_ctrl_vol = new int16[size*CHANNELS]; + this->buf_ctrl_vol = new int16[_size*CHANNELS]; } ToneThread::~ToneThread (void) { @@ -59,7 +59,8 @@ ToneThread::run (void) { bool started = false; // How long do 'size' samples play ? - unsigned int play_time = (_size * 1000) / SAMPLING_RATE - 20; + // let's play it a bit smaller that it should to put more inside the buffer + unsigned int play_time = _size / (SAMPLING_RATE/1000); ManagerImpl& manager = Manager::instance(); manager.getAudioDriver()->flushMain(); diff --git a/src/global.h b/src/global.h index fc299d56471bd5533b626e50ba77a556b1244c9a..268be3db2650dd5e81cb88c5573c6369be08d1dd 100644 --- a/src/global.h +++ b/src/global.h @@ -27,13 +27,19 @@ typedef float float32; typedef short int16; -//#define DEBUG +#define DEBUG +#define DEBUG_LEVEL #ifdef DEBUG #define _debug(...) fprintf(stderr, "[sflphoned] " __VA_ARGS__) #else #define _debug(...) #endif +#ifdef DEBUG_LEVEL + #define _debugInit(...) fprintf(stderr, "[sflphoned-init] " __VA_ARGS__ "\n") +#else + #define _debugInit(...) +#endif #define SFLPHONED_VERSION "0.5" #define SFLPHONED_VERSIONNUM 0x000500 diff --git a/src/gui/guiframework.cpp b/src/gui/guiframework.cpp index a85784c95b1a2bfba6df0f068b09a25bc2a67a94..39264313810b2e7c753a46b1eeaf1a5c9755bc53 100644 --- a/src/gui/guiframework.cpp +++ b/src/gui/guiframework.cpp @@ -165,6 +165,15 @@ GuiFramework::stopTone () return true; } +/** + * Initialization section / redirection + */ +bool +GuiFramework::getEvents() +{ + return Manager::instance().getEvents(); +} + /** * Configuration section / redirection */ diff --git a/src/gui/guiframework.h b/src/gui/guiframework.h index 47407e3ed7eba89f49e605d109cd24169c9595ab..2912b6d17b709e11bcab4962d90f323898ea832b 100644 --- a/src/gui/guiframework.h +++ b/src/gui/guiframework.h @@ -76,6 +76,7 @@ public: bool stopTone (); // config + bool getEvents(); bool getZeroconf(const std::string& sequenceId); bool attachZeroconfEvents(const std::string& sequenceId, Pattern::Observer& observer); bool detachZeroconfEvents(Pattern::Observer& observer); diff --git a/src/gui/server/guiserverimpl.cpp b/src/gui/server/guiserverimpl.cpp index 2e17299d9f62ba7fe58d0e677a7a07c01fab9306..fd9f22f2aebef7b563bb4af61c98a43b49138567 100644 --- a/src/gui/server/guiserverimpl.cpp +++ b/src/gui/server/guiserverimpl.cpp @@ -136,6 +136,10 @@ GUIServerImpl::getEvents(const std::string& sequenceId) std::string stateCode; std::string stateMessage; + + // try to register, if not done yet... + GuiFramework::getEvents(); + if (GuiFramework::getRegistrationState(stateCode,stateMessage)) { _requestManager.sendResponse(ResponseMessage(stateCode, sequenceId, stateMessage)); } diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index 1065c7a910eb43c4fd0e293a43283af906f00a4f..252cc0691e75d492c01725921c5720bdd0f38c5e 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -111,8 +111,9 @@ ManagerImpl::~ManagerImpl (void) } void -ManagerImpl::init (void) +ManagerImpl::init() { + _debugInit("Volume Initialisation"); initVolume(); if (_exist == 0) { @@ -120,6 +121,7 @@ ManagerImpl::init (void) } try { + _debugInit("Audio Driver Selection"); selectAudioDriver(); loaded(true); } @@ -133,7 +135,7 @@ ManagerImpl::init (void) displayError(e.what()); throw e; } - catch (const std::exception &e) + catch (const std::runtime_error &e) { displayError(e.what()); throw e; @@ -143,20 +145,15 @@ ManagerImpl::init (void) displayError("An unknown exception occured."); throw; } - + _debugInit("Audio Codec Initialization"); initAudioCodec(); + _debugInit("Adding new VoIP Link"); // Set a sip voip link by default _voIPLinkVector.push_back(new SipVoIPLink()); - _voIPLinkVector.at(DFT_VOIP_LINK)->init(); - - if (_voIPLinkVector.at(DFT_VOIP_LINK)->checkNetwork()) { - // If network is available - if (getConfigInt(SIGNALISATION, AUTO_REGISTER) && _exist == 1) { - registerVoIPLink(); - } - } + // initRegisterVoIP was here, but we doing it after the gui loaded... + // the stun detection is long, so it's a better idea to do it after getEvents initZeroconf(); } @@ -441,6 +438,25 @@ ManagerImpl::saveConfig (void) return _setupLoaded; } +/** + * Main Thread + */ +void +ManagerImpl::initRegisterVoIPLink() +{ + if (_hasTriedToRegister == false) { + _voIPLinkVector.at(DFT_VOIP_LINK)->init(); // we call here, because it's long... + if (_voIPLinkVector.at(DFT_VOIP_LINK)->checkNetwork()) { + // If network is available + + if (getConfigInt(SIGNALISATION, AUTO_REGISTER) && _exist == 1) { + registerVoIPLink(); + } + } + _hasTriedToRegister = true; + } +} + /** * Initialize action (main thread) * Note that Registration is only send if STUN is not activated @@ -1113,16 +1129,20 @@ ManagerImpl::selectAudioDriver (void) { #if defined(AUDIO_PORTAUDIO) try { + _debugInit(" AudioLayer Creation"); _audiodriverPA = new AudioLayer(*this); int noDevice = getConfigInt(AUDIO, DRIVER_NAME); + _debugInit(" AudioLayer Device Count"); int nbDevice = portaudio::System::instance().deviceCount(); if (nbDevice == 0) { + _debug("Portaudio detect no sound cart."); throw std::runtime_error("Portaudio detect no sound card."); } else if (noDevice >= nbDevice) { _debug("Portaudio auto-select device #0 because device #%d is not found\n", noDevice); _setupLoaded = false; noDevice = 0; } + _debugInit(" AudioLayer Opening Device"); _audiodriverPA->openDevice(noDevice); } catch(...) { throw; @@ -1141,6 +1161,7 @@ void ManagerImpl::initZeroconf(void) { #ifdef USE_ZEROCONF + _debugInit("Zeroconf Initialization"); int useZeroconf = getConfigInt(PREFERENCES, CONFIG_ZEROCONF); if (useZeroconf) { @@ -1234,6 +1255,16 @@ ManagerImpl::detachZeroconfEvents(Pattern::Observer& observer) #endif return returnValue; } + +/** + * Main Thread + */ +bool +ManagerImpl::getEvents() { + initRegisterVoIPLink(); + return true; +} + /** * Main Thread */ diff --git a/src/managerimpl.h b/src/managerimpl.h index 0efb6d458f6a267fdc264f8d7197ba8bb0559f86..573b4fb33d2c7460412779c384b97c12f6b6802a 100644 --- a/src/managerimpl.h +++ b/src/managerimpl.h @@ -174,6 +174,7 @@ public: void stopVoiceMessageNotification (void); // configuration function requests + bool getEvents(); bool getZeroconf(const std::string& sequenceId); bool attachZeroconfEvents(const std::string& sequenceId, Pattern::Observer& observer); bool detachZeroconfEvents(Pattern::Observer& observer); @@ -374,9 +375,6 @@ private: // Current callid CALLID _currentCallId; - // Register state - REGISTRATION_STATE _registerState; - /* * For the call timer */ @@ -403,11 +401,18 @@ private: // Variables used in exception bool _loaded; - // tell if we have zeroconf is enabled - int _hasZeroconf; + // true if we tried to register Once + void initRegisterVoIPLink(); + bool _hasTriedToRegister; + // Register state + REGISTRATION_STATE _registerState; + void switchCall(CALLID id); + // tell if we have zeroconf is enabled + int _hasZeroconf; + #ifdef USE_ZEROCONF // DNSService contain every zeroconf services // configuration detected on the network diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp index 249cd9aa80558bbacdc75fffffcccddf9eda80c4..8ca560691b0f7914b85dae13640dcd90d873a8eb 100644 --- a/src/sipvoiplink.cpp +++ b/src/sipvoiplink.cpp @@ -49,12 +49,15 @@ SipVoIPLink::SipVoIPLink() // defautlt _sipcallVector object initialization _registrationSend = false; + _started = false; } SipVoIPLink::~SipVoIPLink(void) { endSipCalls(); delete _evThread; _evThread = NULL; - eXosip_quit(); + if (_started) { + eXosip_quit(); + } } // for voIPLink interface @@ -79,6 +82,8 @@ SipVoIPLink::init (void) tmp = std::string(PROGNAME) + "/" + std::string(SFLPHONED_VERSION); i = eXosip_init (); + _started = true; + if (i != 0) { _debug("Could not initialize eXosip\n"); exit (0); diff --git a/src/sipvoiplink.h b/src/sipvoiplink.h index aae96dafa779e8832a0b3845cde5dbcaef6f519b..0046f95e6015224412a474a0afb2ded638d71324 100644 --- a/src/sipvoiplink.h +++ b/src/sipvoiplink.h @@ -220,6 +220,7 @@ private: int _nMsgVoicemail; bool _registrationSend; // unregistered + bool _started; // eXosip_init and eXosip_start }; #endif // __SIP_VOIP_LINK_H__ diff --git a/src/user_cfg.h b/src/user_cfg.h index a0c00cd1ad6ad88cfd47cb90aa73b579bd571a29..343e0c887e33e0ee1b97a5ef83f94878961ada94 100644 --- a/src/user_cfg.h +++ b/src/user_cfg.h @@ -58,8 +58,6 @@ #define CODEC1 "Codecs.codec1" #define CODEC2 "Codecs.codec2" #define CODEC3 "Codecs.codec3" -#define CODEC4 "Codecs.codec4" -#define CODEC5 "Codecs.codec5" #define RING_CHOICE "Rings.ringChoice"