[0] | 1 | //roarctl.c: |
---|
| 2 | |
---|
| 3 | #include <roaraudio.h> |
---|
| 4 | |
---|
[25] | 5 | int display_mixer (struct roar_connection * con, int stream); |
---|
| 6 | |
---|
[0] | 7 | void usage (void) { |
---|
| 8 | printf("roarcat [OPTIONS]... COMMAND [OPTS] [COMMAND [OPTS] [COMMAND [OPTS] [...]]]\n"); |
---|
| 9 | |
---|
| 10 | printf("\nOptions:\n\n"); |
---|
| 11 | |
---|
[86] | 12 | printf(" --server SERVER - Set server hostname\n" |
---|
| 13 | " --help - Show this help\n" |
---|
[0] | 14 | ); |
---|
| 15 | |
---|
| 16 | printf("\nCommands:\n\n"); |
---|
| 17 | printf( |
---|
[86] | 18 | " help - Show this help\n" |
---|
[0] | 19 | "\n" |
---|
[86] | 20 | " standby, off - Go into standby mode\n" |
---|
| 21 | " resume, on - Go into active mode\n" |
---|
| 22 | " standbymode - Show current standby mode\n" |
---|
| 23 | " exit - Quits the roard (must be used as last command)\n" |
---|
[0] | 24 | "\n" |
---|
[86] | 25 | " volume ID CHAN V0 V1... - Sets volume for stream ID\n" |
---|
| 26 | " CHAN is the number of channels or 'mono' or 'stereo'\n" |
---|
| 27 | " if mono or stereo is chosen roarctl trys to set\n" |
---|
| 28 | " sensfull values for all channels even if the output\n" |
---|
| 29 | " is has more channels.\n" |
---|
| 30 | " all other args are the volumes of the channels\n" |
---|
| 31 | " you may use integer or percent values.\n" |
---|
| 32 | " percent values can flooding points.\n" |
---|
[0] | 33 | "\n" |
---|
[86] | 34 | " kick TYPE ID - Kicks object of TYPE with id ID\n" |
---|
| 35 | " Types: client stream sample source\n" |
---|
| 36 | "\n" |
---|
| 37 | " serveroinfo - Gets Informations about server output\n" |
---|
| 38 | " listclients - Gets Informations about clients\n" |
---|
| 39 | " liststreams - Gets Informations about streams\n" |
---|
| 40 | " allinfo - Get all infos\n" |
---|
[0] | 41 | ); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | void server_oinfo (struct roar_connection * con) { |
---|
| 45 | struct roar_stream s; |
---|
| 46 | |
---|
| 47 | if ( roar_server_oinfo(con, &s) == -1 ) { |
---|
| 48 | fprintf(stderr, "Error: can not get server output info\n"); |
---|
| 49 | return; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | printf("Stream direction : %s\n", roar_dir2str(s.dir)); |
---|
| 53 | printf("Server Output rate : %i\n", s.info.rate); |
---|
| 54 | printf("Server Output bits : %i\n", s.info.bits); |
---|
| 55 | printf("Server Output channels: %i\n", s.info.channels); |
---|
| 56 | printf("Server Output codec : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec), |
---|
| 57 | s.info.codec == ROAR_CODEC_DEFAULT ? " native" : ""); |
---|
| 58 | // printf("Server Output rate: %i", s.info.rate); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void list_clients (struct roar_connection * con) { |
---|
| 62 | int i; |
---|
| 63 | int num; |
---|
| 64 | int h; |
---|
| 65 | int id[ROAR_CLIENTS_MAX]; |
---|
| 66 | struct roar_client c; |
---|
| 67 | |
---|
| 68 | if ( (num = roar_list_clients(con, id, ROAR_CLIENTS_MAX)) == -1 ) { |
---|
| 69 | fprintf(stderr, "Error: can not get client list\n"); |
---|
| 70 | return; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | for (i = 0; i < num; i++) { |
---|
| 74 | printf("client %i:\n", id[i]); |
---|
| 75 | if ( roar_get_client(con, &c, id[i]) == -1 ) { |
---|
| 76 | fprintf(stderr, "Error: can not get client info\n"); |
---|
| 77 | continue; |
---|
| 78 | } |
---|
| 79 | printf("Player name : %s\n", c.name); |
---|
| 80 | if ( c.execed != -1 ) |
---|
| 81 | printf("Execed stream : %i\n", c.execed); |
---|
| 82 | |
---|
| 83 | for (h = 0; h < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; h++) |
---|
| 84 | if ( c.streams[h] != -1 ) |
---|
| 85 | printf("stream : %i\n", c.streams[h]); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | void list_streams (struct roar_connection * con) { |
---|
| 91 | int i; |
---|
| 92 | int num; |
---|
| 93 | int id[ROAR_STREAMS_MAX]; |
---|
| 94 | struct roar_stream s; |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) { |
---|
| 98 | fprintf(stderr, "Error: can not get stream list\n"); |
---|
| 99 | return; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | for (i = 0; i < num; i++) { |
---|
| 103 | printf("stream %i:\n", id[i]); |
---|
| 104 | if ( roar_get_stream(con, &s, id[i]) == -1 ) { |
---|
| 105 | fprintf(stderr, "Error: can not get stream info\n"); |
---|
| 106 | continue; |
---|
| 107 | } |
---|
| 108 | printf("Stream direction : %s\n", roar_dir2str(s.dir)); |
---|
| 109 | if ( s.pos_rel_id == -1 ) |
---|
| 110 | printf("Relativ position id : none (stream not synchronized)\n"); |
---|
| 111 | else |
---|
| 112 | printf("Relativ position id : %i\n", s.pos_rel_id); |
---|
| 113 | printf("Input rate : %i\n", s.info.rate); |
---|
| 114 | printf("Input bits : %i\n", s.info.bits); |
---|
| 115 | printf("Input channels : %i\n", s.info.channels); |
---|
| 116 | printf("Input codec : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec), |
---|
| 117 | s.info.codec == ROAR_CODEC_DEFAULT ? " native" : ""); |
---|
[25] | 118 | display_mixer(con, id[i]); |
---|
[0] | 119 | } |
---|
| 120 | |
---|
| 121 | } |
---|
| 122 | |
---|
[25] | 123 | int display_mixer (struct roar_connection * con, int stream) { |
---|
| 124 | int channels; |
---|
| 125 | struct roar_mixer_settings mixer; |
---|
| 126 | int i; |
---|
| 127 | |
---|
| 128 | if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) { |
---|
| 129 | fprintf(stderr, "Error: can not get stream mixer info\n"); |
---|
| 130 | return -1; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | for (i = 0; i < channels; i++) |
---|
| 134 | printf("Mixer volume chan %2i : %i (%.2f%%)\n", i, mixer.mixer[i], (float)mixer.mixer[i]/655.35); |
---|
| 135 | |
---|
| 136 | return 0; |
---|
| 137 | } |
---|
[0] | 138 | |
---|
[85] | 139 | int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) { |
---|
| 140 | int chans = 0; |
---|
| 141 | int id; |
---|
| 142 | int i; |
---|
| 143 | int len; |
---|
| 144 | int old_chans; |
---|
| 145 | int vol_l, vol_r; |
---|
| 146 | char * k; |
---|
| 147 | struct roar_mixer_settings mixer; |
---|
| 148 | struct roar_mixer_settings old_mixer; |
---|
| 149 | |
---|
| 150 | if (*cur + 2 > max) |
---|
| 151 | return -1; |
---|
| 152 | |
---|
| 153 | id = atoi(arg[++(*cur)]); |
---|
| 154 | |
---|
| 155 | k = arg[++(*cur)]; |
---|
| 156 | |
---|
| 157 | if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) { |
---|
| 158 | fprintf(stderr, "Error: can not get stream mixer info\n"); |
---|
| 159 | return -1; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | if ( strcmp(k, "mono") == 0 && old_chans != 1 ) { |
---|
| 164 | chans = 1; |
---|
| 165 | |
---|
| 166 | if ( *cur + 1 > max ) |
---|
| 167 | return -1; |
---|
| 168 | |
---|
| 169 | k = arg[++(*cur)]; |
---|
| 170 | len = strlen(k); |
---|
| 171 | |
---|
| 172 | if ( k[len - 1] == '%' ) { |
---|
| 173 | k[len - 1] = 0; |
---|
| 174 | vol_l = (atof(k)*65535)/100; |
---|
| 175 | } else { |
---|
| 176 | vol_l = atoi(k); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | for (i = 0; i < old_chans; i++) |
---|
| 180 | mixer.mixer[i] = vol_l; |
---|
| 181 | |
---|
| 182 | chans = old_chans; |
---|
| 183 | |
---|
| 184 | } else if ( strcmp(k, "stereo") == 0 && old_chans != 2 ) { |
---|
| 185 | chans = 2; |
---|
| 186 | // printf("mode: stereo; chans=%i, old_chans=%i\n", chans, old_chans); |
---|
| 187 | ROAR_ERR("mode stereo not supported"); |
---|
| 188 | return -1; |
---|
| 189 | } else { |
---|
| 190 | if ( strcmp(k, "mono") == 0 ) { |
---|
| 191 | chans = 1; |
---|
| 192 | } else if ( strcmp(k, "stereo") == 0 ) { |
---|
| 193 | chans = 2; |
---|
| 194 | } else { |
---|
| 195 | chans = atoi(k); |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | // printf("mode: int; chans=%i, old_chans=%i\n", chans, old_chans); |
---|
| 199 | |
---|
| 200 | if ( *cur + chans > max ) |
---|
| 201 | return -1; |
---|
| 202 | |
---|
| 203 | for (i = 0; i < chans; i++) { |
---|
| 204 | k = arg[++(*cur)]; |
---|
| 205 | len = strlen(k); |
---|
| 206 | |
---|
| 207 | if ( k[len - 1] == '%' ) { |
---|
| 208 | k[len - 1] = 0; |
---|
| 209 | mixer.mixer[i] = (atof(k)*(int)65535)/100; |
---|
| 210 | } else { |
---|
| 211 | mixer.mixer[i] = atoi(k); |
---|
| 212 | } |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | mixer.scale = 65535; |
---|
| 217 | |
---|
| 218 | return roar_set_vol(con, id, &mixer, chans); |
---|
| 219 | } |
---|
| 220 | |
---|
[99] | 221 | int set_meta (struct roar_connection * con, int id, char * mode, char * type, char * val) { |
---|
| 222 | struct roar_meta meta; |
---|
| 223 | struct roar_stream s; |
---|
| 224 | int mode_i = ROAR_META_MODE_SET; |
---|
| 225 | |
---|
| 226 | s.id = id; |
---|
| 227 | |
---|
[106] | 228 | // printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val); |
---|
[99] | 229 | |
---|
| 230 | if ( strcmp(mode, "add") == 0 ) { |
---|
| 231 | mode_i = ROAR_META_MODE_ADD; |
---|
| 232 | } |
---|
| 233 | |
---|
[109] | 234 | meta.type = roar_meta_inttype(type); |
---|
[106] | 235 | meta.value = val; |
---|
| 236 | meta.key[0] = 0; |
---|
[99] | 237 | |
---|
[109] | 238 | if ( meta.type == -1 ) { |
---|
| 239 | fprintf(stderr, "Error: unknown type: %s\n", type); |
---|
| 240 | return -1; |
---|
| 241 | } |
---|
| 242 | |
---|
[106] | 243 | // printf("D: type=%i, mode=%i\n", meta.type, mode_i); |
---|
[99] | 244 | |
---|
| 245 | return roar_stream_meta_set(con, &s, mode_i, &meta); |
---|
| 246 | } |
---|
| 247 | |
---|
[106] | 248 | int show_meta_type (struct roar_connection * con, int id, char * type) { |
---|
| 249 | struct roar_meta meta; |
---|
| 250 | struct roar_stream s; |
---|
| 251 | |
---|
| 252 | s.id = id; |
---|
| 253 | |
---|
[109] | 254 | meta.type = roar_meta_inttype(type); |
---|
| 255 | |
---|
| 256 | if ( meta.type == -1 ) { |
---|
| 257 | fprintf(stderr, "Error: unknown type: %s\n", type); |
---|
| 258 | return -1; |
---|
| 259 | } |
---|
[106] | 260 | |
---|
| 261 | if ( roar_stream_meta_get(con, &s, &meta) == -1 ) |
---|
| 262 | return -1; |
---|
| 263 | |
---|
[109] | 264 | printf("Meta %s: %s\n", roar_meta_strtype(meta.type), meta.value); |
---|
[106] | 265 | |
---|
| 266 | roar_meta_free(&meta); |
---|
| 267 | |
---|
| 268 | return 0; |
---|
| 269 | } |
---|
| 270 | |
---|
[0] | 271 | int main (int argc, char * argv[]) { |
---|
| 272 | struct roar_connection con; |
---|
| 273 | char * server = NULL; |
---|
| 274 | char * k = NULL; |
---|
| 275 | int i; |
---|
| 276 | int t = 0; |
---|
| 277 | |
---|
| 278 | for (i = 1; i < argc; i++) { |
---|
| 279 | k = argv[i]; |
---|
| 280 | |
---|
| 281 | if ( strcmp(k, "--server") == 0 ) { |
---|
[58] | 282 | server = argv[++i]; |
---|
[0] | 283 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
| 284 | usage(); |
---|
| 285 | return 0; |
---|
| 286 | } else if ( *k == '-' ) { |
---|
| 287 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 288 | usage(); |
---|
| 289 | return 1; |
---|
| 290 | } else { |
---|
| 291 | break; |
---|
| 292 | } |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | // connect |
---|
| 296 | |
---|
| 297 | if ( roar_connect(&con, server) == -1 ) { |
---|
| 298 | fprintf(stderr, "Error: Can not connect to server\n"); |
---|
| 299 | return 1; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | if ( roar_identify(&con, "roarctl") == -1 ) { |
---|
| 303 | fprintf(stderr, "Error: Can not identify to server\n"); |
---|
| 304 | return 1; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | if ( i == argc ) { |
---|
| 308 | fprintf(stderr, "Error: No Commands given\n"); |
---|
| 309 | return 0; // this is not a fatal error... |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | for (; i < argc; i++) { |
---|
| 313 | k = argv[i]; |
---|
| 314 | // cmd is in k |
---|
| 315 | |
---|
| 316 | printf("--- [ %s ] ---\n", k); |
---|
| 317 | |
---|
| 318 | if ( !strcmp(k, "help") ) { |
---|
| 319 | usage(); |
---|
| 320 | |
---|
| 321 | |
---|
| 322 | } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) { |
---|
| 323 | if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) { |
---|
| 324 | fprintf(stderr, "Error: can not set mode to standby\n"); |
---|
| 325 | } else { |
---|
| 326 | printf("going into standby\n"); |
---|
| 327 | } |
---|
| 328 | } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) { |
---|
| 329 | if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) { |
---|
| 330 | fprintf(stderr, "Error: can not set mode to active\n"); |
---|
| 331 | } else { |
---|
| 332 | printf("going into active mode\n"); |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | } else if ( !strcmp(k, "exit") ) { |
---|
| 336 | if ( roar_exit(&con) == -1 ) { |
---|
| 337 | fprintf(stderr, "Error: can not quit server\n"); |
---|
| 338 | } else { |
---|
| 339 | printf("Server quited\n"); |
---|
| 340 | break; |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | } else if ( !strcmp(k, "standbymode") ) { |
---|
| 344 | t = roar_get_standby(&con); |
---|
| 345 | if ( t == -1 ) { |
---|
| 346 | fprintf(stderr, "Error: can not get stanby mode\n"); |
---|
| 347 | } else if ( t == ROAR_STANDBY_ACTIVE ) { |
---|
| 348 | printf("Server is in standby\n"); |
---|
| 349 | } else if ( t == ROAR_STANDBY_INACTIVE ) { |
---|
| 350 | printf("Server is active\n"); |
---|
| 351 | } else { |
---|
| 352 | fprintf(stderr, "Error: unknown standby mode: %i\n", t); |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | } else if ( !strcmp(k, "serveroinfo") ) { |
---|
| 356 | server_oinfo(&con); |
---|
| 357 | } else if ( !strcmp(k, "listclients") ) { |
---|
| 358 | list_clients(&con); |
---|
| 359 | } else if ( !strcmp(k, "liststreams") ) { |
---|
| 360 | list_streams(&con); |
---|
| 361 | } else if ( !strcmp(k, "allinfo") ) { |
---|
| 362 | server_oinfo(&con); |
---|
| 363 | printf("\n"); |
---|
| 364 | list_clients(&con); |
---|
| 365 | printf("\n"); |
---|
| 366 | list_streams(&con); |
---|
| 367 | |
---|
| 368 | } else if ( !strcmp(k, "kick") ) { |
---|
| 369 | k = argv[++i]; |
---|
| 370 | if ( !strcmp(k, "client") ) { |
---|
| 371 | t = ROAR_OT_CLIENT; |
---|
| 372 | } else if ( !strcmp(k, "stream") ) { |
---|
| 373 | t = ROAR_OT_STREAM; |
---|
| 374 | } else if ( !strcmp(k, "sample") ) { |
---|
| 375 | t = ROAR_OT_SAMPLE; |
---|
| 376 | } else if ( !strcmp(k, "source") ) { |
---|
| 377 | t = ROAR_OT_SOURCE; |
---|
| 378 | } else { |
---|
| 379 | fprintf(stderr, "Error: unknown type: %s\n", k); |
---|
| 380 | continue; |
---|
| 381 | } |
---|
| 382 | //t = atoi(argv[i++]); |
---|
| 383 | if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) { |
---|
| 384 | fprintf(stderr, "Error: can not kick %s\n", k); |
---|
| 385 | } else { |
---|
| 386 | printf("%s kicked\n", k); |
---|
| 387 | } |
---|
| 388 | |
---|
[85] | 389 | } else if ( !strcmp(k, "volume") ) { |
---|
| 390 | if ( set_mixer(&con, &i, argc, argv) == -1 ) { |
---|
| 391 | fprintf(stderr, "Error: can not set volume\n"); |
---|
| 392 | } else { |
---|
| 393 | printf("volume changed\n"); |
---|
| 394 | } |
---|
| 395 | |
---|
[106] | 396 | } else if ( !strcmp(k, "metaset") ) { |
---|
[99] | 397 | i++; |
---|
| 398 | if ( set_meta(&con, atoi(argv[i]), argv[i+1], argv[i+2], argv[i+3]) == -1 ) { |
---|
| 399 | fprintf(stderr, "Error: can not set meta data\n"); |
---|
| 400 | } else { |
---|
| 401 | printf("meta data changed\n"); |
---|
| 402 | } |
---|
| 403 | i += 3; |
---|
[106] | 404 | } else if ( !strcmp(k, "metaget") ) { |
---|
| 405 | i++; |
---|
| 406 | if ( show_meta_type(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
| 407 | fprintf(stderr, "Error: can not get meta data\n"); |
---|
| 408 | } |
---|
| 409 | i++; |
---|
[99] | 410 | |
---|
[0] | 411 | } else { |
---|
| 412 | fprintf(stderr, "Error: invalid command: %s\n", k); |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | } |
---|
| 416 | |
---|
| 417 | roar_disconnect(&con); |
---|
| 418 | |
---|
| 419 | return 0; |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | //ll |
---|