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