source: roaraudio/roard/roard.c @ 3684:69134bcda4c2

Last change on this file since 3684:69134bcda4c2 was 3684:69134bcda4c2, checked in by phi, 14 years ago

added most of the rsound interface

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