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