[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> |
---|
[445] | 26 | #include <pwd.h> |
---|
| 27 | #include <grp.h> |
---|
| 28 | |
---|
[963] | 29 | int g_verbose = 0; |
---|
[0] | 30 | |
---|
[25] | 31 | int display_mixer (struct roar_connection * con, int stream); |
---|
[112] | 32 | int show_meta_all (struct roar_connection * con, int id); |
---|
[25] | 33 | |
---|
[0] | 34 | void usage (void) { |
---|
[233] | 35 | printf("roarctl [OPTIONS]... COMMAND [OPTS] [COMMAND [OPTS] [COMMAND [OPTS] [...]]]\n"); |
---|
[0] | 36 | |
---|
| 37 | printf("\nOptions:\n\n"); |
---|
| 38 | |
---|
[86] | 39 | printf(" --server SERVER - Set server hostname\n" |
---|
| 40 | " --help - Show this help\n" |
---|
[963] | 41 | " --verbose -v - Show verbose output\n" |
---|
[0] | 42 | ); |
---|
| 43 | |
---|
| 44 | printf("\nCommands:\n\n"); |
---|
| 45 | printf( |
---|
[86] | 46 | " help - Show this help\n" |
---|
[0] | 47 | "\n" |
---|
[86] | 48 | " standby, off - Go into standby mode\n" |
---|
| 49 | " resume, on - Go into active mode\n" |
---|
| 50 | " standbymode - Show current standby mode\n" |
---|
| 51 | " exit - Quits the roard (must be used as last command)\n" |
---|
[577] | 52 | " terminate - Like exit but let the server up to serve still connected clients,\n" |
---|
| 53 | " new clients cann't connect and the server terminates after the last\n" |
---|
| 54 | " client disconnected\n" |
---|
[0] | 55 | "\n" |
---|
[86] | 56 | " volume ID CHAN V0 V1... - Sets volume for stream ID\n" |
---|
| 57 | " CHAN is the number of channels or 'mono' or 'stereo'\n" |
---|
| 58 | " if mono or stereo is chosen roarctl trys to set\n" |
---|
| 59 | " sensfull values for all channels even if the output\n" |
---|
| 60 | " is has more channels.\n" |
---|
| 61 | " all other args are the volumes of the channels\n" |
---|
| 62 | " you may use integer or percent values.\n" |
---|
| 63 | " percent values can flooding points.\n" |
---|
[0] | 64 | "\n" |
---|
[1123] | 65 | " flag ID FLAGS - Sets flags FLAGS on stream ID. FLAGS may be a comma\n" |
---|
| 66 | " seperated list of flags.\n" |
---|
| 67 | " unflag ID FLAGS - Unsets flags on a stream. See flag.\n" |
---|
| 68 | "\n" |
---|
[86] | 69 | " kick TYPE ID - Kicks object of TYPE with id ID\n" |
---|
| 70 | " Types: client stream sample source\n" |
---|
| 71 | "\n" |
---|
[1160] | 72 | " metasave ID FILE - Saves meta data of stream ID to file FILE\n" |
---|
| 73 | " metaload ID FILE - Loads meta data from file FILE and set it on stream ID\n" |
---|
| 74 | "\n" |
---|
[86] | 75 | " serveroinfo - Gets Informations about server output\n" |
---|
| 76 | " listclients - Gets Informations about clients\n" |
---|
| 77 | " liststreams - Gets Informations about streams\n" |
---|
| 78 | " allinfo - Get all infos\n" |
---|
[0] | 79 | ); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | void server_oinfo (struct roar_connection * con) { |
---|
| 83 | struct roar_stream s; |
---|
| 84 | |
---|
| 85 | if ( roar_server_oinfo(con, &s) == -1 ) { |
---|
| 86 | fprintf(stderr, "Error: can not get server output info\n"); |
---|
| 87 | return; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | printf("Stream direction : %s\n", roar_dir2str(s.dir)); |
---|
| 91 | printf("Server Output rate : %i\n", s.info.rate); |
---|
| 92 | printf("Server Output bits : %i\n", s.info.bits); |
---|
| 93 | printf("Server Output channels: %i\n", s.info.channels); |
---|
| 94 | printf("Server Output codec : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec), |
---|
| 95 | s.info.codec == ROAR_CODEC_DEFAULT ? " native" : ""); |
---|
| 96 | // printf("Server Output rate: %i", s.info.rate); |
---|
[984] | 97 | if ( g_verbose > 1 ) |
---|
| 98 | printf("Server Position : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels)); |
---|
[0] | 99 | } |
---|
| 100 | |
---|
[449] | 101 | const char * proc_name (pid_t pid) { |
---|
| 102 | static char ret[80] = "?"; |
---|
| 103 | #ifdef __linux__ |
---|
| 104 | char file[80], buf[80], *r; |
---|
| 105 | int i; |
---|
| 106 | |
---|
| 107 | snprintf(file, 79, "/proc/%i/exe", pid); |
---|
| 108 | file[79] = 0; |
---|
| 109 | |
---|
| 110 | ret[0] = '?'; |
---|
| 111 | ret[1] = 0; |
---|
| 112 | |
---|
| 113 | if ( (i = readlink(file, buf, 79)) != -1 ) { |
---|
| 114 | buf[i] = 0; |
---|
| 115 | if ( (r = strrchr(buf, '/')) != NULL ) { |
---|
| 116 | r++; |
---|
| 117 | if ( *r != 0 ) |
---|
| 118 | strcpy(ret, r); |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | #endif |
---|
| 122 | |
---|
| 123 | return ret; |
---|
| 124 | } |
---|
| 125 | |
---|
[0] | 126 | void list_clients (struct roar_connection * con) { |
---|
| 127 | int i; |
---|
| 128 | int num; |
---|
| 129 | int h; |
---|
| 130 | int id[ROAR_CLIENTS_MAX]; |
---|
| 131 | struct roar_client c; |
---|
[445] | 132 | struct group * grp = NULL; |
---|
| 133 | struct passwd * pwd = NULL; |
---|
[0] | 134 | |
---|
| 135 | if ( (num = roar_list_clients(con, id, ROAR_CLIENTS_MAX)) == -1 ) { |
---|
| 136 | fprintf(stderr, "Error: can not get client list\n"); |
---|
| 137 | return; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | for (i = 0; i < num; i++) { |
---|
| 141 | printf("client %i:\n", id[i]); |
---|
| 142 | if ( roar_get_client(con, &c, id[i]) == -1 ) { |
---|
| 143 | fprintf(stderr, "Error: can not get client info\n"); |
---|
| 144 | continue; |
---|
| 145 | } |
---|
| 146 | printf("Player name : %s\n", c.name); |
---|
[449] | 147 | printf("Player PID : %i(%s)\n", c.pid, proc_name(c.pid)); |
---|
[445] | 148 | if ( c.uid != -1 ) { |
---|
| 149 | pwd = getpwuid(c.uid); |
---|
| 150 | grp = getgrgid(c.gid); |
---|
| 151 | printf("Player UID/GID : %i(%s)/%i(%s)\n", c.uid, pwd ? pwd->pw_name : "?", c.gid, grp ? grp->gr_name : "?"); |
---|
| 152 | } |
---|
[0] | 153 | if ( c.execed != -1 ) |
---|
| 154 | printf("Execed stream : %i\n", c.execed); |
---|
| 155 | |
---|
| 156 | for (h = 0; h < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; h++) |
---|
| 157 | if ( c.streams[h] != -1 ) |
---|
| 158 | printf("stream : %i\n", c.streams[h]); |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | void list_streams (struct roar_connection * con) { |
---|
| 164 | int i; |
---|
| 165 | int num; |
---|
| 166 | int id[ROAR_STREAMS_MAX]; |
---|
| 167 | struct roar_stream s; |
---|
[465] | 168 | struct roar_stream_info info; |
---|
[963] | 169 | char flags[80]; |
---|
[0] | 170 | |
---|
| 171 | |
---|
| 172 | if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) { |
---|
| 173 | fprintf(stderr, "Error: can not get stream list\n"); |
---|
| 174 | return; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | for (i = 0; i < num; i++) { |
---|
| 178 | printf("stream %i:\n", id[i]); |
---|
| 179 | if ( roar_get_stream(con, &s, id[i]) == -1 ) { |
---|
| 180 | fprintf(stderr, "Error: can not get stream info\n"); |
---|
| 181 | continue; |
---|
| 182 | } |
---|
| 183 | printf("Stream direction : %s\n", roar_dir2str(s.dir)); |
---|
| 184 | if ( s.pos_rel_id == -1 ) |
---|
| 185 | printf("Relativ position id : none (stream not synchronized)\n"); |
---|
| 186 | else |
---|
| 187 | printf("Relativ position id : %i\n", s.pos_rel_id); |
---|
[964] | 188 | if ( g_verbose > 1 ) |
---|
| 189 | printf("Position : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels)); |
---|
[0] | 190 | printf("Input rate : %i\n", s.info.rate); |
---|
| 191 | printf("Input bits : %i\n", s.info.bits); |
---|
| 192 | printf("Input channels : %i\n", s.info.channels); |
---|
[540] | 193 | printf("Input codec : %2i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec), |
---|
| 194 | s.info.codec == ROAR_CODEC_DEFAULT ? " native" : ""); |
---|
[465] | 195 | if ( roar_stream_get_info(con, &s, &info) != -1 ) { |
---|
[540] | 196 | printf("Input codec (streamed): %2i (%s%s)\n", info.codec, roar_codec2str(info.codec), |
---|
| 197 | info.codec == ROAR_CODEC_DEFAULT ? " native" : ""); |
---|
[963] | 198 | if ( g_verbose ) { |
---|
| 199 | printf("Input block size : %i Byte\n", info.block_size); |
---|
| 200 | printf("Underruns pre/post : %i/%i\n", info.pre_underruns, info.post_underruns); |
---|
[1137] | 201 | if ( g_verbose > 1 ) |
---|
| 202 | printf("Stream delay : %ims\n", (int)info.delay/1000); |
---|
[963] | 203 | |
---|
| 204 | *flags = 0; |
---|
| 205 | if ( info.flags & ROAR_FLAG_PRIMARY ) |
---|
| 206 | strcat(flags, "primary "); |
---|
| 207 | if ( info.flags & ROAR_FLAG_SYNC ) |
---|
| 208 | strcat(flags, "sync "); |
---|
| 209 | if ( info.flags & ROAR_FLAG_OUTPUT ) |
---|
| 210 | strcat(flags, "output "); |
---|
| 211 | if ( info.flags & ROAR_FLAG_SOURCE ) |
---|
| 212 | strcat(flags, "source "); |
---|
[1032] | 213 | if ( info.flags & ROAR_FLAG_META ) |
---|
| 214 | strcat(flags, "meta "); |
---|
[963] | 215 | |
---|
| 216 | printf("Flags : %s\n", flags); |
---|
| 217 | } |
---|
[465] | 218 | } |
---|
[25] | 219 | display_mixer(con, id[i]); |
---|
[112] | 220 | show_meta_all(con, id[i]); |
---|
[0] | 221 | } |
---|
| 222 | |
---|
| 223 | } |
---|
| 224 | |
---|
[25] | 225 | int display_mixer (struct roar_connection * con, int stream) { |
---|
| 226 | int channels; |
---|
| 227 | struct roar_mixer_settings mixer; |
---|
| 228 | int i; |
---|
| 229 | |
---|
| 230 | if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) { |
---|
| 231 | fprintf(stderr, "Error: can not get stream mixer info\n"); |
---|
| 232 | return -1; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | for (i = 0; i < channels; i++) |
---|
| 236 | printf("Mixer volume chan %2i : %i (%.2f%%)\n", i, mixer.mixer[i], (float)mixer.mixer[i]/655.35); |
---|
| 237 | |
---|
| 238 | return 0; |
---|
| 239 | } |
---|
[0] | 240 | |
---|
[85] | 241 | int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) { |
---|
| 242 | int chans = 0; |
---|
| 243 | int id; |
---|
| 244 | int i; |
---|
| 245 | int len; |
---|
| 246 | int old_chans; |
---|
| 247 | int vol_l, vol_r; |
---|
| 248 | char * k; |
---|
| 249 | struct roar_mixer_settings mixer; |
---|
| 250 | struct roar_mixer_settings old_mixer; |
---|
| 251 | |
---|
| 252 | if (*cur + 2 > max) |
---|
| 253 | return -1; |
---|
| 254 | |
---|
| 255 | id = atoi(arg[++(*cur)]); |
---|
| 256 | |
---|
| 257 | k = arg[++(*cur)]; |
---|
| 258 | |
---|
| 259 | if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) { |
---|
| 260 | fprintf(stderr, "Error: can not get stream mixer info\n"); |
---|
| 261 | return -1; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | |
---|
| 265 | if ( strcmp(k, "mono") == 0 && old_chans != 1 ) { |
---|
| 266 | chans = 1; |
---|
| 267 | |
---|
| 268 | if ( *cur + 1 > max ) |
---|
| 269 | return -1; |
---|
| 270 | |
---|
| 271 | k = arg[++(*cur)]; |
---|
| 272 | len = strlen(k); |
---|
| 273 | |
---|
| 274 | if ( k[len - 1] == '%' ) { |
---|
| 275 | k[len - 1] = 0; |
---|
| 276 | vol_l = (atof(k)*65535)/100; |
---|
| 277 | } else { |
---|
| 278 | vol_l = atoi(k); |
---|
| 279 | } |
---|
| 280 | |
---|
| 281 | for (i = 0; i < old_chans; i++) |
---|
| 282 | mixer.mixer[i] = vol_l; |
---|
| 283 | |
---|
| 284 | chans = old_chans; |
---|
| 285 | |
---|
| 286 | } else if ( strcmp(k, "stereo") == 0 && old_chans != 2 ) { |
---|
| 287 | chans = 2; |
---|
| 288 | // printf("mode: stereo; chans=%i, old_chans=%i\n", chans, old_chans); |
---|
| 289 | ROAR_ERR("mode stereo not supported"); |
---|
| 290 | return -1; |
---|
| 291 | } else { |
---|
| 292 | if ( strcmp(k, "mono") == 0 ) { |
---|
| 293 | chans = 1; |
---|
| 294 | } else if ( strcmp(k, "stereo") == 0 ) { |
---|
| 295 | chans = 2; |
---|
| 296 | } else { |
---|
| 297 | chans = atoi(k); |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | // printf("mode: int; chans=%i, old_chans=%i\n", chans, old_chans); |
---|
| 301 | |
---|
| 302 | if ( *cur + chans > max ) |
---|
| 303 | return -1; |
---|
| 304 | |
---|
| 305 | for (i = 0; i < chans; i++) { |
---|
| 306 | k = arg[++(*cur)]; |
---|
| 307 | len = strlen(k); |
---|
| 308 | |
---|
| 309 | if ( k[len - 1] == '%' ) { |
---|
| 310 | k[len - 1] = 0; |
---|
| 311 | mixer.mixer[i] = (atof(k)*(int)65535)/100; |
---|
| 312 | } else { |
---|
| 313 | mixer.mixer[i] = atoi(k); |
---|
| 314 | } |
---|
| 315 | } |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | mixer.scale = 65535; |
---|
| 319 | |
---|
| 320 | return roar_set_vol(con, id, &mixer, chans); |
---|
| 321 | } |
---|
| 322 | |
---|
[99] | 323 | int set_meta (struct roar_connection * con, int id, char * mode, char * type, char * val) { |
---|
| 324 | struct roar_meta meta; |
---|
| 325 | struct roar_stream s; |
---|
| 326 | int mode_i = ROAR_META_MODE_SET; |
---|
| 327 | |
---|
[1127] | 328 | memset(&s, 0, sizeof(s)); |
---|
| 329 | |
---|
[99] | 330 | s.id = id; |
---|
| 331 | |
---|
[106] | 332 | // printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val); |
---|
[99] | 333 | |
---|
| 334 | if ( strcmp(mode, "add") == 0 ) { |
---|
| 335 | mode_i = ROAR_META_MODE_ADD; |
---|
| 336 | } |
---|
| 337 | |
---|
[109] | 338 | meta.type = roar_meta_inttype(type); |
---|
[106] | 339 | meta.value = val; |
---|
| 340 | meta.key[0] = 0; |
---|
[99] | 341 | |
---|
[109] | 342 | if ( meta.type == -1 ) { |
---|
| 343 | fprintf(stderr, "Error: unknown type: %s\n", type); |
---|
| 344 | return -1; |
---|
| 345 | } |
---|
| 346 | |
---|
[106] | 347 | // printf("D: type=%i, mode=%i\n", meta.type, mode_i); |
---|
[99] | 348 | |
---|
[1127] | 349 | if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 ) |
---|
| 350 | return -1; |
---|
| 351 | |
---|
| 352 | meta.type = ROAR_META_TYPE_NONE; |
---|
| 353 | meta.value = NULL; |
---|
| 354 | |
---|
| 355 | return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta); |
---|
[99] | 356 | } |
---|
| 357 | |
---|
[1126] | 358 | int load_meta (struct roar_connection * con, int id, char * file) { |
---|
| 359 | struct roar_meta meta; |
---|
| 360 | struct roar_stream s; |
---|
| 361 | int mode_i = ROAR_META_MODE_SET; |
---|
| 362 | FILE * in; |
---|
| 363 | char lion[1024]; |
---|
| 364 | char * v; |
---|
| 365 | |
---|
| 366 | memset(&s, 0, sizeof(s)); |
---|
| 367 | |
---|
| 368 | s.id = id; |
---|
| 369 | |
---|
| 370 | if ( (in = fopen(file, "r")) == NULL ) |
---|
| 371 | return -1; |
---|
| 372 | |
---|
| 373 | while (fgets(lion, 1024, in) != NULL) { |
---|
| 374 | if ( (v = strtok(lion, "\r\n")) != NULL ) |
---|
| 375 | if ( (v = strtok(NULL, "\r\n")) != NULL ) |
---|
| 376 | *(v-1) = 0; |
---|
| 377 | |
---|
| 378 | if ( (v = strstr(lion, "=")) == NULL ) { |
---|
| 379 | fprintf(stderr, "Error: can not parse meta data lion: %s\n", lion); |
---|
| 380 | continue; |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | *v++ = 0; |
---|
| 384 | |
---|
| 385 | meta.type = roar_meta_inttype(lion); |
---|
| 386 | meta.value = v; |
---|
| 387 | meta.key[0] = 0; |
---|
| 388 | |
---|
| 389 | if ( meta.type == -1 ) { |
---|
| 390 | fprintf(stderr, "Error: unknown type: %s\n", lion); |
---|
| 391 | continue; |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 ) |
---|
| 395 | return -1; |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | fclose(in); |
---|
| 399 | |
---|
| 400 | meta.type = ROAR_META_TYPE_NONE; |
---|
| 401 | meta.value = NULL; |
---|
| 402 | |
---|
| 403 | return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta); |
---|
| 404 | } |
---|
| 405 | |
---|
[106] | 406 | int show_meta_type (struct roar_connection * con, int id, char * type) { |
---|
| 407 | struct roar_meta meta; |
---|
| 408 | struct roar_stream s; |
---|
| 409 | |
---|
[1127] | 410 | memset(&s, 0, sizeof(s)); |
---|
| 411 | |
---|
[106] | 412 | s.id = id; |
---|
| 413 | |
---|
[109] | 414 | meta.type = roar_meta_inttype(type); |
---|
| 415 | |
---|
| 416 | if ( meta.type == -1 ) { |
---|
| 417 | fprintf(stderr, "Error: unknown type: %s\n", type); |
---|
| 418 | return -1; |
---|
| 419 | } |
---|
[106] | 420 | |
---|
| 421 | if ( roar_stream_meta_get(con, &s, &meta) == -1 ) |
---|
| 422 | return -1; |
---|
| 423 | |
---|
[112] | 424 | printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value); |
---|
[106] | 425 | |
---|
| 426 | roar_meta_free(&meta); |
---|
| 427 | |
---|
| 428 | return 0; |
---|
| 429 | } |
---|
| 430 | |
---|
[112] | 431 | int show_meta_all (struct roar_connection * con, int id) { |
---|
| 432 | struct roar_stream s; |
---|
| 433 | int types[ROAR_META_MAX_PER_STREAM]; |
---|
| 434 | int i; |
---|
| 435 | int len; |
---|
| 436 | |
---|
[1127] | 437 | memset(&s, 0, sizeof(s)); |
---|
| 438 | |
---|
[112] | 439 | s.id = id; |
---|
| 440 | |
---|
| 441 | if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 ) |
---|
| 442 | return -1; |
---|
| 443 | |
---|
| 444 | for (i = 0; i < len; i++) |
---|
| 445 | show_meta_type(con, id, roar_meta_strtype(types[i])); |
---|
| 446 | |
---|
| 447 | return 0; |
---|
| 448 | } |
---|
| 449 | |
---|
[1126] | 450 | int save_meta (struct roar_connection * con, int id, char * file) { |
---|
| 451 | struct roar_stream s; |
---|
| 452 | struct roar_meta meta; |
---|
| 453 | int types[ROAR_META_MAX_PER_STREAM]; |
---|
| 454 | int i; |
---|
| 455 | int len; |
---|
| 456 | FILE * out; |
---|
| 457 | |
---|
| 458 | memset(&s, 0, sizeof(s)); |
---|
| 459 | |
---|
| 460 | s.id = id; |
---|
| 461 | |
---|
| 462 | if ( (out = fopen(file, "w")) == NULL ) |
---|
| 463 | return -1; |
---|
| 464 | |
---|
| 465 | if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 ) |
---|
| 466 | return -1; |
---|
| 467 | |
---|
| 468 | for (i = 0; i < len; i++) { |
---|
| 469 | /* |
---|
| 470 | show_meta_type(con, id, roar_meta_strtype(types[i])); |
---|
| 471 | */ |
---|
| 472 | meta.type = types[i]; |
---|
| 473 | |
---|
| 474 | if ( roar_stream_meta_get(con, &s, &meta) == -1 ) |
---|
| 475 | continue; |
---|
| 476 | |
---|
| 477 | // printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value); |
---|
| 478 | |
---|
| 479 | fprintf(out, "%s=%s\n", roar_meta_strtype(meta.type), meta.value); |
---|
| 480 | |
---|
| 481 | roar_meta_free(&meta); |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | fclose(out); |
---|
| 485 | |
---|
| 486 | return 0; |
---|
| 487 | } |
---|
| 488 | |
---|
[1043] | 489 | int set_flags (struct roar_connection * con, int id, int reset, char * flags) { |
---|
| 490 | int f = ROAR_FLAG_NONE; |
---|
| 491 | char * c; |
---|
| 492 | struct roar_stream s[1]; |
---|
| 493 | |
---|
| 494 | memset(s, 0, sizeof(struct roar_stream)); |
---|
| 495 | |
---|
| 496 | s->id = id; |
---|
| 497 | |
---|
| 498 | c = strtok(flags, ","); |
---|
| 499 | while (c != NULL) { |
---|
| 500 | if ( !strcmp(c, "meta") ) { |
---|
| 501 | f |= ROAR_FLAG_META; |
---|
| 502 | } else if ( !strcmp(c, "primary") ) { |
---|
| 503 | f |= ROAR_FLAG_PRIMARY; |
---|
[1116] | 504 | } else if ( !strcmp(c, "sync") ) { |
---|
| 505 | f |= ROAR_FLAG_SYNC; |
---|
[1043] | 506 | } else { |
---|
| 507 | fprintf(stderr, "Error: unknown flag: %s\n", c); |
---|
| 508 | return -1; |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | c = strtok(NULL, ","); |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | return roar_stream_set_flags(con, s, f, reset); |
---|
| 515 | } |
---|
| 516 | |
---|
[0] | 517 | int main (int argc, char * argv[]) { |
---|
| 518 | struct roar_connection con; |
---|
| 519 | char * server = NULL; |
---|
| 520 | char * k = NULL; |
---|
| 521 | int i; |
---|
| 522 | int t = 0; |
---|
| 523 | |
---|
| 524 | for (i = 1; i < argc; i++) { |
---|
| 525 | k = argv[i]; |
---|
| 526 | |
---|
| 527 | if ( strcmp(k, "--server") == 0 ) { |
---|
[58] | 528 | server = argv[++i]; |
---|
[963] | 529 | } else if ( strcmp(k, "-v") == 0 || strcmp(k, "--verbose") == 0 ) { |
---|
| 530 | g_verbose++; |
---|
[0] | 531 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
| 532 | usage(); |
---|
| 533 | return 0; |
---|
| 534 | } else if ( *k == '-' ) { |
---|
| 535 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 536 | usage(); |
---|
| 537 | return 1; |
---|
| 538 | } else { |
---|
| 539 | break; |
---|
| 540 | } |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | // connect |
---|
| 544 | |
---|
| 545 | if ( roar_connect(&con, server) == -1 ) { |
---|
| 546 | fprintf(stderr, "Error: Can not connect to server\n"); |
---|
| 547 | return 1; |
---|
| 548 | } |
---|
| 549 | |
---|
| 550 | if ( roar_identify(&con, "roarctl") == -1 ) { |
---|
| 551 | fprintf(stderr, "Error: Can not identify to server\n"); |
---|
| 552 | return 1; |
---|
| 553 | } |
---|
| 554 | |
---|
| 555 | if ( i == argc ) { |
---|
| 556 | fprintf(stderr, "Error: No Commands given\n"); |
---|
| 557 | return 0; // this is not a fatal error... |
---|
| 558 | } |
---|
| 559 | |
---|
| 560 | for (; i < argc; i++) { |
---|
| 561 | k = argv[i]; |
---|
| 562 | // cmd is in k |
---|
| 563 | |
---|
| 564 | printf("--- [ %s ] ---\n", k); |
---|
| 565 | |
---|
| 566 | if ( !strcmp(k, "help") ) { |
---|
| 567 | usage(); |
---|
| 568 | |
---|
| 569 | |
---|
| 570 | } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) { |
---|
| 571 | if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) { |
---|
| 572 | fprintf(stderr, "Error: can not set mode to standby\n"); |
---|
| 573 | } else { |
---|
| 574 | printf("going into standby\n"); |
---|
| 575 | } |
---|
| 576 | } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) { |
---|
| 577 | if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) { |
---|
| 578 | fprintf(stderr, "Error: can not set mode to active\n"); |
---|
| 579 | } else { |
---|
| 580 | printf("going into active mode\n"); |
---|
| 581 | } |
---|
| 582 | |
---|
| 583 | } else if ( !strcmp(k, "exit") ) { |
---|
| 584 | if ( roar_exit(&con) == -1 ) { |
---|
| 585 | fprintf(stderr, "Error: can not quit server\n"); |
---|
| 586 | } else { |
---|
| 587 | printf("Server quited\n"); |
---|
| 588 | break; |
---|
| 589 | } |
---|
[577] | 590 | } else if ( !strcmp(k, "terminate") ) { |
---|
| 591 | if ( roar_terminate(&con, 1) == -1 ) { |
---|
| 592 | fprintf(stderr, "Error: can not terminate server\n"); |
---|
| 593 | } else { |
---|
| 594 | printf("Server got asked to quited\n"); |
---|
| 595 | break; |
---|
| 596 | } |
---|
[0] | 597 | |
---|
| 598 | } else if ( !strcmp(k, "standbymode") ) { |
---|
| 599 | t = roar_get_standby(&con); |
---|
| 600 | if ( t == -1 ) { |
---|
| 601 | fprintf(stderr, "Error: can not get stanby mode\n"); |
---|
| 602 | } else if ( t == ROAR_STANDBY_ACTIVE ) { |
---|
| 603 | printf("Server is in standby\n"); |
---|
| 604 | } else if ( t == ROAR_STANDBY_INACTIVE ) { |
---|
| 605 | printf("Server is active\n"); |
---|
| 606 | } else { |
---|
| 607 | fprintf(stderr, "Error: unknown standby mode: %i\n", t); |
---|
| 608 | } |
---|
| 609 | |
---|
[1162] | 610 | } else if ( !strcmp(k, "whoami") ) { |
---|
| 611 | printf("My client ID is: %i\n", roar_get_clientid(&con)); |
---|
[0] | 612 | } else if ( !strcmp(k, "serveroinfo") ) { |
---|
| 613 | server_oinfo(&con); |
---|
| 614 | } else if ( !strcmp(k, "listclients") ) { |
---|
| 615 | list_clients(&con); |
---|
| 616 | } else if ( !strcmp(k, "liststreams") ) { |
---|
| 617 | list_streams(&con); |
---|
| 618 | } else if ( !strcmp(k, "allinfo") ) { |
---|
| 619 | server_oinfo(&con); |
---|
| 620 | printf("\n"); |
---|
| 621 | list_clients(&con); |
---|
| 622 | printf("\n"); |
---|
| 623 | list_streams(&con); |
---|
| 624 | |
---|
| 625 | } else if ( !strcmp(k, "kick") ) { |
---|
| 626 | k = argv[++i]; |
---|
| 627 | if ( !strcmp(k, "client") ) { |
---|
| 628 | t = ROAR_OT_CLIENT; |
---|
| 629 | } else if ( !strcmp(k, "stream") ) { |
---|
| 630 | t = ROAR_OT_STREAM; |
---|
| 631 | } else if ( !strcmp(k, "sample") ) { |
---|
| 632 | t = ROAR_OT_SAMPLE; |
---|
| 633 | } else if ( !strcmp(k, "source") ) { |
---|
| 634 | t = ROAR_OT_SOURCE; |
---|
| 635 | } else { |
---|
| 636 | fprintf(stderr, "Error: unknown type: %s\n", k); |
---|
| 637 | continue; |
---|
| 638 | } |
---|
| 639 | //t = atoi(argv[i++]); |
---|
| 640 | if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) { |
---|
| 641 | fprintf(stderr, "Error: can not kick %s\n", k); |
---|
| 642 | } else { |
---|
| 643 | printf("%s kicked\n", k); |
---|
| 644 | } |
---|
| 645 | |
---|
[85] | 646 | } else if ( !strcmp(k, "volume") ) { |
---|
| 647 | if ( set_mixer(&con, &i, argc, argv) == -1 ) { |
---|
| 648 | fprintf(stderr, "Error: can not set volume\n"); |
---|
| 649 | } else { |
---|
| 650 | printf("volume changed\n"); |
---|
| 651 | } |
---|
| 652 | |
---|
[1043] | 653 | } else if ( !strcmp(k, "flag") ) { |
---|
| 654 | i++; |
---|
| 655 | if ( set_flags(&con, atoi(argv[i]), ROAR_SET_FLAG, argv[i+1]) == -1 ) { |
---|
| 656 | fprintf(stderr, "Error: can not set flags\n"); |
---|
| 657 | } else { |
---|
| 658 | printf("flags changed\n"); |
---|
| 659 | } |
---|
| 660 | i++; |
---|
| 661 | } else if ( !strcmp(k, "unflag") ) { |
---|
| 662 | i++; |
---|
| 663 | if ( set_flags(&con, atoi(argv[i]), ROAR_RESET_FLAG, argv[i+1]) == -1 ) { |
---|
| 664 | fprintf(stderr, "Error: can not reset flags\n"); |
---|
| 665 | } else { |
---|
| 666 | printf("flags changed\n"); |
---|
| 667 | } |
---|
| 668 | i++; |
---|
[106] | 669 | } else if ( !strcmp(k, "metaset") ) { |
---|
[99] | 670 | i++; |
---|
| 671 | if ( set_meta(&con, atoi(argv[i]), argv[i+1], argv[i+2], argv[i+3]) == -1 ) { |
---|
| 672 | fprintf(stderr, "Error: can not set meta data\n"); |
---|
| 673 | } else { |
---|
| 674 | printf("meta data changed\n"); |
---|
| 675 | } |
---|
| 676 | i += 3; |
---|
[106] | 677 | } else if ( !strcmp(k, "metaget") ) { |
---|
| 678 | i++; |
---|
| 679 | if ( show_meta_type(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
| 680 | fprintf(stderr, "Error: can not get meta data\n"); |
---|
| 681 | } |
---|
| 682 | i++; |
---|
[1126] | 683 | } else if ( !strcmp(k, "metasave") ) { |
---|
| 684 | i++; |
---|
| 685 | if ( save_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
| 686 | fprintf(stderr, "Error: can not get meta data\n"); |
---|
| 687 | } else { |
---|
| 688 | printf("meta data saved\n"); |
---|
| 689 | } |
---|
| 690 | i++; |
---|
| 691 | } else if ( !strcmp(k, "metaload") ) { |
---|
| 692 | i++; |
---|
| 693 | if ( load_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
| 694 | fprintf(stderr, "Error: can not set meta data\n"); |
---|
| 695 | } else { |
---|
| 696 | printf("meta data saved\n"); |
---|
| 697 | } |
---|
| 698 | i++; |
---|
[99] | 699 | |
---|
[0] | 700 | } else { |
---|
| 701 | fprintf(stderr, "Error: invalid command: %s\n", k); |
---|
| 702 | } |
---|
| 703 | |
---|
| 704 | } |
---|
| 705 | |
---|
| 706 | roar_disconnect(&con); |
---|
| 707 | |
---|
| 708 | return 0; |
---|
| 709 | } |
---|
| 710 | |
---|
| 711 | //ll |
---|