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