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