2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
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.
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.
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
23 * common internal API header
26 #ifndef AVUTIL_INTERNAL_H
27 #define AVUTIL_INTERNAL_H
29 #if !defined(DEBUG) && !defined(NDEBUG)
33 // This can be enabled to allow detection of additional integer overflows with ubsan
42 #include "attributes.h"
46 #ifndef attribute_align_arg
47 #if ARCH_X86_32 && AV_GCC_VERSION_AT_LEAST(4,2)
48 # define attribute_align_arg __attribute__((force_align_arg_pointer))
50 # define attribute_align_arg
54 #if defined(_WIN32) && CONFIG_SHARED && !defined(BUILDING_avutil)
55 # define av_export_avutil __declspec(dllimport)
57 # define av_export_avutil
60 #if HAVE_PRAGMA_DEPRECATED
61 # if defined(__ICL) || defined (__INTEL_COMPILER)
62 # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))
63 # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
64 # elif defined(_MSC_VER)
65 # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996))
66 # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
68 # define FF_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
69 # define FF_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic pop")
72 # define FF_DISABLE_DEPRECATION_WARNINGS
73 # define FF_ENABLE_DEPRECATION_WARNINGS
77 #define FF_MEMORY_POISON 0x2a
79 /* Check if the hard coded offset of a struct member still matches reality.
80 * Induce a compilation failure if not.
82 #define AV_CHECK_OFFSET(s, m, o) struct check_##o { \
83 int x_##o[offsetof(s, m) == o? 1: -1]; \
87 #define FF_ALLOC_TYPED_ARRAY(p, nelem) (p = av_malloc_array(nelem, sizeof(*p)))
88 #define FF_ALLOCZ_TYPED_ARRAY(p, nelem) (p = av_calloc(nelem, sizeof(*p)))
90 #define FF_PTR_ADD(ptr, off) ((off) ? (ptr) + (off) : (ptr))
93 * Access a field in a structure by its offset.
95 #define FF_FIELD_AT(type, off, obj) (*(type *)((char *)&(obj) + (off)))
100 * Return NULL if CONFIG_SMALL is true, otherwise the argument
101 * without modification. Used to disable the definition of strings.
104 # define NULL_IF_CONFIG_SMALL(x) NULL
106 # define NULL_IF_CONFIG_SMALL(x) x
110 * Log a generic warning message about a missing feature.
112 * @param[in] avc a pointer to an arbitrary struct of which the first
113 * field is a pointer to an AVClass struct
114 * @param[in] msg string containing the name of the missing feature
116 void avpriv_report_missing_feature(void *avc,
117 const char *msg, ...) av_printf_format(2, 3);
120 * Log a generic warning message about a missing feature.
121 * Additionally request that a sample showcasing the feature be uploaded.
123 * @param[in] avc a pointer to an arbitrary struct of which the first field is
124 * a pointer to an AVClass struct
125 * @param[in] msg string containing the name of the missing feature
127 void avpriv_request_sample(void *avc,
128 const char *msg, ...) av_printf_format(2, 3);
131 #include <crtversion.h>
132 #if defined(_VC_CRT_MAJOR_VERSION) && _VC_CRT_MAJOR_VERSION < 14
133 #pragma comment(linker, "/include:" EXTERN_PREFIX "avpriv_strtod")
134 #pragma comment(linker, "/include:" EXTERN_PREFIX "avpriv_snprintf")
137 #define PTRDIFF_SPECIFIER "Id"
138 #define SIZE_SPECIFIER "Iu"
140 #define PTRDIFF_SPECIFIER "td"
141 #define SIZE_SPECIFIER "zu"
145 # define ff_dlog(ctx, ...) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__)
147 # define ff_dlog(ctx, ...) do { if (0) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
151 # define ff_tlog(ctx, ...) av_log(ctx, AV_LOG_TRACE, __VA_ARGS__)
153 # define ff_tlog(ctx, ...) do { } while(0)
156 // For debuging we use signed operations so overflows can be detected (by ubsan)
157 // For production we use unsigned so there are no undefined operations
160 #define SUINT32 int32_t
162 #define SUINT unsigned
163 #define SUINT32 uint32_t
166 int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt);
168 static av_always_inline av_const int avpriv_mirror(int x, int w)
173 while ((unsigned)x > (unsigned)w) {
181 #endif /* AVUTIL_INTERNAL_H */