Suspend microphone when unused (pipewire only)
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "os/os_time.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/ring_buffer.h"
|
||||
#include <magic_enum.hpp>
|
||||
#include <memory>
|
||||
#include <pipewire/pipewire.h>
|
||||
#include <spa/param/audio/format-utils.h>
|
||||
@@ -62,6 +63,7 @@ struct pipewire_device : public audio_device
|
||||
std::unique_ptr<pw_stream, deleter> microphone;
|
||||
pw_stream_events mic_events{
|
||||
.version = PW_VERSION_STREAM_EVENTS,
|
||||
.state_changed = &pipewire_device::mic_state_changed,
|
||||
.process = &pipewire_device::mic_process,
|
||||
};
|
||||
std::jthread thread;
|
||||
@@ -73,6 +75,7 @@ struct pipewire_device : public audio_device
|
||||
|
||||
static void speaker_process(void * self_v);
|
||||
static void mic_process(void * self_v);
|
||||
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;
|
||||
|
||||
@@ -168,7 +171,6 @@ struct pipewire_device : public audio_device
|
||||
NULL),
|
||||
&mic_events,
|
||||
this));
|
||||
|
||||
std::vector<uint8_t> buffer(1024);
|
||||
spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer.data(), uint32_t(buffer.size()));
|
||||
|
||||
@@ -203,6 +205,7 @@ struct pipewire_device : public audio_device
|
||||
|
||||
void pipewire_device::mic_process(void * self_v)
|
||||
{
|
||||
// std::cerr << "mic_process" << std::endl;
|
||||
auto self = (pipewire_device *)self_v;
|
||||
auto buffer = pw_stream_dequeue_buffer(self->microphone.get());
|
||||
if (not buffer)
|
||||
@@ -269,6 +272,25 @@ 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;
|
||||
switch (state)
|
||||
{
|
||||
case PW_STREAM_STATE_ERROR:
|
||||
U_LOG_W("Error on microphone stream: %s", error);
|
||||
return;
|
||||
case PW_STREAM_STATE_UNCONNECTED:
|
||||
case PW_STREAM_STATE_CONNECTING:
|
||||
case PW_STREAM_STATE_PAUSED:
|
||||
self->session.set_enabled(to_headset::tracking_control::id::microphone, false);
|
||||
return;
|
||||
case PW_STREAM_STATE_STREAMING:
|
||||
self->session.set_enabled(to_headset::tracking_control::id::microphone, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void pipewire_device::speaker_process(void * self_v)
|
||||
{
|
||||
auto self = (pipewire_device *)self_v;
|
||||
|
||||
Reference in New Issue
Block a user