Re-enable microphone on reconnect
This commit is contained in:
@@ -61,6 +61,7 @@ struct pipewire_device : public audio_device
|
|||||||
std::atomic<size_t> mic_buffer_size_bytes;
|
std::atomic<size_t> mic_buffer_size_bytes;
|
||||||
audio_data mic_current;
|
audio_data mic_current;
|
||||||
std::unique_ptr<pw_stream, deleter> microphone;
|
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{
|
pw_stream_events mic_events{
|
||||||
.version = PW_VERSION_STREAM_EVENTS,
|
.version = PW_VERSION_STREAM_EVENTS,
|
||||||
.state_changed = &pipewire_device::mic_state_changed,
|
.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);
|
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 process_mic_data(wivrn::audio_data &&) override;
|
||||||
|
void on_connect() override;
|
||||||
|
|
||||||
~pipewire_device()
|
~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)
|
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;
|
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)
|
switch (state)
|
||||||
{
|
{
|
||||||
case PW_STREAM_STATE_ERROR:
|
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)))
|
if (mic_samples.write(std::move(sample)))
|
||||||
mic_buffer_size_bytes += size;
|
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(
|
std::unique_ptr<audio_device> create_pipewire_handle(
|
||||||
const std::string & source_name,
|
const std::string & source_name,
|
||||||
|
|||||||
@@ -404,6 +404,11 @@ struct pulse_device : public audio_device
|
|||||||
mic_buffer.push(std::move(mic_data));
|
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(
|
pulse_device(
|
||||||
const std::string & source_name,
|
const std::string & source_name,
|
||||||
const std::string & source_description,
|
const std::string & source_description,
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ struct audio_device
|
|||||||
virtual wivrn::to_headset::audio_stream_description description() const = 0;
|
virtual wivrn::to_headset::audio_stream_description description() const = 0;
|
||||||
|
|
||||||
virtual void process_mic_data(wivrn::audio_data &&) = 0;
|
virtual void process_mic_data(wivrn::audio_data &&) = 0;
|
||||||
|
virtual void on_connect() = 0;
|
||||||
|
|
||||||
static std::unique_ptr<audio_device> create(
|
static std::unique_ptr<audio_device> create(
|
||||||
const std::string & source_name,
|
const std::string & source_name,
|
||||||
|
|||||||
@@ -146,7 +146,10 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
|
|||||||
get_info(),
|
get_info(),
|
||||||
*this);
|
*this);
|
||||||
if (audio_handle)
|
if (audio_handle)
|
||||||
|
{
|
||||||
send_control(audio_handle->description());
|
send_control(audio_handle->description());
|
||||||
|
audio_handle->on_connect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception & e)
|
catch (const std::exception & e)
|
||||||
{
|
{
|
||||||
@@ -1128,7 +1131,10 @@ void wivrn_session::reconnect(std::stop_token stop)
|
|||||||
comp_target->reset_encoders();
|
comp_target->reset_encoders();
|
||||||
}
|
}
|
||||||
if (audio_handle)
|
if (audio_handle)
|
||||||
|
{
|
||||||
send_control(audio_handle->description());
|
send_control(audio_handle->description());
|
||||||
|
audio_handle->on_connect();
|
||||||
|
}
|
||||||
|
|
||||||
event.state.visible = true;
|
event.state.visible = true;
|
||||||
event.state.focused = true;
|
event.state.focused = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user