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:
Sebastian Parborg
2025-05-07 14:05:56 +02:00
committed by Gitea
parent b6a86a8fc9
commit 552a395952
2 changed files with 26 additions and 0 deletions

View File

@@ -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();

View File

@@ -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);