mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-07 13:30:03 -05:00
card: Ensure that there's always at least one profile.
In practice there is always at least one profile, and I don't think there will ever be cards without profiles. Therefore, I added assertions to pa_card_new() stating that the card new data must always contain at least one profile. Now a lot of code can be simplified, because it's guaranteed that the profiles hashmap and the active_profile field are always non-NULL.
This commit is contained in:
parent
1a6da64b16
commit
12af302ac7
9 changed files with 35 additions and 70 deletions
|
|
@ -67,6 +67,7 @@ pa_card_new_data* pa_card_new_data_init(pa_card_new_data *data) {
|
|||
|
||||
memset(data, 0, sizeof(*data));
|
||||
data->proplist = pa_proplist_new();
|
||||
data->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
return data;
|
||||
}
|
||||
|
|
@ -114,6 +115,8 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
|
|||
pa_core_assert_ref(core);
|
||||
pa_assert(data);
|
||||
pa_assert(data->name);
|
||||
pa_assert(data->profiles);
|
||||
pa_assert(!pa_hashmap_isempty(data->profiles));
|
||||
|
||||
c = pa_xnew(pa_card, 1);
|
||||
|
||||
|
|
@ -149,11 +152,11 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
|
|||
c->active_profile = NULL;
|
||||
c->save_profile = FALSE;
|
||||
|
||||
if (data->active_profile && c->profiles)
|
||||
if (data->active_profile)
|
||||
if ((c->active_profile = pa_hashmap_get(c->profiles, data->active_profile)))
|
||||
c->save_profile = data->save_profile;
|
||||
|
||||
if (!c->active_profile && c->profiles) {
|
||||
if (!c->active_profile) {
|
||||
void *state;
|
||||
pa_card_profile *p;
|
||||
|
||||
|
|
@ -221,6 +224,7 @@ void pa_card_free(pa_card *c) {
|
|||
int pa_card_set_profile(pa_card *c, const char *name, pa_bool_t save) {
|
||||
pa_card_profile *profile;
|
||||
int r;
|
||||
|
||||
pa_assert(c);
|
||||
|
||||
if (!c->set_profile) {
|
||||
|
|
@ -228,7 +232,7 @@ int pa_card_set_profile(pa_card *c, const char *name, pa_bool_t save) {
|
|||
return -PA_ERR_NOTIMPLEMENTED;
|
||||
}
|
||||
|
||||
if (!c->profiles || !name)
|
||||
if (!name)
|
||||
return -PA_ERR_NOENTITY;
|
||||
|
||||
if (!(profile = pa_hashmap_get(c->profiles, name)))
|
||||
|
|
|
|||
|
|
@ -1840,8 +1840,7 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b
|
|||
nl = TRUE;
|
||||
}
|
||||
|
||||
if (card->active_profile)
|
||||
pa_strbuf_printf(buf, "set-card-profile %s %s\n", card->name, card->active_profile->name);
|
||||
pa_strbuf_printf(buf, "set-card-profile %s %s\n", card->name, card->active_profile->name);
|
||||
}
|
||||
|
||||
nl = FALSE;
|
||||
|
|
|
|||
|
|
@ -149,6 +149,8 @@ char *pa_card_list_to_string(pa_core *c) {
|
|||
pa_sink *sink;
|
||||
pa_source *source;
|
||||
uint32_t sidx;
|
||||
pa_card_profile *profile;
|
||||
void *state;
|
||||
|
||||
pa_strbuf_printf(
|
||||
s,
|
||||
|
|
@ -166,20 +168,14 @@ char *pa_card_list_to_string(pa_core *c) {
|
|||
pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
|
||||
pa_xfree(t);
|
||||
|
||||
if (card->profiles) {
|
||||
pa_card_profile *p;
|
||||
void *state;
|
||||
pa_strbuf_puts(s, "\tprofiles:\n");
|
||||
PA_HASHMAP_FOREACH(profile, card->profiles, state)
|
||||
pa_strbuf_printf(s, "\t\t%s: %s (priority %u)\n", profile->name, profile->description, profile->priority);
|
||||
|
||||
pa_strbuf_puts(s, "\tprofiles:\n");
|
||||
PA_HASHMAP_FOREACH(p, card->profiles, state)
|
||||
pa_strbuf_printf(s, "\t\t%s: %s (priority %u)\n", p->name, p->description, p->priority);
|
||||
}
|
||||
|
||||
if (card->active_profile)
|
||||
pa_strbuf_printf(
|
||||
s,
|
||||
"\tactive profile: <%s>\n",
|
||||
card->active_profile->name);
|
||||
pa_strbuf_printf(
|
||||
s,
|
||||
"\tactive profile: <%s>\n",
|
||||
card->active_profile->name);
|
||||
|
||||
if (!pa_idxset_isempty(card->sinks)) {
|
||||
pa_strbuf_puts(s, "\tsinks:\n");
|
||||
|
|
|
|||
|
|
@ -3239,19 +3239,17 @@ static void card_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_car
|
|||
pa_tagstruct_putu32(t, card->module ? card->module->index : PA_INVALID_INDEX);
|
||||
pa_tagstruct_puts(t, card->driver);
|
||||
|
||||
pa_tagstruct_putu32(t, card->profiles ? pa_hashmap_size(card->profiles) : 0);
|
||||
pa_tagstruct_putu32(t, pa_hashmap_size(card->profiles));
|
||||
|
||||
if (card->profiles) {
|
||||
while ((p = pa_hashmap_iterate(card->profiles, &state, NULL))) {
|
||||
pa_tagstruct_puts(t, p->name);
|
||||
pa_tagstruct_puts(t, p->description);
|
||||
pa_tagstruct_putu32(t, p->n_sinks);
|
||||
pa_tagstruct_putu32(t, p->n_sources);
|
||||
pa_tagstruct_putu32(t, p->priority);
|
||||
}
|
||||
PA_HASHMAP_FOREACH(p, card->profiles, state) {
|
||||
pa_tagstruct_puts(t, p->name);
|
||||
pa_tagstruct_puts(t, p->description);
|
||||
pa_tagstruct_putu32(t, p->n_sinks);
|
||||
pa_tagstruct_putu32(t, p->n_sources);
|
||||
pa_tagstruct_putu32(t, p->priority);
|
||||
}
|
||||
|
||||
pa_tagstruct_puts(t, card->active_profile ? card->active_profile->name : NULL);
|
||||
pa_tagstruct_puts(t, card->active_profile->name);
|
||||
pa_tagstruct_put_proplist(t, card->proplist);
|
||||
|
||||
if (c->version < 26)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue