Revision 05020c89

View differences:

libavutil/common.h
1 1
/**
2 2
 * @file common.h
3
 * common internal api header.
3
 * common internal and external api header.
4 4
 */
5 5

  
6 6
#ifndef COMMON_H
......
10 10
#define M_PI    3.14159265358979323846
11 11
#endif
12 12

  
13
#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
14
#    define PIC
15
#endif
16

  
17 13
#ifdef HAVE_AV_CONFIG_H
18 14
/* only include the following when compiling package */
19 15
#    include "config.h"
......
29 25
#        include "berrno.h"
30 26
#    endif
31 27
#    include <math.h>
32

  
33
#    ifndef ENODATA
34
#        define ENODATA  61
35
#    endif
36

  
37
#include <stddef.h>
38
#ifndef offsetof
39
# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
40
#endif
41

  
42
#define AVOPTION_CODEC_BOOL(name, help, field) \
43
    { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_BOOL }
44
#define AVOPTION_CODEC_DOUBLE(name, help, field, minv, maxv, defval) \
45
    { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_DOUBLE, minv, maxv, defval }
46
#define AVOPTION_CODEC_FLAG(name, help, field, flag, defval) \
47
    { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_FLAG, flag, 0, defval }
48
#define AVOPTION_CODEC_INT(name, help, field, minv, maxv, defval) \
49
    { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_INT, minv, maxv, defval }
50
#define AVOPTION_CODEC_STRING(name, help, field, str, val) \
51
    { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str }
52
#define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \
53
    { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_RCOVERRIDE, .defval = 0, .defstr = NULL }
54
#define AVOPTION_SUB(ptr) { .name = NULL, .help = (const char*)ptr }
55
#define AVOPTION_END() AVOPTION_SUB(NULL)
56

  
57 28
#endif /* HAVE_AV_CONFIG_H */
58 29

  
59 30
/* Suppress restrict if it was not defined in config.h.  */
......
177 148
#define uint64_t_C(c)    (c ## ULL)
178 149
#endif
179 150

  
180
#ifdef HAVE_AV_CONFIG_H
181

  
182
#ifdef __MINGW32__
183
#    ifdef _DEBUG
184
#        define DEBUG
185
#    endif
186

  
187
#    define snprintf _snprintf
188
#    define vsnprintf _vsnprintf
189

  
190
#    ifdef CONFIG_WINCE
191
#        define perror(a)
192
#    endif
193

  
194
/* __MINGW32__ end */
195
#elif defined (CONFIG_OS2)
196
/* OS/2 EMX */
197

  
198
#include <float.h>
199

  
200
#endif /* !__MINGW32__ && CONFIG_OS2 */
201

  
202
#    ifdef USE_FASTMEMCPY
203
#        include "fastmemcpy.h"
204
#    endif
205

  
206 151
#if defined(__MINGW32__) && !defined(BUILD_AVUTIL) && defined(BUILD_SHARED_AV)
207 152
#  define FF_IMPORT_ATTR __declspec(dllimport)
208 153
#else
......
212 157

  
213 158
#    include "bswap.h"
214 159

  
215
// Use rip-relative addressing if compiling PIC code on x86-64.
216
#    if defined(__MINGW32__) || defined(__CYGWIN__) || \
217
        defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
218
#        if defined(ARCH_X86_64) && defined(PIC)
219
#            define MANGLE(a) "_" #a"(%%rip)"
220
#        else
221
#            define MANGLE(a) "_" #a
222
#        endif
223
#    else
224
#        if defined(ARCH_X86_64) && defined(PIC)
225
#            define MANGLE(a) #a"(%%rip)"
226
#        elif defined(CONFIG_DARWIN)
227
#            define MANGLE(a) "_" #a
228
#        else
229
#            define MANGLE(a) #a
230
#        endif
231
#    endif
232

  
233
/* debug stuff */
234

  
235
#    if !defined(DEBUG) && !defined(NDEBUG)
236
#        define NDEBUG
237
#    endif
238
#    include <assert.h>
239

  
240
/* dprintf macros */
241
#    ifdef DEBUG
242
#        define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__)
243
#    else
244
#        define dprintf(fmt,...)
245
#    endif
246

  
247
#    ifdef CONFIG_WINCE
248
#            define abort()
249
#    endif
250

  
251
#    define av_abort()      do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
160
#ifdef HAVE_AV_CONFIG_H
161
/* only include the following when compiling package */
162
#    include "internal.h"
163
#endif
252 164

  
253 165
//rounded divison & shift
254 166
#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
......
259 171
#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
260 172
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
261 173

  
262
extern const uint32_t inverse[256];
263

  
264
#if defined(ARCH_X86) || defined(ARCH_X86_64)
265
#    define FASTDIV(a,b) \
266
    ({\
267
        int ret,dmy;\
268
        asm volatile(\
269
            "mull %3"\
270
            :"=d"(ret),"=a"(dmy)\
271
            :"1"(a),"g"(inverse[b])\
272
            );\
273
        ret;\
274
    })
275
#elif defined(CONFIG_FASTDIV)
276
#    define FASTDIV(a,b)   ((uint32_t)((((uint64_t)a)*inverse[b])>>32))
277
#else
278
#    define FASTDIV(a,b)   ((a)/(b))
279
#endif
280

  
281 174
/* misc math functions */
282 175
extern FF_IMPORT_ATTR const uint8_t ff_log2_tab[256];
283 176

  
......
366 259
}
367 260

  
368 261
/* math */
369
extern FF_IMPORT_ATTR const uint8_t ff_sqrt_tab[128];
370

  
371 262
int64_t ff_gcd(int64_t a, int64_t b);
372 263

  
373
static inline int ff_sqrt(int a)
374
{
375
    int ret=0;
376
    int s;
377
    int ret_sq=0;
378

  
379
    if(a<128) return ff_sqrt_tab[a];
380

  
381
    for(s=15; s>=0; s--){
382
        int b= ret_sq + (1<<(s*2)) + (ret<<s)*2;
383
        if(b<=a){
384
            ret_sq=b;
385
            ret+= 1<<s;
386
        }
387
    }
388
    return ret;
389
}
390

  
391 264
/**
392 265
 * converts fourcc string to int
393 266
 */
394 267
static inline int ff_get_fourcc(const char *s){
268
#ifdef HAVE_AV_CONFIG_H
395 269
    assert( strlen(s)==4 );
270
#endif
396 271

  
397 272
    return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24);
398 273
}
......
401 276
#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
402 277

  
403 278

  
404
#if defined(ARCH_X86) || defined(ARCH_X86_64)
405
#define MASK_ABS(mask, level)\
406
            asm volatile(\
407
                "cdq                    \n\t"\
408
                "xorl %1, %0            \n\t"\
409
                "subl %1, %0            \n\t"\
410
                : "+a" (level), "=&d" (mask)\
411
            );
412
#else
413
#define MASK_ABS(mask, level)\
414
            mask= level>>31;\
415
            level= (level^mask)-mask;
416
#endif
417

  
418 279
#define GET_UTF8(val, GET_BYTE, ERROR)\
419 280
    val= GET_BYTE;\
420 281
    {\
......
430 291
        }\
431 292
    }
432 293

  
433
#if __CPU__ >= 686 && !defined(RUNTIME_CPUDETECT)
434
#define COPY3_IF_LT(x,y,a,b,c,d)\
435
asm volatile (\
436
    "cmpl %0, %3        \n\t"\
437
    "cmovl %3, %0       \n\t"\
438
    "cmovl %4, %1       \n\t"\
439
    "cmovl %5, %2       \n\t"\
440
    : "+r" (x), "+r" (a), "+r" (c)\
441
    : "r" (y), "r" (b), "r" (d)\
442
);
443
#else
444
#define COPY3_IF_LT(x,y,a,b,c,d)\
445
if((y)<(x)){\
446
     (x)=(y);\
447
     (a)=(b);\
448
     (c)=(d);\
449
}
450
#endif
451

  
452 294
#if defined(ARCH_X86) || defined(ARCH_X86_64) || defined(ARCH_POWERPC)
453 295
#if defined(ARCH_X86_64)
454 296
static inline uint64_t read_time(void)
......
513 355
#define STOP_TIMER(id) {}
514 356
#endif
515 357

  
516
/* avoid usage of various functions */
517
#define malloc please_use_av_malloc
518
#define free please_use_av_free
519
#define realloc please_use_av_realloc
520
#define time time_is_forbidden_due_to_security_issues
521
#define rand rand_is_forbidden_due_to_state_trashing
522
#define srand srand_is_forbidden_due_to_state_trashing
523
#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
524
#define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat
525
#if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H))
526
#define printf please_use_av_log
527
#define fprintf please_use_av_log
528
#endif
529

  
530
#define CHECKED_ALLOCZ(p, size)\
531
{\
532
    p= av_mallocz(size);\
533
    if(p==NULL && (size)!=0){\
534
        perror("malloc");\
535
        goto fail;\
536
    }\
537
}
538

  
539
#ifndef HAVE_LRINTF
540
/* XXX: add ISOC specific test to avoid specific BSD testing. */
541
/* better than nothing implementation. */
542
/* btw, rintf() is existing on fbsd too -- alex */
543
static always_inline long int lrintf(float x)
544
{
545
#ifdef __MINGW32__
546
#  ifdef ARCH_X86
547
    int32_t i;
548
    asm volatile(
549
        "fistpl %0\n\t"
550
        : "=m" (i) : "t" (x) : "st"
551
    );
552
    return i;
553
#  else
554
    /* XXX: incorrect, but make it compile */
555
    return (int)(x + (x < 0 ? -0.5 : 0.5));
556
#  endif /* ARCH_X86 */
557
#else
558
    return (int)(rint(x));
559
#endif /* __MINGW32__ */
560
}
561
#endif /* HAVE_LRINTF */
562

  
563
#endif /* HAVE_AV_CONFIG_H */
564

  
565 358
#endif /* COMMON_H */
libavutil/internal.h
1
/**
2
 * @file internal.h
3
 * common internal api header.
4
 */
5

  
6
#ifndef INTERNAL_H
7
#define INTERNAL_H
8

  
9
#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
10
#    define PIC
11
#endif
12

  
13
#    ifndef ENODATA
14
#        define ENODATA  61
15
#    endif
16

  
17
#include <stddef.h>
18
#ifndef offsetof
19
# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
20
#endif
21

  
22
#define AVOPTION_CODEC_BOOL(name, help, field) \
23
    { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_BOOL }
24
#define AVOPTION_CODEC_DOUBLE(name, help, field, minv, maxv, defval) \
25
    { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_DOUBLE, minv, maxv, defval }
26
#define AVOPTION_CODEC_FLAG(name, help, field, flag, defval) \
27
    { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_FLAG, flag, 0, defval }
28
#define AVOPTION_CODEC_INT(name, help, field, minv, maxv, defval) \
29
    { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_INT, minv, maxv, defval }
30
#define AVOPTION_CODEC_STRING(name, help, field, str, val) \
31
    { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str }
32
#define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \
33
    { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_RCOVERRIDE, .defval = 0, .defstr = NULL }
34
#define AVOPTION_SUB(ptr) { .name = NULL, .help = (const char*)ptr }
35
#define AVOPTION_END() AVOPTION_SUB(NULL)
36

  
37
#ifdef __MINGW32__
38
#    ifdef _DEBUG
39
#        define DEBUG
40
#    endif
41

  
42
#    define snprintf _snprintf
43
#    define vsnprintf _vsnprintf
44

  
45
#    ifdef CONFIG_WINCE
46
#        define perror(a)
47
#    endif
48

  
49
/* __MINGW32__ end */
50
#elif defined (CONFIG_OS2)
51
/* OS/2 EMX */
52

  
53
#include <float.h>
54

  
55
#endif /* !__MINGW32__ && CONFIG_OS2 */
56

  
57
#    ifdef USE_FASTMEMCPY
58
#        include "fastmemcpy.h"
59
#    endif
60

  
61
// Use rip-relative addressing if compiling PIC code on x86-64.
62
#    if defined(__MINGW32__) || defined(__CYGWIN__) || \
63
        defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
64
#        if defined(ARCH_X86_64) && defined(PIC)
65
#            define MANGLE(a) "_" #a"(%%rip)"
66
#        else
67
#            define MANGLE(a) "_" #a
68
#        endif
69
#    else
70
#        if defined(ARCH_X86_64) && defined(PIC)
71
#            define MANGLE(a) #a"(%%rip)"
72
#        elif defined(CONFIG_DARWIN)
73
#            define MANGLE(a) "_" #a
74
#        else
75
#            define MANGLE(a) #a
76
#        endif
77
#    endif
78

  
79
/* debug stuff */
80

  
81
#    if !defined(DEBUG) && !defined(NDEBUG)
82
#        define NDEBUG
83
#    endif
84
#    include <assert.h>
85

  
86
/* dprintf macros */
87
#    ifdef DEBUG
88
#        define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__)
89
#    else
90
#        define dprintf(fmt,...)
91
#    endif
92

  
93
#    ifdef CONFIG_WINCE
94
#            define abort()
95
#    endif
96

  
97
#    define av_abort()      do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
98

  
99
extern const uint32_t inverse[256];
100

  
101
#if defined(ARCH_X86) || defined(ARCH_X86_64)
102
#    define FASTDIV(a,b) \
103
    ({\
104
        int ret,dmy;\
105
        asm volatile(\
106
            "mull %3"\
107
            :"=d"(ret),"=a"(dmy)\
108
            :"1"(a),"g"(inverse[b])\
109
            );\
110
        ret;\
111
    })
