Statistics
| Branch: | Revision:

ffmpeg / libavutil / internal.h @ d112aa5a

History | View | Annotate | Download (6.2 KB)

1 04d7f601 Diego Biurrun
/*
2
 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3
 *
4 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7 04d7f601 Diego Biurrun
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
10 04d7f601 Diego Biurrun
 *
11 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
12 04d7f601 Diego Biurrun
 * 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
17 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
18 04d7f601 Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21 05020c89 Reimar Döffinger
/**
22 ba87f080 Diego Biurrun
 * @file
23 89c9ff50 Diego Biurrun
 * common internal API header
24 05020c89 Reimar Döffinger
 */
25
26 98790382 Stefano Sabatini
#ifndef AVUTIL_INTERNAL_H
27
#define AVUTIL_INTERNAL_H
28 05020c89 Reimar Döffinger
29 318049b8 Måns Rullgård
#if !defined(DEBUG) && !defined(NDEBUG)
30
#    define NDEBUG
31
#endif
32
33 ed0fd852 Diego Biurrun
#include <limits.h>
34 99545457 Måns Rullgård
#include <stdint.h>
35 318049b8 Måns Rullgård
#include <stddef.h>
36
#include <assert.h>
37 dbef3f46 Diego Biurrun
#include "config.h"
38 2ed6f399 Måns Rullgård
#include "attributes.h"
39 2f5421d5 Aurelien Jacobs
#include "timer.h"
40 99545457 Måns Rullgård
41 5e4c7ca2 Ramiro Polla
#ifndef attribute_align_arg
42 086e997e Carl Eugen Hoyos
#if ARCH_X86_32 && (!defined(__ICC) || __ICC > 1200) && AV_GCC_VERSION_AT_LEAST(4,2)
43 5e4c7ca2 Ramiro Polla
#    define attribute_align_arg __attribute__((force_align_arg_pointer))
44
#else
45
#    define attribute_align_arg
46
#endif
47
#endif
48
49 33586ee7 Michael Niedermayer
50
/**
51 49bd8e4b Måns Rullgård
 * Mark a variable as used and prevent the compiler from optimizing it away.
52
 * This is useful for asm that accesses varibles in ways that the compiler does not
53 33586ee7 Michael Niedermayer
 * understand
54
 */
