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 <assert.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-06-11 12:08:37 +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-06-11 12:08:37 +00:00
|
|
|
static int core_process_msg(pa_msgobject *o, int code, void *userdata, 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 asyncmsgq_cb(pa_mainloop_api*api, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata) {
|
|
|
|
|
pa_core *c = userdata;
|
|
|
|
|
|
|
|
|
|
pa_assert(pa_asyncmsgq_get_fd(c->asyncmsgq) == fd);
|
|
|
|
|
pa_assert(events == PA_IO_EVENT_INPUT);
|
|
|
|
|
|
|
|
|
|
pa_asyncmsgq_after_poll(c->asyncmsgq);
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
pa_msgobject *object;
|
|
|
|
|
int code;
|
|
|
|
|
void *data;
|
|
|
|
|
pa_memchunk chunk;
|
|
|
|
|
|
|
|
|
|
/* Check whether there is a message for us to process */
|
|
|
|
|
while (pa_asyncmsgq_get(c->asyncmsgq, &object, &code, &data, &chunk, 0) == 0) {
|
|
|
|
|
pa_asyncmsgq_dispatch(object, code, data, &chunk);
|
|
|
|
|
pa_asyncmsgq_done(c->asyncmsgq, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pa_asyncmsgq_before_poll(c->asyncmsgq) == 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-06-11 12:08:37 +00:00
|
|
|
pa_assert(m);
|
|
|
|
|
|
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-06-11 12:08:37 +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;
|
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
|
|
|
|
|
|
|
|
c->disallow_module_loading = 0;
|
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
|
|
|
|
2004-11-20 16:23:53 +00:00
|
|
|
c->resample_method = PA_RESAMPLER_SRC_SINC_FASTEST;
|
2004-10-30 01:55:16 +00:00
|
|
|
|
2006-07-19 17:44:19 +00:00
|
|
|
c->is_system_instance = 0;
|
|
|
|
|
|
2006-08-13 16:19:56 +00:00
|
|
|
pa_hook_init(&c->hook_sink_input_new, c);
|
2006-08-13 17:33:32 +00:00
|
|
|
pa_hook_init(&c->hook_sink_disconnect, c);
|
2006-08-13 19:52:43 +00:00
|
|
|
pa_hook_init(&c->hook_source_output_new, c);
|
|
|
|
|
pa_hook_init(&c->hook_source_disconnect, 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-06-11 12:08:37 +00:00
|
|
|
|
|
|
|
|
pa_assert_se(c->asyncmsgq = pa_asyncmsgq_new(0));
|
|
|
|
|
pa_assert_se(pa_asyncmsgq_before_poll(c->asyncmsgq) == 0);
|
|
|
|
|
pa_assert_se(c->asyncmsgq_event = c->mainloop->io_new(c->mainloop, pa_asyncmsgq_get_fd(c->asyncmsgq), PA_IO_EVENT_INPUT, asyncmsgq_cb, c));
|
|
|
|
|
|
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-06-11 12:08:37 +00:00
|
|
|
static void core_free(pa_object *o) {
|
|
|
|
|
pa_core *c = PA_CORE(o);
|
|
|
|
|
pa_core_assert_ref(c);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_module_unload_all(c);
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(!c->modules);
|
2004-08-04 16:39:30 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
assert(pa_idxset_isempty(c->clients));
|
|
|
|
|
pa_idxset_free(c->clients, NULL, NULL);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
assert(pa_idxset_isempty(c->sinks));
|
|
|
|
|
pa_idxset_free(c->sinks, NULL, NULL);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
assert(pa_idxset_isempty(c->sources));
|
|
|
|
|
pa_idxset_free(c->sources, NULL, NULL);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
assert(pa_idxset_isempty(c->source_outputs));
|
|
|
|
|
pa_idxset_free(c->source_outputs, NULL, NULL);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
assert(pa_idxset_isempty(c->sink_inputs));
|
|
|
|
|
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-06-11 12:08:37 +00:00
|
|
|
c->mainloop->io_free(c->asyncmsgq_event);
|
|
|
|
|
pa_asyncmsgq_after_poll(c->asyncmsgq);
|
|
|
|
|
pa_asyncmsgq_free(c->asyncmsgq);
|
|
|
|
|
|
2006-08-13 16:19:56 +00:00
|
|
|
pa_hook_free(&c->hook_sink_input_new);
|
2006-08-13 17:33:32 +00:00
|
|
|
pa_hook_free(&c->hook_sink_disconnect);
|
2006-08-13 19:52:43 +00:00
|
|
|
pa_hook_free(&c->hook_source_output_new);
|
|
|
|
|
pa_hook_free(&c->hook_source_disconnect);
|
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;
|
2004-09-04 00:27:36 +00:00
|
|
|
assert(c->quit_event = e);
|
|
|
|
|
|
|
|
|
|
m->quit(m, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_core_check_quit(pa_core *c) {
|
2004-09-04 00:27:36 +00:00
|
|
|
assert(c);
|
|
|
|
|
|
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
|
|
|
|