1 #ifndef foointernalhfoo
2 #define foointernalhfoo
7 This file is part of polypaudio.
9 polypaudio 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 polypaudio 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 polypaudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #include <polyp/mainloop-api.h>
26 #include <polyp/context.h>
27 #include <polyp/stream.h>
28 #include <polyp/operation.h>
29 #include <polyp/subscribe.h>
31 #include <polypcore/socket-client.h>
32 #include <polypcore/pstream.h>
33 #include <polypcore/pdispatch.h>
34 #include <polypcore/dynarray.h>
35 #include <polypcore/llist.h>
36 #include <polypcore/native-common.h>
37 #include <polypcore/strlist.h>
38 #include <polypcore/mcalign.h>
39 #include <polypcore/memblockq.h>
40 #include <polypcore/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
;
72 pa_memblock_stat
*memblock_stat
;
76 int autospawn_lock_fd
;
77 pa_spawn_api spawn_api
;
79 pa_strlist
*server_list
;
86 #define PA_MAX_LATENCY_CORRECTIONS 10
88 typedef struct pa_latency_correction
{
92 int absolute
, corrupt
;
93 } pa_latency_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 /* Latency correction stuff */
128 pa_latency_correction latency_corrections
[PA_MAX_LATENCY_CORRECTIONS
];
129 int idx_latency_correction
;
131 /* Latency interpolation stuff */
132 pa_time_event
*ipol_event
;
136 struct timeval ipol_timestamp
;
139 pa_stream_notify_cb_t state_callback
;
140 void *state_userdata
;
141 pa_stream_request_cb_t read_callback
;
143 pa_stream_request_cb_t write_callback
;
144 void *write_userdata
;
145 pa_stream_notify_cb_t overflow_callback
;
146 void *overflow_userdata
;
147 pa_stream_notify_cb_t underflow_callback
;
148 void *underflow_userdata
;
151 typedef void (*pa_operation_cb_t
)(void);
153 struct pa_operation
{
157 PA_LLIST_FIELDS(pa_operation
);
159 pa_operation_state_t state
;
161 pa_operation_cb_t callback
;
164 void pa_command_request(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
165 void pa_command_stream_killed(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
166 void pa_command_subscribe_event(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
167 void pa_command_overflow_or_underflow(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
169 pa_operation
*pa_operation_new(pa_context
*c
, pa_stream
*s
, pa_operation_cb_t callback
, void *userdata
);
170 void pa_operation_done(pa_operation
*o
);
172 void pa_create_stream_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
173 void pa_stream_disconnect_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
174 void pa_context_simple_ack_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
175 void pa_stream_simple_ack_callback(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
);
177 void pa_context_fail(pa_context
*c
, int error
);
178 int pa_context_set_error(pa_context
*c
, int error
);
179 void pa_context_set_state(pa_context
*c
, pa_context_state_t st
);
180 int pa_context_handle_error(pa_context
*c
, uint32_t command
, pa_tagstruct
*t
);
181 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
);
183 void pa_stream_set_state(pa_stream
*s
, pa_stream_state_t st
);
185 pa_tagstruct
*pa_tagstruct_command(pa_context
*c
, uint32_t command
, uint32_t *tag
);
187 #define PA_CHECK_VALIDITY(context, expression, error) do { \
189 return -pa_context_set_error((context), (error)); \
193 #define PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, value) do { \
194 if (!(expression)) { \
195 pa_context_set_error((context), (error)); \
200 #define PA_CHECK_VALIDITY_RETURN_NULL(context, expression, error) PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, NULL)