[0] | 1 | //roarctl.c: |
---|
| 2 | |
---|
[669] | 3 | /* |
---|
[5381] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012 |
---|
[669] | 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 | |
---|
[4885] | 26 | /* ckport options: |
---|
[4922] | 27 | * ckport: ignore-symbol: roar_req of target libroar0 -- Used within ping command. |
---|
[4885] | 28 | */ |
---|
| 29 | |
---|
[3211] | 30 | #define _UNITS_T_BASE_USEC |
---|
| 31 | |
---|
[0] | 32 | #include <roaraudio.h> |
---|
[3211] | 33 | #include <roaraudio/units.h> |
---|
[3539] | 34 | #include <libroardsp/libroardsp.h> |
---|
[1782] | 35 | |
---|
| 36 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) |
---|
| 37 | #define _POSIX_USERS |
---|
| 38 | #endif |
---|
| 39 | |
---|
| 40 | #ifdef _POSIX_USERS |
---|
[445] | 41 | #include <pwd.h> |
---|
| 42 | #include <grp.h> |
---|
[1782] | 43 | #endif |
---|
| 44 | |
---|
[1630] | 45 | #include <sys/time.h> |
---|
| 46 | #include <time.h> |
---|
[445] | 47 | |
---|
[2916] | 48 | #ifdef ROAR_HAVE_LIBM |
---|
| 49 | #include <math.h> |
---|
| 50 | #endif |
---|
| 51 | |
---|
[963] | 52 | int g_verbose = 0; |
---|
[0] | 53 | |
---|
[4818] | 54 | void display_client (struct roar_connection * con, int id); |
---|
| 55 | void display_stream (struct roar_connection * con, int id); |
---|
[25] | 56 | int display_mixer (struct roar_connection * con, int stream); |
---|
[112] | 57 | int show_meta_all (struct roar_connection * con, int id); |
---|
[25] | 58 | |
---|
[0] | 59 | void usage (void) { |
---|
[233] | 60 | printf("roarctl [OPTIONS]... COMMAND [OPTS] [COMMAND [OPTS] [COMMAND [OPTS] [...]]]\n"); |
---|
[0] | 61 | |
---|
| 62 | printf("\nOptions:\n\n"); |
---|
| 63 | |
---|
[86] | 64 | printf(" --server SERVER - Set server hostname\n" |
---|
| 65 | " --help - Show this help\n" |
---|
[963] | 66 | " --verbose -v - Show verbose output\n" |
---|
[3961] | 67 | " --list-aiprofiles - Show audio info profiles and exit\n" |
---|
[5149] | 68 | " --list-libstandards - Gets list of library (libroar) supported standards\n" |
---|
[4413] | 69 | " --enum-servers - Show a list of possible servers\n" |
---|
[5187] | 70 | " --hash-password - Hash a password and exit\n" |
---|
[0] | 71 | ); |
---|
| 72 | |
---|
| 73 | printf("\nCommands:\n\n"); |
---|
| 74 | printf( |
---|
[86] | 75 | " help - Show this help\n" |
---|
[1204] | 76 | " sleep TIME - Sleeps for TIME seconds\n" |
---|
[1781] | 77 | #ifdef ROAR_HAVE_GETTIMEOFDAY |
---|
[1630] | 78 | " ping NUM - Do NUM pings using NOOP commands\n" |
---|
[1781] | 79 | #endif |
---|
[2700] | 80 | " whoami - Get own client ID\n" |
---|
[0] | 81 | "\n" |
---|
[5384] | 82 | " beep - Ask the server to beep.\n" |
---|
| 83 | "\n" |
---|
[3961] | 84 | " listaiprofiles - list audio info profiles\n" |
---|
| 85 | " aiprofileget PROFILE - show audio info profile PROFILE\n" |
---|
| 86 | "\n" |
---|
[86] | 87 | " standby, off - Go into standby mode\n" |
---|
| 88 | " resume, on - Go into active mode\n" |
---|
| 89 | " standbymode - Show current standby mode\n" |
---|
| 90 | " exit - Quits the roard (must be used as last command)\n" |
---|
[577] | 91 | " terminate - Like exit but let the server up to serve still connected clients,\n" |
---|
| 92 | " new clients cann't connect and the server terminates after the last\n" |
---|
| 93 | " client disconnected\n" |
---|
[0] | 94 | "\n" |
---|
[3560] | 95 | " volume ID CHAN [scale S] V0 V1...\n" |
---|
| 96 | " - Sets volume for stream ID\n" |
---|
[86] | 97 | " CHAN is the number of channels or 'mono' or 'stereo'\n" |
---|
| 98 | " if mono or stereo is chosen roarctl trys to set\n" |
---|
| 99 | " sensfull values for all channels even if the output\n" |
---|
| 100 | " is has more channels.\n" |
---|
[3560] | 101 | " An optional scale can be given using S.\n" |
---|
[86] | 102 | " all other args are the volumes of the channels\n" |
---|
| 103 | " you may use integer or percent values.\n" |
---|
[3846] | 104 | " percent values can floating points.\n" |
---|
[0] | 105 | "\n" |
---|
[1123] | 106 | " flag ID FLAGS - Sets flags FLAGS on stream ID. FLAGS may be a comma\n" |
---|
[4012] | 107 | " separated list of flags.\n" |
---|
[1123] | 108 | " unflag ID FLAGS - Unsets flags on a stream. See flag.\n" |
---|
[4552] | 109 | " toogleflag ID FLAGS - Toggels flags on a stream. See flag.\n" |
---|
| 110 | " protectflag ID FLAGS - Protects flags on a stream. Those flags can not be\n" |
---|
| 111 | " changed anymore after the they got protected. See flag.\n" |
---|
[1123] | 112 | "\n" |
---|
[4933] | 113 | " role ID ROLE - Set role ROLE on stream ID.\n" |
---|
| 114 | "\n" |
---|
[86] | 115 | " kick TYPE ID - Kicks object of TYPE with id ID\n" |
---|
| 116 | " Types: client stream sample source\n" |
---|
[2698] | 117 | " newvirtual P D E R B C - Adds a new virtual (child) stream\n" |
---|
| 118 | " Parameters:\n" |
---|
| 119 | " P: Parent stream ID, D: Direction,\n" |
---|
| 120 | " E: codEc, R: sample Rate,\n" |
---|
| 121 | " B: bits per sample, C: nummer of channels\n" |
---|
[86] | 122 | "\n" |
---|
[2700] | 123 | " metaget ID TYPE - Read meta date of type TYPE from stream ID\n" |
---|
| 124 | // TODO: document metaset here. |
---|
[1160] | 125 | " metasave ID FILE - Saves meta data of stream ID to file FILE\n" |
---|
| 126 | " metaload ID FILE - Loads meta data from file FILE and set it on stream ID\n" |
---|
| 127 | "\n" |
---|
[4443] | 128 | " serverinfo - Gets general information about the server\n" |
---|
[5031] | 129 | " servertime - Gets server's time\n" |
---|
[4012] | 130 | " serveroinfo - Gets Information about server output\n" |
---|
[4614] | 131 | " serveroinfo2 DIR - Gets Information about server output for stream direction dir\n" |
---|
[4818] | 132 | "\n" |
---|
[4501] | 133 | " serverstandards - Gets list of server supported standards\n" |
---|
[5149] | 134 | " libstandards - Gets list of library (libroar) supported standards\n" |
---|
[4818] | 135 | "\n" |
---|
[4012] | 136 | " listclients - Gets Information about clients\n" |
---|
[4818] | 137 | " clientinfo ID - Gets Information about client ID\n" |
---|
[4012] | 138 | " liststreams - Gets Information about streams\n" |
---|
[4818] | 139 | " streaminfo ID - Gets Information about stream ID\n" |
---|
[86] | 140 | " allinfo - Get all infos\n" |
---|
[0] | 141 | ); |
---|
| 142 | } |
---|
| 143 | |
---|
[5187] | 144 | static void _bin2hex(char * out, char * in, size_t inlen, int uppercase) { |
---|
| 145 | const char * tab = uppercase ? "0123456789ABCDEF" : "0123456789abcdef"; |
---|
| 146 | unsigned char c; |
---|
| 147 | int nib0, nib1; |
---|
| 148 | |
---|
| 149 | for (; inlen; inlen--) { |
---|
| 150 | c = *(in++); |
---|
| 151 | nib0 = (c & 0x0F) >> 0; |
---|
| 152 | nib1 = (c & 0xF0) >> 4; |
---|
| 153 | // printf("inlen=%zu, c=%u, nibs={%i, %i}\n", inlen, (unsigned)c, nib1, nib0); |
---|
| 154 | *(out++) = tab[nib1]; |
---|
| 155 | *(out++) = tab[nib0]; |
---|
| 156 | } |
---|
| 157 | *out = 0; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | int hash_password (void) { |
---|
| 161 | char * pw = NULL; |
---|
| 162 | char salt[8]; |
---|
| 163 | char digest[24]; |
---|
| 164 | char out[2*(8+24)+3+5+1] = "tiger:"; |
---|
| 165 | |
---|
| 166 | if ( roar_passwd_simple_ask_pw(&pw, "Password to hash?", NULL) == -1 ) |
---|
| 167 | return -1; |
---|
| 168 | |
---|
| 169 | roar_random_gen_nonce(salt, sizeof(salt)); |
---|
| 170 | |
---|
| 171 | roar_hash_salted_buffer(digest, pw, roar_mm_strlen(pw), ROAR_HT_TIGER, salt, sizeof(salt)); |
---|
| 172 | |
---|
| 173 | roar_mm_free(pw); |
---|
| 174 | |
---|
| 175 | _bin2hex(out+6, salt, sizeof(salt), 0); |
---|
| 176 | out[6+16] = ':'; |
---|
| 177 | _bin2hex(out+6+16+1, digest, sizeof(digest), 0); |
---|
| 178 | |
---|
| 179 | out[sizeof(out)-1] = 0; |
---|
| 180 | |
---|
| 181 | printf("Password: %s\n", out); |
---|
| 182 | |
---|
| 183 | return 0; |
---|
| 184 | } |
---|
| 185 | |
---|
[4413] | 186 | int enum_servers (void) { |
---|
| 187 | struct roar_server * list; |
---|
| 188 | struct roar_server * c; |
---|
| 189 | int flags = ROAR_ENUM_FLAG_DESC|ROAR_ENUM_FLAG_LOCATION; |
---|
| 190 | int dir = -1; |
---|
| 191 | int socktype = -1; |
---|
| 192 | int i; |
---|
| 193 | |
---|
| 194 | if ( (list = roar_enum_servers(flags, dir, socktype)) == NULL ) |
---|
| 195 | return -1; |
---|
| 196 | |
---|
| 197 | printf("Server Location Description\n"); |
---|
| 198 | printf("----------------------------------------------------------------------\n"); |
---|
| 199 | |
---|
| 200 | for (i = 0; ; i++) { |
---|
| 201 | c = &(list[i]); |
---|
| 202 | printf("%-16s %-16s %s\n", |
---|
| 203 | c->server == NULL ? "(default)" : c->server, |
---|
| 204 | c->location == NULL ? "" : c->location, |
---|
| 205 | c->description == NULL ? "" : c->description |
---|
| 206 | ); |
---|
| 207 | if ( c->server == NULL ) |
---|
| 208 | break; |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | roar_enum_servers_free(list); |
---|
| 212 | |
---|
| 213 | return 0; |
---|
| 214 | } |
---|
| 215 | |
---|
[1781] | 216 | #ifdef ROAR_HAVE_GETTIMEOFDAY |
---|
[1630] | 217 | int ping (struct roar_connection * con, int num) { |
---|
| 218 | struct timeval try, ans; |
---|
| 219 | struct roar_message m; |
---|
| 220 | register int ret; |
---|
[1631] | 221 | int i; |
---|
| 222 | double cur, min = 3600*1000, max = 0, sum = 0; |
---|
| 223 | |
---|
| 224 | if ( num == 0 ) |
---|
| 225 | return 0; |
---|
[1630] | 226 | |
---|
| 227 | for (i = 0; i < num; i++) { |
---|
[3875] | 228 | memset(&m, 0, sizeof(m)); |
---|
| 229 | |
---|
[1630] | 230 | m.cmd = ROAR_CMD_NOOP; |
---|
[5144] | 231 | m.stream = -1; |
---|
| 232 | m.datalen = 0; |
---|
[1630] | 233 | |
---|
[3875] | 234 | // we use roar_req() directly here because of speed. |
---|
| 235 | // roar_noop() does basicly the same but is a bit slower. |
---|
| 236 | |
---|
[1630] | 237 | gettimeofday(&try, NULL); |
---|
| 238 | ret = roar_req(con, &m, NULL); |
---|
| 239 | gettimeofday(&ans, NULL); |
---|
| 240 | |
---|
| 241 | if ( ret == -1 ) |
---|
| 242 | return -1; |
---|
| 243 | |
---|
| 244 | while (ans.tv_sec > try.tv_sec) { |
---|
| 245 | ans.tv_sec--; |
---|
| 246 | ans.tv_usec += 1000000; |
---|
| 247 | } |
---|
| 248 | ans.tv_usec -= try.tv_usec; |
---|
| 249 | |
---|
[5384] | 250 | cur = ans.tv_usec/1000.0; |
---|
| 251 | |
---|
| 252 | printf("Pong from server: seq=%i time=%.3f%cs\n", i, cur < 0.5 ? cur*1000.0 : cur, cur < 0.5 ? 'u' : 'm'); |
---|
[1631] | 253 | |
---|
| 254 | sum += cur; |
---|
| 255 | if ( min > cur ) |
---|
| 256 | min = cur; |
---|
| 257 | if ( cur > max ) |
---|
| 258 | max = cur; |
---|
[1630] | 259 | |
---|
| 260 | if ( i != (num - 1) ) |
---|
[4914] | 261 | roar_sleep(1); |
---|
[1630] | 262 | } |
---|
| 263 | |
---|
[1631] | 264 | printf("\n--- ping statistics ---\n"); |
---|
| 265 | printf("%i packets transmitted\n", i); |
---|
| 266 | printf("rtt min/avg/max = %.3f/%.3f/%.3f ms\n", min, sum/(double)i, max); |
---|
| 267 | |
---|
[1630] | 268 | return 0; |
---|
| 269 | } |
---|
[1781] | 270 | #endif |
---|
[1630] | 271 | |
---|
[4434] | 272 | #define _pm(m,n) if ( info->m != NULL ) printf("Server %-15s: %s\n", (n), (info->m)); |
---|
[4432] | 273 | void server_info (struct roar_connection * con) { |
---|
| 274 | struct roar_server_info * info = roar_server_info(con); |
---|
[5279] | 275 | long hostid; |
---|
[4432] | 276 | |
---|
| 277 | if ( info == NULL ) { |
---|
| 278 | fprintf(stderr, "Error: can not get server info\n"); |
---|
| 279 | return; |
---|
| 280 | } |
---|
| 281 | |
---|
[5279] | 282 | _pm(version, "Version"); |
---|
| 283 | _pm(location, "Location"); |
---|
| 284 | _pm(description, "Description"); |
---|
| 285 | _pm(contact, "Contact"); |
---|
| 286 | _pm(serial, "Serial"); |
---|
| 287 | _pm(address, "Address"); |
---|
[4434] | 288 | _pm(uiurl, "UI URL"); |
---|
[5279] | 289 | _pm(license, "License"); |
---|
| 290 | // _pm(hostid, "HostID"); |
---|
| 291 | if ( info->hostid != NULL ) { |
---|
| 292 | if ( sscanf(info->hostid, "0x%lx", &hostid) != 1 ) |
---|
| 293 | hostid = 0; |
---|
| 294 | |
---|
| 295 | if ( hostid ) { |
---|
| 296 | printf("Server %-15s: %s (%li.%li.%li.%li)\n", "HostID", info->hostid, |
---|
| 297 | ((hostid & 0x00FF0000UL) >> 16UL), |
---|
| 298 | ((hostid & 0xFF000000UL) >> 24UL), |
---|
| 299 | ((hostid & 0x000000FFUL) >> 0UL), |
---|
| 300 | ((hostid & 0x0000FF00UL) >> 8UL) |
---|
| 301 | ); |
---|
| 302 | } else { |
---|
| 303 | printf("Server %-15s: %s\n", "HostID", info->hostid); |
---|
| 304 | } |
---|
| 305 | } |
---|
[5372] | 306 | _pm(build, "Build"); |
---|
[4434] | 307 | _pm(un.sysname, "System sysname"); |
---|
| 308 | _pm(un.release, "System release"); |
---|
| 309 | _pm(un.nodename, "System nodename"); |
---|
| 310 | _pm(un.machine, "System machine"); |
---|
[4432] | 311 | |
---|
| 312 | roar_server_info_free(info); |
---|
| 313 | } |
---|
[4434] | 314 | #undef _pm |
---|
[4432] | 315 | |
---|
[5031] | 316 | void server_time (struct roar_connection * con) { |
---|
| 317 | struct roar_time time; |
---|
[5379] | 318 | #ifdef ROAR_HAVE_CTIME_R |
---|
| 319 | time_t server_time; |
---|
| 320 | char server_time_buf[32]; |
---|
| 321 | #endif |
---|
| 322 | |
---|
[5031] | 323 | |
---|
| 324 | if ( roar_get_time(con, &time) == -1 ) { |
---|
[5185] | 325 | fprintf(stderr, "Error: can not get server time: %s\n", roar_vs_strerr(roar_error)); |
---|
[5031] | 326 | return; |
---|
| 327 | } |
---|
| 328 | |
---|
[5379] | 329 | #ifdef ROAR_HAVE_CTIME_R |
---|
| 330 | server_time = time.t_sec; |
---|
| 331 | if ( ctime_r(&server_time, server_time_buf) == NULL ) |
---|
| 332 | server_time_buf[0] = 0; |
---|
| 333 | |
---|
| 334 | if ( server_time_buf[0] ) |
---|
| 335 | if ( server_time_buf[strlen(server_time_buf)-1] == '\n' ) |
---|
| 336 | server_time_buf[strlen(server_time_buf)-1] = 0; |
---|
| 337 | #endif |
---|
| 338 | |
---|
[5031] | 339 | if ( g_verbose ) { |
---|
[5379] | 340 | printf("Server time : %s%s%s%llu.%06llu [+%llu/2^64] sec\n", |
---|
| 341 | #ifdef ROAR_HAVE_CTIME_R |
---|
| 342 | "\"", |
---|
| 343 | server_time_buf, |
---|
| 344 | "\" ", |
---|
| 345 | #else |
---|
| 346 | "", "", "", |
---|
| 347 | #endif |
---|
[5031] | 348 | (long long unsigned int)time.t_sec, |
---|
| 349 | (long long unsigned int) time.t_ssec / 18446744073709LLU, |
---|
| 350 | (long long unsigned int) time.t_ssec); |
---|
| 351 | } else { |
---|
[5087] | 352 | if ( time.c_freq == 1000000000LL && time.t_ssec == 0 ) { |
---|
[5379] | 353 | printf("Server time : %s%s%s%llu sec\n", |
---|
| 354 | #ifdef ROAR_HAVE_CTIME_R |
---|
| 355 | "\"", |
---|
| 356 | server_time_buf, |
---|
| 357 | "\" ", |
---|
| 358 | #else |
---|
| 359 | "", "", "", |
---|
| 360 | #endif |
---|
[5087] | 361 | (long long unsigned int)time.t_sec); |
---|
| 362 | } else { |
---|
[5379] | 363 | printf("Server time : %s%s%s%llu.%06llu sec\n", |
---|
| 364 | #ifdef ROAR_HAVE_CTIME_R |
---|
| 365 | "\"", |
---|
| 366 | server_time_buf, |
---|
| 367 | "\" ", |
---|
| 368 | #else |
---|
| 369 | "", "", "", |
---|
| 370 | #endif |
---|
[5087] | 371 | (long long unsigned int)time.t_sec, |
---|
| 372 | (long long unsigned int) time.t_ssec / 18446744073709LLU); |
---|
| 373 | } |
---|
[5031] | 374 | } |
---|
| 375 | if ( time.c_freq ) |
---|
[5067] | 376 | printf("Server clock frequency: %f Hz\n", (float)((double)time.c_freq / (double)1000000000.)); |
---|
[5209] | 377 | if ( time.c_drift ) { |
---|
| 378 | #ifdef ROAR_HAVE_LIBM |
---|
[5031] | 379 | printf("Server clock drift : %llu:2^64 (~10^%f)\n", |
---|
| 380 | (long long unsigned int)time.c_drift, logf((float)time.c_drift)/2.302585f); |
---|
[5209] | 381 | #else |
---|
| 382 | printf("Server clock drift : %llu:2^64\n", |
---|
| 383 | (long long unsigned int)time.c_drift); |
---|
| 384 | #endif |
---|
| 385 | } |
---|
[5031] | 386 | } |
---|
| 387 | |
---|
[4614] | 388 | void server_oinfo (struct roar_connection * con, int dir) { |
---|
[0] | 389 | struct roar_stream s; |
---|
| 390 | |
---|
[5236] | 391 | if ( roar_server_oinfo(con, &s, dir) == -1 ) { |
---|
[0] | 392 | fprintf(stderr, "Error: can not get server output info\n"); |
---|
| 393 | return; |
---|
| 394 | } |
---|
| 395 | |
---|
| 396 | printf("Stream direction : %s\n", roar_dir2str(s.dir)); |
---|
[4591] | 397 | printf("Server Output rate : %i Hz\n", s.info.rate); |
---|
[0] | 398 | printf("Server Output bits : %i\n", s.info.bits); |
---|
| 399 | printf("Server Output channels: %i\n", s.info.channels); |
---|
| 400 | printf("Server Output codec : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec), |
---|
| 401 | s.info.codec == ROAR_CODEC_DEFAULT ? " native" : ""); |
---|
| 402 | // printf("Server Output rate: %i", s.info.rate); |
---|
[4108] | 403 | if ( g_verbose > 1 && s.pos != (uint32_t)-1 ) |
---|
[984] | 404 | printf("Server Position : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels)); |
---|
[0] | 405 | } |
---|
| 406 | |
---|
[5149] | 407 | static void print_stds (const struct roar_stds * stds) { |
---|
[4501] | 408 | size_t i; |
---|
| 409 | int vendor, standard, version; |
---|
[4503] | 410 | char numbuf[2][8]; |
---|
| 411 | const char * vendor_name; |
---|
[4501] | 412 | |
---|
| 413 | for (i = 0; i < stds->stds_len; i++) { |
---|
| 414 | vendor = ROAR_STD_VENDOR(stds->stds[i]); |
---|
| 415 | standard = ROAR_STD_STD(stds->stds[i]); |
---|
| 416 | version = ROAR_STD_VERSION(stds->stds[i]); |
---|
[4503] | 417 | |
---|
| 418 | if ( (vendor_name = roar_stds_vendor2str(vendor)) == NULL ) { |
---|
| 419 | snprintf(numbuf[0], sizeof(numbuf[0]), "%i", vendor); |
---|
| 420 | numbuf[0][sizeof(numbuf[0])-1] = 0; |
---|
| 421 | vendor_name = numbuf[0]; |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | if ( version == 0 ) { |
---|
| 425 | numbuf[1][0] = 0; |
---|
| 426 | } else { |
---|
| 427 | snprintf(numbuf[1], sizeof(numbuf[1]), "-%i", version); |
---|
| 428 | numbuf[1][sizeof(numbuf[1])-1] = 0; |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | printf("Server standard : %s-%i%s\n", vendor_name, standard, numbuf[1]); |
---|
[4501] | 432 | } |
---|
| 433 | } |
---|
| 434 | |
---|
[5149] | 435 | void server_standards (struct roar_connection * con) { |
---|
| 436 | struct roar_stds * stds; |
---|
| 437 | |
---|
| 438 | if ( roar_caps_stds(con, &stds, NULL, -1) == -1 ) { |
---|
| 439 | fprintf(stderr, "Error: can not get server standards\n"); |
---|
| 440 | return; |
---|
| 441 | } |
---|
| 442 | |
---|
| 443 | print_stds(stds); |
---|
| 444 | |
---|
| 445 | roar_stds_free(stds); |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | void lib_standards (void) { |
---|
| 449 | print_stds(libroar_libstds()); |
---|
| 450 | } |
---|
| 451 | |
---|
[449] | 452 | const char * proc_name (pid_t pid) { |
---|
| 453 | static char ret[80] = "?"; |
---|
| 454 | #ifdef __linux__ |
---|
| 455 | char file[80], buf[80], *r; |
---|
| 456 | int i; |
---|
| 457 | |
---|
[4047] | 458 | snprintf(file, sizeof(file)-1, "/proc/%i/exe", pid); |
---|
| 459 | file[sizeof(file)-1] = 0; |
---|
[449] | 460 | |
---|
| 461 | ret[0] = '?'; |
---|
| 462 | ret[1] = 0; |
---|
| 463 | |
---|
[4047] | 464 | if ( (i = readlink(file, buf, sizeof(buf)-1)) != -1 ) { |
---|
[449] | 465 | buf[i] = 0; |
---|
| 466 | if ( (r = strrchr(buf, '/')) != NULL ) { |
---|
| 467 | r++; |
---|
[4047] | 468 | if ( *r != 0 ) { |
---|
| 469 | strncpy(ret, r, sizeof(ret)-1); |
---|
| 470 | ret[sizeof(ret)-1] = 0; |
---|
| 471 | } |
---|
[449] | 472 | } |
---|
| 473 | } |
---|
[3787] | 474 | #else |
---|
| 475 | (void)pid; |
---|
[449] | 476 | #endif |
---|
| 477 | |
---|
| 478 | return ret; |
---|
| 479 | } |
---|
| 480 | |
---|
[0] | 481 | void list_clients (struct roar_connection * con) { |
---|
| 482 | int i; |
---|
| 483 | int num; |
---|
| 484 | int id[ROAR_CLIENTS_MAX]; |
---|
[2814] | 485 | |
---|
[0] | 486 | if ( (num = roar_list_clients(con, id, ROAR_CLIENTS_MAX)) == -1 ) { |
---|
| 487 | fprintf(stderr, "Error: can not get client list\n"); |
---|
| 488 | return; |
---|
| 489 | } |
---|
| 490 | |
---|
| 491 | for (i = 0; i < num; i++) { |
---|
[4818] | 492 | display_client(con, id[i]); |
---|
| 493 | } |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | void display_client (struct roar_connection * con, int id) { |
---|
| 497 | static int self_id = -1; |
---|
| 498 | static struct roar_client self_client_store; |
---|
| 499 | static struct roar_client * self_client = NULL; |
---|
| 500 | struct roar_client c; |
---|
| 501 | char tmp[80]; |
---|
| 502 | int h; |
---|
| 503 | #ifdef _POSIX_USERS |
---|
| 504 | struct group * grp = NULL; |
---|
| 505 | struct passwd * pwd = NULL; |
---|
| 506 | #endif |
---|
| 507 | |
---|
| 508 | if ( self_id == -1 ) { |
---|
| 509 | if ( (self_id = roar_get_clientid(con)) != -1 ) { |
---|
| 510 | if ( roar_get_client(con, &self_client_store, self_id) == -1 ) { |
---|
| 511 | self_id = -1; |
---|
| 512 | } else { |
---|
| 513 | self_client = &self_client_store; |
---|
| 514 | } |
---|
| 515 | } |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | printf("client %i:\n", id); |
---|
| 519 | if ( roar_get_client(con, &c, id) == -1 ) { |
---|
| 520 | fprintf(stderr, "Error: can not get client info\n"); |
---|
| 521 | return; |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | if ( c.name[0] != '\0' ) |
---|
| 525 | printf("Client name : %s\n", c.name); |
---|
| 526 | if ( roar_nnode_get_socktype(&(c.nnode)) != ROAR_SOCKET_TYPE_UNKNOWN ) { |
---|
[5005] | 527 | if ( roar_nnode_to_str(&(c.nnode), tmp, sizeof(tmp)) == 0 ) { |
---|
[4818] | 528 | printf("Client network node : %s\n", tmp); |
---|
| 529 | } |
---|
| 530 | } |
---|
| 531 | |
---|
| 532 | if ( c.pid != -1 ) { |
---|
| 533 | if ( self_id != -1 && roar_nnode_cmp(&(self_client->nnode), &(c.nnode)) == 0 ) { |
---|
| 534 | printf("Client PID : %i(%s)\n", c.pid, proc_name(c.pid)); |
---|
| 535 | } else { |
---|
| 536 | printf("Client PID : %i\n", c.pid); |
---|
| 537 | } |
---|
| 538 | } |
---|
| 539 | if ( c.uid != -1 ) { |
---|
| 540 | #ifdef _POSIX_USERS |
---|
| 541 | if ( self_id != -1 && roar_nnode_cmp(&(self_client->nnode), &(c.nnode)) == 0 ) { |
---|
| 542 | pwd = getpwuid(c.uid); |
---|
| 543 | grp = getgrgid(c.gid); |
---|
| 544 | printf("Client UID/GID : %i(%s)/%i(%s)\n", c.uid, pwd ? pwd->pw_name : "?", c.gid, grp ? grp->gr_name : "?"); |
---|
| 545 | } else { |
---|
| 546 | #else |
---|
| 547 | if ( 1 ) { |
---|
| 548 | #endif |
---|
| 549 | printf("Client UID/GID : %i/%i\n", c.uid, c.gid); |
---|
| 550 | } |
---|
| 551 | } |
---|
| 552 | |
---|
| 553 | if ( g_verbose && c.proto != ROAR_PROTO_NONE ) { |
---|
| 554 | printf("Client Protocol : %s\n", roar_proto2str(c.proto)); |
---|
| 555 | } |
---|
| 556 | |
---|
| 557 | if ( g_verbose && c.byteorder != ROAR_BYTEORDER_UNKNOWN ) { |
---|
| 558 | if ( c.byteorder == ROAR_BYTEORDER_NETWORK ) { |
---|
[5005] | 559 | roar_mm_strscpy(tmp, " (network byteorder"); |
---|
[4818] | 560 | } else { |
---|
| 561 | *tmp = 0; |
---|
[0] | 562 | } |
---|
[3845] | 563 | |
---|
[4818] | 564 | if ( c.byteorder == ROAR_BYTEORDER_NATIVE ) { |
---|
| 565 | if ( *tmp ) { |
---|
[5005] | 566 | roar_mm_strscat(tmp, ", native"); |
---|
[4818] | 567 | } else { |
---|
[5005] | 568 | roar_mm_strscpy(tmp, " (native"); |
---|
[2814] | 569 | } |
---|
| 570 | } |
---|
| 571 | |
---|
[4818] | 572 | if ( *tmp ) |
---|
[5005] | 573 | roar_mm_strscat(tmp, ")"); |
---|
[2550] | 574 | |
---|
[4818] | 575 | printf("Client Byteorder : %s%s\n", roar_byteorder2str(c.byteorder), tmp); |
---|
[0] | 576 | } |
---|
| 577 | |
---|
[4818] | 578 | if ( c.execed != -1 ) |
---|
| 579 | printf("Execed stream : %i\n", c.execed); |
---|
| 580 | |
---|
| 581 | for (h = 0; h < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; h++) |
---|
| 582 | if ( c.streams[h] != -1 ) |
---|
| 583 | printf("stream : %i\n", c.streams[h]); |
---|
[0] | 584 | } |
---|
| 585 | |
---|
| 586 | void list_streams (struct roar_connection * con) { |
---|
| 587 | int i; |
---|
| 588 | int num; |
---|
| 589 | int id[ROAR_STREAMS_MAX]; |
---|
[4818] | 590 | |
---|
| 591 | if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) { |
---|
| 592 | fprintf(stderr, "Error: can not get stream list\n"); |
---|
| 593 | return; |
---|
| 594 | } |
---|
| 595 | |
---|
| 596 | for (i = 0; i < num; i++) { |
---|
| 597 | display_stream(con, id[i]); |
---|
| 598 | } |
---|
| 599 | } |
---|
| 600 | |
---|
| 601 | void display_stream (struct roar_connection * con, int id) { |
---|
[3539] | 602 | char chanmap[ROAR_MAX_CHANNELS]; |
---|
[0] | 603 | struct roar_stream s; |
---|
[465] | 604 | struct roar_stream_info info; |
---|
[3539] | 605 | char buffer[1024]; |
---|
| 606 | char * flags = buffer; |
---|
| 607 | char * name = buffer; |
---|
[2399] | 608 | char * infotext; |
---|
[4603] | 609 | const char * mime; |
---|
[3539] | 610 | size_t len; |
---|
[0] | 611 | |
---|
[4818] | 612 | printf("stream %i:\n", id); |
---|
| 613 | if ( roar_get_stream(con, &s, id) == -1 ) { |
---|
| 614 | fprintf(stderr, "Error: can not get stream info\n"); |
---|
| 615 | return; |
---|
| 616 | } |
---|
| 617 | printf("Stream direction : %s\n", roar_dir2str(s.dir)); |
---|
[0] | 618 | |
---|
[5005] | 619 | if ( roar_stream_get_name(con, &s, name, sizeof(buffer)) == 0 ) |
---|
[4818] | 620 | printf("Stream name : %s\n", name); |
---|
| 621 | |
---|
| 622 | if ( (int)s.pos_rel_id == -1 ) { |
---|
| 623 | printf("Relativ position id : none (stream not synchronized)\n"); |
---|
| 624 | } else if ( (int)s.pos_rel_id == id ) { |
---|
| 625 | printf("Relativ position id : %i (self synchronized)\n", s.pos_rel_id); |
---|
| 626 | } else { |
---|
| 627 | printf("Relativ position id : %i (synchronized)\n", s.pos_rel_id); |
---|
| 628 | } |
---|
| 629 | if ( g_verbose > 1 && s.pos != (uint32_t)-1 ) { |
---|
| 630 | if ( s.info.rate && s.info.channels ) { |
---|
| 631 | printf("Position : %lu S (%.3fs)\n", (unsigned long int) s.pos, |
---|
| 632 | (float)s.pos/(s.info.rate*s.info.channels)); |
---|
| 633 | } else { |
---|
| 634 | printf("Position : %lu S\n", (unsigned long int) s.pos); |
---|
| 635 | } |
---|
[0] | 636 | } |
---|
| 637 | |
---|
[4818] | 638 | switch (s.dir) { |
---|
| 639 | case ROAR_DIR_MIDI_IN: |
---|
| 640 | case ROAR_DIR_MIDI_OUT: |
---|
| 641 | infotext = " ticks/s"; |
---|
| 642 | break; |
---|
| 643 | case ROAR_DIR_LIGHT_IN: |
---|
| 644 | case ROAR_DIR_LIGHT_OUT: |
---|
| 645 | infotext = " updates/s"; |
---|
| 646 | break; |
---|
| 647 | default: |
---|
| 648 | infotext = " Hz"; |
---|
| 649 | } |
---|
| 650 | if ( s.info.rate ) |
---|
| 651 | printf("Stream sample rate : %i%s\n", s.info.rate, infotext); |
---|
| 652 | if ( s.info.bits ) |
---|
| 653 | printf("Stream bits : %i\n", s.info.bits); |
---|
| 654 | if ( s.info.channels ) |
---|
[2399] | 655 | printf("Stream channels : %i\n", s.info.channels); |
---|
[1810] | 656 | |
---|
[4818] | 657 | mime = roar_codec2mime(s.info.codec); |
---|
| 658 | printf("Stream codec : %2i (%s%s%s%s)\n", s.info.codec, roar_codec2str(s.info.codec), |
---|
| 659 | s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "", |
---|
| 660 | mime == NULL ? "" : " mimetype:", |
---|
| 661 | mime == NULL ? "" : mime |
---|
| 662 | ); |
---|
| 663 | if ( roar_stream_get_info(con, &s, &info) != -1 ) { |
---|
| 664 | if ( info.codec != s.info.codec ) { |
---|
| 665 | mime = roar_codec2mime(info.codec); |
---|
| 666 | printf("Streamed codec : %2i (%s%s%s%s)\n", info.codec, roar_codec2str(info.codec), |
---|
| 667 | info.codec == ROAR_CODEC_DEFAULT ? " native" : "", |
---|
| 668 | mime == NULL ? "" : " mimetype:", |
---|
| 669 | mime == NULL ? "" : mime |
---|
| 670 | ); |
---|
[465] | 671 | } |
---|
[1811] | 672 | |
---|
[3539] | 673 | if ( g_verbose ) { |
---|
[4818] | 674 | if ( info.block_size ) |
---|
| 675 | printf("Stream block size : %i Byte\n", info.block_size); |
---|
| 676 | |
---|
| 677 | printf("Underruns pre/post : %i/%i\n", info.pre_underruns, info.post_underruns); |
---|
| 678 | if ( g_verbose > 1 ) |
---|
| 679 | printf("Stream delay : %ims (%.2fm)\n", (int)info.delay/1000, (info.delay*(float)_SPEED_OF_SOUND)); |
---|
| 680 | |
---|
| 681 | if ( g_verbose > 1 ) |
---|
| 682 | printf("Stream mixer : %i\n", info.mixer); |
---|
| 683 | |
---|
| 684 | if ( g_verbose > 1 ) |
---|
| 685 | printf("Stream state : %s\n", roar_streamstate2str(info.state)); |
---|
| 686 | |
---|
| 687 | if ( g_verbose > 1 ) |
---|
| 688 | printf("Stream role : %s\n", roar_role2str(info.role)); |
---|
[3539] | 689 | |
---|
[4818] | 690 | *flags = 0; |
---|
[5005] | 691 | #define _strcat(dst,src) roar_mm_strlcat((dst),(src), sizeof(buffer)) |
---|
[4818] | 692 | if ( info.flags & ROAR_FLAG_PRIMARY ) |
---|
[5005] | 693 | _strcat(flags, "primary "); |
---|
[4818] | 694 | if ( info.flags & ROAR_FLAG_SYNC ) |
---|
[5005] | 695 | _strcat(flags, "sync "); |
---|
[4818] | 696 | if ( info.flags & ROAR_FLAG_OUTPUT ) |
---|
[5005] | 697 | _strcat(flags, "output "); |
---|
[4818] | 698 | if ( info.flags & ROAR_FLAG_SOURCE ) |
---|
[5005] | 699 | _strcat(flags, "source "); |
---|
[4818] | 700 | if ( info.flags & ROAR_FLAG_META ) |
---|
[5005] | 701 | _strcat(flags, "meta "); |
---|
[4818] | 702 | if ( info.flags & ROAR_FLAG_AUTOCONF ) |
---|
[5005] | 703 | _strcat(flags, "autoconf "); |
---|
[4818] | 704 | if ( info.flags & ROAR_FLAG_CLEANMETA ) |
---|
[5005] | 705 | _strcat(flags, "cleanmeta "); |
---|
[4818] | 706 | if ( info.flags & ROAR_FLAG_HWMIXER ) |
---|
[5005] | 707 | _strcat(flags, "hwmixer "); |
---|
[4818] | 708 | if ( info.flags & ROAR_FLAG_PAUSE ) |
---|
[5005] | 709 | _strcat(flags, "pause "); |
---|
[4818] | 710 | if ( info.flags & ROAR_FLAG_MUTE ) |
---|
[5005] | 711 | _strcat(flags, "mute "); |
---|
[4818] | 712 | if ( info.flags & ROAR_FLAG_MMAP ) |
---|
[5005] | 713 | _strcat(flags, "mmap "); |
---|
[4818] | 714 | if ( info.flags & ROAR_FLAG_ANTIECHO ) |
---|
[5005] | 715 | _strcat(flags, "antiecho "); |
---|
[4818] | 716 | if ( info.flags & ROAR_FLAG_VIRTUAL ) |
---|
[5005] | 717 | _strcat(flags, "virtual "); |
---|
[4818] | 718 | if ( info.flags & ROAR_FLAG_RECSOURCE ) |
---|
[5005] | 719 | _strcat(flags, "recsource "); |
---|
[4818] | 720 | if ( info.flags & ROAR_FLAG_PASSMIXER ) |
---|
[5005] | 721 | _strcat(flags, "passmixer "); |
---|
[4818] | 722 | if ( info.flags & ROAR_FLAG_PRETHRU ) |
---|
[5005] | 723 | _strcat(flags, "prethru "); |
---|
[4818] | 724 | if ( info.flags & ROAR_FLAG_IMMUTABLE ) |
---|
[5005] | 725 | _strcat(flags, "immutable "); |
---|
[4818] | 726 | if ( info.flags & ROAR_FLAG_ENHANCE ) |
---|
[5005] | 727 | _strcat(flags, "enhance "); |
---|
[4818] | 728 | if ( info.flags & ROAR_FLAG_SINGLESINK ) |
---|
[5005] | 729 | _strcat(flags, "singlesink "); |
---|
| 730 | #undef _strcat |
---|
[4818] | 731 | |
---|
| 732 | printf("Flags : %s\n", flags); |
---|
[1811] | 733 | } |
---|
[0] | 734 | } |
---|
| 735 | |
---|
[4818] | 736 | if ( g_verbose ) { |
---|
| 737 | len = ROAR_MAX_CHANNELS; |
---|
| 738 | if ( roar_stream_get_chanmap(con, &s, chanmap, &len) == -1 ) { |
---|
| 739 | fprintf(stderr, "Error: can not get stream channel map\n"); |
---|
| 740 | } else { |
---|
| 741 | if ( roardsp_chanlist2str(chanmap, len, buffer, 1024) == -1 ) { |
---|
| 742 | fprintf(stderr, "Error: can not convert channel map into string\n"); |
---|
| 743 | } else { |
---|
| 744 | printf("Channel Map : %s\n", buffer); |
---|
| 745 | } |
---|
| 746 | } |
---|
| 747 | } |
---|
| 748 | |
---|
| 749 | if ( s.dir != ROAR_DIR_THRU ) { |
---|
| 750 | display_mixer(con, id); |
---|
| 751 | show_meta_all(con, id); |
---|
| 752 | } |
---|
[0] | 753 | } |
---|
| 754 | |
---|
[25] | 755 | int display_mixer (struct roar_connection * con, int stream) { |
---|
[3529] | 756 | struct roar_mixer_settings mixer; |
---|
[25] | 757 | int channels; |
---|
| 758 | int i; |
---|
[3529] | 759 | float fs; |
---|
[25] | 760 | |
---|
| 761 | if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) { |
---|
[3530] | 762 | fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", stream); |
---|
[25] | 763 | return -1; |
---|
| 764 | } |
---|
| 765 | |
---|
[2916] | 766 | #ifdef ROAR_HAVE_LIBM |
---|
| 767 | #define _DB ", %.2fdB" |
---|
| 768 | #else |
---|
| 769 | #define _DB "" |
---|
| 770 | #endif |
---|
| 771 | |
---|
[3529] | 772 | fs = (float)mixer.scale / 100.; |
---|
| 773 | |
---|
[3531] | 774 | if ( channels ) { // we hide RPG info for zero-channel streams |
---|
| 775 | printf("Mixer ReplayGain : %i/%i (%.2f%%" _DB ")\n", mixer.rpg_mul, mixer.rpg_div, |
---|
| 776 | 100.*(float)mixer.rpg_mul/((float)mixer.rpg_div) |
---|
[3529] | 777 | #ifdef ROAR_HAVE_LIBM |
---|
[3531] | 778 | , 20*log10f((float)mixer.rpg_mul/(float)mixer.rpg_div) |
---|
[3529] | 779 | #endif |
---|
[3531] | 780 | ); |
---|
| 781 | } |
---|
[3529] | 782 | |
---|
[25] | 783 | for (i = 0; i < channels; i++) |
---|
[3529] | 784 | printf("Mixer volume chan %2i : %i/%i (%.2f%%" _DB ")\n", i, mixer.mixer[i], mixer.scale, |
---|
| 785 | (float)mixer.mixer[i]/fs |
---|
[2916] | 786 | #ifdef ROAR_HAVE_LIBM |
---|
[3529] | 787 | , 20*log10f((float)mixer.mixer[i]/(float)mixer.scale) |
---|
[2916] | 788 | #endif |
---|
| 789 | ); |
---|
[25] | 790 | |
---|
| 791 | return 0; |
---|
| 792 | } |
---|
[0] | 793 | |
---|
[3530] | 794 | static unsigned int set_mixer_parse_volume (char * k, int len, uint16_t scale) { |
---|
| 795 | float fs = scale; |
---|
| 796 | |
---|
[2916] | 797 | switch (k[len - 1]) { |
---|
| 798 | case '%': |
---|
| 799 | k[len - 1] = 0; |
---|
[3530] | 800 | return (atof(k)*fs)/100.; |
---|
[2916] | 801 | break; |
---|
| 802 | #ifdef ROAR_HAVE_LIBM |
---|
| 803 | case 'b': |
---|
| 804 | case 'B': |
---|
| 805 | // TODO: can we hanle the error better? |
---|
| 806 | if ( len < 2 ) |
---|
| 807 | return 0; |
---|
| 808 | |
---|
| 809 | k[len - 2] = 0; |
---|
[3530] | 810 | return powf(10, atof(k)/20.f)*fs; |
---|
[2916] | 811 | break; |
---|
| 812 | #endif |
---|
| 813 | } |
---|
| 814 | |
---|
| 815 | return atoi(k); |
---|
| 816 | } |
---|
| 817 | |
---|
[85] | 818 | int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) { |
---|
[3530] | 819 | uint16_t scale = 65535; |
---|
[85] | 820 | int chans = 0; |
---|
| 821 | int id; |
---|
| 822 | int i; |
---|
| 823 | int len; |
---|
| 824 | int old_chans; |
---|
| 825 | char * k; |
---|
| 826 | struct roar_mixer_settings mixer; |
---|
| 827 | struct roar_mixer_settings old_mixer; |
---|
[4740] | 828 | int mode = ROAR_SET_VOL_ALL; |
---|
[85] | 829 | |
---|
| 830 | if (*cur + 2 > max) |
---|
| 831 | return -1; |
---|
| 832 | |
---|
| 833 | id = atoi(arg[++(*cur)]); |
---|
| 834 | |
---|
| 835 | k = arg[++(*cur)]; |
---|
| 836 | |
---|
[3530] | 837 | if ( !strcmp(arg[*cur + 1], "scale") ) { |
---|
| 838 | (*cur)++; // 'scale' |
---|
[3559] | 839 | (*cur)++; |
---|
| 840 | scale = set_mixer_parse_volume(arg[*cur], strlen(arg[*cur]), 65535); |
---|
[3530] | 841 | } |
---|
[85] | 842 | |
---|
[4740] | 843 | mixer.scale = scale; |
---|
[85] | 844 | |
---|
[4740] | 845 | if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) { |
---|
| 846 | fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", id); |
---|
| 847 | return -1; |
---|
| 848 | } |
---|
[85] | 849 | |
---|
[4740] | 850 | if ( strcmp(k, "mono") == 0 ) { |
---|
| 851 | chans = 1; |
---|
| 852 | mode = ROAR_SET_VOL_UNMAPPED; |
---|
| 853 | } else if ( strcmp(k, "stereo") == 0 ) { |
---|
| 854 | chans = 2; |
---|
| 855 | mode = ROAR_SET_VOL_UNMAPPED; |
---|
| 856 | } else { |
---|
| 857 | chans = atoi(k); |
---|
| 858 | } |
---|
[1203] | 859 | |
---|
[4740] | 860 | // ensure most simple mode: |
---|
| 861 | if ( old_chans == chans && mode == ROAR_SET_VOL_UNMAPPED ) |
---|
| 862 | mode = ROAR_SET_VOL_ALL; |
---|
[1203] | 863 | |
---|
[4740] | 864 | if ( *cur + chans > max ) |
---|
| 865 | return -1; |
---|
[1203] | 866 | |
---|
[4740] | 867 | for (i = 0; i < chans; i++) { |
---|
[1203] | 868 | k = arg[++(*cur)]; |
---|
| 869 | len = strlen(k); |
---|
| 870 | |
---|
[4740] | 871 | mixer.mixer[i] = set_mixer_parse_volume(k, len, scale); |
---|
[85] | 872 | } |
---|
| 873 | |
---|
[5236] | 874 | if ( roar_set_vol(con, id, &mixer, chans, mode) == 0 ) |
---|
[4740] | 875 | return 0; |
---|
| 876 | |
---|
| 877 | // no fallback if already using ROAR_SET_VOL_ALL: |
---|
| 878 | if ( mode == ROAR_SET_VOL_ALL ) |
---|
| 879 | return -1; |
---|
[85] | 880 | |
---|
[4740] | 881 | if ( roar_conv_volume(&mixer, &mixer, old_chans, chans) == -1 ) |
---|
| 882 | return -1; |
---|
| 883 | |
---|
| 884 | chans = old_chans; |
---|
| 885 | mode = ROAR_SET_VOL_ALL; |
---|
| 886 | |
---|
[5236] | 887 | if ( roar_set_vol(con, id, &mixer, chans, mode) == 0 ) |
---|
[4740] | 888 | return 0; |
---|
| 889 | |
---|
| 890 | return -1; |
---|
[85] | 891 | } |
---|
| 892 | |
---|
[2698] | 893 | |
---|
| 894 | int newvirtual (struct roar_connection * con, char *p_s, char *d_s, char *e_s, char *r_s, char *b_s, char *c_s) { |
---|
| 895 | struct roar_stream s; |
---|
| 896 | int dir = roar_str2dir(d_s); |
---|
| 897 | int parent = atoi(p_s); |
---|
| 898 | |
---|
[2699] | 899 | ROAR_DBG("newvirtual(*): dir=%i, parent=%i", dir, parent); |
---|
| 900 | |
---|
[2698] | 901 | if ( roar_stream_new(&s, atoi(r_s), atoi(c_s), atoi(b_s), roar_str2codec(e_s)) == -1 ) |
---|
| 902 | return -1; |
---|
| 903 | |
---|
| 904 | return roar_simple_connect_virtual(con, &s, parent, dir); |
---|
| 905 | } |
---|
| 906 | |
---|
[99] | 907 | int set_meta (struct roar_connection * con, int id, char * mode, char * type, char * val) { |
---|
| 908 | struct roar_meta meta; |
---|
| 909 | struct roar_stream s; |
---|
| 910 | int mode_i = ROAR_META_MODE_SET; |
---|
| 911 | |
---|
[3072] | 912 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 913 | return -1; |
---|
[99] | 914 | |
---|
[106] | 915 | // printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val); |
---|
[99] | 916 | |
---|
| 917 | if ( strcmp(mode, "add") == 0 ) { |
---|
| 918 | mode_i = ROAR_META_MODE_ADD; |
---|
| 919 | } |
---|
| 920 | |
---|
[109] | 921 | meta.type = roar_meta_inttype(type); |
---|
[106] | 922 | meta.value = val; |
---|
| 923 | meta.key[0] = 0; |
---|
[99] | 924 | |
---|
[109] | 925 | if ( meta.type == -1 ) { |
---|
| 926 | fprintf(stderr, "Error: unknown type: %s\n", type); |
---|
| 927 | return -1; |
---|
| 928 | } |
---|
| 929 | |
---|
[106] | 930 | // printf("D: type=%i, mode=%i\n", meta.type, mode_i); |
---|
[99] | 931 | |
---|
[1127] | 932 | if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 ) |
---|
| 933 | return -1; |
---|
| 934 | |
---|
| 935 | meta.type = ROAR_META_TYPE_NONE; |
---|
| 936 | meta.value = NULL; |
---|
| 937 | |
---|
| 938 | return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta); |
---|
[99] | 939 | } |
---|
| 940 | |
---|
[1126] | 941 | int load_meta (struct roar_connection * con, int id, char * file) { |
---|
| 942 | struct roar_meta meta; |
---|
| 943 | struct roar_stream s; |
---|
| 944 | int mode_i = ROAR_META_MODE_SET; |
---|
| 945 | FILE * in; |
---|
| 946 | char lion[1024]; |
---|
| 947 | char * v; |
---|
| 948 | |
---|
[3072] | 949 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 950 | return -1; |
---|
[1126] | 951 | |
---|
| 952 | if ( (in = fopen(file, "r")) == NULL ) |
---|
| 953 | return -1; |
---|
| 954 | |
---|
| 955 | while (fgets(lion, 1024, in) != NULL) { |
---|
| 956 | if ( (v = strtok(lion, "\r\n")) != NULL ) |
---|
| 957 | if ( (v = strtok(NULL, "\r\n")) != NULL ) |
---|
| 958 | *(v-1) = 0; |
---|
| 959 | |
---|
| 960 | if ( (v = strstr(lion, "=")) == NULL ) { |
---|
| 961 | fprintf(stderr, "Error: can not parse meta data lion: %s\n", lion); |
---|
| 962 | continue; |
---|
| 963 | } |
---|
| 964 | |
---|
| 965 | *v++ = 0; |
---|
| 966 | |
---|
| 967 | meta.type = roar_meta_inttype(lion); |
---|
| 968 | meta.value = v; |
---|
| 969 | meta.key[0] = 0; |
---|
| 970 | |
---|
| 971 | if ( meta.type == -1 ) { |
---|
| 972 | fprintf(stderr, "Error: unknown type: %s\n", lion); |
---|
| 973 | continue; |
---|
| 974 | } |
---|
| 975 | |
---|
[4014] | 976 | if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 ) { |
---|
| 977 | fclose(in); |
---|
[1126] | 978 | return -1; |
---|
[4014] | 979 | } |
---|
[1126] | 980 | } |
---|
| 981 | |
---|
| 982 | fclose(in); |
---|
| 983 | |
---|
| 984 | meta.type = ROAR_META_TYPE_NONE; |
---|
| 985 | meta.value = NULL; |
---|
| 986 | |
---|
| 987 | return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta); |
---|
| 988 | } |
---|
| 989 | |
---|
[106] | 990 | int show_meta_type (struct roar_connection * con, int id, char * type) { |
---|
| 991 | struct roar_meta meta; |
---|
| 992 | struct roar_stream s; |
---|
| 993 | |
---|
[3072] | 994 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 995 | return -1; |
---|
[106] | 996 | |
---|
[109] | 997 | meta.type = roar_meta_inttype(type); |
---|
| 998 | |
---|
| 999 | if ( meta.type == -1 ) { |
---|
| 1000 | fprintf(stderr, "Error: unknown type: %s\n", type); |
---|
| 1001 | return -1; |
---|
| 1002 | } |
---|
[106] | 1003 | |
---|
| 1004 | if ( roar_stream_meta_get(con, &s, &meta) == -1 ) |
---|
| 1005 | return -1; |
---|
| 1006 | |
---|
[112] | 1007 | printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value); |
---|
[106] | 1008 | |
---|
| 1009 | roar_meta_free(&meta); |
---|
| 1010 | |
---|
| 1011 | return 0; |
---|
| 1012 | } |
---|
| 1013 | |
---|
[112] | 1014 | int show_meta_all (struct roar_connection * con, int id) { |
---|
| 1015 | struct roar_stream s; |
---|
| 1016 | int types[ROAR_META_MAX_PER_STREAM]; |
---|
| 1017 | int i; |
---|
| 1018 | int len; |
---|
| 1019 | |
---|
[3072] | 1020 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 1021 | return -1; |
---|
[112] | 1022 | |
---|
| 1023 | if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 ) |
---|
| 1024 | return -1; |
---|
| 1025 | |
---|
| 1026 | for (i = 0; i < len; i++) |
---|
| 1027 | show_meta_type(con, id, roar_meta_strtype(types[i])); |
---|
| 1028 | |
---|
| 1029 | return 0; |
---|
| 1030 | } |
---|
| 1031 | |
---|
[1126] | 1032 | int save_meta (struct roar_connection * con, int id, char * file) { |
---|
| 1033 | struct roar_stream s; |
---|
| 1034 | struct roar_meta meta; |
---|
| 1035 | int types[ROAR_META_MAX_PER_STREAM]; |
---|
| 1036 | int i; |
---|
| 1037 | int len; |
---|
| 1038 | FILE * out; |
---|
| 1039 | |
---|
[3072] | 1040 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 1041 | return -1; |
---|
[1126] | 1042 | |
---|
[4014] | 1043 | if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 ) |
---|
[1126] | 1044 | return -1; |
---|
| 1045 | |
---|
[4014] | 1046 | if ( (out = fopen(file, "w")) == NULL ) |
---|
[1126] | 1047 | return -1; |
---|
| 1048 | |
---|
| 1049 | for (i = 0; i < len; i++) { |
---|
| 1050 | /* |
---|
| 1051 | show_meta_type(con, id, roar_meta_strtype(types[i])); |
---|
| 1052 | */ |
---|
| 1053 | meta.type = types[i]; |
---|
| 1054 | |
---|
| 1055 | if ( roar_stream_meta_get(con, &s, &meta) == -1 ) |
---|
| 1056 | continue; |
---|
| 1057 | |
---|
| 1058 | // printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value); |
---|
| 1059 | |
---|
| 1060 | fprintf(out, "%s=%s\n", roar_meta_strtype(meta.type), meta.value); |
---|
| 1061 | |
---|
| 1062 | roar_meta_free(&meta); |
---|
| 1063 | } |
---|
| 1064 | |
---|
| 1065 | fclose(out); |
---|
| 1066 | |
---|
| 1067 | return 0; |
---|
| 1068 | } |
---|
| 1069 | |
---|
[4552] | 1070 | int set_flags (struct roar_connection * con, int id, int action, char * flags) { |
---|
| 1071 | uint32_t f = ROAR_FLAG_NONE; |
---|
[1043] | 1072 | char * c; |
---|
| 1073 | struct roar_stream s[1]; |
---|
| 1074 | |
---|
[3072] | 1075 | if ( roar_stream_new_by_id(s, id) == -1 ) |
---|
| 1076 | return -1; |
---|
[1043] | 1077 | |
---|
| 1078 | c = strtok(flags, ","); |
---|
| 1079 | while (c != NULL) { |
---|
| 1080 | if ( !strcmp(c, "meta") ) { |
---|
| 1081 | f |= ROAR_FLAG_META; |
---|
| 1082 | } else if ( !strcmp(c, "primary") ) { |
---|
| 1083 | f |= ROAR_FLAG_PRIMARY; |
---|
[1116] | 1084 | } else if ( !strcmp(c, "sync") ) { |
---|
| 1085 | f |= ROAR_FLAG_SYNC; |
---|
[1219] | 1086 | } else if ( !strcmp(c, "cleanmeta") ) { |
---|
| 1087 | f |= ROAR_FLAG_CLEANMETA; |
---|
[1585] | 1088 | } else if ( !strcmp(c, "hwmixer") ) { |
---|
| 1089 | f |= ROAR_FLAG_HWMIXER; |
---|
| 1090 | } else if ( !strcmp(c, "pause") ) { |
---|
| 1091 | f |= ROAR_FLAG_PAUSE; |
---|
[1883] | 1092 | } else if ( !strcmp(c, "mute") ) { |
---|
| 1093 | f |= ROAR_FLAG_MUTE; |
---|
[1926] | 1094 | } else if ( !strcmp(c, "mmap") ) { |
---|
| 1095 | f |= ROAR_FLAG_MMAP; |
---|
[2154] | 1096 | } else if ( !strcmp(c, "antiecho") ) { |
---|
| 1097 | f |= ROAR_FLAG_ANTIECHO; |
---|
[2412] | 1098 | } else if ( !strcmp(c, "recsource") ) { |
---|
| 1099 | f |= ROAR_FLAG_RECSOURCE; |
---|
| 1100 | } else if ( !strcmp(c, "passmixer") ) { |
---|
| 1101 | f |= ROAR_FLAG_PASSMIXER; |
---|
[2627] | 1102 | } else if ( !strcmp(c, "virtual") ) { |
---|
| 1103 | f |= ROAR_FLAG_VIRTUAL; |
---|
[2814] | 1104 | } else if ( !strcmp(c, "prethru") ) { |
---|
| 1105 | f |= ROAR_FLAG_PRETHRU; |
---|
[2953] | 1106 | } else if ( !strcmp(c, "immutable") ) { |
---|
| 1107 | f |= ROAR_FLAG_IMMUTABLE; |
---|
| 1108 | } else if ( !strcmp(c, "enhance") ) { |
---|
| 1109 | f |= ROAR_FLAG_ENHANCE; |
---|
[4536] | 1110 | } else if ( !strcmp(c, "singlesink") ) { |
---|
| 1111 | f |= ROAR_FLAG_SINGLESINK; |
---|
[1043] | 1112 | } else { |
---|
| 1113 | fprintf(stderr, "Error: unknown flag: %s\n", c); |
---|
| 1114 | return -1; |
---|
| 1115 | } |
---|
| 1116 | |
---|
| 1117 | c = strtok(NULL, ","); |
---|
| 1118 | } |
---|
| 1119 | |
---|
[5238] | 1120 | return roar_stream_set_flags(con, s, f, action); |
---|
[1043] | 1121 | } |
---|
| 1122 | |
---|
[4933] | 1123 | int set_role (struct roar_connection * con, int id, int role) { |
---|
| 1124 | struct roar_stream s; |
---|
| 1125 | |
---|
| 1126 | if ( id == -1 ) |
---|
| 1127 | return -1; |
---|
| 1128 | |
---|
| 1129 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 1130 | return -1; |
---|
| 1131 | |
---|
| 1132 | if ( roar_stream_set_role(con, &s, role) == -1 ) |
---|
| 1133 | return -1; |
---|
| 1134 | |
---|
| 1135 | return 0; |
---|
| 1136 | } |
---|
| 1137 | |
---|
[3942] | 1138 | int show_aiprofile (const char * profile) { |
---|
| 1139 | struct roar_audio_info info; |
---|
[4882] | 1140 | const char * mime; |
---|
[3942] | 1141 | |
---|
| 1142 | if ( roar_profile2info(&info, profile) == -1 ) { |
---|
| 1143 | fprintf(stderr, "Error: unknown profile: %s\n", profile); |
---|
| 1144 | return -1; |
---|
| 1145 | } |
---|
| 1146 | |
---|
[4882] | 1147 | mime = roar_codec2mime(info.codec); |
---|
| 1148 | |
---|
[3942] | 1149 | printf("Profile Name : %s\n", profile); |
---|
[3944] | 1150 | |
---|
| 1151 | if ( info.rate ) |
---|
| 1152 | printf("Profile sample rate : %i\n", info.rate); |
---|
| 1153 | if ( info.bits ) |
---|
| 1154 | printf("Profile bits : %i\n", info.bits); |
---|
| 1155 | if ( info.channels ) |
---|
| 1156 | printf("Profile channels : %i\n", info.channels); |
---|
| 1157 | |
---|
[4882] | 1158 | printf("Profile codec : %2i (%s%s%s%s)\n", info.codec, roar_codec2str(info.codec), |
---|
| 1159 | info.codec == ROAR_CODEC_DEFAULT ? " native" : "", |
---|
| 1160 | mime == NULL ? "" : " mimetype:", |
---|
| 1161 | mime == NULL ? "" : mime); |
---|
[3942] | 1162 | |
---|
| 1163 | return 0; |
---|
| 1164 | } |
---|
| 1165 | |
---|
| 1166 | int list_aiprofiles (void) { |
---|
| 1167 | const char * list[1024]; |
---|
| 1168 | ssize_t ret; |
---|
| 1169 | ssize_t i; |
---|
| 1170 | |
---|
| 1171 | ret = roar_profiles_list(list, 1024, 0); |
---|
| 1172 | |
---|
| 1173 | if ( ret == -1 ) { |
---|
| 1174 | fprintf(stderr, "Error: can not read list of profiles\n"); |
---|
| 1175 | return -1; |
---|
| 1176 | } |
---|
| 1177 | |
---|
| 1178 | for (i = 0; i < ret; i++) { |
---|
| 1179 | printf("profile %lli:\n", (long long signed int)i); |
---|
| 1180 | show_aiprofile(list[i]); |
---|
| 1181 | } |
---|
| 1182 | |
---|
| 1183 | return 0; |
---|
| 1184 | } |
---|
| 1185 | |
---|
[0] | 1186 | int main (int argc, char * argv[]) { |
---|
| 1187 | struct roar_connection con; |
---|
| 1188 | char * server = NULL; |
---|
| 1189 | char * k = NULL; |
---|
| 1190 | int i; |
---|
| 1191 | int t = 0; |
---|
| 1192 | |
---|
| 1193 | for (i = 1; i < argc; i++) { |
---|
| 1194 | k = argv[i]; |
---|
| 1195 | |
---|
| 1196 | if ( strcmp(k, "--server") == 0 ) { |
---|
[58] | 1197 | server = argv[++i]; |
---|
[963] | 1198 | } else if ( strcmp(k, "-v") == 0 || strcmp(k, "--verbose") == 0 ) { |
---|
| 1199 | g_verbose++; |
---|
[0] | 1200 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
| 1201 | usage(); |
---|
| 1202 | return 0; |
---|
[3960] | 1203 | } else if ( strcmp(k, "--list-aiprofiles") == 0 ) { |
---|
| 1204 | list_aiprofiles(); |
---|
| 1205 | return 0; |
---|
[5149] | 1206 | } else if ( strcmp(k, "--list-libstandards") == 0 ) { |
---|
| 1207 | lib_standards(); |
---|
| 1208 | return 0; |
---|
[4413] | 1209 | } else if ( strcmp(k, "--enum-servers") == 0 ) { |
---|
| 1210 | enum_servers(); |
---|
| 1211 | return 0; |
---|
[5187] | 1212 | } else if ( strcmp(k, "--hash-password") == 0 ) { |
---|
| 1213 | hash_password(); |
---|
| 1214 | return 0; |
---|
[0] | 1215 | } else if ( *k == '-' ) { |
---|
| 1216 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 1217 | usage(); |
---|
| 1218 | return 1; |
---|
| 1219 | } else { |
---|
| 1220 | break; |
---|
| 1221 | } |
---|
| 1222 | } |
---|
| 1223 | |
---|
| 1224 | // connect |
---|
| 1225 | |
---|
[3510] | 1226 | if ( roar_simple_connect(&con, server, "roarctl") == -1 ) { |
---|
[5185] | 1227 | fprintf(stderr, "Error: Can not connect to server: %s: %s(%i)\n", |
---|
| 1228 | server == NULL ? "(default)" : server, roar_vs_strerr(roar_error), roar_error); |
---|
[0] | 1229 | return 1; |
---|
| 1230 | } |
---|
| 1231 | |
---|
| 1232 | if ( i == argc ) { |
---|
| 1233 | fprintf(stderr, "Error: No Commands given\n"); |
---|
| 1234 | return 0; // this is not a fatal error... |
---|
| 1235 | } |
---|
| 1236 | |
---|
| 1237 | for (; i < argc; i++) { |
---|
| 1238 | k = argv[i]; |
---|
| 1239 | // cmd is in k |
---|
| 1240 | |
---|
| 1241 | printf("--- [ %s ] ---\n", k); |
---|
| 1242 | |
---|
| 1243 | if ( !strcmp(k, "help") ) { |
---|
| 1244 | usage(); |
---|
| 1245 | |
---|
[1202] | 1246 | } else if ( !strcmp(k, "sleep") ) { |
---|
[4914] | 1247 | roar_sleep(atoi(argv[++i])); |
---|
[0] | 1248 | |
---|
[1630] | 1249 | } else if ( !strcmp(k, "ping") ) { |
---|
[1781] | 1250 | #ifdef ROAR_HAVE_GETTIMEOFDAY |
---|
[1630] | 1251 | if ( ping(&con, atoi(argv[++i])) == -1 ) { |
---|
| 1252 | fprintf(stderr, "Error: can not ping\n"); |
---|
| 1253 | } |
---|
[1781] | 1254 | #else |
---|
| 1255 | fprintf(stderr, "Error: ping not supported.\n"); |
---|
| 1256 | i++; |
---|
| 1257 | #endif |
---|
[1630] | 1258 | |
---|
[0] | 1259 | } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) { |
---|
| 1260 | if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) { |
---|
| 1261 | fprintf(stderr, "Error: can not set mode to standby\n"); |
---|
| 1262 | } else { |
---|
| 1263 | printf("going into standby\n"); |
---|
| 1264 | } |
---|
| 1265 | } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) { |
---|
| 1266 | if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) { |
---|
| 1267 | fprintf(stderr, "Error: can not set mode to active\n"); |
---|
| 1268 | } else { |
---|
| 1269 | printf("going into active mode\n"); |
---|
| 1270 | } |
---|
| 1271 | |
---|
| 1272 | } else if ( !strcmp(k, "exit") ) { |
---|
[4047] | 1273 | if ( roar_terminate(&con, 0) == -1 ) { |
---|
[0] | 1274 | fprintf(stderr, "Error: can not quit server\n"); |
---|
| 1275 | } else { |
---|
| 1276 | printf("Server quited\n"); |
---|
| 1277 | break; |
---|
| 1278 | } |
---|
[577] | 1279 | } else if ( !strcmp(k, "terminate") ) { |
---|
| 1280 | if ( roar_terminate(&con, 1) == -1 ) { |
---|
| 1281 | fprintf(stderr, "Error: can not terminate server\n"); |
---|
| 1282 | } else { |
---|
| 1283 | printf("Server got asked to quited\n"); |
---|
| 1284 | break; |
---|
| 1285 | } |
---|
[0] | 1286 | |
---|
| 1287 | } else if ( !strcmp(k, "standbymode") ) { |
---|
| 1288 | t = roar_get_standby(&con); |
---|
| 1289 | if ( t == -1 ) { |
---|
| 1290 | fprintf(stderr, "Error: can not get stanby mode\n"); |
---|
| 1291 | } else if ( t == ROAR_STANDBY_ACTIVE ) { |
---|
| 1292 | printf("Server is in standby\n"); |
---|
| 1293 | } else if ( t == ROAR_STANDBY_INACTIVE ) { |
---|
| 1294 | printf("Server is active\n"); |
---|
| 1295 | } else { |
---|
| 1296 | fprintf(stderr, "Error: unknown standby mode: %i\n", t); |
---|
| 1297 | } |
---|
| 1298 | |
---|
[1162] | 1299 | } else if ( !strcmp(k, "whoami") ) { |
---|
| 1300 | printf("My client ID is: %i\n", roar_get_clientid(&con)); |
---|
[5384] | 1301 | } else if ( !strcmp(k, "beep") ) { |
---|
| 1302 | roar_beep(&con, NULL); |
---|
[4432] | 1303 | } else if ( !strcmp(k, "serverinfo") ) { |
---|
| 1304 | server_info(&con); |
---|
[5031] | 1305 | } else if ( !strcmp(k, "servertime") ) { |
---|
| 1306 | server_time(&con); |
---|
[0] | 1307 | } else if ( !strcmp(k, "serveroinfo") ) { |
---|
[4614] | 1308 | server_oinfo(&con, -1); |
---|
| 1309 | } else if ( !strcmp(k, "serveroinfo2") ) { |
---|
| 1310 | t = roar_str2dir(argv[++i]); |
---|
| 1311 | if ( t == -1 ) { |
---|
| 1312 | fprintf(stderr, "Error: unknown stream direction: %s\n", argv[i]); |
---|
| 1313 | } else { |
---|
| 1314 | server_oinfo(&con, t); |
---|
| 1315 | } |
---|
[4501] | 1316 | } else if ( !strcmp(k, "serverstandards") ) { |
---|
| 1317 | server_standards(&con); |
---|
[5149] | 1318 | } else if ( !strcmp(k, "libstandards") ) { |
---|
| 1319 | lib_standards(); |
---|
[0] | 1320 | } else if ( !strcmp(k, "listclients") ) { |
---|
| 1321 | list_clients(&con); |
---|
[4818] | 1322 | } else if ( !strcmp(k, "clientinfo") ) { |
---|
| 1323 | display_client(&con, atoi(argv[++i])); |
---|
[0] | 1324 | } else if ( !strcmp(k, "liststreams") ) { |
---|
| 1325 | list_streams(&con); |
---|
[4818] | 1326 | } else if ( !strcmp(k, "streaminfo") ) { |
---|
| 1327 | display_stream(&con, atoi(argv[++i])); |
---|
[0] | 1328 | } else if ( !strcmp(k, "allinfo") ) { |
---|
[5379] | 1329 | server_info(&con); |
---|
| 1330 | printf("\n"); |
---|
| 1331 | server_time(&con); |
---|
| 1332 | printf("\n"); |
---|
[5383] | 1333 | server_standards(&con); |
---|
[5379] | 1334 | printf("\n"); |
---|
[4614] | 1335 | server_oinfo(&con, -1); |
---|
[0] | 1336 | printf("\n"); |
---|
| 1337 | list_clients(&con); |
---|
| 1338 | printf("\n"); |
---|
| 1339 | list_streams(&con); |
---|
| 1340 | |
---|
| 1341 | } else if ( !strcmp(k, "kick") ) { |
---|
[4328] | 1342 | t = roar_str2ot((k = argv[++i])); |
---|
| 1343 | if ( t == -1 ) { |
---|
[0] | 1344 | fprintf(stderr, "Error: unknown type: %s\n", k); |
---|
| 1345 | continue; |
---|
| 1346 | } |
---|
| 1347 | //t = atoi(argv[i++]); |
---|
| 1348 | if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) { |
---|
| 1349 | fprintf(stderr, "Error: can not kick %s\n", k); |
---|
| 1350 | } else { |
---|
| 1351 | printf("%s kicked\n", k); |
---|
| 1352 | } |
---|
| 1353 | |
---|
[2698] | 1354 | } else if ( !strcmp(k, "newvirtual") ) { |
---|
[2699] | 1355 | if ( newvirtual(&con, argv[i+1], argv[i+2], argv[i+3], argv[i+4], argv[i+5], argv[i+6]) == -1 ) { |
---|
[2698] | 1356 | fprintf(stderr, "Error: can not create new virtual stream\n"); |
---|
| 1357 | } else { |
---|
| 1358 | printf("virtual stream created\n"); |
---|
| 1359 | } |
---|
[2699] | 1360 | i += 6; |
---|
[2698] | 1361 | |
---|
[85] | 1362 | } else if ( !strcmp(k, "volume") ) { |
---|
| 1363 | if ( set_mixer(&con, &i, argc, argv) == -1 ) { |
---|
| 1364 | fprintf(stderr, "Error: can not set volume\n"); |
---|
| 1365 | } else { |
---|
| 1366 | printf("volume changed\n"); |
---|
| 1367 | } |
---|
| 1368 | |
---|
[1043] | 1369 | } else if ( !strcmp(k, "flag") ) { |
---|
| 1370 | i++; |
---|
| 1371 | if ( set_flags(&con, atoi(argv[i]), ROAR_SET_FLAG, argv[i+1]) == -1 ) { |
---|
| 1372 | fprintf(stderr, "Error: can not set flags\n"); |
---|
| 1373 | } else { |
---|
| 1374 | printf("flags changed\n"); |
---|
| 1375 | } |
---|
| 1376 | i++; |
---|
| 1377 | } else if ( !strcmp(k, "unflag") ) { |
---|
| 1378 | i++; |
---|
| 1379 | if ( set_flags(&con, atoi(argv[i]), ROAR_RESET_FLAG, argv[i+1]) == -1 ) { |
---|
| 1380 | fprintf(stderr, "Error: can not reset flags\n"); |
---|
| 1381 | } else { |
---|
| 1382 | printf("flags changed\n"); |
---|
| 1383 | } |
---|
| 1384 | i++; |
---|
[4552] | 1385 | } else if ( !strcmp(k, "toggleflag") ) { |
---|
| 1386 | i++; |
---|
| 1387 | if ( set_flags(&con, atoi(argv[i]), ROAR_TOGGLE_FLAG, argv[i+1]) == -1 ) { |
---|
| 1388 | fprintf(stderr, "Error: can not toggle flags\n"); |
---|
| 1389 | } else { |
---|
| 1390 | printf("flags changed\n"); |
---|
| 1391 | } |
---|
| 1392 | i++; |
---|
| 1393 | } else if ( !strcmp(k, "protectflag") ) { |
---|
| 1394 | i++; |
---|
| 1395 | if ( set_flags(&con, atoi(argv[i]), ROAR_NOOP_FLAG|ROAR_PROTECT_FLAG, argv[i+1]) == -1 ) { |
---|
| 1396 | fprintf(stderr, "Error: can not protect flags\n"); |
---|
| 1397 | } else { |
---|
| 1398 | printf("flags protected\n"); |
---|
| 1399 | } |
---|
| 1400 | i++; |
---|
[4933] | 1401 | |
---|
| 1402 | } else if ( !strcmp(k, "role") ) { |
---|
| 1403 | i++; |
---|
| 1404 | if ( set_role(&con, atoi(argv[i]), roar_str2role(argv[i+1])) == -1 ) { |
---|
| 1405 | fprintf(stderr, "Error: can not set stream role\n"); |
---|
| 1406 | } else { |
---|
[4935] | 1407 | printf("stream role set\n"); |
---|
[4933] | 1408 | } |
---|
| 1409 | i++; |
---|
| 1410 | |
---|
[106] | 1411 | } else if ( !strcmp(k, "metaset") ) { |
---|
[99] | 1412 | i++; |
---|
| 1413 | if ( set_meta(&con, atoi(argv[i]), argv[i+1], argv[i+2], argv[i+3]) == -1 ) { |
---|
| 1414 | fprintf(stderr, "Error: can not set meta data\n"); |
---|
| 1415 | } else { |
---|
| 1416 | printf("meta data changed\n"); |
---|
| 1417 | } |
---|
| 1418 | i += 3; |
---|
[106] | 1419 | } else if ( !strcmp(k, "metaget") ) { |
---|
| 1420 | i++; |
---|
| 1421 | if ( show_meta_type(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
| 1422 | fprintf(stderr, "Error: can not get meta data\n"); |
---|
| 1423 | } |
---|
| 1424 | i++; |
---|
[1126] | 1425 | } else if ( !strcmp(k, "metasave") ) { |
---|
| 1426 | i++; |
---|
| 1427 | if ( save_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
| 1428 | fprintf(stderr, "Error: can not get meta data\n"); |
---|
| 1429 | } else { |
---|
| 1430 | printf("meta data saved\n"); |
---|
| 1431 | } |
---|
| 1432 | i++; |
---|
| 1433 | } else if ( !strcmp(k, "metaload") ) { |
---|
| 1434 | i++; |
---|
| 1435 | if ( load_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
| 1436 | fprintf(stderr, "Error: can not set meta data\n"); |
---|
| 1437 | } else { |
---|
| 1438 | printf("meta data saved\n"); |
---|
| 1439 | } |
---|
| 1440 | i++; |
---|
[99] | 1441 | |
---|
[3942] | 1442 | |
---|
[3961] | 1443 | } else if ( !strcmp(k, "listaiprofiles") || !strcmp(k, "listprofiles") ) { |
---|
[3942] | 1444 | if ( list_aiprofiles() == -1 ) { |
---|
| 1445 | fprintf(stderr, "Error: can not list profiles\n"); |
---|
| 1446 | } |
---|
[3961] | 1447 | } else if ( !strcmp(k, "aiprofileget") || !strcmp(k, "profileget") ) { |
---|
[3942] | 1448 | i++; |
---|
| 1449 | if ( show_aiprofile(argv[i]) == -1 ) { |
---|
| 1450 | fprintf(stderr, "Error: can not get profile data\n"); |
---|
| 1451 | } |
---|
[0] | 1452 | } else { |
---|
| 1453 | fprintf(stderr, "Error: invalid command: %s\n", k); |
---|
| 1454 | } |
---|
| 1455 | |
---|
| 1456 | } |
---|
| 1457 | |
---|
| 1458 | roar_disconnect(&con); |
---|
| 1459 | |
---|
| 1460 | return 0; |
---|
| 1461 | } |
---|
| 1462 | |
---|
| 1463 | //ll |
---|