Statistics
| Branch: | Revision:

ffmpeg / libavutil / internal.h @ f940f7c9

History | View | Annotate | Download (5.55 KB)

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
/**
22
 * @file internal.h
23
 * common internal api header.
24
 */
25

    
26
#ifndef INTERNAL_H
27
#define INTERNAL_H
28

    
29
#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
30
#    define PIC
31
#endif
32

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

    
37
#include "bswap.h"
38

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

    
44
#ifdef __MINGW32__
45
#    ifdef _DEBUG
46
#        define DEBUG
47
#    endif
48

    
49
#    define snprintf _snprintf
50
#    define vsnprintf _vsnprintf
51

    
52
#    ifdef CONFIG_WINCE
53
#        define perror(a)
54
#        define abort()
55
#    endif
56

    
57
/* __MINGW32__ end */
58
#elif defined (CONFIG_OS2)
59
/* OS/2 EMX */
60

    
61
#    include <float.h>
62

    
63
#endif /* !__MINGW32__ && CONFIG_OS2 */
64

    
65
#ifdef USE_FASTMEMCPY
66
#    include "libvo/fastmemcpy.h"
67
#endif
68

    
69
// Use rip-relative addressing if compiling PIC code on x86-64.
70
#if defined(__MINGW32__) || defined(__CYGWIN__) || \
71
    defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
72
#    if defined(ARCH_X86_64) && defined(PIC)
73
#        define MANGLE(a) "_" #a"(%%rip)"
74
#    else
75
#        define MANGLE(a) "_" #a
76
#    endif
77
#else
78
#    if defined(ARCH_X86_64) && defined(PIC)
79
#        define MANGLE(a) #a"(%%rip)"
80
#    elif defined(CONFIG_DARWIN)
81
#        define MANGLE(a) "_" #a
82
#    else
83
#        define MANGLE(a) #a
84
#    endif
85
#endif
86

    
87
/* debug stuff */
88

    
89
#if !defined(DEBUG) && !defined(NDEBUG)
90
#    define NDEBUG
91
#endif
92
#include <assert.h>
93

    
94
/* dprintf macros */
95
#ifdef DEBUG
96
#    define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__)
97
#else
98
#    define dprintf(fmt,...)
99
#endif
100

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

    
103
extern const uint32_t ff_inverse[256];
104

    
105
#if defined(ARCH_X86)
106
#    define FASTDIV(a,b) \
107
    ({\
108
        int ret,dmy;\
109
        asm volatile(\
110
            "mull %3"\
111
            :"=d"(ret),"=a"(dmy)\
112
            :"1"(a),"g"(ff_inverse[b])\
113
            );\
114
        ret;\
115
    })
116
#elif defined(ARCH_ARMV4L)
117
#    define FASTDIV(a,b) \
118
    ({\
119
        int ret,dmy;\
120
        asm volatile(\
121
            "umull %1, %0, %2, %3"\
122
            :"=&r"(ret),"=&r"(dmy)\
123
            :"r"(a),"r"(ff_inverse[b])\
124
            );\
125
        ret;\
126
    })
127
#elif defined(CONFIG_FASTDIV)
128
#    define FASTDIV(a,b)   ((uint32_t)((((uint64_t)a)*ff_inverse[b])>>32))
129
#else
130
#    define FASTDIV(a,b)   ((a)/(b))
131
#endif
132

    
133
/* math */
134
extern FF_IMPORT_ATTR const uint8_t ff_sqrt_tab[128];
135

    
136
static inline int ff_sqrt(int a)
137
{
138
    int ret=0;
139
    int s;
140
    int ret_sq=0;
141

    
142
    if(a<128) return ff_sqrt_tab[a];
143

    
144
    for(s=15; s>=0; s--){
145
        int b= ret_sq + (1<<(s*2)) + (ret<<s)*2;
146
        if(b<=a){
147
            ret_sq=b;
148
            ret+= 1<<s;
149
        }
150
    }
151
    return ret;
152
}
153

    
154
#if defined(ARCH_X86)
155
#define MASK_ABS(mask, level)\
156
            asm volatile(\
157
                "cdq                    \n\t"\
158
                "xorl %1, %0            \n\t"\
159
                "subl %1, %0            \n\t"\
160
                : "+a" (level), "=&d" (mask)\
161
            );
162
#else
163
#define MASK_ABS(mask, level)\
164
            mask= level>>31;\
165
            level= (level^mask)-mask;
166
#endif
167

    
168
#ifdef HAVE_CMOV
169
#define COPY3_IF_LT(x,y,a,b,c,d)\
170
asm volatile (\
171
    "cmpl %0, %3        \n\t"\
172
    "cmovl %3, %0       \n\t"\
173
    "cmovl %4, %1       \n\t"\
174
    "cmovl %5, %2       \n\t"\
175
    : "+r" (x), "+r" (a), "+r" (c)\
176
    : "r" (y), "r" (b), "r" (d)\
177
);
178
#else
179
#define COPY3_IF_LT(x,y,a,b,c,d)\
180
if((y)<(x)){\
181
     (x)=(y);\
182
     (a)=(b);\
183
     (c)=(d);\
184
}
185
#endif
186

    
187
/* avoid usage of various functions */
188
#define malloc please_use_av_malloc
189
#define free please_use_av_free
190
#define realloc please_use_av_realloc
191
#define time time_is_forbidden_due_to_security_issues
192
#define rand rand_is_forbidden_due_to_state_trashing
193
#define srand srand_is_forbidden_due_to_state_trashing
194
#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
195
#define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat
196
#if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H))
197
#define printf please_use_av_log
198
#define fprintf please_use_av_log
199
#endif
200

    
201
#define CHECKED_ALLOCZ(p, size)\
202
{\
203
    p= av_mallocz(size);\
204
    if(p==NULL && (size)!=0){\
205
        perror("malloc");\
206
        goto fail;\
207
    }\
208
}
209

    
210
#ifndef HAVE_LRINTF
211
/* XXX: add ISOC specific test to avoid specific BSD testing. */
212
/* better than nothing implementation. */
213
/* btw, rintf() is existing on fbsd too -- alex */
214
static always_inline long int lrintf(float x)
215
{
216
#ifdef __MINGW32__
217
#  ifdef ARCH_X86_32
218
    int32_t i;
219
    asm volatile(
220
        "fistpl %0\n\t"
221
        : "=m" (i) : "t" (x) : "st"
222
    );
223
    return i;
224
#  else
225
    /* XXX: incorrect, but make it compile */
226
    return (int)(x + (x < 0 ? -0.5 : 0.5));
227
#  endif /* ARCH_X86_32 */
228
#else
229
    return (int)(rint(x));
230
#endif /* __MINGW32__ */
231
}
232
#endif /* HAVE_LRINTF */
233

    
234
#endif /* INTERNAL_H */