55 5403f857 Måns Rullgård
#ifndef attribute_used
56 52476c1b Carl Eugen Hoyos
#if AV_GCC_VERSION_AT_LEAST(3,1)
57 5403f857 Måns Rullgård
#    define attribute_used __attribute__((used))
58
#else
59
#    define attribute_used
60
#endif
61
#endif
62
63 cd107896 Måns Rullgård
#ifndef INT16_MIN
64 ee155011 Diego Biurrun
#define INT16_MIN       (-0x7fff - 1)
65 cd107896 Måns Rullgård
#endif
66
67
#ifndef INT16_MAX
68
#define INT16_MAX       0x7fff
69
#endif
70
71
#ifndef INT32_MIN
72 ee155011 Diego Biurrun
#define INT32_MIN       (-0x7fffffff - 1)
73 cd107896 Måns Rullgård
#endif
74
75
#ifndef INT32_MAX
76
#define INT32_MAX       0x7fffffff
77
#endif
78
79
#ifndef UINT32_MAX
80
#define UINT32_MAX      0xffffffff
81
#endif
82
83
#ifndef INT64_MIN
84 ee155011 Diego Biurrun
#define INT64_MIN       (-0x7fffffffffffffffLL - 1)
85 cd107896 Måns Rullgård
#endif
86
87
#ifndef INT64_MAX
88 8da9266c Måns Rullgård
#define INT64_MAX INT64_C(9223372036854775807)
89 cd107896 Måns Rullgård
#endif
90
91
#ifndef UINT64_MAX
92 8da9266c Måns Rullgård
#define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
93 cd107896 Måns Rullgård
#endif
94
95
#ifndef INT_BIT
96 28499cc8 Måns Rullgård
#    define INT_BIT (CHAR_BIT * sizeof(int))
97 cd107896 Måns Rullgård
#endif
98
99 05020c89 Reimar Döffinger
#ifndef offsetof
100 ee155011 Diego Biurrun
#    define offsetof(T, F) ((unsigned int)((char *)&((T *)0)->F))
101 05020c89 Reimar Döffinger
#endif
102
103 7d9beec7 Ramiro Polla
/* Use to export labels from asm. */
104
#define LABEL_MANGLE(a) EXTERN_PREFIX #a
105
106 05020c89 Reimar Döffinger
// Use rip-relative addressing if compiling PIC code on x86-64.
107 b250f9c6 Aurelien Jacobs
#if ARCH_X86_64 && defined(PIC)
108 df22c35d Alexander Strange
#    define LOCAL_MANGLE(a) #a "(%%rip)"
109 edfd6975 Diego Biurrun
#else
110 df22c35d Alexander Strange
#    define LOCAL_MANGLE(a) #a
111 635eb0cc Måns Rullgård
#endif
112 05020c89 Reimar Döffinger
113 df22c35d Alexander Strange
#define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
114
115 05020c89 Reimar Döffinger
/* debug stuff */
116
117
/* dprintf macros */
118 635eb0cc Måns Rullgård
#ifdef DEBUG
119 318c5e05 Michel Bardiaux
#    define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
120 635eb0cc Måns Rullgård
#else
121 318c5e05 Michel Bardiaux
#    define dprintf(pctx, ...)
122 635eb0cc Måns Rullgård
#endif
123 05020c89 Reimar Döffinger
124 635eb0cc Måns Rullgård
#define av_abort()      do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
125 05020c89 Reimar Döffinger
126 7e5f82dc Måns Rullgård
/* math */
127
128 b250f9c6 Aurelien Jacobs
#if ARCH_X86
129 05020c89 Reimar Döffinger
#define MASK_ABS(mask, level)\
130 be449fca Diego Pettenò
            __asm__ volatile(\
131 7e14b808 Reimar Döffinger
                "cltd                   \n\t"\
132 05020c89 Reimar Döffinger
                "xorl %1, %0            \n\t"\
133
                "subl %1, %0            \n\t"\
134
                : "+a" (level), "=&d" (mask)\
135
            );
136
#else
137
#define MASK_ABS(mask, level)\
138 ee155011 Diego Biurrun
            mask  = level >> 31;\
139
            level = (level ^ mask) - mask;
