]> code.delx.au - pulseaudio/blob - src/pulse/internal.h
do not fix automatic buffer attrs anymore, the new protocol version doesn't need...
[pulseaudio] / src / pulse / internal.h
1 #ifndef foointernalhfoo
2 #define foointernalhfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of PulseAudio.
8
9 Copyright 2004-2006 Lennart Poettering
10 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
11
12 PulseAudio is free software; you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License as published
14 by the Free Software Foundation; either version 2 of the License,
15 or (at your option) any later version.
16
17 PulseAudio is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU Lesser General Public License
23 along with PulseAudio; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 USA.
26 ***/
27
28 #include <pulse/mainloop-api.h>
29 #include <pulse/context.h>
30 #include <pulse/stream.h>
31 #include <pulse/operation.h>
32 #include <pulse/subscribe.h>
33
34 #include <pulsecore/socket-client.h>
35 #include <pulsecore/pstream.h>
36 #include <pulsecore/pdispatch.h>
37 #include <pulsecore/dynarray.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
46 #include "client-conf.h"
47
48 #define DEFAULT_TIMEOUT (30)
49
50 struct pa_context {
51 PA_REFCNT_DECLARE;
52
53 pa_proplist *proplist;
54 pa_mainloop_api* mainloop;
55
56 pa_socket_client *client;
57 pa_pstream *pstream;
58 pa_pdispatch *pdispatch;
59
60 pa_dynarray *record_streams, *playback_streams;
61 PA_LLIST_HEAD(pa_stream, streams);
62 PA_LLIST_HEAD(pa_operation, operations);
63
64 uint32_t version;
65 uint32_t ctag;
66 uint32_t csyncid;
67 uint32_t error;
68 pa_context_state_t state;
69
70 pa_context_notify_cb_t state_callback;
71 void *state_userdata;
72
73 pa_context_subscribe_cb_t subscribe_callback;
74 void *subscribe_userdata;
75
76 pa_mempool *mempool;
77
78 int is_local;
79 int do_autospawn;
80 int autospawn_lock_fd;
81 pa_spawn_api spawn_api;
82
83 pa_strlist *server_list;
84
85 char *server;
86
87 pa_client_conf *conf;
88
89 uint32_t client_index;
90 };
91
92 #define PA_MAX_WRITE_INDEX_CORRECTIONS 10
93
94 typedef struct pa_index_correction {
95 uint32_t tag;
96 int valid;
97 int64_t value;
98 int absolute, corrupt;
99 } pa_index_correction;
100
101 struct pa_stream {
102 PA_REFCNT_DECLARE;
103 pa_context *context;
104 pa_mainloop_api *mainloop;
105 PA_LLIST_FIELDS(pa_stream);
106
107 pa_proplist *proplist;
108 pa_bool_t manual_buffer_attr;
109 pa_buffer_attr buffer_attr;
110 pa_sample_spec sample_spec;
111 pa_channel_map channel_map;
112 pa_stream_flags_t flags;
113 uint32_t channel;
114 uint32_t syncid;
115 int channel_valid;
116 uint32_t stream_index;
117 pa_stream_direction_t direction;
118 pa_stream_state_t state;
119
120 uint32_t requested_bytes;
121
122 uint32_t device_index;
123 char *device_name;
124 pa_bool_t suspended;
125
126 pa_memchunk peek_memchunk;
127 void *peek_data;
128 pa_memblockq *record_memblockq;
129
130 int corked;
131
132 /* Store latest latency info */
133 pa_timing_info timing_info;
134 int timing_info_valid;
135
136 /* Use to make sure that time advances monotonically */
137 pa_usec_t previous_time;
138
139 /* time updates with tags older than these are invalid */
140 uint32_t write_index_not_before;
141 uint32_t read_index_not_before;
142
143 /* Data about individual timing update correctoins */
144 pa_index_correction write_index_corrections[PA_MAX_WRITE_INDEX_CORRECTIONS];
145 int current_write_index_correction;
146
147 /* Latency interpolation stuff */
148 pa_time_event *auto_timing_update_event;
149 int auto_timing_update_requested;
150
151 pa_usec_t cached_time;
152 int cached_time_valid;
153
154 /* Callbacks */
155 pa_stream_notify_cb_t state_callback;
156 void *state_userdata;
157 pa_stream_request_cb_t read_callback;
158 void *read_userdata;
159 pa_stream_request_cb_t write_callback;
160 void *write_userdata;
161 pa_stream_notify_cb_t overflow_callback;
162 void *overflow_userdata;
163 pa_stream_notify_cb_t underflow_callback;
164 void *underflow_userdata;
165 pa_stream_notify_cb_t latency_update_callback;
166 void *latency_update_userdata;
167 pa_stream_notify_cb_t moved_callback;
168 void *moved_userdata;
169 pa_stream_notify_cb_t suspended_callback;
170 void *suspended_userdata;
171 };
172
173 typedef void (*pa_operation_cb_t)(void);
174
175 struct pa_operation {
176 PA_REFCNT_DECLARE;
177
178 pa_context *context;
179 pa_stream *stream;
180
181 PA_LLIST_FIELDS(pa_operation);
182
183 pa_operation_state_t state;
184 void *userdata;
185 pa_operation_cb_t callback;
186
187 void *private; /* some operations might need this */
188 };
189
190 void pa_command_request(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
191 void pa_command_stream_killed(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
192 void pa_command_subscribe_event(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
193 void pa_command_overflow_or_underflow(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
194 void pa_command_stream_suspended(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
195 void pa_command_stream_moved(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
196
197 pa_operation *pa_operation_new(pa_context *c, pa_stream *s, pa_operation_cb_t callback, void *userdata);
198 void pa_operation_done(pa_operation *o);
199
200 void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
201 void pa_stream_disconnect_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
202 void pa_context_simple_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
203 void pa_stream_simple_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
204
205 void pa_context_fail(pa_context *c, int error);
206 int pa_context_set_error(pa_context *c, int error);
207 void pa_context_set_state(pa_context *c, pa_context_state_t st);
208 int pa_context_handle_error(pa_context *c, uint32_t command, pa_tagstruct *t);
209 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);
210
211 void pa_stream_set_state(pa_stream *s, pa_stream_state_t st);
212
213 pa_tagstruct *pa_tagstruct_command(pa_context *c, uint32_t command, uint32_t *tag);
214
215 #define PA_CHECK_VALIDITY(context, expression, error) do { \
216 if (!(expression)) \
217 return -pa_context_set_error((context), (error)); \
218 } while(0)
219
220
221 #define PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, value) do { \
222 if (!(expression)) { \
223 pa_context_set_error((context), (error)); \
224 return value; \
225 } \
226 } while(0)
227
228 #define PA_CHECK_VALIDITY_RETURN_NULL(context, expression, error) PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, NULL)
229
230 void pa_init_proplist(pa_proplist *p);
231
232 #endif