internal.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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. #include <limits.h>
  30. #include <stdint.h>
  31. #include <stddef.h>
  32. #include <assert.h>
  33. #include "config.h"
  34. #include "attributes.h"
  35. #include "timer.h"
  36. #include "dict.h"
  37. #if ARCH_X86
  38. # include "x86/emms.h"
  39. #endif
  40. #ifndef emms_c
  41. # define emms_c()
  42. #endif
  43. #ifndef attribute_align_arg
  44. #if ARCH_X86_32 && AV_GCC_VERSION_AT_LEAST(4,2)
  45. # define attribute_align_arg __attribute__((force_align_arg_pointer))
  46. #else
  47. # define attribute_align_arg
  48. #endif
  49. #endif
  50. #if defined(_MSC_VER) && CONFIG_SHARED
  51. # define av_export __declspec(dllimport)
  52. #else
  53. # define av_export
  54. #endif
  55. #if HAVE_PRAGMA_DEPRECATED
  56. # define FF_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
  57. # define FF_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"")
  58. #else
  59. # define FF_DISABLE_DEPRECATION_WARNINGS
  60. # define FF_ENABLE_DEPRECATION_WARNINGS
  61. #endif
  62. #ifndef INT_BIT
  63. # define INT_BIT (CHAR_BIT * sizeof(int))
  64. #endif
  65. // Some broken preprocessors need a second expansion
  66. // to be forced to tokenize __VA_ARGS__
  67. #define E1(x) x
  68. #define LOCAL_ALIGNED_A(a, t, v, s, o, ...) \
  69. uint8_t la_##v[sizeof(t s o) + (a)]; \
  70. t (*v) o = (void *)FFALIGN((uintptr_t)la_##v, a)
  71. #define LOCAL_ALIGNED_D(a, t, v, s, o, ...) \
  72. DECLARE_ALIGNED(a, t, la_##v) s o; \
  73. t (*v) o = la_##v
  74. #define LOCAL_ALIGNED(a, t, v, ...) E1(LOCAL_ALIGNED_A(a, t, v, __VA_ARGS__,,))
  75. #if HAVE_LOCAL_ALIGNED_8
  76. # define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_D(8, t, v, __VA_ARGS__,,))
  77. #else
  78. # define LOCAL_ALIGNED_8(t, v, ...) LOCAL_ALIGNED(8, t, v, __VA_ARGS__)
  79. #endif
  80. #if HAVE_LOCAL_ALIGNED_16
  81. # define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_D(16, t, v, __VA_ARGS__,,))
  82. #else
  83. # define LOCAL_ALIGNED_16(t, v, ...) LOCAL_ALIGNED(16, t, v, __VA_ARGS__)
  84. #endif
  85. #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
  86. {\
  87. p = av_malloc(size);\
  88. if (p == NULL && (size) != 0) {\
  89. av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
  90. goto label;\
  91. }\
  92. }
  93. #define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
  94. {\
  95. p = av_mallocz(size);\
  96. if (p == NULL && (size) != 0) {\
  97. av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
  98. goto label;\
  99. }\
  100. }
  101. #include "libm.h"
  102. #if defined(_MSC_VER)
  103. #pragma comment(linker, "/include:"EXTERN_PREFIX"avpriv_strtod")
  104. #pragma comment(linker, "/include:"EXTERN_PREFIX"avpriv_snprintf")
  105. #endif
  106. /**
  107. * Return NULL if CONFIG_SMALL is true, otherwise the argument
  108. * without modification. Used to disable the definition of strings
  109. * (for example AVCodec long_names).
  110. */
  111. #if CONFIG_SMALL
  112. # define NULL_IF_CONFIG_SMALL(x) NULL
  113. #else
  114. # define NULL_IF_CONFIG_SMALL(x) x
  115. #endif
  116. /**
  117. * Define a function with only the non-default version specified.
  118. *
  119. * On systems with ELF shared libraries, all symbols exported from
  120. * Libav libraries are tagged with the name and major version of the
  121. * library to which they belong. If a function is moved from one
  122. * library to another, a wrapper must be retained in the original
  123. * location to preserve binary compatibility.
  124. *
  125. * Functions defined with this macro will never be used to resolve
  126. * symbols by the build-time linker.
  127. *
  128. * @param type return type of function
  129. * @param name name of function
  130. * @param args argument list of function
  131. * @param ver version tag to assign function
  132. */
  133. #if HAVE_SYMVER_ASM_LABEL
  134. # define FF_SYMVER(type, name, args, ver) \
  135. type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver); \
  136. type ff_##name args
  137. #elif HAVE_SYMVER_GNU_ASM
  138. # define FF_SYMVER(type, name, args, ver) \
  139. __asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver); \
  140. type ff_##name args; \
  141. type ff_##name args
  142. #endif
  143. /**
  144. * Return NULL if a threading library has not been enabled.
  145. * Used to disable threading functions in AVCodec definitions
  146. * when not needed.
  147. */
  148. #if HAVE_THREADS
  149. # define ONLY_IF_THREADS_ENABLED(x) x
  150. #else
  151. # define ONLY_IF_THREADS_ENABLED(x) NULL
  152. #endif
  153. /**
  154. * Log a generic warning message about a missing feature.
  155. *
  156. * @param[in] avc a pointer to an arbitrary struct of which the first
  157. * field is a pointer to an AVClass struct
  158. * @param[in] msg string containing the name of the missing feature
  159. */
  160. void avpriv_report_missing_feature(void *avc,
  161. const char *msg, ...) av_printf_format(2, 3);
  162. /**
  163. * Log a generic warning message about a missing feature.
  164. * Additionally request that a sample showcasing the feature be uploaded.
  165. *
  166. * @param[in] avc a pointer to an arbitrary struct of which the first field is
  167. * a pointer to an AVClass struct
  168. * @param[in] msg string containing the name of the missing feature
  169. */
  170. void avpriv_request_sample(void *avc,
  171. const char *msg, ...) av_printf_format(2, 3);
  172. #if HAVE_MSVCRT
  173. #define avpriv_open ff_open
  174. #endif
  175. /**
  176. * A wrapper for open() setting O_CLOEXEC.
  177. */
  178. int avpriv_open(const char *filename, int flags, ...);
  179. #endif /* AVUTIL_INTERNAL_H */