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