source: roaraudio/roard/roard.c @ 3597:aff3180d7325

Last change on this file since 3597:aff3180d7325 was 3597:aff3180d7325, checked in by phi, 14 years ago

corrected displayed list

File size: 49.8 KB
Line 
1//roard.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010
5 *
6 *  This file is part of roard 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#include "roard.h"
27
28#ifdef ROAR_SUPPORT_LISTEN
29char * server[ROAR_MAX_LISTEN_SOCKETS];
30#endif
31
32#if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_FS_POSIX)
33#define SUPPORT_PIDFILE
34char * pidfile = NULL;
35#endif
36
37#if defined(ROAR_HAVE_SETGID) || defined(ROAR_HAVE_SETUID)
38int    setids    = 0;
39#endif
40
41#ifdef ROAR_HAVE_LIBX11
42char * x11display = NULL;
43#endif
44
45#ifdef ROAR_HAVE_MAIN_ARGS
46void usage (void) {
47 printf("Usage: roard [OPTIONS]...\n\n");
48
49 printf("Misc Options:\n\n");
50 printf(
51        " --daemon              - Bring the server into background after init\n"
52        " --verbose             - Be more verbose, can be used multiple times\n"
53        " --terminate           - Terminate after last client quited\n"
54        " --start               - No op parameter (starting roard is default operation)\n"
55        " --restart             - Trys to stop an old instance and start a new with new settings\n"
56        " --stop                - Stops a running roard (provide --pidfile!)\n"
57        " --shutdown            - Terminates a running roard (provide --pidfile!)\n"
58        " --realtime            - Trys to get realtime priority,\n"
59        "                         give multible times for being more realtime\n"
60        " --chroot DIR          - chroots to the given dir\n"
61        " --setgid              - GroupID to the audio group as specified via -G\n"
62        " --setuid              - UserID to the audio user as specified via -U\n"
63        " --sysclocksync        - calculate exact sample rate using the system clock\n"
64        " --location  LOC       - Set lion readable location of server\n"
65#ifdef SUPPORT_PIDFILE
66        " --pidfile PIDFILE     - Write a pidfile at PIDFILE\n"
67#endif
68       );
69
70 printf("\nPlugin Options:\n\n");
71 printf(
72        " --plugin-load FILE    - Load plugin FILE\n"
73       );
74
75 printf("\nAudio Options:\n\n");
76 printf(
77        " -R  --rate   RATE     - Set server rate\n"
78        " -B  --bits   BITS     - Set server bits\n"
79        " -C  --chans  CHANNELS - Set server channels\n"
80       );
81
82 printf("\nStream Options:\n\n");
83 printf(
84        " --stream-flags D=F    - Set default flags for stream directions\n"
85        "                         D is the stream direction and F is a comma seperated\n"
86        "                         list of flags in form +flag or -flag to set or unset\n"
87        "                         a flag as default or remove it from the default\n"
88       );
89
90 printf("\nDriver Options: (obsolete, do not use, Use Ouput Options)\n\n");
91 printf(" -d  --driver DRV      - Set the driver (default: %s)\n", ROAR_DRIVER_DEFAULT);
92 printf(" -D  --device DEV      - Set the device\n");
93 printf(" -dO OPTS              - Set output options\n");
94 printf(" --list-driver         - List all drivers\n");
95
96 printf("\nOutput Options:\n\n");
97 printf(" -o  --odriver DRV     - Set the driver, use '--list-driver' to get a list\n");
98 printf(" -O  --odevice DEV     - Set the device\n");
99 printf(" -oO OPTS              - Set output options\n");
100 printf(" -oN                   - Adds another output\n");
101 printf(" -oP                   - Mark output as primary\n");
102
103#ifndef ROAR_WITHOUT_DCOMP_SOURCES
104 printf("\nSource Options:\n\n");
105 printf(" -s  --source DRV      - Use DRV as input driver\n"
106        " -S           DEV      - Use DEV as input device\n"
107        " -sO          OPTS     - Use OPTS as input options\n"
108        " -sN                   - Adds another source\n"
109        " -sP                   - Make souce as primary\n"
110       );
111 printf(" --list-sources        - List all sources\n");
112#endif
113
114 printf("\nCodec Filter Options:\n\n");
115 printf(" --list-cf             - List all codec filter\n"
116       );
117
118#ifndef ROAR_WITHOUT_DCOMP_MIDI
119 printf("\nMIDI Options:\n\n");
120 printf(" --midi-no-console     - Disable console based MIDI synth\n"
121        " --midi-console-enable - Enables the console based MIDI synth\n"
122        " --midi-console DEV    - Set device for MIDI console\n"
123#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
124        " --ssynth-enable       - Enable simple software synth\n"
125        " --ssynth-disable      - Disable simple software synth\n"
126#endif
127       );
128#endif
129
130#ifndef ROAR_WITHOUT_DCOMP_LIGHT
131 printf("\nLight Control Options:\n\n");
132 printf(" --light-channels NUM  - Sets the number of channels for Light control (default: %i)\n",
133                                  LIGHT_CHANNELS_DEFAULT
134       );
135#endif
136
137#ifndef ROAR_WITHOUT_DCOMP_RDTCS
138 printf("\nRadio Data and Transmitter Control System Options:\n\n");
139 printf(" --rds-pi   PI         - Sets the RDS Programme Identification (PI)\n"
140        " --rds-ps   PS         - Sets the RDS Programme Service Name (PS)\n"
141        " --rds-pty  PTY        - Sets the RDS Programme Type (PTY)\n"
142        " --rds-tp              - Sets the RDS Traffic Programme (TP) flag\n"
143        " --rds-ct              - Enables sending of RDS Clock Time (CT)\n"
144       );
145#endif
146
147#ifdef ROAR_HAVE_LIBX11
148 printf("\nX11 Options:\n\n");
149 printf(
150        " --x11-display DISPLAY - Set display for X11\n"
151        " --display DISPLAY     - Set display for X11\n"
152       );
153#endif
154
155 printf("\nServer Options:\n\n");
156 printf(" -t  --tcp             - Use TCP listen socket\n"
157        " -u  --unix            - Use UNIX Domain listen socket (default)\n"
158#ifdef ROAR_HAVE_LIBDNET
159        " -n  --decnet          - use DECnet listen socket\n"
160#endif
161        " -4                    - Use IPv4 connections (implies -t)\n"
162#ifdef PF_INET6
163        " -6                    - Use IPv6 connections (implies -t)\n"
164#endif
165#ifdef IPV6_ADDRFORM
166        " -64                   - Try to downgrade sockets from IPv6 into IPv4,\n"
167        "                         this is normaly not usefull.\n"
168#endif
169        " -p  --port            - TCP Port to bind to\n"
170        " -b  --bind            - IP/Hostname to bind to\n"
171        "     --sock            - Filename for UNIX Domain Socket\n"
172        "     --proto PROTO     - Use PROTO as protocol on Socket\n"
173        "     --proto-dir DIR   - Set direction parameter for protocol\n"
174        "     --proto-rate RATE - Set sample rate parameter for protocol\n"
175        "     --proto-bits BITS - Set bits per sample parameter for protocol\n"
176        "     --proto-codec E   - Set codec parameter for protocol\n"
177        "     --proto-chans C   - Set number of channels paramter for protocol\n"
178        "     --list-proto      - List supported protocols\n"
179        "     --new-sock        - Parameters for new socket follows\n"
180#ifdef ROAR_HAVE_LIBSLP
181        "     --slp             - Enable OpenSLP support\n"
182#endif
183#ifdef ROAR_HAVE_LIBX11
184        "     --x11             - Enable X11 support\n"
185#endif
186        " --jumbo-mtu MTU       - Sets the MTU for Jumbo Packets\n"
187        " -G  GROUP             - Sets the group for the UNIX Domain Socket, (default: %s)\n"
188        "                         You need the permissions to change the GID\n"
189        " -U  USER              - Sets the user for the UNIX Domain Socket, (default: do not set)\n"
190        "                         You need the permissions to change the UID (normaly only root has)\n"
191        " --no-listen           - Do not listen for new clients\n"
192        "                         (only usefull for relaing, impleys --terminate)\n"
193        " --client-fh           - Comunicate with a client over this handle\n"
194        "                         (only usefull for relaing)\n"
195        " --close-fh            - Closes the given fh\n"
196        " --standby             - Start in standby state\n"
197        " --auto-standby        - Automatical goes into standby if there are no streams\n",
198#ifdef ROAR_DEFAULT_SOCKGRP
199        ROAR_DEFAULT_SOCKGRP
200#else
201        "(none)"
202#endif
203       );
204// printf("\n Options:\n\n");
205 printf("\n");
206}
207
208static void list_proto (void) {
209 printf("  Protocol Flag Subsys - Description\n");
210 printf("------------------------------------------------------\n");
211 printf("  roar          WM LRX - RoarAudio native protocol\n");
212#if !defined(ROAR_WITHOUT_DCOMP_EMUL_ESD) && defined(ROAR_HAVE_H_ESD)
213 printf("  esd           W      - EsounD emulation\n");
214#endif
215#ifndef ROAR_MINIMAL
216 printf("  simple        WM LRX - PulseAudio simple protocol\n");
217#endif
218}
219
220#endif
221
222int restart_server (char * server, int terminate) {
223 struct roar_connection con;
224#ifdef ROAR_HAVE_KILL
225 char buf[80];
226 ssize_t l;
227 struct roar_vio_calls fh;
228 pid_t pid;
229 int ok;
230
231 if ( pidfile != NULL ) {
232  if ( roar_vio_open_file(&fh, pidfile, O_RDONLY, 0644) == -1 ) {
233   ROAR_WARN("restart_server(*): Can not read pidfile: %s", pidfile);
234  } else {
235   l = roar_vio_read(&fh, buf, 80);
236   roar_vio_close(&fh);
237   if ( l > 0 ) {
238    buf[l-1] = 0;
239    buf[79]  = 0;
240    pid = atoi(buf);
241    if ( terminate ) {
242     ok = kill(pid, SIGUSR1);
243    } else {
244     ok = kill(pid, SIGINT);
245    }
246    if ( ok == 0 ) {
247     return 0;
248    } else {
249     ROAR_WARN("restart_server(*): Can not kill roard by pidfile");
250    }
251   } else {
252    ROAR_WARN("restart_server(*): Can not find a PID in the pidfile");
253   }
254  }
255 }
256#endif
257
258 if ( roar_connect(&con, server) == -1 ) {
259  return -1;
260 }
261
262 if ( roar_terminate(&con, terminate) == -1 ) {
263  return -1;
264 }
265
266 return roar_disconnect(&con);
267}
268
269#define R_SETUID 1
270#define R_SETGID 2
271
272int init_config (void) {
273 int i;
274
275 memset(g_config, 0, sizeof(struct roard_config));
276
277 for (i = 0; i < ROAR_DIR_DIRIDS; i++) {
278  g_config->streams[i].mixer_channels = 1;
279  g_config->streams[i].mixer.rpg_mul  = 1;
280  g_config->streams[i].mixer.rpg_div  = 1;
281  g_config->streams[i].mixer.scale    = 65535;
282  g_config->streams[i].mixer.mixer[0] = g_config->streams[i].mixer.scale;
283 }
284
285 g_config->streams[ROAR_DIR_PLAY    ].flags = ROAR_FLAG_META;
286 g_config->streams[ROAR_DIR_OUTPUT  ].flags = ROAR_FLAG_PASSMIXER;
287 g_config->streams[ROAR_DIR_FILTER  ].flags = ROAR_FLAG_SYNC;
288 g_config->streams[ROAR_DIR_MIDI_OUT].flags = ROAR_FLAG_SYNC;
289 g_config->streams[ROAR_DIR_BIDIR   ].flags = ROAR_FLAG_ANTIECHO;
290
291 g_config->location = "***default***";
292
293 return 0;
294}
295
296#ifdef ROAR_SUPPORT_LISTEN
297int init_listening (void) {
298 int i;
299
300 memset(g_listen, 0, sizeof(g_listen));
301
302 for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
303  g_listen[i].socket = -1;
304  g_listen[i].proto  = ROAR_PROTO_ROARAUDIO;
305  server[i]          = NULL;
306 }
307
308 return 0;
309}
310
311int add_listen (char * addr, int port, int sock_type, char * user, char * group, int proto, int dir, struct roar_audio_info * info) {
312#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
313 struct group   * grp  = NULL;
314#endif
315#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
316 struct passwd  * pwd  = NULL;
317#endif
318#ifdef ROAR_HAVE_UNIX
319 char * env_roar_proxy_backup;
320#endif
321 int    sockid = -1;
322 int    sock;
323 int    i;
324
325 if ( *addr != 0 ) {
326  for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
327   if ( g_listen[i].socket == -1 ) {
328    sockid = i;
329    break;
330   }
331  }
332
333  if ( sockid == -1 )
334   return -1;
335
336  g_listen[sockid].proto = proto;
337
338  ROAR_DBG("add_listen(*): proto=0x%.4x", proto);
339
340  if ( (g_listen[sockid].socket = roar_socket_listen(sock_type, addr, port)) == -1 ) {
341#ifdef ROAR_HAVE_UNIX
342   if ( *addr == '/' ) {
343    if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) {
344     env_roar_proxy_backup = strdup(env_roar_proxy_backup);
345     unsetenv("ROAR_PROXY");
346    }
347    if ( (sock = roar_socket_connect(addr, port)) != -1 ) {
348     close(sock);
349     ROAR_ERR("Can not open listen socket: Socket allready in use");
350     return 1;
351    } else {
352     unlink(addr);
353     if ( (g_listen[sockid].socket = roar_socket_listen(sock_type, addr, port)) == -1 ) {
354      ROAR_ERR("Can not open listen socket: %s", strerror(errno));
355      return 1;
356     }
357    }
358    if ( env_roar_proxy_backup != NULL ) {
359     setenv("ROAR_PROXY", env_roar_proxy_backup, 0);
360     free(env_roar_proxy_backup);
361    }
362#else
363   if (0) { // noop
364#endif
365   } else {
366    ROAR_ERR("Can not open listen socket: %s", strerror(errno));
367    return 1;
368   }
369  }
370
371#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
372  if ( group != NULL ) {
373   if ( (grp = getgrnam(group)) == NULL ) {
374    ROAR_ERR("Can not get GID for group %s: %s", group, strerror(errno));
375   }
376  }
377#endif
378#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
379  if ( user ) {
380   if ( (pwd = getpwnam(user)) == NULL ) {
381    ROAR_ERR("Can not get UID for user %s: %s", user, strerror(errno));
382   }
383  }
384#endif
385
386#if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_UNIX)
387  if ( *addr == '/' ) {
388   if ( grp || pwd ) {
389     if ( chown(addr, pwd ? pwd->pw_uid : -1, grp ? grp->gr_gid : -1) == -1 )
390      return 1;
391   }
392#ifdef ROAR_HAVE_GETUID
393   if ( grp ) {
394    if ( getuid() == 0 )
395     if ( chmod(addr, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1 )
396      return 1;
397   }
398#endif
399  }
400#endif
401 }
402
403 // in case we opened the listening socket correctly.
404 if ( dir == -1 )
405  dir = ROAR_DIR_PLAY;
406
407 g_listen[sockid].inst.stpl.dir = dir;
408 memcpy(&(g_listen[sockid].inst.stpl.info), info, sizeof(struct roar_audio_info));
409
410 switch (dir) {
411  case ROAR_DIR_PLAY:
412  case ROAR_DIR_RECORD:
413  case ROAR_DIR_MONITOR:
414  case ROAR_DIR_FILTER:
415  case ROAR_DIR_BIDIR:
416    if ( !g_listen[sockid].inst.stpl.info.rate )
417     g_listen[sockid].inst.stpl.info.rate = g_sa->rate;
418
419    if ( !g_listen[sockid].inst.stpl.info.bits )
420     g_listen[sockid].inst.stpl.info.bits = g_sa->bits;
421
422    if ( !g_listen[sockid].inst.stpl.info.channels )
423     g_listen[sockid].inst.stpl.info.channels = g_sa->channels;
424
425    if ( !g_listen[sockid].inst.stpl.info.codec )
426     g_listen[sockid].inst.stpl.info.codec = g_sa->codec;
427   break;
428 }
429
430 server[sockid] = addr;
431 return 0;
432}
433#endif
434
435int update_stream_flags (char * str) {
436 int    dir;
437 char * flags;
438 char * k;
439 int    op;
440 int    flag;
441
442 if ( (flags = strstr(str, "=")) == NULL )
443  return -1;
444
445 *flags = 0;
446  flags++;
447
448 if ( (dir = roar_str2dir(str)) == -1 )
449  return -1;
450
451 while (flags != NULL) {
452  k = flags;
453  flags = strstr(flags, ",");
454
455  if ( flags != NULL )
456   *(flags++) = 0;
457
458  switch (*k) {
459   case '+': k++; op = ROAR_SET_FLAG;   break;
460   case '-': k++; op = ROAR_RESET_FLAG; break;
461   default:
462     op = ROAR_SET_FLAG;
463  }
464
465  flag = 0;
466
467  if ( !strcmp(k, "sync") ) {
468   flag = ROAR_FLAG_SYNC;
469  } else if ( !strcmp(k, "meta") ) {
470   flag = ROAR_FLAG_META;
471  } else if ( !strcmp(k, "cleanmeta") ) {
472   flag = ROAR_FLAG_CLEANMETA;
473  } else if ( !strcmp(k, "pause") ) {
474   flag = ROAR_FLAG_PAUSE;
475  } else if ( !strcmp(k, "mute") ) {
476   flag = ROAR_FLAG_MUTE;
477  } else if ( !strcmp(k, "antiecho") ) {
478   flag = ROAR_FLAG_ANTIECHO;
479  } else if ( !strcmp(k, "passmixer") ) {
480   flag = ROAR_FLAG_PASSMIXER;
481  } else {
482   return -1;
483  }
484
485  g_config->streams[dir].flags |= flag;
486
487  if ( op == ROAR_RESET_FLAG )
488   g_config->streams[dir].flags -= flag;
489 }
490
491 return 0;
492}
493
494int add_output (char * drv, char * dev, char * opts, int prim, int count) {
495 int stream;
496 struct roar_stream * s;
497 struct roar_stream_server * ss;
498 char * k, * v;
499#ifdef ROAR_DRIVER_CODEC
500 char * to_free = NULL;
501#endif
502 int sync = 0, f_mmap = 0;
503 int32_t blocks = -1, blocksize = -1;
504 int dir = ROAR_DIR_OUTPUT;
505 int error = 0;
506 // DMX:
507 int32_t channel  = -1;
508 int32_t universe = -1;
509 uint16_t tu16;
510 float q = -32e6;
511
512 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
513
514 if ( drv == NULL && count == 0 ) {
515  drv  = ROAR_DRIVER_DEFAULT;
516  prim = 1;
517  sync = 1;
518
519#ifdef ROAR_DRIVER_CODEC
520  if ( opts == NULL ) {
521   opts = to_free = strdup("codec=" ROAR_DRIVER_CODEC);
522  }
523#endif
524 }
525
526 if ( opts == NULL && count == 0 ) {
527  sync = 1;
528  prim = 1; // if ( prim == 0 ) prim = 1; -> prim allways = 1
529 }
530
531 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
532
533 if ( (stream = streams_new()) == -1 ) {
534  ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts);
535  if ( prim ) alive = 0;
536  return -1;
537 }
538
539 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
540
541 streams_get(stream, &ss);
542 s = ROAR_STREAM(ss);
543
544 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
545
546 memset(&(s->info), 0xFF, sizeof(struct roar_audio_info)); // set everything to -1
547
548 s->pos_rel_id = -1;
549// s->info.codec = codec;
550
551 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
552
553 if ( opts == NULL ) {
554  k = NULL;
555 } else {
556  k = strtok(opts, ",");
557 }
558
559 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s'): initial k='%s'(%p)", drv, dev, opts, k, k);
560
561 while (k != NULL) {
562//  ROAR_WARN("add_output(*): opts: %s", k);
563
564  if ( (v = strstr(k, "=")) != NULL ) {
565   *v++ = 0;
566  }
567
568  ROAR_DBG("add_output(*): opts: k='%s', v='%s'", k, v);
569  if ( strcmp(k, "rate") == 0 ) {
570   s->info.rate = atoi(v);
571  } else if ( strcmp(k, "channels") == 0 ) {
572   s->info.channels = atoi(v);
573  } else if ( strcmp(k, "bits") == 0 ) {
574   s->info.bits = atoi(v);
575  } else if ( strcmp(k, "codec") == 0 ) {
576   if ( (s->info.codec = roar_str2codec(v)) == -1 ) {
577    ROAR_ERR("add_output(*): unknown codec '%s'", v);
578    error++;
579   }
580  } else if ( strcmp(k, "q") == 0 ) {
581   q = atof(v);
582  } else if ( strcmp(k, "blocks") == 0 ) {
583   blocks = atoi(v);
584  } else if ( strcmp(k, "blocksize") == 0 ) {
585   blocksize = atoi(v);
586  } else if ( strcmp(k, "mmap") == 0 ) {
587   f_mmap = 1;
588  } else if ( strcmp(k, "subsystem") == 0 ) {
589   if ( !strcasecmp(v, "wave") || !strcasecmp(v, "waveform") ) {
590    dir = ROAR_DIR_OUTPUT;
591#ifndef ROAR_WITHOUT_DCOMP_MIDI
592   } else if ( !strcasecmp(v, "midi") ) {
593    dir = ROAR_DIR_MIDI_OUT;
594#endif
595#ifndef ROAR_WITHOUT_DCOMP_LIGHT
596   } else if ( !strcasecmp(v, "light") ) {
597    dir = ROAR_DIR_LIGHT_OUT;
598#endif
599#ifndef ROAR_WITHOUT_DCOMP_RAW
600   } else if ( !strcasecmp(v, "raw") ) {
601    dir = ROAR_DIR_RAW_OUT;
602#endif
603   } else if ( !strcasecmp(v, "complex") ) {
604    dir = ROAR_DIR_COMPLEX_OUT;
605   } else {
606    ROAR_ERR("add_output(*): unknown/unsupported subsystem '%s'", k);
607    error++;
608   }
609  // DMX:
610  } else if ( strcmp(k, "channel") == 0 ) {
611   channel  = atoi(v);
612   if ( channel < 0 || channel > 65535 ) {
613    ROAR_ERR("add_output(*): Invalide channel (not within 0..65535): %i", channel);
614    channel = -1;
615    error++;
616   }
617  } else if ( strcmp(k, "universe") == 0 ) {
618   universe = atoi(v);
619   if ( universe < 0 || universe > 255 ) {
620    ROAR_ERR("add_output(*): Invalide universe (not within 0..255): %i", universe);
621    universe = -1;
622    error++;
623   }
624
625  } else if ( strcmp(k, "name") == 0 ) {
626   if ( streams_set_name(stream, v) == -1 ) {
627    ROAR_ERR("add_output(*): Can not set Stream name");
628    error++;
629   }
630
631  } else if ( strcmp(k, "meta") == 0 ) {
632   streams_set_flag(stream, ROAR_FLAG_META);
633  } else if ( strcmp(k, "sync") == 0 ) {
634   sync = 1;
635  } else if ( strcmp(k, "primary") == 0 ) {
636   prim = 1;
637
638  } else if ( strcmp(k, "cleanmeta") == 0 ) {
639   streams_set_flag(stream, ROAR_FLAG_CLEANMETA);
640  } else if ( strcmp(k, "autoconf") == 0 ) {
641   streams_set_flag(stream, ROAR_FLAG_AUTOCONF);
642  } else if ( strcmp(k, "recsource") == 0 ) {
643   streams_set_flag(stream, ROAR_FLAG_RECSOURCE);
644  } else if ( strcmp(k, "passmixer") == 0 ) {
645   streams_set_flag(stream, ROAR_FLAG_PASSMIXER);
646  } else {
647   ROAR_ERR("add_output(*): unknown option '%s'", k);
648   error++;
649  }
650
651  if ( error ) {
652   streams_delete(stream);
653   if ( prim ) alive = 0;
654#ifdef ROAR_DRIVER_CODEC
655   if ( to_free != NULL )
656    free(to_free);
657#endif
658   return -1;
659  }
660
661  k = strtok(NULL, ",");
662 }
663
664 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
665
666 // set audio info...
667 switch (dir) {
668  case ROAR_DIR_LIGHT_OUT:
669    switch (s->info.codec) {
670     case ROAR_CODEC_DMX512:
671     case -1:
672       if ( s->info.rate == -1 )
673        s->info.rate = ROAR_OUTPUT_CFREQ;
674
675       s->info.channels =   0;
676       s->info.bits     =   8;
677       s->info.codec    = ROAR_CODEC_DMX512; // in case codec == -1
678      break;
679    }
680   break;
681  case ROAR_DIR_MIDI_OUT:
682    switch (s->info.codec) {
683     case ROAR_CODEC_MIDI:
684     case -1:
685       if ( s->info.rate == -1 )
686        s->info.rate    = ROAR_MIDI_TICKS_PER_BEAT;
687
688       s->info.channels = ROAR_MIDI_CHANNELS_DEFAULT;
689       s->info.bits     = ROAR_MIDI_BITS;
690       s->info.codec    = ROAR_CODEC_MIDI; // in case codec == -1
691      break;
692    }
693   break;
694  case ROAR_DIR_RAW_OUT:
695    if ( s->info.rate == -1 )
696     s->info.rate = 0;
697    if ( s->info.bits == -1 )
698     s->info.bits = 0;
699    if ( s->info.channels == -1 )
700     s->info.channels = 0;
701    if ( s->info.codec == -1 )
702     s->info.codec = 0;
703   break;
704 }
705
706 if ( s->info.rate == -1 )
707  s->info.rate = g_sa->rate;
708 if ( s->info.bits == -1 )
709  s->info.bits = g_sa->bits;
710 if ( s->info.channels == -1 )
711  s->info.channels = g_sa->channels;
712 if ( s->info.codec == -1 )
713  s->info.codec = g_sa->codec;
714
715 ROAR_DBG("add_output(*): s->info = {.rate=%i, .bits=%i, .channels=%i, .codec=%i}", s->info.rate, s->info.bits, s->info.channels, s->info.codec);
716
717 if ( streams_set_dir(stream, dir, 1) == -1 ) {
718  streams_delete(stream);
719  return -1;
720 }
721
722#ifdef ROAR_DRIVER_CODEC
723 if ( to_free != NULL )
724  free(to_free);
725#endif
726
727 if ( s->info.codec == ROAR_CODEC_ALAW || s->info.codec == ROAR_CODEC_MULAW )
728  s->info.bits = 8; // needed to open OSS driver, will be overriden by codecfilter
729
730 ROAR_STREAM_SERVER(s)->codec_orgi = s->info.codec;
731
732 if ( driver_openvio(&(ss->vio), &(ss->driver_id), drv, dev, &(s->info), -1, ss) == -1 ) {
733  ss->driver_id = -1; // don't close a driver not opened...
734  memset(&(ss->vio), 0, sizeof(struct roar_vio_calls));
735  streams_delete(stream);
736  ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts);
737  if ( prim ) alive = 0;
738  return -1;
739 }
740
741 roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAMID, &stream); // ignore errors here
742 roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAM,   s); // ignore errors here
743
744 if ( blocks != -1 )
745  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLOCKS, &blocks);
746
747 if ( blocksize != -1 )
748  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLKSIZE, &blocksize);
749
750 // TODO: we shoudld *really* check for errors here...
751 if ( channel != -1 ) {
752  tu16 = channel;
753  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXSCHAN, &tu16);
754 }
755 if ( universe != -1 ) {
756  tu16 = universe;
757  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXUNIV, &tu16);
758 }
759
760 ROAR_DBG("add_output(*): ss->driver_id=%i", ss->driver_id);
761
762 streams_set_fh(stream, -1); // update some internal structures
763
764 if ( q > -1e6 ) {
765  ROAR_DBG("add_output(*): setting q=%f", q);
766  streams_ctl(stream, ROAR_CODECFILTER_CTL_SET_Q|ROAR_STREAM_CTL_TYPE_FLOAT, &q);
767 }
768
769 client_stream_add(g_self_client, stream);
770
771 if ( prim ) {
772  streams_mark_primary(stream);
773  s->pos_rel_id = stream;
774 }
775
776 if ( sync ) {
777  streams_set_flag(stream, ROAR_FLAG_SYNC);
778 } else {
779  streams_reset_flag(stream, ROAR_FLAG_SYNC);
780 }
781
782 if ( f_mmap )
783  streams_set_flag(stream, ROAR_FLAG_MMAP);
784
785 ROAR_DBG("add_output(*): s->info = {.rate=%i, .bits=%i, .channels=%i, .codec=%i}", s->info.rate, s->info.bits, s->info.channels, s->info.codec);
786 return 0;
787}
788
789// X11:
790#ifdef ROAR_HAVE_LIBX11
791int register_x11 (int unreg, char * sockname) {
792 struct roar_x11_connection * x11con = NULL;
793 int ret = 0;
794
795 if ( (x11con = roar_x11_connect(x11display)) == NULL )
796  return -1;
797
798 if ( unreg ) {
799  if ( roar_x11_delete_prop(x11con, "ROAR_SERVER") == -1 )
800   ret = -1;
801 } else {
802  if ( roar_x11_set_prop(x11con, "ROAR_SERVER", sockname) == -1 )
803   ret = -1;
804 }
805
806 roar_x11_disconnect(x11con);
807
808 return ret;
809}
810#endif
811
812// SLP:
813void register_slp_callback(SLPHandle hslp, SLPError errcode, void * cookie) {
814 /* return the error code in the cookie */
815 *(SLPError*)cookie = errcode;
816}
817
818int register_slp (int unreg, char * sockname) {
819#ifdef ROAR_HAVE_LIBSLP
820 static int regged = 0;
821 static char * sn = NULL;
822 SLPError err;
823 SLPError callbackerr;
824 SLPHandle hslp;
825 char addr[1024];
826 char attr[1024] = "";
827 char * location;
828
829 if ( sockname != NULL )
830  sn = sockname;
831
832 snprintf(addr, sizeof(addr), ROAR_SLP_URL_TYPE_ROAR "://%s", sn);
833
834 err = SLPOpen("en", SLP_FALSE, &hslp);
835
836 if (err != SLP_OK) {
837  ROAR_ERR("Error opening slp handle: Error #%i", err);
838  return -1;
839 }
840
841 if (!unreg) {
842
843  if ( SLPEscape(g_config->location, &location, SLP_FALSE) != SLP_OK ) {
844   ROAR_ERR("Error using SLPEscape() on server location, really bad!");
845   SLPClose(hslp);
846   return -1;
847  }
848
849  snprintf(attr, sizeof(attr), "(wave-rate=%i),(wave-channels=%i),(wave-bits=%i),"
850#ifndef ROAR_WITHOUT_DCOMP_LIGHT
851                               "(light-channels=%i),"
852#endif
853                               "(location=%s)",
854           g_sa->rate, g_sa->channels, g_sa->bits,
855#ifndef ROAR_WITHOUT_DCOMP_LIGHT
856           g_light_state.channels,
857#endif
858           location
859          );
860
861  /* Register a service with SLP */
862  err = SLPReg(hslp,
863               addr,
864               SLP_LIFETIME_MAXIMUM,
865               0,
866               attr,
867               SLP_TRUE,
868               register_slp_callback,
869               &callbackerr);
870  regged = 1;
871 } else if ( unreg && regged ) {
872  err = SLPDereg(hslp, addr, register_slp_callback, &callbackerr);
873  regged = 0;
874 } else {
875  SLPClose(hslp);
876  return -1;
877 }
878
879 /* err may contain an error code that occurred as the slp library    */
880 /* _prepared_ to make the call.                                     */
881 if ( err != SLP_OK ) {
882  ROAR_ERR("Error (de)registering service with slp: Error #%i", err);
883  return -1;
884 }
885
886 /* callbackerr may contain an error code (that was assigned through */
887 /* the callback cookie) that occurred as slp packets were sent on    */
888 /* the wire */
889 if (callbackerr != SLP_OK) {
890  ROAR_ERR("Error (de)registering service with slp: Error #%i", callbackerr);
891  return -1;
892 }
893
894 SLPClose(hslp);
895 return 0;
896#else
897 return -1;
898#endif
899}
900
901
902// MAIN:
903
904#ifdef ROAR_HAVE_MAIN_ARGS
905int main (int argc, char * argv[]) {
906#else
907int main (void) {
908#endif
909#ifdef ROAR_HAVE_MAIN_ARGS
910 int i;
911 char * k;
912#endif
913#if defined(ROAR_SUPPORT_LISTEN) && defined(ROAR_HAVE_GETUID)
914 char user_sock[80]  = {0};
915#endif
916 struct roar_audio_info sa, max_sa;
917 struct roard_config config;
918#ifdef ROAR_HAVE_FORK
919 int    daemon       = 0;
920#endif
921 int    realtime     = 0;
922 int    sysclocksync = 0;
923 char * driver    = NULL;
924 char * device    = NULL;
925#ifdef ROAR_HAVE_MAIN_ARGS
926 char * opts      = NULL;
927#endif
928// char * server = ROAR_DEFAULT_SOCK_GLOBAL;
929#ifdef ROAR_SUPPORT_LISTEN
930 int    port       = ROAR_DEFAULT_PORT;
931 char * sock_addr  = NULL;
932 int    sock_proto = ROAR_PROTO_ROARAUDIO;
933 int    sock_dir   = -1;
934 struct roar_audio_info sock_info = {0, 0, 0, 0};
935#endif
936 int               drvid;
937#ifndef ROAR_WITHOUT_DCOMP_SOURCES
938 char * s_drv     = "cf";
939 char * s_dev     = NULL;
940 char * s_con     = NULL;
941 char * s_opt     = NULL;
942 int    s_prim    = 0;
943#endif
944 char * o_drv     = getenv("ROAR_DRIVER");
945 char * o_dev     = getenv("ROAR_DEVICE");
946 char * o_opts    = NULL;
947 int    o_prim    = 0;
948 int    o_count   = 0;
949#ifndef ROAR_WITHOUT_DCOMP_LIGHT
950 int    light_channels = LIGHT_CHANNELS_DEFAULT;
951#endif
952#ifdef ROAR_DEFAULT_SOCKGRP
953 char * sock_grp  = ROAR_DEFAULT_SOCKGRP;
954#else
955 char * sock_grp  = NULL;
956#endif
957 char * sock_user = NULL;
958#ifdef ROAR_SUPPORT_LISTEN
959 int    sock_type = ROAR_SOCKET_TYPE_UNKNOWN;
960#endif
961#ifdef ROAR_HAVE_LIBSLP
962 int    reg_slp   = 0;
963#endif
964#ifdef ROAR_HAVE_LIBX11
965 int    reg_x11   = 0;
966#endif
967#ifdef ROAR_HAVE_CHROOT
968 char * chrootdir = NULL;
969#endif
970#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
971 struct group   * grp  = NULL;
972#endif
973#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
974 struct passwd  * pwd  = NULL;
975#endif
976#ifdef ROAR_HAVE_GETSERVBYNAME
977 struct servent * serv = NULL;
978#endif
979 DRIVER_USERDATA_T drvinst;
980 struct roar_client * self = NULL;
981#ifdef ROAR_HAVE_LIBDNET
982 char decnethost[80];
983#endif
984#ifdef SUPPORT_PIDFILE
985 struct roar_vio_calls pidfile_vio;
986#endif
987
988 ROAR_DBG("main(*): starting roard...");
989
990 g_standby       =  0;
991 g_autostandby   =  0;
992 alive           =  1;
993#ifdef ROAR_SUPPORT_LISTEN
994 g_no_listen     =  0;
995#else
996 g_terminate     =  1;
997#endif
998
999 g_verbose       = ROAR_DBG_INFO_NONE;
1000
1001 sa.bits     = ROAR_BITS_DEFAULT;
1002 sa.channels = ROAR_CHANNELS_DEFAULT;
1003 sa.rate     = ROAR_RATE_DEFAULT;
1004 sa.codec    = ROAR_CODEC_DEFAULT;
1005
1006 g_sa        = &sa;
1007 g_max_sa    = &max_sa;
1008
1009 memcpy(g_max_sa, g_sa, sizeof(max_sa));
1010
1011 g_config = &config;
1012
1013 if ( init_config() == -1 ) {
1014  ROAR_ERR("Can not init default config!");
1015  return 1;
1016 }
1017
1018 // load config
1019 roar_libroar_get_config();
1020
1021#ifdef ROAR_SUPPORT_LISTEN
1022 if ( init_listening() == -1 ) {
1023  ROAR_ERR("Can not init listening sockets!");
1024  return 1;
1025 }
1026#endif
1027
1028#ifndef ROAR_WITHOUT_DCOMP_MIDI
1029 if ( midi_init_config() == -1 ) {
1030  ROAR_ERR("Can not init MIDI config!");
1031  return 1;
1032 }
1033#endif
1034
1035#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
1036 if ( ssynth_init_config() == -1 ) {
1037  ROAR_ERR("Can not init ssynth config!");
1038  return 1;
1039 }
1040#endif
1041
1042#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1043 if ( rdtcs_init_config() == -1 ) {
1044  ROAR_ERR("Can not init RDTCS config!");
1045  return 1;
1046 }
1047#endif
1048
1049 if ( plugins_preinit() == -1 ) {
1050  ROAR_ERR("Can not pre-init plugins!");
1051  return 1;
1052 }
1053
1054#ifdef ROAR_SUPPORT_LISTEN
1055#ifndef ROAR_TARGET_WIN32
1056 sock_addr = ROAR_DEFAULT_SOCK_GLOBAL;
1057#else
1058 sock_addr = ROAR_DEFAULT_HOST;
1059#endif
1060
1061#ifdef ROAR_HAVE_GETUID
1062 if ( getuid() != 0 && getenv("HOME") != NULL ) {
1063  snprintf(user_sock, 79, "%s/%s", (char*)getenv("HOME"), ROAR_DEFAULT_SOCK_USER);
1064  sock_addr = user_sock;
1065 }
1066#endif
1067
1068 if ( getenv("ROAR_SERVER") != NULL )
1069  sock_addr = getenv("ROAR_SERVER");
1070#endif
1071
1072 if ( clients_init() == -1 ) {
1073  ROAR_ERR("Can not init clients!");
1074  return 1;
1075 }
1076
1077 if ( streams_init() == -1 ) {
1078  ROAR_ERR("Can not init streams!");
1079  return 1;
1080 }
1081
1082 if ( (g_self_client = clients_new()) == -1 ) {
1083  ROAR_ERR("Can not create self client!");
1084  return 1;
1085 }
1086
1087#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1088 if ( sources_init() == -1 ) {
1089  ROAR_ERR("Can not init sources!");
1090  return 1;
1091 }
1092
1093 if ( (sources_set_client(g_self_client)) == -1 ) {
1094  ROAR_ERR("Can not init set source client!");
1095  return 1;
1096 }
1097#endif
1098
1099#ifdef ROAR_HAVE_MAIN_ARGS
1100 for (i = 1; i < argc; i++) {
1101  k = argv[i];
1102
1103  if ( strcmp(k, "-h") == 0 || strcmp(k, "--help") == 0 ) {
1104   usage();
1105   return 0;
1106
1107  } else if ( strcmp(k, "--start") == 0 ) {
1108   // this is a no op
1109  } else if ( strcmp(k, "--restart") == 0 ) {
1110#ifdef ROAR_SUPPORT_LISTEN
1111   if ( restart_server(sock_addr, 1) == -1 ) {
1112    ROAR_WARN("Can not terminate old server (not running at %s?), tring to continue anyway", sock_addr);
1113   }
1114#else
1115   ROAR_ERR("--restart not supported");
1116#endif
1117  } else if ( strcmp(k, "--shutdown") == 0 ) {
1118#ifdef ROAR_SUPPORT_LISTEN
1119   if ( restart_server(sock_addr, 1) == -1 ) {
1120    ROAR_WARN("Can not terminate old server (not running at %s?)", sock_addr);
1121    return 1;
1122   }
1123   return 0;
1124#else
1125   ROAR_ERR("--shutdown not supported");
1126   return 1;
1127#endif
1128  } else if ( strcmp(k, "--stop") == 0 ) {
1129#ifdef ROAR_SUPPORT_LISTEN
1130   if ( restart_server(sock_addr, 0) == -1 ) {
1131    ROAR_WARN("Can not stop old server (not running at %s?)", sock_addr);
1132    return 1;
1133   }
1134   return 0;
1135#else
1136   ROAR_ERR("--stop not supported");
1137   return 1;
1138#endif
1139
1140
1141  } else if ( strcmp(k, "--demon") == 0 || strcmp(k, "--daemon") == 0 ) {
1142#ifdef ROAR_HAVE_FORK
1143   daemon = 1;
1144#else
1145   ROAR_ERR("--daemon not supported");
1146#endif
1147  } else if ( strcmp(k, "--verbose") == 0 ) {
1148   g_verbose++;
1149  } else if ( strcmp(k, "--terminate") == 0 ) {
1150   g_terminate = 1;
1151  } else if ( strcmp(k, "--sysclocksync") == 0 ) {
1152   sysclocksync = 1000;
1153  } else if ( strcmp(k, "--realtime") == 0 ) {
1154   realtime++;
1155  } else if ( strcmp(k, "--chroot") == 0 ) {
1156#ifdef ROAR_HAVE_CHROOT
1157   chrootdir = argv[++i];
1158#else
1159   ROAR_ERR("--chroot not supported");
1160   i++;
1161#endif
1162  } else if ( strcmp(k, "--setgid") == 0 ) {
1163#ifdef ROAR_HAVE_SETGID
1164   setids |= R_SETGID;
1165#else
1166   ROAR_ERR("--setgid not supported");
1167#endif
1168  } else if ( strcmp(k, "--setuid") == 0 ) {
1169#ifdef ROAR_HAVE_SETUID
1170   setids |= R_SETUID;
1171#else
1172   ROAR_ERR("--setuid not supported");
1173#endif
1174  } else if ( strcmp(k, "--location") == 0 ) {
1175   g_config->location = argv[++i];
1176  } else if ( strcmp(k, "--pidfile") == 0 ) {
1177#ifdef SUPPORT_PIDFILE
1178   pidfile = argv[++i];
1179#else
1180   ROAR_ERR("--pidfile not supported");
1181   i++;
1182#endif
1183
1184  } else if ( strcmp(k, "--plugin-load") == 0 ) {
1185   if ( plugins_load(argv[++i]) == -1 ) {
1186    ROAR_ERR("Can not load plugin");
1187   }
1188
1189  } else if ( strcmp(k, "--list-cf") == 0 ) {
1190   print_codecfilterlist();
1191   return 0;
1192
1193  } else if ( strcmp(k, "-R") == 0 || strcmp(k, "--rate") == 0 ) {
1194   sa.rate = atoi(argv[++i]);
1195  } else if ( strcmp(k, "-B") == 0 || strcmp(k, "--bits") == 0 ) {
1196   sa.bits = atoi(argv[++i]);
1197  } else if ( strcmp(k, "-C") == 0 || strcmp(k, "--chans") == 0 ) {
1198   sa.channels = atoi(argv[++i]);
1199
1200  } else if ( strcmp(k, "--stream-flags") == 0 ) {
1201   if ( update_stream_flags(argv[++i]) == -1 ) {
1202    ROAR_ERR("Can not set stream flags");
1203    return 1;
1204   }
1205
1206  } else if ( strcmp(k, "-d") == 0 || strcmp(k, "--driver") == 0 ) {
1207   driver = argv[++i];
1208   if ( strcmp(driver, "list") == 0 ) {
1209    ROAR_WARN("The option is obsolete, use --list-driver!");
1210    print_driverlist();
1211    return 0;
1212   }
1213  } else if ( strcmp(k, "-D") == 0 || strcmp(k, "--device") == 0 ) {
1214   device = argv[++i];
1215  } else if ( strcmp(k, "-dO") == 0 ) {
1216   opts = argv[++i];
1217  } else if ( strcmp(k, "--list-driver") == 0 ) {
1218   print_driverlist();
1219   return 0;
1220
1221  } else if ( strcmp(k, "-o") == 0 || strcmp(k, "--odriver") == 0 ) {
1222   o_drv  = argv[++i];
1223  } else if ( strcmp(k, "-O") == 0 || strcmp(k, "--odevice") == 0 ) {
1224   o_dev  = argv[++i];
1225  } else if ( strcmp(k, "-oO") == 0 ) {
1226   o_opts = argv[++i];
1227  } else if ( strcmp(k, "-oP") == 0 ) {
1228   o_prim = 1;
1229  } else if ( strcmp(k, "-oN") == 0 ) {
1230   if ( add_output(o_drv, o_dev, o_opts, o_prim, o_count) != -1 )
1231    o_count++;
1232
1233   o_drv  = o_dev = o_opts = NULL;
1234   o_prim = 0;
1235
1236  } else if ( strcmp(k, "-s") == 0 || strcmp(k, "--source") == 0 ) {
1237#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1238   s_drv = argv[++i];
1239#else
1240   ROAR_ERR("main(*): No support for sources compiled in");
1241#endif
1242  } else if ( strcmp(k, "-S") == 0 ) {
1243#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1244   s_dev = argv[++i];
1245#else
1246   ROAR_ERR("main(*): No support for sources compiled in");
1247#endif
1248  } else if ( strcmp(k, "-sO") == 0 ) {
1249#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1250   s_opt = argv[++i];
1251#else
1252   ROAR_ERR("main(*): No support for sources compiled in");
1253#endif
1254  } else if ( strcmp(k, "-sC") == 0 ) {
1255#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1256   s_con = argv[++i];
1257#else
1258   ROAR_ERR("main(*): No support for sources compiled in");
1259#endif
1260  } else if ( strcmp(k, "-sP") == 0 ) {
1261#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1262   s_prim = 1;
1263#else
1264   ROAR_ERR("main(*): No support for sources compiled in");
1265#endif
1266  } else if ( strcmp(k, "-sN") == 0 ) {
1267#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1268   if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) {
1269    ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv);
1270   }
1271   s_opt = s_dev = s_con = NULL;
1272   s_drv = "cf";
1273   s_prim = 0;
1274#else
1275   ROAR_ERR("main(*): No support for sources compiled in");
1276#endif
1277  } else if ( strcmp(k, "--list-sources") == 0 ) {
1278#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1279   print_sourcelist();
1280   return 0;
1281#else
1282   ROAR_ERR("main(*): No support for sources compiled in");
1283   return 1;
1284#endif
1285
1286  } else if ( strcmp(k, "--light-channels") == 0 ) {
1287#ifndef ROAR_WITHOUT_DCOMP_LIGHT
1288   light_channels = atoi(argv[++i]);
1289#else
1290   ROAR_WARN("main(*): no light subsystem compiled in");
1291#endif
1292
1293  } else if ( strcmp(k, "--rds-pi") == 0 ) {
1294#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1295   g_rdtcs.rds.pi = atoi(argv[++i]);
1296#else
1297   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
1298#endif
1299  } else if ( strcmp(k, "--rds-ps") == 0 ) {
1300#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1301   if ( rdtcs_rds_set_ps(argv[++i]) == -1 ) {
1302    ROAR_ERR("Can not set RDS PS to '%s' (longer than 8 chars?)", argv[i]);
1303    return 1;
1304   }
1305#else
1306   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
1307#endif
1308  } else if ( strcmp(k, "--rds-pty") == 0 ) {
1309#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1310   if ( rdtcs_rds_set_pty(argv[++i]) == -1 ) {
1311    ROAR_ERR("Can not set RDS PTY to '%s'", argv[i]);
1312    return 1;
1313   }
1314#else
1315   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
1316#endif
1317  } else if ( strcmp(k, "--rds-tp") == 0 ) {
1318#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1319   if ( rdtcs_rds_set_flag(RDTCS_RDS_FLAG_TP, 0) == -1 ) {
1320    ROAR_ERR("Can not set RDS TP flag");
1321    return 1;
1322   }
1323#else
1324   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
1325#endif
1326  } else if ( strcmp(k, "--rds-ct") == 0 ) {
1327#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1328   if ( rdtcs_rds_set_flag(RDTCS_RDS_FLAG_CT, 0) == -1 ) {
1329    ROAR_ERR("Can not set RDS CT flag");
1330    return 1;
1331   }
1332#else
1333   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
1334#endif
1335
1336
1337  } else if ( strcmp(k, "--midi-no-console") == 0 ) {
1338#ifndef ROAR_WITHOUT_DCOMP_CB
1339   midi_config.init_cb = 0;
1340#else
1341   // no warning here as this is the disable option
1342#endif
1343  } else if ( strcmp(k, "--midi-console-enable") == 0 ) {
1344#ifndef ROAR_WITHOUT_DCOMP_CB
1345   midi_config.init_cb = 1;
1346#else
1347   ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in");
1348#endif
1349  } else if ( strcmp(k, "--midi-console") == 0 ) {
1350#ifndef ROAR_WITHOUT_DCOMP_CB
1351   midi_config.console_dev = argv[++i];
1352   midi_config.init_cb = 1;
1353#else
1354   ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in");
1355#endif
1356
1357  } else if ( strcmp(k, "--ssynth-enable") == 0 ) {
1358#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
1359   ssynth_conf.enable = 1;
1360#else
1361   ROAR_ERR("main(*): No support for ssynth compiled in");
1362#endif
1363  } else if ( strcmp(k, "--ssynth-disable") == 0 ) {
1364#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
1365   ssynth_conf.enable = 0;
1366#else
1367   // we can safely ignore the disable
1368#endif
1369
1370  } else if ( strcmp(k, "--x11-display") == 0 || strcmp(k, "--display") == 0 ) {
1371#ifdef ROAR_HAVE_LIBX11
1372   x11display = argv[++i];
1373#else
1374   ROAR_ERR("No X11 support compiled in!");
1375   return 1;
1376#endif
1377
1378
1379  } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--port") == 0 ) {
1380   // This is only usefull in INET not UNIX mode.
1381#ifdef ROAR_SUPPORT_LISTEN
1382   if ( *sock_addr == '/' )
1383    sock_addr = ROAR_DEFAULT_HOST;
1384
1385   errno = 0;
1386   if ( (port = atoi(argv[++i])) < 1 ) {
1387#ifdef ROAR_HAVE_GETSERVBYNAME
1388    if ( (serv = getservbyname(argv[i], "tcp")) == NULL ) {
1389     ROAR_ERR("Unknown service: %s: %s", argv[i], strerror(errno));
1390     return 1;
1391    }
1392    // NOTE: we need to use ROAR_NET2HOST16() here even if s_port is of type int!
1393    ROAR_DBG("main(*): serv = {s_name='%s', s_aliases={...}, s_port=%i, s_proto='%s'}",
1394            serv->s_name, ROAR_NET2HOST16(serv->s_port), serv->s_proto);
1395    port = ROAR_NET2HOST16(serv->s_port);
1396#else
1397    ROAR_ERR("invalite port number: %s", argv[i]);
1398    return 1;
1399#endif
1400   }
1401#endif
1402  } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) {
1403#ifdef ROAR_SUPPORT_LISTEN
1404   sock_addr = argv[++i];
1405#endif
1406
1407  } else if ( strcmp(k, "--proto") == 0 ) {
1408#ifdef ROAR_SUPPORT_LISTEN
1409   if ( (sock_proto = roar_str2proto(argv[++i])) == -1 ) {
1410    ROAR_ERR("Unknown protocol: %s", argv[i]);
1411    return 1;
1412   }
1413#endif
1414  } else if ( strcmp(k, "--proto-dir") == 0 ) {
1415#ifdef ROAR_SUPPORT_LISTEN
1416   if ( (sock_dir = roar_str2dir(argv[++i])) == -1 ) {
1417    ROAR_ERR("Unknown stream direction: %s", argv[i]);
1418    return 1;
1419   }
1420#endif
1421  } else if ( strcmp(k, "--proto-rate") == 0 ) {
1422#ifdef ROAR_SUPPORT_LISTEN
1423   sock_info.rate = atoi(argv[++i]);
1424#endif
1425  } else if ( strcmp(k, "--proto-bits") == 0 ) {
1426#ifdef ROAR_SUPPORT_LISTEN
1427   sock_info.bits = atoi(argv[++i]);
1428#endif
1429  } else if ( strcmp(k, "--proto-chans") == 0 ) {
1430#ifdef ROAR_SUPPORT_LISTEN
1431   sock_info.channels = atoi(argv[++i]);
1432#endif
1433  } else if ( strcmp(k, "--proto-codec") == 0 ) {
1434#ifdef ROAR_SUPPORT_LISTEN
1435   if ( (sock_info.codec = roar_str2codec(argv[++i])) == -1 ) {
1436    ROAR_ERR("Unknown codec: %s", argv[i]);
1437    return 1;
1438   }
1439#endif
1440
1441
1442  } else if ( strcmp(k, "--list-proto") == 0 ) {
1443   list_proto();
1444   return 0;
1445
1446  } else if ( strcmp(k, "-t") == 0 || strcmp(k, "--tcp") == 0 ) {
1447#ifdef ROAR_SUPPORT_LISTEN
1448   if ( sock_type != ROAR_SOCKET_TYPE_TCP && sock_type != ROAR_SOCKET_TYPE_TCP6 )
1449    sock_type = ROAR_SOCKET_TYPE_TCP;
1450
1451   if ( *sock_addr == '/' )
1452    sock_addr = ROAR_DEFAULT_HOST;
1453#endif
1454
1455  } else if ( strcmp(k, "-4") == 0 ) {
1456#ifdef ROAR_SUPPORT_LISTEN
1457   sock_type = ROAR_SOCKET_TYPE_TCP;
1458   if ( *sock_addr == '/' )
1459    sock_addr = ROAR_DEFAULT_HOST;
1460#endif
1461  } else if ( strcmp(k, "-6") == 0 ) {
1462#ifdef ROAR_SUPPORT_LISTEN
1463#ifdef PF_INET6
1464   sock_type = ROAR_SOCKET_TYPE_TCP6;
1465   if ( *sock_addr == '/' )
1466    sock_addr = ROAR_DEFAULT_HOST;
1467#else
1468    ROAR_ERR("No IPv6 support compiled in!");
1469    return 1;
1470#endif
1471#endif
1472
1473  } else if ( strcmp(k, "-u") == 0 || strcmp(k, "--unix") == 0 ) {
1474#ifdef ROAR_SUPPORT_LISTEN
1475   // ignore this case as it is the default behavor.
1476   sock_type = ROAR_SOCKET_TYPE_UNIX;
1477#endif
1478
1479  } else if ( strcmp(k, "-n") == 0 || strcmp(k, "--decnet") == 0 ) {
1480#ifdef ROAR_SUPPORT_LISTEN
1481#ifdef ROAR_HAVE_LIBDNET
1482    port   = ROAR_DEFAULT_NUM;
1483    strcpy(decnethost, ROAR_DEFAULT_LISTEN_OBJECT);
1484    sock_addr = decnethost;
1485    sock_type = ROAR_SOCKET_TYPE_DECNET;
1486#else
1487    ROAR_ERR("No DECnet support compiled in!");
1488    return 1;
1489#endif
1490#endif
1491  } else if ( strcmp(k, "--new-sock") == 0 ) {
1492#ifdef ROAR_SUPPORT_LISTEN
1493   if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto, sock_dir, &sock_info) != 0 ) {
1494    ROAR_ERR("Can not open listen socket!");
1495    return 1;
1496   }
1497#endif
1498
1499  } else if ( strcmp(k, "--slp") == 0 ) {
1500#ifdef ROAR_HAVE_LIBSLP
1501   reg_slp = 1;
1502#else
1503   ROAR_ERR("No OpenSLP support compiled in!");
1504   return 1;
1505#endif
1506
1507  } else if ( strcmp(k, "--x11") == 0 ) {
1508#ifdef ROAR_HAVE_LIBX11
1509   reg_x11 = 1;
1510#else
1511   ROAR_ERR("No X11 support compiled in!");
1512   return 1;
1513#endif
1514
1515
1516  } else if ( strcmp(k, "--jumbo-mtu") == 0 ) {
1517   g_config->jumbo_mtu = atoi(argv[++i]);
1518
1519  } else if ( strcmp(k, "-G") == 0 ) {
1520   sock_grp  = argv[++i];
1521  } else if ( strcmp(k, "-U") == 0 ) {
1522   sock_user = argv[++i];
1523
1524  } else if ( strcmp(k, "--no-listen") == 0 ) {
1525#ifdef ROAR_SUPPORT_LISTEN
1526   sock_addr   = "";
1527   g_terminate = 1;
1528   g_no_listen = 1;
1529#endif
1530  } else if ( strcmp(k, "--client-fh") == 0 ) {
1531   if ( clients_set_fh(clients_new(), atoi(argv[++i])) == -1 ) {
1532    ROAR_ERR("main(*): Can not set client's fh");
1533    return 1;
1534   }
1535  } else if ( strcmp(k, "--close-fh") == 0 ) {
1536#ifdef ROAR_HAVE_IO_POSIX
1537   close(atoi(argv[++i]));
1538#else
1539   i++;
1540   ROAR_WARN("can not close file handle %s (closing not supported)", argv[i]);
1541#endif
1542
1543  } else if ( strcmp(k, "--standby") == 0 ) {
1544   g_standby = 1;
1545  } else if ( strcmp(k, "--auto-standby") == 0 ) {
1546   g_autostandby = 1;
1547  } else {
1548   usage();
1549   return 1;
1550  }
1551
1552 }
1553#endif
1554
1555#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1556 if ( s_dev != NULL ) {
1557  if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) {
1558   ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv);
1559  }
1560 }
1561#endif
1562
1563 add_output(o_drv, o_dev, o_opts, o_prim, o_count);
1564
1565 ROAR_DBG("Server config: rate=%i, bits=%i, chans=%i", sa.rate, sa.bits, sa.channels);
1566
1567 if ( waveform_init() == -1 ) {
1568  ROAR_ERR("Can not initialize Waveform subsystem");
1569  return 1;
1570 }
1571
1572#ifndef ROAR_WITHOUT_DCOMP_MIDI
1573 if ( midi_init() == -1 ) {
1574  ROAR_ERR("Can not initialize MIDI subsystem");
1575 }
1576#endif
1577
1578#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
1579 if ( ssynth_init() == -1 ) {
1580  ROAR_ERR("Can not initialize ssynth subsystem");
1581 }
1582#endif
1583
1584#ifndef ROAR_WITHOUT_DCOMP_LIGHT
1585 if ( light_init(light_channels) == -1 ) {
1586  ROAR_ERR("Can not initialize light control subsystem");
1587 }
1588#endif
1589
1590#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1591 if ( rdtcs_init() == -1 ) {
1592  ROAR_ERR("Can not initialize RDTCS subsystem");
1593 }
1594#endif
1595
1596 if ( plugins_init() == -1 ) {
1597  ROAR_ERR("Can not initialize plugins");
1598 }
1599
1600#ifdef ROAR_SUPPORT_LISTEN
1601 if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto, sock_dir, &sock_info) != 0 ) {
1602  ROAR_ERR("Can not open listen socket!");
1603  return 1;
1604 }
1605#endif
1606
1607 if ( output_buffer_init(&sa) == -1 ) {
1608  ROAR_ERR("Can not init output buffer!");
1609  return 1;
1610 }
1611
1612 if ( driver == NULL ) {
1613  driver = "null";
1614 } else {
1615  ROAR_WARN("Usage of old driver interface. use -o not -d!");
1616 }
1617
1618 if ( driver_open(&drvinst, &drvid, driver, device, &sa) == -1 ) {
1619  ROAR_ERR("Can not open output driver!");
1620  return 1;
1621 }
1622
1623 if ( samples_init() == -1 ) {
1624  ROAR_ERR("Can not init samples!");
1625  return 1;
1626 }
1627
1628
1629 // we should handle this on microcontrollers, too.
1630#if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_TARGET_WIN32)
1631 signal(SIGINT,  on_sig_int);
1632 signal(SIGTERM, on_sig_term);
1633 signal(SIGCHLD, on_sig_chld);
1634 signal(SIGUSR1, on_sig_usr1);
1635 signal(SIGPIPE, SIG_IGN);  // ignore broken pipes
1636#endif
1637
1638 if ( realtime ) {
1639#ifdef DEBUG
1640  ROAR_WARN("compiled with -DDEBUG but realtime is enabled: for real realtime support compiel without -DDEBUG");
1641#endif
1642
1643#ifdef ROAR_HAVE_NICE
1644  errno = 0;
1645  nice(-5*realtime); // -5 for each --realtime
1646  if ( errno ) {
1647   ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno));
1648  }
1649#else
1650  ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno));
1651#endif
1652/*
1653#ifdef __linux__
1654  if ( ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0)) == -1 )
1655   ROAR_WARN("Can not set io priority: %s", strerror(errno));
1656#endif
1657*/
1658 }
1659
1660#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
1661 if ( setids & R_SETGID ) {
1662  if ( sock_grp == NULL ) {
1663   ROAR_ERR("Can not set GID if no groupname is supplied");
1664   return 1;
1665  }
1666  if ( (grp = getgrnam(sock_grp)) == NULL ) {
1667   ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno));
1668   return 1;
1669  }
1670  if ( setgroups(0, (const gid_t *) NULL) == -1 ) {
1671   ROAR_ERR("Can not clear supplementary group IDs: %s", strerror(errno));
1672  }
1673  if ( !grp || setgid(grp->gr_gid) == -1 ) {
1674   ROAR_ERR("Can not set GroupID: %s", strerror(errno));
1675  }
1676 }
1677#endif
1678
1679
1680 clients_set_pid(g_self_client, getpid());
1681#ifdef ROAR_HAVE_GETUID
1682 clients_set_uid(g_self_client, getuid());
1683#endif
1684#ifdef ROAR_HAVE_GETGID
1685 clients_set_gid(g_self_client, getgid());
1686#endif
1687 clients_get(g_self_client, &self);
1688
1689 if ( self == NULL ) {
1690  ROAR_ERR("Can not get self client!");
1691  return 1;
1692 }
1693
1694 strcpy(self->name, "RoarAudio daemon internal");
1695
1696 if ( roar_nnode_free(&(self->nnode)) == -1 )
1697  return 1;
1698
1699 // not fully correct but ok as workaorund
1700 // so tools assume that roard runs on the same machine as
1701 // they in case they use AF_UNIX:
1702 if ( roar_nnode_new(&(self->nnode), ROAR_SOCKET_TYPE_UNIX) == -1 )
1703  return 1;
1704
1705#ifdef ROAR_HAVE_FORK
1706 if ( daemon ) {
1707  close(ROAR_STDIN );
1708  close(ROAR_STDOUT);
1709  close(ROAR_STDERR);
1710
1711  if ( fork() )
1712   ROAR_U_EXIT(0);
1713
1714#ifdef ROAR_HAVE_SETSID
1715  setsid();
1716#endif
1717  clients_set_pid(g_self_client, getpid()); // reset pid as it changed
1718 }
1719#endif
1720
1721#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
1722 // early test for UID as we need this for the pidfile and the setuid()
1723 if ( sock_user != NULL ) {
1724  if ( (pwd = getpwnam(sock_user)) == NULL ) {
1725   ROAR_ERR("Can not get UID for user %s: %s", sock_user, strerror(errno));
1726   return 1;
1727  }
1728 }
1729#endif
1730
1731#ifdef SUPPORT_PIDFILE
1732 if ( pidfile != NULL ) {
1733  if ( roar_vio_open_file(&pidfile_vio, pidfile, O_WRONLY|O_CREAT, 0644) == -1 ) {
1734   ROAR_ERR("Can not write pidfile: %s", pidfile);
1735  } else {
1736   roar_vio_printf(&pidfile_vio, "%i\n", getpid());
1737   roar_vio_close(&pidfile_vio);
1738  }
1739#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
1740  if ( pwd || grp ) {
1741   if ( chown(pidfile, pwd ? pwd->pw_uid : -1, grp ? grp->gr_gid : -1) == -1 ) {
1742    ROAR_WARN("Can not change ownership of pidfile: %s: %s", pidfile, strerror(errno));
1743   }
1744  }
1745  if ( chmod(pidfile, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1 ) {
1746   ROAR_WARN("Can not change permissions of pidfile: %s: %s", pidfile, strerror(errno));
1747  }
1748#endif
1749 }
1750#endif
1751
1752#ifdef ROAR_HAVE_CHROOT
1753 if (chrootdir) {
1754  if ( chroot(chrootdir) == -1 ) {
1755   ROAR_ERR("Can not chroot to %s: %s", chrootdir, strerror(errno));
1756   return 2;
1757  }
1758  if ( chdir("/") == -1 ) {
1759   ROAR_ERR("Can not chdir to /: %s", strerror(errno));
1760   return 2;
1761  }
1762 }
1763#endif
1764
1765#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
1766 if ( setids & R_SETUID ) {
1767  if ( sock_user == NULL ) {
1768   ROAR_ERR("Can not set UID if no username is supplied");
1769   return 1;
1770  }
1771  if ( !pwd || setuid(pwd->pw_uid) == -1 ) {
1772   ROAR_ERR("Can not set UserID: %s", strerror(errno));
1773   return 3;
1774  }
1775#ifdef ROAR_HAVE_GETUID
1776  clients_set_uid(g_self_client, getuid());
1777#endif
1778 }
1779#endif
1780
1781 // Register with OpenSLP:
1782#ifdef ROAR_HAVE_LIBSLP
1783 if ( reg_slp ) {
1784  register_slp(0, sock_addr);
1785 }
1786#endif
1787
1788#ifdef ROAR_HAVE_LIBX11
1789 if ( reg_x11 ) {
1790  register_x11(0, sock_addr);
1791 }
1792#endif
1793
1794 // start main loop...
1795 main_loop(drvid, drvinst, &sa, sysclocksync);
1796
1797 // clean up.
1798 clean_quit_prep();
1799 driver_close(drvinst, drvid);
1800 output_buffer_free();
1801
1802 return 0;
1803}
1804
1805void cleanup_listen_socket (int terminate) {
1806 int i;
1807
1808 // Deregister from SLP:
1809#ifdef ROAR_HAVE_LIBSLP
1810 register_slp(1, NULL);
1811#endif
1812
1813#ifdef ROAR_HAVE_LIBX11
1814 register_x11(1, NULL);
1815#endif
1816
1817#ifdef ROAR_SUPPORT_LISTEN
1818 for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
1819  if ( g_listen[i].socket != -1 ) {
1820#ifdef ROAR_HAVE_IO_POSIX
1821   close(g_listen[i].socket);
1822#endif // #else is useless because we are in void context.
1823
1824   g_listen[i].socket = -1;
1825
1826#ifdef ROAR_HAVE_UNIX
1827   if ( server[i] != NULL )
1828    if ( *(server[i]) == '/' )
1829     unlink(server[i]);
1830#endif
1831  }
1832 }
1833
1834#endif
1835
1836 if ( terminate )
1837  g_terminate = 1;
1838}
1839
1840void clean_quit_prep (void) {
1841 cleanup_listen_socket(0);
1842
1843 plugins_free();
1844
1845#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1846 sources_free();
1847#endif
1848 streams_free();
1849 clients_free();
1850#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
1851 ssynth_free();
1852#endif
1853#ifndef ROAR_WITHOUT_DCOMP_CB
1854 midi_cb_stop(); // stop console beep
1855#endif
1856#ifndef ROAR_WITHOUT_DCOMP_MIDI
1857 midi_free();
1858#endif
1859#ifndef ROAR_WITHOUT_DCOMP_LIGHT
1860 light_free();
1861#endif
1862#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1863 rdtcs_free();
1864#endif
1865
1866 waveform_free();
1867
1868#ifdef SUPPORT_PIDFILE
1869 if ( pidfile != NULL )
1870  unlink(pidfile);
1871#endif
1872}
1873
1874void clean_quit (void) {
1875 clean_quit_prep();
1876// driver_close(drvinst, drvid);
1877// output_buffer_free();
1878 exit(0);
1879}
1880
1881//ll
Note: See TracBrowser for help on using the repository browser.