[0] | 1 | //roaraudio.h: |
---|
| 2 | |
---|
[704] | 3 | /* |
---|
[3608] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
[704] | 5 | * |
---|
| 6 | * This file is 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 Lesser 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 Lesser General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU Lesser 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. |
---|
[704] | 23 | * |
---|
| 24 | * NOTE: Even though this file is LGPLed it (may) include GPLed files |
---|
| 25 | * so the license of this file is/may therefore downgraded to GPL. |
---|
| 26 | * See HACKING for details. |
---|
| 27 | */ |
---|
| 28 | |
---|
[0] | 29 | #ifndef _ROARAUDIO_H_ |
---|
| 30 | #define _ROARAUDIO_H_ |
---|
| 31 | |
---|
[1074] | 32 | #include <roaraudio/config.h> |
---|
[1428] | 33 | #include <roaraudio/muconthacks.h> |
---|
[1073] | 34 | #include <roaraudio/win32hacks.h> // we include this at the beginning of the file |
---|
| 35 | // so we can define well known standard types known to everyone |
---|
| 36 | // and everywhere but win32 here |
---|
| 37 | |
---|
[1251] | 38 | // consts we need to set depending on the OS and features: |
---|
| 39 | #if defined(ROAR_NEED_GNU_SOURCE) && !defined(_GNU_SOURCE) |
---|
| 40 | #define _GNU_SOURCE |
---|
| 41 | #endif |
---|
| 42 | |
---|
| 43 | #if defined(ROAR_NEED_BSD_VISIBLE) && !defined(__BSD_VISIBLE) |
---|
| 44 | #define __BSD_VISIBLE 1 |
---|
| 45 | #endif |
---|
| 46 | |
---|
[1477] | 47 | #include <stdint.h> |
---|
[0] | 48 | #include <stdlib.h> |
---|
[1426] | 49 | |
---|
| 50 | #ifdef ROAR_HAVE_H_UNISTD |
---|
[0] | 51 | #include <unistd.h> |
---|
[1426] | 52 | #endif |
---|
| 53 | |
---|
[0] | 54 | #include <stdio.h> |
---|
| 55 | #include <string.h> |
---|
| 56 | #include <errno.h> |
---|
[1425] | 57 | |
---|
| 58 | #ifdef ROAR_HAVE_H_SYS_TYPES |
---|
[0] | 59 | #include <sys/types.h> |
---|
[1425] | 60 | #endif |
---|
| 61 | |
---|
[0] | 62 | #include <limits.h> |
---|
[1422] | 63 | #if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER) |
---|
[57] | 64 | #include <sys/mman.h> |
---|
[1075] | 65 | #endif |
---|
[0] | 66 | |
---|
[60] | 67 | // TODO: can we move the next block into roard specific includes? |
---|
[1422] | 68 | #if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER) |
---|
[60] | 69 | #include <grp.h> |
---|
| 70 | #include <pwd.h> |
---|
| 71 | #include <sys/stat.h> |
---|
[1074] | 72 | #endif |
---|
[60] | 73 | |
---|
[1072] | 74 | #ifdef ROAR_TARGET_WIN32 |
---|
| 75 | #include <winsock2.h> |
---|
[1375] | 76 | #else /* ROAR_TARGET_WIN32 */ |
---|
| 77 | #ifdef ROAR_HAVE_BSDSOCKETS |
---|
| 78 | |
---|
| 79 | #if defined(ROAR_HAVE_IPV4) || defined(ROAR_HAVE_IPV6) |
---|
[0] | 80 | #include <arpa/inet.h> |
---|
[1375] | 81 | #endif |
---|
[0] | 82 | |
---|
[1472] | 83 | #ifdef ROAR_HAVE_SELECT |
---|
[0] | 84 | #include <sys/socket.h> |
---|
[1472] | 85 | #endif |
---|
[1375] | 86 | |
---|
| 87 | #ifdef ROAR_HAVE_IPV4 |
---|
[0] | 88 | #include <netinet/in.h> |
---|
| 89 | #include <netinet/tcp.h> |
---|
[1375] | 90 | #endif |
---|
| 91 | #ifdef ROAR_HAVE_UNIX |
---|
[0] | 92 | #include <sys/un.h> |
---|
[1072] | 93 | #endif |
---|
[0] | 94 | |
---|
[1375] | 95 | #endif /* ROAR_HAVE_BSDSOCKETS */ |
---|
| 96 | #endif /* ROAR_TARGET_WIN32 */ |
---|
| 97 | |
---|
[480] | 98 | #ifdef __NetBSD__ |
---|
| 99 | #include <netinet/in_systm.h> |
---|
| 100 | #endif |
---|
| 101 | |
---|
[1424] | 102 | #if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER) |
---|
[0] | 103 | #include <netdb.h> |
---|
[1074] | 104 | #endif |
---|
[0] | 105 | |
---|
| 106 | // NOTE: we need this macro in some of our header files. |
---|
[3566] | 107 | // TODO: This is oubslute, we will remove it soon. |
---|
[0] | 108 | #if INT_MAX >= 32767 |
---|
| 109 | #define roar_intm16 int |
---|
| 110 | #define roar_uintm16 unsigned int |
---|
| 111 | #else |
---|
| 112 | #define roar_intm16 int16_t |
---|
| 113 | #define roar_uintm16 uint16_t |
---|
| 114 | #endif |
---|
| 115 | |
---|
[988] | 116 | // this is to avoid warning messages on platforms |
---|
| 117 | // where sizeof(void*) == 8 and szeof(int) == 4 |
---|
| 118 | #ifdef __LP64__ |
---|
| 119 | #define ROAR_INSTINT long int |
---|
| 120 | #else |
---|
| 121 | #define ROAR_INSTINT int |
---|
| 122 | #endif |
---|
| 123 | |
---|
[874] | 124 | #ifndef __BEGIN_DECLS |
---|
| 125 | #ifdef __cplusplus |
---|
| 126 | # define __BEGIN_DECLS extern "C" { |
---|
| 127 | # define __END_DECLS } |
---|
| 128 | #else |
---|
| 129 | # define __BEGIN_DECLS |
---|
| 130 | # define __END_DECLS |
---|
| 131 | #endif |
---|
| 132 | #endif |
---|
| 133 | |
---|
| 134 | __BEGIN_DECLS |
---|
| 135 | |
---|
[0] | 136 | #include <roaraudio/proto.h> |
---|
[780] | 137 | #include <roaraudio/error.h> |
---|
[0] | 138 | #include <roaraudio/audio.h> |
---|
| 139 | #include <roaraudio/stream.h> |
---|
| 140 | #include <roaraudio/client.h> |
---|
| 141 | #include <roaraudio/sample.h> |
---|
[87] | 142 | #include <roaraudio/meta.h> |
---|
[3048] | 143 | #include <roaraudio/genre.h> |
---|
[344] | 144 | #include <roaraudio/acl.h> |
---|
[2418] | 145 | #include <roaraudio/misc.h> |
---|
[0] | 146 | |
---|
| 147 | #include <libroar/libroar.h> |
---|
| 148 | |
---|
[2514] | 149 | // IP: |
---|
| 150 | #define ROAR_DEFAULT_PORT 16002 |
---|
| 151 | |
---|
[2512] | 152 | // IPv4 |
---|
[2514] | 153 | #define ROAR_DEFAULT_INET4_PORT ROAR_DEFAULT_PORT |
---|
[2512] | 154 | #define ROAR_DEFAULT_INET4_HOST "localhost" |
---|
| 155 | // aliases: |
---|
| 156 | #define ROAR_DEFAULT_HOST ROAR_DEFAULT_INET4_HOST |
---|
| 157 | |
---|
| 158 | // IPv6: |
---|
[2514] | 159 | #define ROAR_DEFAULT_INET6_PORT ROAR_DEFAULT_PORT |
---|
[2512] | 160 | #define ROAR_DEFAULT_INET6_HOST "ipv6-localhost" |
---|
[0] | 161 | |
---|
[508] | 162 | // UNIX Domain Sockets |
---|
[0] | 163 | #define ROAR_DEFAULT_SOCK_GLOBAL "/tmp/roar" |
---|
| 164 | #define ROAR_DEFAULT_SOCK_USER ".roar" |
---|
| 165 | |
---|
[508] | 166 | // DECnet |
---|
| 167 | #define ROAR_DEFAULT_OBJECT "roar" |
---|
| 168 | #define ROAR_DEFAULT_NUM 0 |
---|
[515] | 169 | #define ROAR_DEFAULT_LISTEN_OBJECT "::" ROAR_DEFAULT_OBJECT |
---|
[508] | 170 | |
---|
[927] | 171 | // now handled by condiguere |
---|
| 172 | //#define ROAR_DEFAULT_SOCKGRP "audio" |
---|
[450] | 173 | |
---|
[2064] | 174 | #if defined(ROAR_HAVE_LIBWSOCK32) && defined(ROAR_HAVE_LIBWS2_32) |
---|
| 175 | #define ROAR_LIBS_WIN32 " -lwsock32 -lws2_32" |
---|
| 176 | #else |
---|
| 177 | #define ROAR_LIBS_WIN32 "" |
---|
| 178 | #endif |
---|
| 179 | |
---|
| 180 | #ifdef ROAR_HAVE_LIBSOCKET |
---|
| 181 | #define ROAR_LIBS_LIBSOCKET " -lsocket" |
---|
| 182 | #else |
---|
| 183 | #define ROAR_LIBS_LIBSOCKET "" |
---|
| 184 | #endif |
---|
| 185 | |
---|
| 186 | #ifdef ROAR_HAVE_LIBSENDFILE |
---|
| 187 | #define ROAR_LIBS_LIBSENDFILE " -lsendfile" |
---|
| 188 | #else |
---|
| 189 | #define ROAR_LIBS_LIBSENDFILE "" |
---|
| 190 | #endif |
---|
| 191 | |
---|
| 192 | #define ROAR_LIBS_NET_LIBS ROAR_LIBS_LIBSOCKET ROAR_LIBS_WIN32 |
---|
| 193 | |
---|
| 194 | #define ROAR_LIBS "-lroar" ROAR_LIBS_LIBSENDFILE ROAR_LIBS_NET_LIBS |
---|
[2024] | 195 | #define ROAR_LIBS_DSP "-lroardsp " ROAR_LIBS |
---|
| 196 | #define ROAR_LIBS_MIDI "-lroarmidi " ROAR_LIBS_DSP |
---|
| 197 | #define ROAR_LIBS_LIGHT "-lroarlight " ROAR_LIBS |
---|
[2277] | 198 | #define ROAR_LIBS_EIO "-lroareio " ROAR_LIBS |
---|
[313] | 199 | #define ROAR_CFLAGS "" |
---|
[0] | 200 | |
---|
[2876] | 201 | // comp libs: |
---|
| 202 | #define ROAR_LIBS_C_ESD "-lroaresd " ROAR_LIBS |
---|
| 203 | #define ROAR_LIBS_C_ARTSC "-lroarartsc " ROAR_LIBS |
---|
| 204 | #define ROAR_LIBS_C_PULSE "-lroarpulse " ROAR_LIBS |
---|
[3826] | 205 | #define ROAR_LIBS_C_PULSE_SIMPLE "-lroarpulse-simple " ROAR_LIBS_C_PULSE |
---|
[2876] | 206 | #define ROAR_LIBS_C_SNDIO "-lroarsndio " ROAR_LIBS |
---|
| 207 | #define ROAR_LIBS_C_YIFF "-lroaryiff " ROAR_LIBS |
---|
| 208 | |
---|
[0] | 209 | //some basic macros: |
---|
| 210 | #define ROAR_STDIN 0 |
---|
| 211 | #define ROAR_STDOUT 1 |
---|
| 212 | #define ROAR_STDERR 2 |
---|
| 213 | |
---|
| 214 | #define ROAR_DEBUG_OUTFH stderr |
---|
| 215 | |
---|
| 216 | #ifdef ROAR_DBG_PREFIX |
---|
| 217 | #undef ROAR_DBG_PREFIX |
---|
| 218 | #endif |
---|
| 219 | #define ROAR_DBG_PREFIX "roaraudio" |
---|
| 220 | |
---|
| 221 | #define ROAR_DBG_FULLPREFIX "(" ROAR_DBG_PREFIX ": " __FILE__ ":%i): " |
---|
| 222 | |
---|
[2969] | 223 | // some default info levels: |
---|
| 224 | #define ROAR_DBG_INFO_NONE 0 |
---|
| 225 | #define ROAR_DBG_INFO_NOTICE 1 |
---|
| 226 | #define ROAR_DBG_INFO_INFO 2 |
---|
| 227 | #define ROAR_DBG_INFO_VERBOSE 3 |
---|
| 228 | |
---|
[472] | 229 | #if __GNUC__ < 3 |
---|
| 230 | #define ROAR_DBG(format, args...) |
---|
| 231 | #define ROAR_ERR(format, args...) |
---|
| 232 | #define ROAR_WARN(format, args...) |
---|
[2969] | 233 | #define ROAR_INFO(format, level, args...) |
---|
[472] | 234 | #else |
---|
| 235 | |
---|
[0] | 236 | #ifdef DEBUG |
---|
[3612] | 237 | #define ROAR_DBG(format, args...) roar_debug_msg(ROAR_DEBUG_TYPE_DEBUG, __LINE__, __FILE__, ROAR_DBG_PREFIX, format, ## args) |
---|
[0] | 238 | #else |
---|
| 239 | #define ROAR_DBG(format, args...) |
---|
| 240 | #endif |
---|
| 241 | |
---|
[3612] | 242 | #define ROAR_ERR(format, args...) roar_debug_msg(ROAR_DEBUG_TYPE_ERROR, __LINE__, __FILE__, ROAR_DBG_PREFIX, format, ## args) |
---|
| 243 | #define ROAR_WARN(format, args...) roar_debug_msg(ROAR_DEBUG_TYPE_WARNING, __LINE__, __FILE__, ROAR_DBG_PREFIX, format, ## args) |
---|
[0] | 244 | |
---|
[2969] | 245 | // INFO function: |
---|
| 246 | #ifdef ROAR_DBG_INFOVAR |
---|
[3612] | 247 | #define ROAR_INFO(format, level, args...) if ( (ROAR_DBG_INFOVAR) >= (level) ) roar_debug_msg(ROAR_DEBUG_TYPE_INFO, __LINE__, __FILE__, ROAR_DBG_PREFIX, format, ## args) |
---|
[2969] | 248 | #else |
---|
| 249 | #define ROAR_INFO(format, level, args...) |
---|
| 250 | #endif |
---|
| 251 | |
---|
[472] | 252 | #endif |
---|
[0] | 253 | |
---|
| 254 | #ifdef ROAR_HAVE_SAFE_OVERFLOW |
---|
| 255 | #define ROAR_MATH_OVERFLOW_ADD(a, b) ((a)+(b)) |
---|
| 256 | #else |
---|
| 257 | #define ROAR_MATH_OVERFLOW_ADD(a, b) ((4294967295U - (a)) + 1 + (b)) |
---|
| 258 | #endif |
---|
| 259 | |
---|
[56] | 260 | #ifdef ROAR_HAVE_MLOCK |
---|
[312] | 261 | #ifdef __linux__ |
---|
[57] | 262 | #define ROAR_MLOCK(p,s) mlock((p), (s)) |
---|
[312] | 263 | #else |
---|
[701] | 264 | int _ROAR_MLOCK(const void *addr, size_t len); |
---|
[700] | 265 | #define ROAR_MLOCK _ROAR_MLOCK |
---|
[56] | 266 | #endif |
---|
[699] | 267 | #endif |
---|
[0] | 268 | |
---|
[3352] | 269 | #ifdef ROAR_HAVE_STRCASESTR |
---|
| 270 | #define _roar_strcasestr(a,b) strcasestr((a), (b)) |
---|
| 271 | #else |
---|
| 272 | #define _roar_strcasestr(a,b) NULL |
---|
| 273 | #endif |
---|
| 274 | |
---|
[1098] | 275 | #if BYTE_ORDER == BIG_ENDIAN && !defined(ROAR_TARGET_WIN32) |
---|
[0] | 276 | |
---|
[1096] | 277 | #ifdef ROAR_TARGET_WIN32 |
---|
| 278 | #error This is nonsens. No win32 runs on a BE machine |
---|
| 279 | #endif |
---|
| 280 | |
---|
[2326] | 281 | #define ROAR_NET2HOST64(x) (x) |
---|
| 282 | #define ROAR_HOST2NET64(x) (x) |
---|
[0] | 283 | #define ROAR_NET2HOST32(x) (x) |
---|
| 284 | #define ROAR_HOST2NET32(x) (x) |
---|
| 285 | #define ROAR_NET2HOST16(x) (x) |
---|
| 286 | #define ROAR_HOST2NET16(x) (x) |
---|
| 287 | |
---|
[2589] | 288 | #define ROAR_BE2HOST64(x) (x) |
---|
| 289 | #define ROAR_HOST2BE64(x) (x) |
---|
| 290 | #define ROAR_BE2HOST32(x) (x) |
---|
| 291 | #define ROAR_HOST2BE32(x) (x) |
---|
| 292 | #define ROAR_BE2HOST16(x) (x) |
---|
| 293 | #define ROAR_HOST2BE16(x) (x) |
---|
| 294 | |
---|
| 295 | #define ROAR_LE2HOST32(x) ROAR_dn_ntohl(x) |
---|
| 296 | #define ROAR_HOST2LE32(x) ROAR_dn_htonl(x) |
---|
| 297 | #define ROAR_LE2HOST16(x) ROAR_dn_ntohs(x) |
---|
| 298 | #define ROAR_HOST2LE16(x) ROAR_dn_htons(x) |
---|
| 299 | |
---|
[508] | 300 | #ifdef ROAR_HAVE_LIBDNET |
---|
| 301 | #define ROAR_dn_ntohs(x) ((((x)&0x0ff)<<8) | (((x)&0xff00)>>8)) |
---|
| 302 | #define ROAR_dn_ntohl(x) ( ((dn_ntohs((x)&0xffff))<<16) |\ |
---|
| 303 | ((dn_ntohs(((x)>>16)))) ) |
---|
| 304 | #define ROAR_dn_htonl(x) ROAR_dn_ntohl(x) |
---|
| 305 | #define ROAR_dn_htons(x) ROAR_dn_ntohs(x) |
---|
| 306 | #endif |
---|
| 307 | |
---|
[0] | 308 | //#elif BYTE_ORDER == LITTLE_ENDIAN |
---|
| 309 | #else |
---|
| 310 | |
---|
[2327] | 311 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
[2326] | 312 | #define _ROAR_MOVE_BYTE(x,p) (((x) & (0xFFUL << (8*(p)))) >> (8*(p)) << (64-8*((p)+1))) |
---|
| 313 | #define ROAR_NET2HOST64(x) ROAR_HOST2NET64(x) |
---|
| 314 | #define ROAR_HOST2NET64(x) (_ROAR_MOVE_BYTE((x), 0) | _ROAR_MOVE_BYTE((x), 1) | \ |
---|
| 315 | _ROAR_MOVE_BYTE((x), 2) | _ROAR_MOVE_BYTE((x), 3) | \ |
---|
| 316 | _ROAR_MOVE_BYTE((x), 4) | _ROAR_MOVE_BYTE((x), 5) | \ |
---|
| 317 | _ROAR_MOVE_BYTE((x), 6) | _ROAR_MOVE_BYTE((x), 7) | ) |
---|
[2327] | 318 | #else |
---|
| 319 | /* PDP byte order */ |
---|
[2326] | 320 | #endif |
---|
| 321 | |
---|
[0] | 322 | #define ROAR_NET2HOST32(x) ntohl((x)) |
---|
| 323 | #define ROAR_HOST2NET32(x) htonl((x)) |
---|
| 324 | #define ROAR_NET2HOST16(x) ntohs((x)) |
---|
| 325 | #define ROAR_HOST2NET16(x) htons((x)) |
---|
| 326 | |
---|
[2589] | 327 | #define ROAR_BE2HOST32(x) ntohl(x) |
---|
| 328 | #define ROAR_HOST2BE32(x) htonl(x) |
---|
| 329 | #define ROAR_BE2HOST16(x) ntohs(x) |
---|
| 330 | #define ROAR_HOST2BE16(x) htons(x) |
---|
| 331 | |
---|
| 332 | #define ROAR_LE2HOST64(x) (x) |
---|
| 333 | #define ROAR_HOST2LE64(x) (x) |
---|
| 334 | #define ROAR_LE2HOST32(x) (x) |
---|
| 335 | #define ROAR_HOST2LE32(x) (x) |
---|
| 336 | #define ROAR_LE2HOST16(x) (x) |
---|
| 337 | #define ROAR_HOST2LE16(x) (x) |
---|
| 338 | |
---|
[508] | 339 | #ifdef ROAR_HAVE_LIBDNET |
---|
| 340 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
| 341 | #define ROAR_dn_ntohs(x) (x) |
---|
| 342 | #define ROAR_dn_htons(x) (x) |
---|
| 343 | |
---|
| 344 | #define ROAR_dn_ntohl(x) (x) |
---|
| 345 | #define ROAR_dn_htonl(x) (x) |
---|
| 346 | #else |
---|
| 347 | #error can not build on this architecture with DECnet support enabled |
---|
| 348 | #endif |
---|
| 349 | #endif |
---|
| 350 | |
---|
[0] | 351 | #endif |
---|
| 352 | |
---|
[874] | 353 | __END_DECLS |
---|
| 354 | |
---|
[0] | 355 | #endif |
---|
| 356 | |
---|
| 357 | //ll |
---|