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