[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); |
---|
[5386] | 403 | if ( g_verbose > 1 && s.pos != (uint32_t)-1 ) { |
---|
| 404 | if ( s.info.rate && s.info.channels ) { |
---|
| 405 | printf("Server Position : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels)); |
---|
| 406 | } else { |
---|
| 407 | printf("Server Position : %lu S\n", (unsigned long int) s.pos); |
---|
| 408 | } |
---|
| 409 | } |
---|
[0] | 410 | } |
---|
| 411 | |
---|
[5149] | 412 | static void print_stds (const struct roar_stds * stds) { |
---|
[4501] | 413 | size_t i; |
---|
| 414 | int vendor, standard, version; |
---|
[4503] | 415 | char numbuf[2][8]; |
---|
| 416 | const char * vendor_name; |
---|
[4501] | 417 | |
---|
| 418 | for (i = 0; i < stds->stds_len; i++) { |
---|
| 419 | vendor = ROAR_STD_VENDOR(stds->stds[i]); |
---|
| 420 | standard = ROAR_STD_STD(stds->stds[i]); |
---|
| 421 | version = ROAR_STD_VERSION(stds->stds[i]); |
---|
[4503] | 422 | |
---|
| 423 | if ( (vendor_name = roar_stds_vendor2str(vendor)) == NULL ) { |
---|
| 424 | snprintf(numbuf[0], sizeof(numbuf[0]), "%i", vendor); |
---|
| 425 | numbuf[0][sizeof(numbuf[0])-1] = 0; |
---|
| 426 | vendor_name = numbuf[0]; |
---|
| 427 | } |
---|
| 428 | |
---|
| 429 | if ( version == 0 ) { |
---|
| 430 | numbuf[1][0] = 0; |
---|
| 431 | } else { |
---|
| 432 | snprintf(numbuf[1], sizeof(numbuf[1]), "-%i", version); |
---|
| 433 | numbuf[1][sizeof(numbuf[1])-1] = 0; |
---|
| 434 | } |
---|
| 435 | |
---|
| 436 | printf("Server standard : %s-%i%s\n", vendor_name, standard, numbuf[1]); |
---|
[4501] | 437 | } |
---|
| 438 | } |
---|
| 439 | |
---|
[5149] | 440 | void server_standards (struct roar_connection * con) { |
---|
| 441 | struct roar_stds * stds; |
---|
| 442 | |
---|
| 443 | if ( roar_caps_stds(con, &stds, NULL, -1) == -1 ) { |
---|
| 444 | fprintf(stderr, "Error: can not get server standards\n"); |
---|
| 445 | return; |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | print_stds(stds); |
---|
| 449 | |
---|
| 450 | roar_stds_free(stds); |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | void lib_standards (void) { |
---|
| 454 | print_stds(libroar_libstds()); |
---|
| 455 | } |
---|
| 456 | |
---|
[449] | 457 | const char * proc_name (pid_t pid) { |
---|
| 458 | static char ret[80] = "?"; |
---|
| 459 | #ifdef __linux__ |
---|
| 460 | char file[80], buf[80], *r; |
---|
| 461 | int i; |
---|
| 462 | |
---|
[4047] | 463 | snprintf(file, sizeof(file)-1, "/proc/%i/exe", pid); |
---|
| 464 | file[sizeof(file)-1] = 0; |
---|
[449] | 465 | |
---|
| 466 | ret[0] = '?'; |
---|
| 467 | ret[1] = 0; |
---|
| 468 | |
---|
[4047] | 469 | if ( (i = readlink(file, buf, sizeof(buf)-1)) != -1 ) { |
---|
[449] | 470 | buf[i] = 0; |
---|
| 471 | if ( (r = strrchr(buf, '/')) != NULL ) { |
---|
| 472 | r++; |
---|
[4047] | 473 | if ( *r != 0 ) { |
---|
| 474 | strncpy(ret, r, sizeof(ret)-1); |
---|
| 475 | ret[sizeof(ret)-1] = 0; |
---|
| 476 | } |
---|
[449] | 477 | } |
---|
| 478 | } |
---|
[3787] | 479 | #else |
---|
| 480 | (void)pid; |
---|
[449] | 481 | #endif |
---|
| 482 | |
---|
| 483 | return ret; |
---|
| 484 | } |
---|
| 485 | |
---|
[0] | 486 | void list_clients (struct roar_connection * con) { |
---|
| 487 | int i; |
---|
| 488 | int num; |
---|
| 489 | int id[ROAR_CLIENTS_MAX]; |
---|
[2814] | 490 | |
---|
[0] | 491 | if ( (num = roar_list_clients(con, id, ROAR_CLIENTS_MAX)) == -1 ) { |
---|
| 492 | fprintf(stderr, "Error: can not get client list\n"); |
---|
| 493 | return; |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | for (i = 0; i < num; i++) { |
---|
[4818] | 497 | display_client(con, id[i]); |
---|
| 498 | } |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | void display_client (struct roar_connection * con, int id) { |
---|
| 502 | static int self_id = -1; |
---|
| 503 | static struct roar_client self_client_store; |
---|
| 504 | static struct roar_client * self_client = NULL; |
---|
| 505 | struct roar_client c; |
---|
| 506 | char tmp[80]; |
---|
| 507 | int h; |
---|
| 508 | #ifdef _POSIX_USERS |
---|
| 509 | struct group * grp = NULL; |
---|
| 510 | struct passwd * pwd = NULL; |
---|
| 511 | #endif |
---|
| 512 | |
---|
| 513 | if ( self_id == -1 ) { |
---|
| 514 | if ( (self_id = roar_get_clientid(con)) != -1 ) { |
---|
| 515 | if ( roar_get_client(con, &self_client_store, self_id) == -1 ) { |
---|
| 516 | self_id = -1; |
---|
| 517 | } else { |
---|
| 518 | self_client = &self_client_store; |
---|
| 519 | } |
---|
| 520 | } |
---|
| 521 | } |
---|
| 522 | |
---|
| 523 | printf("client %i:\n", id); |
---|
| 524 | if ( roar_get_client(con, &c, id) == -1 ) { |
---|
| 525 | fprintf(stderr, "Error: can not get client info\n"); |
---|
| 526 | return; |
---|
| 527 | } |
---|
| 528 | |
---|
| 529 | if ( c.name[0] != '\0' ) |
---|
| 530 | printf("Client name : %s\n", c.name); |
---|
| 531 | if ( roar_nnode_get_socktype(&(c.nnode)) != ROAR_SOCKET_TYPE_UNKNOWN ) { |
---|
[5005] | 532 | if ( roar_nnode_to_str(&(c.nnode), tmp, sizeof(tmp)) == 0 ) { |
---|
[4818] | 533 | printf("Client network node : %s\n", tmp); |
---|
| 534 | } |
---|
| 535 | } |
---|
| 536 | |
---|
| 537 | if ( c.pid != -1 ) { |
---|
| 538 | if ( self_id != -1 && roar_nnode_cmp(&(self_client->nnode), &(c.nnode)) == 0 ) { |
---|
| 539 | printf("Client PID : %i(%s)\n", c.pid, proc_name(c.pid)); |
---|
| 540 | } else { |
---|
| 541 | printf("Client PID : %i\n", c.pid); |
---|
| 542 | } |
---|
| 543 | } |
---|
| 544 | if ( c.uid != -1 ) { |
---|
| 545 | #ifdef _POSIX_USERS |
---|
| 546 | if ( self_id != -1 && roar_nnode_cmp(&(self_client->nnode), &(c.nnode)) == 0 ) { |
---|
| 547 | pwd = getpwuid(c.uid); |
---|
| 548 | grp = getgrgid(c.gid); |
---|
| 549 | printf("Client UID/GID : %i(%s)/%i(%s)\n", c.uid, pwd ? pwd->pw_name : "?", c.gid, grp ? grp->gr_name : "?"); |
---|
| 550 | } else { |
---|
| 551 | #else |
---|
| 552 | if ( 1 ) { |
---|
| 553 | #endif |
---|
| 554 | printf("Client UID/GID : %i/%i\n", c.uid, c.gid); |
---|
| 555 | } |
---|
| 556 | } |
---|
| 557 | |
---|
| 558 | if ( g_verbose && c.proto != ROAR_PROTO_NONE ) { |
---|
| 559 | printf("Client Protocol : %s\n", roar_proto2str(c.proto)); |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | if ( g_verbose && c.byteorder != ROAR_BYTEORDER_UNKNOWN ) { |
---|
| 563 | if ( c.byteorder == ROAR_BYTEORDER_NETWORK ) { |
---|
[5005] | 564 | roar_mm_strscpy(tmp, " (network byteorder"); |
---|
[4818] | 565 | } else { |
---|
| 566 | *tmp = 0; |
---|
[0] | 567 | } |
---|
[3845] | 568 | |
---|
[4818] | 569 | if ( c.byteorder == ROAR_BYTEORDER_NATIVE ) { |
---|
| 570 | if ( *tmp ) { |
---|
[5005] | 571 | roar_mm_strscat(tmp, ", native"); |
---|
[4818] | 572 | } else { |
---|
[5005] | 573 | roar_mm_strscpy(tmp, " (native"); |
---|
[2814] | 574 | } |
---|
| 575 | } |
---|
| 576 | |
---|
[4818] | 577 | if ( *tmp ) |
---|
[5005] | 578 | roar_mm_strscat(tmp, ")"); |
---|
[2550] | 579 | |
---|
[4818] | 580 | printf("Client Byteorder : %s%s\n", roar_byteorder2str(c.byteorder), tmp); |
---|
[0] | 581 | } |
---|
| 582 | |
---|
[4818] | 583 | if ( c.execed != -1 ) |
---|
| 584 | printf("Execed stream : %i\n", c.execed); |
---|
| 585 | |
---|
| 586 | for (h = 0; h < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; h++) |
---|
| 587 | if ( c.streams[h] != -1 ) |
---|
| 588 | printf("stream : %i\n", c.streams[h]); |
---|
[0] | 589 | } |
---|
| 590 | |
---|
| 591 | void list_streams (struct roar_connection * con) { |
---|
| 592 | int i; |
---|
| 593 | int num; |
---|
| 594 | int id[ROAR_STREAMS_MAX]; |
---|
[4818] | 595 | |
---|
| 596 | if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) { |
---|
| 597 | fprintf(stderr, "Error: can not get stream list\n"); |
---|
| 598 | return; |
---|
| 599 | } |
---|
| 600 | |
---|
| 601 | for (i = 0; i < num; i++) { |
---|
| 602 | display_stream(con, id[i]); |
---|
| 603 | } |
---|
| 604 | } |
---|
| 605 | |
---|
| 606 | void display_stream (struct roar_connection * con, int id) { |
---|
[3539] | 607 | char chanmap[ROAR_MAX_CHANNELS]; |
---|
[0] | 608 | struct roar_stream s; |
---|
[465] | 609 | struct roar_stream_info info; |
---|
[3539] | 610 | char buffer[1024]; |
---|
| 611 | char * flags = buffer; |
---|
| 612 | char * name = buffer; |
---|
[2399] | 613 | char * infotext; |
---|
[4603] | 614 | const char * mime; |
---|
[3539] | 615 | size_t len; |
---|
[0] | 616 | |
---|
[4818] | 617 | printf("stream %i:\n", id); |
---|
| 618 | if ( roar_get_stream(con, &s, id) == -1 ) { |
---|
| 619 | fprintf(stderr, "Error: can not get stream info\n"); |
---|
| 620 | return; |
---|
| 621 | } |
---|
| 622 | printf("Stream direction : %s\n", roar_dir2str(s.dir)); |
---|
[0] | 623 | |
---|
[5005] | 624 | if ( roar_stream_get_name(con, &s, name, sizeof(buffer)) == 0 ) |
---|
[4818] | 625 | printf("Stream name : %s\n", name); |
---|
| 626 | |
---|
| 627 | if ( (int)s.pos_rel_id == -1 ) { |
---|
| 628 | printf("Relativ position id : none (stream not synchronized)\n"); |
---|
| 629 | } else if ( (int)s.pos_rel_id == id ) { |
---|
| 630 | printf("Relativ position id : %i (self synchronized)\n", s.pos_rel_id); |
---|
| 631 | } else { |
---|
| 632 | printf("Relativ position id : %i (synchronized)\n", s.pos_rel_id); |
---|
| 633 | } |
---|
| 634 | if ( g_verbose > 1 && s.pos != (uint32_t)-1 ) { |
---|
| 635 | if ( s.info.rate && s.info.channels ) { |
---|
| 636 | printf("Position : %lu S (%.3fs)\n", (unsigned long int) s.pos, |
---|
| 637 | (float)s.pos/(s.info.rate*s.info.channels)); |
---|
| 638 | } else { |
---|
| 639 | printf("Position : %lu S\n", (unsigned long int) s.pos); |
---|
| 640 | } |
---|
[0] | 641 | } |
---|
| 642 | |
---|
[4818] | 643 | switch (s.dir) { |
---|
| 644 | case ROAR_DIR_MIDI_IN: |
---|
| 645 | case ROAR_DIR_MIDI_OUT: |
---|
| 646 | infotext = " ticks/s"; |
---|
| 647 | break; |
---|
| 648 | case ROAR_DIR_LIGHT_IN: |
---|
| 649 | case ROAR_DIR_LIGHT_OUT: |
---|
| 650 | infotext = " updates/s"; |
---|
| 651 | break; |
---|
| 652 | default: |
---|
| 653 | infotext = " Hz"; |
---|
| 654 | } |
---|
| 655 | if ( s.info.rate ) |
---|
| 656 | printf("Stream sample rate : %i%s\n", s.info.rate, infotext); |
---|
| 657 | if ( s.info.bits ) |
---|
| 658 | printf("Stream bits : %i\n", s.info.bits); |
---|
| 659 | if ( s.info.channels ) |
---|
[2399] | 660 | printf("Stream channels : %i\n", s.info.channels); |
---|
[1810] | 661 | |
---|
[4818] | 662 | mime = roar_codec2mime(s.info.codec); |
---|
| 663 | printf("Stream codec : %2i (%s%s%s%s)\n", s.info.codec, roar_codec2str(s.info.codec), |
---|
| 664 | s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "", |
---|
| 665 | mime == NULL ? "" : " mimetype:", |
---|
| 666 | mime == NULL ? "" : mime |
---|
| 667 | ); |
---|
| 668 | if ( roar_stream_get_info(con, &s, &info) != -1 ) { |
---|
| 669 | if ( info.codec != s.info.codec ) { |
---|
| 670 | mime = roar_codec2mime(info.codec); |
---|
| 671 | printf("Streamed codec : %2i (%s%s%s%s)\n", info.codec, roar_codec2str(info.codec), |
---|
| 672 | info.codec == ROAR_CODEC_DEFAULT ? " native" : "", |
---|
| 673 | mime == NULL ? "" : " mimetype:", |
---|
| 674 | mime == NULL ? "" : mime |
---|
| 675 | ); |
---|
[465] | 676 | } |
---|
[1811] | 677 | |
---|
[3539] | 678 | if ( g_verbose ) { |
---|
[4818] | 679 | if ( info.block_size ) |
---|
| 680 | printf("Stream block size : %i Byte\n", info.block_size); |
---|
| 681 | |
---|
| 682 | printf("Underruns pre/post : %i/%i\n", info.pre_underruns, info.post_underruns); |
---|
| 683 | if ( g_verbose > 1 ) |
---|
| 684 | printf("Stream delay : %ims (%.2fm)\n", (int)info.delay/1000, (info.delay*(float)_SPEED_OF_SOUND)); |
---|
| 685 | |
---|
| 686 | if ( g_verbose > 1 ) |
---|
| 687 | printf("Stream mixer : %i\n", info.mixer); |
---|
| 688 | |
---|
| 689 | if ( g_verbose > 1 ) |
---|
| 690 | printf("Stream state : %s\n", roar_streamstate2str(info.state)); |
---|
| 691 | |
---|
| 692 | if ( g_verbose > 1 ) |
---|
| 693 | printf("Stream role : %s\n", roar_role2str(info.role)); |
---|
[3539] | 694 | |
---|
[4818] | 695 | *flags = 0; |
---|
[5005] | 696 | #define _strcat(dst,src) roar_mm_strlcat((dst),(src), sizeof(buffer)) |
---|
[4818] | 697 | if ( info.flags & ROAR_FLAG_PRIMARY ) |
---|
[5005] | 698 | _strcat(flags, "primary "); |
---|
[4818] | 699 | if ( info.flags & ROAR_FLAG_SYNC ) |
---|
[5005] | 700 | _strcat(flags, "sync "); |
---|
[4818] | 701 | if ( info.flags & ROAR_FLAG_OUTPUT ) |
---|
[5005] | 702 | _strcat(flags, "output "); |
---|
[4818] | 703 | if ( info.flags & ROAR_FLAG_SOURCE ) |
---|
[5005] | 704 | _strcat(flags, "source "); |
---|
[4818] | 705 | if ( info.flags & ROAR_FLAG_META ) |
---|
[5005] | 706 | _strcat(flags, "meta "); |
---|
[4818] | 707 | if ( info.flags & ROAR_FLAG_AUTOCONF ) |
---|
[5005] | 708 | _strcat(flags, "autoconf "); |
---|
[4818] | 709 | if ( info.flags & ROAR_FLAG_CLEANMETA ) |
---|
[5005] | 710 | _strcat(flags, "cleanmeta "); |
---|
[4818] | 711 | if ( info.flags & ROAR_FLAG_HWMIXER ) |
---|
[5005] | 712 | _strcat(flags, "hwmixer "); |
---|
[4818] | 713 | if ( info.flags & ROAR_FLAG_PAUSE ) |
---|
[5005] | 714 | _strcat(flags, "pause "); |
---|
[4818] | 715 | if ( info.flags & ROAR_FLAG_MUTE ) |
---|
[5005] | 716 | _strcat(flags, "mute "); |
---|
[4818] | 717 | if ( info.flags & ROAR_FLAG_MMAP ) |
---|
[5005] | 718 | _strcat(flags, "mmap "); |
---|
[4818] | 719 | if ( info.flags & ROAR_FLAG_ANTIECHO ) |
---|
[5005] | 720 | _strcat(flags, "antiecho "); |
---|
[4818] | 721 | if ( info.flags & ROAR_FLAG_VIRTUAL ) |
---|
[5005] | 722 | _strcat(flags, "virtual "); |
---|
[4818] | 723 | if ( info.flags & ROAR_FLAG_RECSOURCE ) |
---|
[5005] | 724 | _strcat(flags, "recsource "); |
---|
[4818] | 725 | if ( info.flags & ROAR_FLAG_PASSMIXER ) |
---|
[5005] | 726 | _strcat(flags, "passmixer "); |
---|
[4818] | 727 | if ( info.flags & ROAR_FLAG_PRETHRU ) |
---|
[5005] | 728 | _strcat(flags, "prethru "); |
---|
[4818] | 729 | if ( info.flags & ROAR_FLAG_IMMUTABLE ) |
---|
[5005] | 730 | _strcat(flags, "immutable "); |
---|
[4818] | 731 | if ( info.flags & ROAR_FLAG_ENHANCE ) |
---|
[5005] | 732 | _strcat(flags, "enhance "); |
---|
[4818] | 733 | if ( info.flags & ROAR_FLAG_SINGLESINK ) |
---|
[5005] | 734 | _strcat(flags, "singlesink "); |
---|
| 735 | #undef _strcat |
---|
[4818] | 736 | |
---|
| 737 | printf("Flags : %s\n", flags); |
---|
[1811] | 738 | } |
---|
[0] | 739 | } |
---|
| 740 | |
---|
[5386] | 741 | if ( g_verbose && (s.info.channels != 0 && s.info.channels <= ROAR_MAX_CHANNELS) ) { |
---|
[4818] | 742 | len = ROAR_MAX_CHANNELS; |
---|
| 743 | if ( roar_stream_get_chanmap(con, &s, chanmap, &len) == -1 ) { |
---|
| 744 | fprintf(stderr, "Error: can not get stream channel map\n"); |
---|
| 745 | } else { |
---|
| 746 | if ( roardsp_chanlist2str(chanmap, len, buffer, 1024) == -1 ) { |
---|
| 747 | fprintf(stderr, "Error: can not convert channel map into string\n"); |
---|
| 748 | } else { |
---|
| 749 | printf("Channel Map : %s\n", buffer); |
---|
| 750 | } |
---|
| 751 | } |
---|
| 752 | } |
---|
| 753 | |
---|
| 754 | if ( s.dir != ROAR_DIR_THRU ) { |
---|
[5386] | 755 | if ( s.info.channels != 0 && s.info.channels <= ROAR_MAX_CHANNELS ) { |
---|
| 756 | display_mixer(con, id); |
---|
| 757 | } |
---|
[4818] | 758 | show_meta_all(con, id); |
---|
| 759 | } |
---|
[0] | 760 | } |
---|
| 761 | |
---|
[25] | 762 | int display_mixer (struct roar_connection * con, int stream) { |
---|
[3529] | 763 | struct roar_mixer_settings mixer; |
---|
[25] | 764 | int channels; |
---|
| 765 | int i; |
---|
[3529] | 766 | float fs; |
---|
[25] | 767 | |
---|
| 768 | if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) { |
---|
[3530] | 769 | fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", stream); |
---|
[25] | 770 | return -1; |
---|
| 771 | } |
---|
| 772 | |
---|
[2916] | 773 | #ifdef ROAR_HAVE_LIBM |
---|
| 774 | #define _DB ", %.2fdB" |
---|
| 775 | #else |
---|
| 776 | #define _DB "" |
---|
| 777 | #endif |
---|
| 778 | |
---|
[3529] | 779 | fs = (float)mixer.scale / 100.; |
---|
| 780 | |
---|
[3531] | 781 | if ( channels ) { // we hide RPG info for zero-channel streams |
---|
| 782 | printf("Mixer ReplayGain : %i/%i (%.2f%%" _DB ")\n", mixer.rpg_mul, mixer.rpg_div, |
---|
| 783 | 100.*(float)mixer.rpg_mul/((float)mixer.rpg_div) |
---|
[3529] | 784 | #ifdef ROAR_HAVE_LIBM |
---|
[3531] | 785 | , 20*log10f((float)mixer.rpg_mul/(float)mixer.rpg_div) |
---|
[3529] | 786 | #endif |
---|
[3531] | 787 | ); |
---|
| 788 | } |
---|
[3529] | 789 | |
---|
[25] | 790 | for (i = 0; i < channels; i++) |
---|
[3529] | 791 | printf("Mixer volume chan %2i : %i/%i (%.2f%%" _DB ")\n", i, mixer.mixer[i], mixer.scale, |
---|
| 792 | (float)mixer.mixer[i]/fs |
---|
[2916] | 793 | #ifdef ROAR_HAVE_LIBM |
---|
[3529] | 794 | , 20*log10f((float)mixer.mixer[i]/(float)mixer.scale) |
---|
[2916] | 795 | #endif |
---|
| 796 | ); |
---|
[25] | 797 | |
---|
| 798 | return 0; |
---|
| 799 | } |
---|
[0] | 800 | |
---|
[3530] | 801 | static unsigned int set_mixer_parse_volume (char * k, int len, uint16_t scale) { |
---|
| 802 | float fs = scale; |
---|
| 803 | |
---|
[2916] | 804 | switch (k[len - 1]) { |
---|
| 805 | case '%': |
---|
| 806 | k[len - 1] = 0; |
---|
[3530] | 807 | return (atof(k)*fs)/100.; |
---|
[2916] | 808 | break; |
---|
| 809 | #ifdef ROAR_HAVE_LIBM |
---|
| 810 | case 'b': |
---|
| 811 | case 'B': |
---|
| 812 | // TODO: can we hanle the error better? |
---|
| 813 | if ( len < 2 ) |
---|
| 814 | return 0; |
---|
| 815 | |
---|
| 816 | k[len - 2] = 0; |
---|
[3530] | 817 | return powf(10, atof(k)/20.f)*fs; |
---|
[2916] | 818 | break; |
---|
| 819 | #endif |
---|
| 820 | } |
---|
| 821 | |
---|
| 822 | return atoi(k); |
---|
| 823 | } |
---|
| 824 | |
---|
[85] | 825 | int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) { |
---|
[3530] | 826 | uint16_t scale = 65535; |
---|
[85] | 827 | int chans = 0; |
---|
| 828 | int id; |
---|
| 829 | int i; |
---|
| 830 | int len; |
---|
| 831 | int old_chans; |
---|
| 832 | char * k; |
---|
| 833 | struct roar_mixer_settings mixer; |
---|
| 834 | struct roar_mixer_settings old_mixer; |
---|
[4740] | 835 | int mode = ROAR_SET_VOL_ALL; |
---|
[85] | 836 | |
---|
| 837 | if (*cur + 2 > max) |
---|
| 838 | return -1; |
---|
| 839 | |
---|
| 840 | id = atoi(arg[++(*cur)]); |
---|
| 841 | |
---|
| 842 | k = arg[++(*cur)]; |
---|
| 843 | |
---|
[3530] | 844 | if ( !strcmp(arg[*cur + 1], "scale") ) { |
---|
| 845 | (*cur)++; // 'scale' |
---|
[3559] | 846 | (*cur)++; |
---|
| 847 | scale = set_mixer_parse_volume(arg[*cur], strlen(arg[*cur]), 65535); |
---|
[3530] | 848 | } |
---|
[85] | 849 | |
---|
[4740] | 850 | mixer.scale = scale; |
---|
[85] | 851 | |
---|
[4740] | 852 | if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) { |
---|
| 853 | fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", id); |
---|
| 854 | return -1; |
---|
| 855 | } |
---|
[85] | 856 | |
---|
[4740] | 857 | if ( strcmp(k, "mono") == 0 ) { |
---|
| 858 | chans = 1; |
---|
| 859 | mode = ROAR_SET_VOL_UNMAPPED; |
---|
| 860 | } else if ( strcmp(k, "stereo") == 0 ) { |
---|
| 861 | chans = 2; |
---|
| 862 | mode = ROAR_SET_VOL_UNMAPPED; |
---|
| 863 | } else { |
---|
| 864 | chans = atoi(k); |
---|
| 865 | } |
---|
[1203] | 866 | |
---|
[4740] | 867 | // ensure most simple mode: |
---|
| 868 | if ( old_chans == chans && mode == ROAR_SET_VOL_UNMAPPED ) |
---|
| 869 | mode = ROAR_SET_VOL_ALL; |
---|
[1203] | 870 | |
---|
[4740] | 871 | if ( *cur + chans > max ) |
---|
| 872 | return -1; |
---|
[1203] | 873 | |
---|
[4740] | 874 | for (i = 0; i < chans; i++) { |
---|
[1203] | 875 | k = arg[++(*cur)]; |
---|
| 876 | len = strlen(k); |
---|
| 877 | |
---|
[4740] | 878 | mixer.mixer[i] = set_mixer_parse_volume(k, len, scale); |
---|
[85] | 879 | } |
---|
| 880 | |
---|
[5236] | 881 | if ( roar_set_vol(con, id, &mixer, chans, mode) == 0 ) |
---|
[4740] | 882 | return 0; |
---|
| 883 | |
---|
| 884 | // no fallback if already using ROAR_SET_VOL_ALL: |
---|
| 885 | if ( mode == ROAR_SET_VOL_ALL ) |
---|
| 886 | return -1; |
---|
[85] | 887 | |
---|
[4740] | 888 | if ( roar_conv_volume(&mixer, &mixer, old_chans, chans) == -1 ) |
---|
| 889 | return -1; |
---|
| 890 | |
---|
| 891 | chans = old_chans; |
---|
| 892 | mode = ROAR_SET_VOL_ALL; |
---|
| 893 | |
---|
[5236] | 894 | if ( roar_set_vol(con, id, &mixer, chans, mode) == 0 ) |
---|
[4740] | 895 | return 0; |
---|
| 896 | |
---|
| 897 | return -1; |
---|
[85] | 898 | } |
---|
| 899 | |
---|
[2698] | 900 | |
---|
| 901 | int newvirtual (struct roar_connection * con, char *p_s, char *d_s, char *e_s, char *r_s, char *b_s, char *c_s) { |
---|
| 902 | struct roar_stream s; |
---|
| 903 | int dir = roar_str2dir(d_s); |
---|
| 904 | int parent = atoi(p_s); |
---|
| 905 | |
---|
[2699] | 906 | ROAR_DBG("newvirtual(*): dir=%i, parent=%i", dir, parent); |
---|
| 907 | |
---|
[2698] | 908 | if ( roar_stream_new(&s, atoi(r_s), atoi(c_s), atoi(b_s), roar_str2codec(e_s)) == -1 ) |
---|
| 909 | return -1; |
---|
| 910 | |
---|
| 911 | return roar_simple_connect_virtual(con, &s, parent, dir); |
---|
| 912 | } |
---|
| 913 | |
---|
[99] | 914 | int set_meta (struct roar_connection * con, int id, char * mode, char * type, char * val) { |
---|
| 915 | struct roar_meta meta; |
---|
| 916 | struct roar_stream s; |
---|
| 917 | int mode_i = ROAR_META_MODE_SET; |
---|
| 918 | |
---|
[3072] | 919 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 920 | return -1; |
---|
[99] | 921 | |
---|
[106] | 922 | // printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val); |
---|
[99] | 923 | |
---|
| 924 | if ( strcmp(mode, "add") == 0 ) { |
---|
| 925 | mode_i = ROAR_META_MODE_ADD; |
---|
| 926 | } |
---|
| 927 | |
---|
[109] | 928 | meta.type = roar_meta_inttype(type); |
---|
[106] | 929 | meta.value = val; |
---|
| 930 | meta.key[0] = 0; |
---|
[99] | 931 | |
---|
[109] | 932 | if ( meta.type == -1 ) { |
---|
| 933 | fprintf(stderr, "Error: unknown type: %s\n", type); |
---|
| 934 | return -1; |
---|
| 935 | } |
---|
| 936 | |
---|
[106] | 937 | // printf("D: type=%i, mode=%i\n", meta.type, mode_i); |
---|
[99] | 938 | |
---|
[1127] | 939 | if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 ) |
---|
| 940 | return -1; |
---|
| 941 | |
---|
| 942 | meta.type = ROAR_META_TYPE_NONE; |
---|
| 943 | meta.value = NULL; |
---|
| 944 | |
---|
| 945 | return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta); |
---|
[99] | 946 | } |
---|
| 947 | |
---|
[1126] | 948 | int load_meta (struct roar_connection * con, int id, char * file) { |
---|
| 949 | struct roar_meta meta; |
---|
| 950 | struct roar_stream s; |
---|
| 951 | int mode_i = ROAR_META_MODE_SET; |
---|
| 952 | FILE * in; |
---|
| 953 | char lion[1024]; |
---|
| 954 | char * v; |
---|
| 955 | |
---|
[3072] | 956 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 957 | return -1; |
---|
[1126] | 958 | |
---|
| 959 | if ( (in = fopen(file, "r")) == NULL ) |
---|
| 960 | return -1; |
---|
| 961 | |
---|
| 962 | while (fgets(lion, 1024, in) != NULL) { |
---|
| 963 | if ( (v = strtok(lion, "\r\n")) != NULL ) |
---|
| 964 | if ( (v = strtok(NULL, "\r\n")) != NULL ) |
---|
| 965 | *(v-1) = 0; |
---|
| 966 | |
---|
| 967 | if ( (v = strstr(lion, "=")) == NULL ) { |
---|
| 968 | fprintf(stderr, "Error: can not parse meta data lion: %s\n", lion); |
---|
| 969 | continue; |
---|
| 970 | } |
---|
| 971 | |
---|
| 972 | *v++ = 0; |
---|
| 973 | |
---|
| 974 | meta.type = roar_meta_inttype(lion); |
---|
| 975 | meta.value = v; |
---|
| 976 | meta.key[0] = 0; |
---|
| 977 | |
---|
| 978 | if ( meta.type == -1 ) { |
---|
| 979 | fprintf(stderr, "Error: unknown type: %s\n", lion); |
---|
| 980 | continue; |
---|
| 981 | } |
---|
| 982 | |
---|
[4014] | 983 | if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 ) { |
---|
| 984 | fclose(in); |
---|
[1126] | 985 | return -1; |
---|
[4014] | 986 | } |
---|
[1126] | 987 | } |
---|
| 988 | |
---|
| 989 | fclose(in); |
---|
| 990 | |
---|
| 991 | meta.type = ROAR_META_TYPE_NONE; |
---|
| 992 | meta.value = NULL; |
---|
| 993 | |
---|
| 994 | return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta); |
---|
| 995 | } |
---|
| 996 | |
---|
[106] | 997 | int show_meta_type (struct roar_connection * con, int id, char * type) { |
---|
| 998 | struct roar_meta meta; |
---|
| 999 | struct roar_stream s; |
---|
| 1000 | |
---|
[3072] | 1001 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 1002 | return -1; |
---|
[106] | 1003 | |
---|
[109] | 1004 | meta.type = roar_meta_inttype(type); |
---|
| 1005 | |
---|
| 1006 | if ( meta.type == -1 ) { |
---|
| 1007 | fprintf(stderr, "Error: unknown type: %s\n", type); |
---|
| 1008 | return -1; |
---|
| 1009 | } |
---|
[106] | 1010 | |
---|
| 1011 | if ( roar_stream_meta_get(con, &s, &meta) == -1 ) |
---|
| 1012 | return -1; |
---|
| 1013 | |
---|
[112] | 1014 | printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value); |
---|
[106] | 1015 | |
---|
| 1016 | roar_meta_free(&meta); |
---|
| 1017 | |
---|
| 1018 | return 0; |
---|
| 1019 | } |
---|
| 1020 | |
---|
[112] | 1021 | int show_meta_all (struct roar_connection * con, int id) { |
---|
| 1022 | struct roar_stream s; |
---|
| 1023 | int types[ROAR_META_MAX_PER_STREAM]; |
---|
| 1024 | int i; |
---|
| 1025 | int len; |
---|
| 1026 | |
---|
[3072] | 1027 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 1028 | return -1; |
---|
[112] | 1029 | |
---|
| 1030 | if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 ) |
---|
| 1031 | return -1; |
---|
| 1032 | |
---|
| 1033 | for (i = 0; i < len; i++) |
---|
| 1034 | show_meta_type(con, id, roar_meta_strtype(types[i])); |
---|
| 1035 | |
---|
| 1036 | return 0; |
---|
| 1037 | } |
---|
| 1038 | |
---|
[1126] | 1039 | int save_meta (struct roar_connection * con, int id, char * file) { |
---|
| 1040 | struct roar_stream s; |
---|
| 1041 | struct roar_meta meta; |
---|
| 1042 | int types[ROAR_META_MAX_PER_STREAM]; |
---|
| 1043 | int i; |
---|
| 1044 | int len; |
---|
| 1045 | FILE * out; |
---|
| 1046 | |
---|
[3072] | 1047 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 1048 | return -1; |
---|
[1126] | 1049 | |
---|
[4014] | 1050 | if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 ) |
---|
[1126] | 1051 | return -1; |
---|
| 1052 | |
---|
[4014] | 1053 | if ( (out = fopen(file, "w")) == NULL ) |
---|
[1126] | 1054 | return -1; |
---|
| 1055 | |
---|
| 1056 | for (i = 0; i < len; i++) { |
---|
| 1057 | /* |
---|
| 1058 | show_meta_type(con, id, roar_meta_strtype(types[i])); |
---|
| 1059 | */ |
---|
| 1060 | meta.type = types[i]; |
---|
| 1061 | |
---|
| 1062 | if ( roar_stream_meta_get(con, &s, &meta) == -1 ) |
---|
| 1063 | continue; |
---|
| 1064 | |
---|
| 1065 | // printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value); |
---|
| 1066 | |
---|
| 1067 | fprintf(out, "%s=%s\n", roar_meta_strtype(meta.type), meta.value); |
---|
| 1068 | |
---|
| 1069 | roar_meta_free(&meta); |
---|
| 1070 | } |
---|
| 1071 | |
---|
| 1072 | fclose(out); |
---|
| 1073 | |
---|
| 1074 | return 0; |
---|
| 1075 | } |
---|
| 1076 | |
---|
[4552] | 1077 | int set_flags (struct roar_connection * con, int id, int action, char * flags) { |
---|
| 1078 | uint32_t f = ROAR_FLAG_NONE; |
---|
[1043] | 1079 | char * c; |
---|
| 1080 | struct roar_stream s[1]; |
---|
| 1081 | |
---|
[3072] | 1082 | if ( roar_stream_new_by_id(s, id) == -1 ) |
---|
| 1083 | return -1; |
---|
[1043] | 1084 | |
---|
| 1085 | c = strtok(flags, ","); |
---|
| 1086 | while (c != NULL) { |
---|
| 1087 | if ( !strcmp(c, "meta") ) { |
---|
| 1088 | f |= ROAR_FLAG_META; |
---|
| 1089 | } else if ( !strcmp(c, "primary") ) { |
---|
| 1090 | f |= ROAR_FLAG_PRIMARY; |
---|
[1116] | 1091 | } else if ( !strcmp(c, "sync") ) { |
---|
| 1092 | f |= ROAR_FLAG_SYNC; |
---|
[1219] | 1093 | } else if ( !strcmp(c, "cleanmeta") ) { |
---|
| 1094 | f |= ROAR_FLAG_CLEANMETA; |
---|
[1585] | 1095 | } else if ( !strcmp(c, "hwmixer") ) { |
---|
| 1096 | f |= ROAR_FLAG_HWMIXER; |
---|
| 1097 | } else if ( !strcmp(c, "pause") ) { |
---|
| 1098 | f |= ROAR_FLAG_PAUSE; |
---|
[1883] | 1099 | } else if ( !strcmp(c, "mute") ) { |
---|
| 1100 | f |= ROAR_FLAG_MUTE; |
---|
[1926] | 1101 | } else if ( !strcmp(c, "mmap") ) { |
---|
| 1102 | f |= ROAR_FLAG_MMAP; |
---|
[2154] | 1103 | } else if ( !strcmp(c, "antiecho") ) { |
---|
| 1104 | f |= ROAR_FLAG_ANTIECHO; |
---|
[2412] | 1105 | } else if ( !strcmp(c, "recsource") ) { |
---|
| 1106 | f |= ROAR_FLAG_RECSOURCE; |
---|
| 1107 | } else if ( !strcmp(c, "passmixer") ) { |
---|
| 1108 | f |= ROAR_FLAG_PASSMIXER; |
---|
[2627] | 1109 | } else if ( !strcmp(c, "virtual") ) { |
---|
| 1110 | f |= ROAR_FLAG_VIRTUAL; |
---|
[2814] | 1111 | } else if ( !strcmp(c, "prethru") ) { |
---|
| 1112 | f |= ROAR_FLAG_PRETHRU; |
---|
[2953] | 1113 | } else if ( !strcmp(c, "immutable") ) { |
---|
| 1114 | f |= ROAR_FLAG_IMMUTABLE; |
---|
| 1115 | } else if ( !strcmp(c, "enhance") ) { |
---|
| 1116 | f |= ROAR_FLAG_ENHANCE; |
---|
[4536] | 1117 | } else if ( !strcmp(c, "singlesink") ) { |
---|
| 1118 | f |= ROAR_FLAG_SINGLESINK; |
---|
[1043] | 1119 | } else { |
---|
| 1120 | fprintf(stderr, "Error: unknown flag: %s\n", c); |
---|
| 1121 | return -1; |
---|
| 1122 | } |
---|
| 1123 | |
---|
| 1124 | c = strtok(NULL, ","); |
---|
| 1125 | } |
---|
| 1126 | |
---|
[5238] | 1127 | return roar_stream_set_flags(con, s, f, action); |
---|
[1043] | 1128 | } |
---|
| 1129 | |
---|
[4933] | 1130 | int set_role (struct roar_connection * con, int id, int role) { |
---|
| 1131 | struct roar_stream s; |
---|
| 1132 | |
---|
| 1133 | if ( id == -1 ) |
---|
| 1134 | return -1; |
---|
| 1135 | |
---|
| 1136 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
| 1137 | return -1; |
---|
| 1138 | |
---|
| 1139 | if ( roar_stream_set_role(con, &s, role) == -1 ) |
---|
| 1140 | return -1; |
---|
| 1141 | |
---|
| 1142 | return 0; |
---|
| 1143 | } |
---|
| 1144 | |
---|
[3942] | 1145 | int show_aiprofile (const char * profile) { |
---|
| 1146 | struct roar_audio_info info; |
---|
[4882] | 1147 | const char * mime; |
---|
[3942] | 1148 | |
---|
| 1149 | if ( roar_profile2info(&info, profile) == -1 ) { |
---|
| 1150 | fprintf(stderr, "Error: unknown profile: %s\n", profile); |
---|
| 1151 | return -1; |
---|
| 1152 | } |
---|
| 1153 | |
---|
[4882] | 1154 | mime = roar_codec2mime(info.codec); |
---|
| 1155 | |
---|
[3942] | 1156 | printf("Profile Name : %s\n", profile); |
---|
[3944] | 1157 | |
---|
| 1158 | if ( info.rate ) |
---|
| 1159 | printf("Profile sample rate : %i\n", info.rate); |
---|
| 1160 | if ( info.bits ) |
---|
| 1161 | printf("Profile bits : %i\n", info.bits); |
---|
| 1162 | if ( info.channels ) |
---|
| 1163 | printf("Profile channels : %i\n", info.channels); |
---|
| 1164 | |
---|
[4882] | 1165 | printf("Profile codec : %2i (%s%s%s%s)\n", info.codec, roar_codec2str(info.codec), |
---|
| 1166 | info.codec == ROAR_CODEC_DEFAULT ? " native" : "", |
---|
| 1167 | mime == NULL ? "" : " mimetype:", |
---|
| 1168 | mime == NULL ? "" : mime); |
---|
[3942] | 1169 | |
---|
| 1170 | return 0; |
---|
| 1171 | } |
---|
| 1172 | |
---|
| 1173 | int list_aiprofiles (void) { |
---|
| 1174 | const char * list[1024]; |
---|
| 1175 | ssize_t ret; |
---|
| 1176 | ssize_t i; |
---|
| 1177 | |
---|
| 1178 | ret = roar_profiles_list(list, 1024, 0); |
---|
| 1179 | |
---|
| 1180 | if ( ret == -1 ) { |
---|
| 1181 | fprintf(stderr, "Error: can not read list of profiles\n"); |
---|
| 1182 | return -1; |
---|
| 1183 | } |
---|
| 1184 | |
---|
| 1185 | for (i = 0; i < ret; i++) { |
---|
| 1186 | printf("profile %lli:\n", (long long signed int)i); |
---|
| 1187 | show_aiprofile(list[i]); |
---|
| 1188 | } |
---|
| 1189 | |
---|
| 1190 | return 0; |
---|
| 1191 | } |
---|
| 1192 | |
---|
[0] | 1193 | int main (int argc, char * argv[]) { |
---|
| 1194 | struct roar_connection con; |
---|
| 1195 | char * server = NULL; |
---|
| 1196 | char * k = NULL; |
---|
| 1197 | int i; |
---|
| 1198 | int t = 0; |
---|
| 1199 | |
---|
| 1200 | for (i = 1; i < argc; i++) { |
---|
| 1201 | k = argv[i]; |
---|
| 1202 | |
---|
| 1203 | if ( strcmp(k, "--server") == 0 ) { |
---|
[58] | 1204 | server = argv[++i]; |
---|
[963] | 1205 | } else if ( strcmp(k, "-v") == 0 || strcmp(k, "--verbose") == 0 ) { |
---|
| 1206 | g_verbose++; |
---|
[0] | 1207 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
| 1208 | usage(); |
---|
| 1209 | return 0; |
---|
[3960] | 1210 | } else if ( strcmp(k, "--list-aiprofiles") == 0 ) { |
---|
| 1211 | list_aiprofiles(); |
---|
| 1212 | return 0; |
---|
[5149] | 1213 | } else if ( strcmp(k, "--list-libstandards") == 0 ) { |
---|
| 1214 | lib_standards(); |
---|
| 1215 | return 0; |
---|
[4413] | 1216 | } else if ( strcmp(k, "--enum-servers") == 0 ) { |
---|
| 1217 | enum_servers(); |
---|
| 1218 | return 0; |
---|
[5187] | 1219 | } else if ( strcmp(k, "--hash-password") == 0 ) { |
---|
| 1220 | hash_password(); |
---|
| 1221 | return 0; |
---|
[0] | 1222 | } else if ( *k == '-' ) { |
---|
| 1223 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 1224 | usage(); |
---|
| 1225 | return 1; |
---|
| 1226 | } else { |
---|
| 1227 | break; |
---|
| 1228 | } |
---|
| 1229 | } |
---|
| 1230 | |
---|
| 1231 | // connect |
---|
| 1232 | |
---|
[3510] | 1233 | if ( roar_simple_connect(&con, server, "roarctl") == -1 ) { |
---|
[5185] | 1234 | fprintf(stderr, "Error: Can not connect to server: %s: %s(%i)\n", |
---|
| 1235 | server == NULL ? "(default)" : server, roar_vs_strerr(roar_error), roar_error); |
---|
[0] | 1236 | return 1; |
---|
| 1237 | } |
---|
| 1238 | |
---|
| 1239 | if ( i == argc ) { |
---|
| 1240 | fprintf(stderr, "Error: No Commands given\n"); |
---|
| 1241 | return 0; // this is not a fatal error... |
---|
| 1242 | } |
---|
| 1243 | |
---|
| 1244 | for (; i < argc; i++) { |
---|
| 1245 | k = argv[i]; |
---|
| 1246 | // cmd is in k |
---|
| 1247 | |
---|
| 1248 | printf("--- [ %s ] ---\n", k); |
---|
| 1249 | |
---|
| 1250 | if ( !strcmp(k, "help") ) { |
---|
| 1251 | usage(); |
---|
| 1252 | |
---|
[1202] | 1253 | } else if ( !strcmp(k, "sleep") ) { |
---|
[4914] | 1254 | roar_sleep(atoi(argv[++i])); |
---|
[0] | 1255 | |
---|
[1630] | 1256 | } else if ( !strcmp(k, "ping") ) { |
---|
[1781] | 1257 | #ifdef ROAR_HAVE_GETTIMEOFDAY |
---|
[1630] | 1258 | if ( ping(&con, atoi(argv[++i])) == -1 ) { |
---|
| 1259 | fprintf(stderr, "Error: can not ping\n"); |
---|
| 1260 | } |
---|
[1781] | 1261 | #else |
---|
| 1262 | fprintf(stderr, "Error: ping not supported.\n"); |
---|
| 1263 | i++; |
---|
| 1264 | #endif |
---|
[1630] | 1265 | |
---|
[0] | 1266 | } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) { |
---|
| 1267 | if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) { |
---|
| 1268 | fprintf(stderr, "Error: can not set mode to standby\n"); |
---|
| 1269 | } else { |
---|
| 1270 | printf("going into standby\n"); |
---|
| 1271 | } |
---|
| 1272 | } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) { |
---|
| 1273 | if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) { |
---|
| 1274 | fprintf(stderr, "Error: can not set mode to active\n"); |
---|
| 1275 | } else { |
---|
| 1276 | printf("going into active mode\n"); |
---|
| 1277 | } |
---|
| 1278 | |
---|
| 1279 | } else if ( !strcmp(k, "exit") ) { |
---|
[4047] | 1280 | if ( roar_terminate(&con, 0) == -1 ) { |
---|
[0] | 1281 | fprintf(stderr, "Error: can not quit server\n"); |
---|
| 1282 | } else { |
---|
| 1283 | printf("Server quited\n"); |
---|
| 1284 | break; |
---|
| 1285 | } |
---|
[577] | 1286 | } else if ( !strcmp(k, "terminate") ) { |
---|
| 1287 | if ( roar_terminate(&con, 1) == -1 ) { |
---|
| 1288 | fprintf(stderr, "Error: can not terminate server\n"); |
---|
| 1289 | } else { |
---|
| 1290 | printf("Server got asked to quited\n"); |
---|
| 1291 | break; |
---|
| 1292 | } |
---|
[0] | 1293 | |
---|
| 1294 | } else if ( !strcmp(k, "standbymode") ) { |
---|
| 1295 | t = roar_get_standby(&con); |
---|
| 1296 | if ( t == -1 ) { |
---|
| 1297 | fprintf(stderr, "Error: can not get stanby mode\n"); |
---|
| 1298 | } else if ( t == ROAR_STANDBY_ACTIVE ) { |
---|
| 1299 | printf("Server is in standby\n"); |
---|
| 1300 | } else if ( t == ROAR_STANDBY_INACTIVE ) { |
---|
| 1301 | printf("Server is active\n"); |
---|
| 1302 | } else { |
---|
| 1303 | fprintf(stderr, "Error: unknown standby mode: %i\n", t); |
---|
| 1304 | } |
---|
| 1305 | |
---|
[1162] | 1306 | } else if ( !strcmp(k, "whoami") ) { |
---|
| 1307 | printf("My client ID is: %i\n", roar_get_clientid(&con)); |
---|
[5384] | 1308 | } else if ( !strcmp(k, "beep") ) { |
---|
| 1309 | roar_beep(&con, NULL); |
---|
[4432] | 1310 | } else if ( !strcmp(k, "serverinfo") ) { |
---|
| 1311 | server_info(&con); |
---|
[5031] | 1312 | } else if ( !strcmp(k, "servertime") ) { |
---|
| 1313 | server_time(&con); |
---|
[0] | 1314 | } else if ( !strcmp(k, "serveroinfo") ) { |
---|
[4614] | 1315 | server_oinfo(&con, -1); |
---|
| 1316 | } else if ( !strcmp(k, "serveroinfo2") ) { |
---|
| 1317 | t = roar_str2dir(argv[++i]); |
---|
| 1318 | if ( t == -1 ) { |
---|
| 1319 | fprintf(stderr, "Error: unknown stream direction: %s\n", argv[i]); |
---|
| 1320 | } else { |
---|
| 1321 | server_oinfo(&con, t); |
---|
| 1322 | } |
---|
[4501] | 1323 | } else if ( !strcmp(k, "serverstandards") ) { |
---|
| 1324 | server_standards(&con); |
---|
[5149] | 1325 | } else if ( !strcmp(k, "libstandards") ) { |
---|
| 1326 | lib_standards(); |
---|
[0] | 1327 | } else if ( !strcmp(k, "listclients") ) { |
---|
| 1328 | list_clients(&con); |
---|
[4818] | 1329 | } else if ( !strcmp(k, "clientinfo") ) { |
---|
| 1330 | display_client(&con, atoi(argv[++i])); |
---|
[0] | 1331 | } else if ( !strcmp(k, "liststreams") ) { |
---|
| 1332 | list_streams(&con); |
---|
[4818] | 1333 | } else if ( !strcmp(k, "streaminfo") ) { |
---|
| 1334 | display_stream(&con, atoi(argv[++i])); |
---|
[0] | 1335 | } else if ( !strcmp(k, "allinfo") ) { |
---|
[5379] | 1336 | server_info(&con); |
---|
| 1337 | printf("\n"); |
---|
| 1338 | server_time(&con); |
---|
| 1339 | printf("\n"); |
---|
[5383] | 1340 | server_standards(&con); |
---|
[5379] | 1341 | printf("\n"); |
---|
[4614] | 1342 | server_oinfo(&con, -1); |
---|
[0] | 1343 | printf("\n"); |
---|
| 1344 | list_clients(&con); |
---|
| 1345 | printf("\n"); |
---|
| 1346 | list_streams(&con); |
---|
| 1347 | |
---|
| 1348 | } else if ( !strcmp(k, "kick") ) { |
---|
[4328] | 1349 | t = roar_str2ot((k = argv[++i])); |
---|
| 1350 | if ( t == -1 ) { |
---|
[0] | 1351 | fprintf(stderr, "Error: unknown type: %s\n", k); |
---|
| 1352 | continue; |
---|
| 1353 | } |
---|
| 1354 | //t = atoi(argv[i++]); |
---|
| 1355 | if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) { |
---|
| 1356 | fprintf(stderr, "Error: can not kick %s\n", k); |
---|
| 1357 | } else { |
---|
| 1358 | printf("%s kicked\n", k); |
---|
| 1359 | } |
---|
| 1360 | |
---|
[2698] | 1361 | } else if ( !strcmp(k, "newvirtual") ) { |
---|
[2699] | 1362 | if ( newvirtual(&con, argv[i+1], argv[i+2], argv[i+3], argv[i+4], argv[i+5], argv[i+6]) == -1 ) { |
---|
[2698] | 1363 | fprintf(stderr, "Error: can not create new virtual stream\n"); |
---|
| 1364 | } else { |
---|
| 1365 | printf("virtual stream created\n"); |
---|
| 1366 | } |
---|
[2699] | 1367 | i += 6; |
---|
[2698] | 1368 | |
---|
[85] | 1369 | } else if ( !strcmp(k, "volume") ) { |
---|
| 1370 | if ( set_mixer(&con, &i, argc, argv) == -1 ) { |
---|
| 1371 | fprintf(stderr, "Error: can not set volume\n"); |
---|
| 1372 | } else { |
---|
| 1373 | printf("volume changed\n"); |
---|
| 1374 | } |
---|
| 1375 | |
---|
[1043] | 1376 | } else if ( !strcmp(k, "flag") ) { |
---|
| 1377 | i++; |
---|
| 1378 | if ( set_flags(&con, atoi(argv[i]), ROAR_SET_FLAG, argv[i+1]) == -1 ) { |
---|
| 1379 | fprintf(stderr, "Error: can not set flags\n"); |
---|
| 1380 | } else { |
---|
| 1381 | printf("flags changed\n"); |
---|
| 1382 | } |
---|
| 1383 | i++; |
---|
| 1384 | } else if ( !strcmp(k, "unflag") ) { |
---|
| 1385 | i++; |
---|
| 1386 | if ( set_flags(&con, atoi(argv[i]), ROAR_RESET_FLAG, argv[i+1]) == -1 ) { |
---|
| 1387 | fprintf(stderr, "Error: can not reset flags\n"); |
---|
| 1388 | } else { |
---|
| 1389 | printf("flags changed\n"); |
---|
| 1390 | } |
---|
| 1391 | i++; |
---|
[4552] | 1392 | } else if ( !strcmp(k, "toggleflag") ) { |
---|
| 1393 | i++; |
---|
| 1394 | if ( set_flags(&con, atoi(argv[i]), ROAR_TOGGLE_FLAG, argv[i+1]) == -1 ) { |
---|
| 1395 | fprintf(stderr, "Error: can not toggle flags\n"); |
---|
| 1396 | } else { |
---|
| 1397 | printf("flags changed\n"); |
---|
| 1398 | } |
---|
| 1399 | i++; |
---|
| 1400 | } else if ( !strcmp(k, "protectflag") ) { |
---|
| 1401 | i++; |
---|
| 1402 | if ( set_flags(&con, atoi(argv[i]), ROAR_NOOP_FLAG|ROAR_PROTECT_FLAG, argv[i+1]) == -1 ) { |
---|
| 1403 | fprintf(stderr, "Error: can not protect flags\n"); |
---|
| 1404 | } else { |
---|
| 1405 | printf("flags protected\n"); |
---|
| 1406 | } |
---|
| 1407 | i++; |
---|
[4933] | 1408 | |
---|
| 1409 | } else if ( !strcmp(k, "role") ) { |
---|
| 1410 | i++; |
---|
| 1411 | if ( set_role(&con, atoi(argv[i]), roar_str2role(argv[i+1])) == -1 ) { |
---|
| 1412 | fprintf(stderr, "Error: can not set stream role\n"); |
---|
| 1413 | } else { |
---|
[4935] | 1414 | printf("stream role set\n"); |
---|
[4933] | 1415 | } |
---|
| 1416 | i++; |
---|
| 1417 | |
---|
[106] | 1418 | } else if ( !strcmp(k, "metaset") ) { |
---|
[99] | 1419 | i++; |
---|
| 1420 | if ( set_meta(&con, atoi(argv[i]), argv[i+1], argv[i+2], argv[i+3]) == -1 ) { |
---|
| 1421 | fprintf(stderr, "Error: can not set meta data\n"); |
---|
| 1422 | } else { |
---|
| 1423 | printf("meta data changed\n"); |
---|
| 1424 | } |
---|
| 1425 | i += 3; |
---|
[106] | 1426 | } else if ( !strcmp(k, "metaget") ) { |
---|
| 1427 | i++; |
---|
| 1428 | if ( show_meta_type(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
| 1429 | fprintf(stderr, "Error: can not get meta data\n"); |
---|
| 1430 | } |
---|
| 1431 | i++; |
---|
[1126] | 1432 | } else if ( !strcmp(k, "metasave") ) { |
---|
| 1433 | i++; |
---|
| 1434 | if ( save_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
| 1435 | fprintf(stderr, "Error: can not get meta data\n"); |
---|
| 1436 | } else { |
---|
| 1437 | printf("meta data saved\n"); |
---|
| 1438 | } |
---|
| 1439 | i++; |
---|
| 1440 | } else if ( !strcmp(k, "metaload") ) { |
---|
| 1441 | i++; |
---|
| 1442 | if ( load_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
| 1443 | fprintf(stderr, "Error: can not set meta data\n"); |
---|
| 1444 | } else { |
---|
| 1445 | printf("meta data saved\n"); |
---|
| 1446 | } |
---|
| 1447 | i++; |
---|
[99] | 1448 | |
---|
[3942] | 1449 | |
---|
[3961] | 1450 | } else if ( !strcmp(k, "listaiprofiles") || !strcmp(k, "listprofiles") ) { |
---|
[3942] | 1451 | if ( list_aiprofiles() == -1 ) { |
---|
| 1452 | fprintf(stderr, "Error: can not list profiles\n"); |
---|
| 1453 | } |
---|
[3961] | 1454 | } else if ( !strcmp(k, "aiprofileget") || !strcmp(k, "profileget") ) { |
---|
[3942] | 1455 | i++; |
---|
| 1456 | if ( show_aiprofile(argv[i]) == -1 ) { |
---|
| 1457 | fprintf(stderr, "Error: can not get profile data\n"); |
---|
| 1458 | } |
---|
[0] | 1459 | } else { |
---|
| 1460 | fprintf(stderr, "Error: invalid command: %s\n", k); |
---|
| 1461 | } |
---|
| 1462 | |
---|
| 1463 | } |
---|
| 1464 | |
---|
| 1465 | roar_disconnect(&con); |
---|
| 1466 | |
---|
| 1467 | return 0; |
---|
| 1468 | } |
---|
| 1469 | |
---|
| 1470 | //ll |
---|