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