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