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