Skip to content

Commit

Permalink
Allow output plugins to have multiple mixer FD lists
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin authored and flyingmutant committed Dec 24, 2021
1 parent 47b02f8 commit 4f46f27
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 26 deletions.
7 changes: 6 additions & 1 deletion mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
2 changes: 1 addition & 1 deletion op.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <fcntl.h>
#endif

#define OP_ABI_VERSION 1
#define OP_ABI_VERSION 2

enum {
/* no error */
Expand Down
13 changes: 9 additions & 4 deletions op/coreaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions op/mixer_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions op/pulse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,15 @@ 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;
if (!op->mixer_open)
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;
Expand Down
2 changes: 1 addition & 1 deletion output.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions ui_curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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]);
}
}

Expand All @@ -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();
Expand Down

0 comments on commit 4f46f27

Please sign in to comment.