112
#elif defined(CONFIG_FASTDIV)
113
#    define FASTDIV(a,b)   ((uint32_t)((((uint64_t)a)*inverse[b])>>32))
114
#else
115
#    define FASTDIV(a,b)   ((a)/(b))
116
#endif
117

  
118
/* math */
119
extern FF_IMPORT_ATTR const uint8_t ff_sqrt_tab[128];
120

  
121
static inline int ff_sqrt(int a)
122
{
123
    int ret=0;
124
    int s;
125
    int ret_sq=0;
126

  
127
    if(a<128) return ff_sqrt_tab[a];
128

  
129
    for(s=15; s>=0; s--){
130
        int b= ret_sq + (1<<(s*2)) + (ret<<s)*2;
131
        if(b<=a){
132
            ret_sq=b;
133
            ret+= 1<<s;
134
        }
135
    }
136
    return ret;
137
}
138

  
139
#if defined(ARCH_X86) || defined(ARCH_X86_64)
140
#define MASK_ABS(mask, level)\
141
            asm volatile(\
142
                "cdq                    \n\t"\
143
                "xorl %1, %0            \n\t"\
144
                "subl %1, %0            \n\t"\
145
                : "+a" (level), "=&d" (mask)\
146
            );
147
#else
148
#define MASK_ABS(mask, level)\
149
            mask= level>>31;\
150
            level= (level^mask)-mask;
151
#endif
152

  
153
#if __CPU__ >= 686 && !defined(RUNTIME_CPUDETECT)
154
#define COPY3_IF_LT(x,y,a,b,c,d)\
155
asm volatile (\
156
    "cmpl %0, %3        \n\t"\
157
    "cmovl %3, %0       \n\t"\
158
    "cmovl %4, %1       \n\t"\
159
    "cmovl %5, %2       \n\t"\
160
    : "+r" (x), "+r" (a), "+r" (c)\
161
    : "r" (y), "r" (b), "r" (d)\
162
);
163
#else
164
#define COPY3_IF_LT(x,y,a,b,c,d)\
165
if((y)<(x)){\
166
     (x)=(y);\
167
     (a)=(b);\
168
     (c)=(d);\
169
}
170
#endif
171

  
172
/* avoid usage of various functions */
173
#define malloc please_use_av_malloc
174
#define free please_use_av_free
175
#define realloc please_use_av_realloc
176
#define time time_is_forbidden_due_to_security_issues
177
#define rand rand_is_forbidden_due_to_state_trashing
178
#define srand srand_is_forbidden_due_to_state_trashing
179
#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
180
#define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat
181
#if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H))
182
#define printf please_use_av_log
183
#define fprintf please_use_av_log
184
#endif
185

  
186
#define CHECKED_ALLOCZ(p, size)\
187
{\
188
    p= av_mallocz(size);\
189
    if(p==NULL && (size)!=0){\
190
        perror("malloc");\
191
        goto fail;\
192
    }\
193
}
194

  
195
#ifndef HAVE_LRINTF
196
/* XXX: add ISOC specific test to avoid specific BSD testing. */
197
/* better than nothing implementation. */
198
/* btw, rintf() is existing on fbsd too -- alex */
199
static always_inline long int lrintf(float x)
200
{
201
#ifdef __MINGW32__
202
#  ifdef ARCH_X86
203
    int32_t i;
204
    asm volatile(
205
        "fistpl %0\n\t"
206
        : "=m" (i) : "t" (x) : "st"
207
    );
208
    return i;
209
#  else
210
    /* XXX: incorrect, but make it compile */
211
    return (int)(x + (x < 0 ? -0.5 : 0.5));
212
#  endif /* ARCH_X86 */
213
#else
214
    return (int)(rint(x));
215
#endif /* __MINGW32__ */
216
}
217
#endif /* HAVE_LRINTF */
218

  
219
#endif /* INTERNAL_H */

Also available in: Unified diff