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