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