os_support.h 3.1 KB

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