Commit 78257408 authored by Max Kellermann's avatar Max Kellermann

output/pipewire: report errors from the "state_changed" callback

parent f447b761
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
#include <boost/lockfree/spsc_queue.hpp> #include <boost/lockfree/spsc_queue.hpp>
#include <stdexcept> #include <stdexcept>
#include <string>
static constexpr Domain pipewire_output_domain("pipewire_output"); static constexpr Domain pipewire_output_domain("pipewire_output");
...@@ -65,6 +66,8 @@ class PipeWireOutput final : AudioOutput { ...@@ -65,6 +66,8 @@ class PipeWireOutput final : AudioOutput {
struct pw_thread_loop *thread_loop = nullptr; struct pw_thread_loop *thread_loop = nullptr;
struct pw_stream *stream; struct pw_stream *stream;
std::string error_message;
std::byte buffer[1024]; std::byte buffer[1024];
struct spa_pod_builder pod_builder; struct spa_pod_builder pod_builder;
...@@ -149,8 +152,12 @@ public: ...@@ -149,8 +152,12 @@ public:
private: private:
void CheckThrowError() { void CheckThrowError() {
if (disconnected) if (disconnected) {
throw std::runtime_error("Disconnected from PipeWire"); if (error_message.empty())
throw std::runtime_error("Disconnected from PipeWire");
else
throw std::runtime_error(error_message);
}
} }
void StateChanged(enum pw_stream_state state, void StateChanged(enum pw_stream_state state,
...@@ -426,6 +433,7 @@ ToPipeWireAudioFormat(AudioFormat &audio_format) noexcept ...@@ -426,6 +433,7 @@ ToPipeWireAudioFormat(AudioFormat &audio_format) noexcept
void void
PipeWireOutput::Open(AudioFormat &audio_format) PipeWireOutput::Open(AudioFormat &audio_format)
{ {
error_message.clear();
disconnected = false; disconnected = false;
restore_volume = true; restore_volume = true;
...@@ -521,8 +529,12 @@ PipeWireOutput::StateChanged(enum pw_stream_state state, ...@@ -521,8 +529,12 @@ PipeWireOutput::StateChanged(enum pw_stream_state state,
const bool was_disconnected = disconnected; const bool was_disconnected = disconnected;
disconnected = state == PW_STREAM_STATE_ERROR || disconnected = state == PW_STREAM_STATE_ERROR ||
state == PW_STREAM_STATE_UNCONNECTED; state == PW_STREAM_STATE_UNCONNECTED;
if (!was_disconnected && disconnected) if (!was_disconnected && disconnected) {
if (error != nullptr)
error_message = error;
pw_thread_loop_signal(thread_loop, false); pw_thread_loop_signal(thread_loop, false);
}
} }
......
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