source: roaraudio/roarclients/roarctl.c @ 5386:a3dc37deacbb

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

only try to display mixer data as well as channel map if number of channels is in range for those functions

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