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