source: roaraudio/include/libroar/vs.h @ 5076:e5982ce08be1

Last change on this file since 5076:e5982ce08be1 was 5076:e5982ce08be1, checked in by phi, 13 years ago

commit what has been forgotten

File size: 13.2 KB
Line 
1//vs.h:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2011
5 *
6 *  This file is part of libroar a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  libroar is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illegal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#ifndef _LIBROARVS_H_
37#define _LIBROARVS_H_
38
39#include "libroar.h"
40
41struct roar_vs;
42
43typedef struct roar_vs roar_vs_t;
44typedef signed long int roar_mus_t;
45
46/* return readable string describing the problem */
47const char * roar_vs_strerr(int error);
48
49/* create a new VS object from normal RoarAudio connection object
50 * The connection must not be closed caller before roar_vs_close() is called.
51 * The connection is not closed by roar_vs_close().
52 */
53roar_vs_t * roar_vs_new_from_con(struct roar_connection * con, int * error);
54
55/* create a new VS object with a new connection */
56roar_vs_t * roar_vs_new(const char * server, const char * name, int * error);
57
58/* start a the stream in the VS object */
59int roar_vs_stream(roar_vs_t * vss, const struct roar_audio_info * info, int dir, int * error);
60
61/* connect to server and start stream in once
62 * this is basically roar_vs_new() and roar_vs_stream() in one function.
63 */
64roar_vs_t * roar_vs_new_simple(const char * server, const char * name, int rate, int channels, int codec, int bits, int dir, int * error);
65
66/* create a VS object for playback.
67 * This is roar_vs_new_simple() with direction set to 'playback' (wave form data)
68 */
69#define roar_vs_new_playback(s,n,r,c,e,b,error) roar_vs_new_simple((s), (n), (r), (c), (e), (b), ROAR_DIR_PLAY, (error))
70
71
72/* Attach a open file.
73 */
74
75int roar_vs_file(roar_vs_t * vss, struct roar_vio_calls * vio, int closefile, int * error);
76
77/* Open a file and attach it.
78 */
79int roar_vs_file_simple(roar_vs_t * vss, char * filename, int * error);
80
81/* Connects to a server to just play a file.
82 */
83roar_vs_t * roar_vs_new_from_file(const char * server, const char * name, char * filename, int * error);
84
85/* Switch to buffered mode.
86 * After swiching to buffered mode you can use the buffered
87 * mode functions. You must use roar_vs_iterate() to send data
88 * from local buffer to server.
89 * This is currently not thread safe but you may implement it in
90 * diffrent thread if you do the locking yourself.
91 * Takes the size for the used buffers as argument.
92 * Buffer size should be a value of 2^n. Typical values are 2048 and 4096.
93 */
94int roar_vs_buffer(roar_vs_t * vss, size_t buffer, int * error);
95
96
97/* Boolean TRUE for VS functions */
98#define ROAR_VS_TRUE     1
99/* Boolean FALSE for VS functions */
100#define ROAR_VS_FALSE    0
101/* Boolean TOGGLE for VS functions */
102#define ROAR_VS_TOGGLE  -1
103/* Boolean value used to ask for a value, do not change the value only ask for current value */
104#define ROAR_VS_ASK     -2
105
106/* close and free the VS object
107 * This does all needed cleanup.
108 * If server connection was made by VS it is closed, too.
109 * If server connection was provided by caller it is untouched.
110 */
111int roar_vs_close(roar_vs_t * vss, int killit, int * error);
112
113/* write data to a stream
114 * This function writes some data to the stream.
115 * return is number of bytes written or -1 on error.
116 * return value can be zero to indicate no data can be written but no error.
117 * this may be the case with non-blocking streams.
118 * returned value can be less then requested value. indicates a short write.
119 * you should wait some (short!) time (for example one main loop iteration) and try again.
120 */
121ssize_t roar_vs_write(roar_vs_t * vss, const void * buf, size_t len, int * error);
122
123/* read data from a stream
124 * This function reads some data from the stream.
125 * return is number of bytes read or -1 on error.
126 * return value can be zero to indicate no data can be read but no error.
127 * this may be the case with non-blocking streams.
128 * returned value can be less then requested value. indicates a short read.
129 * you should wait some (short!) time (for example one main loop iteration) and try again.
130 */
131ssize_t roar_vs_read (roar_vs_t * vss,       void * buf, size_t len, int * error);
132
133/* wait value for waiting */
134#define ROAR_VS_WAIT    1
135/* wait value for no waiting */
136#define ROAR_VS_NOWAIT  0
137/* Trigger action but do not wait for it to complet */
138#define ROAR_VS_ASYNC  -1
139
140/* sync a stream with the server (flush buffers)
141 * Returns 0 on no error and -1 on error.
142 */
143int     roar_vs_sync (roar_vs_t * vss, int wait, int * error);
144
145/* set blocking mode of stream
146 * returns old blocking state
147 */
148int     roar_vs_blocking (roar_vs_t * vss, int val, int * error);
149
150/* do not supply backend offset */
151#define ROAR_VS_BACKEND_NONE    -1
152/* use first found primary stream of same mixer as offset source */
153#define ROAR_VS_BACKEND_FIRST   -2
154/* use mean of primary streams of same mixer as offset source */
155#define ROAR_VS_BACKEND_MEAN    -3
156/* default backend, now handled at runtime, old value was hard coded to _FIRST */
157#define ROAR_VS_BACKEND_DEFAULT -4
158
159/* get server's position of stream
160 * returns server's position of the stream or -1 on error.
161 * The returned server position is the position in samples
162 * plus a offset provided by the selected backend
163 */
164ssize_t roar_vs_position(roar_vs_t * vss, int backend, int * error);
165
166/* get latency between playback and local write counter
167 * This function may fail because the used codec uses
168 * non-fixed bitrate.
169 * if this function fails it returns zero and sets error or
170 * clear error to ROAR_ERROR_NONE.
171 * If non-zero is returned error is untouched.
172 * return value is in mu-sec (units of 10^-6s).
173 * Note that the returned value may be negative (the server being
174 * ahead of us). This is normal in case we read a stream.
175 */
176roar_mus_t roar_vs_latency(roar_vs_t * vss, int backend, int * error);
177roar_mus_t roar_vs_latency2(roar_vs_t * vss, int backend, int wait, int * error);
178
179/* set pause flag
180 * The pause flag should be set whenever the user presses the pause button or similar.
181 * The stream may be come blocking after the pause flag has been set.
182 * returns old pause setting (useful with ROAR_VS_TOGGLE)
183 */
184int     roar_vs_pause(roar_vs_t * vss, int val, int * error);
185
186/* set the mute flag of the stream
187 * The pause flag should be set whenever the user mutes the stream in some way.
188 * This flag is used so the volume is not changed and can be restored by the server
189 * while unmuting.
190 * It is very recommended to use this flag and not just set the volume to zero
191 * returns old mute setting (useful with ROAR_VS_TOGGLE)
192 */
193int     roar_vs_mute (roar_vs_t * vss, int val, int * error);
194
195/* set volume of stream (all channels to the same value)
196 * volume c is float from 0 ('muted', see above) to 1 (full volume).
197 * Returns 0 on no error and -1 on error.
198 */
199int     roar_vs_volume_mono   (roar_vs_t * vss, float c, int * error);
200/* set volume of stream (like volume + balance, stereo mode)
201 * volume l and r are floats from 0 ('muted', see above) to 1 (full volume).
202 * Returns 0 on no error and -1 on error.
203 */
204int     roar_vs_volume_stereo (roar_vs_t * vss, float l, float r, int * error);
205
206/* get volume from stream (like volume + balance, stereo mode)
207 * volume pointers l and r are floats from 0 ('muted', see above) to 1 (full volume).
208 * Returns 0 on no error and -1 on error.
209 * NOTE: if you want a 'mono' volume (like roar_vs_volume_mono() takes)
210 * you can just use: c = (*l + *r)/2
211 */
212int     roar_vs_volume_get    (roar_vs_t * vss, float * l, float * r, int * error);
213
214/* set an array of meta data for the stream
215 * This sets an array of meta data stored in kv of length len for
216 * the stream.
217 * This should be called before streaming is started using read or write functions
218 * but may be called at any time (for example to updata meta data).
219 * Returns 0 on no error and -1 on error.
220 * Example:
221 * struct roar_keyval kv = {.key = "TITLE", .value = "Some title"};
222 * ret = roar_vs_meta(vss, &kv, 1, &err);
223 */
224int     roar_vs_meta          (roar_vs_t * vss, struct roar_keyval * kv, size_t len, int * error);
225
226/* sets the stream role
227 * see ../roaraudio/stream.h for possible roles
228 * Returns 0 on no error and -1 on error.
229 */
230int     roar_vs_role          (roar_vs_t * vss, int role, int * error);
231
232/* Run a single iteration.
233 * This will try to read data from source, write it to the stream
234 * and flush the buffer in buffered mode.
235 * Returns -1 on error, 0 on EOF and positive true value on no error.
236 */
237int     roar_vs_iterate       (roar_vs_t * vss, int wait, int * error);
238
239/* Iterate until EOF or error.
240 * Very simple main loop.
241 * Returns 0 on no error and -1 on error.
242 */
243int     roar_vs_run           (roar_vs_t * vss, int * error);
244
245ssize_t roar_vs_get_avail_read(roar_vs_t * vss, int * error);
246ssize_t roar_vs_get_avail_write(roar_vs_t * vss, int * error);
247
248/* If in buffered mode drop all data from internal buffer.
249 * This drops all data in current ringbuffers. You can
250 * select if data is only droped in write or read buffer.
251 * This may be usefull in case of seeking and such
252 * but should be avoided as it may break the bitstream.
253 */
254int     roar_vs_reset_buffer(roar_vs_t * vss, int writering, int readring, int * error);
255
256/* Misc controls.
257 * Use of this should be avoided by application.
258 */
259
260enum roar_vs_ctlcmd {
261 ROAR_VS_CMD_NOOP      = 0,
262#define ROAR_VS_CMD_NOOP ROAR_VS_CMD_NOOP
263 ROAR_VS_CMD_SET_MIXER,
264#define ROAR_VS_CMD_SET_MIXER ROAR_VS_CMD_SET_MIXER
265 ROAR_VS_CMD_GET_MIXER,
266#define ROAR_VS_CMD_GET_MIXER ROAR_VS_CMD_GET_MIXER
267 ROAR_VS_CMD_SET_FIRST_PRIM,
268#define ROAR_VS_CMD_SET_FIRST_PRIM ROAR_VS_CMD_SET_FIRST_PRIM
269 ROAR_VS_CMD_GET_FIRST_PRIM,
270#define ROAR_VS_CMD_GET_FIRST_PRIM ROAR_VS_CMD_GET_FIRST_PRIM
271
272 // Latency control:
273 ROAR_VS_CMD_SET_LATC_P,
274#define ROAR_VS_CMD_SET_LATC_P ROAR_VS_CMD_SET_LATC_P
275 ROAR_VS_CMD_GET_LATC_P,
276#define ROAR_VS_CMD_GET_LATC_P ROAR_VS_CMD_GET_LATC_P
277 ROAR_VS_CMD_SET_LATC_TARGET,
278#define ROAR_VS_CMD_SET_LATC_TARGET ROAR_VS_CMD_SET_LATC_TARGET
279 ROAR_VS_CMD_GET_LATC_TARGET,
280#define ROAR_VS_CMD_GET_LATC_TARGET ROAR_VS_CMD_GET_LATC_TARGET
281 ROAR_VS_CMD_SET_LATC_WINDOW,
282#define ROAR_VS_CMD_SET_LATC_WINDOW ROAR_VS_CMD_SET_LATC_WINDOW
283 ROAR_VS_CMD_GET_LATC_WINDOW,
284#define ROAR_VS_CMD_GET_LATC_WINDOW ROAR_VS_CMD_GET_LATC_WINDOW
285 ROAR_VS_CMD_SET_LATC_MINLAG,
286#define ROAR_VS_CMD_SET_LATC_MINLAG ROAR_VS_CMD_SET_LATC_MINLAG
287 ROAR_VS_CMD_GET_LATC_MINLAG,
288#define ROAR_VS_CMD_GET_LATC_MINLAG ROAR_VS_CMD_GET_LATC_MINLAG
289
290 // Volume:
291 ROAR_VS_CMD_SET_FREE_VOLUME,
292#define ROAR_VS_CMD_SET_FREE_VOLUME ROAR_VS_CMD_SET_FREE_VOLUME
293 ROAR_VS_CMD_GET_FREE_VOLUME,
294#define ROAR_VS_CMD_GET_FREE_VOLUME ROAR_VS_CMD_GET_FREE_VOLUME
295
296 // auto pause flag, needed for sync streams:
297 ROAR_VS_CMD_SET_DEFAULT_PAUSED,
298#define ROAR_VS_CMD_SET_DEFAULT_PAUSED ROAR_VS_CMD_SET_DEFAULT_PAUSED
299 ROAR_VS_CMD_GET_DEFAULT_PAUSED,
300#define ROAR_VS_CMD_GET_DEFAULT_PAUSED ROAR_VS_CMD_GET_DEFAULT_PAUSED
301
302 // Async operation:
303 ROAR_VS_CMD_SET_ASYNC,
304#define ROAR_VS_CMD_SET_ASYNC ROAR_VS_CMD_SET_ASYNC
305 ROAR_VS_CMD_GET_ASYNC,
306#define ROAR_VS_CMD_GET_ASYNC ROAR_VS_CMD_GET_ASYNC
307 ROAR_VS_CMD_LOCK_ASYNC,
308#define ROAR_VS_CMD_LOCK_ASYNC ROAR_VS_CMD_LOCK_ASYNC
309 ROAR_VS_CMD_UNLOCK_ASYNC,
310#define ROAR_VS_CMD_UNLOCK_ASYNC ROAR_VS_CMD_UNLOCK_ASYNC
311};
312
313typedef enum roar_vs_ctlcmd roar_vs_ctlcmd;
314
315int     roar_vs_ctl           (roar_vs_t * vss, roar_vs_ctlcmd cmd, void * argp, int * error);
316
317
318/* Get used connection object
319 * This may be useful if you want to use functions from the main API.
320 * Returns used connection object or NULL on error.
321 */
322struct roar_connection * roar_vs_connection_obj(roar_vs_t * vss, int * error);
323
324/* Get used stream object
325 * This may be useful if you want to use functions from the main API.
326 * Returns used stream object or NULL on error.
327 */
328struct roar_stream     * roar_vs_stream_obj    (roar_vs_t * vss, int * error);
329
330/* Get used VIO object
331 * This may be useful if you want to use functions from the main API.
332 * For example this can be used in non-blocking mode
333 * to test if we can read or write. To test that use roar_vio_select().
334 * Returns used VIO object or NULL on error.
335 */
336struct roar_vio_calls  * roar_vs_vio_obj       (roar_vs_t * vss, int * error);
337
338/* send NOOP command to server
339 * This can be used to ping the server.
340 * This is of no use normally.
341 * Returns 0 on no error and -1 on error.
342 */
343#define roar_vs_noop(v, error) roar_noop(roar_vs_connection_obj((v), (error)))
344
345#endif
346
347//ll
Note: See TracBrowser for help on using the repository browser.