Fix pipewire destruction
This commit is contained in:
@@ -35,7 +35,6 @@ struct deleter
|
|||||||
{
|
{
|
||||||
void operator()(pw_main_loop * loop)
|
void operator()(pw_main_loop * loop)
|
||||||
{
|
{
|
||||||
pw_main_loop_quit(loop);
|
|
||||||
pw_main_loop_destroy(loop);
|
pw_main_loop_destroy(loop);
|
||||||
}
|
}
|
||||||
void operator()(pw_stream * stream)
|
void operator()(pw_stream * stream)
|
||||||
@@ -49,6 +48,8 @@ struct pipewire_device : public audio_device
|
|||||||
to_headset::audio_stream_description desc;
|
to_headset::audio_stream_description desc;
|
||||||
wivrn_session & session;
|
wivrn_session & session;
|
||||||
|
|
||||||
|
std::unique_ptr<pw_main_loop, deleter> pw_loop;
|
||||||
|
|
||||||
std::unique_ptr<pw_stream, deleter> speaker;
|
std::unique_ptr<pw_stream, deleter> speaker;
|
||||||
pw_stream_events speaker_events{
|
pw_stream_events speaker_events{
|
||||||
.version = PW_VERSION_STREAM_EVENTS,
|
.version = PW_VERSION_STREAM_EVENTS,
|
||||||
@@ -63,10 +64,7 @@ struct pipewire_device : public audio_device
|
|||||||
.version = PW_VERSION_STREAM_EVENTS,
|
.version = PW_VERSION_STREAM_EVENTS,
|
||||||
.process = &pipewire_device::mic_process,
|
.process = &pipewire_device::mic_process,
|
||||||
};
|
};
|
||||||
|
std::jthread thread;
|
||||||
std::unique_ptr<pw_main_loop, deleter> pw_loop;
|
|
||||||
|
|
||||||
std::thread thread;
|
|
||||||
|
|
||||||
to_headset::audio_stream_description description() const override
|
to_headset::audio_stream_description description() const override
|
||||||
{
|
{
|
||||||
@@ -78,7 +76,10 @@ struct pipewire_device : public audio_device
|
|||||||
|
|
||||||
void process_mic_data(wivrn::audio_data &&) override;
|
void process_mic_data(wivrn::audio_data &&) override;
|
||||||
|
|
||||||
~pipewire_device() = default;
|
~pipewire_device()
|
||||||
|
{
|
||||||
|
pw_main_loop_quit(pw_loop.get());
|
||||||
|
};
|
||||||
|
|
||||||
pipewire_device(
|
pipewire_device(
|
||||||
const std::string & source_name,
|
const std::string & source_name,
|
||||||
@@ -188,8 +189,12 @@ struct pipewire_device : public audio_device
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (desc.speaker or desc.microphone)
|
if (desc.speaker or desc.microphone)
|
||||||
thread = std::thread(
|
thread = std::jthread(
|
||||||
[loop = pw_loop.get()]() { pw_main_loop_run(loop); });
|
[this](std::stop_token) {
|
||||||
|
pw_main_loop_run(pw_loop.get());
|
||||||
|
speaker.reset();
|
||||||
|
microphone.reset();
|
||||||
|
; });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user