mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-06 21:01:42 +02:00
Check some more PulseAudio init errors
This commit is contained in:
parent
4b7c313fa0
commit
21665d163e
1 changed files with 10 additions and 2 deletions
|
@ -239,7 +239,8 @@ void PulsePlayer::start()
|
||||||
pa_ml_ = pa_mainloop_new();
|
pa_ml_ = pa_mainloop_new();
|
||||||
pa_mainloop_api* pa_mlapi = pa_mainloop_get_api(pa_ml_);
|
pa_mainloop_api* pa_mlapi = pa_mainloop_get_api(pa_ml_);
|
||||||
pa_ctx_ = pa_context_new(pa_mlapi, "Snapcast");
|
pa_ctx_ = pa_context_new(pa_mlapi, "Snapcast");
|
||||||
pa_context_connect(pa_ctx_, nullptr, PA_CONTEXT_NOFLAGS, nullptr);
|
if (pa_context_connect(pa_ctx_, nullptr, PA_CONTEXT_NOFLAGS, nullptr) < 0)
|
||||||
|
throw SnapException("Failed to connect to PulseAudio context: " + std::string(pa_strerror(pa_context_errno(pa_ctx_))));
|
||||||
|
|
||||||
// This function defines a callback so the server will tell us it's state.
|
// This function defines a callback so the server will tell us it's state.
|
||||||
// Our callback will wait for the state to be ready. The callback will
|
// Our callback will wait for the state to be ready. The callback will
|
||||||
|
@ -255,8 +256,15 @@ void PulsePlayer::start()
|
||||||
|
|
||||||
// We can't do anything until PA is ready, so just iterate the mainloop
|
// We can't do anything until PA is ready, so just iterate the mainloop
|
||||||
// and continue
|
// and continue
|
||||||
|
auto wait_start = std::chrono::steady_clock::now();
|
||||||
while (pa_ready_ == 0)
|
while (pa_ready_ == 0)
|
||||||
pa_mainloop_iterate(pa_ml_, 1, nullptr);
|
{
|
||||||
|
auto now = std::chrono::steady_clock::now();
|
||||||
|
if (now - wait_start > 5s)
|
||||||
|
throw SnapException("Timeout while waiting for PulseAudio to become ready");
|
||||||
|
if (pa_mainloop_iterate(pa_ml_, 1, nullptr) < 0)
|
||||||
|
throw SnapException("Error while waiting for PulseAudio to become ready: " + std::string(pa_strerror(pa_context_errno(pa_ctx_))));
|
||||||
|
}
|
||||||
|
|
||||||
if (pa_ready_ == 2)
|
if (pa_ready_ == 2)
|
||||||
throw SnapException("PulseAudio is not ready");
|
throw SnapException("PulseAudio is not ready");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue