[2292] | 1 | //roarmon.c: |
---|
[0] | 2 | |
---|
[669] | 3 | /* |
---|
[2045] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008, 2009 |
---|
[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 |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
[0] | 25 | #include <roaraudio.h> |
---|
| 26 | |
---|
| 27 | #define BUFSIZE 1024 |
---|
| 28 | |
---|
| 29 | void usage (void) { |
---|
[991] | 30 | printf("roarmon [OPTIONS]... [FILE]\n"); |
---|
[0] | 31 | |
---|
| 32 | printf("\nOptions:\n\n"); |
---|
| 33 | |
---|
[1507] | 34 | printf(" --server SERVER - Set server hostname\n" |
---|
| 35 | " --rate -R RATE - Set sample rate\n" |
---|
| 36 | " --bits -B BITS - Set bits per sample\n" |
---|
| 37 | " --chans -C CHANNELS - Set number of channels\n" |
---|
| 38 | " --codec CODEC - Set the codec\n" |
---|
[1808] | 39 | " --wave - Output Wave Audio (PCM)\n" |
---|
| 40 | " --midi - Output MIDI Audio\n" |
---|
| 41 | " --light - Output light control\n" |
---|
[2241] | 42 | " --raw - Output raw data\n" |
---|
[2681] | 43 | " --complex - Output complex data\n" |
---|
[2712] | 44 | " --rdtcs - Output Radio Data and Transmitter Control System data\n" |
---|
[1808] | 45 | " --thru - Output copy of other stream\n" |
---|
[2813] | 46 | " --prethru - Sets prethru flag on stream\n" |
---|
[1814] | 47 | " --rel-id ID - Set ID of relative stream\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_MONITOR; |
---|
[1814] | 59 | int rel_id = -1; |
---|
[0] | 60 | char * server = NULL; |
---|
| 61 | char * k; |
---|
| 62 | int i; |
---|
[2813] | 63 | int prethru = 0; |
---|
[2045] | 64 | struct roar_connection con; |
---|
| 65 | struct roar_stream s; |
---|
| 66 | struct roar_vio_calls file, stream; |
---|
| 67 | struct roar_vio_defaults def; |
---|
| 68 | int file_opened = 0; |
---|
| 69 | |
---|
| 70 | if ( roar_vio_open_fh(&file, ROAR_STDOUT) == -1 ) |
---|
| 71 | return 1; |
---|
| 72 | |
---|
| 73 | if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_CREAT|O_TRUNC|O_WRONLY, 0644) == -1 ) |
---|
| 74 | return 1; |
---|
[0] | 75 | |
---|
| 76 | for (i = 1; i < argc; i++) { |
---|
| 77 | k = argv[i]; |
---|
| 78 | |
---|
[1195] | 79 | // esdmon [-s server ][-b] [-m] [-r freq] < file |
---|
| 80 | |
---|
| 81 | if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) { |
---|
[58] | 82 | server = argv[++i]; |
---|
[1507] | 83 | } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) { |
---|
[0] | 84 | rate = atoi(argv[++i]); |
---|
[1507] | 85 | } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) { |
---|
[0] | 86 | bits = atoi(argv[++i]); |
---|
[1195] | 87 | } else if ( !strcmp(k, "-b") ) { |
---|
| 88 | bits = 8; |
---|
[1507] | 89 | } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) { |
---|
[0] | 90 | channels = atoi(argv[++i]); |
---|
[1195] | 91 | } else if ( !strcmp(k, "-m") ) { |
---|
| 92 | channels = 2; |
---|
| 93 | } else if ( !strcmp(k, "--codec") ) { |
---|
[1897] | 94 | if ( (codec = roar_str2codec(argv[++i])) == -1 ) { |
---|
| 95 | fprintf(stderr, "Error: Unknown codec: %s\n", argv[i]); |
---|
| 96 | return 1; |
---|
| 97 | } |
---|
[1808] | 98 | |
---|
| 99 | } else if ( !strcmp(k, "--wave") ) { |
---|
| 100 | dir = ROAR_DIR_MONITOR; |
---|
| 101 | } else if ( !strcmp(k, "--midi") ) { |
---|
[2407] | 102 | dir = ROAR_DIR_MIDI_OUT; |
---|
[1808] | 103 | } else if ( !strcmp(k, "--light") ) { |
---|
| 104 | dir = ROAR_DIR_LIGHT_OUT; |
---|
[2241] | 105 | } else if ( !strcmp(k, "--raw") ) { |
---|
| 106 | dir = ROAR_DIR_RAW_OUT; |
---|
[2681] | 107 | } else if ( !strcmp(k, "--complex") ) { |
---|
| 108 | dir = ROAR_DIR_COMPLEX_OUT; |
---|
[2712] | 109 | } else if ( !strcmp(k, "--rdtcs") ) { |
---|
| 110 | dir = ROAR_DIR_RDTCS_OUT; |
---|
[1808] | 111 | } else if ( !strcmp(k, "--thru") ) { |
---|
| 112 | dir = ROAR_DIR_THRU; |
---|
[1814] | 113 | } else if ( !strcmp(k, "--rel-id") ) { |
---|
| 114 | rel_id = atoi(argv[++i]); |
---|
[1808] | 115 | |
---|
[2813] | 116 | } else if ( !strcmp(k, "--prethru") ) { |
---|
| 117 | prethru = 1; |
---|
| 118 | |
---|
[1635] | 119 | } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) { |
---|
[0] | 120 | usage(); |
---|
| 121 | return 0; |
---|
[2045] | 122 | } else if ( !file_opened ) { |
---|
| 123 | file_opened = 1; |
---|
| 124 | if ( roar_vio_open_dstr(&file, k, &def, 1) == -1 ) { |
---|
[991] | 125 | fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno)); |
---|
| 126 | return 1; |
---|
| 127 | } |
---|
[0] | 128 | } else { |
---|
| 129 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 130 | usage(); |
---|
| 131 | return 1; |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
[2420] | 135 | switch (dir) { |
---|
| 136 | case ROAR_DIR_MONITOR: |
---|
| 137 | if ( rate == -1 ) rate = ROAR_RATE_DEFAULT; |
---|
| 138 | if ( bits == -1 ) bits = ROAR_BITS_DEFAULT; |
---|
| 139 | if ( channels == -1 ) channels = ROAR_CHANNELS_DEFAULT; |
---|
| 140 | if ( codec == -1 ) codec = ROAR_CODEC_DEFAULT; |
---|
| 141 | break; |
---|
| 142 | case ROAR_DIR_MIDI_OUT: |
---|
| 143 | if ( rate == -1 ) rate = 0; |
---|
| 144 | if ( bits == -1 ) bits = ROAR_MIDI_BITS; |
---|
| 145 | if ( channels == -1 ) channels = ROAR_MIDI_CHANNELS_DEFAULT; |
---|
| 146 | if ( codec == -1 ) codec = ROAR_CODEC_MIDI; |
---|
| 147 | break; |
---|
| 148 | case ROAR_DIR_LIGHT_OUT: |
---|
| 149 | if ( rate == -1 ) rate = 0; |
---|
| 150 | if ( bits == -1 ) bits = ROAR_LIGHT_BITS; |
---|
| 151 | if ( channels == -1 ) channels = 0; |
---|
| 152 | if ( codec == -1 ) codec = ROAR_CODEC_DMX512; |
---|
| 153 | break; |
---|
[2692] | 154 | case ROAR_DIR_COMPLEX_OUT: |
---|
[2681] | 155 | if ( rate == -1 ) rate = ROAR_COMPLEX_RATE; |
---|
| 156 | if ( bits == -1 ) bits = ROAR_COMPLEX_BITS; |
---|
| 157 | if ( channels == -1 ) channels = ROAR_COMPLEX_CHANNELS; |
---|
| 158 | if ( codec == -1 ) codec = ROAR_COMPLEX_CODEC; |
---|
| 159 | break; |
---|
[2712] | 160 | case ROAR_DIR_RDTCS_OUT: |
---|
| 161 | if ( rate == -1 ) rate = ROAR_RDTCS_RATE; |
---|
| 162 | if ( bits == -1 ) bits = ROAR_RDTCS_BITS; |
---|
| 163 | if ( channels == -1 ) channels = ROAR_RDTCS_CHANNELS; |
---|
| 164 | if ( codec == -1 ) codec = ROAR_RDTCS_CODEC; |
---|
| 165 | break; |
---|
[2420] | 166 | case ROAR_DIR_RAW_OUT: |
---|
| 167 | case ROAR_DIR_THRU: |
---|
| 168 | default: |
---|
| 169 | if ( rate == -1 ) rate = 0; |
---|
| 170 | if ( bits == -1 ) bits = 0; |
---|
| 171 | if ( channels == -1 ) channels = 0; |
---|
| 172 | if ( codec == -1 ) codec = ROAR_CODEC_DEFAULT; |
---|
| 173 | break; |
---|
| 174 | } |
---|
| 175 | |
---|
[1814] | 176 | if ( roar_simple_connect(&con, server, "roarmon") == -1 ) { |
---|
| 177 | fprintf(stderr, "Error: can not connect to server\n"); |
---|
| 178 | return 10; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) { |
---|
| 182 | fprintf(stderr, "Error: can not create stream\n"); |
---|
| 183 | roar_disconnect(&con); |
---|
| 184 | return 20; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | if ( rel_id != -1 ) { |
---|
| 188 | if ( roar_stream_set_rel_id(&s, rel_id) ) { |
---|
| 189 | fprintf(stderr, "Error: can not set id or realative stream\n"); |
---|
| 190 | roar_disconnect(&con); |
---|
| 191 | return 21; |
---|
| 192 | } |
---|
[0] | 193 | } |
---|
| 194 | |
---|
[1814] | 195 | if ( roar_stream_connect(&con, &s, dir) == -1 ) { |
---|
| 196 | fprintf(stderr, "Error: can not connect stream to server\n"); |
---|
| 197 | roar_disconnect(&con); |
---|
| 198 | return 11; |
---|
| 199 | } |
---|
| 200 | |
---|
[2813] | 201 | if ( prethru ) { |
---|
| 202 | if ( roar_stream_set_flags(&con, &s, ROAR_FLAG_PRETHRU, 0) == -1 ) { |
---|
| 203 | fprintf(stderr, "Error: can not set prethru flag on stream\n"); |
---|
| 204 | roar_disconnect(&con); |
---|
| 205 | return 14; |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | |
---|
[1814] | 209 | if ( roar_stream_exec(&con, &s) == -1 ) { |
---|
| 210 | fprintf(stderr, "Error: can not exec stream\n"); |
---|
| 211 | roar_disconnect(&con); |
---|
| 212 | return 12; |
---|
| 213 | } |
---|
| 214 | |
---|
[2045] | 215 | if ( roar_get_connection_vio(&con, &stream) == -1 ) { |
---|
| 216 | fprintf(stderr, "Error: can not get stream vio\n"); |
---|
[1814] | 217 | roar_disconnect(&con); |
---|
| 218 | return 13; |
---|
| 219 | } |
---|
| 220 | |
---|
[2045] | 221 | // TODO: FIXME: |
---|
| 222 | // ROAR_SHUTDOWN(fh, SHUT_WR); // we need to have something do do shutdowns here... |
---|
[1814] | 223 | |
---|
[2045] | 224 | roar_vio_copy_data(&file, &stream); |
---|
[0] | 225 | |
---|
[2045] | 226 | roar_vio_close(&stream); |
---|
| 227 | roar_vio_close(&file); |
---|
[0] | 228 | |
---|
| 229 | return 0; |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | //ll |
---|