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