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