]> code.delx.au - pulseaudio/blob - src/pulsecore/core.h
762157efac6d857aa768892f070ff1416f4d73dd
[pulseaudio] / src / pulsecore / core.h
1 #ifndef foocorehfoo
2 #define foocorehfoo
3
4 /***
5 This file is part of PulseAudio.
6
7 Copyright 2004-2006 Lennart Poettering
8
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2.1 of the License,
12 or (at your option) any later version.
13
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA.
23 ***/
24
25 #include <pulse/mainloop-api.h>
26 #include <pulse/sample.h>
27 #include <pulsecore/cpu.h>
28
29 typedef struct pa_core pa_core;
30
31 /* This is a bitmask that encodes the cause why a sink/source is
32 * suspended. */
33 typedef enum pa_suspend_cause {
34 PA_SUSPEND_USER = 1, /* Exposed to the user via some protocol */
35 PA_SUSPEND_APPLICATION = 2, /* Used by the device reservation logic */
36 PA_SUSPEND_IDLE = 4, /* Used by module-suspend-on-idle */
37 PA_SUSPEND_SESSION = 8, /* Used by module-hal for mark inactive sessions */
38 PA_SUSPEND_PASSTHROUGH = 16, /* Used to suspend monitor sources when the sink is in passthrough mode */
39 PA_SUSPEND_INTERNAL = 32, /* This is used for short period server-internal suspends, such as for sample rate updates */
40 PA_SUSPEND_ALL = 0xFFFF /* Magic cause that can be used to resume forcibly */
41 } pa_suspend_cause_t;
42
43 #include <pulsecore/idxset.h>
44 #include <pulsecore/hashmap.h>
45 #include <pulsecore/memblock.h>
46 #include <pulsecore/resampler.h>
47 #include <pulsecore/llist.h>
48 #include <pulsecore/hook-list.h>
49 #include <pulsecore/asyncmsgq.h>
50 #include <pulsecore/sample-util.h>
51 #include <pulsecore/sink.h>
52 #include <pulsecore/source.h>
53 #include <pulsecore/core-subscribe.h>
54 #include <pulsecore/msgobject.h>
55
56 typedef enum pa_server_type {
57 PA_SERVER_TYPE_UNSET,
58 PA_SERVER_TYPE_USER,
59 PA_SERVER_TYPE_SYSTEM,
60 PA_SERVER_TYPE_NONE
61 } pa_server_type_t;
62
63 typedef enum pa_core_state {
64 PA_CORE_STARTUP,
65 PA_CORE_RUNNING,
66 PA_CORE_SHUTDOWN
67 } pa_core_state_t;
68
69 typedef enum pa_core_hook {
70 PA_CORE_HOOK_SINK_NEW,
71 PA_CORE_HOOK_SINK_FIXATE,
72 PA_CORE_HOOK_SINK_PUT,
73 PA_CORE_HOOK_SINK_UNLINK,
74 PA_CORE_HOOK_SINK_UNLINK_POST,
75 PA_CORE_HOOK_SINK_STATE_CHANGED,
76 PA_CORE_HOOK_SINK_PROPLIST_CHANGED,
77 PA_CORE_HOOK_SINK_PORT_CHANGED,
78 PA_CORE_HOOK_SINK_FLAGS_CHANGED,
79 PA_CORE_HOOK_SINK_VOLUME_CHANGED,
80 PA_CORE_HOOK_SINK_MUTE_CHANGED,
81 PA_CORE_HOOK_SOURCE_NEW,
82 PA_CORE_HOOK_SOURCE_FIXATE,
83 PA_CORE_HOOK_SOURCE_PUT,
84 PA_CORE_HOOK_SOURCE_UNLINK,
85 PA_CORE_HOOK_SOURCE_UNLINK_POST,
86 PA_CORE_HOOK_SOURCE_STATE_CHANGED,
87 PA_CORE_HOOK_SOURCE_PROPLIST_CHANGED,
88 PA_CORE_HOOK_SOURCE_PORT_CHANGED,
89 PA_CORE_HOOK_SOURCE_FLAGS_CHANGED,
90 PA_CORE_HOOK_SOURCE_VOLUME_CHANGED,
91 PA_CORE_HOOK_SOURCE_MUTE_CHANGED,
92 PA_CORE_HOOK_SINK_INPUT_NEW,
93 PA_CORE_HOOK_SINK_INPUT_FIXATE,
94 PA_CORE_HOOK_SINK_INPUT_PUT,
95 PA_CORE_HOOK_SINK_INPUT_UNLINK,
96 PA_CORE_HOOK_SINK_INPUT_UNLINK_POST,
97 PA_CORE_HOOK_SINK_INPUT_MOVE_START,
98 PA_CORE_HOOK_SINK_INPUT_MOVE_FINISH,
99 PA_CORE_HOOK_SINK_INPUT_MOVE_FAIL,
100 PA_CORE_HOOK_SINK_INPUT_STATE_CHANGED,
101 PA_CORE_HOOK_SINK_INPUT_PROPLIST_CHANGED,
102 PA_CORE_HOOK_SINK_INPUT_VOLUME_CHANGED,
103 PA_CORE_HOOK_SINK_INPUT_SEND_EVENT,
104 PA_CORE_HOOK_SOURCE_OUTPUT_NEW,
105 PA_CORE_HOOK_SOURCE_OUTPUT_FIXATE,
106 PA_CORE_HOOK_SOURCE_OUTPUT_PUT,
107 PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK,
108 PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK_POST,
109 PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_START,
110 PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FINISH,
111 PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FAIL,
112 PA_CORE_HOOK_SOURCE_OUTPUT_STATE_CHANGED,
113 PA_CORE_HOOK_SOURCE_OUTPUT_PROPLIST_CHANGED,
114 PA_CORE_HOOK_SOURCE_OUTPUT_VOLUME_CHANGED,
115 PA_CORE_HOOK_SOURCE_OUTPUT_SEND_EVENT,
116 PA_CORE_HOOK_CLIENT_NEW,
117 PA_CORE_HOOK_CLIENT_PUT,
118 PA_CORE_HOOK_CLIENT_UNLINK,
119 PA_CORE_HOOK_CLIENT_PROPLIST_CHANGED,
120 PA_CORE_HOOK_CLIENT_SEND_EVENT,
121 PA_CORE_HOOK_CARD_NEW,
122 PA_CORE_HOOK_CARD_PUT,
123 PA_CORE_HOOK_CARD_UNLINK,
124 PA_CORE_HOOK_CARD_PROFILE_CHANGED,
125 PA_CORE_HOOK_CARD_PROFILE_ADDED,
126 PA_CORE_HOOK_CARD_PROFILE_AVAILABLE_CHANGED,
127 PA_CORE_HOOK_PORT_AVAILABLE_CHANGED,
128 PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED,
129 PA_CORE_HOOK_MAX
130 } pa_core_hook_t;
131
132 /* The core structure of PulseAudio. Every PulseAudio daemon contains
133 * exactly one of these. It is used for storing kind of global
134 * variables for the daemon. */
135
136 struct pa_core {
137 pa_msgobject parent;
138
139 pa_core_state_t state;
140
141 /* A random value which may be used to identify this instance of
142 * PulseAudio. Not cryptographically secure in any way. */
143 uint32_t cookie;
144
145 pa_mainloop_api *mainloop;
146
147 /* idxset of all kinds of entities */
148 pa_idxset *clients, *cards, *sinks, *sources, *sink_inputs, *source_outputs, *modules, *scache;
149
150 /* Some hashmaps for all sorts of entities */
151 pa_hashmap *namereg, *shared;
152
153 /* The default sink/source */
154 pa_source *default_source;
155 pa_sink *default_sink;
156
157 pa_channel_map default_channel_map;
158 pa_sample_spec default_sample_spec;
159 uint32_t alternate_sample_rate;
160 unsigned default_n_fragments, default_fragment_size_msec;
161 unsigned deferred_volume_safety_margin_usec;
162 int deferred_volume_extra_delay_usec;
163
164 pa_defer_event *module_defer_unload_event;
165
166 pa_defer_event *subscription_defer_event;
167 PA_LLIST_HEAD(pa_subscription, subscriptions);
168 PA_LLIST_HEAD(pa_subscription_event, subscription_event_queue);
169 pa_subscription_event *subscription_event_last;
170
171 pa_mempool *mempool;
172 pa_silence_cache silence_cache;
173
174 pa_time_event *exit_event;
175 pa_time_event *scache_auto_unload_event;
176
177 int exit_idle_time, scache_idle_time;
178
179 bool flat_volumes:1;
180 bool disallow_module_loading:1;
181 bool disallow_exit:1;
182 bool running_as_daemon:1;
183 bool realtime_scheduling:1;
184 bool disable_remixing:1;
185 bool disable_lfe_remixing:1;
186 bool deferred_volume:1;
187
188 pa_resample_method_t resample_method;
189 int realtime_priority;
190
191 pa_server_type_t server_type;
192 pa_cpu_info cpu_info;
193
194 /* hooks */
195 pa_hook hooks[PA_CORE_HOOK_MAX];
196 };
197
198 PA_DECLARE_PUBLIC_CLASS(pa_core);
199 #define PA_CORE(o) pa_core_cast(o)
200
201 enum {
202 PA_CORE_MESSAGE_UNLOAD_MODULE,
203 PA_CORE_MESSAGE_MAX
204 };
205
206 pa_core* pa_core_new(pa_mainloop_api *m, bool shared, size_t shm_size);
207
208 /* Check whether no one is connected to this core */
209 void pa_core_check_idle(pa_core *c);
210
211 int pa_core_exit(pa_core *c, bool force, int retval);
212
213 void pa_core_maybe_vacuum(pa_core *c);
214
215 /* wrapper for c->mainloop->time_*() RT time events */
216 pa_time_event* pa_core_rttime_new(pa_core *c, pa_usec_t usec, pa_time_event_cb_t cb, void *userdata);
217 void pa_core_rttime_restart(pa_core *c, pa_time_event *e, pa_usec_t usec);
218
219 #endif