1 #ifndef foointernalhfoo
2 #define foointernalhfoo
7 This file is part of PulseAudio.
9 PulseAudio 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.
14 PulseAudio 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.
19 You should have received a copy of the GNU Lesser General Public License
20 along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #include <pulse/mainloop-api.h>
26 #include <pulse/context.h>
27 #include <pulse/stream.h>
28 #include <pulse/operation.h>
29 #include <pulse/subscribe.h>
31 #include <pulsecore/socket-client.h>
32 #include <pulsecore/pstream.h>
33 #include <pulsecore/pdispatch.h>
34 #include <pulsecore/dynarray.h>
35 #include <pulsecore/llist.h>
36 #include <pulsecore/native-common.h>
37 #include <pulsecore/strlist.h>
38 #include <pulsecore/mcalign.h>
39 #include <pulsecore/memblockq.h>
40 #include <pulsecore/hashmap.h>
42 #include "client-conf.h"
44 #define DEFAULT_TIMEOUT (10)
50 pa_mainloop_api
* mainloop
;
52 pa_socket_client
*client
;
54 pa_pdispatch
*pdispatch
;
56 pa_dynarray
*record_streams
, *playback_streams
;
57 PA_LLIST_HEAD(pa_stream
, streams
);
58 PA_LLIST_HEAD(pa_operation
, operations
);
64 pa_context_state_t state
;
66 pa_context_notify_cb_t state_callback
;
69 pa_context_subscribe_cb_t subscribe_callback
;
70 void *subscribe_userdata
;
76 int autospawn_lock_fd
;
77 pa_spawn_api spawn_api
;
79 pa_strlist
*server_list
;
86 #define PA_MAX_WRITE_INDEX_CORRECTIONS 10
88 typedef struct pa_index_correction
{
92 int absolute
, corrupt
;
93 } pa_index_correction
;
98 pa_mainloop_api
*mainloop
;
99 PA_LLIST_FIELDS(pa_stream
);
102 pa_buffer_attr buffer_attr
;
103 pa_sample_spec sample_spec
;
104 pa_channel_map channel_map
;
105 pa_stream_flags_t flags
;
109 uint32_t device_index
;
110 pa_stream_direction_t direction
;
111 pa_stream_state_t state
;
113 uint32_t requested_bytes
;
115 pa_memchunk peek_memchunk
;
116 pa_memblockq
*record_memblockq
;
120 /* Store latest latency info */
121 pa_timing_info timing_info
;
122 int timing_info_valid
;
124 /* Use to make sure that time advances monotonically */
125 pa_usec_t previous_time
;
127 /* time updates with tags older than these are invalid */
128 uint32_t write_index_not_before
;
129 uint32_t read_index_not_before
;
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
;
135 /* Latency interpolation stuff */
136 pa_time_event
*auto_timing_update_event
;
137 int auto_timing_update_requested
;
139 pa_usec_t cached_time
;
140 int cached_time_valid
;
143 pa_stream_notify_cb_t state_callback
;
144 void *state_userdata
;
145 pa_stream_request_cb_t read_callback
;
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
;
157 typedef void (*pa_operation_cb_t
)(void);
159 struct pa_operation
{
164 PA_LLIST_FIELDS(pa_operation
);
166 pa_operation_state_t state
;
168 pa_operation_cb_t callback
;
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
);
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
);
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
);
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
);
190 void pa_stream_set_state(pa_stream
*s
, pa_stream_state_t st
);
192 pa_tagstruct
*pa_tagstruct_command(pa_context
*c
, uint32_t command
, uint32_t *tag
);
194 #define PA_CHECK_VALIDITY(context, expression, error) do { \
196 return -pa_context_set_error((context), (error)); \
200 #define PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, value) do { \
201 if (!(expression)) { \
202 pa_context_set_error((context), (error)); \
207 #define PA_CHECK_VALIDITY_RETURN_NULL(context, expression, error) PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, NULL)