1 #ifndef foointernalhfoo
2 #define foointernalhfoo
5 This file is part of PulseAudio.
7 Copyright 2004-2006 Lennart Poettering
8 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
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.
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.
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
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>
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>
46 #include "client-conf.h"
48 #define DEFAULT_TIMEOUT (30)
53 pa_proplist
*proplist
;
54 pa_mainloop_api
* mainloop
;
56 pa_socket_client
*client
;
58 pa_pdispatch
*pdispatch
;
60 pa_dynarray
*record_streams
, *playback_streams
;
61 PA_LLIST_HEAD(pa_stream
, streams
);
62 PA_LLIST_HEAD(pa_operation
, operations
);
68 pa_context_state_t state
;
70 pa_context_notify_cb_t state_callback
;
72 pa_context_subscribe_cb_t subscribe_callback
;
73 void *subscribe_userdata
;
80 pa_bool_t do_autospawn
:1;
81 pa_bool_t autospawn_locked
:1;
83 pa_io_event
*autospawn_event
;
84 pa_spawn_api spawn_api
;
86 pa_strlist
*server_list
;
92 uint32_t client_index
;
94 /* Extension specific data */
96 pa_ext_stream_restore_subscribe_cb_t callback
;
101 #define PA_MAX_WRITE_INDEX_CORRECTIONS 32
103 typedef struct pa_index_correction
{
107 pa_bool_t absolute
:1;
109 } pa_index_correction
;
113 PA_LLIST_FIELDS(pa_stream
);
116 pa_mainloop_api
*mainloop
;
118 uint32_t direct_on_input
;
120 pa_stream_direction_t direction
;
121 pa_stream_state_t state
;
122 pa_stream_flags_t flags
;
124 pa_sample_spec sample_spec
;
125 pa_channel_map channel_map
;
127 pa_proplist
*proplist
;
129 pa_bool_t channel_valid
:1;
130 pa_bool_t suspended
:1;
132 pa_bool_t timing_info_valid
:1;
133 pa_bool_t auto_timing_update_requested
:1;
137 uint32_t stream_index
;
139 uint32_t requested_bytes
;
140 pa_buffer_attr buffer_attr
;
142 uint32_t device_index
;
145 pa_memchunk peek_memchunk
;
147 pa_memblockq
*record_memblockq
;
149 /* Store latest latency info */
150 pa_timing_info timing_info
;
152 /* Use to make sure that time advances monotonically */
153 pa_usec_t previous_time
;
155 /* time updates with tags older than these are invalid */
156 uint32_t write_index_not_before
;
157 uint32_t read_index_not_before
;
159 /* Data about individual timing update correctoins */
160 pa_index_correction write_index_corrections
[PA_MAX_WRITE_INDEX_CORRECTIONS
];
161 int current_write_index_correction
;
163 /* Latency interpolation stuff */
164 pa_time_event
*auto_timing_update_event
;
166 pa_smoother
*smoother
;
169 pa_stream_notify_cb_t state_callback
;
170 void *state_userdata
;
171 pa_stream_request_cb_t read_callback
;
173 pa_stream_request_cb_t write_callback
;
174 void *write_userdata
;
175 pa_stream_notify_cb_t overflow_callback
;
176 void *overflow_userdata
;
177 pa_stream_notify_cb_t underflow_callback
;
178 void *underflow_userdata
;
179 pa_stream_notify_cb_t latency_update_callback
;
180 void *latency_update_userdata
;
181 pa_stream_notify_cb_t moved_callback
;
182 void *moved_userdata
;
183 pa_stream_notify_cb_t suspended_callback
;
184 void *suspended_userdata
;
185 pa_stream_notify_cb_t started_callback
;
186 void *started_userdata
;
189 typedef void (*pa_operation_cb_t
)(void);
191 struct pa_operation
{
197 PA_LLIST_FIELDS(pa_operation
);
199 pa_operation_state_t state
;
201 pa_operation_cb_t callback
;
203 void *private; /* some operations might need this */
206 void pa_command_request(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
207 void pa_command_stream_killed(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
208 void pa_command_subscribe_event(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
209 void pa_command_overflow_or_underflow(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
210 void pa_command_stream_suspended(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
211 void pa_command_stream_moved(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
212 void pa_command_stream_started(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
213 pa_operation
*pa_operation_new(pa_context
*c
, pa_stream
*s
, pa_operation_cb_t callback
, void *userdata
);
214 void pa_operation_done(pa_operation
*o
);
216 void pa_create_stream_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
217 void pa_stream_disconnect_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
218 void pa_context_simple_ack_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
219 void pa_stream_simple_ack_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
221 void pa_context_fail(pa_context
*c
, int error
);
222 int pa_context_set_error(pa_context
*c
, int error
);
223 void pa_context_set_state(pa_context
*c
, pa_context_state_t st
);
224 int pa_context_handle_error(pa_context
*c
, uint32_t command
, pa_tagstruct
*t
, pa_bool_t fail
);
225 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
);
227 void pa_stream_set_state(pa_stream
*s
, pa_stream_state_t st
);
229 pa_tagstruct
*pa_tagstruct_command(pa_context
*c
, uint32_t command
, uint32_t *tag
);
231 #define PA_CHECK_VALIDITY(context, expression, error) do { \
233 return -pa_context_set_error((context), (error)); \
237 #define PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, value) do { \
238 if (!(expression)) { \
239 pa_context_set_error((context), (error)); \
244 #define PA_CHECK_VALIDITY_RETURN_NULL(context, expression, error) PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, NULL)
246 void pa_ext_stream_restore_command(pa_context
*c
, uint32_t tag
, pa_tagstruct
*t
);