]> code.delx.au - pulseaudio/blob - polyp/polyplib-def.h
Make the whole stuff LGPL only
[pulseaudio] / polyp / polyplib-def.h
1 #ifndef foopolyplibdefhfoo
2 #define foopolyplibdefhfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of polypaudio.
8
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
11 published by the Free Software Foundation; either version 2.1 of the
12 License, or (at your option) any later version.
13
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 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with polypaudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA.
23 ***/
24
25 #include <inttypes.h>
26 #include <sys/time.h>
27 #include <time.h>
28
29 #include "cdecl.h"
30 #include "sample.h"
31
32 /** \file
33 * Global definitions */
34
35 PA_C_DECL_BEGIN
36
37 /** The state of a connection context */
38 enum pa_context_state {
39 PA_CONTEXT_UNCONNECTED, /**< The context hasn't been connected yet */
40 PA_CONTEXT_CONNECTING, /**< A connection is being established */
41 PA_CONTEXT_AUTHORIZING, /**< The client is authorizing itself to the daemon */
42 PA_CONTEXT_SETTING_NAME, /**< The client is passing its application name to the daemon */
43 PA_CONTEXT_READY, /**< The connection is established, the context is ready to execute operations */
44 PA_CONTEXT_FAILED, /**< The connection failed or was disconnected */
45 PA_CONTEXT_TERMINATED /**< The connection was terminated cleanly */
46 };
47
48 /** The state of a stream */
49 enum pa_stream_state {
50 PA_STREAM_DISCONNECTED, /**< The stream is not yet connected to any sink or source */
51 PA_STREAM_CREATING, /**< The stream is being created */
52 PA_STREAM_READY, /**< The stream is established, you may pass audio data to it now */
53 PA_STREAM_FAILED, /**< An error occured that made the stream invalid */
54 PA_STREAM_TERMINATED /**< The stream has been terminated cleanly */
55 };
56
57 /** The state of an operation */
58 enum pa_operation_state {
59 PA_OPERATION_RUNNING, /**< The operation is still running */
60 PA_OPERATION_DONE, /**< The operation has been completed */
61 PA_OPERATION_CANCELED /**< The operation has been canceled */
62 };
63
64 /** An invalid index */
65 #define PA_INVALID_INDEX ((uint32_t) -1)
66
67 /** The direction of a pa_stream object */
68 enum pa_stream_direction {
69 PA_STREAM_NODIRECTION, /**< Invalid direction */
70 PA_STREAM_PLAYBACK, /**< Playback stream */
71 PA_STREAM_RECORD, /**< Record stream */
72 PA_STREAM_UPLOAD /**< Sample upload stream */
73 };
74
75 /** Some special flags for stream connections. \since 0.6 */
76 enum pa_stream_flags {
77 PA_STREAM_START_CORKED = 1, /**< Create the stream corked, requiring an explicit pa_stream_cork() call to uncork it. */
78 PA_STREAM_INTERPOLATE_LATENCY = 2 /**< Interpolate the latency for
79 * this stream. When enabled,
80 * you can use
81 * pa_stream_interpolated_xxx()
82 * for synchronization. Using
83 * these functions instead of
84 * pa_stream_get_latency() has
85 * the advantage of not
86 * requiring a whole roundtrip
87 * for responses. Consider using
88 * this option when frequently
89 * requesting latency
90 * information. This is
91 * especially useful on long latency
92 * network connections. */
93 };
94
95 /** Playback and record buffer metrics */
96 struct pa_buffer_attr{
97 uint32_t maxlength; /**< Maximum length of the buffer */
98 uint32_t tlength; /**< Playback only: target length of the buffer. The server tries to assure that at least tlength bytes are always available in the buffer */
99 uint32_t prebuf; /**< Playback only: pre-buffering. The server does not start with playback before at least prebug bytes are available in the buffer */
100 uint32_t minreq; /**< Playback only: minimum request. The server does not request less than minreq bytes from the client, instead waints until the buffer is free enough to request more bytes at once */
101 uint32_t fragsize; /**< Recording only: fragment size. The server sends data in blocks of fragsize bytes size. Large values deminish interactivity with other operations on the connection context but decrease control overhead. */
102 };
103
104 /** Error values as used by pa_context_errno(). Use pa_strerror() to convert these values to human readable strings */
105 enum {
106 PA_ERROR_OK, /**< No error */
107 PA_ERROR_ACCESS, /**< Access failure */
108 PA_ERROR_COMMAND, /**< Unknown command */
109 PA_ERROR_INVALID, /**< Invalid argument */
110 PA_ERROR_EXIST, /**< Entity exists */
111 PA_ERROR_NOENTITY, /**< No such entity */
112 PA_ERROR_CONNECTIONREFUSED, /**< Connection refused */
113 PA_ERROR_PROTOCOL, /**< Protocol error */
114 PA_ERROR_TIMEOUT, /**< Timeout */
115 PA_ERROR_AUTHKEY, /**< No authorization key */
116 PA_ERROR_INTERNAL, /**< Internal error */
117 PA_ERROR_CONNECTIONTERMINATED, /**< Connection terminated */
118 PA_ERROR_KILLED, /**< Entity killed */
119 PA_ERROR_INVALIDSERVER, /**< Invalid server */
120 PA_ERROR_INITFAILED, /**< Module initialization failed */
121 PA_ERROR_MAX /**< Not really an error but the first invalid error code */
122 };
123
124 /** Subscription event mask, as used by pa_context_subscribe() */
125 enum pa_subscription_mask {
126 PA_SUBSCRIPTION_MASK_NULL = 0, /**< No events */
127 PA_SUBSCRIPTION_MASK_SINK = 1, /**< Sink events */
128 PA_SUBSCRIPTION_MASK_SOURCE = 2, /**< Source events */
129 PA_SUBSCRIPTION_MASK_SINK_INPUT = 4, /**< Sink input events */
130 PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT = 8, /**< Source output events */
131 PA_SUBSCRIPTION_MASK_MODULE = 16, /**< Module events */
132 PA_SUBSCRIPTION_MASK_CLIENT = 32, /**< Client events */
133 PA_SUBSCRIPTION_MASK_SAMPLE_CACHE = 64, /**< Sample cache events */
134 PA_SUBSCRIPTION_MASK_SERVER = 128, /**< Other global server changes. \since 0.4 */
135 PA_SUBSCRIPTION_MASK_AUTOLOAD = 256 /**< Autoload table events. \since 0.5 */
136 };
137
138 /** Subscription event types, as used by pa_context_subscribe() */
139 enum pa_subscription_event_type {
140 PA_SUBSCRIPTION_EVENT_SINK = 0, /**< Event type: Sink */
141 PA_SUBSCRIPTION_EVENT_SOURCE = 1, /**< Event type: Source */
142 PA_SUBSCRIPTION_EVENT_SINK_INPUT = 2, /**< Event type: Sink input */
143 PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT = 3, /**< Event type: Source output */
144 PA_SUBSCRIPTION_EVENT_MODULE = 4, /**< Event type: Module */
145 PA_SUBSCRIPTION_EVENT_CLIENT = 5, /**< Event type: Client */
146 PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE = 6, /**< Event type: Sample cache item */
147 PA_SUBSCRIPTION_EVENT_SERVER = 7, /**< Event type: Global server change, only occuring with PA_SUBSCRIPTION_EVENT_CHANGE. \since 0.4 */
148 PA_SUBSCRIPTION_EVENT_AUTOLOAD = 8, /**< Event type: Autoload table changes. \since 0.5 */
149 PA_SUBSCRIPTION_EVENT_FACILITY_MASK = 15, /**< A mask to extract the event type from an event value */
150
151 PA_SUBSCRIPTION_EVENT_NEW = 0, /**< A new object was created */
152 PA_SUBSCRIPTION_EVENT_CHANGE = 16, /**< A property of the object was modified */
153 PA_SUBSCRIPTION_EVENT_REMOVE = 32, /**< An object was removed */
154 PA_SUBSCRIPTION_EVENT_TYPE_MASK = 16+32 /**< A mask to extract the event operation from an event value */
155 };
156
157 /** Return one if an event type t matches an event mask bitfield */
158 #define pa_subscription_match_flags(m, t) (!!((m) & (1 << ((t) & PA_SUBSCRIPTION_EVENT_FACILITY_MASK))))
159
160 /** A structure for latency info. See pa_stream_get_latency(). The
161 * total output latency a sample that is written with
162 * pa_stream_write() takes to be played may be estimated by
163 * sink_usec+buffer_usec+transport_usec. The output buffer to which
164 * buffer_usec relates may be manipulated freely (with
165 * pa_stream_write()'s delta argument, pa_stream_flush() and friends),
166 * the buffers sink_usec/source_usec relates to is a first-in
167 * first-out buffer which cannot be flushed or manipulated in any
168 * way. The total input latency a sample that is recorded takes to be
169 * delivered to the application is:
170 * source_usec+buffer_usec+transport_usec-sink_usec. (Take care of
171 * sign issues!) When connected to a monitor source sink_usec contains
172 * the latency of the owning sink.*/
173 struct pa_latency_info {
174 pa_usec_t buffer_usec; /**< Time in usecs the current buffer takes to play. For both playback and record streams. */
175 pa_usec_t sink_usec; /**< Time in usecs a sample takes to be played on the sink. For playback streams and record streams connected to a monitor source. */
176 pa_usec_t source_usec; /**< Time in usecs a sample takes from being recorded to being delivered to the application. Only for record streams. \since 0.5*/
177 pa_usec_t transport_usec; /**< Estimated time in usecs a sample takes to be transferred to/from the daemon. For both playback and record streams. \since 0.5 */
178 int playing; /**< Non-zero when the stream is currently playing. Only for playback streams. */
179 uint32_t queue_length; /**< Queue size in bytes. For both playback and recrd streams. */
180 int synchronized_clocks; /**< Non-zero if the local and the
181 * remote machine have synchronized
182 * clocks. If synchronized clocks are
183 * detected transport_usec becomes much
184 * more reliable. However, the code that
185 * detects synchronized clocks is very
186 * limited und unreliable itself. \since
187 * 0.5 */
188 struct timeval timestamp; /**< The time when this latency info was current */
189 uint64_t counter; /**< The byte counter current when the latency info was requested. \since 0.6 */
190 };
191
192 /** A structure for the spawn api. This may be used to integrate auto
193 * spawned daemons into your application. For more information see
194 * pa_context_connect(). When spawning a new child process the
195 * waitpid() is used on the child's PID. The spawn routine will not
196 * block or ignore SIGCHLD signals, since this cannot be done in a
197 * thread compatible way. You might have to do this in
198 * prefork/postfork. \since 0.4 */
199 struct pa_spawn_api {
200 void (*prefork)(void); /**< Is called just before the fork in the parent process. May be NULL. */
201 void (*postfork)(void); /**< Is called immediately after the fork in the parent process. May be NULL.*/
202 void (*atfork)(void); /**< Is called immediately after the
203 * fork in the child process. May be
204 * NULL. It is not safe to close all
205 * file descriptors in this function
206 * unconditionally, since a UNIX socket
207 * (created using socketpair()) is
208 * passed to the new process. */
209 };
210
211 PA_C_DECL_END
212
213 #endif