]> code.delx.au - pulseaudio/blob - src/pulse/internal.h
92379094dfb132324592406cde95533819a93513
[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-device-restore.h>
33 #include <pulse/ext-stream-restore.h>
34
35 #include <pulsecore/socket-client.h>
36 #include <pulsecore/pstream.h>
37 #include <pulsecore/pdispatch.h>
38 #include <pulsecore/llist.h>
39 #include <pulsecore/native-common.h>
40 #include <pulsecore/strlist.h>
41 #include <pulsecore/mcalign.h>
42 #include <pulsecore/memblockq.h>
43 #include <pulsecore/hashmap.h>
44 #include <pulsecore/refcnt.h>
45 #include <pulsecore/time-smoother.h>
46 #ifdef HAVE_DBUS
47 #include <pulsecore/dbus-util.h>
48 #endif
49
50 #include "client-conf.h"
51
52 #define DEFAULT_TIMEOUT (30)
53
54 struct pa_context {
55 PA_REFCNT_DECLARE;
56
57 #ifdef HAVE_DBUS
58 pa_dbus_wrap_connection *system_bus;
59 pa_dbus_wrap_connection *session_bus;
60 #endif
61
62 pa_proplist *proplist;
63 pa_mainloop_api* mainloop;
64
65 pa_socket_client *client;
66 pa_pstream *pstream;
67 pa_pdispatch *pdispatch;
68
69 pa_hashmap *record_streams, *playback_streams;
70 PA_LLIST_HEAD(pa_stream, streams);
71 PA_LLIST_HEAD(pa_operation, operations);
72
73 uint32_t version;
74 uint32_t ctag;
75 uint32_t csyncid;
76 int error;
77 pa_context_state_t state;
78
79 pa_context_notify_cb_t state_callback;
80 void *state_userdata;
81 pa_context_subscribe_cb_t subscribe_callback;
82 void *subscribe_userdata;
83 pa_context_event_cb_t event_callback;
84 void *event_userdata;
85
86 pa_mempool *mempool;
87
88 pa_bool_t is_local:1;
89 pa_bool_t do_shm:1;
90 pa_bool_t server_specified:1;
91 pa_bool_t no_fail:1;
92 pa_bool_t do_autospawn:1;
93 pa_bool_t use_rtclock:1;
94 pa_bool_t filter_added:1;
95 pa_spawn_api spawn_api;
96
97 pa_strlist *server_list;
98
99 char *server;
100
101 pa_client_conf *conf;
102
103 uint32_t client_index;
104
105 /* Extension specific data */
106 struct {
107 pa_ext_device_manager_subscribe_cb_t callback;
108 void *userdata;
109 } ext_device_manager;
110 struct {
111 pa_ext_device_restore_subscribe_cb_t callback;
112 void *userdata;
113 } ext_device_restore;
114 struct {
115 pa_ext_stream_restore_subscribe_cb_t callback;
116 void *userdata;
117 } ext_stream_restore;
118 };
119
120 #define PA_MAX_WRITE_INDEX_CORRECTIONS 32
121
122 typedef struct pa_index_correction {
123 uint32_t tag;
124 int64_t value;
125 pa_bool_t valid:1;
126 pa_bool_t absolute:1;
127 pa_bool_t corrupt:1;
128 } pa_index_correction;
129
130 #define PA_MAX_FORMATS (PA_ENCODING_MAX)
131
132 struct pa_stream {
133 PA_REFCNT_DECLARE;
134 PA_LLIST_FIELDS(pa_stream);
135
136 pa_context *context;
137 pa_mainloop_api *mainloop;
138
139 uint32_t direct_on_input;
140
141 pa_stream_direction_t direction;
142 pa_stream_state_t state;
143 pa_stream_flags_t flags;
144
145 pa_sample_spec sample_spec;
146 pa_channel_map channel_map;
147 uint8_t n_formats;
148 pa_format_info *req_formats[PA_MAX_FORMATS];
149 pa_format_info *format;
150
151 pa_proplist *proplist;
152
153 pa_bool_t channel_valid:1;
154 pa_bool_t suspended:1;
155 pa_bool_t corked:1;
156 pa_bool_t timing_info_valid:1;
157 pa_bool_t auto_timing_update_requested:1;
158
159 uint32_t channel;
160 uint32_t syncid;
161 uint32_t stream_index;
162
163 int64_t requested_bytes;
164 pa_buffer_attr buffer_attr;
165
166 uint32_t device_index;
167 char *device_name;
168
169 /* playback */
170 pa_memblock *write_memblock;
171 void *write_data;
172
173 /* recording */
174 pa_memchunk peek_memchunk;
175 void *peek_data;
176 pa_memblockq *record_memblockq;
177
178 /* Store latest latency info */
179 pa_timing_info timing_info;
180
181 /* Use to make sure that time advances monotonically */
182 pa_usec_t previous_time;
183
184 /* time updates with tags older than these are invalid */
185 uint32_t write_index_not_before;
186 uint32_t read_index_not_before;
187
188 /* Data about individual timing update corrections */
189 pa_index_correction write_index_corrections[PA_MAX_WRITE_INDEX_CORRECTIONS];
190 int current_write_index_correction;
191
192 /* Latency interpolation stuff */
193 pa_time_event *auto_timing_update_event;
194 pa_usec_t auto_timing_interval_usec;
195
196 pa_smoother *smoother;
197
198 /* Callbacks */
199 pa_stream_notify_cb_t state_callback;
200 void *state_userdata;
201 pa_stream_request_cb_t read_callback;
202 void *read_userdata;
203 pa_stream_request_cb_t write_callback;
204 void *write_userdata;
205 pa_stream_notify_cb_t overflow_callback;
206 void *overflow_userdata;
207 pa_stream_notify_cb_t underflow_callback;
208 void *underflow_userdata;
209 pa_stream_notify_cb_t latency_update_callback;
210 void *latency_update_userdata;
211 pa_stream_notify_cb_t moved_callback;
212 void *moved_userdata;
213 pa_stream_notify_cb_t suspended_callback;
214 void *suspended_userdata;
215 pa_stream_notify_cb_t started_callback;
216 void *started_userdata;
217 pa_stream_event_cb_t event_callback;
218 void *event_userdata;
219 pa_stream_notify_cb_t buffer_attr_callback;
220 void *buffer_attr_userdata;
221 };
222
223 typedef void (*pa_operation_cb_t)(void);
224
225 struct pa_operation {
226 PA_REFCNT_DECLARE;
227
228 pa_context *context;
229 pa_stream *stream;
230
231 PA_LLIST_FIELDS(pa_operation);
232
233 pa_operation_state_t state;
234 void *userdata;
235 pa_operation_cb_t callback;
236
237 void *private; /* some operations might need this */
238 };
239
240 void pa_command_request(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
241 void pa_command_stream_killed(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
242 void pa_command_subscribe_event(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
243 void pa_command_overflow_or_underflow(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
244 void pa_command_stream_suspended(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
245 void pa_command_stream_moved(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
246 void pa_command_stream_started(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
247 void pa_command_stream_event(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
248 void pa_command_client_event(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
249 void pa_command_stream_buffer_attr(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
250
251 pa_operation *pa_operation_new(pa_context *c, pa_stream *s, pa_operation_cb_t callback, void *userdata);
252 void pa_operation_done(pa_operation *o);
253
254 void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
255 void pa_stream_disconnect_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
256 void pa_context_simple_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
257 void pa_stream_simple_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
258
259 void pa_context_fail(pa_context *c, int error);
260 int pa_context_set_error(pa_context *c, int error);
261 void pa_context_set_state(pa_context *c, pa_context_state_t st);
262 int pa_context_handle_error(pa_context *c, uint32_t command, pa_tagstruct *t, pa_bool_t fail);
263 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);
264
265 void pa_stream_set_state(pa_stream *s, pa_stream_state_t st);
266
267 pa_tagstruct *pa_tagstruct_command(pa_context *c, uint32_t command, uint32_t *tag);
268
269 #define PA_CHECK_VALIDITY(context, expression, error) \
270 do { \
271 if (!(expression)) \
272 return -pa_context_set_error((context), (error)); \
273 } while(FALSE)
274
275
276 #define PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, value) \
277 do { \
278 if (!(expression)) { \
279 pa_context_set_error((context), (error)); \
280 return value; \
281 } \
282 } while(FALSE)
283
284 #define PA_CHECK_VALIDITY_RETURN_NULL(context, expression, error) \
285 PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, NULL)
286
287 #define PA_FAIL(context, error) \
288 do { \
289 return -pa_context_set_error((context), (error)); \
290 } while(FALSE)
291
292 #define PA_FAIL_RETURN_ANY(context, error, value) \
293 do { \
294 pa_context_set_error((context), (error)); \
295 return value; \
296 } while(FALSE)
297
298 #define PA_FAIL_RETURN_NULL(context, error) \
299 PA_FAIL_RETURN_ANY(context, error, NULL)
300
301 void pa_ext_device_manager_command(pa_context *c, uint32_t tag, pa_tagstruct *t);
302 void pa_ext_device_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t);
303 void pa_ext_stream_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t);
304
305 void pa_format_info_free2(pa_format_info *f, void *userdata);
306 pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_map *map);
307 pa_bool_t pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map);
308 pa_bool_t pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss);
309 pa_bool_t pa_format_info_get_prop_int(pa_format_info *f, const char *key, int *v);
310 pa_bool_t pa_format_info_get_prop_string(pa_format_info *f, const char *key, char **v);
311
312 pa_bool_t pa_mainloop_is_our_api(pa_mainloop_api*m);
313
314 #endif