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