cannam@154: /* Copyright (C) 2007 Jean-Marc Valin cannam@154: cannam@154: File: os_support.h cannam@154: This is the (tiny) OS abstraction layer. Aside from math.h, this is the cannam@154: only place where system headers are allowed. cannam@154: cannam@154: Redistribution and use in source and binary forms, with or without cannam@154: modification, are permitted provided that the following conditions are cannam@154: met: cannam@154: cannam@154: 1. Redistributions of source code must retain the above copyright notice, cannam@154: this list of conditions and the following disclaimer. cannam@154: cannam@154: 2. Redistributions in binary form must reproduce the above copyright cannam@154: notice, this list of conditions and the following disclaimer in the cannam@154: documentation and/or other materials provided with the distribution. cannam@154: cannam@154: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR cannam@154: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES cannam@154: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE cannam@154: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, cannam@154: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES cannam@154: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR cannam@154: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) cannam@154: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, cannam@154: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN cannam@154: ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE cannam@154: POSSIBILITY OF SUCH DAMAGE. cannam@154: */ cannam@154: cannam@154: #ifndef OS_SUPPORT_H cannam@154: #define OS_SUPPORT_H cannam@154: cannam@154: #ifdef CUSTOM_SUPPORT cannam@154: # include "custom_support.h" cannam@154: #endif cannam@154: cannam@154: #include "opus_types.h" cannam@154: #include "opus_defines.h" cannam@154: cannam@154: #include cannam@154: #include cannam@154: #include cannam@154: cannam@154: /** Opus wrapper for malloc(). To do your own dynamic allocation, all you need to do is replace this function and opus_free */ cannam@154: #ifndef OVERRIDE_OPUS_ALLOC cannam@154: static OPUS_INLINE void *opus_alloc (size_t size) cannam@154: { cannam@154: return malloc(size); cannam@154: } cannam@154: #endif cannam@154: cannam@154: /** Same as celt_alloc(), except that the area is only needed inside a CELT call (might cause problem with wideband though) */ cannam@154: #ifndef OVERRIDE_OPUS_ALLOC_SCRATCH cannam@154: static OPUS_INLINE void *opus_alloc_scratch (size_t size) cannam@154: { cannam@154: /* Scratch space doesn't need to be cleared */ cannam@154: return opus_alloc(size); cannam@154: } cannam@154: #endif cannam@154: cannam@154: /** Opus wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function and opus_alloc */ cannam@154: #ifndef OVERRIDE_OPUS_FREE cannam@154: static OPUS_INLINE void opus_free (void *ptr) cannam@154: { cannam@154: free(ptr); cannam@154: } cannam@154: #endif cannam@154: cannam@154: /** Copy n elements from src to dst. The 0* term provides compile-time type checking */ cannam@154: #ifndef OVERRIDE_OPUS_COPY cannam@154: #define OPUS_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) cannam@154: #endif cannam@154: cannam@154: /** Copy n elements from src to dst, allowing overlapping regions. The 0* term cannam@154: provides compile-time type checking */ cannam@154: #ifndef OVERRIDE_OPUS_MOVE cannam@154: #define OPUS_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) cannam@154: #endif cannam@154: cannam@154: /** Set n elements of dst to zero */ cannam@154: #ifndef OVERRIDE_OPUS_CLEAR cannam@154: #define OPUS_CLEAR(dst, n) (memset((dst), 0, (n)*sizeof(*(dst)))) cannam@154: #endif cannam@154: cannam@154: /*#ifdef __GNUC__ cannam@154: #pragma GCC poison printf sprintf cannam@154: #pragma GCC poison malloc free realloc calloc cannam@154: #endif*/ cannam@154: cannam@154: #endif /* OS_SUPPORT_H */ cannam@154: