4 This file is part of PulseAudio.
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 #include <pulse/timeval.h>
32 #include <pulse/xmalloc.h>
34 #include <pulsecore/module.h>
35 #include <pulsecore/sink.h>
36 #include <pulsecore/source.h>
37 #include <pulsecore/namereg.h>
38 #include <pulsecore/core-util.h>
39 #include <pulsecore/core-scache.h>
40 #include <pulsecore/autoload.h>
41 #include <pulsecore/core-subscribe.h>
42 #include <pulsecore/props.h>
43 #include <pulsecore/random.h>
47 pa_core
* pa_core_new(pa_mainloop_api
*m
) {
50 c
= pa_xnew(pa_core
, 1);
53 c
->clients
= pa_idxset_new(NULL
, NULL
);
54 c
->sinks
= pa_idxset_new(NULL
, NULL
);
55 c
->sources
= pa_idxset_new(NULL
, NULL
);
56 c
->source_outputs
= pa_idxset_new(NULL
, NULL
);
57 c
->sink_inputs
= pa_idxset_new(NULL
, NULL
);
59 c
->default_source_name
= c
->default_sink_name
= NULL
;
64 c
->autoload_idxset
= NULL
;
65 c
->autoload_hashmap
= NULL
;
66 c
->running_as_daemon
= 0;
68 c
->default_sample_spec
.format
= PA_SAMPLE_S16NE
;
69 c
->default_sample_spec
.rate
= 44100;
70 c
->default_sample_spec
.channels
= 2;
72 c
->module_auto_unload_event
= NULL
;
73 c
->module_defer_unload_event
= NULL
;
74 c
->scache_auto_unload_event
= NULL
;
76 c
->subscription_defer_event
= NULL
;
77 PA_LLIST_HEAD_INIT(pa_subscription
, c
->subscriptions
);
78 PA_LLIST_HEAD_INIT(pa_subscription_event
, c
->subscription_event_queue
);
79 c
->subscription_event_last
= NULL
;
81 c
->memblock_stat
= pa_memblock_stat_new();
83 c
->disallow_module_loading
= 0;
87 c
->exit_idle_time
= -1;
88 c
->module_idle_time
= 20;
89 c
->scache_idle_time
= 20;
91 c
->resample_method
= PA_RESAMPLER_SRC_SINC_FASTEST
;
93 c
->is_system_instance
= 0;
95 pa_hook_init(&c
->hook_sink_input_new
, c
);
96 pa_hook_init(&c
->hook_sink_disconnect
, c
);
100 pa_random(&c
->cookie
, sizeof(c
->cookie
));
103 pa_check_signal_is_blocked(SIGPIPE
);
108 void pa_core_free(pa_core
*c
) {
111 pa_module_unload_all(c
);
114 assert(pa_idxset_isempty(c
->clients
));
115 pa_idxset_free(c
->clients
, NULL
, NULL
);
117 assert(pa_idxset_isempty(c
->sinks
));
118 pa_idxset_free(c
->sinks
, NULL
, NULL
);
120 assert(pa_idxset_isempty(c
->sources
));
121 pa_idxset_free(c
->sources
, NULL
, NULL
);
123 assert(pa_idxset_isempty(c
->source_outputs
));
124 pa_idxset_free(c
->source_outputs
, NULL
, NULL
);
126 assert(pa_idxset_isempty(c
->sink_inputs
));
127 pa_idxset_free(c
->sink_inputs
, NULL
, NULL
);
132 pa_subscription_free_all(c
);
135 c
->mainloop
->time_free(c
->quit_event
);
137 pa_xfree(c
->default_source_name
);
138 pa_xfree(c
->default_sink_name
);
140 pa_memblock_stat_unref(c
->memblock_stat
);
142 pa_property_cleanup(c
);
144 pa_hook_free(&c
->hook_sink_input_new
);
145 pa_hook_free(&c
->hook_sink_disconnect
);
150 static void quit_callback(pa_mainloop_api
*m
, pa_time_event
*e
, PA_GCC_UNUSED
const struct timeval
*tv
, void *userdata
) {
151 pa_core
*c
= userdata
;
152 assert(c
->quit_event
= e
);
157 void pa_core_check_quit(pa_core
*c
) {
160 if (!c
->quit_event
&& c
->exit_idle_time
>= 0 && pa_idxset_size(c
->clients
) == 0) {
162 pa_gettimeofday(&tv
);
163 tv
.tv_sec
+= c
->exit_idle_time
;
164 c
->quit_event
= c
->mainloop
->time_new(c
->mainloop
, &tv
, quit_callback
, c
);
165 } else if (c
->quit_event
&& pa_idxset_size(c
->clients
) > 0) {
166 c
->mainloop
->time_free(c
->quit_event
);
167 c
->quit_event
= NULL
;