internal.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. #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 "cpu.h"
  37. #include "dict.h"
  38. #ifndef attribute_align_arg
  39. #if ARCH_X86_32 && AV_GCC_VERSION_AT_LEAST(4,2)
  40. # define attribute_align_arg __attribute__((force_align_arg_pointer))
  41. #else
  42. # define attribute_align_arg
  43. #endif
  44. #endif
  45. #if defined(_MSC_VER) && CONFIG_SHARED
  46. # define av_export __declspec(dllimport)
  47. #else
  48. # define av_export
  49. #endif
  50. #ifndef INT_BIT
  51. # define INT_BIT (CHAR_BIT * sizeof(int))
  52. #endif
  53. #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
  54. {\
  55. p = av_malloc(size);\
  56. if (p == NULL && (size) != 0) {\
  57. av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
  58. goto label;\
  59. }\
  60. }
  61. #define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
  62. {\
  63. p = av_mallocz(size);\
  64. if (p == NULL && (size) != 0) {\
  65. av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
  66. goto label;\
  67. }\
  68. }
  69. #include "libm.h"
  70. /**
  71. * Return NULL if CONFIG_SMALL is true, otherwise the argument
  72. * without modification. Used to disable the definition of strings
  73. * (for example AVCodec long_names).
  74. */
  75. #if CONFIG_SMALL
  76. # define NULL_IF_CONFIG_SMALL(x) NULL
  77. #else
  78. # define NULL_IF_CONFIG_SMALL(x) x
  79. #endif
  80. /**
  81. * Define a function with only the non-default version specified.
  82. *
  83. * On systems with ELF shared libraries, all symbols exported from
  84. * FFmpeg libraries are tagged with the name and major version of the
  85. * library to which they belong. If a function is moved from one
  86. * library to another, a wrapper must be retained in the original
  87. * location to preserve binary compatibility.
  88. *
  89. * Functions defined with this macro will never be used to resolve
  90. * symbols by the build-time linker.
  91. *
  92. * @param type return type of function
  93. * @param name name of function
  94. * @param args argument list of function
  95. * @param ver version tag to assign function
  96. */
  97. #if HAVE_SYMVER_ASM_LABEL
  98. # define FF_SYMVER(type, name, args, ver) \
  99. type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver); \
  100. type ff_##name args
  101. #elif HAVE_SYMVER_GNU_ASM
  102. # define FF_SYMVER(type, name, args, ver) \
  103. __asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver); \
  104. type ff_##name args; \
  105. type ff_##name args
  106. #endif
  107. /**
  108. * Return NULL if a threading library has not been enabled.
  109. * Used to disable threading functions in AVCodec definitions
  110. * when not needed.
  111. */
  112. #if HAVE_THREADS
  113. # define ONLY_IF_THREADS_ENABLED(x) x
  114. #else
  115. # define ONLY_IF_THREADS_ENABLED(x) NULL
  116. #endif
  117. #if HAVE_MMX_INLINE
  118. /**
  119. * Empty mmx state.
  120. * this must be called between any dsp function and float/double code.
  121. * for example sin(); dsp->idct_put(); emms_c(); cos()
  122. */
  123. static av_always_inline void emms_c(void)
  124. {
  125. if(av_get_cpu_flags() & AV_CPU_FLAG_MMX)
  126. __asm__ volatile ("emms" ::: "memory");
  127. }
  128. #elif HAVE_MMX && HAVE_MM_EMPTY
  129. # include <mmintrin.h>
  130. # define emms_c _mm_empty
  131. #else
  132. # define emms_c()
  133. #endif /* HAVE_MMX_INLINE */
  134. #endif /* AVUTIL_INTERNAL_H */