[0] | 1 | //roarctl.c: |
---|
| 2 | |
---|
[669] | 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
| 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 | |
---|
[3211] | 26 | #define _UNITS_T_BASE_USEC |
---|
| 27 | |
---|
[0] | 28 | #include <roaraudio.h> |
---|
[3211] | 29 | #include <roaraudio/units.h> |
---|
[3539] | 30 | #include <libroardsp/libroardsp.h> |
---|
[1782] | 31 | |
---|
| 32 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) |
---|
| 33 | #define _POSIX_USERS |
---|
| 34 | #endif |
---|
| 35 | |
---|
| 36 | #ifdef _POSIX_USERS |
---|
[445] | 37 | #include <pwd.h> |
---|
| 38 | #include <grp.h> |
---|
[1782] | 39 | #endif |
---|
| 40 | |
---|
[1630] | 41 | #include <sys/time.h> |
---|
| 42 | #include <time.h> |
---|
[445] | 43 | |
---|
[2916] | 44 | #ifdef ROAR_HAVE_LIBM |
---|
| 45 | #include <math.h> |
---|
| 46 | #endif |
---|
| 47 | |
---|
[963] | 48 | int g_verbose = 0; |
---|
[0] | 49 | |
---|
[25] | 50 | int display_mixer (struct roar_connection * con, int stream); |
---|
[112] | 51 | int show_meta_all (struct roar_connection * con, int id); |
---|
[25] | 52 | |
---|
[0] | 53 | void usage (void) { |
---|
[233] | 54 | printf("roarctl [OPTIONS]... COMMAND [OPTS] [COMMAND [OPTS] [COMMAND [OPTS] [...]]]\n"); |
---|
[0] | 55 | |
---|
| 56 | printf("\nOptions:\n\n"); |
---|
| 57 | |
---|
[86] | 58 | printf(" --server SERVER - Set server hostname\n" |
---|
| 59 | " --help - Show this help\n" |
---|
[963] | 60 | " --verbose -v - Show verbose output\n" |
---|
[0] | 61 | ); |
---|
| 62 | |
---|
| 63 | printf("\nCommands:\n\n"); |
---|
| 64 | printf( |
---|
[86] | 65 | " help - Show this help\n" |
---|
[1204] | 66 | " sleep TIME - Sleeps for TIME seconds\n" |
---|
[1781] | 67 | #ifdef ROAR_HAVE_GETTIMEOFDAY |
---|
[1630] | 68 | " ping NUM - Do NUM pings using NOOP commands\n" |
---|
[1781] | 69 | #endif |
---|
[2700] | 70 | " whoami - Get own client ID\n" |
---|
[0] | 71 | "\n" |
---|
[86] | 72 | " standby, off - Go into standby mode\n" |
---|
| 73 | " resume, on - Go into active mode\n" |
---|
| 74 | " standbymode - Show current standby mode\n" |
---|
| 75 | " exit - Quits the roard (must be used as last command)\n" |
---|
[577] | 76 | " terminate - Like exit but let the server up to serve still connected clients,\n" |
---|
| 77 | " new clients cann't connect and the server terminates after the last\n" |
---|
| 78 | " client disconnected\n" |
---|
[0] | 79 | "\n" |
---|
[3560] | 80 | " volume ID CHAN [scale S] V0 V1...\n" |
---|
| 81 | " - Sets volume for stream ID\n" |
---|
[86] | 82 | " CHAN is the number of channels or 'mono' or 'stereo'\n" |
---|
| 83 | " if mono or stereo is chosen roarctl trys to set\n" |
---|
| 84 | " sensfull values for all channels even if the output\n" |
---|
| 85 | " is has more channels.\n" |
---|
[3560] | 86 | " An optional scale can be given using S.\n" |
---|
[86] | 87 | " all other args are the volumes of the channels\n" |
---|
| 88 | " you may use integer or percent values.\n" |
---|
| 89 | " percent values can flooding points.\n" |
---|
[0] | 90 | "\n" |
---|
[1123] | 91 | " flag ID FLAGS - Sets flags FLAGS on stream ID. FLAGS may be a comma\n" |
---|
| 92 | " seperated list of flags.\n" |
---|
| 93 | " unflag ID FLAGS - Unsets flags on a stream. See flag.\n" |
---|
| 94 | "\n" |
---|
[86] | 95 | " kick TYPE ID - Kicks object of TYPE with id ID\n" |
---|
| 96 | " Types: client stream sample source\n" |
---|
[2698] | 97 | " newvirtual P D E R B C - Adds a new virtual (child) stream\n" |
---|
| 98 | " Parameters:\n" |
---|
| 99 | " P: Parent stream ID, D: Direction,\n" |
---|
| 100 | " E: codEc, R: sample Rate,\n" |
---|
| 101 | " B: bits per sample, C: nummer of channels\n" |
---|
[86] | 102 | "\n" |
---|
[2700] | 103 | " metaget ID TYPE - Read meta date of type TYPE from stream ID\n" |
---|
| 104 | // TODO: document metaset here. |
---|
[1160] | 105 | " metasave ID FILE - Saves meta data of stream ID to file FILE\n" |
---|
| 106 | " metaload ID FILE - Loads meta data from file FILE and set it on stream ID\n" |
---|
| 107 | "\n" |
---|
[86] | 108 | " serveroinfo - Gets Informations about server output\n" |
---|
| 109 | " listclients - Gets Informations about clients\n" |
---|
| 110 | " liststreams - Gets Informations about streams\n" |
---|
| 111 | " allinfo - Get all infos\n" |
---|
[0] | 112 | ); |
---|
| 113 | } |
---|
| 114 | |
---|
[1781] | 115 | #ifdef ROAR_HAVE_GETTIMEOFDAY |
---|
[1630] | 116 | int ping (struct roar_connection * con, int num) { |
---|
| 117 | struct timeval try, ans; |
---|
| 118 | struct roar_message m; |
---|
| 119 | register int ret; |
---|
[1631] | 120 | int i; |
---|
| 121 | double cur, min = 3600*1000, max = 0, sum = 0; |
---|
| 122 | |
---|
| 123 | if ( num == 0 ) |
---|
| 124 | return 0; |
---|
[1630] | 125 | |
---|
| 126 | for (i = 0; i < num; i++) { |
---|
| 127 | m.cmd = ROAR_CMD_NOOP; |
---|
| 128 | m.datalen = 0; |
---|
| 129 | |
---|
| 130 | gettimeofday(&try, NULL); |
---|
| 131 | ret = roar_req(con, &m, NULL); |
---|
| 132 | gettimeofday(&ans, NULL); |
---|
| 133 | |
---|
| 134 | if ( ret == -1 ) |
---|
| 135 | return -1; |
---|
| 136 | |
---|
| 137 | while (ans.tv_sec > try.tv_sec) { |
---|
| 138 | ans.tv_sec--; |
---|
| 139 | ans.tv_usec += 1000000; |
---|
| 140 | } |
---|
| 141 | ans.tv_usec -= try.tv_usec; |
---|
| 142 | |
---|
[1631] | 143 | printf("Pong from server: seq=%i time=%.3fms\n", i, (cur = ans.tv_usec/1000.0)); |
---|
| 144 | |
---|
| 145 | sum += cur; |
---|
| 146 | if ( min > cur ) |
---|
| 147 | min = cur; |
---|
| 148 | if ( cur > max ) |
---|
| 149 | max = cur; |
---|
[1630] | 150 | |
---|
| 151 | if ( i != (num - 1) ) |
---|
| 152 | sleep(1); |
---|
| 153 | } |
---|
| 154 | |
---|
[1631] | 155 | printf("\n--- ping statistics ---\n"); |
---|
| 156 | printf("%i packets transmitted\n", i); |
---|
| 157 | printf("rtt min/avg/max = %.3f/%.3f/%.3f ms\n", min, sum/(double)i, max); |
---|
| 158 | |
---|
[1630] | 159 | return 0; |
---|
| 160 | } |
---|
[1781] | 161 | #endif |
---|
[1630] | 162 | |
---|
[0] | 163 | void server_oinfo (struct roar_connection * con) { |
---|
| 164 | struct roar_stream s; |
---|
| 165 | |
---|
| 166 | if ( roar_server_oinfo(con, &s) == -1 ) { |
---|
| 167 | fprintf(stderr, "Error: can not get server output info\n"); |
---|
| 168 | return; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | printf("Stream direction : %s\n", roar_dir2str(s.dir)); |
---|
| 172 | printf("Server Output rate : %i\n", s.info.rate); |
---|
| 173 | printf("Server Output bits : %i\n", s.info.bits); |
---|
| 174 | printf("Server Output channels: %i\n", s.info.channels); |
---|
| 175 | printf("Server Output codec : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec), |
---|
| 176 | s.info.codec == ROAR_CODEC_DEFAULT ? " native" : ""); |
---|
| 177 | // printf("Server Output rate: %i", s.info.rate); |
---|
[984] | 178 | if ( g_verbose > 1 ) |
---|
| 179 | printf("Server Position : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels)); |
---|
[0] | 180 | } |
---|
| 181 | |
---|
[449] | 182 | const char * proc_name (pid_t pid) { |
---|
| 183 | static char ret[80] = "?"; |
---|
| 184 | #ifdef __linux__ |
---|
| 185 | char file[80], buf[80], *r; |
---|
| 186 | int i; |
---|
| 187 | |
---|
| 188 | snprintf(file, 79, "/proc/%i/exe", pid); |
---|
| 189 | file[79] = 0; |
---|
| 190 | |
---|
| 191 | ret[0] = '?'; |
---|
| 192 | ret[1] = 0; |
---|
| 193 | |
---|
| 194 | if ( (i = readlink(file, buf, 79)) != -1 ) { |
---|
| 195 | buf[i] = 0; |
---|
| 196 | if ( (r = strrchr(buf, '/')) != NULL ) { |
---|
| 197 | r++; |
---|
| 198 | if ( *r != 0 ) |
---|
| 199 | strcpy(ret, r); |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | #endif |
---|
| 203 | |
---|
| 204 | return ret; |
---|
| 205 | } |
---|
| 206 | |
---|
[0] | 207 | void list_clients (struct roar_connection * con) { |
---|
| 208 | int i; |
---|
| 209 | int num; |
---|
| 210 | int h; |
---|
| 211 | int id[ROAR_CLIENTS_MAX]; |
---|
[2620] | 212 | char tmp[80]; |
---|
[2814] | 213 | int self_id; |
---|
| 214 | struct roar_client self_client; |
---|
[0] | 215 | struct roar_client c; |
---|
[1782] | 216 | #ifdef _POSIX_USERS |
---|
[445] | 217 | struct group * grp = NULL; |
---|
| 218 | struct passwd * pwd = NULL; |
---|
[1782] | 219 | #endif |
---|
[0] | 220 | |
---|
[2814] | 221 | if ( (self_id = roar_get_clientid(con)) != -1 ) { |
---|
| 222 | if ( roar_get_client(con, &self_client, self_id) == -1 ) |
---|
| 223 | self_id = -1; |
---|
| 224 | } |
---|
| 225 | |
---|
[0] | 226 | if ( (num = roar_list_clients(con, id, ROAR_CLIENTS_MAX)) == -1 ) { |
---|
| 227 | fprintf(stderr, "Error: can not get client list\n"); |
---|
| 228 | return; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | for (i = 0; i < num; i++) { |
---|
| 232 | printf("client %i:\n", id[i]); |
---|
| 233 | if ( roar_get_client(con, &c, id[i]) == -1 ) { |
---|
| 234 | fprintf(stderr, "Error: can not get client info\n"); |
---|
| 235 | continue; |
---|
| 236 | } |
---|
[2621] | 237 | printf("Client name : %s\n", c.name); |
---|
[2814] | 238 | |
---|
| 239 | if ( roar_nnode_get_socktype(&(c.nnode)) != ROAR_SOCKET_TYPE_UNKNOWN ) { |
---|
| 240 | if ( roar_nnode_to_str(&(c.nnode), tmp, 80) == 0 ) { |
---|
| 241 | printf("Client network node : %s\n", tmp); |
---|
| 242 | } |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | if ( self_id != -1 && roar_nnode_cmp(&(self_client.nnode), &(c.nnode)) == 0 ) { |
---|
| 246 | printf("Client PID : %i(%s)\n", c.pid, proc_name(c.pid)); |
---|
| 247 | } else { |
---|
| 248 | printf("Client PID : %i\n", c.pid); |
---|
| 249 | } |
---|
[445] | 250 | if ( c.uid != -1 ) { |
---|
[1782] | 251 | #ifdef _POSIX_USERS |
---|
[2814] | 252 | if ( self_id != -1 && roar_nnode_cmp(&(self_client.nnode), &(c.nnode)) == 0 ) { |
---|
| 253 | pwd = getpwuid(c.uid); |
---|
| 254 | grp = getgrgid(c.gid); |
---|
| 255 | printf("Client UID/GID : %i(%s)/%i(%s)\n", c.uid, pwd ? pwd->pw_name : "?", c.gid, grp ? grp->gr_name : "?"); |
---|
| 256 | } else { |
---|
[1782] | 257 | #else |
---|
[2814] | 258 | if ( 1 ) { |
---|
[1782] | 259 | #endif |
---|
[2814] | 260 | printf("Client UID/GID : %i/%i\n", c.uid, c.gid); |
---|
| 261 | } |
---|
[445] | 262 | } |
---|
[2550] | 263 | |
---|
| 264 | if ( g_verbose && c.proto != ROAR_PROTO_NONE ) { |
---|
[2621] | 265 | printf("Client Protocol : %s\n", roar_proto2str(c.proto)); |
---|
[2550] | 266 | } |
---|
| 267 | |
---|
[2617] | 268 | if ( g_verbose && c.byteorder != ROAR_BYTEORDER_UNKNOWN ) { |
---|
[2620] | 269 | if ( c.byteorder == ROAR_BYTEORDER_NETWORK ) { |
---|
| 270 | strcpy(tmp, " (network byteorder"); |
---|
| 271 | } else { |
---|
| 272 | *tmp = 0; |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | if ( c.byteorder == ROAR_BYTEORDER_NATIVE ) { |
---|
| 276 | if ( *tmp ) { |
---|
| 277 | strcat(tmp, ", native"); |
---|
| 278 | } else { |
---|
| 279 | strcpy(tmp, " (native"); |
---|
| 280 | } |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | if ( *tmp ) |
---|
| 284 | strcat(tmp, ")"); |
---|
| 285 | |
---|
[2621] | 286 | printf("Client Byteorder : %s%s\n", roar_byteorder2str(c.byteorder), tmp); |
---|
[2617] | 287 | } |
---|
| 288 | |
---|
[0] | 289 | if ( c.execed != -1 ) |
---|
| 290 | printf("Execed stream : %i\n", c.execed); |
---|
| 291 | |
---|
| 292 | for (h = 0; h < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; h++) |
---|
| 293 | if ( c.streams[h] != -1 ) |
---|
| 294 | printf("stream : %i\n", c.streams[h]); |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | void list_streams (struct roar_connection * con) { |
---|
| 300 | int i; |
---|
| 301 | int num; |
---|
| 302 | int id[ROAR_STREAMS_MAX]; |
---|
[3539] | 303 | char chanmap[ROAR_MAX_CHANNELS]; |
---|
[0] | 304 | struct roar_stream s; |
---|
[465] | 305 | struct roar_stream_info info; |
---|
[3539] | 306 | char buffer[1024]; |
---|
| 307 | char * flags = buffer; |
---|
| 308 | char * name = buffer; |
---|
[2399] | 309 | char * infotext; |
---|
[3539] | 310 | size_t len; |
---|
[0] | 311 | |
---|
| 312 | |
---|
| 313 | if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) { |
---|
| 314 | fprintf(stderr, "Error: can not get stream list\n"); |
---|
| 315 | return; |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | for (i = 0; i < num; i++) { |
---|
| 319 | printf("stream %i:\n", id[i]); |
---|
| 320 | if ( roar_get_stream(con, &s, id[i]) == -1 ) { |
---|
| 321 | fprintf(stderr, "Error: can not get stream info\n"); |
---|
| 322 | continue; |
---|
| 323 | } |
---|
| 324 | printf("Stream direction : %s\n", roar_dir2str(s.dir)); |
---|
[1842] | 325 | |
---|
| 326 | if ( roar_stream_get_name(con, &s, name, 1024) == 0 ) |
---|
| 327 | printf("Stream name : %s\n", name); |
---|
| 328 | |
---|
[1201] | 329 | if ( s.pos_rel_id == -1 ) { |
---|
[0] | 330 | printf("Relativ position id : none (stream not synchronized)\n"); |
---|
[1201] | 331 | } else if ( s.pos_rel_id == id[i] ) { |
---|
| 332 | printf("Relativ position id : %i (self synchronized)\n", s.pos_rel_id); |
---|
| 333 | } else { |
---|
| 334 | printf("Relativ position id : %i (synchronized)\n", s.pos_rel_id); |
---|
| 335 | } |
---|
[1889] | 336 | if ( g_verbose > 1 ) { |
---|
| 337 | if ( s.info.rate && s.info.channels ) { |
---|
| 338 | printf("Position : %lu S (%.3fs)\n", (unsigned long int) s.pos, |
---|
| 339 | (float)s.pos/(s.info.rate*s.info.channels)); |
---|
| 340 | } else { |
---|
| 341 | printf("Position : %lu S\n", (unsigned long int) s.pos); |
---|
| 342 | } |
---|
| 343 | } |
---|
[1810] | 344 | |
---|
[2399] | 345 | switch (s.dir) { |
---|
| 346 | case ROAR_DIR_MIDI_IN: |
---|
| 347 | case ROAR_DIR_MIDI_OUT: |
---|
| 348 | infotext = " ticks/s"; |
---|
| 349 | break; |
---|
| 350 | case ROAR_DIR_LIGHT_IN: |
---|
| 351 | case ROAR_DIR_LIGHT_OUT: |
---|
| 352 | infotext = " updates/s"; |
---|
| 353 | break; |
---|
| 354 | default: |
---|
| 355 | infotext = " Hz"; |
---|
| 356 | } |
---|
| 357 | if ( s.info.rate ) |
---|
| 358 | printf("Stream sample rate : %i%s\n", s.info.rate, infotext); |
---|
| 359 | if ( s.info.bits ) |
---|
[2261] | 360 | printf("Stream bits : %i\n", s.info.bits); |
---|
[2399] | 361 | if ( s.info.channels ) |
---|
| 362 | printf("Stream channels : %i\n", s.info.channels); |
---|
[1810] | 363 | |
---|
[2261] | 364 | printf("Stream codec : %2i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec), |
---|
[540] | 365 | s.info.codec == ROAR_CODEC_DEFAULT ? " native" : ""); |
---|
[465] | 366 | if ( roar_stream_get_info(con, &s, &info) != -1 ) { |
---|
[1833] | 367 | if ( info.codec != s.info.codec ) { |
---|
[2554] | 368 | printf("Streamed codec : %2i (%s%s)\n", info.codec, roar_codec2str(info.codec), |
---|
[1833] | 369 | info.codec == ROAR_CODEC_DEFAULT ? " native" : ""); |
---|
| 370 | } |
---|
| 371 | |
---|
[963] | 372 | if ( g_verbose ) { |
---|
[1889] | 373 | if ( info.block_size ) |
---|
[2261] | 374 | printf("Stream block size : %i Byte\n", info.block_size); |
---|
[1889] | 375 | |
---|
[963] | 376 | printf("Underruns pre/post : %i/%i\n", info.pre_underruns, info.post_underruns); |
---|
[1137] | 377 | if ( g_verbose > 1 ) |
---|
[3211] | 378 | printf("Stream delay : %ims (%.2fm)\n", (int)info.delay/1000, (info.delay*(float)_SPEED_OF_SOUND)); |
---|
[963] | 379 | |
---|
[2634] | 380 | if ( g_verbose > 1 ) |
---|
[3213] | 381 | printf("Stream mixer : %i\n", info.mixer); |
---|
| 382 | |
---|
| 383 | if ( g_verbose > 1 ) |
---|
[2634] | 384 | printf("Stream state : %s\n", roar_streamstate2str(info.state)); |
---|
| 385 | |
---|
[963] | 386 | *flags = 0; |
---|
| 387 | if ( info.flags & ROAR_FLAG_PRIMARY ) |
---|
| 388 | strcat(flags, "primary "); |
---|
| 389 | if ( info.flags & ROAR_FLAG_SYNC ) |
---|
| 390 | strcat(flags, "sync "); |
---|
| 391 | if ( info.flags & ROAR_FLAG_OUTPUT ) |
---|
| 392 | strcat(flags, "output "); |
---|
| 393 | if ( info.flags & ROAR_FLAG_SOURCE ) |
---|
| 394 | strcat(flags, "source "); |
---|
[1032] | 395 | if ( info.flags & ROAR_FLAG_META ) |
---|
| 396 | strcat(flags, "meta "); |
---|
[1219] | 397 | if ( info.flags & ROAR_FLAG_AUTOCONF ) |
---|
| 398 | strcat(flags, "autoconf "); |
---|
| 399 | if ( info.flags & ROAR_FLAG_CLEANMETA ) |
---|
| 400 | strcat(flags, "cleanmeta "); |
---|
[1585] | 401 | if ( info.flags & ROAR_FLAG_HWMIXER ) |
---|
| 402 | strcat(flags, "hwmixer "); |
---|
| 403 | if ( info.flags & ROAR_FLAG_PAUSE ) |
---|
| 404 | strcat(flags, "pause "); |
---|
[1883] | 405 | if ( info.flags & ROAR_FLAG_MUTE ) |
---|
| 406 | strcat(flags, "mute "); |
---|
[1926] | 407 | if ( info.flags & ROAR_FLAG_MMAP ) |
---|
| 408 | strcat(flags, "mmap "); |
---|
[2154] | 409 | if ( info.flags & ROAR_FLAG_ANTIECHO ) |
---|
| 410 | strcat(flags, "antiecho "); |
---|
[2324] | 411 | if ( info.flags & ROAR_FLAG_VIRTUAL ) |
---|
| 412 | strcat(flags, "virtual "); |
---|
[2412] | 413 | if ( info.flags & ROAR_FLAG_RECSOURCE ) |
---|
| 414 | strcat(flags, "recsource "); |
---|
| 415 | if ( info.flags & ROAR_FLAG_PASSMIXER ) |
---|
| 416 | strcat(flags, "passmixer "); |
---|
[2814] | 417 | if ( info.flags & ROAR_FLAG_PRETHRU ) |
---|
| 418 | strcat(flags, "prethru "); |
---|
[2953] | 419 | if ( info.flags & ROAR_FLAG_IMMUTABLE ) |
---|
| 420 | strcat(flags, "immutable "); |
---|
| 421 | if ( info.flags & ROAR_FLAG_ENHANCE ) |
---|
| 422 | strcat(flags, "enhance "); |
---|
[963] | 423 | |
---|
| 424 | printf("Flags : %s\n", flags); |
---|
| 425 | } |
---|
[465] | 426 | } |
---|
[1811] | 427 | |
---|
[3539] | 428 | if ( g_verbose ) { |
---|
| 429 | len = ROAR_MAX_CHANNELS; |
---|
| 430 | if ( roar_stream_get_chanmap(con, &s, chanmap, &len) == -1 ) { |
---|
| 431 | fprintf(stderr, "Error: can not get stream channel map\n"); |
---|
| 432 | } else { |
---|
| 433 | if ( roardsp_chanlist2str(chanmap, len, buffer, 1024) == -1 ) { |
---|
| 434 | fprintf(stderr, "Error: can not convert channel map into string\n"); |
---|
| 435 | } else { |
---|
| 436 | printf("Channel Map : %s\n", buffer); |
---|
| 437 | } |
---|
| 438 | } |
---|
| 439 | } |
---|
| 440 | |
---|
[1811] | 441 | if ( s.dir != ROAR_DIR_THRU ) { |
---|
| 442 | display_mixer(con, id[i]); |
---|
| 443 | show_meta_all(con, id[i]); |
---|
| 444 | } |
---|
[0] | 445 | } |
---|
| 446 | |
---|
| 447 | } |
---|
| 448 | |
---|
[25] | 449 | int display_mixer (struct roar_connection * con, int stream) { |
---|
[3529] | 450 | struct roar_mixer_settings mixer; |
---|
[25] | 451 | int channels; |
---|
| 452 | int i; |
---|
[3529] | 453 | float fs; |
---|
[25] | 454 | |
---|
| 455 | if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) { |
---|
[3530] | 456 | fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", stream); |
---|
[25] | 457 | return -1; |
---|
| 458 | } |
---|
| 459 | |
---|
[2916] | 460 | #ifdef ROAR_HAVE_LIBM |
---|
| 461 | #define _DB ", %.2fdB" |
---|
| 462 | #else |
---|
| 463 | #define _DB "" |
---|
| 464 | #endif |
---|
| 465 | |
---|
[3529] | 466 | fs = (float)mixer.scale / 100.; |
---|
| 467 | |
---|
[3531] | 468 | if ( channels ) { // we hide RPG info for zero-channel streams |
---|
| 469 | printf("Mixer ReplayGain : %i/%i (%.2f%%" _DB ")\n", mixer.rpg_mul, mixer.rpg_div, |
---|
| 470 | 100.*(float)mixer.rpg_mul/((float)mixer.rpg_div) |
---|
[3529] | 471 | #ifdef ROAR_HAVE_LIBM |
---|
[3531] | 472 | , 20*log10f((float)mixer.rpg_mul/(float)mixer.rpg_div) |
---|
[3529] | 473 | #endif |
---|
[3531] | 474 | ); |
---|
| 475 | } |
---|
[3529] | 476 | |
---|
[25] | 477 | for (i = 0; i < channels; i++) |
---|
[3529] | 478 | printf("Mixer volume chan %2i : %i/%i (%.2f%%" _DB ")\n", i, mixer.mixer[i], mixer.scale, |
---|
| 479 | (float)mixer.mixer[i]/fs |
---|
[2916] | 480 | #ifdef ROAR_HAVE_LIBM |
---|
[3529] | 481 | , 20*log10f((float)mixer.mixer[i]/(float)mixer.scale) |
---|
[2916] | 482 | #endif |
---|
| 483 | ); |
---|
[25] | 484 | |
---|
| 485 | return 0; |
---|
| 486 | } |
---|
[0] | 487 | |
---|
[3530] | 488 | static unsigned int set_mixer_parse_volume (char * k, int len, uint16_t scale) { |
---|
| 489 | float fs = scale; |
---|
| 490 | |
---|
[2916] | 491 | switch (k[len - 1]) { |
---|
| 492 | case '%': |
---|
| 493 | k[len - 1] = 0; |
---|
[3530] | 494 | return (atof(k)*fs)/100.; |
---|
[2916] | 495 | break; |
---|
| 496 | #ifdef ROAR_HAVE_LIBM |
---|
| 497 | case 'b': |
---|
| 498 | case 'B': |
---|
| 499 | // TODO: can we hanle the error better? |
---|
| 500 | if ( len < 2 ) |
---|
| 501 | return 0; |
---|
| 502 | |
---|
| 503 | k[len - 2] = 0; |
---|
[3530] | 504 | return powf(10, atof(k)/20.f)*fs; |
---|
[2916] | 505 | break; |
---|
| 506 | #endif |
---|
| 507 | } |
---|
| 508 | |
---|
| 509 | return atoi(k); |
---|
| 510 | } |
---|
| 511 | |
---|
[85] | 512 | int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) { |
---|
[3530] | 513 | uint16_t scale = 65535; |
---|
[85] | 514 | int chans = 0; |
---|
| 515 | int id; |
---|
| 516 | int i; |
---|
| 517 | int len; |
---|
| 518 | int old_chans; |
---|
[2738] | 519 | int vol_l, vol_r, vol_mono; |
---|
[85] | 520 | char * k; |
---|
| 521 | struct roar_mixer_settings mixer; |
---|
| 522 | struct roar_mixer_settings old_mixer; |
---|
| 523 | |
---|
| 524 | if (*cur + 2 > max) |
---|
| 525 | return -1; |
---|
| 526 | |
---|
| 527 | id = atoi(arg[++(*cur)]); |
---|
| 528 | |
---|
| 529 | k = arg[++(*cur)]; |
---|
| 530 | |
---|
| 531 | if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) { |
---|
[3530] | 532 | fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", id); |
---|
[85] | 533 | return -1; |
---|
| 534 | } |
---|
| 535 | |
---|
[3530] | 536 | if ( !strcmp(arg[*cur + 1], "scale") ) { |
---|
| 537 | (*cur)++; // 'scale' |
---|
[3559] | 538 | (*cur)++; |
---|
| 539 | scale = set_mixer_parse_volume(arg[*cur], strlen(arg[*cur]), 65535); |
---|
[3530] | 540 | } |
---|
[85] | 541 | |
---|
[1203] | 542 | // TODO: clean up code here as the % vs. abs code is very duplicate... |
---|
| 543 | |
---|
[85] | 544 | if ( strcmp(k, "mono") == 0 && old_chans != 1 ) { |
---|
| 545 | chans = 1; |
---|
| 546 | |
---|
| 547 | if ( *cur + 1 > max ) |
---|
| 548 | return -1; |
---|
| 549 | |
---|
| 550 | k = arg[++(*cur)]; |
---|
| 551 | len = strlen(k); |
---|
| 552 | |
---|
[3530] | 553 | vol_mono = set_mixer_parse_volume(k, len, scale); |
---|
[85] | 554 | |
---|
| 555 | for (i = 0; i < old_chans; i++) |
---|
[2738] | 556 | mixer.mixer[i] = vol_mono; |
---|
[85] | 557 | |
---|
| 558 | chans = old_chans; |
---|
| 559 | |
---|
[2738] | 560 | } else if ( strcmp(k, "stereo") == 0 && old_chans != 2 ) { |
---|
| 561 | chans = old_chans; |
---|
[1203] | 562 | |
---|
| 563 | if ( *cur + 2 > max ) |
---|
| 564 | return -1; |
---|
| 565 | |
---|
| 566 | k = arg[++(*cur)]; |
---|
| 567 | len = strlen(k); |
---|
| 568 | |
---|
[3530] | 569 | vol_l = set_mixer_parse_volume(k, len, scale); |
---|
[1203] | 570 | |
---|
| 571 | k = arg[++(*cur)]; |
---|
| 572 | len = strlen(k); |
---|
| 573 | |
---|
[3530] | 574 | vol_r = set_mixer_parse_volume(k, len, scale); |
---|
[1203] | 575 | |
---|
[2738] | 576 | vol_mono = (vol_l + vol_r) / 2; |
---|
| 577 | |
---|
[1203] | 578 | mixer.mixer[0] = vol_l; |
---|
| 579 | mixer.mixer[1] = vol_r; |
---|
| 580 | |
---|
[2738] | 581 | switch (chans) { |
---|
[2739] | 582 | case 1: |
---|
| 583 | mixer.mixer[0] = vol_mono; |
---|
| 584 | break; |
---|
| 585 | // case 2: classic stereo... |
---|
[2738] | 586 | case 3: |
---|
| 587 | mixer.mixer[2] = vol_mono; |
---|
| 588 | break; |
---|
| 589 | case 4: |
---|
| 590 | mixer.mixer[2] = vol_l; |
---|
| 591 | mixer.mixer[3] = vol_r; |
---|
| 592 | break; |
---|
| 593 | case 5: |
---|
| 594 | mixer.mixer[2] = vol_mono; |
---|
| 595 | mixer.mixer[3] = vol_l; |
---|
| 596 | mixer.mixer[4] = vol_r; |
---|
| 597 | break; |
---|
| 598 | case 6: |
---|
| 599 | mixer.mixer[2] = vol_mono; |
---|
| 600 | mixer.mixer[3] = vol_mono; |
---|
| 601 | mixer.mixer[4] = vol_l; |
---|
| 602 | mixer.mixer[5] = vol_r; |
---|
| 603 | break; |
---|
| 604 | default: |
---|
[2739] | 605 | ROAR_ERR("mode stereo not supported on stream with %i channels", chans); |
---|
[2738] | 606 | return -1; |
---|
| 607 | break; |
---|
| 608 | } |
---|
| 609 | |
---|
[85] | 610 | } else { |
---|
| 611 | if ( strcmp(k, "mono") == 0 ) { |
---|
| 612 | chans = 1; |
---|
| 613 | } else if ( strcmp(k, "stereo") == 0 ) { |
---|
| 614 | chans = 2; |
---|
| 615 | } else { |
---|
| 616 | chans = atoi(k); |
---|
| 617 | } |
---|
| 618 | |
---|
| 619 | // printf("mode: int; chans=%i, old_chans=%i\n", chans, old_chans); |
---|
| 620 | |
---|
| 621 | if ( *cur + chans > max ) |
---|
| 622 | return -1; |
---|
| 623 | |
---|
| 624 | for (i = 0; i < chans; i++) { |
---|
| 625 | k = arg[++(*cur)]; |
---|
| 626 | len = strlen(k); |
---|
| 627 | |
---|
[3530] | 628 | mixer.mixer[i] = set_mixer_parse_volume(k, len, scale); |
---|
[85] | 629 | } |
---|
| 630 | } |
---|
| 631 | |
---|
[3530] | 632 | mixer.scale = scale; |
---|
[85] | 633 | |
---|
| 634 | return roar_set_vol(con, id, &mixer, chans); |
---|
| 635 | } |
---|
| 636 | |
---|
[2698] | 637 | |
---|
| 638 | int newvirtual (struct roar_connection * con, char *p_s, char *d_s, char *e_s, char *r_s, char *b_s, char *c_s) { |
---|
| 639 | struct roar_stream s; |
---|
| 640 | int dir = roar_str2dir(d_s); |
---|
| 641 | int parent = atoi(p_s); |
---|
| 642 | |
---|
[2699] | 643 | ROAR_DBG("newvirtual(*): dir=%i, parent=%i", dir, parent); |
---|
| 644 | |
---|
[2698] | 645 | if ( roar_stream_new(&s, atoi(r_s), atoi(c_s), atoi(b_s), roar_str2codec(e_s)) == -1 ) |
---|
| 646 | return -1; |
---|
| 647 | |
---|
| 648 | return roar_simple_connect_virtual(con, &s, parent, dir); |
---|
| 649 | } |
---|
| 650 | |
---|
[99] | 651 | int set_meta (struct roar_connection * con, int id, char * mode, char * type, char * val) { |
---|
| 652 | struct roar_meta meta; |
---|
| 653 | struct roar_stream s; |
---|
| 654 | int mode_i = ROAR_META_MODE_SET; |
---|
| 655 | |
---|
[3072] | 656 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 657 | return -1; |
---|
[99] | 658 | |
---|
[106] | 659 | // printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val); |
---|
[99] | 660 | |
---|
| 661 | if ( strcmp(mode, "add") == 0 ) { |
---|
| 662 | mode_i = ROAR_META_MODE_ADD; |
---|
| 663 | } |
---|
| 664 | |
---|
[109] | 665 | meta.type = roar_meta_inttype(type); |
---|
[106] | 666 | meta.value = val; |
---|
| 667 | meta.key[0] = 0; |
---|
[99] | 668 | |
---|
[109] | 669 | if ( meta.type == -1 ) { |
---|
| 670 | fprintf(stderr, "Error: unknown type: %s\n", type); |
---|
| 671 | return -1; |
---|
| 672 | } |
---|
| 673 | |
---|
[106] | 674 | // printf("D: type=%i, mode=%i\n", meta.type, mode_i); |
---|
[99] | 675 | |
---|
[1127] | 676 | if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 ) |
---|
| 677 | return -1; |
---|
| 678 | |
---|
| 679 | meta.type = ROAR_META_TYPE_NONE; |
---|
| 680 | meta.value = NULL; |
---|
| 681 | |
---|
| 682 | return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta); |
---|
[99] | 683 | } |
---|
| 684 | |
---|
[1126] | 685 | int load_meta (struct roar_connection * con, int id, char * file) { |
---|
| 686 | struct roar_meta meta; |
---|
| 687 | struct roar_stream s; |
---|
| 688 | int mode_i = ROAR_META_MODE_SET; |
---|
| 689 | FILE * in; |
---|
| 690 | char lion[1024]; |
---|
| 691 | char * v; |
---|
| 692 | |
---|
[3072] | 693 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 694 | return -1; |
---|
[1126] | 695 | |
---|
| 696 | if ( (in = fopen(file, "r")) == NULL ) |
---|
| 697 | return -1; |
---|
| 698 | |
---|
| 699 | while (fgets(lion, 1024, in) != NULL) { |
---|
| 700 | if ( (v = strtok(lion, "\r\n")) != NULL ) |
---|
| 701 | if ( (v = strtok(NULL, "\r\n")) != NULL ) |
---|
| 702 | *(v-1) = 0; |
---|
| 703 | |
---|
| 704 | if ( (v = strstr(lion, "=")) == NULL ) { |
---|
| 705 | fprintf(stderr, "Error: can not parse meta data lion: %s\n", lion); |
---|
| 706 | continue; |
---|
| 707 | } |
---|
| 708 | |
---|
| 709 | *v++ = 0; |
---|
| 710 | |
---|
| 711 | meta.type = roar_meta_inttype(lion); |
---|
| 712 | meta.value = v; |
---|
| 713 | meta.key[0] = 0; |
---|
| 714 | |
---|
| 715 | if ( meta.type == -1 ) { |
---|
| 716 | fprintf(stderr, "Error: unknown type: %s\n", lion); |
---|
| 717 | continue; |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 ) |
---|
| 721 | return -1; |
---|
| 722 | } |
---|
| 723 | |
---|
| 724 | fclose(in); |
---|
| 725 | |
---|
| 726 | meta.type = ROAR_META_TYPE_NONE; |
---|
| 727 | meta.value = NULL; |
---|
| 728 | |
---|
| 729 | return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta); |
---|
| 730 | } |
---|
| 731 | |
---|
[106] | 732 | int show_meta_type (struct roar_connection * con, int id, char * type) { |
---|
| 733 | struct roar_meta meta; |
---|
| 734 | struct roar_stream s; |
---|
| 735 | |
---|
[3072] | 736 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 737 | return -1; |
---|
[106] | 738 | |
---|
[109] | 739 | meta.type = roar_meta_inttype(type); |
---|
| 740 | |
---|
| 741 | if ( meta.type == -1 ) { |
---|
| 742 | fprintf(stderr, "Error: unknown type: %s\n", type); |
---|
| 743 | return -1; |
---|
| 744 | } |
---|
[106] | 745 | |
---|
| 746 | if ( roar_stream_meta_get(con, &s, &meta) == -1 ) |
---|
| 747 | return -1; |
---|
| 748 | |
---|
[112] | 749 | printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value); |
---|
[106] | 750 | |
---|
| 751 | roar_meta_free(&meta); |
---|
| 752 | |
---|
| 753 | return 0; |
---|
| 754 | } |
---|
| 755 | |
---|
[112] | 756 | int show_meta_all (struct roar_connection * con, int id) { |
---|
| 757 | struct roar_stream s; |
---|
| 758 | int types[ROAR_META_MAX_PER_STREAM]; |
---|
| 759 | int i; |
---|
| 760 | int len; |
---|
| 761 | |
---|
[3072] | 762 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 763 | return -1; |
---|
[112] | 764 | |
---|
| 765 | if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 ) |
---|
| 766 | return -1; |
---|
| 767 | |
---|
| 768 | for (i = 0; i < len; i++) |
---|
| 769 | show_meta_type(con, id, roar_meta_strtype(types[i])); |
---|
| 770 | |
---|
| 771 | return 0; |
---|
| 772 | } |
---|
| 773 | |
---|
[1126] | 774 | int save_meta (struct roar_connection * con, int id, char * file) { |
---|
| 775 | struct roar_stream s; |
---|
| 776 | struct roar_meta meta; |
---|
| 777 | int types[ROAR_META_MAX_PER_STREAM]; |
---|
| 778 | int i; |
---|
| 779 | int len; |
---|
| 780 | FILE * out; |
---|
| 781 | |
---|
[3072] | 782 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 783 | return -1; |
---|
[1126] | 784 | |
---|
| 785 | if ( (out = fopen(file, "w")) == NULL ) |
---|
| 786 | return -1; |
---|
| 787 | |
---|
| 788 | if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 ) |
---|
| 789 | return -1; |
---|
| 790 | |
---|
| 791 | for (i = 0; i < len; i++) { |
---|
| 792 | /* |
---|
| 793 | show_meta_type(con, id, roar_meta_strtype(types[i])); |
---|
| 794 | */ |
---|
| 795 | meta.type = types[i]; |
---|
| 796 | |
---|
| 797 | if ( roar_stream_meta_get(con, &s, &meta) == -1 ) |
---|
| 798 | continue; |
---|
| 799 | |
---|
| 800 | // printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value); |
---|
| 801 | |
---|
| 802 | fprintf(out, "%s=%s\n", roar_meta_strtype(meta.type), meta.value); |
---|
| 803 | |
---|
| 804 | roar_meta_free(&meta); |
---|
| 805 | } |
---|
| 806 | |
---|
| 807 | fclose(out); |
---|
| 808 | |
---|
| 809 | return 0; |
---|
| 810 | } |
---|
| 811 | |
---|
[1043] | 812 | int set_flags (struct roar_connection * con, int id, int reset, char * flags) { |
---|
| 813 | int f = ROAR_FLAG_NONE; |
---|
| 814 | char * c; |
---|
| 815 | struct roar_stream s[1]; |
---|
| 816 | |
---|
[3072] | 817 | if ( roar_stream_new_by_id(s, id) == -1 ) |
---|
| 818 | return -1; |
---|
[1043] | 819 | |
---|
| 820 | c = strtok(flags, ","); |
---|
| 821 | while (c != NULL) { |
---|
| 822 | if ( !strcmp(c, "meta") ) { |
---|
| 823 | f |= ROAR_FLAG_META; |
---|
| 824 | } else if ( !strcmp(c, "primary") ) { |
---|
| 825 | f |= ROAR_FLAG_PRIMARY; |
---|
[1116] | 826 | } else if ( !strcmp(c, "sync") ) { |
---|
| 827 | f |= ROAR_FLAG_SYNC; |
---|
[1219] | 828 | } else if ( !strcmp(c, "cleanmeta") ) { |
---|
| 829 | f |= ROAR_FLAG_CLEANMETA; |
---|
[1585] | 830 | } else if ( !strcmp(c, "hwmixer") ) { |
---|
| 831 | f |= ROAR_FLAG_HWMIXER; |
---|
| 832 | } else if ( !strcmp(c, "pause") ) { |
---|
| 833 | f |= ROAR_FLAG_PAUSE; |
---|
[1883] | 834 | } else if ( !strcmp(c, "mute") ) { |
---|
| 835 | f |= ROAR_FLAG_MUTE; |
---|
[1926] | 836 | } else if ( !strcmp(c, "mmap") ) { |
---|
| 837 | f |= ROAR_FLAG_MMAP; |
---|
[2154] | 838 | } else if ( !strcmp(c, "antiecho") ) { |
---|
| 839 | f |= ROAR_FLAG_ANTIECHO; |
---|
[2412] | 840 | } else if ( !strcmp(c, "recsource") ) { |
---|
| 841 | f |= ROAR_FLAG_RECSOURCE; |
---|
| 842 | } else if ( !strcmp(c, "passmixer") ) { |
---|
| 843 | f |= ROAR_FLAG_PASSMIXER; |
---|
[2627] | 844 | } else if ( !strcmp(c, "virtual") ) { |
---|
| 845 | f |= ROAR_FLAG_VIRTUAL; |
---|
[2814] | 846 | } else if ( !strcmp(c, "prethru") ) { |
---|
| 847 | f |= ROAR_FLAG_PRETHRU; |
---|
[2953] | 848 | } else if ( !strcmp(c, "immutable") ) { |
---|
| 849 | f |= ROAR_FLAG_IMMUTABLE; |
---|
| 850 | } else if ( !strcmp(c, "enhance") ) { |
---|
| 851 | f |= ROAR_FLAG_ENHANCE; |
---|
[1043] | 852 | } else { |
---|
| 853 | fprintf(stderr, "Error: unknown flag: %s\n", c); |
---|
| 854 | return -1; |
---|
| 855 | } |
---|
| 856 | |
---|
| 857 | c = strtok(NULL, ","); |
---|
| 858 | } |
---|
| 859 | |
---|
| 860 | return roar_stream_set_flags(con, s, f, reset); |
---|
| 861 | } |
---|
| 862 | |
---|
[0] | 863 | int main (int argc, char * argv[]) { |
---|
| 864 | struct roar_connection con; |
---|
| 865 | char * server = NULL; |
---|
| 866 | char * k = NULL; |
---|
| 867 | int i; |
---|
| 868 | int t = 0; |
---|
| 869 | |
---|
| 870 | for (i = 1; i < argc; i++) { |
---|
| 871 | k = argv[i]; |
---|
| 872 | |
---|
| 873 | if ( strcmp(k, "--server") == 0 ) { |
---|
[58] | 874 | server = argv[++i]; |
---|
[963] | 875 | } else if ( strcmp(k, "-v") == 0 || strcmp(k, "--verbose") == 0 ) { |
---|
| 876 | g_verbose++; |
---|
[0] | 877 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
| 878 | usage(); |
---|
| 879 | return 0; |
---|
| 880 | } else if ( *k == '-' ) { |
---|
| 881 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 882 | usage(); |
---|
| 883 | return 1; |
---|
| 884 | } else { |
---|
| 885 | break; |
---|
| 886 | } |
---|
| 887 | } |
---|
| 888 | |
---|
| 889 | // connect |
---|
| 890 | |
---|
[3510] | 891 | if ( roar_simple_connect(&con, server, "roarctl") == -1 ) { |
---|
[0] | 892 | fprintf(stderr, "Error: Can not connect to server\n"); |
---|
| 893 | return 1; |
---|
| 894 | } |
---|
| 895 | |
---|
| 896 | if ( i == argc ) { |
---|
| 897 | fprintf(stderr, "Error: No Commands given\n"); |
---|
| 898 | return 0; // this is not a fatal error... |
---|
| 899 | } |
---|
| 900 | |
---|
| 901 | for (; i < argc; i++) { |
---|
| 902 | k = argv[i]; |
---|
| 903 | // cmd is in k |
---|
| 904 | |
---|
| 905 | printf("--- [ %s ] ---\n", k); |
---|
| 906 | |
---|
| 907 | if ( !strcmp(k, "help") ) { |
---|
| 908 | usage(); |
---|
| 909 | |
---|
[1202] | 910 | } else if ( !strcmp(k, "sleep") ) { |
---|
| 911 | sleep(atoi(argv[++i])); |
---|
[0] | 912 | |
---|
[1630] | 913 | } else if ( !strcmp(k, "ping") ) { |
---|
[1781] | 914 | #ifdef ROAR_HAVE_GETTIMEOFDAY |
---|
[1630] | 915 | if ( ping(&con, atoi(argv[++i])) == -1 ) { |
---|
| 916 | fprintf(stderr, "Error: can not ping\n"); |
---|
| 917 | } |
---|
[1781] | 918 | #else |
---|
| 919 | fprintf(stderr, "Error: ping not supported.\n"); |
---|
| 920 | i++; |
---|
| 921 | #endif |
---|
[1630] | 922 | |
---|
[0] | 923 | } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) { |
---|
| 924 | if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) { |
---|
| 925 | fprintf(stderr, "Error: can not set mode to standby\n"); |
---|
| 926 | } else { |
---|
| 927 | printf("going into standby\n"); |
---|
| 928 | } |
---|
| 929 | } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) { |
---|
| 930 | if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) { |
---|
| 931 | fprintf(stderr, "Error: can not set mode to active\n"); |
---|
| 932 | } else { |
---|
| 933 | printf("going into active mode\n"); |
---|
| 934 | } |
---|
| 935 | |
---|
| 936 | } else if ( !strcmp(k, "exit") ) { |
---|
| 937 | if ( roar_exit(&con) == -1 ) { |
---|
| 938 | fprintf(stderr, "Error: can not quit server\n"); |
---|
| 939 | } else { |
---|
| 940 | printf("Server quited\n"); |
---|
| 941 | break; |
---|
| 942 | } |
---|
[577] | 943 | } else if ( !strcmp(k, "terminate") ) { |
---|
| 944 | if ( roar_terminate(&con, 1) == -1 ) { |
---|
| 945 | fprintf(stderr, "Error: can not terminate server\n"); |
---|
| 946 | } else { |
---|
| 947 | printf("Server got asked to quited\n"); |
---|
| 948 | break; |
---|
| 949 | } |
---|
[0] | 950 | |
---|
| 951 | } else if ( !strcmp(k, "standbymode") ) { |
---|
| 952 | t = roar_get_standby(&con); |
---|
| 953 | if ( t == -1 ) { |
---|
| 954 | fprintf(stderr, "Error: can not get stanby mode\n"); |
---|
| 955 | } else if ( t == ROAR_STANDBY_ACTIVE ) { |
---|
| 956 | printf("Server is in standby\n"); |
---|
| 957 | } else if ( t == ROAR_STANDBY_INACTIVE ) { |
---|
| 958 | printf("Server is active\n"); |
---|
| 959 | } else { |
---|
| 960 | fprintf(stderr, "Error: unknown standby mode: %i\n", t); |
---|
| 961 | } |
---|
| 962 | |
---|
[1162] | 963 | } else if ( !strcmp(k, "whoami") ) { |
---|
| 964 | printf("My client ID is: %i\n", roar_get_clientid(&con)); |
---|
[0] | 965 | } else if ( !strcmp(k, "serveroinfo") ) { |
---|
| 966 | server_oinfo(&con); |
---|
| 967 | } else if ( !strcmp(k, "listclients") ) { |
---|
| 968 | list_clients(&con); |
---|
| 969 | } else if ( !strcmp(k, "liststreams") ) { |
---|
| 970 | list_streams(&con); |
---|
| 971 | } else if ( !strcmp(k, "allinfo") ) { |
---|
| 972 | server_oinfo(&con); |
---|
| 973 | printf("\n"); |
---|
| 974 | list_clients(&con); |
---|
| 975 | printf("\n"); |
---|
| 976 | list_streams(&con); |
---|
| 977 | |
---|
| 978 | } else if ( !strcmp(k, "kick") ) { |
---|
| 979 | k = argv[++i]; |
---|
| 980 | if ( !strcmp(k, "client") ) { |
---|
| 981 | t = ROAR_OT_CLIENT; |
---|
| 982 | } else if ( !strcmp(k, "stream") ) { |
---|
| 983 | t = ROAR_OT_STREAM; |
---|
| 984 | } else if ( !strcmp(k, "sample") ) { |
---|
| 985 | t = ROAR_OT_SAMPLE; |
---|
| 986 | } else if ( !strcmp(k, "source") ) { |
---|
| 987 | t = ROAR_OT_SOURCE; |
---|
| 988 | } else { |
---|
| 989 | fprintf(stderr, "Error: unknown type: %s\n", k); |
---|
| 990 | continue; |
---|
| 991 | } |
---|
| 992 | //t = atoi(argv[i++]); |
---|
| 993 | if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) { |
---|
| 994 | fprintf(stderr, "Error: can not kick %s\n", k); |
---|
| 995 | } else { |
---|
| 996 | printf("%s kicked\n", k); |
---|
| 997 | } |
---|
| 998 | |
---|
[2698] | 999 | } else if ( !strcmp(k, "newvirtual") ) { |
---|
[2699] | 1000 | if ( newvirtual(&con, argv[i+1], argv[i+2], argv[i+3], argv[i+4], argv[i+5], argv[i+6]) == -1 ) { |
---|
[2698] | 1001 | fprintf(stderr, "Error: can not create new virtual stream\n"); |
---|
| 1002 | } else { |
---|
| 1003 | printf("virtual stream created\n"); |
---|
| 1004 | } |
---|
[2699] | 1005 | i += 6; |
---|
[2698] | 1006 | |
---|
[85] | 1007 | } else if ( !strcmp(k, "volume") ) { |
---|
| 1008 | if ( set_mixer(&con, &i, argc, argv) == -1 ) { |
---|
| 1009 | fprintf(stderr, "Error: can not set volume\n"); |
---|
| 1010 | } else { |
---|
| 1011 | printf("volume changed\n"); |
---|
| 1012 | } |
---|
| 1013 | |
---|
[1043] | 1014 | } else if ( !strcmp(k, "flag") ) { |
---|
| 1015 | i++; |
---|
| 1016 | if ( set_flags(&con, atoi(argv[i]), ROAR_SET_FLAG, argv[i+1]) == -1 ) { |
---|
| 1017 | fprintf(stderr, "Error: can not set flags\n"); |
---|
| 1018 | } else { |
---|
| 1019 | printf("flags changed\n"); |
---|
| 1020 | } |
---|
| 1021 | i++; |
---|
| 1022 | } else if ( !strcmp(k, "unflag") ) { |
---|
| 1023 | i++; |
---|
| 1024 | if ( set_flags(&con, atoi(argv[i]), ROAR_RESET_FLAG, argv[i+1]) == -1 ) { |
---|
| 1025 | fprintf(stderr, "Error: can not reset flags\n"); |
---|
| 1026 | } else { |
---|
| 1027 | printf("flags changed\n"); |
---|
| 1028 | } |
---|
| 1029 | i++; |
---|
[106] | 1030 | } else if ( !strcmp(k, "metaset") ) { |
---|
[99] | 1031 | i++; |
---|
| 1032 | if ( set_meta(&con, atoi(argv[i]), argv[i+1], argv[i+2], argv[i+3]) == -1 ) { |
---|
| 1033 | fprintf(stderr, "Error: can not set meta data\n"); |
---|
| 1034 | } else { |
---|
| 1035 | printf("meta data changed\n"); |
---|
| 1036 | } |
---|
| 1037 | i += 3; |
---|
[106] | 1038 | } else if ( !strcmp(k, "metaget") ) { |
---|
| 1039 | i++; |
---|
| 1040 | if ( show_meta_type(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
| 1041 | fprintf(stderr, "Error: can not get meta data\n"); |
---|
| 1042 | } |
---|
| 1043 | i++; |
---|
[1126] | 1044 | } else if ( !strcmp(k, "metasave") ) { |
---|
| 1045 | i++; |
---|
| 1046 | if ( save_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
| 1047 | fprintf(stderr, "Error: can not get meta data\n"); |
---|
| 1048 | } else { |
---|
| 1049 | printf("meta data saved\n"); |
---|
| 1050 | } |
---|
| 1051 | i++; |
---|
| 1052 | } else if ( !strcmp(k, "metaload") ) { |
---|
| 1053 | i++; |
---|
| 1054 | if ( load_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
| 1055 | fprintf(stderr, "Error: can not set meta data\n"); |
---|
| 1056 | } else { |
---|
| 1057 | printf("meta data saved\n"); |
---|
| 1058 | } |
---|
| 1059 | i++; |
---|
[99] | 1060 | |
---|
[0] | 1061 | } else { |
---|
| 1062 | fprintf(stderr, "Error: invalid command: %s\n", k); |
---|
| 1063 | } |
---|
| 1064 | |
---|
| 1065 | } |
---|
| 1066 | |
---|
| 1067 | roar_disconnect(&con); |
---|
| 1068 | |
---|
| 1069 | return 0; |
---|
| 1070 | } |
---|
| 1071 | |
---|
| 1072 | //ll |
---|