Audaspace: Wait for the PulseAudio stream to be ready when initializing
Otherwise, the stream might be in an invalid state when we are trying to start playback. Pull Request: https://projects.blender.org/blender/blender/pulls/136845
This commit is contained in:
@@ -77,6 +77,7 @@ void PulseAudioDevice::PulseAudio_request(pa_stream* stream, size_t total_bytes,
|
||||
|
||||
total_bytes -= num_bytes;
|
||||
}
|
||||
AUD_pa_threaded_mainloop_signal(device->m_mainloop, 0);
|
||||
}
|
||||
|
||||
void PulseAudioDevice::playing(bool playing)
|
||||
@@ -218,6 +219,30 @@ PulseAudioDevice::PulseAudioDevice(const std::string& name, DeviceSpecs specs, i
|
||||
AUD_THROW(DeviceException, "Could not connect PulseAudio stream.");
|
||||
}
|
||||
|
||||
/* Make sure that the stream is ready to be used before we proceed. */
|
||||
int stream_state;
|
||||
while((stream_state = AUD_pa_stream_get_state(m_stream)) != PA_STREAM_READY)
|
||||
{
|
||||
switch(stream_state)
|
||||
{
|
||||
case PA_STREAM_FAILED:
|
||||
case PA_STREAM_TERMINATED:
|
||||
AUD_pa_threaded_mainloop_unlock(m_mainloop);
|
||||
AUD_pa_threaded_mainloop_stop(m_mainloop);
|
||||
|
||||
AUD_pa_context_disconnect(m_context);
|
||||
AUD_pa_context_unref(m_context);
|
||||
|
||||
AUD_pa_threaded_mainloop_free(m_mainloop);
|
||||
|
||||
AUD_THROW(DeviceException, "Could not connect to PulseAudio.");
|
||||
break;
|
||||
default:
|
||||
AUD_pa_threaded_mainloop_wait(m_mainloop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
AUD_pa_threaded_mainloop_unlock(m_mainloop);
|
||||
|
||||
create();
|
||||
|
||||
@@ -25,6 +25,7 @@ PULSEAUDIO_SYMBOL(pa_stream_begin_write);
|
||||
PULSEAUDIO_SYMBOL(pa_stream_connect_playback);
|
||||
PULSEAUDIO_SYMBOL(pa_stream_cork);
|
||||
PULSEAUDIO_SYMBOL(pa_stream_flush);
|
||||
PULSEAUDIO_SYMBOL(pa_stream_get_state);
|
||||
PULSEAUDIO_SYMBOL(pa_stream_get_time);
|
||||
PULSEAUDIO_SYMBOL(pa_stream_is_corked);
|
||||
PULSEAUDIO_SYMBOL(pa_stream_new);
|
||||
|
||||
Reference in New Issue
Block a user