source: roaraudio/roarclients/roarctl.c @ 5387:ec00c0a72024

Last change on this file since 5387:ec00c0a72024 was 5387:ec00c0a72024, checked in by phi, 12 years ago

added function to get serverinfo for library as well as libinfo command for roarctl to list those infos

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