[2292] | 1 | //roarphone.c: |
---|
[2124] | 2 | |
---|
| 3 | /* |
---|
[2282] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009 |
---|
[2124] | 5 | * |
---|
| 6 | * This file is part of roarclients 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 | * RoarAudio 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, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #include <roaraudio.h> |
---|
[2185] | 26 | #include <libroardsp/libroardsp.h> |
---|
[2282] | 27 | #include <libroareio/libroareio.h> |
---|
[2124] | 28 | |
---|
[2215] | 29 | #if defined(ROAR_HAVE_LIBSPEEX) && !defined(ROAR_HAVE_LIBSPEEXDSP) |
---|
| 30 | #define _SPEEX_API_OLD |
---|
| 31 | #elif defined(ROAR_HAVE_LIBSPEEX) && defined(ROAR_HAVE_LIBSPEEXDSP) |
---|
| 32 | #define _SPEEX_API_NEW |
---|
| 33 | #endif |
---|
| 34 | |
---|
| 35 | #ifdef _SPEEX_API_OLD |
---|
[2141] | 36 | #include <speex/speex_echo.h> |
---|
| 37 | #endif |
---|
| 38 | |
---|
| 39 | #define TIMEDIV 100 |
---|
[2124] | 40 | |
---|
[2125] | 41 | #define DRIVER "oss" |
---|
| 42 | |
---|
[2140] | 43 | // anti echo: |
---|
| 44 | #define AE_NONE 0 |
---|
| 45 | #define AE_SIMPLE 1 |
---|
| 46 | #define AE_SPEEX 2 |
---|
[2141] | 47 | #define AE_ROARD 3 |
---|
[2140] | 48 | |
---|
[2322] | 49 | #define DTX_F 25 |
---|
| 50 | |
---|
[2329] | 51 | #define CON_NONE 0x00 |
---|
| 52 | #define CON_CON 0x01 |
---|
| 53 | #define CON_STREAM 0x02 |
---|
| 54 | |
---|
[2140] | 55 | struct { |
---|
| 56 | int antiecho; |
---|
[2166] | 57 | int samples; |
---|
[2167] | 58 | int transcode; |
---|
[2321] | 59 | int64_t dtx_threshold; |
---|
[2140] | 60 | } g_conf; |
---|
| 61 | |
---|
[2322] | 62 | int dtx_counter = 0; |
---|
| 63 | |
---|
[2329] | 64 | struct { |
---|
| 65 | int state; |
---|
| 66 | struct roar_connection con; |
---|
| 67 | struct roar_stream stream; |
---|
| 68 | struct roar_vio_calls * svio; |
---|
| 69 | } g_cons; |
---|
| 70 | |
---|
[2185] | 71 | struct roar_bixcoder transcoder[1]; |
---|
| 72 | |
---|
[2330] | 73 | struct { |
---|
| 74 | struct { |
---|
| 75 | char key[ROAR_META_MAX_NAMELEN]; |
---|
| 76 | char value[LIBROAR_BUFFER_MSGDATA]; |
---|
| 77 | } tmp; |
---|
| 78 | char * rn; |
---|
| 79 | char * nick; |
---|
| 80 | char * org; |
---|
| 81 | char * email; |
---|
| 82 | char * hp; |
---|
| 83 | char * loc; |
---|
| 84 | char * thumbnail; |
---|
| 85 | } g_meta; |
---|
| 86 | |
---|
[2124] | 87 | void usage (void) { |
---|
[2292] | 88 | printf("roarphone [OPTIONS]...\n"); |
---|
[2124] | 89 | |
---|
[2330] | 90 | printf("\nServer Options:\n\n"); |
---|
[2124] | 91 | |
---|
[2141] | 92 | printf(" --server SERVER - Set server hostname\n" |
---|
[2330] | 93 | ); |
---|
| 94 | |
---|
| 95 | printf("\nAudio Options:\n\n"); |
---|
| 96 | printf(" --rate RATE - Set sample rate\n" |
---|
[2141] | 97 | " --bits BITS - Set bits per sample\n" |
---|
| 98 | " --chans CHANNELS - Set number of channels\n" |
---|
[2330] | 99 | ); |
---|
| 100 | |
---|
| 101 | printf("\nCodec Options:\n\n"); |
---|
| 102 | printf(" --codec CODEC - Set the codec\n" |
---|
| 103 | " --transcode - Use local transcodeing\n" |
---|
| 104 | ); |
---|
| 105 | |
---|
| 106 | printf("\nDriver Options:\n\n"); |
---|
| 107 | printf(" --driver DRIVER - Set the driver\n" |
---|
[2141] | 108 | " --device DEVICE - Set the device\n" |
---|
[2330] | 109 | ); |
---|
| 110 | |
---|
| 111 | printf("\nGeneral Options:\n\n"); |
---|
| 112 | printf(" --antiecho AEMODE - Set the anti echo mode\n" |
---|
[2321] | 113 | " --threshold DTXTHRES - Set the DTX threshold, disabled by default\n" |
---|
[2141] | 114 | " --help - Show this help\n" |
---|
[2124] | 115 | ); |
---|
| 116 | |
---|
[2330] | 117 | printf("\nMeta Data Options:\n\n"); |
---|
| 118 | printf(" --m-rn REALNAME - Sets the real name\n" |
---|
| 119 | " --m-nick NICK - Sets the nick name\n" |
---|
| 120 | " --m-email EMAIL - Sets the email address\n" |
---|
| 121 | " --m-hp HOMEPAGE - Sets the homepage URL\n" |
---|
| 122 | " --m-thumbn THUMBNAIL - Sets a URL to a thumbnail\n" |
---|
| 123 | " --m-loc LOCATION - Sets the location (room number)\n" |
---|
| 124 | " --m-org ORGANIZATION - Sets the organization/company name\n" |
---|
| 125 | ); |
---|
[2124] | 126 | } |
---|
| 127 | |
---|
[2128] | 128 | int open_stream (struct roar_vio_calls * vio, char * server, struct roar_audio_info * info) { |
---|
[2329] | 129 | int fh; |
---|
| 130 | |
---|
| 131 | g_cons.svio = vio; |
---|
| 132 | |
---|
| 133 | if ( !(g_cons.state & CON_CON) ) |
---|
| 134 | if ( roar_simple_connect(&(g_cons.con), server, "roarphone") == -1 ) |
---|
| 135 | return -1; |
---|
| 136 | |
---|
| 137 | g_cons.state |= CON_CON; |
---|
| 138 | |
---|
| 139 | // TODO: find out if this can be done more nicely by using VIOs |
---|
| 140 | |
---|
| 141 | if ( (fh = roar_simple_new_stream_obj(&(g_cons.con), &(g_cons.stream), |
---|
| 142 | info->rate, info->channels, info->bits, info->codec, |
---|
| 143 | ROAR_DIR_BIDIR |
---|
| 144 | )) == -1 ) |
---|
| 145 | return -1; |
---|
| 146 | |
---|
| 147 | roar_vio_open_fh_socket(vio, fh); |
---|
| 148 | |
---|
| 149 | g_cons.state |= CON_STREAM; |
---|
| 150 | |
---|
| 151 | return 0; |
---|
[2128] | 152 | } |
---|
| 153 | |
---|
[2330] | 154 | #define _SET_META(ivar,itype) if ( (ivar) != NULL ) { \ |
---|
| 155 | meta.value = (ivar); \ |
---|
| 156 | meta.type = (itype); \ |
---|
| 157 | roar_stream_meta_set(&(g_cons.con), &(g_cons.stream), ROAR_META_MODE_SET, &meta); \ |
---|
| 158 | } |
---|
| 159 | int set_meta (void) { |
---|
| 160 | struct roar_meta meta; |
---|
| 161 | |
---|
| 162 | meta.value = g_meta.tmp.value; |
---|
| 163 | meta.key[0] = 0; |
---|
| 164 | meta.type = ROAR_META_TYPE_NONE; |
---|
| 165 | |
---|
| 166 | roar_stream_meta_set(&(g_cons.con), &(g_cons.stream), ROAR_META_MODE_CLEAR, &meta); |
---|
| 167 | |
---|
| 168 | _SET_META(g_meta.thumbnail, ROAR_META_TYPE_THUMBNAIL); |
---|
| 169 | _SET_META(g_meta.loc, ROAR_META_TYPE_LOCATION); |
---|
| 170 | _SET_META(g_meta.hp, ROAR_META_TYPE_HOMEPAGE); |
---|
| 171 | _SET_META(g_meta.org, ROAR_META_TYPE_ORGANIZATION); |
---|
| 172 | |
---|
| 173 | if ( g_meta.nick != NULL ) { |
---|
| 174 | if ( g_meta.rn != NULL ) { |
---|
| 175 | snprintf(g_meta.tmp.value, LIBROAR_BUFFER_MSGDATA-1, "%s (%s)", g_meta.rn, g_meta.nick); |
---|
| 176 | g_meta.tmp.value[LIBROAR_BUFFER_MSGDATA-1] = 0; |
---|
| 177 | _SET_META(g_meta.tmp.value, ROAR_META_TYPE_AUTHOR); |
---|
| 178 | } else { |
---|
| 179 | _SET_META(g_meta.nick, ROAR_META_TYPE_AUTHOR); |
---|
| 180 | } |
---|
| 181 | } else { |
---|
| 182 | if ( g_meta.rn != NULL ) { |
---|
| 183 | _SET_META(g_meta.rn, ROAR_META_TYPE_AUTHOR); |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | // TODO: make this more nice... |
---|
| 188 | if ( g_meta.email != NULL ) { |
---|
| 189 | if ( g_meta.nick != NULL ) { |
---|
| 190 | if ( g_meta.rn != NULL ) { |
---|
| 191 | snprintf(g_meta.tmp.value, LIBROAR_BUFFER_MSGDATA-1, "%s (%s) <%s>", g_meta.rn, g_meta.nick, g_meta.email); |
---|
| 192 | } else { |
---|
| 193 | snprintf(g_meta.tmp.value, LIBROAR_BUFFER_MSGDATA-1, "%s <%s>", g_meta.nick, g_meta.email); |
---|
| 194 | } |
---|
| 195 | } else { |
---|
| 196 | if ( g_meta.rn != NULL ) { |
---|
| 197 | snprintf(g_meta.tmp.value, LIBROAR_BUFFER_MSGDATA-1, "%s <%s>", g_meta.rn, g_meta.email); |
---|
| 198 | } else { |
---|
| 199 | snprintf(g_meta.tmp.value, LIBROAR_BUFFER_MSGDATA-1, "<%s>", g_meta.email); |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | g_meta.tmp.value[LIBROAR_BUFFER_MSGDATA-1] = 0; |
---|
| 203 | _SET_META(g_meta.tmp.value, ROAR_META_TYPE_CONTACT); |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | return 0; |
---|
| 207 | } |
---|
| 208 | |
---|
[2215] | 209 | #ifdef _SPEEX_API_OLD |
---|
[2141] | 210 | int anti_echo_speex16(int16_t * buf, int16_t * aebuf, size_t len, struct roar_audio_info * info) { |
---|
| 211 | static SpeexEchoState * state = NULL; |
---|
| 212 | size_t samples = info->rate / TIMEDIV; |
---|
| 213 | static int16_t * obuf = NULL; |
---|
| 214 | |
---|
| 215 | if ( info->channels != 1 ) |
---|
| 216 | return -1; |
---|
| 217 | |
---|
| 218 | if (len != samples) |
---|
| 219 | return -1; |
---|
| 220 | |
---|
[2142] | 221 | ROAR_DBG("anti_echo_speex16(*) = ?"); |
---|
| 222 | |
---|
[2141] | 223 | if ( state == NULL ) { |
---|
| 224 | if ( (state = speex_echo_state_init(samples, 100*samples)) == NULL ) |
---|
| 225 | return -1; |
---|
| 226 | |
---|
| 227 | // todo: set sample rate. |
---|
| 228 | } |
---|
| 229 | |
---|
[2142] | 230 | ROAR_DBG("anti_echo_speex16(*) = ?"); |
---|
| 231 | |
---|
[2141] | 232 | if ( obuf == NULL ) { |
---|
| 233 | if ( (obuf = malloc(2*samples)) == NULL ) |
---|
| 234 | return -1; |
---|
| 235 | } |
---|
| 236 | |
---|
[2142] | 237 | ROAR_DBG("anti_echo_speex16(*) = ?"); |
---|
| 238 | |
---|
[2141] | 239 | /* |
---|
| 240 | speex_echo_cancellation(state, buf, aebuf, obuf); |
---|
| 241 | */ |
---|
| 242 | |
---|
| 243 | speex_echo_cancel(state, buf, aebuf, obuf, NULL); |
---|
| 244 | |
---|
| 245 | memcpy(buf, obuf, 2*samples); |
---|
| 246 | |
---|
[2142] | 247 | ROAR_DBG("anti_echo_speex16(*) = 0"); |
---|
| 248 | |
---|
[2141] | 249 | return 0; |
---|
| 250 | } |
---|
| 251 | #endif |
---|
| 252 | |
---|
| 253 | int anti_echo16(int16_t * buf, int16_t * aebuf, size_t len, struct roar_audio_info * info) { |
---|
[2140] | 254 | size_t i; |
---|
| 255 | |
---|
| 256 | switch (g_conf.antiecho) { |
---|
| 257 | case AE_NONE: |
---|
| 258 | return 0; |
---|
| 259 | break; |
---|
| 260 | case AE_SIMPLE: |
---|
| 261 | for (i = 0; i < len; i++) |
---|
| 262 | buf[i] -= aebuf[i]; |
---|
[2293] | 263 | return 0; |
---|
[2140] | 264 | break; |
---|
[2215] | 265 | #ifdef _SPEEX_API_OLD |
---|
[2141] | 266 | case AE_SPEEX: |
---|
| 267 | return anti_echo_speex16(buf, aebuf, len, info); |
---|
| 268 | break; |
---|
| 269 | #endif |
---|
[2293] | 270 | case AE_ROARD: |
---|
| 271 | return 0; |
---|
| 272 | break; |
---|
[2140] | 273 | default: |
---|
| 274 | return -1; |
---|
| 275 | break; |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | return -1; |
---|
| 279 | } |
---|
| 280 | |
---|
[2321] | 281 | int zero_if_noise16 (int16_t * data, size_t samples) { |
---|
| 282 | int64_t rms = roar_rms2_1_16(data, samples); |
---|
| 283 | |
---|
[2322] | 284 | if ( rms < g_conf.dtx_threshold ) { |
---|
| 285 | if ( dtx_counter ) { |
---|
| 286 | dtx_counter--; |
---|
| 287 | } else { |
---|
| 288 | memset(data, 0, samples*2); |
---|
| 289 | } |
---|
| 290 | } else { |
---|
| 291 | dtx_counter = DTX_F; |
---|
| 292 | } |
---|
[2321] | 293 | |
---|
| 294 | return 0; |
---|
| 295 | } |
---|
| 296 | |
---|
[2128] | 297 | int run_stream (struct roar_vio_calls * s0, struct roar_vio_calls * s1, struct roar_audio_info * info) { |
---|
[2129] | 298 | size_t len; |
---|
[2140] | 299 | void * outbuf, * micbuf; |
---|
| 300 | ssize_t outlen, miclen; |
---|
[2129] | 301 | |
---|
[2312] | 302 | ROAR_DBG("run_stream(*): g_conf.samples = %i, info->bits = %i", g_conf.samples, info->bits); |
---|
[2166] | 303 | len = g_conf.samples * info->bits / 8; |
---|
[2312] | 304 | ROAR_DBG("run_stream(*): len=%lu", (unsigned long) len); |
---|
[2129] | 305 | |
---|
[2140] | 306 | if ( (outbuf = malloc(2*len)) == NULL ) |
---|
[2129] | 307 | return -1; |
---|
| 308 | |
---|
[2140] | 309 | micbuf = outbuf + len; |
---|
| 310 | |
---|
[2129] | 311 | while (1) { |
---|
[2140] | 312 | if ( (miclen = roar_vio_read(s0, micbuf, len)) <= 0 ) |
---|
[2129] | 313 | break; |
---|
[2321] | 314 | |
---|
| 315 | if ( g_conf.dtx_threshold > 0 ) |
---|
| 316 | if ( info->bits == 16 ) |
---|
| 317 | zero_if_noise16(micbuf, miclen/2); |
---|
| 318 | |
---|
[2185] | 319 | if ( g_conf.transcode ) { |
---|
| 320 | if ( roar_bixcoder_write_packet(transcoder, micbuf, miclen) == -1 ) |
---|
| 321 | break; |
---|
| 322 | } else { |
---|
| 323 | if ( roar_vio_write(s1, micbuf, miclen) != miclen ) |
---|
| 324 | break; |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | if ( g_conf.transcode ) { |
---|
[2312] | 328 | ROAR_DBG("run_stream(*): outbuf=%p, len=%lu", outbuf, (unsigned long) len); |
---|
[2185] | 329 | if ( roar_bixcoder_read_packet(transcoder, outbuf, len) == -1 ) |
---|
| 330 | break; |
---|
| 331 | |
---|
| 332 | outlen = len; |
---|
| 333 | } else { |
---|
| 334 | if ( (outlen = roar_vio_read(s1, outbuf, len)) <= 0 ) |
---|
| 335 | break; |
---|
| 336 | } |
---|
[2140] | 337 | |
---|
[2162] | 338 | if ( g_conf.antiecho != AE_NONE && info->bits == 16 ) |
---|
[2141] | 339 | anti_echo16(outbuf, micbuf, ROAR_MIN(miclen, outlen)/2, info); |
---|
[2140] | 340 | |
---|
| 341 | if ( roar_vio_write(s0, outbuf, outlen) != outlen ) |
---|
[2129] | 342 | break; |
---|
| 343 | } |
---|
| 344 | |
---|
[2140] | 345 | free(outbuf); |
---|
[2129] | 346 | |
---|
| 347 | return 0; |
---|
[2128] | 348 | } |
---|
| 349 | |
---|
[2124] | 350 | int main (int argc, char * argv[]) { |
---|
[2125] | 351 | struct roar_audio_info info = {.rate = ROAR_RATE_DEFAULT, |
---|
| 352 | .bits = ROAR_BITS_DEFAULT, |
---|
| 353 | .channels = ROAR_CHANNELS_DEFAULT, |
---|
| 354 | .codec = ROAR_CODEC_DEFAULT |
---|
| 355 | }; |
---|
[2167] | 356 | struct roar_audio_info dinfo; |
---|
[2128] | 357 | struct roar_vio_calls dvio, svio; |
---|
[2126] | 358 | char * driver = DRIVER; |
---|
| 359 | char * device = NULL; |
---|
[2124] | 360 | char * server = NULL; |
---|
| 361 | char * k; |
---|
| 362 | int i; |
---|
| 363 | |
---|
[2140] | 364 | memset(&g_conf, 0, sizeof(g_conf)); |
---|
| 365 | |
---|
[2321] | 366 | g_conf.antiecho = AE_ROARD; |
---|
| 367 | g_conf.dtx_threshold = -1; |
---|
[2140] | 368 | |
---|
[2329] | 369 | memset(&g_cons, 0, sizeof(g_cons)); |
---|
| 370 | g_cons.state = CON_NONE; |
---|
| 371 | |
---|
[2330] | 372 | memset(&g_meta, 0, sizeof(g_meta)); |
---|
| 373 | |
---|
[2124] | 374 | for (i = 1; i < argc; i++) { |
---|
| 375 | k = argv[i]; |
---|
| 376 | |
---|
| 377 | if ( strcmp(k, "--server") == 0 ) { |
---|
| 378 | server = argv[++i]; |
---|
| 379 | } else if ( strcmp(k, "--rate") == 0 ) { |
---|
[2125] | 380 | info.rate = atoi(argv[++i]); |
---|
[2124] | 381 | } else if ( strcmp(k, "--bits") == 0 ) { |
---|
[2125] | 382 | info.bits = atoi(argv[++i]); |
---|
[2124] | 383 | } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 ) { |
---|
[2125] | 384 | info.channels = atoi(argv[++i]); |
---|
[2124] | 385 | } else if ( strcmp(k, "--codec") == 0 ) { |
---|
[2125] | 386 | info.codec = roar_str2codec(argv[++i]); |
---|
[2127] | 387 | } else if ( strcmp(k, "--driver") == 0 ) { |
---|
| 388 | driver = argv[++i]; |
---|
| 389 | } else if ( strcmp(k, "--device") == 0 ) { |
---|
| 390 | device = argv[++i]; |
---|
[2141] | 391 | } else if ( strcmp(k, "--antiecho") == 0 ) { |
---|
| 392 | k = argv[++i]; |
---|
| 393 | if ( !strcmp(k, "none") ) { |
---|
| 394 | g_conf.antiecho = AE_NONE; |
---|
| 395 | } else if ( !strcmp(k, "simple") ) { |
---|
| 396 | g_conf.antiecho = AE_SIMPLE; |
---|
| 397 | } else if ( !strcmp(k, "speex") ) { |
---|
| 398 | g_conf.antiecho = AE_SPEEX; |
---|
| 399 | } else if ( !strcmp(k, "roard") ) { |
---|
| 400 | g_conf.antiecho = AE_ROARD; |
---|
| 401 | } else { |
---|
| 402 | fprintf(stderr, "Error: unknown mode: %s\n", k); |
---|
| 403 | return 1; |
---|
| 404 | } |
---|
[2321] | 405 | } else if ( strcmp(k, "--threshold") == 0 ) { |
---|
| 406 | g_conf.dtx_threshold = atol(argv[++i]); |
---|
| 407 | |
---|
| 408 | // use threshold^2 or threshold < 0 for not using DTX |
---|
| 409 | if ( g_conf.dtx_threshold > 0 ) |
---|
| 410 | g_conf.dtx_threshold *= g_conf.dtx_threshold; |
---|
[2167] | 411 | } else if ( strcmp(k, "--transcode") == 0 ) { |
---|
| 412 | g_conf.transcode = 1; |
---|
[2330] | 413 | |
---|
| 414 | // META DATA: |
---|
| 415 | } else if ( strcmp(k, "--m-rn") == 0 ) { |
---|
| 416 | g_meta.rn = argv[++i]; |
---|
| 417 | } else if ( strcmp(k, "--m-nick") == 0 ) { |
---|
| 418 | g_meta.nick = argv[++i]; |
---|
| 419 | } else if ( strcmp(k, "--m-email") == 0 ) { |
---|
| 420 | g_meta.email = argv[++i]; |
---|
| 421 | } else if ( strcmp(k, "--m-hp") == 0 ) { |
---|
| 422 | g_meta.hp = argv[++i]; |
---|
| 423 | } else if ( strcmp(k, "--m-thumbn") == 0 ) { |
---|
| 424 | g_meta.thumbnail = argv[++i]; |
---|
| 425 | } else if ( strcmp(k, "--m-loc") == 0 ) { |
---|
| 426 | g_meta.loc = argv[++i]; |
---|
| 427 | } else if ( strcmp(k, "--m-org") == 0 ) { |
---|
| 428 | g_meta.org = argv[++i]; |
---|
| 429 | |
---|
| 430 | |
---|
[2124] | 431 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
| 432 | usage(); |
---|
| 433 | return 0; |
---|
| 434 | } else { |
---|
| 435 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 436 | usage(); |
---|
| 437 | return 1; |
---|
| 438 | } |
---|
| 439 | } |
---|
| 440 | |
---|
[2293] | 441 | if ( g_conf.antiecho == AE_SPEEX ) { |
---|
| 442 | ROAR_WARN("Speex Antiecho is obsolete and may be removed in future versions. Use --antiecho roard"); |
---|
| 443 | } |
---|
| 444 | |
---|
[2166] | 445 | g_conf.samples = info.channels * info.rate / TIMEDIV; |
---|
| 446 | |
---|
[2167] | 447 | memcpy(&dinfo, &info, sizeof(dinfo)); |
---|
| 448 | |
---|
| 449 | if ( g_conf.transcode ) { |
---|
| 450 | dinfo.bits = 16; |
---|
| 451 | dinfo.codec = ROAR_CODEC_DEFAULT; |
---|
| 452 | |
---|
| 453 | switch (info.codec) { |
---|
| 454 | case ROAR_CODEC_ALAW: |
---|
| 455 | case ROAR_CODEC_MULAW: |
---|
| 456 | info.bits = 8; |
---|
| 457 | break; |
---|
| 458 | case ROAR_CODEC_ROAR_CELT: |
---|
| 459 | info.bits = 16; |
---|
| 460 | break; |
---|
| 461 | case ROAR_CODEC_ROAR_SPEEX: |
---|
| 462 | info.bits = 16; |
---|
| 463 | break; |
---|
| 464 | } |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | if ( roar_cdriver_open(&dvio, driver, device, &dinfo, ROAR_DIR_BIDIR) == -1 ) { |
---|
[2126] | 468 | return 1; |
---|
| 469 | } |
---|
| 470 | |
---|
[2312] | 471 | ROAR_DBG("main(*): CALL open_stream(&svio, server, &info)"); |
---|
[2128] | 472 | if ( open_stream(&svio, server, &info) == -1 ) { |
---|
| 473 | roar_vio_close(&dvio); |
---|
| 474 | return 2; |
---|
| 475 | } |
---|
[2312] | 476 | ROAR_DBG("main(*): RET"); |
---|
[2128] | 477 | |
---|
[2330] | 478 | set_meta(); |
---|
| 479 | |
---|
[2185] | 480 | if ( g_conf.transcode ) { |
---|
| 481 | dinfo.codec = info.codec; |
---|
| 482 | |
---|
| 483 | if ( roar_bixcoder_init(transcoder, &dinfo, &svio) == -1 ) { |
---|
| 484 | roar_vio_close(&svio); |
---|
| 485 | roar_vio_close(&dvio); |
---|
| 486 | return 10; |
---|
| 487 | } |
---|
| 488 | |
---|
[2196] | 489 | g_conf.samples = 8 * roar_bixcoder_packet_size(transcoder, -1) / dinfo.bits; |
---|
[2185] | 490 | } |
---|
| 491 | |
---|
[2312] | 492 | ROAR_DBG("main(*): CALL run_stream(&dvio, &svio, &info);"); |
---|
[2140] | 493 | run_stream(&dvio, &svio, &info); |
---|
[2312] | 494 | ROAR_DBG("main(*): RET"); |
---|
[2128] | 495 | |
---|
[2185] | 496 | roar_bixcoder_close(transcoder); |
---|
| 497 | |
---|
[2128] | 498 | roar_vio_close(&svio); |
---|
[2126] | 499 | roar_vio_close(&dvio); |
---|
| 500 | |
---|
[2329] | 501 | roar_disconnect(&(g_cons.con)); |
---|
| 502 | |
---|
[2124] | 503 | return 0; |
---|
| 504 | } |
---|
| 505 | |
---|
| 506 | //ll |
---|