From 194dae11ac51dd47f748148d534d5be29311ca5b Mon Sep 17 00:00:00 2001 From: Alexandre Savard <alexandre.savard@savoirfairelinux.net> Date: Mon, 2 Mar 2009 11:51:01 -0500 Subject: [PATCH] Switching from ALSA to PULSEAUDIO during a call --- src/audio/alsalayer.cpp | 4 ++-- src/audio/audiostream.cpp | 1 + src/audio/pulselayer.cpp | 8 ++++---- src/iaxvoiplink.cpp | 2 ++ src/managerimpl.cpp | 29 ++++++++++++++++++++++++----- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/audio/alsalayer.cpp b/src/audio/alsalayer.cpp index b1b0dd69a6..2d2811b363 100644 --- a/src/audio/alsalayer.cpp +++ b/src/audio/alsalayer.cpp @@ -194,9 +194,9 @@ void AlsaLayer::stopCaptureStream (void) if(_CaptureHandle){ err = snd_pcm_drop (_CaptureHandle); - _debug("AlsaLayer::stopCaptureStream snd_pcm_drop returned vaue : %i\n",err); + stop_capture (); - _debug("Wroking here !!!!!!!!!!!!!!!\n"); + } } diff --git a/src/audio/audiostream.cpp b/src/audio/audiostream.cpp index 778192643d..c031b4ac0d 100644 --- a/src/audio/audiostream.cpp +++ b/src/audio/audiostream.cpp @@ -66,6 +66,7 @@ AudioStream::stream_state_callback( pa_stream* s, void* user_data UNUSED ) case PA_STREAM_READY: _debug("Stream successfully created, connected to %s\n", pa_stream_get_device_name( s )); + pa_stream_cork( s, 0, NULL, NULL); break; case PA_STREAM_UNCONNECTED: _debug("Stream unconnected\n"); diff --git a/src/audio/pulselayer.cpp b/src/audio/pulselayer.cpp index 40de7e886f..8101e5e238 100644 --- a/src/audio/pulselayer.cpp +++ b/src/audio/pulselayer.cpp @@ -140,12 +140,12 @@ void PulseLayer::createStreams( pa_context* c ) playback = new AudioStream(c, PLAYBACK_STREAM, PLAYBACK_STREAM_NAME, _manager->getSpkrVolume()); pa_stream_set_write_callback( playback->pulseStream(), audioCallback, this); - //pa_stream_set_overflow_callback( playback->pulseStream() , overflow , this); + // pa_stream_set_overflow_callback( playback->pulseStream() , overflow , this); // pa_stream_set_suspended_callback( playback->pulseStream(), stream_suspended_callback, this); record = new AudioStream(c, CAPTURE_STREAM, CAPTURE_STREAM_NAME , _manager->getMicVolume()); pa_stream_set_read_callback( record->pulseStream() , audioCallback, this); - //pa_stream_set_underflow_callback( record->pulseStream() , underflow , this); + // pa_stream_set_underflow_callback( record->pulseStream() , underflow , this); // pa_stream_set_suspended_callback(record->pulseStream(), stream_suspended_callback, this); @@ -173,6 +173,8 @@ bool PulseLayer::openDevice(int indexIn UNUSED, int indexOut UNUSED, int sampleR assert(context); connectPulseAudioServer(); + + startStream(); _debug("Connection Done!! \n"); return true; @@ -254,8 +256,6 @@ void PulseLayer::stream_suspended_callback(pa_stream *s, void *userdata UNUSED ) void PulseLayer::processData( void ) { - _debug("PulseLayer::processData() \n"); - // Handle the mic // We check if the stream is ready if( (record->pulseStream()) && (pa_stream_get_state( record->pulseStream()) == PA_STREAM_READY)) diff --git a/src/iaxvoiplink.cpp b/src/iaxvoiplink.cpp index 231e024d46..79466dc502 100644 --- a/src/iaxvoiplink.cpp +++ b/src/iaxvoiplink.cpp @@ -74,6 +74,8 @@ IAXVoIPLink::~IAXVoIPLink() audiolayer = NULL; + delete converter; + delete [] micData; micData = NULL; delete [] micDataConverted; micDataConverted = NULL; delete [] micDataEncoded; micDataEncoded = NULL; diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index c24affc647..70dd45a810 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -124,7 +124,7 @@ ManagerImpl::init() AudioLayer *audiolayer = getAudioDriver(); - if (audiolayer!=0) { + if (audiolayer != 0) { unsigned int sampleRate = audiolayer->getSampleRate(); _debugInit("Load Telephone Tone"); @@ -134,6 +134,9 @@ ManagerImpl::init() _debugInit("Loading DTMF key"); _dtmfKey = new DTMF(sampleRate); } + + if (audiolayer == 0) + audiolayer->stopStream(); } void ManagerImpl::terminate() @@ -190,6 +193,9 @@ ManagerImpl::outgoingCall(const std::string& accountid, const CallID& id, const { _debug("ManagerImpl::outgoingCall() method \n"); + stopTone(false); + playTone(); + if (!accountExists(accountid)) { _debug("! Manager Error: Outgoing Call: account doesn't exist\n"); return false; @@ -313,7 +319,7 @@ ManagerImpl::cancelCall (const CallID& id) bool ManagerImpl::onHoldCall(const CallID& id) { - _debug("*************** ON HOLD ***********************************\n"); + stopTone(true); AccountID accountid = getAccountFromCall( id ); if (accountid == AccountNULL) { @@ -336,7 +342,7 @@ ManagerImpl::onHoldCall(const CallID& id) bool ManagerImpl::offHoldCall(const CallID& id) { - _debug("*************** OFF HOLD ***********************************\n"); + stopTone(false); AccountID accountid = getAccountFromCall( id ); if (accountid == AccountNULL) { @@ -1592,6 +1598,8 @@ void ManagerImpl::setAudioManager( const int32_t& api ) { int manager; + _debug(" ManagerImpl::setAudioManager :: %i \n",api); + manager = api; if( manager == PULSEAUDIO ) { @@ -1705,8 +1713,8 @@ ManagerImpl::initAudioDriver(void) if (error == -1) { _debug("Init audio driver: %i\n", error); } - } - + } + } /** @@ -1756,6 +1764,7 @@ ManagerImpl::selectAudioDriver (void) /* Notify the error if there is one */ if( _audiodriver -> getErrorMessage() != -1 ) notifyErrClient( _audiodriver -> getErrorMessage()); + } void ManagerImpl::switchAudioManager (void) @@ -1796,6 +1805,16 @@ void ManagerImpl::switchAudioManager (void) _audiodriver->openDevice( numCardIn , numCardOut, samplerate, framesize, SFL_PCM_BOTH, alsaPlugin ); if( _audiodriver -> getErrorMessage() != -1 ) notifyErrClient( _audiodriver -> getErrorMessage()); + + _debug("Current device: %i \n", type); + _debug("has current call: %i \n", hasCurrentCall()); + + // need to stop audio streams if there is currently no call + if( (type != PULSEAUDIO) && (!hasCurrentCall())) { + _debug("There is currently a call!!\n"); + _audiodriver->stopStream(); + + } } /** -- GitLab