2004-07-16 19:56:36 +00:00
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2004-2006 Lennart Poettering
|
|
|
|
|
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
2009-03-03 20:23:02 +00:00
|
|
|
by the Free Software Foundation; either version 2.1 of the License,
|
2004-07-16 19:56:36 +00:00
|
|
|
or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-07-16 19:56:36 +00:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2014-11-26 14:14:51 +01:00
|
|
|
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
|
2004-07-16 19:56:36 +00:00
|
|
|
***/
|
|
|
|
|
|
2004-07-16 19:16:42 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
2004-09-15 13:03:25 +00:00
|
|
|
#include <signal.h>
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2009-04-05 02:13:43 +03:00
|
|
|
#include <pulse/rtclock.h>
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/timeval.h>
|
|
|
|
|
#include <pulse/xmalloc.h>
|
2006-05-17 16:34:18 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/module.h>
|
2009-04-05 02:13:43 +03:00
|
|
|
#include <pulsecore/core-rtclock.h>
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/core-util.h>
|
2020-01-14 11:00:20 +01:00
|
|
|
#include <pulsecore/message-handler.h>
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/core-scache.h>
|
|
|
|
|
#include <pulsecore/core-subscribe.h>
|
|
|
|
|
#include <pulsecore/random.h>
|
2006-08-22 12:46:05 +00:00
|
|
|
#include <pulsecore/log.h>
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <pulsecore/macro.h>
|
2020-01-14 11:00:20 +01:00
|
|
|
#include <pulsecore/strbuf.h>
|
2006-02-17 12:10:58 +00:00
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
#include "core.h"
|
|
|
|
|
|
2009-08-21 21:27:44 +02:00
|
|
|
PA_DEFINE_PUBLIC_CLASS(pa_core, pa_msgobject);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
static int core_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offset, pa_memchunk *chunk) {
|
|
|
|
|
pa_core *c = PA_CORE(o);
|
|
|
|
|
|
|
|
|
|
pa_core_assert_ref(c);
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
|
|
|
|
case PA_CORE_MESSAGE_UNLOAD_MODULE:
|
2015-06-25 21:59:36 +05:30
|
|
|
pa_module_unload(userdata, true);
|
2007-10-28 19:13:50 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void core_free(pa_object *o);
|
|
|
|
|
|
2020-01-14 11:00:20 +01:00
|
|
|
/* Returns a list of handlers. */
|
|
|
|
|
static char *message_handler_list(pa_core *c) {
|
2021-03-14 09:49:05 +03:00
|
|
|
pa_json_encoder *encoder;
|
2020-01-14 11:00:20 +01:00
|
|
|
void *state = NULL;
|
|
|
|
|
struct pa_message_handler *handler;
|
|
|
|
|
|
2021-03-14 09:49:05 +03:00
|
|
|
encoder = pa_json_encoder_new();
|
2020-01-14 11:00:20 +01:00
|
|
|
|
2021-03-14 09:49:05 +03:00
|
|
|
pa_json_encoder_begin_element_array(encoder);
|
2020-01-14 11:00:20 +01:00
|
|
|
PA_HASHMAP_FOREACH(handler, c->message_handlers, state) {
|
2021-03-14 09:49:05 +03:00
|
|
|
pa_json_encoder_begin_element_object(encoder);
|
2020-01-14 11:00:20 +01:00
|
|
|
|
2021-03-14 09:49:05 +03:00
|
|
|
pa_json_encoder_add_member_string(encoder, "name", handler->object_path);
|
|
|
|
|
pa_json_encoder_add_member_string(encoder, "description", handler->description);
|
2020-01-14 11:00:20 +01:00
|
|
|
|
2021-03-14 09:49:05 +03:00
|
|
|
pa_json_encoder_end_object(encoder);
|
2020-01-14 11:00:20 +01:00
|
|
|
}
|
2021-03-14 09:49:05 +03:00
|
|
|
pa_json_encoder_end_array(encoder);
|
2020-01-14 11:00:20 +01:00
|
|
|
|
2021-03-14 09:49:05 +03:00
|
|
|
return pa_json_encoder_to_string_free(encoder);
|
2020-01-14 11:00:20 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-14 09:49:05 +03:00
|
|
|
static int core_message_handler(const char *object_path, const char *message, const pa_json_object *parameters, char **response, void *userdata) {
|
2020-01-14 11:00:20 +01:00
|
|
|
pa_core *c;
|
|
|
|
|
|
|
|
|
|
pa_assert(c = (pa_core *) userdata);
|
|
|
|
|
pa_assert(message);
|
|
|
|
|
pa_assert(response);
|
|
|
|
|
pa_assert(pa_safe_streq(object_path, "/core"));
|
|
|
|
|
|
|
|
|
|
if (pa_streq(message, "list-handlers")) {
|
|
|
|
|
*response = message_handler_list(c);
|
|
|
|
|
return PA_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -PA_ERR_NOTIMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-15 23:07:36 +02:00
|
|
|
pa_core* pa_core_new(pa_mainloop_api *m, bool shared, bool enable_memfd, size_t shm_size) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_core* c;
|
2006-08-19 01:15:48 +00:00
|
|
|
pa_mempool *pool;
|
2016-04-15 23:07:36 +02:00
|
|
|
pa_mem_type_t type;
|
2007-10-28 19:13:50 +00:00
|
|
|
int j;
|
|
|
|
|
|
|
|
|
|
pa_assert(m);
|
2006-08-19 01:15:48 +00:00
|
|
|
|
2006-08-22 12:51:29 +00:00
|
|
|
if (shared) {
|
2016-04-15 23:07:36 +02:00
|
|
|
type = (enable_memfd) ? PA_MEM_TYPE_SHARED_MEMFD : PA_MEM_TYPE_SHARED_POSIX;
|
|
|
|
|
if (!(pool = pa_mempool_new(type, shm_size, false))) {
|
|
|
|
|
pa_log_warn("Failed to allocate %s memory pool. Falling back to a normal memory pool.",
|
|
|
|
|
pa_mem_type_to_string(type));
|
2013-06-27 19:28:09 +02:00
|
|
|
shared = false;
|
2006-08-22 12:51:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!shared) {
|
2016-03-13 01:09:39 +02:00
|
|
|
if (!(pool = pa_mempool_new(PA_MEM_TYPE_PRIVATE, shm_size, false))) {
|
2006-09-06 22:19:11 +00:00
|
|
|
pa_log("pa_mempool_new() failed.");
|
2006-08-22 12:51:29 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2006-09-06 22:19:11 +00:00
|
|
|
}
|
2006-08-22 12:51:29 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
c = pa_msgobject_new(pa_core);
|
|
|
|
|
c->parent.parent.free = core_free;
|
|
|
|
|
c->parent.process_msg = core_process_msg;
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2009-01-23 22:29:02 +01:00
|
|
|
c->state = PA_CORE_STARTUP;
|
2004-06-08 23:54:24 +00:00
|
|
|
c->mainloop = m;
|
2009-01-29 16:25:29 +01:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
c->clients = pa_idxset_new(NULL, NULL);
|
2009-01-29 16:25:29 +01:00
|
|
|
c->cards = pa_idxset_new(NULL, NULL);
|
2004-07-03 23:35:12 +00:00
|
|
|
c->sinks = pa_idxset_new(NULL, NULL);
|
|
|
|
|
c->sources = pa_idxset_new(NULL, NULL);
|
|
|
|
|
c->sink_inputs = pa_idxset_new(NULL, NULL);
|
2009-01-29 16:25:29 +01:00
|
|
|
c->source_outputs = pa_idxset_new(NULL, NULL);
|
|
|
|
|
c->modules = pa_idxset_new(NULL, NULL);
|
|
|
|
|
c->scache = pa_idxset_new(NULL, NULL);
|
|
|
|
|
|
|
|
|
|
c->namereg = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
|
|
|
|
c->shared = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
2019-03-26 10:41:05 +01:00
|
|
|
c->message_handlers = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2020-01-14 11:00:20 +01:00
|
|
|
pa_message_handler_register(c, "/core", "Core message handler", core_message_handler, (void *) c);
|
|
|
|
|
|
2009-01-28 01:46:27 +01:00
|
|
|
c->default_source = NULL;
|
|
|
|
|
c->default_sink = NULL;
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-07-15 20:12:21 +00:00
|
|
|
c->default_sample_spec.format = PA_SAMPLE_S16NE;
|
|
|
|
|
c->default_sample_spec.rate = 44100;
|
|
|
|
|
c->default_sample_spec.channels = 2;
|
2009-02-21 16:32:42 +01:00
|
|
|
pa_channel_map_init_extend(&c->default_channel_map, c->default_sample_spec.channels, PA_CHANNEL_MAP_DEFAULT);
|
2007-10-28 19:13:50 +00:00
|
|
|
c->default_n_fragments = 4;
|
|
|
|
|
c->default_fragment_size_msec = 25;
|
2004-08-04 16:39:30 +00:00
|
|
|
|
2011-09-13 21:15:49 +01:00
|
|
|
c->deferred_volume_safety_margin_usec = 8000;
|
|
|
|
|
c->deferred_volume_extra_delay_usec = 0;
|
2010-10-15 13:05:17 +03:00
|
|
|
|
2004-09-14 23:08:39 +00:00
|
|
|
c->module_defer_unload_event = NULL;
|
2014-12-05 15:51:35 +02:00
|
|
|
c->modules_pending_unload = pa_hashmap_new(NULL, NULL);
|
2004-08-11 00:11:12 +00:00
|
|
|
|
|
|
|
|
c->subscription_defer_event = NULL;
|
2006-08-12 02:18:24 +00:00
|
|
|
PA_LLIST_HEAD_INIT(pa_subscription, c->subscriptions);
|
|
|
|
|
PA_LLIST_HEAD_INIT(pa_subscription_event, c->subscription_event_queue);
|
|
|
|
|
c->subscription_event_last = NULL;
|
2004-08-17 19:37:29 +00:00
|
|
|
|
2006-08-19 01:15:48 +00:00
|
|
|
c->mempool = pool;
|
2016-03-13 00:48:15 +02:00
|
|
|
c->shm_size = shm_size;
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_silence_cache_init(&c->silence_cache);
|
2004-09-03 22:44:55 +00:00
|
|
|
|
2008-08-06 19:39:12 +02:00
|
|
|
c->exit_event = NULL;
|
2014-12-05 15:51:35 +02:00
|
|
|
c->scache_auto_unload_event = NULL;
|
2004-09-13 23:28:30 +00:00
|
|
|
|
|
|
|
|
c->exit_idle_time = -1;
|
2004-09-14 23:08:39 +00:00
|
|
|
c->scache_idle_time = 20;
|
2004-10-30 01:55:16 +00:00
|
|
|
|
2013-06-27 19:28:09 +02:00
|
|
|
c->flat_volumes = true;
|
|
|
|
|
c->disallow_module_loading = false;
|
|
|
|
|
c->disallow_exit = false;
|
|
|
|
|
c->running_as_daemon = false;
|
|
|
|
|
c->realtime_scheduling = false;
|
2007-11-01 02:58:26 +00:00
|
|
|
c->realtime_priority = 5;
|
2013-06-27 19:28:09 +02:00
|
|
|
c->disable_remixing = false;
|
2017-01-04 11:55:49 -05:00
|
|
|
c->remixing_use_all_sink_channels = true;
|
2019-12-10 06:50:59 +00:00
|
|
|
c->remixing_produce_lfe = false;
|
|
|
|
|
c->remixing_consume_lfe = false;
|
2016-05-21 22:37:08 +05:00
|
|
|
c->lfe_crossover_freq = 0;
|
2013-06-27 19:28:09 +02:00
|
|
|
c->deferred_volume = true;
|
2012-11-19 15:08:34 +05:30
|
|
|
c->resample_method = PA_RESAMPLER_SPEEX_FLOAT_BASE + 1;
|
2006-07-19 17:44:19 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
for (j = 0; j < PA_CORE_HOOK_MAX; j++)
|
|
|
|
|
pa_hook_init(&c->hooks[j], c);
|
2006-08-13 16:19:56 +00:00
|
|
|
|
2004-12-12 22:58:53 +00:00
|
|
|
pa_random(&c->cookie, sizeof(c->cookie));
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-01-10 17:51:06 +00:00
|
|
|
#ifdef SIGPIPE
|
2004-09-15 13:03:25 +00:00
|
|
|
pa_check_signal_is_blocked(SIGPIPE);
|
2006-01-10 17:51:06 +00:00
|
|
|
#endif
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
return c;
|
2004-08-19 23:14:59 +00:00
|
|
|
}
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
static void core_free(pa_object *o) {
|
|
|
|
|
pa_core *c = PA_CORE(o);
|
|
|
|
|
int j;
|
|
|
|
|
pa_assert(c);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2009-01-23 22:29:02 +01:00
|
|
|
c->state = PA_CORE_SHUTDOWN;
|
|
|
|
|
|
2011-08-16 10:54:24 +01:00
|
|
|
/* Note: All modules and samples in the cache should be unloaded before
|
|
|
|
|
* we get here */
|
2009-01-29 16:25:29 +01:00
|
|
|
|
|
|
|
|
pa_assert(pa_idxset_isempty(c->scache));
|
2013-02-12 21:36:55 +02:00
|
|
|
pa_idxset_free(c->scache, NULL);
|
2009-01-29 16:25:29 +01:00
|
|
|
|
|
|
|
|
pa_assert(pa_idxset_isempty(c->modules));
|
2013-02-12 21:36:55 +02:00
|
|
|
pa_idxset_free(c->modules, NULL);
|
2004-08-04 16:39:30 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(pa_idxset_isempty(c->clients));
|
2013-02-12 21:36:55 +02:00
|
|
|
pa_idxset_free(c->clients, NULL);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2009-01-15 18:29:16 +01:00
|
|
|
pa_assert(pa_idxset_isempty(c->cards));
|
2013-02-12 21:36:55 +02:00
|
|
|
pa_idxset_free(c->cards, NULL);
|
2009-01-15 18:29:16 +01:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(pa_idxset_isempty(c->sinks));
|
2013-02-12 21:36:55 +02:00
|
|
|
pa_idxset_free(c->sinks, NULL);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(pa_idxset_isempty(c->sources));
|
2013-02-12 21:36:55 +02:00
|
|
|
pa_idxset_free(c->sources, NULL);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(pa_idxset_isempty(c->source_outputs));
|
2013-02-12 21:36:55 +02:00
|
|
|
pa_idxset_free(c->source_outputs, NULL);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(pa_idxset_isempty(c->sink_inputs));
|
2013-02-12 21:36:55 +02:00
|
|
|
pa_idxset_free(c->sink_inputs, NULL);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2009-01-29 16:25:29 +01:00
|
|
|
pa_assert(pa_hashmap_isempty(c->namereg));
|
2013-09-14 11:50:10 +05:30
|
|
|
pa_hashmap_free(c->namereg);
|
2009-01-29 16:25:29 +01:00
|
|
|
|
|
|
|
|
pa_assert(pa_hashmap_isempty(c->shared));
|
2013-09-14 11:50:10 +05:30
|
|
|
pa_hashmap_free(c->shared);
|
2009-01-29 16:25:29 +01:00
|
|
|
|
2020-01-14 11:00:20 +01:00
|
|
|
pa_message_handler_unregister(c, "/core");
|
|
|
|
|
|
2019-03-26 10:41:05 +01:00
|
|
|
pa_assert(pa_hashmap_isempty(c->message_handlers));
|
|
|
|
|
pa_hashmap_free(c->message_handlers);
|
|
|
|
|
|
2014-12-05 15:51:35 +02:00
|
|
|
pa_assert(pa_hashmap_isempty(c->modules_pending_unload));
|
|
|
|
|
pa_hashmap_free(c->modules_pending_unload);
|
|
|
|
|
|
2004-08-11 00:11:12 +00:00
|
|
|
pa_subscription_free_all(c);
|
2004-09-04 00:27:36 +00:00
|
|
|
|
2008-08-06 19:39:12 +02:00
|
|
|
if (c->exit_event)
|
|
|
|
|
c->mainloop->time_free(c->exit_event);
|
2004-09-14 23:08:39 +00:00
|
|
|
|
2009-01-28 01:46:27 +01:00
|
|
|
pa_assert(!c->default_source);
|
|
|
|
|
pa_assert(!c->default_sink);
|
2017-06-30 00:09:34 +03:00
|
|
|
pa_xfree(c->configured_default_source);
|
|
|
|
|
pa_xfree(c->configured_default_sink);
|
2004-08-17 19:37:29 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_silence_cache_done(&c->silence_cache);
|
2016-03-13 00:51:12 +02:00
|
|
|
pa_mempool_unref(c->mempool);
|
2004-10-30 01:55:16 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
for (j = 0; j < PA_CORE_HOOK_MAX; j++)
|
2008-08-03 16:21:08 +02:00
|
|
|
pa_hook_done(&c->hooks[j]);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
|
|
|
|
pa_xfree(c);
|
2004-08-19 23:14:59 +00:00
|
|
|
}
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2017-06-30 00:09:34 +03:00
|
|
|
void pa_core_set_configured_default_sink(pa_core *core, const char *sink) {
|
|
|
|
|
char *old_sink;
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
|
|
|
|
|
pa_assert(core);
|
|
|
|
|
|
2017-06-30 00:09:34 +03:00
|
|
|
old_sink = pa_xstrdup(core->configured_default_sink);
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
|
2017-06-30 00:09:34 +03:00
|
|
|
if (pa_safe_streq(sink, old_sink))
|
|
|
|
|
goto finish;
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
|
2017-06-30 00:09:34 +03:00
|
|
|
pa_xfree(core->configured_default_sink);
|
|
|
|
|
core->configured_default_sink = pa_xstrdup(sink);
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
pa_log_info("configured_default_sink: %s -> %s",
|
2017-06-30 00:09:34 +03:00
|
|
|
old_sink ? old_sink : "(unset)", sink ? sink : "(unset)");
|
2019-05-21 15:57:20 +03:00
|
|
|
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SERVER | PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
|
|
|
|
|
pa_core_update_default_sink(core);
|
2017-06-30 00:09:34 +03:00
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
pa_xfree(old_sink);
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-30 00:09:34 +03:00
|
|
|
void pa_core_set_configured_default_source(pa_core *core, const char *source) {
|
|
|
|
|
char *old_source;
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
|
|
|
|
|
pa_assert(core);
|
|
|
|
|
|
2017-06-30 00:09:34 +03:00
|
|
|
old_source = pa_xstrdup(core->configured_default_source);
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
|
2017-06-30 00:09:34 +03:00
|
|
|
if (pa_safe_streq(source, old_source))
|
|
|
|
|
goto finish;
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
|
2017-06-30 00:09:34 +03:00
|
|
|
pa_xfree(core->configured_default_source);
|
|
|
|
|
core->configured_default_source = pa_xstrdup(source);
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
pa_log_info("configured_default_source: %s -> %s",
|
2017-06-30 00:09:34 +03:00
|
|
|
old_source ? old_source : "(unset)", source ? source : "(unset)");
|
2019-05-21 15:57:20 +03:00
|
|
|
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SERVER | PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
|
|
|
|
|
pa_core_update_default_source(core);
|
2017-06-30 00:09:34 +03:00
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
pa_xfree(old_source);
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* a < b -> return -1
|
|
|
|
|
* a == b -> return 0
|
|
|
|
|
* a > b -> return 1 */
|
|
|
|
|
static int compare_sinks(pa_sink *a, pa_sink *b) {
|
|
|
|
|
pa_core *core;
|
|
|
|
|
|
|
|
|
|
core = a->core;
|
|
|
|
|
|
2017-02-16 12:09:39 +02:00
|
|
|
/* Available sinks always beat unavailable sinks. */
|
|
|
|
|
if (a->active_port && a->active_port->available == PA_AVAILABLE_NO
|
|
|
|
|
&& (!b->active_port || b->active_port->available != PA_AVAILABLE_NO))
|
|
|
|
|
return -1;
|
|
|
|
|
if (b->active_port && b->active_port->available == PA_AVAILABLE_NO
|
|
|
|
|
&& (!a->active_port || a->active_port->available != PA_AVAILABLE_NO))
|
|
|
|
|
return 1;
|
|
|
|
|
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
/* The configured default sink is preferred over any other sink. */
|
2017-06-30 00:09:34 +03:00
|
|
|
if (pa_safe_streq(b->name, core->configured_default_sink))
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
return -1;
|
2017-06-30 00:09:34 +03:00
|
|
|
if (pa_safe_streq(a->name, core->configured_default_sink))
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
if (a->priority < b->priority)
|
|
|
|
|
return -1;
|
|
|
|
|
if (a->priority > b->priority)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
/* It's hard to find any difference between these sinks, but maybe one of
|
|
|
|
|
* them is already the default sink? If so, it's best to keep it as the
|
|
|
|
|
* default to avoid changing the routing for no good reason. */
|
|
|
|
|
if (b == core->default_sink)
|
|
|
|
|
return -1;
|
|
|
|
|
if (a == core->default_sink)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_core_update_default_sink(pa_core *core) {
|
|
|
|
|
pa_sink *best = NULL;
|
|
|
|
|
pa_sink *sink;
|
|
|
|
|
uint32_t idx;
|
|
|
|
|
pa_sink *old_default_sink;
|
|
|
|
|
|
|
|
|
|
pa_assert(core);
|
|
|
|
|
|
|
|
|
|
PA_IDXSET_FOREACH(sink, core->sinks, idx) {
|
2017-08-30 21:51:15 +03:00
|
|
|
if (!PA_SINK_IS_LINKED(sink->state))
|
|
|
|
|
continue;
|
|
|
|
|
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
if (!best) {
|
|
|
|
|
best = sink;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (compare_sinks(sink, best) > 0)
|
|
|
|
|
best = sink;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
old_default_sink = core->default_sink;
|
|
|
|
|
|
|
|
|
|
if (best == old_default_sink)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
core->default_sink = best;
|
|
|
|
|
pa_log_info("default_sink: %s -> %s",
|
|
|
|
|
old_default_sink ? old_default_sink->name : "(unset)", best ? best->name : "(unset)");
|
|
|
|
|
|
|
|
|
|
/* If the default sink changed, it may be that the default source has to be
|
|
|
|
|
* changed too, because monitor sources are prioritized partly based on the
|
|
|
|
|
* priorities of the monitored sinks. */
|
|
|
|
|
pa_core_update_default_source(core);
|
|
|
|
|
|
|
|
|
|
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SERVER | PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
|
|
|
|
|
pa_hook_fire(&core->hooks[PA_CORE_HOOK_DEFAULT_SINK_CHANGED], core->default_sink);
|
2019-01-16 10:35:45 +08:00
|
|
|
|
|
|
|
|
/* try to move the streams from old_default_sink to the new default_sink conditionally */
|
|
|
|
|
if (old_default_sink)
|
2019-01-16 15:40:53 +08:00
|
|
|
pa_sink_move_streams_to_default_sink(core, old_default_sink, true);
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* a < b -> return -1
|
|
|
|
|
* a == b -> return 0
|
|
|
|
|
* a > b -> return 1 */
|
|
|
|
|
static int compare_sources(pa_source *a, pa_source *b) {
|
|
|
|
|
pa_core *core;
|
|
|
|
|
|
|
|
|
|
core = a->core;
|
|
|
|
|
|
2017-02-16 12:09:39 +02:00
|
|
|
/* Available sources always beat unavailable sources. */
|
|
|
|
|
if (a->active_port && a->active_port->available == PA_AVAILABLE_NO
|
|
|
|
|
&& (!b->active_port || b->active_port->available != PA_AVAILABLE_NO))
|
|
|
|
|
return -1;
|
|
|
|
|
if (b->active_port && b->active_port->available == PA_AVAILABLE_NO
|
|
|
|
|
&& (!a->active_port || a->active_port->available != PA_AVAILABLE_NO))
|
|
|
|
|
return 1;
|
|
|
|
|
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
/* The configured default source is preferred over any other source. */
|
2017-06-30 00:09:34 +03:00
|
|
|
if (pa_safe_streq(b->name, core->configured_default_source))
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
return -1;
|
2017-06-30 00:09:34 +03:00
|
|
|
if (pa_safe_streq(a->name, core->configured_default_source))
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
/* Monitor sources lose to non-monitor sources. */
|
|
|
|
|
if (a->monitor_of && !b->monitor_of)
|
|
|
|
|
return -1;
|
|
|
|
|
if (!a->monitor_of && b->monitor_of)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
if (a->priority < b->priority)
|
|
|
|
|
return -1;
|
|
|
|
|
if (a->priority > b->priority)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
/* If the sources are monitors, we can compare the monitored sinks. */
|
|
|
|
|
if (a->monitor_of)
|
|
|
|
|
return compare_sinks(a->monitor_of, b->monitor_of);
|
|
|
|
|
|
|
|
|
|
/* It's hard to find any difference between these sources, but maybe one of
|
|
|
|
|
* them is already the default source? If so, it's best to keep it as the
|
|
|
|
|
* default to avoid changing the routing for no good reason. */
|
|
|
|
|
if (b == core->default_source)
|
|
|
|
|
return -1;
|
|
|
|
|
if (a == core->default_source)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_core_update_default_source(pa_core *core) {
|
|
|
|
|
pa_source *best = NULL;
|
|
|
|
|
pa_source *source;
|
|
|
|
|
uint32_t idx;
|
|
|
|
|
pa_source *old_default_source;
|
|
|
|
|
|
|
|
|
|
pa_assert(core);
|
|
|
|
|
|
|
|
|
|
PA_IDXSET_FOREACH(source, core->sources, idx) {
|
2017-08-30 21:51:15 +03:00
|
|
|
if (!PA_SOURCE_IS_LINKED(source->state))
|
|
|
|
|
continue;
|
|
|
|
|
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
if (!best) {
|
|
|
|
|
best = source;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (compare_sources(source, best) > 0)
|
|
|
|
|
best = source;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
old_default_source = core->default_source;
|
|
|
|
|
|
|
|
|
|
if (best == old_default_source)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
core->default_source = best;
|
|
|
|
|
pa_log_info("default_source: %s -> %s",
|
|
|
|
|
old_default_source ? old_default_source->name : "(unset)", best ? best->name : "(unset)");
|
|
|
|
|
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SERVER | PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
|
|
|
|
|
pa_hook_fire(&core->hooks[PA_CORE_HOOK_DEFAULT_SOURCE_CHANGED], core->default_source);
|
2019-12-07 11:14:23 +08:00
|
|
|
|
|
|
|
|
/* try to move the streams from old_default_source to the new default_source conditionally */
|
|
|
|
|
if (old_default_source)
|
2019-12-10 16:26:34 +08:00
|
|
|
pa_source_move_streams_to_default_source(core, old_default_source, true);
|
improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.
I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.
This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.
pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().
I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-02-16 12:09:38 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-06 15:09:06 +02:00
|
|
|
void pa_core_set_exit_idle_time(pa_core *core, int time) {
|
|
|
|
|
pa_assert(core);
|
|
|
|
|
|
|
|
|
|
if (time == core->exit_idle_time)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
pa_log_info("exit_idle_time: %i -> %i", core->exit_idle_time, time);
|
|
|
|
|
core->exit_idle_time = time;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-05 02:13:43 +03:00
|
|
|
static void exit_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *t, void *userdata) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_core *c = userdata;
|
2008-08-06 19:39:12 +02:00
|
|
|
pa_assert(c->exit_event == e);
|
2004-09-04 00:27:36 +00:00
|
|
|
|
2008-09-05 03:17:48 +02:00
|
|
|
pa_log_info("We are idle, quitting...");
|
2013-06-27 19:28:09 +02:00
|
|
|
pa_core_exit(c, true, 0);
|
2004-09-04 00:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
2008-08-06 19:39:12 +02:00
|
|
|
void pa_core_check_idle(pa_core *c) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(c);
|
2004-09-04 00:27:36 +00:00
|
|
|
|
2008-08-06 19:39:12 +02:00
|
|
|
if (!c->exit_event &&
|
2008-06-11 16:55:43 +00:00
|
|
|
c->exit_idle_time >= 0 &&
|
|
|
|
|
pa_idxset_size(c->clients) == 0) {
|
|
|
|
|
|
2009-04-05 02:13:43 +03:00
|
|
|
c->exit_event = pa_core_rttime_new(c, pa_rtclock_now() + c->exit_idle_time * PA_USEC_PER_SEC, exit_callback, c);
|
2008-06-11 16:55:43 +00:00
|
|
|
|
2008-08-06 19:39:12 +02:00
|
|
|
} else if (c->exit_event && pa_idxset_size(c->clients) > 0) {
|
|
|
|
|
c->mainloop->time_free(c->exit_event);
|
|
|
|
|
c->exit_event = NULL;
|
2004-09-04 00:27:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-08-06 19:39:12 +02:00
|
|
|
|
2013-06-27 19:28:09 +02:00
|
|
|
int pa_core_exit(pa_core *c, bool force, int retval) {
|
2008-08-06 19:39:12 +02:00
|
|
|
pa_assert(c);
|
|
|
|
|
|
|
|
|
|
if (c->disallow_exit && !force)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
c->mainloop->quit(c->mainloop, retval);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2009-02-25 09:13:19 +01:00
|
|
|
|
|
|
|
|
void pa_core_maybe_vacuum(pa_core *c) {
|
|
|
|
|
pa_assert(c);
|
|
|
|
|
|
2011-09-08 15:12:00 +02:00
|
|
|
if (pa_idxset_isempty(c->sink_inputs) && pa_idxset_isempty(c->source_outputs)) {
|
|
|
|
|
pa_log_debug("Hmm, no streams around, trying to vacuum.");
|
|
|
|
|
} else {
|
|
|
|
|
pa_sink *si;
|
|
|
|
|
pa_source *so;
|
|
|
|
|
uint32_t idx;
|
|
|
|
|
|
|
|
|
|
idx = 0;
|
|
|
|
|
PA_IDXSET_FOREACH(si, c->sinks, idx)
|
2018-06-26 16:25:58 +03:00
|
|
|
if (si->state != PA_SINK_SUSPENDED)
|
2011-09-08 15:12:00 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
idx = 0;
|
|
|
|
|
PA_IDXSET_FOREACH(so, c->sources, idx)
|
2018-06-26 16:25:58 +03:00
|
|
|
if (so->state != PA_SOURCE_SUSPENDED)
|
2011-09-08 15:12:00 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
pa_log_info("All sinks and sources are suspended, vacuuming memory");
|
|
|
|
|
}
|
2014-04-25 14:20:57 +02:00
|
|
|
|
|
|
|
|
pa_mempool_vacuum(c->mempool);
|
2009-02-25 09:13:19 +01:00
|
|
|
}
|
2009-04-05 02:13:43 +03:00
|
|
|
|
|
|
|
|
pa_time_event* pa_core_rttime_new(pa_core *c, pa_usec_t usec, pa_time_event_cb_t cb, void *userdata) {
|
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
|
|
pa_assert(c);
|
|
|
|
|
pa_assert(c->mainloop);
|
|
|
|
|
|
2013-06-27 19:28:09 +02:00
|
|
|
return c->mainloop->time_new(c->mainloop, pa_timeval_rtstore(&tv, usec, true), cb, userdata);
|
2009-04-05 02:13:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_core_rttime_restart(pa_core *c, pa_time_event *e, pa_usec_t usec) {
|
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
|
|
pa_assert(c);
|
|
|
|
|
pa_assert(c->mainloop);
|
|
|
|
|
|
2013-06-27 19:28:09 +02:00
|
|
|
c->mainloop->time_restart(e, pa_timeval_rtstore(&tv, usec, true));
|
2009-04-05 02:13:43 +03:00
|
|
|
}
|
2017-12-28 12:09:19 +02:00
|
|
|
|
2019-01-16 12:10:38 +08:00
|
|
|
void pa_core_move_streams_to_newly_available_preferred_sink(pa_core *c, pa_sink *s) {
|
|
|
|
|
pa_sink_input *si;
|
|
|
|
|
uint32_t idx;
|
|
|
|
|
|
|
|
|
|
pa_assert(c);
|
|
|
|
|
pa_assert(s);
|
|
|
|
|
|
|
|
|
|
PA_IDXSET_FOREACH(si, c->sink_inputs, idx) {
|
|
|
|
|
if (si->sink == s)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!si->sink)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* Skip this sink input if it is connecting a filter sink to
|
|
|
|
|
* the master */
|
|
|
|
|
if (si->origin_sink)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* It might happen that a stream and a sink are set up at the
|
|
|
|
|
same time, in which case we want to make sure we don't
|
|
|
|
|
interfere with that */
|
|
|
|
|
if (!PA_SINK_INPUT_IS_LINKED(si->state))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (pa_safe_streq(si->preferred_sink, s->name))
|
|
|
|
|
pa_sink_input_move_to(si, s, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-07 11:36:25 +08:00
|
|
|
void pa_core_move_streams_to_newly_available_preferred_source(pa_core *c, pa_source *s) {
|
|
|
|
|
pa_source_output *so;
|
|
|
|
|
uint32_t idx;
|
|
|
|
|
|
|
|
|
|
pa_assert(c);
|
|
|
|
|
pa_assert(s);
|
|
|
|
|
|
|
|
|
|
PA_IDXSET_FOREACH(so, c->source_outputs, idx) {
|
|
|
|
|
if (so->source == s)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (so->direct_on_input)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!so->source)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* Skip this source output if it is connecting a filter source to
|
|
|
|
|
* the master */
|
|
|
|
|
if (so->destination_source)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* It might happen that a stream and a source are set up at the
|
|
|
|
|
same time, in which case we want to make sure we don't
|
|
|
|
|
interfere with that */
|
|
|
|
|
if (!PA_SOURCE_OUTPUT_IS_LINKED(so->state))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (pa_safe_streq(so->preferred_source, s->name))
|
|
|
|
|
pa_source_output_move_to(so, s, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-12-28 12:09:19 +02:00
|
|
|
/* Helper macro to reduce repetition in pa_suspend_cause_to_string().
|
|
|
|
|
* Parameters:
|
|
|
|
|
* char *p: the current position in the write buffer
|
|
|
|
|
* bool first: is cause_to_check the first cause to be written?
|
|
|
|
|
* pa_suspend_cause_t cause_bitfield: the causes given to pa_suspend_cause_to_string()
|
|
|
|
|
* pa_suspend_cause_t cause_to_check: the cause whose presence in cause_bitfield is to be checked
|
|
|
|
|
*/
|
|
|
|
|
#define CHECK_CAUSE(p, first, cause_bitfield, cause_to_check) \
|
|
|
|
|
if (cause_bitfield & PA_SUSPEND_##cause_to_check) { \
|
|
|
|
|
size_t len = sizeof(#cause_to_check) - 1; \
|
|
|
|
|
if (!first) { \
|
|
|
|
|
*p = '|'; \
|
|
|
|
|
p++; \
|
|
|
|
|
} \
|
|
|
|
|
first = false; \
|
|
|
|
|
memcpy(p, #cause_to_check, len); \
|
|
|
|
|
p += len; \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *pa_suspend_cause_to_string(pa_suspend_cause_t cause_bitfield, char buf[PA_SUSPEND_CAUSE_TO_STRING_BUF_SIZE]) {
|
|
|
|
|
char *p = buf;
|
|
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
|
|
CHECK_CAUSE(p, first, cause_bitfield, USER);
|
|
|
|
|
CHECK_CAUSE(p, first, cause_bitfield, APPLICATION);
|
|
|
|
|
CHECK_CAUSE(p, first, cause_bitfield, IDLE);
|
|
|
|
|
CHECK_CAUSE(p, first, cause_bitfield, SESSION);
|
|
|
|
|
CHECK_CAUSE(p, first, cause_bitfield, PASSTHROUGH);
|
|
|
|
|
CHECK_CAUSE(p, first, cause_bitfield, INTERNAL);
|
|
|
|
|
CHECK_CAUSE(p, first, cause_bitfield, UNAVAILABLE);
|
|
|
|
|
|
|
|
|
|
if (p == buf) {
|
|
|
|
|
memcpy(p, "(none)", 6);
|
|
|
|
|
p += 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|