source: roaraudio/roard/roard.c @ 3517:1a3218a3fc5b

Last change on this file since 3517:1a3218a3fc5b was 3517:1a3218a3fc5b, checked in by phi, 14 years ago

updated license headers, FSF moved office

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