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