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