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