[0] | 1 | //roarcat.c: |
---|
| 2 | |
---|
[669] | 3 | /* |
---|
[5381] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012 |
---|
[669] | 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. |
---|
[669] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
[0] | 26 | #include <roaraudio.h> |
---|
| 27 | |
---|
| 28 | #define BUFSIZE 1024 |
---|
| 29 | |
---|
| 30 | void usage (void) { |
---|
[290] | 31 | printf("roarcat [OPTIONS]... [FILE]\n"); |
---|
[0] | 32 | |
---|
| 33 | printf("\nOptions:\n\n"); |
---|
| 34 | |
---|
[1507] | 35 | printf(" --server SERVER - Set server hostname\n" |
---|
| 36 | " --rate -R RATE - Set sample rate\n" |
---|
| 37 | " --bits -B BITS - Set bits per sample\n" |
---|
| 38 | " --chans -C CHANNELS - Set number of channels\n" |
---|
| 39 | " --codec CODEC - Set the codec\n" |
---|
[1808] | 40 | " --wave - Use Wave Audio (PCM) as input\n" |
---|
| 41 | " --midi - Use MIDI Audio as input\n" |
---|
| 42 | " --light - Use light control input\n" |
---|
[2241] | 43 | " --raw - Use raw input\n" |
---|
[2681] | 44 | " --complex - Use complex input\n" |
---|
[2712] | 45 | " --rdtcs - Use Radio Data and Transmitter Control System input\n" |
---|
[2591] | 46 | " --rel-id ID - Set ID of relative stream\n" |
---|
[5456] | 47 | " --role ROLE - Set stream role\n" |
---|
[1507] | 48 | " --help - Show this help\n" |
---|
[0] | 49 | ); |
---|
| 50 | |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | int main (int argc, char * argv[]) { |
---|
[2420] | 54 | int rate = -1; |
---|
| 55 | int bits = -1; |
---|
| 56 | int channels = -1; |
---|
| 57 | int codec = -1; |
---|
[1808] | 58 | int dir = ROAR_DIR_PLAY; |
---|
[2242] | 59 | int rel_id = -1; |
---|
[5456] | 60 | int role = ROAR_ROLE_UNKNOWN; |
---|
[0] | 61 | char * server = NULL; |
---|
| 62 | char * k; |
---|
| 63 | int i; |
---|
[1194] | 64 | char * name = "roarcat"; |
---|
[2242] | 65 | struct roar_connection con; |
---|
| 66 | struct roar_stream s; |
---|
[4044] | 67 | struct roar_vio_calls file, * stream; |
---|
[2242] | 68 | struct roar_vio_defaults def; |
---|
| 69 | int file_opened = 0; |
---|
[0] | 70 | |
---|
[2247] | 71 | if ( roar_vio_open_fh(&file, ROAR_STDIN) == -1 ) |
---|
[2243] | 72 | return 1; |
---|
| 73 | |
---|
[2246] | 74 | if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 ) |
---|
[2243] | 75 | return 1; |
---|
| 76 | |
---|
[0] | 77 | for (i = 1; i < argc; i++) { |
---|
| 78 | k = argv[i]; |
---|
| 79 | |
---|
[1194] | 80 | if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) { |
---|
[58] | 81 | server = argv[++i]; |
---|
[1194] | 82 | } else if ( !strcmp(k, "-n") ) { |
---|
| 83 | name = argv[++i]; |
---|
[1507] | 84 | } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) { |
---|
[4883] | 85 | rate = roar_str2rate(argv[++i]); |
---|
[1507] | 86 | } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) { |
---|
[4883] | 87 | bits = roar_str2bits(argv[++i]); |
---|
[1194] | 88 | } else if ( !strcmp(k, "-b") ) { |
---|
| 89 | bits = 8; |
---|
[1507] | 90 | } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) { |
---|
[4883] | 91 | channels = roar_str2channels(argv[++i]); |
---|
[1194] | 92 | } else if ( !strcmp(k, "-m") ) { |
---|
| 93 | channels = 1; |
---|
| 94 | } else if ( !strcmp(k, "--codec") ) { |
---|
[1897] | 95 | if ( (codec = roar_str2codec(argv[++i])) == -1 ) { |
---|
| 96 | fprintf(stderr, "Error: Unknown codec: %s\n", argv[i]); |
---|
| 97 | return 1; |
---|
| 98 | } |
---|
[1808] | 99 | |
---|
| 100 | } else if ( !strcmp(k, "--wave") ) { |
---|
| 101 | dir = ROAR_DIR_PLAY; |
---|
| 102 | } else if ( !strcmp(k, "--midi") ) { |
---|
[5349] | 103 | dir = ROAR_DIR_MIDI_IN; |
---|
[1808] | 104 | } else if ( !strcmp(k, "--light") ) { |
---|
| 105 | dir = ROAR_DIR_LIGHT_IN; |
---|
[2241] | 106 | } else if ( !strcmp(k, "--raw") ) { |
---|
| 107 | dir = ROAR_DIR_RAW_IN; |
---|
[2681] | 108 | } else if ( !strcmp(k, "--complex") ) { |
---|
| 109 | dir = ROAR_DIR_COMPLEX_IN; |
---|
[2712] | 110 | } else if ( !strcmp(k, "--rdtcs") ) { |
---|
| 111 | dir = ROAR_DIR_RDTCS_IN; |
---|
[1808] | 112 | |
---|
[2242] | 113 | } else if ( !strcmp(k, "--rel-id") ) { |
---|
| 114 | rel_id = atoi(argv[++i]); |
---|
[5456] | 115 | } else if ( !strcmp(k, "--role") ) { |
---|
| 116 | role = roar_str2role(argv[++i]); |
---|
[2242] | 117 | |
---|
[1635] | 118 | } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) { |
---|
[0] | 119 | usage(); |
---|
| 120 | return 0; |
---|
[2242] | 121 | } else if ( !file_opened ) { |
---|
| 122 | file_opened = 1; |
---|
| 123 | if ( roar_vio_open_dstr(&file, k, &def, 1) == -1 ) { |
---|
[5021] | 124 | fprintf(stderr, "Error: can not open file: %s: %s\n", k, roar_error2str(roar_error)); |
---|
[289] | 125 | return 1; |
---|
| 126 | } |
---|
[0] | 127 | } else { |
---|
| 128 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 129 | usage(); |
---|
| 130 | return 1; |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
[2420] | 134 | switch (dir) { |
---|
| 135 | case ROAR_DIR_PLAY: |
---|
| 136 | if ( rate == -1 ) rate = ROAR_RATE_DEFAULT; |
---|
| 137 | if ( bits == -1 ) bits = ROAR_BITS_DEFAULT; |
---|
| 138 | if ( channels == -1 ) channels = ROAR_CHANNELS_DEFAULT; |
---|
| 139 | if ( codec == -1 ) codec = ROAR_CODEC_DEFAULT; |
---|
| 140 | break; |
---|
| 141 | case ROAR_DIR_MIDI_IN: |
---|
| 142 | if ( rate == -1 ) rate = 0; |
---|
| 143 | if ( bits == -1 ) bits = ROAR_MIDI_BITS; |
---|
| 144 | if ( channels == -1 ) channels = ROAR_MIDI_CHANNELS_DEFAULT; |
---|
| 145 | if ( codec == -1 ) codec = ROAR_CODEC_MIDI; |
---|
| 146 | break; |
---|
| 147 | case ROAR_DIR_LIGHT_IN: |
---|
| 148 | if ( rate == -1 ) rate = 0; |
---|
| 149 | if ( bits == -1 ) bits = ROAR_LIGHT_BITS; |
---|
| 150 | if ( channels == -1 ) channels = 0; |
---|
| 151 | if ( codec == -1 ) codec = ROAR_CODEC_DMX512; |
---|
| 152 | break; |
---|
[2681] | 153 | case ROAR_DIR_COMPLEX_IN: |
---|
| 154 | if ( rate == -1 ) rate = ROAR_COMPLEX_RATE; |
---|
| 155 | if ( bits == -1 ) bits = ROAR_COMPLEX_BITS; |
---|
| 156 | if ( channels == -1 ) channels = ROAR_COMPLEX_CHANNELS; |
---|
| 157 | if ( codec == -1 ) codec = ROAR_COMPLEX_CODEC; |
---|
| 158 | break; |
---|
[2712] | 159 | case ROAR_DIR_RDTCS_IN: |
---|
| 160 | if ( rate == -1 ) rate = ROAR_RDTCS_RATE; |
---|
| 161 | if ( bits == -1 ) bits = ROAR_RDTCS_BITS; |
---|
| 162 | if ( channels == -1 ) channels = ROAR_RDTCS_CHANNELS; |
---|
| 163 | if ( codec == -1 ) codec = ROAR_RDTCS_CODEC; |
---|
| 164 | break; |
---|
[2420] | 165 | case ROAR_DIR_RAW_IN: |
---|
| 166 | default: |
---|
| 167 | if ( rate == -1 ) rate = 0; |
---|
| 168 | if ( bits == -1 ) bits = 0; |
---|
| 169 | if ( channels == -1 ) channels = 0; |
---|
| 170 | if ( codec == -1 ) codec = ROAR_CODEC_DEFAULT; |
---|
| 171 | break; |
---|
| 172 | } |
---|
| 173 | |
---|
[3126] | 174 | if ( roar_simple_connect(&con, server, name) == -1 ) { |
---|
[5202] | 175 | fprintf(stderr, "Error: can not connect to server: %s\n", roar_error2str(roar_error)); |
---|
[2242] | 176 | return 10; |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) { |
---|
| 180 | fprintf(stderr, "Error: can not create stream\n"); |
---|
| 181 | roar_disconnect(&con); |
---|
| 182 | return 20; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | if ( rel_id != -1 ) { |
---|
| 186 | if ( roar_stream_set_rel_id(&s, rel_id) ) { |
---|
| 187 | fprintf(stderr, "Error: can not set id or realative stream\n"); |
---|
| 188 | roar_disconnect(&con); |
---|
| 189 | return 21; |
---|
| 190 | } |
---|
[0] | 191 | } |
---|
| 192 | |
---|
[5238] | 193 | if ( roar_stream_connect(&con, &s, dir, -1) == -1 ) { |
---|
[2242] | 194 | fprintf(stderr, "Error: can not connect stream to server\n"); |
---|
| 195 | roar_disconnect(&con); |
---|
| 196 | return 11; |
---|
| 197 | } |
---|
[289] | 198 | |
---|
[5456] | 199 | if ( role != ROAR_ROLE_UNKNOWN ) { |
---|
| 200 | if ( roar_stream_set_role(&con, &s, role) == -1 ) { |
---|
| 201 | fprintf(stderr, "Warning: can not set stream role\n"); |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | |
---|
[2242] | 205 | if ( roar_stream_exec(&con, &s) == -1 ) { |
---|
| 206 | fprintf(stderr, "Error: can not exec stream\n"); |
---|
| 207 | roar_disconnect(&con); |
---|
| 208 | return 12; |
---|
| 209 | } |
---|
[0] | 210 | |
---|
[4044] | 211 | if ( (stream = roar_get_connection_vio2(&con)) == NULL ) { |
---|
[2242] | 212 | fprintf(stderr, "Error: can not get stream vio\n"); |
---|
| 213 | roar_disconnect(&con); |
---|
| 214 | return 13; |
---|
| 215 | } |
---|
[0] | 216 | |
---|
[5109] | 217 | if ( roar_vio_copy_data(stream, &file) == -1 ) { |
---|
| 218 | fprintf(stderr, "Error: can not copy data from source to server.\n"); |
---|
| 219 | roar_vio_close(stream); |
---|
| 220 | roar_vio_close(&file); |
---|
| 221 | return 14; |
---|
| 222 | } |
---|
[2242] | 223 | |
---|
[4044] | 224 | roar_vio_close(stream); |
---|
[2242] | 225 | roar_vio_close(&file); |
---|
[292] | 226 | |
---|
[0] | 227 | return 0; |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | //ll |
---|