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.1 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 <pulsecore/dbus-util.h>
49 #include "client-conf.h"
51 #define DEFAULT_TIMEOUT (30)
57 pa_dbus_wrap_connection
*system_bus
;
58 pa_dbus_wrap_connection
*session_bus
;
61 pa_proplist
*proplist
;
62 pa_mainloop_api
* mainloop
;
64 pa_socket_client
*client
;
66 pa_pdispatch
*pdispatch
;
68 pa_dynarray
*record_streams
, *playback_streams
;
69 PA_LLIST_HEAD(pa_stream
, streams
);
70 PA_LLIST_HEAD(pa_operation
, operations
);
76 pa_context_state_t state
;
78 pa_context_notify_cb_t state_callback
;
80 pa_context_subscribe_cb_t subscribe_callback
;
81 void *subscribe_userdata
;
82 pa_context_event_cb_t event_callback
;
89 pa_bool_t server_specified
:1;
91 pa_bool_t do_autospawn
:1;
92 pa_bool_t use_rtclock
:1;
93 pa_spawn_api spawn_api
;
95 pa_strlist
*server_list
;
101 uint32_t client_index
;
103 /* Extension specific data */
105 pa_ext_stream_restore_subscribe_cb_t callback
;
107 } ext_stream_restore
;
110 #define PA_MAX_WRITE_INDEX_CORRECTIONS 32
112 typedef struct pa_index_correction
{
116 pa_bool_t absolute
:1;
118 } pa_index_correction
;
122 PA_LLIST_FIELDS(pa_stream
);
125 pa_mainloop_api
*mainloop
;
127 uint32_t direct_on_input
;
129 pa_stream_direction_t direction
;
130 pa_stream_state_t state
;
131 pa_stream_flags_t flags
;
133 pa_sample_spec sample_spec
;
134 pa_channel_map channel_map
;
136 pa_proplist
*proplist
;
138 pa_bool_t channel_valid
:1;
139 pa_bool_t suspended
:1;
141 pa_bool_t timing_info_valid
:1;
142 pa_bool_t auto_timing_update_requested
:1;
146 uint32_t stream_index
;
148 int64_t requested_bytes
;
149 pa_buffer_attr buffer_attr
;
151 uint32_t device_index
;
155 pa_memblock
*write_memblock
;
159 pa_memchunk peek_memchunk
;
161 pa_memblockq
*record_memblockq
;
163 /* Store latest latency info */
164 pa_timing_info timing_info
;
166 /* Use to make sure that time advances monotonically */
167 pa_usec_t previous_time
;
169 /* time updates with tags older than these are invalid */
170 uint32_t write_index_not_before
;
171 uint32_t read_index_not_before
;
173 /* Data about individual timing update corrections */
174 pa_index_correction write_index_corrections
[PA_MAX_WRITE_INDEX_CORRECTIONS
];
175 int current_write_index_correction
;
177 /* Latency interpolation stuff */
178 pa_time_event
*auto_timing_update_event
;
179 pa_usec_t auto_timing_interval_usec
;
181 pa_smoother
*smoother
;
184 pa_stream_notify_cb_t state_callback
;
185 void *state_userdata
;
186 pa_stream_request_cb_t read_callback
;
188 pa_stream_request_cb_t write_callback
;
189 void *write_userdata
;
190 pa_stream_notify_cb_t overflow_callback
;
191 void *overflow_userdata
;
192 pa_stream_notify_cb_t underflow_callback
;
193 void *underflow_userdata
;
194 pa_stream_notify_cb_t latency_update_callback
;
195 void *latency_update_userdata
;
196 pa_stream_notify_cb_t moved_callback
;
197 void *moved_userdata
;
198 pa_stream_notify_cb_t suspended_callback
;
199 void *suspended_userdata
;
200 pa_stream_notify_cb_t started_callback
;
201 void *started_userdata
;
202 pa_stream_event_cb_t event_callback
;
203 void *event_userdata
;
204 pa_stream_notify_cb_t buffer_attr_callback
;
205 void *buffer_attr_userdata
;
208 typedef void (*pa_operation_cb_t
)(void);
210 struct pa_operation
{
216 PA_LLIST_FIELDS(pa_operation
);
218 pa_operation_state_t state
;
220 pa_operation_cb_t callback
;
222 void *private; /* some operations might need this */
225 void pa_command_request(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
226 void pa_command_stream_killed(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
227 void pa_command_subscribe_event(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
228 void pa_command_overflow_or_underflow(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
229 void pa_command_stream_suspended(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
230 void pa_command_stream_moved(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
231 void pa_command_stream_started(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
232 void pa_command_stream_event(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
233 void pa_command_client_event(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
234 void pa_command_stream_buffer_attr(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
236 pa_operation
*pa_operation_new(pa_context
*c
, pa_stream
*s
, pa_operation_cb_t callback
, void *userdata
);
237 void pa_operation_done(pa_operation
*o
);
239 void pa_create_stream_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
240 void pa_stream_disconnect_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
241 void pa_context_simple_ack_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
242 void pa_stream_simple_ack_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
244 void pa_context_fail(pa_context
*c
, int error
);
245 int pa_context_set_error(pa_context
*c
, int error
);
246 void pa_context_set_state(pa_context
*c
, pa_context_state_t st
);
247 int pa_context_handle_error(pa_context
*c
, uint32_t command
, pa_tagstruct
*t
, pa_bool_t fail
);
248 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
);
250 void pa_stream_set_state(pa_stream
*s
, pa_stream_state_t st
);
252 pa_tagstruct
*pa_tagstruct_command(pa_context
*c
, uint32_t command
, uint32_t *tag
);
254 #define PA_CHECK_VALIDITY(context, expression, error) \
257 return -pa_context_set_error((context), (error)); \
261 #define PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, value) \
263 if (!(expression)) { \
264 pa_context_set_error((context), (error)); \
269 #define PA_CHECK_VALIDITY_RETURN_NULL(context, expression, error) \
270 PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, NULL)
272 #define PA_FAIL(context, error) \
274 return -pa_context_set_error((context), (error)); \
277 #define PA_FAIL_RETURN_ANY(context, error, value) \
279 pa_context_set_error((context), (error)); \
283 #define PA_FAIL_RETURN_NULL(context, error) \
284 PA_FAIL_RETURN_ANY(context, error, NULL)
286 void pa_ext_stream_restore_command(pa_context
*c
, uint32_t tag
, pa_tagstruct
*t
);
288 pa_bool_t
pa_mainloop_is_our_api(pa_mainloop_api
*m
);