Merge HUGE set of changes temporarily into a branch, to allow me to move them from...
[profile/ivi/pulseaudio-panda.git] / 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
45 #include "client-conf.h"
46
47 #define DEFAULT_TIMEOUT (30)
48
49 struct pa_context {
50     int ref;
51
52     char *name;
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
72     pa_context_subscribe_cb_t subscribe_callback;
73     void *subscribe_userdata;
74
75     pa_mempool *mempool;
76
77     int is_local;
78     int do_autospawn;
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
89 #define PA_MAX_WRITE_INDEX_CORRECTIONS 10
90
91 typedef struct pa_index_correction {
92     uint32_t tag;
93     int valid;
94     int64_t value;
95     int absolute, corrupt;
96 } pa_index_correction;
97
98 struct pa_stream {
99     int ref;
100     pa_context *context;
101     pa_mainloop_api *mainloop;
102     PA_LLIST_FIELDS(pa_stream);
103
104     char *name;
105     pa_buffer_attr buffer_attr;
106     pa_sample_spec sample_spec;
107     pa_channel_map channel_map;
108     pa_stream_flags_t flags;
109     uint32_t channel;
110     uint32_t syncid;
111     int channel_valid;
112     uint32_t device_index;
113     pa_stream_direction_t direction;
114     pa_stream_state_t state;
115
116     uint32_t requested_bytes;
117
118     pa_memchunk peek_memchunk;
119     void *peek_data;
120     pa_memblockq *record_memblockq;
121
122     int corked;
123
124     /* Store latest latency info */
125     pa_timing_info timing_info;
126     int timing_info_valid;
127
128     /* Use to make sure that time advances monotonically */
129     pa_usec_t previous_time;
130
131     /* time updates with tags older than these are invalid */
132     uint32_t write_index_not_before;
133     uint32_t read_index_not_before;
134
135     /* Data about individual timing update correctoins */
136     pa_index_correction write_index_corrections[PA_MAX_WRITE_INDEX_CORRECTIONS];
137     int current_write_index_correction;
138
139     /* Latency interpolation stuff */
140     pa_time_event *auto_timing_update_event;
141     int auto_timing_update_requested;
142
143     pa_usec_t cached_time;
144     int cached_time_valid;
145
146     /* Callbacks */
147     pa_stream_notify_cb_t state_callback;
148     void *state_userdata;
149     pa_stream_request_cb_t read_callback;
150     void *read_userdata;
151     pa_stream_request_cb_t write_callback;
152     void *write_userdata;
153     pa_stream_notify_cb_t overflow_callback;
154     void *overflow_userdata;
155     pa_stream_notify_cb_t underflow_callback;
156     void *underflow_userdata;
157     pa_stream_notify_cb_t latency_update_callback;
158     void *latency_update_userdata;
159 };
160
161 typedef void (*pa_operation_cb_t)(void);
162
163 struct pa_operation {
164     int ref;
165     pa_context *context;
166     pa_stream *stream;
167
168     PA_LLIST_FIELDS(pa_operation);
169
170     pa_operation_state_t state;
171     void *userdata;
172     pa_operation_cb_t callback;
173 };
174
175 void pa_command_request(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
176 void pa_command_stream_killed(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
177 void pa_command_subscribe_event(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
178 void pa_command_overflow_or_underflow(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
179
180 pa_operation *pa_operation_new(pa_context *c, pa_stream *s, pa_operation_cb_t callback, void *userdata);
181 void pa_operation_done(pa_operation *o);
182
183 void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
184 void pa_stream_disconnect_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
185 void pa_context_simple_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
186 void pa_stream_simple_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
187
188 void pa_context_fail(pa_context *c, int error);
189 int pa_context_set_error(pa_context *c, int error);
190 void pa_context_set_state(pa_context *c, pa_context_state_t st);
191 int pa_context_handle_error(pa_context *c, uint32_t command, pa_tagstruct *t);
192 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);
193
194 void pa_stream_set_state(pa_stream *s, pa_stream_state_t st);
195
196 pa_tagstruct *pa_tagstruct_command(pa_context *c, uint32_t command, uint32_t *tag);
197
198 #define PA_CHECK_VALIDITY(context, expression, error) do { \
199         if (!(expression)) \
200             return -pa_context_set_error((context), (error)); \
201 } while(0)
202
203
204 #define PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, value) do { \
205         if (!(expression)) { \
206             pa_context_set_error((context), (error)); \
207             return value; \
208         } \
209 } while(0)
210
211 #define PA_CHECK_VALIDITY_RETURN_NULL(context, expression, error) PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, NULL)
212
213
214 #endif