From 4f46f27547d9d8749161f5c9a80108da2522aeb7 Mon Sep 17 00:00:00 2001 From: Patrick Gaskin Date: Thu, 9 Dec 2021 22:52:05 -0500 Subject: [PATCH] Allow output plugins to have multiple mixer FD lists --- mixer.h | 7 ++++++- op.h | 2 +- op/coreaudio.c | 13 +++++++++---- op/mixer_alsa.c | 15 ++++++++++----- op/pulse.c | 11 ++++++++--- output.c | 4 ++-- output.h | 2 +- ui_curses.c | 18 +++++++++--------- 8 files changed, 46 insertions(+), 26 deletions(-) diff --git a/mixer.h b/mixer.h index 20f722980..ed61dba52 100644 --- a/mixer.h +++ b/mixer.h @@ -25,12 +25,17 @@ #define NR_MIXER_FDS 4 +enum { + /* volume changes */ + MIXER_FDS_VOLUME +}; + struct mixer_plugin_ops { int (*init)(void); int (*exit)(void); int (*open)(int *volume_max); int (*close)(void); - int (*get_fds)(int *fds); + int (*get_fds)(int what, int *fds); int (*set_volume)(int l, int r); int (*get_volume)(int *l, int *r); }; diff --git a/op.h b/op.h index b79bae85f..2f645d39b 100644 --- a/op.h +++ b/op.h @@ -26,7 +26,7 @@ #include #endif -#define OP_ABI_VERSION 1 +#define OP_ABI_VERSION 2 enum { /* no error */ diff --git a/op/coreaudio.c b/op/coreaudio.c index b6b286e6a..adc114f43 100644 --- a/op/coreaudio.c +++ b/op/coreaudio.c @@ -864,10 +864,15 @@ static int coreaudio_mixer_dummy(void) return OP_ERROR_SUCCESS; } -static int coreaudio_mixer_get_fds(int *fds) -{ - fds[0] = coreaudio_mixer_pipe_out; - return 1; +static int coreaudio_mixer_get_fds(int what, int *fds) +{ + switch (what) { + case MIXER_FDS_VOLUME: + fds[0] = coreaudio_mixer_pipe_out; + return 1; + default: + return 0; + } } static int coreaudio_pause(void) diff --git a/op/mixer_alsa.c b/op/mixer_alsa.c index ed5d3e302..fc90fc01e 100644 --- a/op/mixer_alsa.c +++ b/op/mixer_alsa.c @@ -137,15 +137,20 @@ static int alsa_mixer_close(void) return 0; } -static int alsa_mixer_get_fds(int *fds) +static int alsa_mixer_get_fds(int what, int *fds) { struct pollfd pfd[NR_MIXER_FDS]; int count, i; - count = snd_mixer_poll_descriptors(alsa_mixer_handle, pfd, NR_MIXER_FDS); - for (i = 0; i < count; i++) - fds[i] = pfd[i].fd; - return count; + switch (what) { + case MIXER_FDS_VOLUME: + count = snd_mixer_poll_descriptors(alsa_mixer_handle, pfd, NR_MIXER_FDS); + for (i = 0; i < count; i++) + fds[i] = pfd[i].fd; + return count; + default: + return 0; + } } static int alsa_mixer_set_volume(int l, int r) diff --git a/op/pulse.c b/op/pulse.c index a7b3f641e..4610e67c8 100644 --- a/op/pulse.c +++ b/op/pulse.c @@ -524,10 +524,15 @@ static int op_pulse_mixer_close(void) return OP_ERROR_SUCCESS; } -static int op_pulse_mixer_get_fds(int *fds) +static int op_pulse_mixer_get_fds(int what, int *fds) { - fds[0] = mixer_notify_out; - return 1; + switch (what) { + case MIXER_FDS_VOLUME: + fds[0] = mixer_notify_out; + return 1; + default: + return 0; + } } static int op_pulse_mixer_set_volume(int l, int r) diff --git a/output.c b/output.c index a080dc2ac..81c6d2649 100644 --- a/output.c +++ b/output.c @@ -316,7 +316,7 @@ int mixer_read_volume(void) return op->mixer_ops->get_volume(&volume_l, &volume_r); } -int mixer_get_fds(int *fds) +int mixer_get_fds(int what, int *fds) { if (op == NULL) return -OP_ERROR_NOT_INITIALIZED; @@ -324,7 +324,7 @@ int mixer_get_fds(int *fds) return -OP_ERROR_NOT_OPEN; if (!op->mixer_ops->get_fds) return -OP_ERROR_NOT_SUPPORTED; - return op->mixer_ops->get_fds(fds); + return op->mixer_ops->get_fds(what, fds); } extern int soft_vol; diff --git a/output.h b/output.h index 6cf26a388..369230a66 100644 --- a/output.h +++ b/output.h @@ -85,7 +85,7 @@ void mixer_open(void); void mixer_close(void); int mixer_set_volume(int left, int right); int mixer_read_volume(void); -int mixer_get_fds(int *fds); +int mixer_get_fds(int what, int *fds); void op_add_options(void); char *op_get_error_msg(int rc, const char *arg); diff --git a/ui_curses.c b/ui_curses.c index 5371b4022..d3cb5ae0f 100644 --- a/ui_curses.c +++ b/ui_curses.c @@ -2138,8 +2138,8 @@ static void main_loop(void) fd_set set; struct timeval tv; int poll_mixer = 0; - int i, nr_fds = 0; - int fds[NR_MIXER_FDS]; + int i; + int nr_fds_vol = 0, fds_vol[NR_MIXER_FDS]; struct list_head *item; struct client *client; @@ -2174,15 +2174,15 @@ static void main_loop(void) SELECT_ADD_FD(client->fd); } if (!soft_vol) { - nr_fds = mixer_get_fds(fds); - if (nr_fds <= 0) { + nr_fds_vol = mixer_get_fds(MIXER_FDS_VOLUME, fds_vol); + if (nr_fds_vol <= 0) { poll_mixer = 1; if (!tv.tv_usec) tv.tv_usec = 500e3; } - for (i = 0; i < nr_fds; i++) { - BUG_ON(fds[i] <= 0); - SELECT_ADD_FD(fds[i]); + for (i = 0; i < nr_fds_vol; i++) { + BUG_ON(fds_vol[i] <= 0); + SELECT_ADD_FD(fds_vol[i]); } } @@ -2207,8 +2207,8 @@ static void main_loop(void) continue; } - for (i = 0; i < nr_fds; i++) { - if (FD_ISSET(fds[i], &set)) { + for (i = 0; i < nr_fds_vol; i++) { + if (FD_ISSET(fds_vol[i], &set)) { d_print("vol changed\n"); mixer_read_volume(); mpris_volume_changed();