Add debugging information for initialization, the audiolayer initialization is too long

This commit is contained in:
yanmorin
2005-10-23 20:46:21 +00:00
parent 78c6b42bce
commit f418734e8e
11 changed files with 89 additions and 25 deletions

View File

@ -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;
}

View File

@ -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();

View File

@ -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

View File

@ -165,6 +165,15 @@ GuiFramework::stopTone ()
return true;
}
/**
* Initialization section / redirection
*/
bool
GuiFramework::getEvents()
{
return Manager::instance().getEvents();
}
/**
* Configuration section / redirection
*/

View File

@ -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);

View File

@ -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));
}

View File

@ -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
*/

View File

@ -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

View File

@ -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);

View File

@ -220,6 +220,7 @@ private:
int _nMsgVoicemail;
bool _registrationSend; // unregistered
bool _started; // eXosip_init and eXosip_start
};
#endif // __SIP_VOIP_LINK_H__

View File

@ -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"