140 05020c89 Reimar Döffinger
#endif
141
142 7d685b48 Diego Biurrun
/* avoid usage of dangerous/inappropriate system functions */
143 84662c01 Måns Rullgård
#undef  malloc
144 05020c89 Reimar Döffinger
#define malloc please_use_av_malloc
145 84662c01 Måns Rullgård
#undef  free
146 05020c89 Reimar Döffinger
#define free please_use_av_free
147 84662c01 Måns Rullgård
#undef  realloc
148 05020c89 Reimar Döffinger
#define realloc please_use_av_realloc
149 84662c01 Måns Rullgård
#undef  time
150 05020c89 Reimar Döffinger
#define time time_is_forbidden_due_to_security_issues
151 84662c01 Måns Rullgård
#undef  rand
152 9f5da4d1 Diego Biurrun
#define rand rand_is_forbidden_due_to_state_trashing_use_av_lfg_get
153 84662c01 Måns Rullgård
#undef  srand
154 9f5da4d1 Diego Biurrun
#define srand srand_is_forbidden_due_to_state_trashing_use_av_lfg_init
155 84662c01 Måns Rullgård
#undef  random
156 9f5da4d1 Diego Biurrun
#define random random_is_forbidden_due_to_state_trashing_use_av_lfg_get
157 84662c01 Måns Rullgård
#undef  sprintf
158 05020c89 Reimar Döffinger
#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
159 84662c01 Måns Rullgård
#undef  strcat
160 272605c7 Reimar Döffinger
#define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
161 84662c01 Måns Rullgård
#undef  exit
162 c367d067 Michael Niedermayer
#define exit exit_is_forbidden
163 6123abad Stefano Sabatini
#ifndef LIBAVFORMAT_BUILD
164 84662c01 Måns Rullgård
#undef  printf
165 b58f29a1 Diego Biurrun
#define printf please_use_av_log_instead_of_printf
166 84662c01 Måns Rullgård
#undef  fprintf
167 b58f29a1 Diego Biurrun
#define fprintf please_use_av_log_instead_of_fprintf
168 59ec6991 Diego Biurrun
#undef  puts
169 b58f29a1 Diego Biurrun
#define puts please_use_av_log_instead_of_puts
170 c5a2fe8f Luca Abeni
#undef  perror
171
#define perror please_use_av_log_instead_of_perror
172 05020c89 Reimar Döffinger
#endif
173
174 d31dbec3 Ramiro Polla
#define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
175 e48a0966 Ramiro Polla
{\
176 ee155011 Diego Biurrun
    p = av_malloc(size);\
177
    if (p == NULL && (size) != 0) {\
178 d31dbec3 Ramiro Polla
        av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
179
        goto label;\
180 e48a0966 Ramiro Polla
    }\
181
}
182
183 d31dbec3 Ramiro Polla
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
184 05020c89 Reimar Döffinger
{\
185 ee155011 Diego Biurrun
    p = av_mallocz(size);\
186
    if (p == NULL && (size) != 0) {\
187 d31dbec3 Ramiro Polla
        av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
188
        goto label;\
189 05020c89 Reimar Döffinger
    }\
190
}
191
192 335ee1aa Måns Rullgård
#include "libm.h"
193 7b04b8a0 Michael Kostylev
194 d80a7fe5 Aurelien Jacobs
/**
195 49bd8e4b Måns Rullgård
 * Return NULL if CONFIG_SMALL is true, otherwise the argument
196 bfe3676f Diego Biurrun
 * without modification. Used to disable the definition of strings
197 d80a7fe5 Aurelien Jacobs
 * (for example AVCodec long_names).
198
 */
199
#if CONFIG_SMALL
200
#   define NULL_IF_CONFIG_SMALL(x) NULL
201
#else
202
#   define NULL_IF_CONFIG_SMALL(x) x
203
#endif
204
205 33586ee7 Michael Niedermayer
206
/**
207 cae70f99 Måns Rullgård
 * Define a function with only the non-default version specified.
208
 *
209
 * On systems with ELF shared libraries, all symbols exported from
210
 * FFmpeg libraries are tagged with the name and major version of the
211
 * library to which they belong.  If a function is moved from one
212
 * library to another, a wrapper must be retained in the original
213
 * location to preserve binary compatibility.
214
 *
215
 * Functions defined with this macro will never be used to resolve
216
 * symbols by the build-time linker.
217
 *
218
 * @param type return type of function
219
 * @param name name of function
220
 * @param args argument list of function
221
 * @param ver  version tag to assign function
222 33586ee7 Michael Niedermayer
 */
223 b462d132 Måns Rullgård
#if HAVE_SYMVER_ASM_LABEL
224 ccc87908 Måns Rullgård
#   define FF_SYMVER(type, name, args, ver)                     \
225
    type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver);  \
226 b462d132 Måns Rullgård
    type ff_##name args
227
#elif HAVE_SYMVER_GNU_ASM
228 ccc87908 Måns Rullgård
#   define FF_SYMVER(type, name, args, ver)                             \
229
    __asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver);      \
230
    type ff_##name args;                                                \
231 b462d132 Måns Rullgård
    type ff_##name args
232
#endif
233
234 98790382 Stefano Sabatini
#endif /* AVUTIL_INTERNAL_H */