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.

200 lines
4.9KB

  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. #ifndef attribute_align_arg
  37. #if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,2)
  38. # define attribute_align_arg __attribute__((force_align_arg_pointer))
  39. #else
  40. # define attribute_align_arg
  41. #endif
  42. #endif
  43. #ifndef attribute_used
  44. #if AV_GCC_VERSION_AT_LEAST(3,1)
  45. # define attribute_used __attribute__((used))
  46. #else
  47. # define attribute_used
  48. #endif
  49. #endif
  50. #ifndef INT16_MIN
  51. #define INT16_MIN (-0x7fff - 1)
  52. #endif
  53. #ifndef INT16_MAX
  54. #define INT16_MAX 0x7fff
  55. #endif
  56. #ifndef INT32_MIN
  57. #define INT32_MIN (-0x7fffffff - 1)
  58. #endif
  59. #ifndef INT32_MAX
  60. #define INT32_MAX 0x7fffffff
  61. #endif
  62. #ifndef UINT32_MAX
  63. #define UINT32_MAX 0xffffffff
  64. #endif
  65. #ifndef INT64_MIN
  66. #define INT64_MIN (-0x7fffffffffffffffLL - 1)
  67. #endif
  68. #ifndef INT64_MAX
  69. #define INT64_MAX INT64_C(9223372036854775807)
  70. #endif
  71. #ifndef UINT64_MAX
  72. #define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
  73. #endif
  74. #ifndef INT_BIT
  75. # define INT_BIT (CHAR_BIT * sizeof(int))
  76. #endif
  77. #ifndef offsetof
  78. # define offsetof(T, F) ((unsigned int)((char *)&((T *)0)->F))
  79. #endif
  80. /* Use to export labels from asm. */
  81. #define LABEL_MANGLE(a) EXTERN_PREFIX #a
  82. // Use rip-relative addressing if compiling PIC code on x86-64.
  83. #if ARCH_X86_64 && defined(PIC)
  84. # define LOCAL_MANGLE(a) #a "(%%rip)"
  85. #else
  86. # define LOCAL_MANGLE(a) #a
  87. #endif
  88. #define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
  89. /* debug stuff */
  90. /* dprintf macros */
  91. #ifdef DEBUG
  92. # define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
  93. #else
  94. # define dprintf(pctx, ...)
  95. #endif
  96. #define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
  97. /* math */
  98. #if ARCH_X86
  99. #define MASK_ABS(mask, level)\
  100. __asm__ volatile(\
  101. "cltd \n\t"\
  102. "xorl %1, %0 \n\t"\
  103. "subl %1, %0 \n\t"\
  104. : "+a" (level), "=&d" (mask)\
  105. );
  106. #else
  107. #define MASK_ABS(mask, level)\
  108. mask = level >> 31;\
  109. level = (level ^ mask) - mask;
  110. #endif
  111. /* avoid usage of dangerous/inappropriate system functions */
  112. #undef malloc
  113. #define malloc please_use_av_malloc
  114. #undef free
  115. #define free please_use_av_free
  116. #undef realloc
  117. #define realloc please_use_av_realloc
  118. #undef time
  119. #define time time_is_forbidden_due_to_security_issues
  120. #undef rand
  121. #define rand rand_is_forbidden_due_to_state_trashing_use_av_lfg_get
  122. #undef srand
  123. #define srand srand_is_forbidden_due_to_state_trashing_use_av_lfg_init
  124. #undef random
  125. #define random random_is_forbidden_due_to_state_trashing_use_av_lfg_get
  126. #undef sprintf
  127. #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
  128. #undef strcat
  129. #define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
  130. #undef exit
  131. #define exit exit_is_forbidden
  132. #ifndef LIBAVFORMAT_BUILD
  133. #undef printf
  134. #define printf please_use_av_log_instead_of_printf
  135. #undef fprintf
  136. #define fprintf please_use_av_log_instead_of_fprintf
  137. #undef puts
  138. #define puts please_use_av_log_instead_of_puts
  139. #undef perror
  140. #define perror please_use_av_log_instead_of_perror
  141. #endif
  142. #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
  143. {\
  144. p = av_malloc(size);\
  145. if (p == NULL && (size) != 0) {\
  146. av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
  147. goto label;\
  148. }\
  149. }
  150. #define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
  151. {\
  152. p = av_mallocz(size);\
  153. if (p == NULL && (size) != 0) {\
  154. av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
  155. goto label;\
  156. }\
  157. }
  158. #include "libm.h"
  159. /**
  160. * Returns NULL if CONFIG_SMALL is true, otherwise the argument
  161. * without modification. Used to disable the definition of strings
  162. * (for example AVCodec long_names).
  163. */
  164. #if CONFIG_SMALL
  165. # define NULL_IF_CONFIG_SMALL(x) NULL
  166. #else
  167. # define NULL_IF_CONFIG_SMALL(x) x
  168. #endif
  169. #endif /* AVUTIL_INTERNAL_H */