~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to ffmpeg/libavutil/common.h

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc, Andrew Starr-Bochicchio, Lionel Le Folgoc
  • Date: 2008-12-26 00:10:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081226001006-2040ls9680bd1blt
Tags: 1.1.7-0.2ubuntu1
[ Andrew Starr-Bochicchio ]
* Merge from debian-multimedia (LP: #298547), Ubuntu Changes:
 - For ffmpeg-related build-deps, fix versionized dependencies
   as the ubuntu versioning is different than debian-multimedia's.

[ Lionel Le Folgoc ]
* LP: #311412 is fixed since the 1.1.7~rc1-0.1 revision.
* debian/patches/03_ffmpeg.diff: updated to fix FTBFS due to libswscale API
  change (cherry-pick from Gentoo #234383).

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
/**
22
22
 * @file common.h
23
 
 * common internal and external api header.
 
23
 * common internal and external API header
24
24
 */
25
25
 
26
 
#ifndef COMMON_H
27
 
#define COMMON_H
 
26
#ifndef FFMPEG_COMMON_H
 
27
#define FFMPEG_COMMON_H
28
28
 
29
29
#include <inttypes.h>
30
30
 
44
44
#ifndef av_always_inline
45
45
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
46
46
#    define av_always_inline __attribute__((always_inline)) inline
 
47
#else
 
48
#    define av_always_inline inline
 
49
#endif
 
50
#endif
 
51
 
 
52
#ifndef av_noinline
 
53
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
47
54
#    define av_noinline __attribute__((noinline))
48
55
#else
49
 
#    define av_always_inline inline
50
56
#    define av_noinline
51
57
#endif
52
58
#endif
53
59
 
 
60
#ifndef av_pure
 
61
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
 
62
#    define av_pure __attribute__((pure))
 
63
#else
 
64
#    define av_pure
 
65
#endif
 
66
#endif
 
67
 
 
68
#ifndef av_const
 
69
#if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ > 5)
 
70
#    define av_const __attribute__((const))
 
71
#else
 
72
#    define av_const
 
73
#endif
 
74
#endif
 
75
 
 
76
#ifndef av_cold
 
77
#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 2)
 
78
#    define av_cold __attribute__((cold))
 
79
#else
 
80
#    define av_cold
 
81
#endif
 
82
#endif
 
83
 
54
84
#ifdef HAVE_AV_CONFIG_H
55
85
#    include "internal.h"
56
86
#endif /* HAVE_AV_CONFIG_H */
63
93
#endif
64
94
#endif
65
95
 
 
96
#ifndef av_unused
 
97
#if defined(__GNUC__)
 
98
#    define av_unused __attribute__((unused))
 
99
#else
 
100
#    define av_unused
 
101
#endif
 
102
#endif
 
103
 
 
104
#include "mem.h"
 
105
 
66
106
//rounded divison & shift
67
107
#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
68
108
/* assume b>0 */
71
111
#define FFSIGN(a) ((a) > 0 ? 1 : -1)
72
112
 
73
113
#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
 
114
#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
74
115
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
 
116
#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
75
117
 
76
118
#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
77
119
 
78
120
/* misc math functions */
79
121
extern const uint8_t ff_log2_tab[256];
80
122
 
81
 
static inline int av_log2(unsigned int v)
 
123
static inline av_const int av_log2(unsigned int v)
82
124
{
83
 
    int n;
84
 
 
85
 
    n = 0;
 
125
    int n = 0;
86
126
    if (v & 0xffff0000) {
87
127
        v >>= 16;
88
128
        n += 16;
96
136
    return n;
97
137
}
98
138
 
99
 
static inline int av_log2_16bit(unsigned int v)
 
139
static inline av_const int av_log2_16bit(unsigned int v)
100
140
{
101
 
    int n;
102
 
 
103
 
    n = 0;
 
141
    int n = 0;
104
142
    if (v & 0xff00) {
105
143
        v >>= 8;
106
144
        n += 8;
111
149
}
112
150
 
113
151
/* median of 3 */
114
 
static inline int mid_pred(int a, int b, int c)
 
152
static inline av_const int mid_pred(int a, int b, int c)
115
153
{
116
154
#ifdef HAVE_CMOV
117
155
    int i=b;
158
196
 * @param amax maximum value of the clip range
159
197
 * @return clipped value
160
198
 */
161
 
static inline int av_clip(int a, int amin, int amax)
 
199
static inline av_const int av_clip(int a, int amin, int amax)
162
200
{
163
 
    if (a < amin)      return amin;
 
201
    if      (a < amin) return amin;
164
202
    else if (a > amax) return amax;
165
203
    else               return a;
166
204
}
170
208
 * @param a value to clip
171
209
 * @return clipped value
172
210
 */
173
 
static inline uint8_t av_clip_uint8(int a)
 
211
static inline av_const uint8_t av_clip_uint8(int a)
174
212
{
175
213
    if (a&(~255)) return (-a)>>31;
176
214
    else          return a;
177
215
}
178
216
 
 
217
/**
 
218
 * clip a signed integer value into the -32768,32767 range
 
219
 * @param a value to clip
 
220
 * @return clipped value
 
221
 */
 
222
static inline av_const int16_t av_clip_int16(int a)
 
223
{
 
224
    if ((a+32768) & ~65535) return (a>>31) ^ 32767;
 
225
    else                    return a;
 
226
}
 
227
 
179
228
/* math */
180
 
int64_t ff_gcd(int64_t a, int64_t b);
 
229
int64_t av_const ff_gcd(int64_t a, int64_t b);
181
230
 
182
231
/**
183
232
 * converts fourcc string to int
184
233
 */
185
 
static inline int ff_get_fourcc(const char *s){
 
234
static inline av_pure int ff_get_fourcc(const char *s){
186
235
#ifdef HAVE_AV_CONFIG_H
187
236
    assert( strlen(s)==4 );
188
237
#endif
195
244
 
196
245
/*!
197
246
 * \def GET_UTF8(val, GET_BYTE, ERROR)
198
 
 * converts a utf-8 character (up to 4 bytes long) to its 32-bit ucs-4 encoded form
 
247
 * converts a UTF-8 character (up to 4 bytes long) to its 32-bit UCS-4 encoded form
199
248
 * \param val is the output and should be of type uint32_t. It holds the converted
200
 
 * ucs-4 character and should be a left value.
201
 
 * \param GET_BYTE gets utf-8 encoded bytes from any proper source. It can be
 
249
 * UCS-4 character and should be a left value.
 
250
 * \param GET_BYTE gets UTF-8 encoded bytes from any proper source. It can be
202
251
 * a function or a statement whose return value or evaluated value is of type
203
 
 * uint8_t. It will be executed up to 4 times for values in the valid utf-8 range,
 
252
 * uint8_t. It will be executed up to 4 times for values in the valid UTF-8 range,
204
253
 * and up to 7 times in the general case.
205
 
 * \param ERROR action that should be taken when an invalid utf-8 byte is returned
 
254
 * \param ERROR action that should be taken when an invalid UTF-8 byte is returned
206
255
 * from GET_BYTE. It should be a statement that jumps out of the macro,
207
256
 * like exit(), goto, return, break, or continue.
208
257
 */
223
272
 
224
273
/*!
225
274
 * \def PUT_UTF8(val, tmp, PUT_BYTE)
226
 
 * converts a 32-bit unicode character to its utf-8 encoded form (up to 4 bytes long).
 
275
 * converts a 32-bit unicode character to its UTF-8 encoded form (up to 4 bytes long).
227
276
 * \param val is an input only argument and should be of type uint32_t. It holds
228
 
 * a ucs4 encoded unicode character that is to be converted to utf-8. If
 
277
 * a ucs4 encoded unicode character that is to be converted to UTF-8. If
229
278
 * val is given as a function it's executed only once.
230
279
 * \param tmp is a temporary variable and should be of type uint8_t. It
231
280
 * represents an intermediate value during conversion that is to be
232
281
 * outputted by PUT_BYTE.
233
 
 * \param PUT_BYTE writes the converted utf-8 bytes to any proper destination.
 
282
 * \param PUT_BYTE writes the converted UTF-8 bytes to any proper destination.
234
283
 * It could be a function or a statement, and uses tmp as the input byte.
235
284
 * For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be
236
 
 * executed up to 4 times for values in the valid utf-8 range and up to
 
285
 * executed up to 4 times for values in the valid UTF-8 range and up to
237
286
 * 7 times in the general case, depending on the length of the converted
238
287
 * unicode character.
239
288
 */
257
306
        }\
258
307
    }
259
308
 
260
 
#if defined(ARCH_X86) || defined(ARCH_POWERPC)
 
309
#if defined(ARCH_X86) || defined(ARCH_POWERPC) || defined(ARCH_BFIN)
 
310
#define AV_READ_TIME read_time
261
311
#if defined(ARCH_X86_64)
262
312
static inline uint64_t read_time(void)
263
313
{
264
 
        uint64_t a, d;
265
 
        asm volatile(   "rdtsc\n\t"
266
 
                : "=a" (a), "=d" (d)
267
 
        );
268
 
        return (d << 32) | (a & 0xffffffff);
 
314
    uint64_t a, d;
 
315
    asm volatile("rdtsc\n\t"
 
316
                 : "=a" (a), "=d" (d));
 
317
    return (d << 32) | (a & 0xffffffff);
269
318
}
270
319
#elif defined(ARCH_X86_32)
271
320
static inline long long read_time(void)
272
321
{
273
 
        long long l;
274
 
        asm volatile(   "rdtsc\n\t"
275
 
                : "=A" (l)
276
 
        );
277
 
        return l;
 
322
    long long l;
 
323
    asm volatile("rdtsc\n\t"
 
324
                 : "=A" (l));
 
325
    return l;
 
326
}
 
327
#elif ARCH_BFIN
 
328
static inline uint64_t read_time(void)
 
329
{
 
330
    union {
 
331
        struct {
 
332
            unsigned lo;
 
333
            unsigned hi;
 
334
        } p;
 
335
        unsigned long long c;
 
336
    } t;
 
337
    asm volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi));
 
338
    return t.c;
278
339
}
279
340
#else //FIXME check ppc64
280
341
static inline uint64_t read_time(void)
282
343
    uint32_t tbu, tbl, temp;
283
344
 
284
345
     /* from section 2.2.1 of the 32-bit PowerPC PEM */
285
 
     __asm__ __volatile__(
 
346
     asm volatile(
286
347
         "1:\n"
287
348
         "mftbu  %2\n"
288
349
         "mftb   %0\n"
296
357
     return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
297
358
}
298
359
#endif
 
360
#elif defined(HAVE_GETHRTIME)
 
361
#define AV_READ_TIME gethrtime
 
362
#endif
299
363
 
 
364
#ifdef AV_READ_TIME
300
365
#define START_TIMER \
301
366
uint64_t tend;\
302
 
uint64_t tstart= read_time();\
 
367
uint64_t tstart= AV_READ_TIME();\
303
368
 
304
369
#define STOP_TIMER(id) \
305
 
tend= read_time();\
 
370
tend= AV_READ_TIME();\
306
371
{\
307
 
  static uint64_t tsum=0;\
308
 
  static int tcount=0;\
309
 
  static int tskip_count=0;\
310
 
  if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\
311
 
      tsum+= tend - tstart;\
312
 
      tcount++;\
313
 
  }else\
314
 
      tskip_count++;\
315
 
  if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
316
 
      av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\
317
 
  }\
 
372
    static uint64_t tsum=0;\
 
373
    static int tcount=0;\
 
374
    static int tskip_count=0;\
 
375
    if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\
 
376
        tsum+= tend - tstart;\
 
377
        tcount++;\
 
378
    }else\
 
379
        tskip_count++;\
 
380
    if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
 
381
        av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
 
382
               tsum*10/tcount, id, tcount, tskip_count);\
 
383
    }\
318
384
}
319
385
#else
320
386
#define START_TIMER
321
387
#define STOP_TIMER(id) {}
322
388
#endif
323
389
 
324
 
/* memory */
325
 
 
326
 
#ifdef __GNUC__
327
 
  #define DECLARE_ALIGNED(n,t,v)       t v __attribute__ ((aligned (n)))
328
 
#else
329
 
  #define DECLARE_ALIGNED(n,t,v)      __declspec(align(n)) t v
330
 
#endif
331
 
 
332
 
/* memory */
333
 
void *av_malloc(unsigned int size);
334
 
void *av_realloc(void *ptr, unsigned int size);
335
 
void av_free(void *ptr);
336
 
 
337
 
void *av_mallocz(unsigned int size);
338
 
char *av_strdup(const char *s);
339
 
void av_freep(void *ptr);
340
 
 
341
 
#endif /* COMMON_H */
 
390
#endif /* FFMPEG_COMMON_H */