Run dummy loop when PulseAudio fails connection

This commit is contained in:
Javier Serrano Polo
2016-07-22 01:49:54 +02:00
parent 7a98b3e669
commit a11642df0b
2 changed files with 45 additions and 8 deletions

View File

@@ -30,6 +30,7 @@
#ifdef LMMS_HAVE_PULSEAUDIO
#include <pulse/pulseaudio.h>
#include <QSemaphore>
#include <QThread>
#include "AudioDevice.h"
@@ -71,6 +72,8 @@ public:
void streamWriteCallback( pa_stream * s, size_t length );
void signalConnected( bool connected );
pa_stream * m_s;
pa_sample_spec m_sampleSpec;
@@ -85,6 +88,9 @@ private:
bool m_convertEndian;
bool m_connected;
QSemaphore m_connectedSemaphore;
} ;
#endif

View File

@@ -187,6 +187,7 @@ static void context_state_callback(pa_context *c, void *userdata)
PA_STREAM_ADJUST_LATENCY,
NULL, // volume
NULL );
_this->signalConnected( true );
break;
}
@@ -196,6 +197,7 @@ static void context_state_callback(pa_context *c, void *userdata)
case PA_CONTEXT_FAILED:
default:
qCritical( "Connection failure: %s\n", pa_strerror( pa_context_errno( c ) ) );
_this->signalConnected( false );
}
}
@@ -219,19 +221,36 @@ void AudioPulseAudio::run()
return;
}
m_connected = false;
pa_context_set_state_callback( context, context_state_callback, this );
// connect the context
pa_context_connect( context, NULL, (pa_context_flags) 0, NULL );
// run the main loop
int ret = 0;
m_quit = false;
while( m_quit == false && pa_mainloop_iterate( mainLoop, 1, &ret ) >= 0 )
{
}
m_connectedSemaphore.acquire();
pa_stream_disconnect( m_s );
pa_stream_unref( m_s );
// run the main loop
if( m_connected )
{
int ret = 0;
m_quit = false;
while( m_quit == false
&& pa_mainloop_iterate( mainLoop, 1, &ret ) >= 0 )
{
}
pa_stream_disconnect( m_s );
pa_stream_unref( m_s );
}
else
{
const fpp_t fpp = mixer()->framesPerPeriod();
surroundSampleFrame * temp = new surroundSampleFrame[fpp];
while( getNextBuffer( temp ) )
{
}
delete[] temp;
}
pa_context_disconnect( context );
pa_context_unref( context );
@@ -276,6 +295,18 @@ void AudioPulseAudio::streamWriteCallback( pa_stream *s, size_t length )
void AudioPulseAudio::signalConnected( bool connected )
{
if( !m_connected )
{
m_connected = connected;
m_connectedSemaphore.release();
}
}
AudioPulseAudio::setupWidget::setupWidget( QWidget * _parent ) :
AudioDeviceSetupWidget( AudioPulseAudio::name(), _parent )
{