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