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