[2164] | 1 | //roarinterconnect.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009 |
---|
| 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> |
---|
| 26 | |
---|
| 27 | void usage (void) { |
---|
| 28 | printf("roarcat [OPTIONS]...\n"); |
---|
| 29 | |
---|
| 30 | printf("\nOptions:\n\n"); |
---|
| 31 | |
---|
| 32 | printf(" --server SERVER - Set server hostname\n" |
---|
| 33 | " --remote SERVER - Set remote server\n" |
---|
| 34 | " --type TYPE - Set type of remote server\n" |
---|
| 35 | " --rate RATE - Set sample rate\n" |
---|
| 36 | " --bits BITS - Set bits per sample\n" |
---|
| 37 | " --chans CHANNELS - Set number of channels\n" |
---|
| 38 | " --codec CODEC - Set the codec\n" |
---|
| 39 | " --help - Show this help\n" |
---|
| 40 | ); |
---|
| 41 | |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | int main (int argc, char * argv[]) { |
---|
| 45 | struct roar_connection con[1]; |
---|
| 46 | struct roar_stream stream[1]; |
---|
| 47 | int rate = 44100; |
---|
| 48 | int bits = 16; |
---|
| 49 | int channels = 2; |
---|
| 50 | int codec = ROAR_CODEC_DEFAULT; |
---|
| 51 | char * server = NULL; |
---|
| 52 | char * remote = NULL; |
---|
| 53 | char * k; |
---|
| 54 | int rfh; |
---|
| 55 | int i; |
---|
| 56 | |
---|
| 57 | for (i = 1; i < argc; i++) { |
---|
| 58 | k = argv[i]; |
---|
| 59 | |
---|
| 60 | if ( strcmp(k, "--server") == 0 ) { |
---|
| 61 | server = argv[++i]; |
---|
| 62 | } else if ( strcmp(k, "--remote") == 0 ) { |
---|
| 63 | remote = argv[++i]; |
---|
| 64 | } else if ( strcmp(k, "--rate") == 0 ) { |
---|
| 65 | rate = atoi(argv[++i]); |
---|
| 66 | } else if ( strcmp(k, "--bits") == 0 ) { |
---|
| 67 | bits = atoi(argv[++i]); |
---|
| 68 | } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 ) { |
---|
| 69 | channels = atoi(argv[++i]); |
---|
| 70 | } else if ( strcmp(k, "--codec") == 0 ) { |
---|
| 71 | codec = roar_str2codec(argv[++i]); |
---|
| 72 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
| 73 | usage(); |
---|
| 74 | return 0; |
---|
| 75 | } else { |
---|
| 76 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 77 | usage(); |
---|
| 78 | return 1; |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | if ( (rfh = roar_simple_stream(rate, channels, bits, codec, remote, ROAR_DIR_BIDIR, "roarinterconnect")) == -1 ) { |
---|
| 83 | fprintf(stderr, "Error: can not start playback\n"); |
---|
| 84 | return 1; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | if ( roar_simple_connect(con, server, "roarinterconnect") == -1 ) { |
---|
| 88 | ROAR_ERR("Can not connect to server"); |
---|
| 89 | return 0; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | if ( roar_stream_new(stream, rate, channels, bits, codec) == -1 ) { |
---|
| 93 | roar_disconnect(con); |
---|
| 94 | return -1; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | if ( roar_stream_connect(con, stream, ROAR_DIR_BIDIR) == -1 ) { |
---|
| 98 | roar_disconnect(con); |
---|
| 99 | return -1; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | if ( roar_stream_passfh(con, stream, rfh) == -1 ) { |
---|
| 103 | roar_disconnect(con); |
---|
| 104 | return -1; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | roar_simple_close(rfh); |
---|
| 108 | |
---|
| 109 | if ( roar_stream_attach_simple(con, stream, 0) == -1 ) { |
---|
| 110 | ROAR_ERR("Can not attach stream to server"); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | roar_disconnect(con); |
---|
| 114 | |
---|
| 115 | return 0; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | //ll |
---|