FFmpeg
internal.h
Go to the documentation of this file.
1 /*
2  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
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
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * common internal API header
24  */
25 
26 #ifndef AVUTIL_INTERNAL_H
27 #define AVUTIL_INTERNAL_H
28 
29 #if !defined(DEBUG) && !defined(NDEBUG)
30 # define NDEBUG
31 #endif
32 
33 // This can be enabled to allow detection of additional integer overflows with ubsan
34 //#define CHECKED
35 
36 #include <limits.h>
37 #include <stdint.h>
38 #include <stddef.h>
39 #include <assert.h>
40 #include <stdio.h>
41 #include "config.h"
42 #include "attributes.h"
43 #include "timer.h"
44 #include "macros.h"
45 #include "pixfmt.h"
46 
47 #if ARCH_X86
48 # include "x86/emms.h"
49 #endif
50 
51 #ifndef emms_c
52 # define emms_c() do {} while(0)
53 #endif
54 
55 #ifndef attribute_align_arg
56 #if ARCH_X86_32 && AV_GCC_VERSION_AT_LEAST(4,2)
57 # define attribute_align_arg __attribute__((force_align_arg_pointer))
58 #else
59 # define attribute_align_arg
60 #endif
61 #endif
62 
63 #if defined(_WIN32) && CONFIG_SHARED && !defined(BUILDING_avutil)
64 # define av_export_avutil __declspec(dllimport)
65 #else
66 # define av_export_avutil
67 #endif
68 
69 #if HAVE_PRAGMA_DEPRECATED
70 # if defined(__ICL) || defined (__INTEL_COMPILER)
71 # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))
72 # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
73 # elif defined(_MSC_VER)
74 # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996))
75 # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
76 # else
77 # define FF_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
78 # define FF_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic pop")
79 # endif
80 #else
81 # define FF_DISABLE_DEPRECATION_WARNINGS
82 # define FF_ENABLE_DEPRECATION_WARNINGS
83 #endif
84 
85 
86 #define FF_MEMORY_POISON 0x2a
87 
88 /* Check if the hard coded offset of a struct member still matches reality.
89  * Induce a compilation failure if not.
90  */
91 #define AV_CHECK_OFFSET(s, m, o) struct check_##o { \
92  int x_##o[offsetof(s, m) == o? 1: -1]; \
93  }
94 
95 
96 #define FF_ALLOC_TYPED_ARRAY(p, nelem) (p = av_malloc_array(nelem, sizeof(*p)))
97 #define FF_ALLOCZ_TYPED_ARRAY(p, nelem) (p = av_calloc(nelem, sizeof(*p)))
98 
99 #define FF_PTR_ADD(ptr, off) ((off) ? (ptr) + (off) : (ptr))
100 
101 /**
102  * Access a field in a structure by its offset.
103  */
104 #define FF_FIELD_AT(type, off, obj) (*(type *)((char *)&(obj) + (off)))
105 
106 #include "libm.h"
107 
108 /**
109  * Return NULL if CONFIG_SMALL is true, otherwise the argument
110  * without modification. Used to disable the definition of strings.
111  */
112 #if CONFIG_SMALL
113 # define NULL_IF_CONFIG_SMALL(x) NULL
114 #else
115 # define NULL_IF_CONFIG_SMALL(x) x
116 #endif
117 
118 /**
119  * Log a generic warning message about a missing feature.
120  *
121  * @param[in] avc a pointer to an arbitrary struct of which the first
122  * field is a pointer to an AVClass struct
123  * @param[in] msg string containing the name of the missing feature
124  */
125 void avpriv_report_missing_feature(void *avc,
126  const char *msg, ...) av_printf_format(2, 3);
127 
128 /**
129  * Log a generic warning message about a missing feature.
130  * Additionally request that a sample showcasing the feature be uploaded.
131  *
132  * @param[in] avc a pointer to an arbitrary struct of which the first field is
133  * a pointer to an AVClass struct
134  * @param[in] msg string containing the name of the missing feature
135  */
136 void avpriv_request_sample(void *avc,
137  const char *msg, ...) av_printf_format(2, 3);
138 
139 #if HAVE_LIBC_MSVCRT
140 #include <crtversion.h>
141 #if defined(_VC_CRT_MAJOR_VERSION) && _VC_CRT_MAJOR_VERSION < 14
142 #pragma comment(linker, "/include:" EXTERN_PREFIX "avpriv_strtod")
143 #pragma comment(linker, "/include:" EXTERN_PREFIX "avpriv_snprintf")
144 #endif
145 
146 #define PTRDIFF_SPECIFIER "Id"
147 #define SIZE_SPECIFIER "Iu"
148 #else
149 #define PTRDIFF_SPECIFIER "td"
150 #define SIZE_SPECIFIER "zu"
151 #endif
152 
153 #ifdef DEBUG
154 # define ff_dlog(ctx, ...) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__)
155 #else
156 # define ff_dlog(ctx, ...) do { if (0) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
157 #endif
158 
159 #ifdef TRACE
160 # define ff_tlog(ctx, ...) av_log(ctx, AV_LOG_TRACE, __VA_ARGS__)
161 #else
162 # define ff_tlog(ctx, ...) do { } while(0)
163 #endif
164 
165 // For debuging we use signed operations so overflows can be detected (by ubsan)
166 // For production we use unsigned so there are no undefined operations
167 #ifdef CHECKED
168 #define SUINT int
169 #define SUINT32 int32_t
170 #else
171 #define SUINT unsigned
172 #define SUINT32 uint32_t
173 #endif
174 
175 int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt);
176 
177 static av_always_inline av_const int avpriv_mirror(int x, int w)
178 {
179  if (!w)
180  return 0;
181 
182  while ((unsigned)x > (unsigned)w) {
183  x = -x;
184  if (x < 0)
185  x += 2 * w;
186  }
187  return x;
188 }
189 
190 #endif /* AVUTIL_INTERNAL_H */
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
libm.h
avpriv_set_systematic_pal2
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
Definition: imgutils.c:178
w
uint8_t w
Definition: llviddspenc.c:38
av_const
#define av_const
Definition: attributes.h:84
macros.h
limits.h
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demuxing_decoding.c:41
avpriv_request_sample
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
av_printf_format
#define av_printf_format(fmtpos, attrpos)
Definition: attributes.h:161
timer.h
avpriv_mirror
static av_always_inline av_const int avpriv_mirror(int x, int w)
Definition: internal.h:177
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
attributes.h
emms.h
av_always_inline
#define av_always_inline
Definition: attributes.h:49
pixfmt.h