Commit 2ee8dbb5 authored by alexandresavard's avatar alexandresavard
Browse files

Merge branch 'master' into recording

Conflicts:

	src/audio/audiortp.cpp
	src/sipvoiplink.cpp
parents 007abd23 9c27daf4
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -2,16 +2,6 @@ include ../globals.mak ...@@ -2,16 +2,6 @@ include ../globals.mak
bin_PROGRAMS = sflphoned bin_PROGRAMS = sflphoned
if USE_ZEROCONF
ZEROCONFDIR = zeroconf
ZEROCONFLIB = zeroconf/libzeroconf.la
ZEROCONFFLAGS = -DUSE_ZEROCONF
else
ZEROCONFDIR =
ZEROCONFLIB =
ZEROCONFFLAGS =
endif
if USE_IAX if USE_IAX
# Use the global instead of locally built # Use the global instead of locally built
IAX_FLAGS = -DUSE_IAX IAX_FLAGS = -DUSE_IAX
...@@ -23,7 +13,7 @@ IAXSOURCES = ...@@ -23,7 +13,7 @@ IAXSOURCES =
IAXHEADERS = IAXHEADERS =
endif endif
SUBDIRS = audio config dbus $(ZEROCONFDIR) plug-in SUBDIRS = audio config dbus plug-in
# Add here the cpp files to be build with sflphone # Add here the cpp files to be build with sflphone
sflphoned_SOURCES = \ sflphoned_SOURCES = \
...@@ -43,7 +33,6 @@ sflphoned_SOURCES = \ ...@@ -43,7 +33,6 @@ sflphoned_SOURCES = \
sflphoned_CXXFLAGS = \ sflphoned_CXXFLAGS = \
-DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\" \ -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\" \
$(ZEROCONFFLAGS) \
$(IAX_FLAGS) $(IAX_FLAGS)
...@@ -52,14 +41,12 @@ sflphoned_LDADD = \ ...@@ -52,14 +41,12 @@ sflphoned_LDADD = \
./libsflphone.la \ ./libsflphone.la \
@CCGNU2_LIBS@ \ @CCGNU2_LIBS@ \
@CCEXT2_LIBS@ \ @CCEXT2_LIBS@ \
$(ZEROCONFLIB) \
$(IAX_LIBS) \ $(IAX_LIBS) \
$(PJSIP_LIBS) \ $(PJSIP_LIBS) \
@DBUSCPP_LIBS@ \ @DBUSCPP_LIBS@ \
@CCRTP_LIBS@ \ @CCRTP_LIBS@ \
@ALSA_LIBS@ \ @ALSA_LIBS@ \
@PULSEAUDIO_LIBS@ \ @PULSEAUDIO_LIBS@ \
-luuid \
@SAMPLERATE_LIBS@ @SAMPLERATE_LIBS@
#sflphoned_LDFLAGS=-pg #sflphoned_LDFLAGS=-pg
......
...@@ -96,6 +96,8 @@ class Account{ ...@@ -96,6 +96,8 @@ class Account{
*/ */
inline VoIPLink* getVoIPLink() { return _link; } inline VoIPLink* getVoIPLink() { return _link; }
inline void setVoIPLink (VoIPLink *link) { _link = link; }
/** /**
* Register the underlying VoIPLink. Launch the event listener. * Register the underlying VoIPLink. Launch the event listener.
* This should update the getRegistrationState() return value. * This should update the getRegistrationState() return value.
......
...@@ -54,15 +54,25 @@ AlsaLayer::~AlsaLayer (void) ...@@ -54,15 +54,25 @@ AlsaLayer::~AlsaLayer (void)
AlsaLayer::closeLayer() AlsaLayer::closeLayer()
{ {
_debugAlsa("Close ALSA streams\n"); _debugAlsa("Close ALSA streams\n");
if (_audioThread) try {
{ /* Stop the audio thread first */
_debug("Try to stop audio thread\n"); if (_audioThread)
delete _audioThread; _audioThread=NULL; {
delete _audioThread; _audioThread=NULL;
}
} }
catch(...) {
_debugException("! ARTP Exception: when stopping audiortp\n");
throw;
}
/* Then close the audio devices */
closeCaptureStream(); closeCaptureStream();
closePlaybackStream(); closePlaybackStream();
_CaptureHandle = 0;
_PlaybackHandle = 0;
} }
bool bool
...@@ -106,6 +116,7 @@ AlsaLayer::startStream(void) ...@@ -106,6 +116,7 @@ AlsaLayer::startStream(void)
prepareCaptureStream (); prepareCaptureStream ();
startCaptureStream (); startCaptureStream ();
startPlaybackStream (); startPlaybackStream ();
} }
void void
...@@ -116,38 +127,36 @@ AlsaLayer::stopStream(void) ...@@ -116,38 +127,36 @@ AlsaLayer::stopStream(void)
//stopPlaybackStream (); //stopPlaybackStream ();
/* Flush the ring buffers */ /* Flush the ring buffers */
flushUrgent(); flushUrgent ();
flushMain(); flushMain ();
flushMic ();
} }
int int
AlsaLayer::canGetMic() AlsaLayer::canGetMic()
{ {
int avail; if(_CaptureHandle)
return _micRingBuffer.AvailForGet();
if (! _CaptureHandle )
return 0;
avail = snd_pcm_avail_update( _CaptureHandle );
if( avail == -EPIPE ){
stop_capture ();
return 0;
}
else else
return ((avail < 0)? 0:avail); return 0;
} }
int int
AlsaLayer::getMic(void *buffer, int toCopy) AlsaLayer::getMic(void *buffer, int toCopy)
{ {
int res = 0 ; if( _CaptureHandle ){
if( _CaptureHandle ) return _micRingBuffer.Get(buffer, toCopy,100);
{ }
res = read( buffer, toCopy ); else
adjustVolume( buffer , toCopy , SFL_PCM_CAPTURE ); return 0;
} }
return res ;
bool AlsaLayer::isCaptureActive(void) {
ost::MutexLock guard( _mutex );
if( _CaptureHandle )
return (snd_pcm_state( _CaptureHandle) == SND_PCM_STATE_RUNNING ? true : false);
else
return false;
} }
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
...@@ -175,6 +184,7 @@ void AlsaLayer::closeCaptureStream (void) ...@@ -175,6 +184,7 @@ void AlsaLayer::closeCaptureStream (void)
void AlsaLayer::startCaptureStream (void) void AlsaLayer::startCaptureStream (void)
{ {
if(_CaptureHandle){ if(_CaptureHandle){
_debug("Start the capture\n");
snd_pcm_start (_CaptureHandle); snd_pcm_start (_CaptureHandle);
start_capture(); start_capture();
} }
...@@ -183,8 +193,10 @@ void AlsaLayer::startCaptureStream (void) ...@@ -183,8 +193,10 @@ void AlsaLayer::startCaptureStream (void)
void AlsaLayer::prepareCaptureStream (void) void AlsaLayer::prepareCaptureStream (void)
{ {
if (is_capture_open() ) { if (is_capture_open() ) {
if(snd_pcm_prepare (_CaptureHandle) < 0) _debug("Error preparing the device\n"); if(snd_pcm_prepare (_CaptureHandle) < 0)
prepare_capture (); _debug("");
else
prepare_capture ();
} }
} }
...@@ -360,7 +372,7 @@ AlsaLayer::open_device(std::string pcm_p, std::string pcm_c, int flag) ...@@ -360,7 +372,7 @@ AlsaLayer::open_device(std::string pcm_p, std::string pcm_c, int flag)
close_capture (); close_capture ();
return false; return false;
} }
if(!alsa_set_params( _CaptureHandle, 0, 8000 /*getSampleRate()*/ )){ if(!alsa_set_params( _CaptureHandle, 0, 8000 )){
_debug("capture failed\n"); _debug("capture failed\n");
snd_pcm_close( _CaptureHandle ); snd_pcm_close( _CaptureHandle );
close_capture (); close_capture ();
...@@ -368,12 +380,16 @@ AlsaLayer::open_device(std::string pcm_p, std::string pcm_c, int flag) ...@@ -368,12 +380,16 @@ AlsaLayer::open_device(std::string pcm_p, std::string pcm_c, int flag)
} }
open_capture (); open_capture ();
prepare_capture ();
startCaptureStream ();
} }
/* Start the secondary audio thread for callbacks */ /* Start the secondary audio thread for callbacks */
_audioThread->start(); try{
_audioThread->start();
}
catch (...) {
_debugException("Fail to start audio thread\n");
}
return true; return true;
} }
...@@ -382,8 +398,6 @@ AlsaLayer::open_device(std::string pcm_p, std::string pcm_c, int flag) ...@@ -382,8 +398,6 @@ AlsaLayer::open_device(std::string pcm_p, std::string pcm_c, int flag)
int int
AlsaLayer::write(void* buffer, int length) AlsaLayer::write(void* buffer, int length)
{ {
if (_trigger_request == true) if (_trigger_request == true)
{ {
_trigger_request = false; _trigger_request = false;
...@@ -417,13 +431,12 @@ AlsaLayer::write(void* buffer, int length) ...@@ -417,13 +431,12 @@ AlsaLayer::write(void* buffer, int length)
int int
AlsaLayer::read( void* buffer, int toCopy) AlsaLayer::read( void* buffer, int toCopy)
{ {
ost::MutexLock lock( _mutex ); //ost::MutexLock lock( _mutex );
int samples; int samples;
if(snd_pcm_state( _CaptureHandle ) == SND_PCM_STATE_XRUN) if(snd_pcm_state( _CaptureHandle ) == SND_PCM_STATE_XRUN)
{ {
_debug("xrun caught before start\n");
prepareCaptureStream (); prepareCaptureStream ();
startCaptureStream (); startCaptureStream ();
} }
...@@ -437,12 +450,16 @@ AlsaLayer::read( void* buffer, int toCopy) ...@@ -437,12 +450,16 @@ AlsaLayer::read( void* buffer, int toCopy)
case -EIO: case -EIO:
_debugAlsa(" XRUN capture ignored (%s)\n", snd_strerror(samples)); _debugAlsa(" XRUN capture ignored (%s)\n", snd_strerror(samples));
handle_xrun_capture(); handle_xrun_capture();
samples = snd_pcm_readi( _CaptureHandle, buffer, frames); //samples = snd_pcm_readi( _CaptureHandle, buffer, frames);
if (samples<0) samples=0; //if (samples<0) samples=0;
break;
case EPERM:
_debugAlsa(" Capture EPERM (%s)\n", snd_strerror(samples));
prepareCaptureStream ();
startCaptureStream ();
break; break;
default: default:
//_debugAlsa ("Error when capturing data ***********************************************: %s\n", snd_strerror(samples)); _debugAlsa("%s\n", snd_strerror(samples));
stopCaptureStream();
break; break;
} }
return 0; return 0;
...@@ -599,11 +616,12 @@ AlsaLayer::soundCardGetIndex( std::string description ) ...@@ -599,11 +616,12 @@ AlsaLayer::soundCardGetIndex( std::string description )
void AlsaLayer::audioCallback (void) void AlsaLayer::audioCallback (void)
{ {
int toGet, toPut, urgentAvail, normalAvail, micAvailPut, maxBytes; int toGet, toPut, urgentAvail, normalAvail, micAvailAlsa, micAvailPut, maxBytes;
unsigned short spkrVolume, micVolume; unsigned short spkrVolume, micVolume;
AudioLoop *tone; AudioLoop *tone;
SFLDataFormat *out; SFLDataFormat *out;
SFLDataFormat *in;
spkrVolume = _manager->getSpkrVolume(); spkrVolume = _manager->getSpkrVolume();
micVolume = _manager->getMicVolume(); micVolume = _manager->getMicVolume();
...@@ -650,13 +668,21 @@ void AlsaLayer::audioCallback (void) ...@@ -650,13 +668,21 @@ void AlsaLayer::audioCallback (void)
} }
// Additionally handle the mic's audio stream // Additionally handle the mic's audio stream
//micAvailPut = _micRingBuffer.AvailForPut(); //if(is_capture_running()){
//toPut = (micAvailPut <= (int)(framesPerBufferAlsa * sizeof(SFLDataFormat))) ? micAvailPut : framesPerBufferAlsa * sizeof(SFLDataFormat); micAvailAlsa = snd_pcm_avail_update(_CaptureHandle);
//_debug("AL: Nb sample: %d char, [0]=%f [1]=%f [2]=%f\n", toPut, in[0], in[1], in[2]); if(micAvailAlsa > 0) {
//_micRingBuffer.Put(in, toPut, micVolume); micAvailPut = _micRingBuffer.AvailForPut();
toPut = (micAvailAlsa <= micAvailPut) ? micAvailAlsa : micAvailPut;
in = (SFLDataFormat*)malloc(toPut * sizeof(SFLDataFormat));
toPut = read (in, toPut);
if (in != 0)
{
_micRingBuffer.Put(in, toPut, 100);
}
free(in); in=0;
}
} }
void* AlsaLayer::adjustVolume( void* buffer , int len, int stream ) void* AlsaLayer::adjustVolume( void* buffer , int len, int stream )
{ {
int vol, i, size; int vol, i, size;
......
...@@ -139,7 +139,7 @@ class AlsaLayer : public AudioLayer { ...@@ -139,7 +139,7 @@ class AlsaLayer : public AudioLayer {
void audioCallback (void); void audioCallback (void);
bool isCaptureActive (void) { return is_capture_running (); } bool isCaptureActive (void);
private: private:
......
This diff is collapsed.
...@@ -44,16 +44,10 @@ static void audioCallback ( pa_stream* s, size_t bytes, void* userdata ) ...@@ -44,16 +44,10 @@ static void audioCallback ( pa_stream* s, size_t bytes, void* userdata )
// Destructor // Destructor
PulseLayer::~PulseLayer (void) PulseLayer::~PulseLayer (void)
{ {
//closeLayer(); closeLayer ();
/* Delete the pointer streams */
delete playback;
delete record;
pa_context_disconnect( context ); pa_context_disconnect( context );
pa_context_unref( context ); pa_context_unref( context );
sleep(2);
} }
void void
......
...@@ -54,6 +54,7 @@ void AudioThread::run (void) ...@@ -54,6 +54,7 @@ void AudioThread::run (void)
{ {
while(!testCancel()) { while(!testCancel()) {
_alsa->audioCallback(); _alsa->audioCallback();
Thread::sleep(3);
} }
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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