avcodec: Rename avpriv_frame_rate_tab to ff_mpeg12_frame_rate_tab
[libav.git] / libavutil / internal.h
CommitLineData
04d7f601
DB
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
2912e87a 4 * This file is part of Libav.
b78e7197 5 *
2912e87a 6 * Libav is free software; you can redistribute it and/or
04d7f601
DB
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
b78e7197 9 * version 2.1 of the License, or (at your option) any later version.
04d7f601 10 *
2912e87a 11 * Libav is distributed in the hope that it will be useful,
04d7f601
DB
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
2912e87a 17 * License along with Libav; if not, write to the Free Software
04d7f601
DB
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
05020c89 21/**
ba87f080 22 * @file
89c9ff50 23 * common internal API header
05020c89
RD
24 */
25
98790382
SS
26#ifndef AVUTIL_INTERNAL_H
27#define AVUTIL_INTERNAL_H
05020c89 28
318049b8
MR
29#if !defined(DEBUG) && !defined(NDEBUG)
30# define NDEBUG
31#endif
32
ed0fd852 33#include <limits.h>
99545457 34#include <stdint.h>
318049b8
MR
35#include <stddef.h>
36#include <assert.h>
dbef3f46 37#include "config.h"
2ed6f399 38#include "attributes.h"
2f5421d5 39#include "timer.h"
d9f80ea2
AK
40#include "dict.h"
41
5e4c7ca2 42#ifndef attribute_align_arg
820818a3 43#if ARCH_X86_32 && AV_GCC_VERSION_AT_LEAST(4,2)
5e4c7ca2
RP
44# define attribute_align_arg __attribute__((force_align_arg_pointer))
45#else
46# define attribute_align_arg
47#endif
48#endif
49
cd107896 50#ifndef INT_BIT
28499cc8 51# define INT_BIT (CHAR_BIT * sizeof(int))
cd107896
MR
52#endif
53
7d685b48 54/* avoid usage of dangerous/inappropriate system functions */
84662c01 55#undef malloc
05020c89 56#define malloc please_use_av_malloc
84662c01 57#undef free
05020c89 58#define free please_use_av_free
84662c01 59#undef realloc
05020c89 60#define realloc please_use_av_realloc
84662c01 61#undef time
05020c89 62#define time time_is_forbidden_due_to_security_issues
84662c01 63#undef rand
9f5da4d1 64#define rand rand_is_forbidden_due_to_state_trashing_use_av_lfg_get
84662c01 65#undef srand
9f5da4d1 66#define srand srand_is_forbidden_due_to_state_trashing_use_av_lfg_init
84662c01 67#undef random
9f5da4d1 68#define random random_is_forbidden_due_to_state_trashing_use_av_lfg_get
84662c01 69#undef sprintf
05020c89 70#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
84662c01 71#undef strcat
272605c7 72#define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
84662c01 73#undef exit
c367d067 74#define exit exit_is_forbidden
84662c01 75#undef printf
b58f29a1 76#define printf please_use_av_log_instead_of_printf
84662c01 77#undef fprintf
b58f29a1 78#define fprintf please_use_av_log_instead_of_fprintf
59ec6991 79#undef puts
b58f29a1 80#define puts please_use_av_log_instead_of_puts
c5a2fe8f
LA
81#undef perror
82#define perror please_use_av_log_instead_of_perror
de8d1940
RD
83#undef strcasecmp
84#define strcasecmp please_use_av_strcasecmp
85#undef strncasecmp
86#define strncasecmp please_use_av_strncasecmp
05020c89 87
d31dbec3 88#define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
e48a0966 89{\
ee155011
DB
90 p = av_malloc(size);\
91 if (p == NULL && (size) != 0) {\
d31dbec3
RP
92 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
93 goto label;\
e48a0966
RP
94 }\
95}
96
d31dbec3 97#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
05020c89 98{\
ee155011
DB
99 p = av_mallocz(size);\
100 if (p == NULL && (size) != 0) {\
d31dbec3
RP
101 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
102 goto label;\
05020c89
RD
103 }\
104}
105
335ee1aa 106#include "libm.h"
7b04b8a0 107
d80a7fe5 108/**
49bd8e4b 109 * Return NULL if CONFIG_SMALL is true, otherwise the argument
bfe3676f 110 * without modification. Used to disable the definition of strings
d80a7fe5
AJ
111 * (for example AVCodec long_names).
112 */
113#if CONFIG_SMALL
114# define NULL_IF_CONFIG_SMALL(x) NULL
115#else
116# define NULL_IF_CONFIG_SMALL(x) x
117#endif
118
33586ee7
MN
119
120/**
cae70f99
MR
121 * Define a function with only the non-default version specified.
122 *
123 * On systems with ELF shared libraries, all symbols exported from
2912e87a 124 * Libav libraries are tagged with the name and major version of the
cae70f99
MR
125 * library to which they belong. If a function is moved from one
126 * library to another, a wrapper must be retained in the original
127 * location to preserve binary compatibility.
128 *
129 * Functions defined with this macro will never be used to resolve
130 * symbols by the build-time linker.
131 *
132 * @param type return type of function
133 * @param name name of function
134 * @param args argument list of function
135 * @param ver version tag to assign function
33586ee7 136 */
b462d132 137#if HAVE_SYMVER_ASM_LABEL
ccc87908
MR
138# define FF_SYMVER(type, name, args, ver) \
139 type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver); \
b462d132
MR
140 type ff_##name args
141#elif HAVE_SYMVER_GNU_ASM
ccc87908
MR
142# define FF_SYMVER(type, name, args, ver) \
143 __asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver); \
144 type ff_##name args; \
b462d132
MR
145 type ff_##name args
146#endif
147
37b00b47 148/**
58c42af7 149 * Return NULL if a threading library has not been enabled.
37b00b47
AS
150 * Used to disable threading functions in AVCodec definitions
151 * when not needed.
152 */
153#if HAVE_THREADS
154# define ONLY_IF_THREADS_ENABLED(x) x
155#else
156# define ONLY_IF_THREADS_ENABLED(x) NULL
157#endif
158
17337f54 159#if HAVE_MMX_INLINE
e9735572
RB
160/**
161 * Empty mmx state.
162 * this must be called between any dsp function and float/double code.
163 * for example sin(); dsp->idct_put(); emms_c(); cos()
164 */
165static av_always_inline void emms_c(void)
166{
167 __asm__ volatile ("emms" ::: "memory");
168}
f80ddd5b
RB
169#elif HAVE_MMX && HAVE_MM_EMPTY
170# include <mmintrin.h>
171# define emms_c _mm_empty
17337f54 172#else
f80ddd5b 173# define emms_c()
17337f54 174#endif /* HAVE_MMX_INLINE */
e9735572 175
98790382 176#endif /* AVUTIL_INTERNAL_H */