Skip to content

Commit

Permalink
PipeWire improvements
Browse files Browse the repository at this point in the history
* Use given latency
* Fix (non)blocking microphone
* Mute microphone on startuo
* Reset buffer when the microphone stops
* Delete client-info handler
* Refactor the naming conventions, styling
  • Loading branch information
viachaslavic committed Jan 14, 2025
1 parent 0bb0077 commit 5feb02f
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 146 deletions.
13 changes: 5 additions & 8 deletions audio/common/pipewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ static void core_error_cb(void *data, uint32_t id, int seq, int res, const char
RARCH_ERR("[PipeWire]: error id:%u seq:%d res:%d (%s): %s\n",
id, seq, res, spa_strerror(res), message);

/* stop and exit the thread loop */
pw_thread_loop_stop(pw->thread_loop);
}

Expand All @@ -42,11 +41,9 @@ static void core_done_cb(void *data, uint32_t id, int seq)
retro_assert(id == PW_ID_CORE);

pw->last_seq = seq;

if (pw->pending_seq == seq)
{
/* stop and exit the thread loop */
pw_thread_loop_signal(pw->thread_loop, false);
}
}

static const struct pw_core_events core_events = {
Expand All @@ -55,7 +52,7 @@ static const struct pw_core_events core_events = {
.error = core_error_cb,
};

size_t calc_frame_size(enum spa_audio_format fmt, uint32_t nchannels)
size_t pipewire_calc_frame_size(enum spa_audio_format fmt, uint32_t nchannels)
{
uint32_t sample_size = 1;
switch (fmt)
Expand Down Expand Up @@ -85,7 +82,7 @@ size_t calc_frame_size(enum spa_audio_format fmt, uint32_t nchannels)
return sample_size * nchannels;
}

void set_position(uint32_t channels, uint32_t position[SPA_AUDIO_MAX_CHANNELS])
void pipewire_set_position(uint32_t channels, uint32_t position[SPA_AUDIO_MAX_CHANNELS])
{
memcpy(position, (uint32_t[SPA_AUDIO_MAX_CHANNELS]) { SPA_AUDIO_CHANNEL_UNKNOWN, },
sizeof(uint32_t) * SPA_AUDIO_MAX_CHANNELS);
Expand Down Expand Up @@ -114,7 +111,7 @@ void set_position(uint32_t channels, uint32_t position[SPA_AUDIO_MAX_CHANNELS])
}
}

void pipewire_wait_resync(pipewire_core_t *pw)
void pipewire_core_wait_resync(pipewire_core_t *pw)
{
retro_assert(pw);
pw->pending_seq = pw_core_sync(pw->core, PW_ID_CORE, pw->pending_seq);
Expand All @@ -127,7 +124,7 @@ void pipewire_wait_resync(pipewire_core_t *pw)
}
}

bool pipewire_set_active(struct pw_thread_loop *loop, struct pw_stream *stream, bool active)
bool pipewire_stream_set_active(struct pw_thread_loop *loop, struct pw_stream *stream, bool active)
{
enum pw_stream_state st;
const char *error;
Expand Down
15 changes: 7 additions & 8 deletions audio/common/pipewire.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,26 @@ typedef struct pipewire_core
{
struct pw_thread_loop *thread_loop;
struct pw_context *ctx;

struct pw_core *core;
struct spa_hook core_listener;
int last_seq, pending_seq;

struct pw_registry *registry;
struct spa_hook registry_listener;
struct pw_client *client;
struct spa_hook client_listener;

bool nonblock;
struct string_list *devicelist;
bool nonblock;
} pipewire_core_t;

size_t calc_frame_size(enum spa_audio_format fmt, uint32_t nchannels);
size_t pipewire_calc_frame_size(enum spa_audio_format fmt, uint32_t nchannels);

void set_position(uint32_t channels, uint32_t position[SPA_AUDIO_MAX_CHANNELS]);
void pipewire_set_position(uint32_t channels, uint32_t position[SPA_AUDIO_MAX_CHANNELS]);

void pipewire_wait_resync(pipewire_core_t *pipewire);
bool pipewire_core_init(pipewire_core_t *pipewire, const char *loop_name);

bool pipewire_set_active(struct pw_thread_loop *loop, struct pw_stream *stream, bool active);
void pipewire_core_wait_resync(pipewire_core_t *pipewire);

bool pipewire_core_init(pipewire_core_t *pipewire, const char *loop_name);
bool pipewire_stream_set_active(struct pw_thread_loop *loop, struct pw_stream *stream, bool active);

#endif /* _RETROARCH_PIPEWIRE */
Loading

0 comments on commit 5feb02f

Please sign in to comment.