cannam@154
|
1 /* Copyright (C) 2007 Jean-Marc Valin
|
cannam@154
|
2
|
cannam@154
|
3 File: os_support.h
|
cannam@154
|
4 This is the (tiny) OS abstraction layer. Aside from math.h, this is the
|
cannam@154
|
5 only place where system headers are allowed.
|
cannam@154
|
6
|
cannam@154
|
7 Redistribution and use in source and binary forms, with or without
|
cannam@154
|
8 modification, are permitted provided that the following conditions are
|
cannam@154
|
9 met:
|
cannam@154
|
10
|
cannam@154
|
11 1. Redistributions of source code must retain the above copyright notice,
|
cannam@154
|
12 this list of conditions and the following disclaimer.
|
cannam@154
|
13
|
cannam@154
|
14 2. Redistributions in binary form must reproduce the above copyright
|
cannam@154
|
15 notice, this list of conditions and the following disclaimer in the
|
cannam@154
|
16 documentation and/or other materials provided with the distribution.
|
cannam@154
|
17
|
cannam@154
|
18 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
cannam@154
|
19 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
cannam@154
|
20 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
cannam@154
|
21 DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
cannam@154
|
22 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
cannam@154
|
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
cannam@154
|
24 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
cannam@154
|
25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
cannam@154
|
26 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
cannam@154
|
27 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
cannam@154
|
28 POSSIBILITY OF SUCH DAMAGE.
|
cannam@154
|
29 */
|
cannam@154
|
30
|
cannam@154
|
31 #ifndef OS_SUPPORT_H
|
cannam@154
|
32 #define OS_SUPPORT_H
|
cannam@154
|
33
|
cannam@154
|
34 #ifdef CUSTOM_SUPPORT
|
cannam@154
|
35 # include "custom_support.h"
|
cannam@154
|
36 #endif
|
cannam@154
|
37
|
cannam@154
|
38 #include "opus_types.h"
|
cannam@154
|
39 #include "opus_defines.h"
|
cannam@154
|
40
|
cannam@154
|
41 #include <string.h>
|
cannam@154
|
42 #include <stdio.h>
|
cannam@154
|
43 #include <stdlib.h>
|
cannam@154
|
44
|
cannam@154
|
45 /** Opus wrapper for malloc(). To do your own dynamic allocation, all you need to do is replace this function and opus_free */
|
cannam@154
|
46 #ifndef OVERRIDE_OPUS_ALLOC
|
cannam@154
|
47 static OPUS_INLINE void *opus_alloc (size_t size)
|
cannam@154
|
48 {
|
cannam@154
|
49 return malloc(size);
|
cannam@154
|
50 }
|
cannam@154
|
51 #endif
|
cannam@154
|
52
|
cannam@154
|
53 /** Same as celt_alloc(), except that the area is only needed inside a CELT call (might cause problem with wideband though) */
|
cannam@154
|
54 #ifndef OVERRIDE_OPUS_ALLOC_SCRATCH
|
cannam@154
|
55 static OPUS_INLINE void *opus_alloc_scratch (size_t size)
|
cannam@154
|
56 {
|
cannam@154
|
57 /* Scratch space doesn't need to be cleared */
|
cannam@154
|
58 return opus_alloc(size);
|
cannam@154
|
59 }
|
cannam@154
|
60 #endif
|
cannam@154
|
61
|
cannam@154
|
62 /** Opus wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function and opus_alloc */
|
cannam@154
|
63 #ifndef OVERRIDE_OPUS_FREE
|
cannam@154
|
64 static OPUS_INLINE void opus_free (void *ptr)
|
cannam@154
|
65 {
|
cannam@154
|
66 free(ptr);
|
cannam@154
|
67 }
|
cannam@154
|
68 #endif
|
cannam@154
|
69
|
cannam@154
|
70 /** Copy n elements from src to dst. The 0* term provides compile-time type checking */
|
cannam@154
|
71 #ifndef OVERRIDE_OPUS_COPY
|
cannam@154
|
72 #define OPUS_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
|
cannam@154
|
73 #endif
|
cannam@154
|
74
|
cannam@154
|
75 /** Copy n elements from src to dst, allowing overlapping regions. The 0* term
|
cannam@154
|
76 provides compile-time type checking */
|
cannam@154
|
77 #ifndef OVERRIDE_OPUS_MOVE
|
cannam@154
|
78 #define OPUS_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
|
cannam@154
|
79 #endif
|
cannam@154
|
80
|
cannam@154
|
81 /** Set n elements of dst to zero */
|
cannam@154
|
82 #ifndef OVERRIDE_OPUS_CLEAR
|
cannam@154
|
83 #define OPUS_CLEAR(dst, n) (memset((dst), 0, (n)*sizeof(*(dst))))
|
cannam@154
|
84 #endif
|
cannam@154
|
85
|
cannam@154
|
86 /*#ifdef __GNUC__
|
cannam@154
|
87 #pragma GCC poison printf sprintf
|
cannam@154
|
88 #pragma GCC poison malloc free realloc calloc
|
cannam@154
|
89 #endif*/
|
cannam@154
|
90
|
cannam@154
|
91 #endif /* OS_SUPPORT_H */
|
cannam@154
|
92
|