From ff705de069f42d0eb76cab7e0d418115a3e90d8a Mon Sep 17 00:00:00 2001 From: Alexandre Savard <alexandre.savard@savoirfairelinux.net> Date: Wed, 28 Oct 2009 09:58:25 -0400 Subject: [PATCH] [#2360] Moved MainBuffer from AudioLayer to ManagerImpl As the mainbuffer was deleted when switching audio device, the application crashed Now in ManagerImpl, we can switch audio device during a call --- sflphone-common/src/audio/audiolayer.cpp | 10 +++++----- sflphone-common/src/audio/audiolayer.h | 6 +++--- sflphone-common/src/managerimpl.cpp | 7 ++++++- sflphone-common/src/managerimpl.h | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/sflphone-common/src/audio/audiolayer.cpp b/sflphone-common/src/audio/audiolayer.cpp index 8966eb6aba..0dcace767b 100644 --- a/sflphone-common/src/audio/audiolayer.cpp +++ b/sflphone-common/src/audio/audiolayer.cpp @@ -24,7 +24,7 @@ void AudioLayer::flushMain (void) ost::MutexLock guard (_mutex); // should pass call id - _mainBuffer.flushAllBuffers(); + getMainBuffer()->flushAllBuffers(); } void AudioLayer::flushUrgent (void) @@ -36,7 +36,7 @@ void AudioLayer::flushUrgent (void) void AudioLayer::flushMic (void) { ost::MutexLock guard (_mutex); - _mainBuffer.flushDefault(); + getMainBuffer()->flushDefault(); } int AudioLayer::putUrgent (void* buffer, int toCopy) @@ -60,13 +60,13 @@ int AudioLayer::putMain (void *buffer, int toCopy, CallID call_id) int a; ost::MutexLock guard (_mutex); - a = _mainBuffer.availForPut(call_id); + a = getMainBuffer()->availForPut(call_id); if (a >= toCopy) { - return _mainBuffer.putData (buffer, toCopy, _defaultVolume, call_id); + return getMainBuffer()->putData (buffer, toCopy, _defaultVolume, call_id); } else { _debug ("Chopping sound, Ouch! RingBuffer full ?\n"); - return _mainBuffer.putData (buffer, a, _defaultVolume, call_id); + return getMainBuffer()->putData (buffer, a, _defaultVolume, call_id); } return 0; diff --git a/sflphone-common/src/audio/audiolayer.h b/sflphone-common/src/audio/audiolayer.h index b995a87af9..2e3dbee8e2 100644 --- a/sflphone-common/src/audio/audiolayer.h +++ b/sflphone-common/src/audio/audiolayer.h @@ -208,12 +208,12 @@ class AudioLayer { * * @return MainBuffer* a pointer to the MainBuffer instance */ - MainBuffer* getMainBuffer( void ) { return &_mainBuffer; } + MainBuffer* getMainBuffer( void ) { return _mainBuffer; } /** * Set the mainbuffer once the audiolayer is created */ - // void setMainBuffer( MainBuffer* mainbuffer ) { _mainBuffer = mainbuffer; } + void setMainBuffer( MainBuffer* mainbuffer ) { _mainBuffer = mainbuffer; } /** * Default volume for incoming RTP and Urgent sounds. @@ -261,7 +261,7 @@ class AudioLayer { * Audio instances must be registered into the MainBuffer and bound together via the ManagerImpl. * */ - MainBuffer _mainBuffer; + MainBuffer* _mainBuffer; /** * A pointer to the recordable instance (may be a call or a conference) diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index 51599a04d9..274bd21820 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -3072,12 +3072,15 @@ ManagerImpl::initAudioDriver (void) if (getConfigInt (PREFERENCES , CONFIG_AUDIO) == ALSA) { _audiodriver = new AlsaLayer (this); + _audiodriver->setMainBuffer(&_mainBuffer); } else if (getConfigInt (PREFERENCES , CONFIG_AUDIO) == PULSEAUDIO) { if (app_is_running ("pulseaudio") == 0) { _audiodriver = new PulseLayer (this); + _audiodriver->setMainBuffer(&_mainBuffer); } else { _audiodriver = new AlsaLayer (this); setConfig (PREFERENCES, CONFIG_AUDIO, ALSA); + _audiodriver->setMainBuffer(&_mainBuffer); } } else _debug ("Error - Audio API unknown\n"); @@ -3176,7 +3179,7 @@ void ManagerImpl::switchAudioManager (void) _debug ("Deleting current layer... \n"); - //_audiodriver->closeLayer(); + // _audiodriver->closeLayer(); delete _audiodriver; _audiodriver = NULL; @@ -3186,11 +3189,13 @@ void ManagerImpl::switchAudioManager (void) case ALSA: _debug ("Creating Pulseaudio layer...\n"); _audiodriver = new PulseLayer (this); + _audiodriver->setMainBuffer(&_mainBuffer); break; case PULSEAUDIO: _debug ("Creating ALSA layer...\n"); _audiodriver = new AlsaLayer (this); + _audiodriver->setMainBuffer(&_mainBuffer); break; default: diff --git a/sflphone-common/src/managerimpl.h b/sflphone-common/src/managerimpl.h index 19904a204c..9689044a08 100644 --- a/sflphone-common/src/managerimpl.h +++ b/sflphone-common/src/managerimpl.h @@ -43,6 +43,8 @@ #include "audio/sound/dtmf.h" // DTMF class contained by value here #include "audio/codecs/codecDescriptor.h" // CodecDescriptor class contained by value here +#include "audio/mainbuffer.h" + class AudioLayer; class GuiFramework; class TelephoneTone; @@ -1191,6 +1193,17 @@ class ManagerImpl { * Unload the account (delete them) */ void unloadAccountMap(); + + + /** + * Instance of the MainBuffer for the whole application + * + * In order to send signal to other parts of the application, one must pass through the mainbuffer. + * Audio instances must be registered into the MainBuffer and bound together via the ManagerImpl. + * + */ + MainBuffer _mainBuffer; + public: @@ -1252,6 +1265,8 @@ class ManagerImpl { // ConferenceMap _conferencemap; + + private: // Copy Constructor -- GitLab