2004-07-16 19:56:36 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
/***
|
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
|
2004-07-16 19:56:36 +00:00
|
|
|
by the Free Software Foundation; either version 2 of the License,
|
|
|
|
|
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
|
2006-06-19 21:53:48 +00:00
|
|
|
along with PulseAudio; if not, write to the Free Software
|
2004-07-16 19:56:36 +00:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
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
|
|
|
|
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>
|
|
|
|
|
#include <pulsecore/sink.h>
|
|
|
|
|
#include <pulsecore/source.h>
|
|
|
|
|
#include <pulsecore/namereg.h>
|
|
|
|
|
#include <pulsecore/core-util.h>
|
|
|
|
|
#include <pulsecore/core-scache.h>
|
|
|
|
|
#include <pulsecore/autoload.h>
|
|
|
|
|
#include <pulsecore/core-subscribe.h>
|
|
|
|
|
#include <pulsecore/props.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>
|
2006-02-17 12:10:58 +00:00
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
#include "core.h"
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
static PA_DEFINE_CHECK_TYPE(pa_core, pa_msgobject);
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
pa_module_unload(c, userdata);
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void core_free(pa_object *o);
|
|
|
|
|
|
2006-08-18 19:55:18 +00:00
|
|
|
pa_core* pa_core_new(pa_mainloop_api *m, int shared) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_core* c;
|
2006-08-19 01:15:48 +00:00
|
|
|
pa_mempool *pool;
|
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) {
|
|
|
|
|
if (!(pool = pa_mempool_new(shared))) {
|
|
|
|
|
pa_log_warn("failed to allocate shared memory pool. Falling back to a normal memory pool.");
|
|
|
|
|
shared = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!shared) {
|
|
|
|
|
if (!(pool = pa_mempool_new(shared))) {
|
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
|
|
|
|
|
|
|
|
c->mainloop = m;
|
2004-07-03 23:35:12 +00:00
|
|
|
c->clients = pa_idxset_new(NULL, NULL);
|
|
|
|
|
c->sinks = pa_idxset_new(NULL, NULL);
|
|
|
|
|
c->sources = pa_idxset_new(NULL, NULL);
|
|
|
|
|
c->source_outputs = pa_idxset_new(NULL, NULL);
|
|
|
|
|
c->sink_inputs = pa_idxset_new(NULL, NULL);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-08-04 16:39:30 +00:00
|
|
|
c->default_source_name = c->default_sink_name = NULL;
|
2004-06-08 23:54:24 +00:00
|
|
|
|
|
|
|
|
c->modules = NULL;
|
2004-06-27 22:42:17 +00:00
|
|
|
c->namereg = NULL;
|
2004-08-19 23:14:59 +00:00
|
|
|
c->scache = NULL;
|
2004-10-27 16:23:23 +00:00
|
|
|
c->autoload_idxset = NULL;
|
2004-08-04 16:39:30 +00:00
|
|
|
c->autoload_hashmap = NULL;
|
2005-09-16 00:09:19 +00:00
|
|
|
c->running_as_daemon = 0;
|
2004-08-04 16:39:30 +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;
|
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
|
|
|
|
2004-09-14 23:08:39 +00:00
|
|
|
c->module_auto_unload_event = NULL;
|
|
|
|
|
c->module_defer_unload_event = NULL;
|
|
|
|
|
c->scache_auto_unload_event = 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;
|
2004-09-03 22:44:55 +00:00
|
|
|
|
2004-09-04 00:27:36 +00:00
|
|
|
c->quit_event = NULL;
|
2004-09-13 23:28:30 +00:00
|
|
|
|
|
|
|
|
c->exit_idle_time = -1;
|
|
|
|
|
c->module_idle_time = 20;
|
2004-09-14 23:08:39 +00:00
|
|
|
c->scache_idle_time = 20;
|
2004-09-17 19:45:44 +00:00
|
|
|
|
2007-10-29 08:34:30 +00:00
|
|
|
c->resample_method = PA_RESAMPLER_SPEEX_FLOAT_BASE + 3;
|
2004-10-30 01:55:16 +00:00
|
|
|
|
2006-07-19 17:44:19 +00:00
|
|
|
c->is_system_instance = 0;
|
2007-10-28 19:13:50 +00:00
|
|
|
c->disallow_module_loading = 0;
|
|
|
|
|
c->high_priority = 0;
|
|
|
|
|
|
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-10-30 01:55:16 +00:00
|
|
|
pa_property_init(c);
|
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
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_module_unload_all(c);
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(!c->modules);
|
2004-08-04 16:39:30 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(pa_idxset_isempty(c->clients));
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_idxset_free(c->clients, NULL, NULL);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(pa_idxset_isempty(c->sinks));
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_idxset_free(c->sinks, NULL, NULL);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(pa_idxset_isempty(c->sources));
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_idxset_free(c->sources, NULL, 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));
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_idxset_free(c->source_outputs, NULL, 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));
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_idxset_free(c->sink_inputs, NULL, NULL);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-07-20 01:07:06 +00:00
|
|
|
pa_scache_free(c);
|
2004-08-19 23:14:59 +00:00
|
|
|
pa_namereg_free(c);
|
2004-08-04 16:39:30 +00:00
|
|
|
pa_autoload_free(c);
|
2004-08-11 00:11:12 +00:00
|
|
|
pa_subscription_free_all(c);
|
2004-09-04 00:27:36 +00:00
|
|
|
|
2004-09-14 23:08:39 +00:00
|
|
|
if (c->quit_event)
|
2004-09-04 00:27:36 +00:00
|
|
|
c->mainloop->time_free(c->quit_event);
|
2004-09-14 23:08:39 +00:00
|
|
|
|
2004-08-04 16:39:30 +00:00
|
|
|
pa_xfree(c->default_source_name);
|
|
|
|
|
pa_xfree(c->default_sink_name);
|
2004-08-17 19:37:29 +00:00
|
|
|
|
2006-08-18 19:55:18 +00:00
|
|
|
pa_mempool_free(c->mempool);
|
2004-10-30 01:55:16 +00:00
|
|
|
|
|
|
|
|
pa_property_cleanup(c);
|
2006-08-13 16:19:56 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
for (j = 0; j < PA_CORE_HOOK_MAX; j++)
|
|
|
|
|
pa_hook_free(&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
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
static void quit_callback(pa_mainloop_api*m, pa_time_event *e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) {
|
|
|
|
|
pa_core *c = userdata;
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(c->quit_event == e);
|
2004-09-04 00:27:36 +00:00
|
|
|
|
|
|
|
|
m->quit(m, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_core_check_quit(pa_core *c) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(c);
|
2004-09-04 00:27:36 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
if (!c->quit_event && c->exit_idle_time >= 0 && pa_idxset_size(c->clients) == 0) {
|
2004-09-04 00:27:36 +00:00
|
|
|
struct timeval tv;
|
2006-01-10 17:51:06 +00:00
|
|
|
pa_gettimeofday(&tv);
|
2004-09-13 23:28:30 +00:00
|
|
|
tv.tv_sec+= c->exit_idle_time;
|
2004-09-04 00:27:36 +00:00
|
|
|
c->quit_event = c->mainloop->time_new(c->mainloop, &tv, quit_callback, c);
|
2006-01-11 01:17:39 +00:00
|
|
|
} else if (c->quit_event && pa_idxset_size(c->clients) > 0) {
|
2004-09-04 00:27:36 +00:00
|
|
|
c->mainloop->time_free(c->quit_event);
|
|
|
|
|
c->quit_event = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-09-07 14:58:42 +00:00
|
|
|
|