Libav 0.7.1
|
00001 /* 00002 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> 00003 * 00004 * This file is part of Libav. 00005 * 00006 * Libav is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * Libav is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with Libav; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00026 #ifndef AVUTIL_INTERNAL_H 00027 #define AVUTIL_INTERNAL_H 00028 00029 #if !defined(DEBUG) && !defined(NDEBUG) 00030 # define NDEBUG 00031 #endif 00032 00033 #include <limits.h> 00034 #include <stdint.h> 00035 #include <stddef.h> 00036 #include <assert.h> 00037 #include "config.h" 00038 #include "attributes.h" 00039 #include "timer.h" 00040 #include "dict.h" 00041 00042 struct AVDictionary { 00043 int count; 00044 AVDictionaryEntry *elems; 00045 }; 00046 00047 #ifndef attribute_align_arg 00048 #if ARCH_X86_32 && AV_GCC_VERSION_AT_LEAST(4,2) 00049 # define attribute_align_arg __attribute__((force_align_arg_pointer)) 00050 #else 00051 # define attribute_align_arg 00052 #endif 00053 #endif 00054 00055 #ifndef INT16_MIN 00056 #define INT16_MIN (-0x7fff - 1) 00057 #endif 00058 00059 #ifndef INT16_MAX 00060 #define INT16_MAX 0x7fff 00061 #endif 00062 00063 #ifndef INT32_MIN 00064 #define INT32_MIN (-0x7fffffff - 1) 00065 #endif 00066 00067 #ifndef INT32_MAX 00068 #define INT32_MAX 0x7fffffff 00069 #endif 00070 00071 #ifndef UINT32_MAX 00072 #define UINT32_MAX 0xffffffff 00073 #endif 00074 00075 #ifndef INT64_MIN 00076 #define INT64_MIN (-0x7fffffffffffffffLL - 1) 00077 #endif 00078 00079 #ifndef INT64_MAX 00080 #define INT64_MAX INT64_C(9223372036854775807) 00081 #endif 00082 00083 #ifndef UINT64_MAX 00084 #define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF) 00085 #endif 00086 00087 #ifndef INT_BIT 00088 # define INT_BIT (CHAR_BIT * sizeof(int)) 00089 #endif 00090 00091 #ifndef offsetof 00092 # define offsetof(T, F) ((unsigned int)((char *)&((T *)0)->F)) 00093 #endif 00094 00095 /* Use to export labels from asm. */ 00096 #define LABEL_MANGLE(a) EXTERN_PREFIX #a 00097 00098 // Use rip-relative addressing if compiling PIC code on x86-64. 00099 #if ARCH_X86_64 && defined(PIC) 00100 # define LOCAL_MANGLE(a) #a "(%%rip)" 00101 #else 00102 # define LOCAL_MANGLE(a) #a 00103 #endif 00104 00105 #define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a) 00106 00107 /* debug stuff */ 00108 00109 #define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0) 00110 00111 /* math */ 00112 00113 #if ARCH_X86 00114 #define MASK_ABS(mask, level)\ 00115 __asm__ volatile(\ 00116 "cltd \n\t"\ 00117 "xorl %1, %0 \n\t"\ 00118 "subl %1, %0 \n\t"\ 00119 : "+a" (level), "=&d" (mask)\ 00120 ); 00121 #else 00122 #define MASK_ABS(mask, level)\ 00123 mask = level >> 31;\ 00124 level = (level ^ mask) - mask; 00125 #endif 00126 00127 /* avoid usage of dangerous/inappropriate system functions */ 00128 #undef malloc 00129 #define malloc please_use_av_malloc 00130 #undef free 00131 #define free please_use_av_free 00132 #undef realloc 00133 #define realloc please_use_av_realloc 00134 #undef time 00135 #define time time_is_forbidden_due_to_security_issues 00136 #undef rand 00137 #define rand rand_is_forbidden_due_to_state_trashing_use_av_lfg_get 00138 #undef srand 00139 #define srand srand_is_forbidden_due_to_state_trashing_use_av_lfg_init 00140 #undef random 00141 #define random random_is_forbidden_due_to_state_trashing_use_av_lfg_get 00142 #undef sprintf 00143 #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf 00144 #undef strcat 00145 #define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat 00146 #undef strncpy 00147 #define strncpy strncpy_is_forbidden_due_to_security_issues_use_av_strlcpy 00148 #undef exit 00149 #define exit exit_is_forbidden 00150 #undef printf 00151 #define printf please_use_av_log_instead_of_printf 00152 #undef fprintf 00153 #define fprintf please_use_av_log_instead_of_fprintf 00154 #undef puts 00155 #define puts please_use_av_log_instead_of_puts 00156 #undef perror 00157 #define perror please_use_av_log_instead_of_perror 00158 00159 #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\ 00160 {\ 00161 p = av_malloc(size);\ 00162 if (p == NULL && (size) != 0) {\ 00163 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\ 00164 goto label;\ 00165 }\ 00166 } 00167 00168 #define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\ 00169 {\ 00170 p = av_mallocz(size);\ 00171 if (p == NULL && (size) != 0) {\ 00172 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\ 00173 goto label;\ 00174 }\ 00175 } 00176 00177 #include "libm.h" 00178 00184 #if CONFIG_SMALL 00185 # define NULL_IF_CONFIG_SMALL(x) NULL 00186 #else 00187 # define NULL_IF_CONFIG_SMALL(x) x 00188 #endif 00189 00190 00208 #if HAVE_SYMVER_ASM_LABEL 00209 # define FF_SYMVER(type, name, args, ver) \ 00210 type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver); \ 00211 type ff_##name args 00212 #elif HAVE_SYMVER_GNU_ASM 00213 # define FF_SYMVER(type, name, args, ver) \ 00214 __asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver); \ 00215 type ff_##name args; \ 00216 type ff_##name args 00217 #endif 00218 00224 #if HAVE_THREADS 00225 # define ONLY_IF_THREADS_ENABLED(x) x 00226 #else 00227 # define ONLY_IF_THREADS_ENABLED(x) NULL 00228 #endif 00229 00230 #if HAVE_MMX 00231 00236 static av_always_inline void emms_c(void) 00237 { 00238 __asm__ volatile ("emms" ::: "memory"); 00239 } 00240 #else /* HAVE_MMX */ 00241 #define emms_c() 00242 #endif /* HAVE_MMX */ 00243 00244 #endif /* AVUTIL_INTERNAL_H */