diff --git a/src/audio/alsalayer.cpp b/src/audio/alsalayer.cpp index 33a6baae1a42e3211d962116247fdcf44128fae0..a6964f2a9f70aafad3bab0f07f65ba6c9e4d5cc6 100644 --- a/src/audio/alsalayer.cpp +++ b/src/audio/alsalayer.cpp @@ -31,6 +31,14 @@ int framesPerBufferAlsa = 2048; , _inChannel() , _outChannel() , IDSoundCards() + , _is_prepared_playback (false) + , _is_running_playback (false) + , _is_open_playback (false) + , _is_prepared_capture (false) + , _is_running_capture (false) + , _is_open_capture (false) + , _trigger_request (false) + { _debug(" Constructor of AlsaLayer called\n"); /* Instanciate the audio thread */ @@ -40,6 +48,7 @@ int framesPerBufferAlsa = 2048; // Destructor AlsaLayer::~AlsaLayer (void) { + _debug("Destructor of AlsaLayer called\n"); closeLayer(); } @@ -48,35 +57,31 @@ AlsaLayer::closeLayer() { _debugAlsa("Close ALSA streams\n"); - ost::MutexLock guard(_mutex); - if (_audioThread) { + _debug("Try to stop audio thread\n"); _audioThread->stop(); delete _audioThread; _audioThread=NULL; } + closeCaptureStream(); closePlaybackStream(); - - deviceClosed = true; } bool AlsaLayer::openDevice (int indexIn, int indexOut, int sampleRate, int frameSize, int stream , std::string plugin) { - - if(deviceClosed == false) + /* Close the devices before open it */ + if (stream == SFL_PCM_BOTH && is_capture_open() == true && is_playback_open() == true) { - if( stream == SFL_PCM_CAPTURE ) - closeCaptureStream(); - else if( stream == SFL_PCM_PLAYBACK) - closePlaybackStream(); - else - { - closeCaptureStream(); - closePlaybackStream(); - } + closeCaptureStream(); + closePlaybackStream(); } + else if ((stream == SFL_PCM_CAPTURE || stream == SFL_PCM_BOTH) && is_capture_open() == true) + closeCaptureStream (); + else if ((stream == SFL_PCM_PLAYBACK || stream == SFL_PCM_BOTH) && is_playback_open () == true) + closePlaybackStream (); + _indexIn = indexIn; _indexOut = indexOut; @@ -92,17 +97,7 @@ AlsaLayer::openDevice (int indexIn, int indexOut, int sampleRate, int frameSize, _debugAlsa(" : sample rate=%5d, format=%s\n", _sampleRate, SFLDataFormatString); ost::MutexLock lock( _mutex ); - - /*void **hint; - int r = snd_device_name_hint(-1, "pcm", &hint); - - while( *hint ){ - printf("%s\n", snd_device_name_get_hint(*hint, "DESC")); - ++hint; - }*/ - - std::string pcmp = buildDeviceTopo( plugin , indexOut , 0); std::string pcmc = buildDeviceTopo( PCM_PLUGHW , indexIn , 0); @@ -112,44 +107,22 @@ AlsaLayer::openDevice (int indexIn, int indexOut, int sampleRate, int frameSize, void AlsaLayer::startStream(void) { - ost::MutexLock guard(_mutex); - int err; - - if( _CaptureHandle && _PlaybackHandle ) - { - _debugAlsa(" Start stream\n"); - snd_pcm_prepare( _CaptureHandle ); - snd_pcm_start( _CaptureHandle ) ; - - snd_pcm_prepare( _PlaybackHandle ); - if( (err = snd_pcm_start( _PlaybackHandle)) < 0 ) _debugAlsa(" Cannot start (%s)\n", snd_strerror(err)); - } + _debug ("Start ALSA streams\n"); + prepareCaptureStream (); + startCaptureStream (); + startPlaybackStream (); } void AlsaLayer::stopStream(void) { - ost::MutexLock guard(_mutex); - - if( _CaptureHandle && _PlaybackHandle ) - { - //ost::MutexLock lock( _mutex ); - _debugAlsa(" Stop Stream\n "); - snd_pcm_drop( _CaptureHandle ); - snd_pcm_prepare( _CaptureHandle ); - snd_pcm_drop( _PlaybackHandle ); - snd_pcm_prepare( _PlaybackHandle ); - flushUrgent(); - flushMain(); - } -} + _debug ("Stop ALSA streams\n"); + stopCaptureStream (); + //stopPlaybackStream (); - - bool -AlsaLayer::isStreamActive (void) -{ - //ost::MutexLock lock( _mutex ); - return (isPlaybackActive() && isCaptureActive()); + /* Flush the ring buffers */ + flushUrgent(); + flushMain(); } int @@ -179,38 +152,86 @@ AlsaLayer::getMic(void *buffer, int toCopy) return res ; } - - bool -AlsaLayer::isStreamStopped (void) -{ - //ost::MutexLock lock( _mutex ); - return !(isStreamActive()); -} - - void AlsaLayer::reducePulseAppsVolume( void ){} void AlsaLayer::restorePulseAppsVolume( void ){} ////////////////////////////////////////////////////////////////////////////////////////////// ///////////////// ALSA PRIVATE FUNCTIONS //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// + +void AlsaLayer::stopCaptureStream (void) +{ + if(_CaptureHandle){ + snd_pcm_drop (_CaptureHandle); + stop_capture (); + } +} -bool -AlsaLayer::isPlaybackActive(void) { - //ost::MutexLock guard( _mutex ); - if( _PlaybackHandle ) - return (snd_pcm_state(_PlaybackHandle) == SND_PCM_STATE_RUNNING ? true : false); - else - return false; +void AlsaLayer::closeCaptureStream (void) +{ + if( is_capture_prepared() == true && is_capture_running() == true ) + stopCaptureStream (); + if (is_capture_open()) + snd_pcm_close (_CaptureHandle); + + close_capture (); } -bool -AlsaLayer::isCaptureActive(void) { - //ost::MutexLock guard( _mutex ); - if( _CaptureHandle ) - return (snd_pcm_state( _CaptureHandle) == SND_PCM_STATE_RUNNING ? true : false); - else - return false; +void AlsaLayer::startCaptureStream (void) +{ + if(_CaptureHandle){ + snd_pcm_start (_CaptureHandle); + start_capture(); + } +} + +void AlsaLayer::prepareCaptureStream (void) +{ + int err; + + err = snd_pcm_prepare (_CaptureHandle); + if( err<0 ) + _debug("Error preparing the device\n"); + + prepare_capture (); +} + +void AlsaLayer::stopPlaybackStream (void) +{ + if( _PlaybackHandle){ + snd_pcm_drop (_PlaybackHandle); + stop_playback (); + } +} + + +void AlsaLayer::closePlaybackStream (void) +{ + if( is_playback_prepared() == true && is_playback_running() == true ) + stopPlaybackStream (); + if (is_playback_open()) + snd_pcm_close (_PlaybackHandle); + + close_playback (); +} + +void AlsaLayer::startPlaybackStream (void) +{ + if( _PlaybackHandle){ + snd_pcm_start (_PlaybackHandle); + start_playback(); + } +} + +void AlsaLayer::preparePlaybackStream (void) +{ + int err; + + err = snd_pcm_prepare (_PlaybackHandle); + if( err<0 ) + _debug("Error preparing the device\n"); + + prepare_playback (); } bool AlsaLayer::alsa_set_params( snd_pcm_t *pcm_handle, int type, int rate ){ @@ -311,12 +332,8 @@ bool AlsaLayer::alsa_set_params( snd_pcm_t *pcm_handle, int type, int rate ){ return false; } - if( type == 1 ){ - - } snd_pcm_sw_params_free( swparams ); - deviceClosed = false; return true; } @@ -340,6 +357,8 @@ AlsaLayer::open_device(std::string pcm_p, std::string pcm_c, int flag) snd_pcm_close( _PlaybackHandle ); return false; } + + open_playback (); } if(flag == SFL_PCM_BOTH || flag == SFL_PCM_CAPTURE) @@ -354,9 +373,10 @@ AlsaLayer::open_device(std::string pcm_p, std::string pcm_c, int flag) snd_pcm_close( _CaptureHandle ); return false; } - if( (err = snd_pcm_start( _CaptureHandle ))<0) { - _debugAlsa( "snd_pcm_start failed\n"); - } + + open_capture (); + + startCaptureStream (); } /* Start the secondary audio thread for callbacks */ @@ -369,33 +389,34 @@ AlsaLayer::open_device(std::string pcm_p, std::string pcm_c, int flag) int AlsaLayer::write(void* buffer, int length) { - //if(snd_pcm_state( _PlaybackHandle ) == SND_PCM_STATE_XRUN) - //handle_xrun_playback(); - //_debugAlsa("avail = %d - toWrite = %d\n" , snd_pcm_avail_update( _PlaybackHandle ) , length / 2); - snd_pcm_uframes_t frames = snd_pcm_bytes_to_frames( _PlaybackHandle, length); - int err = snd_pcm_writei( _PlaybackHandle , buffer , frames ); - switch(err) { - case -EAGAIN: - _debugAlsa("EAGAIN (%s)\n", snd_strerror( err )); - snd_pcm_resume( _PlaybackHandle ); - break; - case -EPIPE: - _debugAlsa(" UNDERRUN (%s)\n", snd_strerror(err)); - handle_xrun_playback(); - snd_pcm_writei( _PlaybackHandle , buffer , frames ); - break; - case -ESTRPIPE: - _debugAlsa(" ESTRPIPE(%s)\n", snd_strerror(err)); - snd_pcm_resume( _PlaybackHandle ); - break; - case -EBADFD: - _debugAlsa(" (%s)\n", snd_strerror( err )); - break; + + if (_trigger_request == true) + { + _trigger_request = false; + startPlaybackStream (); } - if( ( err >=0 ) && ( err < (int)frames ) ) - _debugAlsa("Short write : %d out of %d\n", err , (int)frames); + snd_pcm_uframes_t frames = snd_pcm_bytes_to_frames( _PlaybackHandle, length); + int err; + if ((err=snd_pcm_writei( _PlaybackHandle , buffer , frames ))<0) + { + switch(err) { + case -EPIPE: + case -ESTRPIPE: + case -EIO: + //_debugAlsa(" XRUN playback ignored (%s)\n", snd_strerror(err)); + handle_xrun_playback(); + if (snd_pcm_writei( _PlaybackHandle , buffer , frames )<0) + _debugAlsa ("XRUN handling failed\n"); + _trigger_request = true; + break; + default: + //_debugAlsa ("Write error unknown - dropping frames **********************************: %s\n", snd_strerror(err)); + stopPlaybackStream (); + break; + } + } return ( err > 0 )? err : 0 ; } @@ -405,29 +426,29 @@ AlsaLayer::read( void* buffer, int toCopy) { ost::MutexLock lock( _mutex ); - if(deviceClosed || _CaptureHandle == NULL) - return 0; + int samples; - int err; if(snd_pcm_state( _CaptureHandle ) == SND_PCM_STATE_XRUN) { - snd_pcm_prepare( _CaptureHandle ); - snd_pcm_start( _CaptureHandle ); + prepareCaptureStream (); + startCaptureStream (); } + snd_pcm_uframes_t frames = snd_pcm_bytes_to_frames( _CaptureHandle, toCopy ); - if(( err = snd_pcm_readi( _CaptureHandle, buffer, frames)) < 0 ) { - switch(err){ - case EPERM: - _debugAlsa(" Capture EPERM (%s)\n", snd_strerror(err)); - snd_pcm_prepare( _CaptureHandle); - snd_pcm_start( _CaptureHandle ); - break; - case -EAGAIN: - _debugAlsa(" Capture EAGAIN (%s)\n", snd_strerror(err)); - break; + if(( samples = snd_pcm_readi( _CaptureHandle, buffer, frames)) < 0 ) { + switch (samples) + { case -EPIPE: - _debugAlsa(" Capture EPIPE (%s)\n", snd_strerror(err)); + case -ESTRPIPE: + 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; + break; + default: + //_debugAlsa ("Error when capturing data ***********************************************: %s\n", snd_strerror(samples)); + stopCaptureStream(); break; } return 0; @@ -446,9 +467,9 @@ AlsaLayer::handle_xrun_capture( void ) int res = snd_pcm_status( _CaptureHandle, status ); if( res <= 0){ if(snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN ){ - snd_pcm_drop( _CaptureHandle ); - snd_pcm_prepare( _CaptureHandle ); - snd_pcm_start( _CaptureHandle ); + stop_capture (); + prepare_capture (); + start_capture (); } } else @@ -468,9 +489,9 @@ AlsaLayer::handle_xrun_playback( void ) state = snd_pcm_status_get_state( status ); if( state == SND_PCM_STATE_XRUN ) { - snd_pcm_drop( _PlaybackHandle ); - snd_pcm_prepare( _PlaybackHandle ); - //snd_pcm_start( _PlaybackHandle ); + stopPlaybackStream (); + preparePlaybackStream (); + _trigger_request = true; } } } @@ -545,25 +566,7 @@ AlsaLayer::getSoundCardsInfo( int stream ) return cards_id; } - void -AlsaLayer::closeCaptureStream( void) -{ - if(_CaptureHandle){ - snd_pcm_drop( _CaptureHandle ); - snd_pcm_close( _CaptureHandle ); - _CaptureHandle = 0; - } -} - void -AlsaLayer::closePlaybackStream( void) -{ - if(_PlaybackHandle){ - snd_pcm_drop( _PlaybackHandle ); - snd_pcm_close( _PlaybackHandle ); - _PlaybackHandle = 0; - } -} bool AlsaLayer::soundCardIndexExist( int card , int stream ) @@ -653,8 +656,8 @@ void AlsaLayer::audioCallback (void) } // Additionally handle the mic's audio stream - micAvailPut = _micRingBuffer.AvailForPut(); - toPut = (micAvailPut <= (int)(framesPerBufferAlsa * sizeof(SFLDataFormat))) ? micAvailPut : framesPerBufferAlsa * sizeof(SFLDataFormat); + //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); + //_micRingBuffer.Put(in, toPut, micVolume); } diff --git a/src/audio/alsalayer.h b/src/audio/alsalayer.h index 9f8ffe0283620a163499612fa7e1d865f2b0f9c7..b64d1e66810879a14f235425fe165ce2b02bc706 100644 --- a/src/audio/alsalayer.h +++ b/src/audio/alsalayer.h @@ -80,34 +80,6 @@ class AlsaLayer : public AudioLayer { void stopStream(void); /** - * Check if the playback is running - * @return true if the state of the playback handle equals SND_PCM_STATE_RUNNING - * false otherwise - */ - bool isPlaybackActive( void ); - - /** - * Check if the capture is running - * @return true if the state of the capture handle equals SND_PCM_STATE_RUNNING - * false otherwise - */ - bool isCaptureActive( void ); - - /** - * Check if both capture and playback are running - * @return true if capture and playback are running - * false otherwise - */ - bool isStreamActive(void); - - /** - * Check if both capture and playback are stopped - * @return true if capture and playback are stopped - * false otherwise - */ - bool isStreamStopped(void); - - /** * Query the capture device for number of bytes available in the hardware ring buffer * @return int The number of bytes available */ @@ -191,17 +163,44 @@ class AlsaLayer : public AudioLayer { // Assignment Operator AlsaLayer& operator=( const AlsaLayer& rh); + bool _is_prepared_playback; + bool _is_prepared_capture; + bool _is_running_capture; + bool _is_running_playback; + bool _is_open_playback; + bool _is_open_capture; + bool _trigger_request; + + bool is_playback_prepared (void) { return _is_prepared_playback; } + bool is_capture_prepared (void) { return _is_prepared_capture; } + void prepare_playback (void) { _is_prepared_playback = true; } + void prepare_capture (void) { _is_prepared_capture = true; } + bool is_capture_running (void) { return _is_running_capture; } + bool is_playback_running (void) { return _is_running_playback; } + void start_playback (void) { _is_running_playback = true; } + void stop_playback (void) { _is_running_playback = false; _is_prepared_playback = false; } + void start_capture (void) { _is_running_capture = true; } + void stop_capture (void) { _is_running_capture = false; _is_prepared_capture = false; } + void close_playback (void) { _is_open_playback = false; } + void close_capture (void) { _is_open_capture = false; } + void open_playback (void) { _is_open_playback = true; } + void open_capture (void) { _is_open_capture = true; } + bool is_capture_open (void) { return _is_open_capture; } + bool is_playback_open (void) { return _is_open_playback; } + /** * Drop the pending frames and close the capture device * ALSA Library API */ void closeCaptureStream( void ); + void stopCaptureStream( void ); + void startCaptureStream( void ); + void prepareCaptureStream( void ); - /** - * Drop the pending frames and close the playback device - * ALSA Library API - */ void closePlaybackStream( void ); + void stopPlaybackStream( void ); + void startPlaybackStream( void ); + void preparePlaybackStream( void ); /** * Open the specified device. diff --git a/src/audio/audiolayer.cpp b/src/audio/audiolayer.cpp index a94eaf2595d22324cd47f96b44cf2e6fbdab26f7..3eea4392c737b51c3f954b438ca3dac7b57a30b9 100644 --- a/src/audio/audiolayer.cpp +++ b/src/audio/audiolayer.cpp @@ -31,6 +31,12 @@ void AudioLayer::flushUrgent (void) _urgentRingBuffer.flush(); } +void AudioLayer::flushMic (void) +{ + ost::MutexLock guard(_mutex); + _micRingBuffer.flush(); +} + int AudioLayer::putUrgent(void* buffer, int toCopy) { int a; diff --git a/src/audio/audiolayer.h b/src/audio/audiolayer.h index 6a558c9081f480a6a91be05fce050a68e422a77f..91aaafe78a2a584fd927b8030447dec25e501f36 100644 --- a/src/audio/audiolayer.h +++ b/src/audio/audiolayer.h @@ -60,7 +60,6 @@ class AudioLayer { , _micRingBuffer( SIZEBUF ) , _defaultVolume(100) , _talk ( false ) - , deviceClosed ( true ) , _indexIn ( 0 ) , _indexOut ( 0 ) , _sampleRate ( 0 ) @@ -77,7 +76,7 @@ class AudioLayer { /** * Destructor */ - ~AudioLayer(void){} + virtual ~AudioLayer(void) {} virtual void closeLayer( void ) = 0; @@ -110,14 +109,6 @@ class AudioLayer { */ virtual void stopStream(void) = 0; - - /** - * Check if the capture is running - * @return true if the state of the capture handle equals SND_PCM_STATE_RUNNING - * false otherwise - */ - virtual bool isCaptureActive( void ) = 0; - /** * Query the capture device for number of bytes available in the hardware ring buffer * @return int The number of bytes available @@ -194,6 +185,11 @@ class AudioLayer { void flushUrgent (void); + /** + * Flush the mic ringbuffer + */ + void flushMic(); + /** * Write accessor to the error state @@ -282,13 +278,6 @@ class AudioLayer { */ bool _talk; - /** - * Enable to determine if the devices are opened or not - * true if the devices are closed - * false otherwise - */ - bool deviceClosed; - /** * Number of audio cards on which capture stream has been opened */ diff --git a/src/audio/audiortp.cpp b/src/audio/audiortp.cpp index 31f90fe56c662c8c159ced5cd5d77da3fcd7fb6e..ed25feec437a4373e2dc787453a348e3e9bb510a 100644 --- a/src/audio/audiortp.cpp +++ b/src/audio/audiortp.cpp @@ -60,7 +60,6 @@ AudioRtp::createNewSession (SIPCall *ca) { _debug("! ARTP Failure: Thread already exists..., stopping it\n"); _debug("**********************************************************\n"); delete _RTXThread; _RTXThread = 0; - //return -1; } // Start RTP Send/Receive threads @@ -263,7 +262,7 @@ AudioRtpRTX::sendSessionFromMic(int timestamp) int nb_sample_up = nbSample; int nbSamplesMax = _layerFrameSize * _audiocodec->getClockRate() / 1000; - //_debug("resample data\n"); + //_debug("resample data = %i\n", nb_sample_up); nbSample = reSampleData(_audiocodec->getClockRate(), nb_sample_up, DOWN_SAMPLING); if ( nbSample < nbSamplesMax - 10 ) { // if only 10 is missing, it's ok diff --git a/src/audio/pulselayer.cpp b/src/audio/pulselayer.cpp index 4004cd557f43aa6ab6b3798c6ab4121566129042..9843666c645c3bef501f25beb4b22785e55542bc 100644 --- a/src/audio/pulselayer.cpp +++ b/src/audio/pulselayer.cpp @@ -198,12 +198,6 @@ PulseLayer::getMic(void *buffer, int toCopy) return 0; } - void -PulseLayer::flushMic() -{ - _micRingBuffer.flush(); -} - void PulseLayer::startStream (void) { @@ -221,6 +215,8 @@ PulseLayer::stopStream (void) pa_stream_flush( playback->pulseStream(), NULL, NULL ); pa_stream_flush( record->pulseStream(), NULL, NULL ); flushMic(); + flushMain(); + flushUrgent(); } @@ -273,7 +269,7 @@ void PulseLayer::writeToSpeaker( void ) if (urgentAvail > 0) { // Urgent data (dtmf, incoming call signal) come first. - //_debug("Play urgent!: %i\n" , urgentAvail); + //_debug("Play urgent!: %i\e" , urgentAvail); toGet = (urgentAvail < (int)(framesPerBuffer * sizeof(SFLDataFormat))) ? urgentAvail : framesPerBuffer * sizeof(SFLDataFormat); out = (SFLDataFormat*)pa_xmalloc(toGet * sizeof(SFLDataFormat) ); _urgentRingBuffer.Get(out, toGet, 100); diff --git a/src/audio/pulselayer.h b/src/audio/pulselayer.h index ae1844b7861edcca8e6eb23849b526126697d726..a1948652411aa9fd45c8c06653c74b339194b385 100644 --- a/src/audio/pulselayer.h +++ b/src/audio/pulselayer.h @@ -57,16 +57,6 @@ class PulseLayer : public AudioLayer { void stopStream(void); - /** - * UNUSED in pulseaudio layer - */ - bool isCaptureActive( void ) { return true; } - - /** - * UNUSED in pulseaudio layer - */ - bool isStreamActive (void); - /** * Query the capture device for number of bytes available in the hardware ring buffer * @return int The number of bytes available @@ -81,11 +71,6 @@ class PulseLayer : public AudioLayer { */ int getMic(void *, int); - /** - * Flush the mic ringbuffer - */ - void flushMic(); - static void overflow ( pa_stream* s, void* userdata ); static void underflow ( pa_stream* s, void* userdata ); static void stream_state_callback( pa_stream* s, void* user_data ); diff --git a/src/eventthread.cpp b/src/eventthread.cpp index c6389ecad181eb010b564ab3e970747e7b498df5..045d62dd63bb24dc663b5f1ea664975805c00730 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -59,5 +59,10 @@ void AudioThread::run (void) void AudioThread::stop (void) { - exit(); + try{ + terminate(); + } catch(...){ + _debugException("! ARTP: Thread destructor didn't terminate correctly"); + throw; + } } diff --git a/src/iaxvoiplink.cpp b/src/iaxvoiplink.cpp index 6a553427c61a7002f11c92319ba1590b7f3affc3..8fc1c5f308539f677d871d1d2996994c788c0fbc 100644 --- a/src/iaxvoiplink.cpp +++ b/src/iaxvoiplink.cpp @@ -285,7 +285,7 @@ IAXVoIPLink::sendAudioFromMic(void) _mutexIAX.enterMutex(); // Make sure the session and the call still exists. if (currentCall->getSession()) { - if ( iax_send_voice(currentCall->getSession(), currentCall->getFormat(), micDataEncoded, compSize, nbSample) == -1) { + if (iax_send_voice(currentCall->getSession(), currentCall->getFormat(), micDataEncoded, compSize, nbSample) == -1) { _debug("IAX: Error sending voice data.\n"); } } @@ -540,8 +540,6 @@ IAXVoIPLink::iaxOutgoingInvite(IAXCall* call) std::string username, strNum; char *lang=NULL; int wait, audio_format_preferred, audio_format_capability; - char user[username.length()+1]; - char num[strNum.length()+1]; IAXAccount *account; newsession = iax_session_new(); @@ -554,16 +552,14 @@ IAXVoIPLink::iaxOutgoingInvite(IAXCall* call) account = dynamic_cast<IAXAccount*> (getAccountPtr()); username = account->getUsername(); strNum = username + ":" + account->getPassword() + "@" + account->getHostname() + "/" + call->getPeerNumber(); - strcpy(user, username.c_str()); - strcpy(num, strNum.c_str()); wait = 0; /** @todo Make preference dynamic, and configurable */ audio_format_preferred = call->getFirstMatchingFormat(call->getSupportedFormat()); audio_format_capability = call->getSupportedFormat(); - _debug("IAX New call: %s\n", num); - iax_call(newsession, user, user, num, lang, wait, audio_format_preferred, audio_format_capability); + _debug("IAX New call: %s\n", strNum.c_str()); + iax_call(newsession, username.c_str(), username.c_str(), strNum.c_str(), lang, wait, audio_format_preferred, audio_format_capability); return true; } @@ -653,8 +649,8 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call) case IAX_EVENT_VOICE: //_debug("Should have a decent value!!!!!! = %i\n" , call -> getAudioCodec()); //TODO Check this method - if( !audiolayer -> isCaptureActive()) - audiolayer->startStream(); + //if( !audiolayer -> is_capture_running()) + //audiolayer->startStream(); iaxHandleVoiceEvent(event, call); break; diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index 56f5cb18c8f28d8af32673c0c2d450ca5654e0af..3a06ab61923c0d8b445d8c23afa0fce4a4a5e295 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -1590,17 +1590,20 @@ ManagerImpl::initAudioDriver(void) void ManagerImpl::selectAudioDriver (void) { - int layer = _audiodriver->getLayerType(); + int layer, numCardIn, numCardOut, sampleRate, frameSize; + std::string alsaPlugin; + + layer = _audiodriver->getLayerType(); _debug("Audio layer type: %i\n" , layer); - std::string alsaPlugin = getConfigString( AUDIO , ALSA_PLUGIN ); - int numCardIn = getConfigInt( AUDIO , ALSA_CARD_ID_IN ); - int numCardOut = getConfigInt( AUDIO , ALSA_CARD_ID_OUT ); - int sampleRate = getConfigInt( AUDIO , ALSA_SAMPLE_RATE ); + alsaPlugin = getConfigString( AUDIO , ALSA_PLUGIN ); + numCardIn = getConfigInt( AUDIO , ALSA_CARD_ID_IN ); + numCardOut = getConfigInt( AUDIO , ALSA_CARD_ID_OUT ); + sampleRate = getConfigInt( AUDIO , ALSA_SAMPLE_RATE ); if (sampleRate <=0 || sampleRate > 48000) { sampleRate = 44100; } - int frameSize = getConfigInt( AUDIO , ALSA_FRAME_SIZE ); + frameSize = getConfigInt( AUDIO , ALSA_FRAME_SIZE ); if( !_audiodriver -> soundCardIndexExist( numCardIn , SFL_PCM_CAPTURE ) ) { @@ -1614,8 +1617,7 @@ ManagerImpl::selectAudioDriver (void) numCardOut = ALSA_DFT_CARD_ID ; setConfig( AUDIO , ALSA_CARD_ID_OUT , ALSA_DFT_CARD_ID ); } - - + if(CHECK_INTERFACE( layer , ALSA )) { delete _audiodriver; diff --git a/src/samplerateconverter.cpp b/src/samplerateconverter.cpp index 3c6d0ed90db1902bc1e1ee0f29224f1e767453b4..52d047ca4cb5c5da507b1d91b4a7851b49cea9b9 100644 --- a/src/samplerateconverter.cpp +++ b/src/samplerateconverter.cpp @@ -78,6 +78,7 @@ void SamplerateConverter::init( void ) { int SamplerateConverter::upsampleData( SFLDataFormat* dataIn , SFLDataFormat* dataOut, int samplerate1 , int samplerate2 , int nbSamples ){ double upsampleFactor = (double)samplerate2 / samplerate1 ; + //_debug("factor = %f\n" , upsampleFactor); int nbSamplesMax = (int) ( samplerate2 * getFramesize() / 1000 ); if( upsampleFactor != 1 && dataIn != NULL ) { @@ -106,7 +107,7 @@ int SamplerateConverter::downsampleData( SFLDataFormat* dataIn , SFLDataFormat* double downsampleFactor = (double)samplerate1 / samplerate2; //_debug("factor = %f\n" , downsampleFactor); int nbSamplesMax = (int) ( samplerate1 * getFramesize() / 1000 ); - if ( downsampleFactor != 1) + if ( downsampleFactor != 1 ) { SRC_DATA src_data; src_data.data_in = _floatBufferUpMic;