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