source: roaraudio/roard/roard.c @ 3215:13678c1774be

Last change on this file since 3215:13678c1774be was 3129:70bda82a9984, checked in by phi, 14 years ago

replaced g_listen_socket

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