1 #ifndef foointernalhfoo
2 #define foointernalhfoo
7 This file is part of PulseAudio.
9 Copyright 2004-2006 Lennart Poettering
10 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
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.
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.
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
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>
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 #include <pulsecore/time-smoother.h>
47 #include "client-conf.h"
49 #define DEFAULT_TIMEOUT (30)
54 pa_proplist
*proplist
;
55 pa_mainloop_api
* mainloop
;
57 pa_socket_client
*client
;
59 pa_pdispatch
*pdispatch
;
61 pa_dynarray
*record_streams
, *playback_streams
;
62 PA_LLIST_HEAD(pa_stream
, streams
);
63 PA_LLIST_HEAD(pa_operation
, operations
);
69 pa_context_state_t state
;
71 pa_context_notify_cb_t state_callback
;
73 pa_context_subscribe_cb_t subscribe_callback
;
74 void *subscribe_userdata
;
79 pa_bool_t do_autospawn
;
80 int autospawn_lock_fd
;
81 pa_spawn_api spawn_api
;
83 pa_strlist
*server_list
;
89 uint32_t client_index
;
92 #define PA_MAX_WRITE_INDEX_CORRECTIONS 32
94 typedef struct pa_index_correction
{
100 } pa_index_correction
;
104 PA_LLIST_FIELDS(pa_stream
);
107 pa_mainloop_api
*mainloop
;
109 pa_stream_direction_t direction
;
110 pa_stream_state_t state
;
111 pa_stream_flags_t flags
;
113 pa_sample_spec sample_spec
;
114 pa_channel_map channel_map
;
116 pa_proplist
*proplist
;
119 pa_bool_t channel_valid
;
121 uint32_t stream_index
;
123 uint32_t requested_bytes
;
124 pa_buffer_attr buffer_attr
;
126 uint32_t device_index
;
130 pa_memchunk peek_memchunk
;
132 pa_memblockq
*record_memblockq
;
136 /* Store latest latency info */
137 pa_timing_info timing_info
;
138 pa_bool_t timing_info_valid
;
140 /* Use to make sure that time advances monotonically */
141 pa_usec_t previous_time
;
143 /* time updates with tags older than these are invalid */
144 uint32_t write_index_not_before
;
145 uint32_t read_index_not_before
;
147 /* Data about individual timing update correctoins */
148 pa_index_correction write_index_corrections
[PA_MAX_WRITE_INDEX_CORRECTIONS
];
149 int current_write_index_correction
;
151 /* Latency interpolation stuff */
152 pa_time_event
*auto_timing_update_event
;
153 pa_bool_t auto_timing_update_requested
;
155 pa_smoother
*smoother
;
158 pa_stream_notify_cb_t state_callback
;
159 void *state_userdata
;
160 pa_stream_request_cb_t read_callback
;
162 pa_stream_request_cb_t write_callback
;
163 void *write_userdata
;
164 pa_stream_notify_cb_t overflow_callback
;
165 void *overflow_userdata
;
166 pa_stream_notify_cb_t underflow_callback
;
167 void *underflow_userdata
;
168 pa_stream_notify_cb_t latency_update_callback
;
169 void *latency_update_userdata
;
170 pa_stream_notify_cb_t moved_callback
;
171 void *moved_userdata
;
172 pa_stream_notify_cb_t suspended_callback
;
173 void *suspended_userdata
;
174 pa_stream_notify_cb_t started_callback
;
175 void *started_userdata
;
178 typedef void (*pa_operation_cb_t
)(void);
180 struct pa_operation
{
186 PA_LLIST_FIELDS(pa_operation
);
188 pa_operation_state_t state
;
190 pa_operation_cb_t callback
;
192 void *private; /* some operations might need this */
195 void pa_command_request(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
196 void pa_command_stream_killed(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
197 void pa_command_subscribe_event(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
198 void pa_command_overflow_or_underflow(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
199 void pa_command_stream_suspended(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
200 void pa_command_stream_moved(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
201 void pa_command_stream_started(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
202 pa_operation
*pa_operation_new(pa_context
*c
, pa_stream
*s
, pa_operation_cb_t callback
, void *userdata
);
203 void pa_operation_done(pa_operation
*o
);
205 void pa_create_stream_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
206 void pa_stream_disconnect_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
207 void pa_context_simple_ack_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
208 void pa_stream_simple_ack_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
210 void pa_context_fail(pa_context
*c
, int error
);
211 int pa_context_set_error(pa_context
*c
, int error
);
212 void pa_context_set_state(pa_context
*c
, pa_context_state_t st
);
213 int pa_context_handle_error(pa_context
*c
, uint32_t command
, pa_tagstruct
*t
, pa_bool_t fail
);
214 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
);
216 void pa_stream_set_state(pa_stream
*s
, pa_stream_state_t st
);
218 pa_tagstruct
*pa_tagstruct_command(pa_context
*c
, uint32_t command
, uint32_t *tag
);
220 #define PA_CHECK_VALIDITY(context, expression, error) do { \
222 return -pa_context_set_error((context), (error)); \
226 #define PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, value) do { \
227 if (!(expression)) { \
228 pa_context_set_error((context), (error)); \
233 #define PA_CHECK_VALIDITY_RETURN_NULL(context, expression, error) PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, NULL)
235 void pa_init_proplist(pa_proplist
*p
);