[4172] | 1 | //vs.h: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010 |
---|
| 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 illigal 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 | |
---|
| 41 | struct roar_vs; |
---|
| 42 | |
---|
| 43 | typedef struct roar_vs roar_vs_t; |
---|
[4206] | 44 | typedef signed long int roar_mus_t; |
---|
[4172] | 45 | |
---|
[4204] | 46 | /* return readable string descriping the problem */ |
---|
[4172] | 47 | const char * roar_vs_strerr(int error); |
---|
| 48 | |
---|
[4204] | 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 | */ |
---|
[4172] | 53 | roar_vs_t * roar_vs_new_from_con(struct roar_connection * con, int * error); |
---|
[4204] | 54 | |
---|
| 55 | /* create a new VS object with a new connection */ |
---|
[4172] | 56 | roar_vs_t * roar_vs_new(const char * server, const char * name, int * error); |
---|
| 57 | |
---|
[4204] | 58 | /* start a the stream in the VS object */ |
---|
[4172] | 59 | int roar_vs_stream(roar_vs_t * vss, const struct roar_audio_info * info, int dir, int * error); |
---|
| 60 | |
---|
[4204] | 61 | /* connect to server and start stream in once |
---|
| 62 | * this is basicly roar_vs_new() and roar_vs_stream() in one function. |
---|
| 63 | */ |
---|
[4172] | 64 | roar_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 | |
---|
[4204] | 66 | /* create a VS object for playback. |
---|
| 67 | * This is roar_vs_new_simple() with direction set to 'playback' (wave form data) |
---|
| 68 | */ |
---|
[4172] | 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 | |
---|
[4204] | 71 | /* Boolean TRUE for VS functions */ |
---|
[4172] | 72 | #define ROAR_VS_TRUE 1 |
---|
[4204] | 73 | /* Boolean FALSE for VS functions */ |
---|
[4172] | 74 | #define ROAR_VS_FALSE 0 |
---|
[4204] | 75 | /* Boolean TOGGLE for VS functions */ |
---|
[4172] | 76 | #define ROAR_VS_TOGGLE -1 |
---|
[4204] | 77 | /* Boolean value used to ask for a value, do not change the value only ask for current value */ |
---|
[4172] | 78 | #define ROAR_VS_ASK -2 |
---|
| 79 | |
---|
[4204] | 80 | /* close and free the VS object |
---|
| 81 | * This does all needed cleanup. |
---|
| 82 | * If server connection was made by VS it is closed, too. |
---|
| 83 | * If server connectionw as provided by caller it is untouched. |
---|
| 84 | */ |
---|
[4172] | 85 | int roar_vs_close(roar_vs_t * vss, int killit, int * error); |
---|
| 86 | |
---|
[4204] | 87 | /* write data to a stream |
---|
| 88 | * This function writes some data to the stream. |
---|
| 89 | * return is number of bytes written or -1 on error. |
---|
| 90 | * return value can be zero to intercate no data can be written but no error. |
---|
| 91 | * this may be the case with non-blocking streams. |
---|
| 92 | * retruned value can be less then requested value. indecates a short write. |
---|
| 93 | * you should wait some (short!) time (for example one main loop interation) and try again. |
---|
| 94 | */ |
---|
[4172] | 95 | ssize_t roar_vs_write(roar_vs_t * vss, const void * buf, size_t len, int * error); |
---|
[4204] | 96 | |
---|
| 97 | /* read data from a stream |
---|
| 98 | * This function reads some data from the stream. |
---|
| 99 | * return is number of bytes read or -1 on error. |
---|
| 100 | * return value can be zero to intercate no data can be read but no error. |
---|
| 101 | * this may be the case with non-blocking streams. |
---|
| 102 | * retruned value can be less then requested value. indecates a short read. |
---|
| 103 | * you should wait some (short!) time (for example one main loop interation) and try again. |
---|
| 104 | */ |
---|
[4172] | 105 | ssize_t roar_vs_read (roar_vs_t * vss, void * buf, size_t len, int * error); |
---|
| 106 | |
---|
[4204] | 107 | /* wait value for waiting */ |
---|
[4172] | 108 | #define ROAR_VS_WAIT 1 |
---|
[4204] | 109 | /* wait value for no waiting */ |
---|
[4172] | 110 | #define ROAR_VS_NOWAIT 0 |
---|
| 111 | |
---|
[4204] | 112 | /* sync a stream with the server (flush buffers) |
---|
| 113 | * Returns 0 on no error and -1 on error. |
---|
| 114 | */ |
---|
[4172] | 115 | int roar_vs_sync (roar_vs_t * vss, int wait, int * error); |
---|
| 116 | |
---|
[4204] | 117 | /* set blocking mode of stream |
---|
| 118 | * returns old blocking state |
---|
| 119 | */ |
---|
[4172] | 120 | int roar_vs_blocking (roar_vs_t * vss, int val, int * error); |
---|
| 121 | |
---|
[4213] | 122 | /* default backend */ |
---|
[4172] | 123 | #define ROAR_VS_BACKEND_DEFAULT ROAR_VS_BACKEND_FIRST |
---|
[4213] | 124 | /* do not supply backend offset */ |
---|
[4172] | 125 | #define ROAR_VS_BACKEND_NONE -1 |
---|
[4213] | 126 | /* use first found primay stream of same mixer as offset source */ |
---|
[4172] | 127 | #define ROAR_VS_BACKEND_FIRST -2 |
---|
[4213] | 128 | /* use mean of primary streams of same mixer as offset source */ |
---|
[4172] | 129 | #define ROAR_VS_BACKEND_MEAN -3 |
---|
| 130 | |
---|
[4213] | 131 | /* get server's possition of stream |
---|
| 132 | * returns server's possition of the stream or -1 on error. |
---|
| 133 | * The retruned server possition is the possition in samples |
---|
| 134 | * plus a offset provided by the selected backend |
---|
| 135 | */ |
---|
[4206] | 136 | ssize_t roar_vs_position(roar_vs_t * vss, int backend, int * error); |
---|
| 137 | |
---|
[4213] | 138 | /* get latency between playback and local write counter |
---|
| 139 | * This function may fail because the used codec uses |
---|
| 140 | * non-fixed bitrate. |
---|
| 141 | * if this function fails it retruns zero and sets error or |
---|
| 142 | * clear error to ROAR_ERROR_NONE. |
---|
| 143 | * If non-zero is retruned error is untouched. |
---|
| 144 | * return value is in mu-sec (units of 10^-6s). |
---|
| 145 | * Note that the retruned value may be negative (the server being |
---|
| 146 | * ahead of us). This is normal in case we read a stream. |
---|
| 147 | */ |
---|
[4206] | 148 | roar_mus_t roar_vs_latency(roar_vs_t * vss, int backend, int * error); |
---|
[4172] | 149 | |
---|
[4204] | 150 | /* set pause flag |
---|
| 151 | * The pause flag should be set whenever the user presses the pause button or simular. |
---|
| 152 | * The stream may be come blocking after the pause flag has been set. |
---|
| 153 | * returns old pause setting (usefull with ROAR_VS_TOGGLE) |
---|
| 154 | */ |
---|
[4172] | 155 | int roar_vs_pause(roar_vs_t * vss, int val, int * error); |
---|
| 156 | |
---|
[4204] | 157 | /* set the mute flag of the stream |
---|
| 158 | * Thie pause flag should be set wehnever the user mutes the stream in some way. |
---|
| 159 | * This flag is used so the volume is not changed and can be restored by the server |
---|
| 160 | * while unmuting. |
---|
| 161 | * It is very recommended to use this flag and not just set the volume to zero |
---|
| 162 | * returns old mute setting (usefull with ROAR_VS_TOGGLE) |
---|
| 163 | */ |
---|
[4172] | 164 | int roar_vs_mute (roar_vs_t * vss, int val, int * error); |
---|
| 165 | |
---|
[4204] | 166 | /* set volume of stream (all channels to the same value) |
---|
| 167 | * volume c is float from 0 ('muted', see above) to 1 (full volume). |
---|
| 168 | * Returns 0 on no error and -1 on error. |
---|
| 169 | */ |
---|
[4172] | 170 | int roar_vs_volume_mono (roar_vs_t * vss, float c, int * error); |
---|
[4204] | 171 | /* set volume of stream (like volume + ballance, stereo mode) |
---|
| 172 | * volume l and r are floats from 0 ('muted', see above) to 1 (full volume). |
---|
| 173 | * Returns 0 on no error and -1 on error. |
---|
| 174 | */ |
---|
[4172] | 175 | int roar_vs_volume_stereo (roar_vs_t * vss, float l, float r, int * error); |
---|
| 176 | |
---|
[4204] | 177 | /* get volume from stream (like volume + ballance, stereo mode) |
---|
| 178 | * volume pinters l and r are floats from 0 ('muted', see above) to 1 (full volume). |
---|
| 179 | * Returns 0 on no error and -1 on error. |
---|
| 180 | * NOTE: if you want a 'mono' volume (like roar_vs_volume_mono() takes) |
---|
| 181 | * you can just use: c = (*l + *r)/2 |
---|
| 182 | */ |
---|
[4172] | 183 | int roar_vs_volume_get (roar_vs_t * vss, float * l, float * r, int * error); |
---|
| 184 | |
---|
[4204] | 185 | /* set an array of meta data for the stream |
---|
| 186 | * This sets an array of meta data stored in kv of length len for |
---|
| 187 | * the stream. |
---|
| 188 | * This should be called before streaming is started using read or write functions |
---|
| 189 | * but may be called at any time (for example to updata meta data). |
---|
| 190 | * Returns 0 on no error and -1 on error. |
---|
| 191 | * Example: |
---|
| 192 | * struct roar_keyval kv = {.key = "TITLE", .value = "Some artist"}; |
---|
| 193 | * ret = roar_vs_meta(vss, &kv, 1, &err); |
---|
| 194 | */ |
---|
[4172] | 195 | int roar_vs_meta (roar_vs_t * vss, struct roar_keyval * kv, size_t len, int * error); |
---|
| 196 | |
---|
[4212] | 197 | /* sets the stream role |
---|
| 198 | * see ../roaraudio/stream.h for possible roles |
---|
| 199 | * Returns 0 on no error and -1 on error. |
---|
| 200 | */ |
---|
| 201 | int roar_vs_role (roar_vs_t * vss, int role, int * error); |
---|
| 202 | |
---|
[4204] | 203 | /* Get used connection object |
---|
| 204 | * This may be usefull if you want to use functions from the main API. |
---|
| 205 | * Returns used connection object or NULL on error. |
---|
| 206 | */ |
---|
[4183] | 207 | struct roar_connection * roar_vs_connection_obj(roar_vs_t * vss, int * error); |
---|
[4204] | 208 | |
---|
| 209 | /* Get used stream object |
---|
| 210 | * This may be usefull if you want to use functions from the main API. |
---|
| 211 | * Returns used stream object or NULL on error. |
---|
| 212 | */ |
---|
[4183] | 213 | struct roar_stream * roar_vs_stream_obj (roar_vs_t * vss, int * error); |
---|
[4204] | 214 | |
---|
| 215 | /* Get used VIO object |
---|
| 216 | * This may be usefull if you want to use functions from the main API. |
---|
| 217 | * For example this can be used in non-blocking mode |
---|
| 218 | * to test if we can read or write. To test that use roar_vio_select(). |
---|
| 219 | * Returns used VIO object or NULL on error. |
---|
| 220 | */ |
---|
[4183] | 221 | struct roar_vio_calls * roar_vs_vio_obj (roar_vs_t * vss, int * error); |
---|
| 222 | |
---|
[4204] | 223 | /* send NOOP command to server |
---|
| 224 | * This can be used to ping the server. |
---|
| 225 | * This is of no use normaly. |
---|
| 226 | * Returns 0 on no error and -1 on error. |
---|
| 227 | */ |
---|
[4184] | 228 | #define roar_vs_noop(v, error) roar_noop(roar_vs_connection_obj((v), (error))) |
---|
| 229 | |
---|
[4172] | 230 | #endif |
---|
| 231 | |
---|
| 232 | //ll |
---|