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