You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

282 lines
8.2KB

  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. * @file
  22. * common internal API header
  23. */
  24. #ifndef AVUTIL_INTERNAL_H
  25. #define AVUTIL_INTERNAL_H
  26. #if !defined(DEBUG) && !defined(NDEBUG)
  27. # define NDEBUG
  28. #endif
  29. #if defined(DEBUG) && !defined(CHECKED)
  30. # define CHECKED
  31. #endif
  32. #include <limits.h>
  33. #include <stdint.h>
  34. #include <stddef.h>
  35. #include <assert.h>
  36. #include "config.h"
  37. #include "attributes.h"
  38. #include "timer.h"
  39. #include "cpu.h"
  40. #include "dict.h"
  41. #include "pixfmt.h"
  42. #include "version.h"
  43. #if ARCH_X86
  44. # include "x86/emms.h"
  45. #endif
  46. #ifndef emms_c
  47. # define emms_c()
  48. #endif
  49. #ifndef attribute_align_arg
  50. #if ARCH_X86_32 && AV_GCC_VERSION_AT_LEAST(4,2)
  51. # define attribute_align_arg __attribute__((force_align_arg_pointer))
  52. #else
  53. # define attribute_align_arg
  54. #endif
  55. #endif
  56. #if defined(_MSC_VER) && CONFIG_SHARED
  57. # define av_export __declspec(dllimport)
  58. #else
  59. # define av_export
  60. #endif
  61. #if HAVE_PRAGMA_DEPRECATED
  62. # if defined(__ICL) || defined (__INTEL_COMPILER)
  63. # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))
  64. # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
  65. # elif defined(_MSC_VER)
  66. # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996))
  67. # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
  68. # else
  69. # define FF_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
  70. # define FF_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"")
  71. # endif
  72. #else
  73. # define FF_DISABLE_DEPRECATION_WARNINGS
  74. # define FF_ENABLE_DEPRECATION_WARNINGS
  75. #endif
  76. #ifndef INT_BIT
  77. # define INT_BIT (CHAR_BIT * sizeof(int))
  78. #endif
  79. #define FF_MEMORY_POISON 0x2a
  80. #define MAKE_ACCESSORS(str, name, type, field) \
  81. type av_##name##_get_##field(const str *s) { return s->field; } \
  82. void av_##name##_set_##field(str *s, type v) { s->field = v; }
  83. // Some broken preprocessors need a second expansion
  84. // to be forced to tokenize __VA_ARGS__
  85. #define E1(x) x
  86. /* Check if the hard coded offset of a struct member still matches reality.
  87. * Induce a compilation failure if not.
  88. */
  89. #define AV_CHECK_OFFSET(s, m, o) struct check_##o { \
  90. int x_##o[offsetof(s, m) == o? 1: -1]; \
  91. }
  92. #define LOCAL_ALIGNED_A(a, t, v, s, o, ...) \
  93. uint8_t la_##v[sizeof(t s o) + (a)]; \
  94. t (*v) o = (void *)FFALIGN((uintptr_t)la_##v, a)
  95. #define LOCAL_ALIGNED_D(a, t, v, s, o, ...) \
  96. DECLARE_ALIGNED(a, t, la_##v) s o; \
  97. t (*v) o = la_##v
  98. #define LOCAL_ALIGNED(a, t, v, ...) E1(LOCAL_ALIGNED_A(a, t, v, __VA_ARGS__,,))
  99. #if HAVE_LOCAL_ALIGNED_8
  100. # define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_D(8, t, v, __VA_ARGS__,,))
  101. #else
  102. # define LOCAL_ALIGNED_8(t, v, ...) LOCAL_ALIGNED(8, t, v, __VA_ARGS__)
  103. #endif
  104. #if HAVE_LOCAL_ALIGNED_16
  105. # define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_D(16, t, v, __VA_ARGS__,,))
  106. #else
  107. # define LOCAL_ALIGNED_16(t, v, ...) LOCAL_ALIGNED(16, t, v, __VA_ARGS__)
  108. #endif
  109. #if HAVE_LOCAL_ALIGNED_32
  110. # define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_D(32, t, v, __VA_ARGS__,,))
  111. #else
  112. # define LOCAL_ALIGNED_32(t, v, ...) LOCAL_ALIGNED(32, t, v, __VA_ARGS__)
  113. #endif
  114. #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
  115. {\
  116. p = av_malloc(size);\
  117. if (!(p) && (size) != 0) {\
  118. av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
  119. goto label;\
  120. }\
  121. }
  122. #define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
  123. {\
  124. p = av_mallocz(size);\
  125. if (!(p) && (size) != 0) {\
  126. av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
  127. goto label;\
  128. }\
  129. }
  130. #define FF_ALLOC_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)\
  131. {\
  132. p = av_malloc_array(nelem, elsize);\
  133. if (!p) {\
  134. av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
  135. goto label;\
  136. }\
  137. }
  138. #define FF_ALLOCZ_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)\
  139. {\
  140. p = av_mallocz_array(nelem, elsize);\
  141. if (!p) {\
  142. av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
  143. goto label;\
  144. }\
  145. }
  146. #include "libm.h"
  147. #if defined(_MSC_VER)
  148. #pragma comment(linker, "/include:"EXTERN_PREFIX"avpriv_strtod")
  149. #pragma comment(linker, "/include:"EXTERN_PREFIX"avpriv_snprintf")
  150. #endif
  151. /**
  152. * Return NULL if CONFIG_SMALL is true, otherwise the argument
  153. * without modification. Used to disable the definition of strings
  154. * (for example AVCodec long_names).
  155. */
  156. #if CONFIG_SMALL
  157. # define NULL_IF_CONFIG_SMALL(x) NULL
  158. #else
  159. # define NULL_IF_CONFIG_SMALL(x) x
  160. #endif
  161. /**
  162. * Define a function with only the non-default version specified.
  163. *
  164. * On systems with ELF shared libraries, all symbols exported from
  165. * FFmpeg libraries are tagged with the name and major version of the
  166. * library to which they belong. If a function is moved from one
  167. * library to another, a wrapper must be retained in the original
  168. * location to preserve binary compatibility.
  169. *
  170. * Functions defined with this macro will never be used to resolve
  171. * symbols by the build-time linker.
  172. *
  173. * @param type return type of function
  174. * @param name name of function
  175. * @param args argument list of function
  176. * @param ver version tag to assign function
  177. */
  178. #if HAVE_SYMVER_ASM_LABEL
  179. # define FF_SYMVER(type, name, args, ver) \
  180. type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver); \
  181. type ff_##name args
  182. #elif HAVE_SYMVER_GNU_ASM
  183. # define FF_SYMVER(type, name, args, ver) \
  184. __asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver); \
  185. type ff_##name args; \
  186. type ff_##name args
  187. #endif
  188. /**
  189. * Return NULL if a threading library has not been enabled.
  190. * Used to disable threading functions in AVCodec definitions
  191. * when not needed.
  192. */
  193. #if HAVE_THREADS
  194. # define ONLY_IF_THREADS_ENABLED(x) x
  195. #else
  196. # define ONLY_IF_THREADS_ENABLED(x) NULL
  197. #endif
  198. /**
  199. * Log a generic warning message about a missing feature.
  200. *
  201. * @param[in] avc a pointer to an arbitrary struct of which the first
  202. * field is a pointer to an AVClass struct
  203. * @param[in] msg string containing the name of the missing feature
  204. */
  205. void avpriv_report_missing_feature(void *avc,
  206. const char *msg, ...) av_printf_format(2, 3);
  207. /**
  208. * Log a generic warning message about a missing feature.
  209. * Additionally request that a sample showcasing the feature be uploaded.
  210. *
  211. * @param[in] avc a pointer to an arbitrary struct of which the first field is
  212. * a pointer to an AVClass struct
  213. * @param[in] msg string containing the name of the missing feature
  214. */
  215. void avpriv_request_sample(void *avc,
  216. const char *msg, ...) av_printf_format(2, 3);
  217. #if HAVE_LIBC_MSVCRT
  218. #define avpriv_open ff_open
  219. #define PTRDIFF_SPECIFIER "Id"
  220. #define SIZE_SPECIFIER "Iu"
  221. #else
  222. #define PTRDIFF_SPECIFIER "td"
  223. #define SIZE_SPECIFIER "zu"
  224. #endif
  225. // For debuging we use signed operations so overflows can be detected (by ubsan)
  226. // For production we use unsigned so there are no undefined operations
  227. #ifdef CHECKED
  228. #define SUINT int
  229. #define SUINT32 int32_t
  230. #else
  231. #define SUINT unsigned
  232. #define SUINT32 uint32_t
  233. #endif
  234. /**
  235. * A wrapper for open() setting O_CLOEXEC.
  236. */
  237. int avpriv_open(const char *filename, int flags, ...);
  238. int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt);
  239. #if FF_API_GET_CHANNEL_LAYOUT_COMPAT
  240. uint64_t ff_get_channel_layout(const char *name, int compat);
  241. #endif
  242. #endif /* AVUTIL_INTERNAL_H */