diff options
author | Wim Taymans <wtaymans@redhat.com> | 2020-05-28 18:38:59 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2020-07-03 17:33:07 +0200 |
commit | bae717b12284dd2776d9b090c3279f78e5fe3ed8 (patch) | |
tree | c26b917ae51882b6c6a78e584ec9f03c8c87d7e8 | |
parent | 2bce0d3ca5f3592b20543f56a5c8f1970c281ae0 (diff) |
wip: cleanups
-rw-r--r-- | spa/plugins/pulse/acp.h | 6 | ||||
-rw-r--r-- | spa/plugins/pulse/alsa-mixer.c | 12 | ||||
-rw-r--r-- | spa/plugins/pulse/alsa-mixer.h | 3 | ||||
-rw-r--r-- | spa/plugins/pulse/test-probe.c | 118 |
4 files changed, 74 insertions, 65 deletions
diff --git a/spa/plugins/pulse/acp.h b/spa/plugins/pulse/acp.h index 6e2febe8..98698eda 100644 --- a/spa/plugins/pulse/acp.h +++ b/spa/plugins/pulse/acp.h @@ -117,10 +117,7 @@ struct acp_port { struct acp_dict props; uint32_t n_profiles; - uint32_t preferred_profile_index; struct acp_card_profile **profiles; - - int64_t latency_offset; }; struct acp_device { @@ -153,9 +150,6 @@ struct acp_card_profile { uint32_t priority; enum acp_available available; - char *input_name; - char *output_name; - uint32_t n_devices; struct acp_device **devices; }; diff --git a/spa/plugins/pulse/alsa-mixer.c b/spa/plugins/pulse/alsa-mixer.c index 6b909847..f21ec39f 100644 --- a/spa/plugins/pulse/alsa-mixer.c +++ b/spa/plugins/pulse/alsa-mixer.c @@ -3338,8 +3338,8 @@ static void profile_free(pa_alsa_profile *p) { pa_xfree(p->profile.name); pa_xfree(p->profile.description); - pa_xfree(p->profile.input_name); - pa_xfree(p->profile.output_name); + pa_xfree(p->input_name); + pa_xfree(p->output_name); pa_xstrfreev(p->input_mapping_names); pa_xstrfreev(p->output_mapping_names); @@ -4019,7 +4019,7 @@ static void profile_set_add_auto_pair( p->profile.name = name; if (m) { - p->profile.output_name = pa_xstrdup(m->name); + p->output_name = pa_xstrdup(m->name); p->output_mappings = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); pa_idxset_put(p->output_mappings, m, NULL); p->profile.priority += m->priority * 100; @@ -4027,7 +4027,7 @@ static void profile_set_add_auto_pair( } if (n) { - p->profile.input_name = pa_xstrdup(n->name); + p->input_name = pa_xstrdup(n->name); p->input_mappings = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); pa_idxset_put(p->input_mappings, n, NULL); p->profile.priority += n->priority; @@ -4196,8 +4196,8 @@ void pa_alsa_profile_dump(pa_alsa_profile *p) { pa_log_debug("Profile %s (%s), input=%s, output=%s priority=%u, supported=%s n_input_mappings=%u, n_output_mappings=%u", p->profile.name, pa_strnull(p->profile.description), - pa_strnull(p->profile.input_name), - pa_strnull(p->profile.output_name), + pa_strnull(p->input_name), + pa_strnull(p->output_name), p->profile.priority, pa_yes_no(p->supported), p->input_mappings ? pa_idxset_size(p->input_mappings) : 0, diff --git a/spa/plugins/pulse/alsa-mixer.h b/spa/plugins/pulse/alsa-mixer.h index 217978fc..a69a4f7a 100644 --- a/spa/plugins/pulse/alsa-mixer.h +++ b/spa/plugins/pulse/alsa-mixer.h @@ -373,6 +373,9 @@ struct pa_alsa_profile { bool fallback_input:1; bool fallback_output:1; + char *input_name; + char *output_name; + char **input_mapping_names; char **output_mapping_names; diff --git a/spa/plugins/pulse/test-probe.c b/spa/plugins/pulse/test-probe.c index 94885f35..7dfaebb7 100644 --- a/spa/plugins/pulse/test-probe.c +++ b/spa/plugins/pulse/test-probe.c @@ -1,4 +1,4 @@ -/* Spa +/* ALSA card profile test * * Copyright © 2020 Wim Taymans * @@ -30,9 +30,6 @@ #include <time.h> #include <stdbool.h> #include <getopt.h> -#include <termios.h> - -#include <spa/utils/defs.h> #include "acp.h" @@ -186,12 +183,13 @@ struct command { const char *args; const char *alias; const char *description; - int (*func) (struct data *data, int argc, char *argv[]); + int (*func) (struct data *data, const struct command *cmd, int argc, char *argv[]); + void *extra; }; -static int cmd_help(struct data *data, int argc, char *argv[]); +static int cmd_help(struct data *data, const struct command *cmd, int argc, char *argv[]); -static int cmd_quit(struct data *data, int argc, char *argv[]) +static int cmd_quit(struct data *data, const struct command *cmd, int argc, char *argv[]) { data->quit = true; return 0; @@ -203,9 +201,10 @@ static void print_port(struct data *data, struct acp_port *p, int indent, int le { uint32_t i; - fprintf(stderr, "%*s%cport %u: name:\"%s\" direction:%s available:%s\n", + fprintf(stderr, "%*s%cport %u: name:\"%s\" direction:%s prio:%d (available: %s)\n", indent, "", p->flags & ACP_PORT_ACTIVE ? '*' : ' ', p->index, - p->name, str_direction(p->direction), str_available(p->available)); + p->name, str_direction(p->direction), p->priority, + str_available(p->available)); if (level > 0) { acp_debug_dict(&p->props, indent + 4); } @@ -222,9 +221,9 @@ static void print_device(struct data *data, struct acp_device *d, int indent, in char **s; uint32_t i; - fprintf(stderr, "%*s%cdevice %u: direction:%s name:\"%s\" devices: ", + fprintf(stderr, "%*s%cdevice %u: direction:%s name:\"%s\" prio:%d devices: ", indent, "", d->flags & ACP_DEVICE_ACTIVE ? '*' : ' ', d->index, - str_direction(d->direction), d->name); + str_direction(d->direction), d->name, d->priority); for (s = d->device_strings; *s; s++) fprintf(stderr, "\"%s\" ", *s); fprintf(stderr, "\n"); @@ -245,13 +244,13 @@ static void print_profile(struct data *data, struct acp_card_profile *p, int ind { uint32_t i; - fprintf(stderr, "%*s%cprofile %u: name:\"%s\" (available: %s)\n", + fprintf(stderr, "%*s%cprofile %u: name:\"%s\" prio:%d (available: %s)\n", indent, "", p->flags & ACP_PROFILE_ACTIVE ? '*' : ' ', p->index, - p->name, str_available(p->available)); + p->name, p->priority, str_available(p->available)); if (level > 0) { - fprintf(stderr, "%*s description:\"%s\" priority:%d n_devices:%d\n", + fprintf(stderr, "%*s description:\"%s\" n_devices:%d\n", indent, "", p->description, - p->priority, p->n_devices); + p->n_devices); } if (level > 1) { for (i = 0; i < p->n_devices; i++) { @@ -261,7 +260,28 @@ static void print_profile(struct data *data, struct acp_card_profile *p, int ind } } -static int cmd_list_profiles(struct data *data, int argc, char *argv[]) +static int cmd_list(struct data *data, const struct command *cmd, int argc, char *argv[]) +{ + struct acp_card *card = data->card; + uint32_t i; + int level = 0; + + if (!strcmp(cmd->name, "list-verbose")) + level = 2; + + for (i = 0; i < card->n_profiles; i++) + print_profile(data, card->profiles[i], 0, level); + + for (i = 0; i < card->n_ports; i++) + print_port(data, card->ports[i], 0, level); + + for (i = 0; i < card->n_devices; i++) + print_device(data, card->devices[i], 0, level); + + return 0; +} + +static int cmd_list_profiles(struct data *data, const struct command *cmd, int argc, char *argv[]) { uint32_t i; struct acp_card *card = data->card; @@ -278,7 +298,7 @@ static int cmd_list_profiles(struct data *data, int argc, char *argv[]) return 0; } -static int cmd_set_profile(struct data *data, int argc, char *argv[]) +static int cmd_set_profile(struct data *data, const struct command *cmd, int argc, char *argv[]) { struct acp_card *card = data->card; uint32_t index; @@ -291,7 +311,7 @@ static int cmd_set_profile(struct data *data, int argc, char *argv[]) return acp_card_set_profile(card, index); } -static int cmd_list_ports(struct data *data, int argc, char *argv[]) +static int cmd_list_ports(struct data *data, const struct command *cmd, int argc, char *argv[]) { uint32_t i; struct acp_card *card = data->card; @@ -308,7 +328,7 @@ static int cmd_list_ports(struct data *data, int argc, char *argv[]) return 0; } -static int cmd_set_port(struct data *data, int argc, char *argv[]) +static int cmd_set_port(struct data *data, const struct command *cmd, int argc, char *argv[]) { struct acp_card *card = data->card; uint32_t dev_id, port_id; @@ -326,7 +346,7 @@ static int cmd_set_port(struct data *data, int argc, char *argv[]) return acp_device_set_port(card->devices[dev_id], port_id); } -static int cmd_list_devices(struct data *data, int argc, char *argv[]) +static int cmd_list_devices(struct data *data, const struct command *cmd, int argc, char *argv[]) { uint32_t i; struct acp_card *card = data->card; @@ -343,7 +363,7 @@ static int cmd_list_devices(struct data *data, int argc, char *argv[]) return 0; } -static int cmd_get_volume(struct data *data, int argc, char *argv[]) +static int cmd_get_volume(struct data *data, const struct command *cmd, int argc, char *argv[]) { struct acp_card *card = data->card; uint32_t dev_id; @@ -363,7 +383,7 @@ static int cmd_get_volume(struct data *data, int argc, char *argv[]) return 0; } -static int cmd_set_volume(struct data *data, int argc, char *argv[]) +static int cmd_set_volume(struct data *data, const struct command *cmd, int argc, char *argv[]) { struct acp_card *card = data->card; uint32_t dev_id; @@ -382,7 +402,7 @@ static int cmd_set_volume(struct data *data, int argc, char *argv[]) return acp_device_set_volume(card->devices[dev_id], &vol, 1); } -static int adjust_volume(struct data *data, int argc, char *argv[], float adjust) +static int adjust_volume(struct data *data, const struct command *cmd, int argc, char *argv[], float adjust) { struct acp_card *card = data->card; uint32_t dev_id; @@ -402,17 +422,17 @@ static int adjust_volume(struct data *data, int argc, char *argv[], float adjust return 0; } -static int cmd_inc_volume(struct data *data, int argc, char *argv[]) +static int cmd_inc_volume(struct data *data, const struct command *cmd, int argc, char *argv[]) { - return adjust_volume(data, argc, argv, 0.2); + return adjust_volume(data, cmd, argc, argv, 0.2); } -static int cmd_dec_volume(struct data *data, int argc, char *argv[]) +static int cmd_dec_volume(struct data *data, const struct command *cmd, int argc, char *argv[]) { - return adjust_volume(data, argc, argv, -0.2); + return adjust_volume(data, cmd, argc, argv, -0.2); } -static int cmd_get_mute(struct data *data, int argc, char *argv[]) +static int cmd_get_mute(struct data *data, const struct command *cmd, int argc, char *argv[]) { struct acp_card *card = data->card; uint32_t dev_id; @@ -432,7 +452,7 @@ static int cmd_get_mute(struct data *data, int argc, char *argv[]) return 0; } -static int cmd_set_mute(struct data *data, int argc, char *argv[]) +static int cmd_set_mute(struct data *data, const struct command *cmd, int argc, char *argv[]) { struct acp_card *card = data->card; uint32_t dev_id; @@ -452,7 +472,7 @@ static int cmd_set_mute(struct data *data, int argc, char *argv[]) return 0; } -static int cmd_toggle_mute(struct data *data, int argc, char *argv[]) +static int cmd_toggle_mute(struct data *data, const struct command *cmd, int argc, char *argv[]) { struct acp_card *card = data->card; uint32_t dev_id; @@ -472,9 +492,11 @@ static int cmd_toggle_mute(struct data *data, int argc, char *argv[]) return 0; } -static struct command command_list[] = { +static const struct command command_list[] = { { "help", "", "h", "Show this help", cmd_help }, { "quit", "", "q", "Quit", cmd_quit }, + { "list", "", "l", "List all objects", cmd_list }, + { "list-verbose", "", "lv", "List all data", cmd_list }, { "list-profiles", "[id]", "lpr", "List profiles", cmd_list_profiles }, { "set-profile", "<id>", "spr", "Activate a profile", cmd_set_profile }, { "list-ports", "[id]", "lp", "List ports", cmd_list_ports }, @@ -488,11 +510,12 @@ static struct command command_list[] = { { "set-mute", "<id> <val>", "sm", "Set mute on device", cmd_set_mute }, { "toggle-mute", "<id>", "m", "Toggle mute on device", cmd_toggle_mute }, }; +#define N_COMMANDS sizeof(command_list)/sizeof(command_list[0]) -static struct command *find_command(struct data *data, const char *cmd) +static const struct command *find_command(struct data *data, const char *cmd) { size_t i; - for (i = 0; i < SPA_N_ELEMENTS(command_list); i++) { + for (i = 0; i < N_COMMANDS; i++) { if (!strcmp(command_list[i].name, cmd) || !strcmp(command_list[i].alias, cmd)) return &command_list[i]; @@ -500,12 +523,12 @@ static struct command *find_command(struct data *data, const char *cmd) return NULL; } -static int cmd_help(struct data *data, int argc, char *argv[]) +static int cmd_help(struct data *data, const struct command *cmd, int argc, char *argv[]) { size_t i; fprintf(stderr, "Available commands:\n"); - for (i = 0; i < SPA_N_ELEMENTS(command_list); i++) { - fprintf(stdout, "\t%-20.20s %-10.10s\t%s (%s)\n", + for (i = 0; i < N_COMMANDS; i++) { + fprintf(stdout, "\t%-15.15s %-10.10s\t%s (%s)\n", command_list[i].name, command_list[i].args, command_list[i].description, @@ -519,7 +542,7 @@ static int handle_keyboard(struct data *data) char buf[4096] = { 0, }, *p, *argv[64]; ssize_t r; int res, argc; - struct command *command; + const struct command *command; if ((r = read(STDIN_FILENO, buf, sizeof(buf)-1)) < 0) return -errno; @@ -534,10 +557,11 @@ static int handle_keyboard(struct data *data) command = find_command(data, argv[0]); if (command == NULL) { - cmd_help(data, argc, argv); + fprintf(stderr, "unknown command %s\n", argv[0]); + cmd_help(data, NULL, argc, argv); res = -EINVAL; } else if (command->func) { - res = command->func(data, argc, argv); + res = command->func(data, command, argc, argv); if (res < 0) { fprintf(stderr, "error: %s\n", strerror(-res)); } @@ -556,7 +580,6 @@ static int do_probe(struct data *data) uint32_t n_items = 0; struct acp_dict_item items[2]; struct acp_dict props; - uint32_t i; struct pollfd *pfds; int err, count; @@ -569,19 +592,6 @@ static int do_probe(struct data *data) data->card = card = acp_card_new(data->card_index, &props); - for (i = 0; i < card->n_profiles; i++) { - struct acp_card_profile *p = card->profiles[i]; - print_profile(data, p, 0, 0); - } - for (i = 0; i < card->n_ports; i++) { - struct acp_port *p = card->ports[i]; - print_port(data, p, 0, 0); - } - for (i = 0; i < card->n_devices; i++) { - struct acp_device *d = card->devices[i]; - print_device(data, d, 0, 0); - } - acp_card_add_listener(card, &card_events, data); count = acp_card_poll_descriptors_count(card); @@ -593,6 +603,8 @@ static int do_probe(struct data *data) pfds[0].fd = STDIN_FILENO; pfds[0].events = POLLIN; + fprintf(stderr, "Probed card %d: profiles:%d devices:%d ports:%d\n", + card->index, card->n_profiles, card->n_devices, card->n_ports); fprintf(stderr, "type 'help' for usage.\n"); show_prompt(data); |