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