[2164] | 1 | //roarinterconnect.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[4708] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011 |
---|
[2164] | 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[2164] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
[4885] | 26 | /* ckport options: |
---|
[4922] | 27 | * ckport: ignore-symbol: roar_cdriver_oss of target libroareio0 -- For OSS streams |
---|
[4885] | 28 | */ |
---|
| 29 | |
---|
[3670] | 30 | // configure ROAR_INFO() |
---|
| 31 | int g_verbose = 0; |
---|
| 32 | #define ROAR_DBG_INFOVAR g_verbose |
---|
| 33 | |
---|
[2164] | 34 | #include <roaraudio.h> |
---|
[3669] | 35 | #include <libroareio/libroareio.h> |
---|
[2164] | 36 | |
---|
[2227] | 37 | #ifdef ROAR_HAVE_ESD |
---|
| 38 | #include <esd.h> |
---|
| 39 | #endif |
---|
| 40 | |
---|
[3929] | 41 | #ifdef ROAR_HAVE_LIBRSOUND |
---|
| 42 | #include <rsound.h> |
---|
| 43 | #ifdef RSD_EXEC |
---|
| 44 | #define _HAVE_RSOUND |
---|
| 45 | #endif |
---|
| 46 | #endif |
---|
| 47 | |
---|
[3807] | 48 | #if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS) |
---|
| 49 | #define _HAVE_OSS |
---|
| 50 | #endif |
---|
| 51 | |
---|
[4928] | 52 | #define CLIENT_NAME "roarinterconnect" |
---|
| 53 | |
---|
[2904] | 54 | #define MT_NONE 0x00 |
---|
[3009] | 55 | #define MT_MASK 0xF0 |
---|
[2904] | 56 | #define MT_ROAR 0x10 |
---|
| 57 | #define MT_ESD 0x20 |
---|
[3266] | 58 | #define MT_SIMPLE 0x30 |
---|
[3669] | 59 | #define MT_OSS 0x40 |
---|
[3929] | 60 | #define MT_RSOUND 0x50 |
---|
[2904] | 61 | #define MT_DEFAULT MT_ROAR |
---|
[2227] | 62 | |
---|
[2904] | 63 | #define ST_NONE 0x00 |
---|
| 64 | #define ST_MASK 0x0F |
---|
| 65 | #define ST_BIDIR 0x01 |
---|
| 66 | #define ST_FILTER 0x02 |
---|
| 67 | #define ST_TRANSMIT 0x03 |
---|
| 68 | #define ST_RECEIVE 0x04 |
---|
[2228] | 69 | // no default here as the default depend on the server type |
---|
[2227] | 70 | |
---|
[2164] | 71 | void usage (void) { |
---|
[2226] | 72 | printf("roarinterconnect [OPTIONS]...\n"); |
---|
[2164] | 73 | |
---|
| 74 | printf("\nOptions:\n\n"); |
---|
| 75 | |
---|
| 76 | printf(" --server SERVER - Set server hostname\n" |
---|
| 77 | " --remote SERVER - Set remote server\n" |
---|
| 78 | " --type TYPE - Set type of remote server\n" |
---|
| 79 | " --rate RATE - Set sample rate\n" |
---|
| 80 | " --bits BITS - Set bits per sample\n" |
---|
| 81 | " --chans CHANNELS - Set number of channels\n" |
---|
| 82 | " --codec CODEC - Set the codec\n" |
---|
| 83 | " --help - Show this help\n" |
---|
[3673] | 84 | " --verbose -v - Be verbose\n" |
---|
[2164] | 85 | ); |
---|
| 86 | |
---|
[3073] | 87 | printf("\nPossible Types:\n\n"); |
---|
| 88 | printf(" roar - RoarAudio Server\n" |
---|
[3807] | 89 | #ifdef ROAR_HAVE_ESD |
---|
[3073] | 90 | " esd - EsounD Server\n" |
---|
[3807] | 91 | #endif |
---|
[3266] | 92 | " simple - PulseAudio using simple protocol\n" |
---|
[3807] | 93 | #ifdef _HAVE_OSS |
---|
[3669] | 94 | " oss - Open Sound System (OSS) device\n" |
---|
[3807] | 95 | #endif |
---|
[3929] | 96 | #ifdef _HAVE_RSOUND |
---|
| 97 | " rsound - RSound server\n" |
---|
| 98 | #endif |
---|
[3073] | 99 | "\n" |
---|
| 100 | " bidir - Connect bidirectional\n" |
---|
| 101 | " filter - Use local server as filter for remote server\n" |
---|
| 102 | " transmit - Transmit data from local server to remote server\n" |
---|
| 103 | " receive - Receive data from remote server\n" |
---|
| 104 | ); |
---|
| 105 | |
---|
[2164] | 106 | } |
---|
| 107 | |
---|
[2228] | 108 | int parse_type (char * type) { |
---|
[2229] | 109 | int ret = MT_NONE|ST_NONE; |
---|
| 110 | char * colon; |
---|
[2228] | 111 | |
---|
| 112 | if ( type != NULL ) { |
---|
[2229] | 113 | while (type != NULL && *type) { |
---|
| 114 | if ( (colon = strstr(type, ":")) != NULL ) { |
---|
| 115 | *colon = 0; |
---|
| 116 | colon++; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | if ( !strcmp(type, "roar") ) { |
---|
| 120 | ret -= ret & MT_MASK; |
---|
| 121 | ret += MT_ROAR; |
---|
| 122 | } else if ( !strcmp(type, "esd") ) { |
---|
| 123 | ret -= ret & MT_MASK; |
---|
| 124 | ret += MT_ESD; |
---|
[3266] | 125 | } else if ( !strcmp(type, "simple") ) { |
---|
| 126 | ret -= ret & MT_MASK; |
---|
| 127 | ret += MT_SIMPLE; |
---|
[3669] | 128 | } else if ( !strcmp(type, "oss") ) { |
---|
| 129 | ret -= ret & MT_MASK; |
---|
| 130 | ret += MT_OSS; |
---|
[3929] | 131 | } else if ( !strcmp(type, "rsound") ) { |
---|
| 132 | ret -= ret & MT_MASK; |
---|
| 133 | ret += MT_RSOUND; |
---|
[2229] | 134 | } else if ( !strcmp(type, "bidir") ) { |
---|
| 135 | ret -= ret & ST_MASK; |
---|
| 136 | ret += ST_BIDIR; |
---|
| 137 | } else if ( !strcmp(type, "filter") ) { |
---|
| 138 | ret -= ret & ST_MASK; |
---|
| 139 | ret += ST_FILTER; |
---|
[2904] | 140 | } else if ( !strcmp(type, "transmit") ) { |
---|
| 141 | ret -= ret & ST_MASK; |
---|
| 142 | ret += ST_TRANSMIT; |
---|
| 143 | } else if ( !strcmp(type, "receive") ) { |
---|
| 144 | ret -= ret & ST_MASK; |
---|
| 145 | ret += ST_RECEIVE; |
---|
[2229] | 146 | } else { |
---|
| 147 | return MT_NONE|ST_NONE; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | type = colon; |
---|
| 151 | } |
---|
[2228] | 152 | } |
---|
| 153 | |
---|
| 154 | if ( (ret & MT_MASK) == MT_NONE ) |
---|
| 155 | ret |= MT_DEFAULT; |
---|
| 156 | |
---|
| 157 | if ( (ret & ST_MASK) == ST_NONE ) { |
---|
| 158 | switch (ret & MT_MASK) { |
---|
[3266] | 159 | case MT_ROAR: ret |= ST_BIDIR; break; |
---|
| 160 | case MT_ESD: ret |= ST_FILTER; break; |
---|
[3271] | 161 | case MT_SIMPLE: ret |= ST_TRANSMIT; break; // we use ST_TRANSMIT because ST_BIDIR is |
---|
| 162 | // very unlike to be configured at the server side. |
---|
[3669] | 163 | case MT_OSS: ret |= ST_BIDIR; break; |
---|
[3929] | 164 | case MT_RSOUND: ret |= ST_TRANSMIT; break; // RSound does only handle playback streams. |
---|
[2228] | 165 | default: |
---|
| 166 | return MT_NONE|ST_NONE; // error case |
---|
| 167 | break; |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | return ret; |
---|
| 172 | } |
---|
| 173 | |
---|
[3929] | 174 | #ifdef _HAVE_RSOUND |
---|
| 175 | // RSound format helper function: |
---|
| 176 | enum rsd_format para2rsdfmt (int bits, int codec) { |
---|
| 177 | switch (codec) { |
---|
| 178 | case ROAR_CODEC_PCM_S_LE: |
---|
| 179 | switch (bits) { |
---|
| 180 | #ifdef RSD_S8 |
---|
| 181 | case 8: return RSD_S8; break; |
---|
| 182 | #endif |
---|
| 183 | #ifdef RSD_S16_LE |
---|
| 184 | case 16: return RSD_S16_LE; break; |
---|
| 185 | #endif |
---|
[4928] | 186 | #ifdef RSD_S32_LE |
---|
| 187 | case 32: return RSD_S32_LE; break; |
---|
| 188 | #endif |
---|
[3929] | 189 | } |
---|
| 190 | break; |
---|
| 191 | case ROAR_CODEC_PCM_S_BE: |
---|
| 192 | switch (bits) { |
---|
| 193 | #ifdef RSD_S8 |
---|
| 194 | case 8: return RSD_S8; break; |
---|
| 195 | #endif |
---|
| 196 | #ifdef RSD_S16_BE |
---|
| 197 | case 16: return RSD_S16_BE; break; |
---|
| 198 | #endif |
---|
[4928] | 199 | #ifdef RSD_S32_BE |
---|
| 200 | case 32: return RSD_S32_BE; break; |
---|
| 201 | #endif |
---|
[3929] | 202 | } |
---|
| 203 | break; |
---|
| 204 | case ROAR_CODEC_PCM_U_LE: |
---|
| 205 | switch (bits) { |
---|
| 206 | #ifdef RSD_U8 |
---|
| 207 | case 8: return RSD_U8; break; |
---|
| 208 | #endif |
---|
| 209 | #ifdef RSD_U16_LE |
---|
| 210 | case 16: return RSD_U16_LE; break; |
---|
| 211 | #endif |
---|
[4928] | 212 | #ifdef RSD_U32_LE |
---|
| 213 | case 32: return RSD_U32_LE; break; |
---|
| 214 | #endif |
---|
[3929] | 215 | } |
---|
| 216 | break; |
---|
| 217 | case ROAR_CODEC_PCM_U_BE: |
---|
| 218 | switch (bits) { |
---|
| 219 | #ifdef RSD_U8 |
---|
| 220 | case 8: return RSD_U8; break; |
---|
| 221 | #endif |
---|
| 222 | #ifdef RSD_U16_BE |
---|
| 223 | case 16: return RSD_U16_BE; break; |
---|
| 224 | #endif |
---|
[4928] | 225 | #ifdef RSD_U32_BE |
---|
| 226 | case 32: return RSD_U32_BE; break; |
---|
| 227 | #endif |
---|
[3929] | 228 | } |
---|
| 229 | break; |
---|
| 230 | #ifdef RSD_ALAW |
---|
| 231 | case ROAR_CODEC_ALAW: |
---|
| 232 | return RSD_ALAW; |
---|
| 233 | break; |
---|
| 234 | #endif |
---|
| 235 | #ifdef RSD_MULAW |
---|
| 236 | case ROAR_CODEC_MULAW: |
---|
| 237 | return RSD_MULAW; |
---|
| 238 | break; |
---|
| 239 | #endif |
---|
| 240 | } |
---|
| 241 | return 0; |
---|
| 242 | } |
---|
| 243 | #endif |
---|
| 244 | |
---|
[2164] | 245 | int main (int argc, char * argv[]) { |
---|
| 246 | struct roar_connection con[1]; |
---|
| 247 | struct roar_stream stream[1]; |
---|
[4909] | 248 | struct roar_vio_calls vio; |
---|
[3808] | 249 | #ifdef _HAVE_OSS |
---|
[3669] | 250 | struct roar_audio_info info; |
---|
[3808] | 251 | #endif |
---|
[3929] | 252 | #ifdef _HAVE_RSOUND |
---|
| 253 | rsound_t *rd; |
---|
| 254 | enum rsd_format fmt = 0; |
---|
| 255 | #endif |
---|
[2164] | 256 | int rate = 44100; |
---|
| 257 | int bits = 16; |
---|
| 258 | int channels = 2; |
---|
| 259 | int codec = ROAR_CODEC_DEFAULT; |
---|
[2228] | 260 | int type = parse_type(NULL); |
---|
[2227] | 261 | int tmp; |
---|
[2164] | 262 | char * server = NULL; |
---|
[3121] | 263 | char * remote = "+slp"; // we hope SLP located server is not local one |
---|
[2164] | 264 | char * k; |
---|
| 265 | int rfh; |
---|
| 266 | int i; |
---|
[2904] | 267 | int localdir = ROAR_DIR_BIDIR; |
---|
[3266] | 268 | int rport; |
---|
[2164] | 269 | |
---|
| 270 | for (i = 1; i < argc; i++) { |
---|
| 271 | k = argv[i]; |
---|
| 272 | |
---|
| 273 | if ( strcmp(k, "--server") == 0 ) { |
---|
| 274 | server = argv[++i]; |
---|
| 275 | } else if ( strcmp(k, "--remote") == 0 ) { |
---|
| 276 | remote = argv[++i]; |
---|
[2228] | 277 | } else if ( strcmp(k, "--type") == 0 ) { |
---|
| 278 | type = parse_type(argv[++i]); |
---|
[2164] | 279 | } else if ( strcmp(k, "--rate") == 0 ) { |
---|
| 280 | rate = atoi(argv[++i]); |
---|
| 281 | } else if ( strcmp(k, "--bits") == 0 ) { |
---|
| 282 | bits = atoi(argv[++i]); |
---|
| 283 | } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 ) { |
---|
| 284 | channels = atoi(argv[++i]); |
---|
| 285 | } else if ( strcmp(k, "--codec") == 0 ) { |
---|
| 286 | codec = roar_str2codec(argv[++i]); |
---|
[3670] | 287 | } else if ( strcmp(k, "--verbose") == 0 || strcmp(k, "-v") == 0 ) { |
---|
| 288 | g_verbose++; |
---|
[2164] | 289 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
| 290 | usage(); |
---|
| 291 | return 0; |
---|
| 292 | } else { |
---|
| 293 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 294 | usage(); |
---|
| 295 | return 1; |
---|
| 296 | } |
---|
| 297 | } |
---|
| 298 | |
---|
[2227] | 299 | switch (type & MT_MASK) { |
---|
| 300 | case MT_ROAR: |
---|
| 301 | switch (type & ST_MASK) { |
---|
| 302 | case ST_BIDIR: |
---|
[2904] | 303 | tmp = ROAR_DIR_BIDIR; |
---|
[2227] | 304 | break; |
---|
| 305 | case ST_FILTER: |
---|
[2904] | 306 | tmp = ROAR_DIR_FILTER; |
---|
| 307 | break; |
---|
| 308 | case ST_TRANSMIT: |
---|
| 309 | tmp = ROAR_DIR_PLAY; |
---|
| 310 | localdir = ROAR_DIR_MONITOR; |
---|
| 311 | break; |
---|
| 312 | case ST_RECEIVE: |
---|
| 313 | tmp = ROAR_DIR_MONITOR; |
---|
| 314 | localdir = ROAR_DIR_PLAY; |
---|
[2227] | 315 | break; |
---|
| 316 | default: |
---|
| 317 | fprintf(stderr, "Error: unknown stream type\n"); |
---|
| 318 | return 2; |
---|
| 319 | } |
---|
[4928] | 320 | if ( roar_vio_simple_stream(&vio, rate, channels, bits, codec, remote, tmp, CLIENT_NAME) == -1 ) { |
---|
[4909] | 321 | fprintf(stderr, "Error: can not open RoarAudio stream to %s: %s\n", remote, roar_error2str(roar_error)); |
---|
| 322 | return 2; |
---|
| 323 | } |
---|
| 324 | if ( roar_vio_ctl(&vio, ROAR_VIO_CTL_GET_FH, &rfh) == -1 ) { |
---|
| 325 | fprintf(stderr, "Error: can not get filehandle for RoarAudio stream: %s\n", roar_error2str(roar_error)); |
---|
| 326 | roar_vio_close(&vio); |
---|
| 327 | return 2; |
---|
| 328 | } |
---|
[2227] | 329 | break; |
---|
[3807] | 330 | #ifdef _HAVE_OSS |
---|
[3669] | 331 | case MT_OSS: |
---|
| 332 | switch (type & ST_MASK) { |
---|
| 333 | case ST_BIDIR: |
---|
| 334 | tmp = ROAR_DIR_BIDIR; |
---|
| 335 | break; |
---|
| 336 | case ST_TRANSMIT: |
---|
| 337 | tmp = ROAR_DIR_PLAY; |
---|
| 338 | localdir = ROAR_DIR_MONITOR; |
---|
| 339 | break; |
---|
| 340 | case ST_RECEIVE: |
---|
| 341 | tmp = ROAR_DIR_RECORD; |
---|
| 342 | localdir = ROAR_DIR_PLAY; |
---|
| 343 | break; |
---|
| 344 | default: |
---|
| 345 | fprintf(stderr, "Error: unknown stream type\n"); |
---|
| 346 | return 2; |
---|
| 347 | } |
---|
| 348 | info.rate = rate; |
---|
| 349 | info.channels = channels; |
---|
| 350 | info.bits = bits; |
---|
| 351 | info.codec = codec; |
---|
| 352 | if ( roar_cdriver_oss(&vio, "OSS", remote, &info, tmp) == -1 ) { |
---|
[4909] | 353 | fprintf(stderr, "Error: can not open OSS device %s: %s\n", remote, roar_error2str(roar_error)); |
---|
[3669] | 354 | return 2; |
---|
| 355 | } |
---|
| 356 | if ( roar_vio_ctl(&vio, ROAR_VIO_CTL_GET_FH, &rfh) == -1 ) { |
---|
[4909] | 357 | fprintf(stderr, "Error: can not get filehandle for OSS device %s: %s\n", remote, roar_error2str(roar_error)); |
---|
[3669] | 358 | roar_vio_close(&vio); |
---|
| 359 | return 2; |
---|
| 360 | } |
---|
| 361 | break; |
---|
[3807] | 362 | #endif |
---|
[2227] | 363 | #ifdef ROAR_HAVE_ESD |
---|
| 364 | case MT_ESD: |
---|
| 365 | tmp = ESD_STREAM|ESD_PLAY; |
---|
| 366 | |
---|
| 367 | switch (bits) { |
---|
| 368 | case 8: tmp |= ESD_BITS8; break; |
---|
| 369 | case 16: tmp |= ESD_BITS16; break; |
---|
| 370 | default: |
---|
| 371 | fprintf(stderr, "Error: EsounD only supports 8 and 16 bit streams\n"); |
---|
| 372 | return 2; |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | switch (channels) { |
---|
| 376 | case 1: tmp |= ESD_MONO; break; |
---|
| 377 | case 2: tmp |= ESD_STEREO; break; |
---|
| 378 | default: |
---|
| 379 | fprintf(stderr, "Error: EsounD only supports mono and stereo streams\n"); |
---|
| 380 | return 2; |
---|
| 381 | } |
---|
| 382 | |
---|
[3842] | 383 | // TODO: FIXME: this is only true if the esd runs on a LE system,... |
---|
[2260] | 384 | if ( bits == 8 && codec != ROAR_CODEC_PCM_U_LE ) { |
---|
| 385 | fprintf(stderr, "Error: EsounD only supports unsigned PCM in 8 bit mode\n"); |
---|
| 386 | return 2; |
---|
| 387 | } else if ( bits == 16 && codec != ROAR_CODEC_DEFAULT ) { |
---|
| 388 | fprintf(stderr, "Error: EsounD only supports signed PCM in 16 bit mode\n"); |
---|
| 389 | return 2; |
---|
| 390 | } |
---|
| 391 | |
---|
[2905] | 392 | switch (type & ST_MASK) { |
---|
| 393 | case ST_FILTER: |
---|
[4928] | 394 | rfh = esd_filter_stream(tmp, rate, remote, CLIENT_NAME); |
---|
[2905] | 395 | break; |
---|
| 396 | case ST_TRANSMIT: |
---|
[4928] | 397 | rfh = esd_play_stream(tmp, rate, remote, CLIENT_NAME); |
---|
[2905] | 398 | break; |
---|
| 399 | case ST_RECEIVE: |
---|
[4928] | 400 | rfh = esd_monitor_stream(tmp, rate, remote, CLIENT_NAME); |
---|
[2905] | 401 | break; |
---|
| 402 | default: |
---|
| 403 | fprintf(stderr, "Error: this type is not supported by EsounD\n"); |
---|
| 404 | return 2; |
---|
| 405 | break; |
---|
| 406 | } |
---|
[2227] | 407 | break; |
---|
| 408 | #endif |
---|
[3929] | 409 | #ifdef _HAVE_RSOUND |
---|
| 410 | case MT_RSOUND: |
---|
| 411 | fmt = para2rsdfmt(bits, codec); |
---|
| 412 | |
---|
| 413 | if ( fmt == 0 ) { |
---|
| 414 | fprintf(stderr, "Error: Bits/Codec not supported by RSound\n"); |
---|
| 415 | return 2; |
---|
| 416 | } |
---|
| 417 | |
---|
| 418 | switch (type & ST_MASK) { |
---|
| 419 | case ST_TRANSMIT: |
---|
| 420 | localdir = ROAR_DIR_MONITOR; |
---|
| 421 | |
---|
| 422 | rsd_init(&rd); |
---|
| 423 | rsd_set_param(rd, RSD_HOST, remote); |
---|
| 424 | rsd_set_param(rd, RSD_CHANNELS, &channels); |
---|
| 425 | rsd_set_param(rd, RSD_SAMPLERATE, &rate); |
---|
| 426 | rsd_set_param(rd, RSD_FORMAT, &fmt); |
---|
[4928] | 427 | #ifdef RSD_IDENTITY |
---|
| 428 | rsd_set_param(rd, RSD_IDENTITY, CLIENT_NAME); |
---|
| 429 | #endif |
---|
[3929] | 430 | rfh = rsd_exec(rd); |
---|
| 431 | if ( rfh == -1 ) { |
---|
| 432 | rsd_stop(rd); |
---|
| 433 | rsd_free(rd); |
---|
| 434 | } |
---|
| 435 | break; |
---|
| 436 | default: |
---|
| 437 | fprintf(stderr, "Error: this type is not supported by RSound\n"); |
---|
| 438 | return 2; |
---|
| 439 | break; |
---|
| 440 | } |
---|
| 441 | break; |
---|
| 442 | #endif |
---|
[3266] | 443 | case MT_SIMPLE: |
---|
| 444 | switch (type & ST_MASK) { |
---|
[3271] | 445 | case ST_BIDIR: |
---|
| 446 | tmp = -1; |
---|
| 447 | localdir = ROAR_DIR_BIDIR; |
---|
| 448 | break; |
---|
[3266] | 449 | case ST_TRANSMIT: |
---|
| 450 | tmp = SHUT_RD; |
---|
| 451 | localdir = ROAR_DIR_MONITOR; |
---|
| 452 | break; |
---|
| 453 | case ST_RECEIVE: |
---|
| 454 | tmp = SHUT_WR; |
---|
| 455 | localdir = ROAR_DIR_PLAY; |
---|
| 456 | break; |
---|
| 457 | default: |
---|
| 458 | fprintf(stderr, "Error: this type is not supported by PulseAudio\n"); |
---|
| 459 | return 2; |
---|
| 460 | } |
---|
| 461 | // we guess INET here... |
---|
| 462 | if ( strstr(remote, "/") == NULL && (k = strstr(remote, ":")) != NULL ) { |
---|
| 463 | *k = 0; |
---|
| 464 | k++; |
---|
| 465 | rport = atoi(k); |
---|
| 466 | } else { |
---|
[4909] | 467 | rport = ROAR_DEFAULT_PA_PORT; |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | if ( roar_vio_open_socket(&vio, remote, rport) == -1 ) { |
---|
| 471 | fprintf(stderr, "Error: can not open socket for Simple stream: %s\n", roar_error2str(roar_error)); |
---|
| 472 | return 2; |
---|
[3266] | 473 | } |
---|
[4909] | 474 | |
---|
| 475 | roar_vio_shutdown(&vio, tmp); |
---|
| 476 | |
---|
| 477 | if ( roar_vio_ctl(&vio, ROAR_VIO_CTL_GET_FH, &rfh) == -1 ) { |
---|
| 478 | fprintf(stderr, "Error: can not get filehandle for Simple stream: %s\n", roar_error2str(roar_error)); |
---|
| 479 | roar_vio_close(&vio); |
---|
| 480 | return 2; |
---|
| 481 | } |
---|
[3266] | 482 | break; |
---|
[2227] | 483 | default: |
---|
| 484 | fprintf(stderr, "Error: unknown/not supported server type\n"); |
---|
| 485 | return 2; |
---|
| 486 | } |
---|
[2224] | 487 | |
---|
| 488 | if ( rfh == -1 ) { |
---|
| 489 | fprintf(stderr, "Error: can not connect to remote server\n"); |
---|
| 490 | return 10; |
---|
[2164] | 491 | } |
---|
| 492 | |
---|
[4928] | 493 | if ( roar_simple_connect(con, server, CLIENT_NAME) == -1 ) { |
---|
[2224] | 494 | fprintf(stderr, "Can not connect to local server\n"); |
---|
| 495 | return 20; |
---|
[2164] | 496 | } |
---|
| 497 | |
---|
| 498 | if ( roar_stream_new(stream, rate, channels, bits, codec) == -1 ) { |
---|
| 499 | roar_disconnect(con); |
---|
[2224] | 500 | return 21; |
---|
[2164] | 501 | } |
---|
| 502 | |
---|
[5109] | 503 | if ( roar_stream_connect2(con, stream, localdir, -1) == -1 ) { |
---|
[2164] | 504 | roar_disconnect(con); |
---|
[2224] | 505 | return 22; |
---|
[2164] | 506 | } |
---|
| 507 | |
---|
| 508 | if ( roar_stream_passfh(con, stream, rfh) == -1 ) { |
---|
| 509 | roar_disconnect(con); |
---|
[2224] | 510 | return 23; |
---|
[2164] | 511 | } |
---|
| 512 | |
---|
[4909] | 513 | switch (type & MT_MASK) { |
---|
| 514 | case MT_ESD: |
---|
| 515 | close(rfh); |
---|
| 516 | break; |
---|
| 517 | case MT_RSOUND: |
---|
| 518 | roar_vio_open_fh_socket(&vio, rfh); |
---|
| 519 | case MT_ROAR: |
---|
| 520 | case MT_OSS: |
---|
| 521 | case MT_SIMPLE: |
---|
| 522 | roar_vio_close(&vio); |
---|
| 523 | break; |
---|
| 524 | default: |
---|
| 525 | close(rfh); |
---|
| 526 | } |
---|
[2164] | 527 | |
---|
| 528 | if ( roar_stream_attach_simple(con, stream, 0) == -1 ) { |
---|
[2224] | 529 | fprintf(stderr, "Can not attach remote stream to local server\n"); |
---|
[2164] | 530 | } |
---|
| 531 | |
---|
| 532 | roar_disconnect(con); |
---|
| 533 | |
---|
[3670] | 534 | ROAR_INFO("Stream ID: %i", 1, stream->id); |
---|
| 535 | |
---|
[2164] | 536 | return 0; |
---|
| 537 | } |
---|
| 538 | |
---|
| 539 | //ll |
---|