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