Commit 1d7d0580 authored by Emmanuel Milou's avatar Emmanuel Milou

fix ticket #113 - handle cases when pulseaudio is not running

parent d2f9c009
......@@ -6,5 +6,4 @@ libtoolize --force
autoheader
autoconf -f
automake -a
echo "\nDone! Now you can ./configure. \n"
./configure $@
......@@ -6,6 +6,6 @@ libtoolize --force
autoheader
autoconf -f
automake -a
./configure $@
echo "\nDone! Now you can ./configure."
......@@ -30,6 +30,9 @@ sflphone_throw_exception( int err )
case ALSA_CAPTURE_DEVICE:
markup = g_markup_printf_escaped(_("<b>ALSA notification</b>\n\nError while opening capture device"));
break;
case PULSEAUDIO_NOT_RUNNING:
markup = g_markup_printf_escaped(_("<b>Pulseaudio notification</b>\n\nPulseaudio is not running"));
break;
}
main_window_error_message( markup );
free( markup );
......
......@@ -66,6 +66,10 @@
#define ALSA_CAPTURE_DEVICE 0x0001
/** Error while opening playback device */
#define ALSA_PLAYBACK_DEVICE 0x0010
/** Error pulseaudio */
#define PULSEAUDIO_NOT_RUNNING 0x0100
/** Tone to play when no voice mails */
#define TONE_WITHOUT_MESSAGE 0
......
......@@ -126,6 +126,7 @@ typedef short int16;
#define ALSA_CAPTURE_DEVICE 0x0001 /** Error while opening capture device */
#define ALSA_PLAYBACK_DEVICE 0x0010 /** Error while opening playback device */
#define NETWORK_UNREACHABLE 0x0011 /** Network unreachable */
#define PULSEAUDIO_NOT_RUNNING 0x0100 /** Pulseaudio is not running */
#define ALSA 0
#define PULSEAUDIO 1
......
......@@ -1522,11 +1522,27 @@ ManagerImpl::setPulseAppVolumeControl( void )
(getConfigInt( PREFERENCES , CONFIG_PA_VOLUME_CTRL ) == 1)? setConfig( PREFERENCES , CONFIG_PA_VOLUME_CTRL , NO_STR) : setConfig( PREFERENCES , CONFIG_PA_VOLUME_CTRL , YES_STR) ;
}
void
ManagerImpl::setAudioManager( const int32_t& api )
void ManagerImpl::setAudioManager( const int32_t& api )
{
setConfig( PREFERENCES , CONFIG_AUDIO , api) ;
switchAudioManager();
int manager;
manager = api;
if( manager == PULSEAUDIO )
{
if(app_is_running("pulseaudio") != 0)
{
// The pulseaudio daemon is not running
manager = ALSA;
notifyErrClient(PULSEAUDIO_NOT_RUNNING);
}
}
if(manager == api)
{
// it means that we can change the audio manager
setConfig( PREFERENCES , CONFIG_AUDIO , api) ;
switchAudioManager();
}
}
int32_t
......@@ -1571,6 +1587,14 @@ ManagerImpl::getCurrentAudioOutputPlugin( void )
return _audiodriver -> getAudioPlugin();
}
int ManagerImpl::app_is_running( std::string process )
{
std::ostringstream cmd;
cmd << "ps -C " << process;
return system(cmd.str().c_str());
}
/**
* Initialization: Main Thread
......@@ -1583,12 +1607,23 @@ ManagerImpl::initAudioDriver(void)
_debugInit("AudioLayer Creation");
if( getConfigInt( PREFERENCES , CONFIG_AUDIO ) == ALSA )
_audiodriver = new AlsaLayer( this );
else if( getConfigInt( PREFERENCES , CONFIG_AUDIO ) == PULSEAUDIO )
_audiodriver = new PulseLayer( this );
else
_debug("Error - Audio API unknown\n");
if( getConfigInt( PREFERENCES , CONFIG_AUDIO ) == ALSA )
{
_audiodriver = new AlsaLayer( this );
}
else if( getConfigInt( PREFERENCES , CONFIG_AUDIO ) == PULSEAUDIO )
{
if( app_is_running("pulseaudio") == 0 )
{
_audiodriver = new PulseLayer( this );
} else
{
_audiodriver = new AlsaLayer( this );
setConfig( PREFERENCES, CONFIG_AUDIO, ALSA);
}
}
else
_debug("Error - Audio API unknown\n");
if (_audiodriver == 0) {
_debug("Init audio driver error\n");
......@@ -1632,6 +1667,7 @@ ManagerImpl::selectAudioDriver (void)
setConfig( AUDIO , ALSA_CARD_ID_OUT , ALSA_DFT_CARD_ID );
}
if(CHECK_INTERFACE( layer , ALSA ))
{
delete _audiodriver;
......
......@@ -829,6 +829,14 @@ class ManagerImpl {
private:
/**
* Check if a process is running with the system command
*
* @return 0 on success
* 1 otherelse
*/
int app_is_running(std::string process);
/**
* Create .PROGNAME directory in home user and create
* configuration tree from the settings file if this file exists.
......
Markdown is supported
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