blob: a2171971e9d657849210a6f90549a5d867002dd1 [file] [log] [blame]
Jean-Marc Valin63590892007-11-29 17:01:16 +11001/* Copyright (C) 2007 Jean-Marc Valin
Gregory Maxwell71d39ad2011-07-30 00:00:29 -04002
Jean-Marc Valin63590892007-11-29 17:01:16 +11003 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
Jean-Marc Valin63590892007-11-29 17:01:16 +110018 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
Jean-Marc Valinc8133082008-03-06 00:12:27 +110034#ifdef CUSTOM_SUPPORT
35# include "custom_support.h"
36#endif
37
Gregory Maxwell7830cf12013-10-17 15:56:52 -070038#include "opus_types.h"
39#include "opus_defines.h"
40
Jean-Marc Valin63590892007-11-29 17:01:16 +110041#include <string.h>
42#include <stdio.h>
43#include <stdlib.h>
44
Jean-Marc Valin07f88402011-08-29 15:08:51 -040045/** Opus wrapper for malloc(). To do your own dynamic allocation, all you need to do is replace this function and opus_free */
Jean-Marc Valinbe89c392011-08-30 12:39:51 -040046#ifndef OVERRIDE_OPUS_ALLOC
Gregory Maxwell7830cf12013-10-17 15:56:52 -070047static OPUS_INLINE void *opus_alloc (size_t size)
Jean-Marc Valin63590892007-11-29 17:01:16 +110048{
Jean-Marc Valin4a4a5462011-08-29 13:48:58 -040049 return malloc(size);
Jean-Marc Valin63590892007-11-29 17:01:16 +110050}
51#endif
52
Jean-Marc Valin619a9682010-01-16 19:12:06 -050053/** Same as celt_alloc(), except that the area is only needed inside a CELT call (might cause problem with wideband though) */
Jean-Marc Valinbe89c392011-08-30 12:39:51 -040054#ifndef OVERRIDE_OPUS_ALLOC_SCRATCH
Gregory Maxwell7830cf12013-10-17 15:56:52 -070055static OPUS_INLINE void *opus_alloc_scratch (size_t size)
Jean-Marc Valin63590892007-11-29 17:01:16 +110056{
57 /* Scratch space doesn't need to be cleared */
Jean-Marc Valin07f88402011-08-29 15:08:51 -040058 return opus_alloc(size);
Jean-Marc Valin63590892007-11-29 17:01:16 +110059}
60#endif
61
Jean-Marc Valin07f88402011-08-29 15:08:51 -040062/** Opus wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function and opus_alloc */
Jean-Marc Valinbe89c392011-08-30 12:39:51 -040063#ifndef OVERRIDE_OPUS_FREE
Gregory Maxwell7830cf12013-10-17 15:56:52 -070064static OPUS_INLINE void opus_free (void *ptr)
Jean-Marc Valin63590892007-11-29 17:01:16 +110065{
Jean-Marc Valinebec87a2011-08-29 16:28:01 -040066 free(ptr);
Jean-Marc Valin63590892007-11-29 17:01:16 +110067}
68#endif
69
Tristan Matthewsdacfd282014-08-10 13:56:31 -040070/** Copy n elements from src to dst. The 0* term provides compile-time type checking */
Jean-Marc Valinbe89c392011-08-30 12:39:51 -040071#ifndef OVERRIDE_OPUS_COPY
72#define OPUS_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
Jean-Marc Valin63590892007-11-29 17:01:16 +110073#endif
74
Tristan Matthewsdacfd282014-08-10 13:56:31 -040075/** Copy n elements from src to dst, allowing overlapping regions. The 0* term
Jean-Marc Valin63590892007-11-29 17:01:16 +110076 provides compile-time type checking */
Jean-Marc Valinbe89c392011-08-30 12:39:51 -040077#ifndef OVERRIDE_OPUS_MOVE
78#define OPUS_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
Jean-Marc Valin63590892007-11-29 17:01:16 +110079#endif
80
Tristan Matthewsdacfd282014-08-10 13:56:31 -040081/** Set n elements of dst to zero */
Jean-Marc Valinbe89c392011-08-30 12:39:51 -040082#ifndef OVERRIDE_OPUS_CLEAR
83#define OPUS_CLEAR(dst, n) (memset((dst), 0, (n)*sizeof(*(dst))))
Jean-Marc Valin63590892007-11-29 17:01:16 +110084#endif
85
Jean-Marc Valinf7cec832008-04-18 17:29:56 +100086/*#ifdef __GNUC__
Jean-Marc Valinc7e0b762008-03-16 07:55:29 +110087#pragma GCC poison printf sprintf
88#pragma GCC poison malloc free realloc calloc
Jean-Marc Valinf7cec832008-04-18 17:29:56 +100089#endif*/
Jean-Marc Valin4ff068e2008-03-15 23:34:39 +110090
91#endif /* OS_SUPPORT_H */
Jean-Marc Valin63590892007-11-29 17:01:16 +110092