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