]> code.delx.au - pulseaudio/blob - src/pulse/internal.h
dbus: remove filter functions only if they were actually set before
[pulseaudio] / src / pulse / internal.h
1 #ifndef foointernalhfoo
2 #define foointernalhfoo
3
4 /***
5 This file is part of PulseAudio.
6
7 Copyright 2004-2006 Lennart Poettering
8 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9
10 PulseAudio is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published
12 by the Free Software Foundation; either version 2.1 of the License,
13 or (at your option) any later version.
14
15 PulseAudio is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with PulseAudio; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 USA.
24 ***/
25
26 #include <pulse/mainloop-api.h>
27 #include <pulse/context.h>
28 #include <pulse/stream.h>
29 #include <pulse/operation.h>
30 #include <pulse/subscribe.h>
31 #include <pulse/ext-device-manager.h>
32 #include <pulse/ext-stream-restore.h>
33
34 #include <pulsecore/socket-client.h>
35 #include <pulsecore/pstream.h>
36 #include <pulsecore/pdispatch.h>
37 #include <pulsecore/llist.h>
38 #include <pulsecore/native-common.h>
39 #include <pulsecore/strlist.h>
40 #include <pulsecore/mcalign.h>
41 #include <pulsecore/memblockq.h>
42 #include <pulsecore/hashmap.h>
43 #include <pulsecore/refcnt.h>
44 #include <pulsecore/time-smoother.h>
45 #ifdef HAVE_DBUS
46 #include <pulsecore/dbus-util.h>
47 #endif
48
49 #include "client-conf.h"
50
51 #define DEFAULT_TIMEOUT (30)
52
53 struct pa_context {
54 PA_REFCNT_DECLARE;
55
56 #ifdef HAVE_DBUS
57 pa_dbus_wrap_connection *system_bus;
58 pa_dbus_wrap_connection *session_bus;
59 #endif
60
61 pa_proplist *proplist;
62 pa_mainloop_api* mainloop;
63
64 pa_socket_client *client;
65 pa_pstream *pstream;
66 pa_pdispatch *pdispatch;
67
68 pa_hashmap *record_streams, *playback_streams;
69 PA_LLIST_HEAD(pa_stream, streams);
70 PA_LLIST_HEAD(pa_operation, operations);
71
72 uint32_t version;
73 uint32_t ctag;
74 uint32_t csyncid;
75 int error;
76 pa_context_state_t state;
77
78 pa_context_notify_cb_t state_callback;
79 void *state_userdata;
80 pa_context_subscribe_cb_t subscribe_callback;
81 void *subscribe_userdata;
82 pa_context_event_cb_t event_callback;
83 void *event_userdata;
84
85 pa_mempool *mempool;
86
87 pa_bool_t is_local:1;
88 pa_bool_t do_shm:1;
89 pa_bool_t server_specified:1;
90 pa_bool_t no_fail:1;
91 pa_bool_t do_autospawn:1;
92 pa_bool_t use_rtclock:1;
93 pa_bool_t filter_added:1;
94 pa_spawn_api spawn_api;
95
96 pa_strlist *server_list;
97
98 char *server;
99
100 pa_client_conf *conf;
101
102 uint32_t client_index;
103
104 /* Extension specific data */
105 struct {
106 pa_ext_device_manager_subscribe_cb_t callback;
107 void *userdata;
108 } ext_device_manager;
109 struct {
110 pa_ext_stream_restore_subscribe_cb_t callback;
111 void *userdata;
112 } ext_stream_restore;
113 };
114
115 #define PA_MAX_WRITE_INDEX_CORRECTIONS 32
116
117 typedef struct pa_index_correction {
118 uint32_t tag;
119 int64_t value;
120 pa_bool_t valid:1;
121 pa_bool_t absolute:1;
122 pa_bool_t corrupt:1;
123 } pa_index_correction;
124
125 struct pa_stream {
126 PA_REFCNT_DECLARE;
127 PA_LLIST_FIELDS(pa_stream);
128
129 pa_context *context;
130 pa_mainloop_api *mainloop;
131
132 uint32_t direct_on_input;
133
134 pa_stream_direction_t direction;
135 pa_stream_state_t state;
136 pa_stream_flags_t flags;
137
138 pa_sample_spec sample_spec;
139 pa_channel_map channel_map;
140
141 pa_proplist *proplist;
142
143 pa_bool_t channel_valid:1;
144 pa_bool_t suspended:1;
145 pa_bool_t corked:1;
146 pa_bool_t timing_info_valid:1;
147 pa_bool_t auto_timing_update_requested:1;
148
149 uint32_t channel;
150 uint32_t syncid;
151 uint32_t stream_index;
152
153 int64_t requested_bytes;
154 pa_buffer_attr buffer_attr;
155
156 uint32_t device_index;
157 char *device_name;
158
159 /* playback */
160 pa_memblock *write_memblock;
161 void *write_data;
162
163 /* recording */
164 pa_memchunk peek_memchunk;
165 void *peek_data;
166 pa_memblockq *record_memblockq;
167
168 /* Store latest latency info */
169 pa_timing_info timing_info;
170
171 /* Use to make sure that time advances monotonically */
172 pa_usec_t previous_time;
173
174 /* time updates with tags older than these are invalid */
175 uint32_t write_index_not_before;
176 uint32_t read_index_not_before;
177
178 /* Data about individual timing update corrections */
179 pa_index_correction write_index_corrections[PA_MAX_WRITE_INDEX_CORRECTIONS];
180 int current_write_index_correction;
181
182 /* Latency interpolation stuff */
183 pa_time_event *auto_timing_update_event;
184 pa_usec_t auto_timing_interval_usec;
185
186 pa_smoother *smoother;
187
188 /* Callbacks */
189 pa_stream_notify_cb_t state_callback;
190 void *state_userdata;
191 pa_stream_request_cb_t read_callback;
192 void *read_userdata;
193 pa_stream_request_cb_t write_callback;
194 void *write_userdata;
195 pa_stream_notify_cb_t overflow_callback;
196 void *overflow_userdata;
197 pa_stream_notify_cb_t underflow_callback;
198 void *underflow_userdata;
199 pa_stream_notify_cb_t latency_update_callback;
200 void *latency_update_userdata;
201 pa_stream_notify_cb_t moved_callback;
202 void *moved_userdata;
203 pa_stream_notify_cb_t suspended_callback;
204 void *suspended_userdata;
205 pa_stream_notify_cb_t started_callback;
206 void *started_userdata;
207 pa_stream_event_cb_t event_callback;
208 void *event_userdata;
209 pa_stream_notify_cb_t buffer_attr_callback;
210 void *buffer_attr_userdata;
211 };
212
213 typedef void (*pa_operation_cb_t)(void);
214
215 struct pa_operation {
216 PA_REFCNT_DECLARE;
217
218 pa_context *context;
219 pa_stream *stream;
220
221 PA_LLIST_FIELDS(pa_operation);
222
223 pa_operation_state_t state;
224 void *userdata;
225 pa_operation_cb_t callback;
226
227 void *private; /* some operations might need this */
228 };
229
230 void pa_command_request(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
231 void pa_command_stream_killed(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
232 void pa_command_subscribe_event(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
233 void pa_command_overflow_or_underflow(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
234 void pa_command_stream_suspended(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
235 void pa_command_stream_moved(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
236 void pa_command_stream_started(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
237 void pa_command_stream_event(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
238 void pa_command_client_event(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
239 void pa_command_stream_buffer_attr(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
240
241 pa_operation *pa_operation_new(pa_context *c, pa_stream *s, pa_operation_cb_t callback, void *userdata);
242 void pa_operation_done(pa_operation *o);
243
244 void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
245 void pa_stream_disconnect_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
246 void pa_context_simple_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
247 void pa_stream_simple_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
248
249 void pa_context_fail(pa_context *c, int error);
250 int pa_context_set_error(pa_context *c, int error);
251 void pa_context_set_state(pa_context *c, pa_context_state_t st);
252 int pa_context_handle_error(pa_context *c, uint32_t command, pa_tagstruct *t, pa_bool_t fail);
253 pa_operation* pa_context_send_simple_command(pa_context *c, uint32_t command, void (*internal_callback)(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata), void (*cb)(void), void *userdata);
254
255 void pa_stream_set_state(pa_stream *s, pa_stream_state_t st);
256
257 pa_tagstruct *pa_tagstruct_command(pa_context *c, uint32_t command, uint32_t *tag);
258
259 #define PA_CHECK_VALIDITY(context, expression, error) \
260 do { \
261 if (!(expression)) \
262 return -pa_context_set_error((context), (error)); \
263 } while(FALSE)
264
265
266 #define PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, value) \
267 do { \
268 if (!(expression)) { \
269 pa_context_set_error((context), (error)); \
270 return value; \
271 } \
272 } while(FALSE)
273
274 #define PA_CHECK_VALIDITY_RETURN_NULL(context, expression, error) \
275 PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, NULL)
276
277 #define PA_FAIL(context, error) \
278 do { \
279 return -pa_context_set_error((context), (error)); \
280 } while(FALSE)
281
282 #define PA_FAIL_RETURN_ANY(context, error, value) \
283 do { \
284 pa_context_set_error((context), (error)); \
285 return value; \
286 } while(FALSE)
287
288 #define PA_FAIL_RETURN_NULL(context, error) \
289 PA_FAIL_RETURN_ANY(context, error, NULL)
290
291 void pa_ext_device_manager_command(pa_context *c, uint32_t tag, pa_tagstruct *t);
292 void pa_ext_stream_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t);
293
294 pa_bool_t pa_mainloop_is_our_api(pa_mainloop_api*m);
295
296 #endif