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