Re-enable microphone on reconnect

This commit is contained in:
Sapphire
2026-02-11 18:33:11 +01:00
committed by xytovl
parent 399477edf5
commit f0e3e8d4ad
4 changed files with 20 additions and 0 deletions
+8
View File
@@ -61,6 +61,7 @@ struct pipewire_device : public audio_device
std::atomic<size_t> mic_buffer_size_bytes;
audio_data mic_current;
std::unique_ptr<pw_stream, deleter> microphone;
std::atomic<std::underlying_type_t<pw_stream_state>> mic_state{PW_STREAM_STATE_UNCONNECTED};
pw_stream_events mic_events{
.version = PW_VERSION_STREAM_EVENTS,
.state_changed = &pipewire_device::mic_state_changed,
@@ -78,6 +79,7 @@ struct pipewire_device : public audio_device
static void mic_state_changed(void * self_v, pw_stream_state old, pw_stream_state state, const char * error);
void process_mic_data(wivrn::audio_data &&) override;
void on_connect() override;
~pipewire_device()
{
@@ -342,6 +344,8 @@ void pipewire_device::mic_process(void * self_v)
void pipewire_device::mic_state_changed(void * self_v, pw_stream_state old, pw_stream_state state, const char * error)
{
auto self = (pipewire_device *)self_v;
self->mic_state = state;
U_LOG_I("Microphone state changed from %s to %s (error: %s)", magic_enum::enum_name(old).data(), magic_enum::enum_name(state).data(), error != nullptr ? error : "<unknown>");
switch (state)
{
case PW_STREAM_STATE_ERROR:
@@ -408,6 +412,10 @@ void pipewire_device::process_mic_data(wivrn::audio_data && sample)
if (mic_samples.write(std::move(sample)))
mic_buffer_size_bytes += size;
}
void pipewire_device::on_connect()
{
session.send_control(to_headset::feature_control{to_headset::feature_control::microphone, mic_state == PW_STREAM_STATE_STREAMING});
}
std::unique_ptr<audio_device> create_pipewire_handle(
const std::string & source_name,
+5
View File
@@ -404,6 +404,11 @@ struct pulse_device : public audio_device
mic_buffer.push(std::move(mic_data));
}
void on_connect() override
{
session.send_control(to_headset::feature_control{to_headset::feature_control::microphone, true});
}
pulse_device(
const std::string & source_name,
const std::string & source_description,
+1
View File
@@ -36,6 +36,7 @@ struct audio_device
virtual wivrn::to_headset::audio_stream_description description() const = 0;
virtual void process_mic_data(wivrn::audio_data &&) = 0;
virtual void on_connect() = 0;
static std::unique_ptr<audio_device> create(
const std::string & source_name,
+6
View File
@@ -146,7 +146,10 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
get_info(),
*this);
if (audio_handle)
{
send_control(audio_handle->description());
audio_handle->on_connect();
}
}
catch (const std::exception & e)
{
@@ -1128,7 +1131,10 @@ void wivrn_session::reconnect(std::stop_token stop)
comp_target->reset_encoders();
}
if (audio_handle)
{
send_control(audio_handle->description());
audio_handle->on_connect();
}
event.state.visible = true;
event.state.focused = true;