mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-12 13:30:10 -05:00
core: change configured_default_sink/source type to string
This allows us to restore the default device properly when a hotpluggable device (e.g. a USB sound card) is set as the default, but unplugged temporarily. Previously we would forget that the unplugged device was ever set as the default, because we had to set configured_default_sink to NULL to avoid having a stale pa_sink pointer, and also because module-default-device-restore couldn't resolve the name of a currently-unplugged device to a pa_sink pointer. BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=89934
This commit is contained in:
parent
abdd14d5e0
commit
a448cc587c
9 changed files with 63 additions and 56 deletions
|
|
@ -1030,7 +1030,7 @@ static int pa_cli_command_sink_default(pa_core *c, pa_tokenizer *t, pa_strbuf *b
|
|||
}
|
||||
|
||||
if ((s = pa_namereg_get(c, n, PA_NAMEREG_SINK)))
|
||||
pa_core_set_configured_default_sink(c, s);
|
||||
pa_core_set_configured_default_sink(c, s->name);
|
||||
else
|
||||
pa_strbuf_printf(buf, "Sink %s does not exist.\n", n);
|
||||
|
||||
|
|
@ -1052,7 +1052,7 @@ static int pa_cli_command_source_default(pa_core *c, pa_tokenizer *t, pa_strbuf
|
|||
}
|
||||
|
||||
if ((s = pa_namereg_get(c, n, PA_NAMEREG_SOURCE)))
|
||||
pa_core_set_configured_default_source(c, s);
|
||||
pa_core_set_configured_default_source(c, s->name);
|
||||
else
|
||||
pa_strbuf_printf(buf, "Source %s does not exist.\n", n);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -214,6 +214,8 @@ static void core_free(pa_object *o) {
|
|||
|
||||
pa_assert(!c->default_source);
|
||||
pa_assert(!c->default_sink);
|
||||
pa_xfree(c->configured_default_source);
|
||||
pa_xfree(c->configured_default_sink);
|
||||
|
||||
pa_silence_cache_done(&c->silence_cache);
|
||||
pa_mempool_unref(c->mempool);
|
||||
|
|
@ -224,38 +226,46 @@ static void core_free(pa_object *o) {
|
|||
pa_xfree(c);
|
||||
}
|
||||
|
||||
void pa_core_set_configured_default_sink(pa_core *core, pa_sink *sink) {
|
||||
pa_sink *old_sink;
|
||||
void pa_core_set_configured_default_sink(pa_core *core, const char *sink) {
|
||||
char *old_sink;
|
||||
|
||||
pa_assert(core);
|
||||
|
||||
old_sink = core->configured_default_sink;
|
||||
old_sink = pa_xstrdup(core->configured_default_sink);
|
||||
|
||||
if (sink == old_sink)
|
||||
return;
|
||||
if (pa_safe_streq(sink, old_sink))
|
||||
goto finish;
|
||||
|
||||
core->configured_default_sink = sink;
|
||||
pa_xfree(core->configured_default_sink);
|
||||
core->configured_default_sink = pa_xstrdup(sink);
|
||||
pa_log_info("configured_default_sink: %s -> %s",
|
||||
old_sink ? old_sink->name : "(unset)", sink ? sink->name : "(unset)");
|
||||
old_sink ? old_sink : "(unset)", sink ? sink : "(unset)");
|
||||
|
||||
pa_core_update_default_sink(core);
|
||||
|
||||
finish:
|
||||
pa_xfree(old_sink);
|
||||
}
|
||||
|
||||
void pa_core_set_configured_default_source(pa_core *core, pa_source *source) {
|
||||
pa_source *old_source;
|
||||
void pa_core_set_configured_default_source(pa_core *core, const char *source) {
|
||||
char *old_source;
|
||||
|
||||
pa_assert(core);
|
||||
|
||||
old_source = core->configured_default_source;
|
||||
old_source = pa_xstrdup(core->configured_default_source);
|
||||
|
||||
if (source == old_source)
|
||||
return;
|
||||
if (pa_safe_streq(source, old_source))
|
||||
goto finish;
|
||||
|
||||
core->configured_default_source = source;
|
||||
pa_xfree(core->configured_default_source);
|
||||
core->configured_default_source = pa_xstrdup(source);
|
||||
pa_log_info("configured_default_source: %s -> %s",
|
||||
old_source ? old_source->name : "(unset)", source ? source->name : "(unset)");
|
||||
old_source ? old_source : "(unset)", source ? source : "(unset)");
|
||||
|
||||
pa_core_update_default_source(core);
|
||||
|
||||
finish:
|
||||
pa_xfree(old_source);
|
||||
}
|
||||
|
||||
/* a < b -> return -1
|
||||
|
|
@ -275,9 +285,9 @@ static int compare_sinks(pa_sink *a, pa_sink *b) {
|
|||
return 1;
|
||||
|
||||
/* The configured default sink is preferred over any other sink. */
|
||||
if (b == core->configured_default_sink)
|
||||
if (pa_safe_streq(b->name, core->configured_default_sink))
|
||||
return -1;
|
||||
if (a == core->configured_default_sink)
|
||||
if (pa_safe_streq(a->name, core->configured_default_sink))
|
||||
return 1;
|
||||
|
||||
if (a->priority < b->priority)
|
||||
|
|
@ -349,9 +359,9 @@ static int compare_sources(pa_source *a, pa_source *b) {
|
|||
return 1;
|
||||
|
||||
/* The configured default source is preferred over any other source. */
|
||||
if (b == core->configured_default_source)
|
||||
if (pa_safe_streq(b->name, core->configured_default_source))
|
||||
return -1;
|
||||
if (a == core->configured_default_source)
|
||||
if (pa_safe_streq(a->name, core->configured_default_source))
|
||||
return 1;
|
||||
|
||||
/* Monitor sources lose to non-monitor sources. */
|
||||
|
|
|
|||
|
|
@ -163,9 +163,12 @@ struct pa_core {
|
|||
pa_hashmap *namereg, *shared;
|
||||
|
||||
/* The default sink/source as configured by the user. If the user hasn't
|
||||
* explicitly configured anything, these are set to NULL. */
|
||||
pa_sink *configured_default_sink;
|
||||
pa_source *configured_default_source;
|
||||
* explicitly configured anything, these are set to NULL. These are strings
|
||||
* instead of sink/source pointers, because that allows us to reference
|
||||
* devices that don't currently exist. That's useful for remembering that
|
||||
* a hotplugged USB sink was previously set as the default sink. */
|
||||
char *configured_default_sink;
|
||||
char *configured_default_source;
|
||||
|
||||
/* The effective default sink/source. If no sink or source is explicitly
|
||||
* configured as the default, we pick the device that ranks highest
|
||||
|
|
@ -236,8 +239,8 @@ enum {
|
|||
|
||||
pa_core* pa_core_new(pa_mainloop_api *m, bool shared, bool enable_memfd, size_t shm_size);
|
||||
|
||||
void pa_core_set_configured_default_sink(pa_core *core, pa_sink *sink);
|
||||
void pa_core_set_configured_default_source(pa_core *core, pa_source *source);
|
||||
void pa_core_set_configured_default_sink(pa_core *core, const char *sink);
|
||||
void pa_core_set_configured_default_source(pa_core *core, const char *source);
|
||||
|
||||
/* These should be called whenever something changes that may affect the
|
||||
* default sink or source choice.
|
||||
|
|
|
|||
|
|
@ -4346,7 +4346,7 @@ static void command_set_default_sink_or_source(pa_pdispatch *pd, uint32_t comman
|
|||
source = pa_namereg_get(c->protocol->core, s, PA_NAMEREG_SOURCE);
|
||||
CHECK_VALIDITY(c->pstream, source, tag, PA_ERR_NOENTITY);
|
||||
|
||||
pa_core_set_configured_default_source(c->protocol->core, source);
|
||||
pa_core_set_configured_default_source(c->protocol->core, source->name);
|
||||
} else {
|
||||
pa_sink *sink;
|
||||
pa_assert(command == PA_COMMAND_SET_DEFAULT_SINK);
|
||||
|
|
@ -4354,7 +4354,7 @@ static void command_set_default_sink_or_source(pa_pdispatch *pd, uint32_t comman
|
|||
sink = pa_namereg_get(c->protocol->core, s, PA_NAMEREG_SINK);
|
||||
CHECK_VALIDITY(c->pstream, sink, tag, PA_ERR_NOENTITY);
|
||||
|
||||
pa_core_set_configured_default_sink(c->protocol->core, sink);
|
||||
pa_core_set_configured_default_sink(c->protocol->core, sink->name);
|
||||
}
|
||||
|
||||
pa_pstream_send_simple_ack(c->pstream, tag);
|
||||
|
|
|
|||
|
|
@ -694,10 +694,7 @@ void pa_sink_unlink(pa_sink* s) {
|
|||
pa_namereg_unregister(s->core, s->name);
|
||||
pa_idxset_remove_by_data(s->core->sinks, s, NULL);
|
||||
|
||||
if (s == s->core->configured_default_sink)
|
||||
pa_core_set_configured_default_sink(s->core, NULL);
|
||||
else
|
||||
pa_core_update_default_sink(s->core);
|
||||
pa_core_update_default_sink(s->core);
|
||||
|
||||
if (s->card)
|
||||
pa_idxset_remove_by_data(s->card->sinks, s, NULL);
|
||||
|
|
|
|||
|
|
@ -636,10 +636,7 @@ void pa_source_unlink(pa_source *s) {
|
|||
pa_namereg_unregister(s->core, s->name);
|
||||
pa_idxset_remove_by_data(s->core->sources, s, NULL);
|
||||
|
||||
if (s == s->core->configured_default_source)
|
||||
pa_core_set_configured_default_source(s->core, NULL);
|
||||
else
|
||||
pa_core_update_default_source(s->core);
|
||||
pa_core_update_default_source(s->core);
|
||||
|
||||
if (s->card)
|
||||
pa_idxset_remove_by_data(s->card->sources, s, NULL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue