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 "libm.h"
44 #include "macros.h"
45 
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))
49 #else
50 # define attribute_align_arg
51 #endif
52 #endif
53 
54 #if HAVE_PRAGMA_DEPRECATED
55 # if defined(__ICL) || defined (__INTEL_COMPILER)
56 # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))
57 # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
58 # elif defined(_MSC_VER)
59 # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996))
60 # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
61 # else
62 # define FF_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
63 # define FF_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic pop")
64 # endif
65 #else
66 # define FF_DISABLE_DEPRECATION_WARNINGS
67 # define FF_ENABLE_DEPRECATION_WARNINGS
68 #endif
69 
70 
71 #define FF_ALLOC_TYPED_ARRAY(p, nelem) (p = av_malloc_array(nelem, sizeof(*p)))
72 #define FF_ALLOCZ_TYPED_ARRAY(p, nelem) (p = av_calloc(nelem, sizeof(*p)))
73 
74 #define FF_PTR_ADD(ptr, off) ((off) ? (ptr) + (off) : (ptr))
75 
76 /**
77  * Access a field in a structure by its offset.
78  */
79 #define FF_FIELD_AT(type, off, obj) (*(type *)((char *)&(obj) + (off)))
80 
81 /**
82  * Return NULL if CONFIG_SMALL is true, otherwise the argument
83  * without modification. Used to disable the definition of strings.
84  */
85 #if CONFIG_SMALL
86 # define NULL_IF_CONFIG_SMALL(x) NULL
87 #else
88 # define NULL_IF_CONFIG_SMALL(x) x
89 #endif
90 
91 /**
92  * Log a generic warning message about a missing feature.
93  *
94  * @param[in] avc a pointer to an arbitrary struct of which the first
95  * field is a pointer to an AVClass struct
96  * @param[in] msg string containing the name of the missing feature
97  */
98 void avpriv_report_missing_feature(void *avc,
99  const char *msg, ...) av_printf_format(2, 3);
100 
101 /**
102  * Log a generic warning message about a missing feature.
103  * Additionally request that a sample showcasing the feature be uploaded.
104  *
105  * @param[in] avc a pointer to an arbitrary struct of which the first field is
106  * a pointer to an AVClass struct
107  * @param[in] msg string containing the name of the missing feature
108  */
109 void avpriv_request_sample(void *avc,
110  const char *msg, ...) av_printf_format(2, 3);
111 
112 #ifdef DEBUG
113 # define ff_dlog(ctx, ...) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__)
114 #else
115 # define ff_dlog(ctx, ...) do { if (0) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
116 #endif
117 
118 #ifdef TRACE
119 # define ff_tlog(ctx, ...) av_log(ctx, AV_LOG_TRACE, __VA_ARGS__)
120 #else
121 # define ff_tlog(ctx, ...) do { } while(0)
122 #endif
123 
124 // For debugging we use signed operations so overflows can be detected (by ubsan)
125 // For production we use unsigned so there are no undefined operations
126 #ifdef CHECKED
127 #define SUINT int
128 #define SUINT32 int32_t
129 #else
130 #define SUINT unsigned
131 #define SUINT32 uint32_t
132 #endif
133 
134 static av_always_inline av_const int avpriv_mirror(int x, int w)
135 {
136  if (!w)
137  return 0;
138 
139  while ((unsigned)x > (unsigned)w) {
140  x = -x;
141  if (x < 0)
142  x += 2 * w;
143  }
144  return x;
145 }
146 
147 #endif /* AVUTIL_INTERNAL_H */
av_printf_format
#define av_printf_format(fmtpos, attrpos)
Definition: attributes.h:218
libm.h
av_always_inline
#define av_always_inline
Definition: attributes.h:76
macros.h
av_const
#define av_const
Definition: attributes.h:113
limits.h
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.
attributes.h
avpriv_mirror
static av_always_inline av_const int avpriv_mirror(int x, int w)
Definition: internal.h:134
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.
w
uint8_t w
Definition: llvidencdsp.c:39