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