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