Skip to content

Commit

Permalink
Preserve compatibility with ABI v1 output plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin authored and flyingmutant committed Dec 24, 2021
1 parent 4f46f27 commit 5ecc3ad
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
5 changes: 4 additions & 1 deletion mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ struct mixer_plugin_ops {
int (*exit)(void);
int (*open)(int *volume_max);
int (*close)(void);
int (*get_fds)(int what, int *fds);
union {
int (*abi_1)(int *fds); // MIXER_FDS_VOLUME
int (*abi_2)(int what, int *fds);
} get_fds;
int (*set_volume)(int l, int r);
int (*get_volume)(int *l, int *r);
};
Expand Down
14 changes: 7 additions & 7 deletions op/coreaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,13 +957,13 @@ const struct output_plugin_ops op_pcm_ops = {


const struct mixer_plugin_ops op_mixer_ops = {
.init = coreaudio_mixer_dummy,
.exit = coreaudio_mixer_dummy,
.open = coreaudio_mixer_open,
.close = coreaudio_mixer_close,
.get_fds = coreaudio_mixer_get_fds,
.set_volume = coreaudio_mixer_set_volume,
.get_volume = coreaudio_mixer_get_volume,
.init = coreaudio_mixer_dummy,
.exit = coreaudio_mixer_dummy,
.open = coreaudio_mixer_open,
.close = coreaudio_mixer_close,
.get_fds.abi_2 = coreaudio_mixer_get_fds,
.set_volume = coreaudio_mixer_set_volume,
.get_volume = coreaudio_mixer_get_volume,
};

const struct output_plugin_opt op_pcm_options[] = {
Expand Down
2 changes: 1 addition & 1 deletion op/mixer_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const struct mixer_plugin_ops op_mixer_ops = {
.exit = alsa_mixer_exit,
.open = alsa_mixer_open,
.close = alsa_mixer_close,
.get_fds = alsa_mixer_get_fds,
.get_fds.abi_2 = alsa_mixer_get_fds,
.set_volume = alsa_mixer_set_volume,
.get_volume = alsa_mixer_get_volume,
};
Expand Down
2 changes: 1 addition & 1 deletion op/pulse.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ const struct mixer_plugin_ops op_mixer_ops = {
.exit = op_pulse_mixer_exit,
.open = op_pulse_mixer_open,
.close = op_pulse_mixer_close,
.get_fds = op_pulse_mixer_get_fds,
.get_fds.abi_2 = op_pulse_mixer_get_fds,
.set_volume = op_pulse_mixer_set_volume,
.get_volume = op_pulse_mixer_get_volume,
};
Expand Down
22 changes: 16 additions & 6 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct output_plugin {
char *name;
void *handle;

const unsigned *abi_version_ptr;
const struct output_plugin_ops *pcm_ops;
const struct mixer_plugin_ops *mixer_ops;
const struct output_plugin_opt *pcm_options;
Expand Down Expand Up @@ -95,7 +96,6 @@ void op_load_plugins(void)
struct output_plugin *plug;
void *so, *symptr;
char *ext;
const unsigned *abi_version_ptr;
bool err = false;

if (d->d_name[0] == '.')
Expand All @@ -119,12 +119,13 @@ void op_load_plugins(void)
plug->pcm_ops = dlsym(so, "op_pcm_ops");
plug->pcm_options = dlsym(so, "op_pcm_options");
symptr = dlsym(so, "op_priority");
abi_version_ptr = dlsym(so, "op_abi_version");
plug->abi_version_ptr = dlsym(so, "op_abi_version");
if (!plug->pcm_ops || !plug->pcm_options || !symptr) {
error_msg("%s: missing symbol", filename);
err = true;
}
if (!abi_version_ptr || *abi_version_ptr != OP_ABI_VERSION) {
STATIC_ASSERT(OP_ABI_VERSION == 2);
if (!plug->abi_version_ptr || (*plug->abi_version_ptr != 1 && *plug->abi_version_ptr != 2)) {
error_msg("%s: incompatible plugin version", filename);
err = true;
}
Expand Down Expand Up @@ -322,9 +323,18 @@ int mixer_get_fds(int what, int *fds)
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(what, fds);
switch (*op->abi_version_ptr) {
case 1:
if (!op->mixer_ops->get_fds.abi_1)
return -OP_ERROR_NOT_SUPPORTED;
if (what != MIXER_FDS_VOLUME)
return 0;
return op->mixer_ops->get_fds.abi_1(fds);
default:
if (!op->mixer_ops->get_fds.abi_2)
return -OP_ERROR_NOT_SUPPORTED;
return op->mixer_ops->get_fds.abi_2(what, fds);
}
}

extern int soft_vol;
Expand Down

0 comments on commit 5ecc3ad

Please sign in to comment.