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