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