annotate src/wma/libffwma/common.h @ 2231:a8471cee0697

fix indentation.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Sat, 15 Dec 2007 01:08:36 +0900
parents 5412f8c2ec29
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
1 /**
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
2 * @file common.h
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
3 * common internal api header.
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
4 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
5
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
6 #ifndef COMMON_H
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
7 #define COMMON_H
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
8
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
9 #include "config.h"
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
10
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
11 #define TUNECPU generic
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
12 #undef HAVE_MMX
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
13 #define __CPU__ 586
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
14 #define HAVE_BUILTIN_VECTOR 1
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
15 #define CONFIG_DECODERS 1
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
16 /*#define CONFIG_HAVE_DLOPEN 1
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
17 #define CONFIG_HAVE_DLFCN 1*/
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
18 /*#undef CONFIG_AUDIO_OSS*/
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
19 #define SIMPLE_IDCT 1
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
20 /*#undef CONFIG_FFSERVER*/
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
21 #define CONFIG_RISKY 1
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
22
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
23 #define ALT_BITSTREAM_READER
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
24 //#define LIBMPEG2_BITSTREAM_READER
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
25 //#define A32_BITSTREAM_READER
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
26 //#define LIBMPEG2_BITSTREAM_READER_HACK //add BERO
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
27
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
28 #ifndef M_PI
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
29 #define M_PI 3.14159265358979323846
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
30 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
31
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
32 #if 1
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
33 /* only include the following when compiling package */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
34
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
35 #include <stdlib.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
36 #include <stdio.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
37 #include <string.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
38 #include <ctype.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
39 #include <errno.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
40 #include <math.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
41
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
42 # ifndef ENODATA
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
43 # define ENODATA 61
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
44 # endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
45
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
46 #include <stddef.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
47 #ifndef offsetof
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
48 # define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
49 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
50
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
51 #define AVOPTION_CODEC_BOOL(name, help, field) \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
52 { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_BOOL }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
53 #define AVOPTION_CODEC_DOUBLE(name, help, field, minv, maxv, defval) \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
54 { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_DOUBLE, minv, maxv, defval }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
55 #define AVOPTION_CODEC_FLAG(name, help, field, flag, defval) \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
56 { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_FLAG, flag, 0, defval }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
57 #define AVOPTION_CODEC_INT(name, help, field, minv, maxv, defval) \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
58 { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_INT, minv, maxv, defval }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
59 #define AVOPTION_CODEC_STRING(name, help, field, str, val) \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
60 { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
61 #define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
62 { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_RCOVERRIDE, .defval = 0, .defstr = NULL }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
63 #define AVOPTION_SUB(ptr) { .name = NULL, .help = (const char*)ptr }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
64 #define AVOPTION_END() AVOPTION_SUB(NULL)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
65
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
66 /**
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
67 * AVOption.
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
68 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
69 typedef struct AVOption {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
70 /** options' name */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
71 const char *name; /* if name is NULL, it indicates a link to next */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
72 /** short English text help or const struct AVOption* subpointer */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
73 const char *help; // const struct AVOption* sub;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
74 /** offset to context structure where the parsed value should be stored */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
75 int offset;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
76 /** options' type */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
77 int type;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
78 #define FF_OPT_TYPE_BOOL 1 ///< boolean - true,1,on (or simply presence)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
79 #define FF_OPT_TYPE_DOUBLE 2 ///< double
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
80 #define FF_OPT_TYPE_INT 3 ///< integer
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
81 #define FF_OPT_TYPE_STRING 4 ///< string (finished with \0)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
82 #define FF_OPT_TYPE_MASK 0x1f ///< mask for types - upper bits are various flags
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
83 //#define FF_OPT_TYPE_EXPERT 0x20 // flag for expert option
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
84 #define FF_OPT_TYPE_FLAG (FF_OPT_TYPE_BOOL | 0x40)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
85 #define FF_OPT_TYPE_RCOVERRIDE (FF_OPT_TYPE_STRING | 0x80)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
86 /** min value (min == max -> no limits) */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
87 double min;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
88 /** maximum value for double/int */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
89 double max;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
90 /** default boo [0,1]l/double/int value */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
91 double defval;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
92 /**
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
93 * default string value (with optional semicolon delimited extra option-list
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
94 * i.e. option1;option2;option3
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
95 * defval might select other then first argument as default
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
96 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
97 const char *defstr;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
98 #define FF_OPT_MAX_DEPTH 10
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
99 } AVOption;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
100
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
101 #ifdef HAVE_MMX
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
102 extern const struct AVOption avoptions_common[3 + 5];
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
103 #else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
104 extern const struct AVOption avoptions_common[3];
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
105 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
106 extern const struct AVOption avoptions_workaround_bug[11];
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
107
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
108 #endif /* HAVE_AV_CONFIG_H */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
109
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
110 /* Suppress restrict if it was not defined in config.h. */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
111 #ifndef restrict
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
112 # define restrict
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
113 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
114
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
115 #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
116 # define always_inline __attribute__((always_inline)) inline
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
117 #else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
118 # define always_inline inline
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
119 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
120
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
121 #ifndef EMULATE_INTTYPES
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
122 # include <inttypes.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
123 #else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
124 typedef signed char int8_t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
125 typedef signed short int16_t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
126 typedef signed int int32_t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
127 typedef unsigned char uint8_t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
128 typedef unsigned short uint16_t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
129 typedef unsigned int uint32_t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
130 typedef signed long long int64_t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
131 typedef unsigned long long uint64_t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
132 #endif /* HAVE_INTTYPES_H */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
133
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
134 #ifndef INT64_MAX
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
135 #define INT64_MAX 9223372036854775807LL
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
136 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
137
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
138 #ifdef EMULATE_FAST_INT
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
139 /* note that we don't emulate 64bit ints */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
140 typedef signed char int_fast8_t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
141 typedef signed int int_fast16_t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
142 typedef signed int int_fast32_t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
143 typedef unsigned char uint_fast8_t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
144 typedef unsigned int uint_fast16_t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
145 typedef unsigned int uint_fast32_t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
146 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
147
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
148 #if 1
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
149
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
150 #include <float.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
151
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
152 #endif /* HAVE_AV_CONFIG_H */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
153
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
154 /* CONFIG_OS2 end */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
155
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
156 /* unix */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
157
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
158 #ifndef int64_t_C
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
159 #define int64_t_C(c) (c ## LL)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
160 #define uint64_t_C(c) (c ## ULL)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
161
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
162 #if 1
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
163
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
164 # ifdef USE_FASTMEMCPY
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
165 # include "fastmemcpy.h"
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
166 # endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
167 # endif /* HAVE_AV_CONFIG_H */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
168
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
169 #endif /* !CONFIG_WIN32 && !CONFIG_OS2 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
170
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
171 #if 1
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
172
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
173 # include "bswap.h"
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
174
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
175 # if defined(__MINGW32__) || defined(__CYGWIN__) || \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
176 defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
177 # define MANGLE(a) "_" #a
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
178 # else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
179 # define MANGLE(a) #a
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
180 # endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
181
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
182 /* debug stuff */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
183
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
184 # ifndef DEBUG
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
185 # define NDEBUG
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
186 # endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
187 # include <assert.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
188
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
189 /* dprintf macros */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
190 # if defined(CONFIG_WIN32) && !defined(__MINGW32__)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
191
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
192 inline void dprintf(const char* fmt,...) {}
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
193
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
194 # else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
195
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
196 # ifdef DEBUG
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
197 # define dprintf(fmt,...) printf(fmt, __VA_ARGS__)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
198 # else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
199 # define dprintf(fmt,...)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
200 # endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
201
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
202 # endif /* !CONFIG_WIN32 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
203
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
204 # define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
205
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
206 //rounded divison & shift
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
207 #define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
208 /* assume b>0 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
209 #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
210
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
211 #ifndef ABS
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
212 #define ABS(a) ((a) >= 0 ? (a) : (-(a)))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
213 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
214
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
215 #define FFMAX(a,b) ((a) > (b) ? (a) : (b))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
216 #define FFMIN(a,b) ((a) > (b) ? (b) : (a))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
217
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
218 extern const uint32_t inverse[256];
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
219
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
220 #ifdef ARCH_X86
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
221 # define FASTDIV(a,b) \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
222 ({\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
223 int ret,dmy;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
224 asm volatile(\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
225 "mull %3"\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
226 :"=d"(ret),"=a"(dmy)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
227 :"1"(a),"g"(inverse[b])\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
228 );\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
229 ret;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
230 })
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
231 #elif defined(CONFIG_FASTDIV)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
232 # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*inverse[b])>>32))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
233 #else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
234 # define FASTDIV(a,b) ((a)/(b))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
235 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
236
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
237 #ifdef ARCH_X86
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
238 // avoid +32 for shift optimization (gcc should do that ...)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
239 static inline int32_t NEG_SSR32( int32_t a, int8_t s){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
240 asm ("sarl %1, %0\n\t"
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
241 : "+r" (a)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
242 : "ic" ((uint8_t)(-s))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
243 );
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
244 return a;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
245 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
246 static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
247 asm ("shrl %1, %0\n\t"
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
248 : "+r" (a)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
249 : "ic" ((uint8_t)(-s))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
250 );
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
251 return a;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
252 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
253 #else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
254 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
255 # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
256 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
257
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
258 /* bit output */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
259
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
260 struct PutBitContext;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
261
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
262 typedef void (*WriteDataFunc)(void *, uint8_t *, int);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
263
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
264 typedef struct PutBitContext {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
265 uint32_t bit_buf;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
266 int bit_left;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
267 uint8_t *buf, *buf_ptr, *buf_end;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
268 } PutBitContext;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
269
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
270 void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
271
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
272 // XXX XXX XXX
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
273 #if 0
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
274 int get_bit_count(PutBitContext *s); /* XXX: change function name */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
275 void align_put_bits(PutBitContext *s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
276 void flush_put_bits(PutBitContext *s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
277 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
278
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
279 /* bit input */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
280
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
281 typedef struct GetBitContext {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
282 const uint8_t *buffer, *buffer_end;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
283 int index;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
284 int size_in_bits;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
285 } GetBitContext;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
286
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
287 static inline int get_bits_count(GetBitContext *s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
288
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
289 #define VLC_TYPE int16_t
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
290
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
291 typedef struct VLC {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
292 int bits;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
293 VLC_TYPE (*table)[2]; ///< code, bits
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
294 int table_size, table_allocated;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
295 } VLC;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
296
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
297 typedef struct RL_VLC_ELEM {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
298 int16_t level;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
299 int8_t len;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
300 uint8_t run;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
301 } RL_VLC_ELEM;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
302
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
303 #ifdef ARCH_SPARC64
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
304 #define UNALIGNED_STORES_ARE_BAD
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
305 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
306
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
307 /* used to avoid missaligned exceptions on some archs (alpha, ...) */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
308 #ifdef ARCH_X86
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
309 # define unaligned32(a) (*(uint32_t*)(a))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
310 #else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
311 # ifdef __GNUC__
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
312 static inline uint32_t unaligned32(const void *v) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
313 struct Unaligned {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
314 uint32_t i;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
315 } __attribute__((packed));
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
316
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
317 return ((const struct Unaligned *) v)->i;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
318 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
319 # elif defined(__DECC)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
320 static inline uint32_t unaligned32(const void *v) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
321 return *(const __unaligned uint32_t *) v;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
322 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
323 # else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
324 static inline uint32_t unaligned32(const void *v) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
325 return *(const uint32_t *) v;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
326 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
327 # endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
328 #endif //!ARCH_X86
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
329
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
330 static inline void put_bits(PutBitContext *s, int n, unsigned int value)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
331 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
332 unsigned int bit_buf;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
333 int bit_left;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
334
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
335 #ifdef STATS
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
336 st_out_bit_counts[st_current_index] += n;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
337 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
338 // printf("put_bits=%d %x\n", n, value);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
339 assert(n == 32 || value < (1U << n));
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
340
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
341 bit_buf = s->bit_buf;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
342 bit_left = s->bit_left;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
343
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
344 // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
345 /* XXX: optimize */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
346 if (n < bit_left) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
347 bit_buf = (bit_buf<<n) | value;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
348 bit_left-=n;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
349 } else {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
350 bit_buf<<=bit_left;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
351 bit_buf |= value >> (n - bit_left);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
352 #ifdef UNALIGNED_STORES_ARE_BAD
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
353 if (3 & (int) s->buf_ptr) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
354 s->buf_ptr[0] = bit_buf >> 24;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
355 s->buf_ptr[1] = bit_buf >> 16;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
356 s->buf_ptr[2] = bit_buf >> 8;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
357 s->buf_ptr[3] = bit_buf ;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
358 } else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
359 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
360 *(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
361 //printf("bitbuf = %08x\n", bit_buf);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
362 s->buf_ptr+=4;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
363 bit_left+=32 - n;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
364 bit_buf = value;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
365 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
366
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
367 s->bit_buf = bit_buf;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
368 s->bit_left = bit_left;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
369 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
370
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
371 static inline uint8_t* pbBufPtr(PutBitContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
372 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
373 return s->buf_ptr;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
374 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
375
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
376 /* Bitstream reader API docs:
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
377 name
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
378 abritary name which is used as prefix for the internal variables
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
379
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
380 gb
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
381 getbitcontext
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
382
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
383 OPEN_READER(name, gb)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
384 loads gb into local variables
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
385
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
386 CLOSE_READER(name, gb)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
387 stores local vars in gb
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
388
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
389 UPDATE_CACHE(name, gb)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
390 refills the internal cache from the bitstream
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
391 after this call at least MIN_CACHE_BITS will be available,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
392
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
393 GET_CACHE(name, gb)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
394 will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
395
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
396 SHOW_UBITS(name, gb, num)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
397 will return the nest num bits
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
398
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
399 SHOW_SBITS(name, gb, num)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
400 will return the nest num bits and do sign extension
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
401
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
402 SKIP_BITS(name, gb, num)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
403 will skip over the next num bits
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
404 note, this is equinvalent to SKIP_CACHE; SKIP_COUNTER
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
405
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
406 SKIP_CACHE(name, gb, num)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
407 will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
408
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
409 SKIP_COUNTER(name, gb, num)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
410 will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
411
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
412 LAST_SKIP_CACHE(name, gb, num)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
413 will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
414
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
415 LAST_SKIP_BITS(name, gb, num)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
416 is equinvalent to SKIP_LAST_CACHE; SKIP_COUNTER
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
417
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
418 for examples see get_bits, show_bits, skip_bits, get_vlc
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
419 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
420
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
421 static inline int unaligned32_be(const void *v)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
422 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
423 #ifdef CONFIG_ALIGN
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
424 const uint8_t *p=v;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
425 return (((p[0]<<8) | p[1])<<16) | (p[2]<<8) | (p[3]);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
426 #else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
427 return be2me_32( unaligned32(v)); //original
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
428 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
429 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
430
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
431 # define MIN_CACHE_BITS 25
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
432
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
433 # define OPEN_READER(name, gb)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
434 int name##_index= (gb)->index;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
435 int name##_cache= 0;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
436
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
437 # define CLOSE_READER(name, gb)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
438 (gb)->index= name##_index;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
439
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
440 # define UPDATE_CACHE(name, gb)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
441 name##_cache= unaligned32_be( ((uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
442
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
443 # define SKIP_CACHE(name, gb, num)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
444 name##_cache <<= (num);\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
445
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
446 // FIXME name?
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
447 # define SKIP_COUNTER(name, gb, num)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
448 name##_index += (num);\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
449
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
450 # define SKIP_BITS(name, gb, num)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
451 {\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
452 SKIP_CACHE(name, gb, num)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
453 SKIP_COUNTER(name, gb, num)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
454 }\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
455
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
456 # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
457 # define LAST_SKIP_CACHE(name, gb, num) ;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
458
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
459 # define SHOW_UBITS(name, gb, num)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
460 NEG_USR32(name##_cache, num)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
461
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
462 # define SHOW_SBITS(name, gb, num)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
463 NEG_SSR32(name##_cache, num)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
464
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
465 # define GET_CACHE(name, gb)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
466 ((uint32_t)name##_cache)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
467
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
468 static inline int get_bits_count(GetBitContext *s){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
469 return s->index;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
470 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
471
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
472 /**
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
473 * read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
474 * if MSB not set it is negative
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
475 * @param n length in bits
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
476 * @author BERO
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
477 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
478 static inline int get_xbits(GetBitContext *s, int n){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
479 register int tmp;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
480 register int32_t cache;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
481 OPEN_READER(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
482 UPDATE_CACHE(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
483 cache = GET_CACHE(re,s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
484 if ((int32_t)cache<0) { //MSB=1
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
485 tmp = NEG_USR32(cache,n);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
486 } else {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
487 // tmp = (-1<<n) | NEG_USR32(cache,n) + 1; mpeg12.c algo
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
488 // tmp = - (NEG_USR32(cache,n) ^ ((1 << n) - 1)); h263.c algo
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
489 tmp = - NEG_USR32(~cache,n);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
490 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
491 LAST_SKIP_BITS(re, s, n)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
492 CLOSE_READER(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
493 return tmp;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
494 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
495
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
496 static inline int get_sbits(GetBitContext *s, int n){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
497 register int tmp;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
498 OPEN_READER(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
499 UPDATE_CACHE(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
500 tmp= SHOW_SBITS(re, s, n);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
501 LAST_SKIP_BITS(re, s, n)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
502 CLOSE_READER(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
503 return tmp;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
504 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
505
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
506 /**
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
507 * reads 0-17 bits.
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
508 * Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
509 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
510 static inline unsigned int get_bits(GetBitContext *s, int n){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
511 register int tmp;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
512 OPEN_READER(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
513 UPDATE_CACHE(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
514 tmp= SHOW_UBITS(re, s, n);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
515 LAST_SKIP_BITS(re, s, n)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
516 CLOSE_READER(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
517 return tmp;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
518 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
519
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
520 unsigned int get_bits_long(GetBitContext *s, int n);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
521
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
522 /**
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
523 * shows 0-17 bits.
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
524 * Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
525 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
526 static inline unsigned int show_bits(GetBitContext *s, int n){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
527 register int tmp;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
528 OPEN_READER(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
529 UPDATE_CACHE(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
530 tmp= SHOW_UBITS(re, s, n);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
531 // CLOSE_READER(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
532 return tmp;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
533 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
534
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
535 unsigned int show_bits_long(GetBitContext *s, int n);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
536
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
537 static inline void skip_bits(GetBitContext *s, int n){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
538 //Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
539 OPEN_READER(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
540 UPDATE_CACHE(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
541 LAST_SKIP_BITS(re, s, n)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
542 CLOSE_READER(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
543 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
544
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
545 static inline unsigned int get_bits1(GetBitContext *s){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
546 #ifdef ALT_BITSTREAM_READER
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
547 int index= s->index;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
548 uint8_t result= s->buffer[ index>>3 ];
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
549 result<<= (index&0x07);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
550 result>>= 8 - 1;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
551 index++;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
552 s->index= index;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
553
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
554 return result;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
555 #else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
556 return get_bits(s, 1);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
557 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
558 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
559
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
560 static inline unsigned int show_bits1(GetBitContext *s){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
561 return show_bits(s, 1);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
562 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
563
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
564 static inline void skip_bits1(GetBitContext *s){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
565 skip_bits(s, 1);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
566 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
567
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
568 void init_get_bits(GetBitContext *s,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
569 const uint8_t *buffer, int buffer_size);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
570
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
571 int check_marker(GetBitContext *s, const char *msg);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
572 void align_get_bits(GetBitContext *s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
573 int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
574 const void *bits, int bits_wrap, int bits_size,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
575 const void *codes, int codes_wrap, int codes_size);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
576 void free_vlc(VLC *vlc);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
577
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
578 /**
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
579 *
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
580 * if the vlc code is invalid and max_depth=1 than no bits will be removed
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
581 * if the vlc code is invalid and max_depth>1 than the number of bits removed
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
582 * is undefined
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
583 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
584 #define GET_VLC(code, name, gb, table, bits, max_depth)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
585 {\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
586 int n, index, nb_bits;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
587 \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
588 index= SHOW_UBITS(name, gb, bits);\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
589 code = table[index][0];\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
590 n = table[index][1];\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
591 \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
592 if(max_depth > 1 && n < 0){\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
593 LAST_SKIP_BITS(name, gb, bits)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
594 UPDATE_CACHE(name, gb)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
595 \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
596 nb_bits = -n;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
597 \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
598 index= SHOW_UBITS(name, gb, nb_bits) + code;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
599 code = table[index][0];\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
600 n = table[index][1];\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
601 if(max_depth > 2 && n < 0){\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
602 LAST_SKIP_BITS(name, gb, nb_bits)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
603 UPDATE_CACHE(name, gb)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
604 \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
605 nb_bits = -n;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
606 \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
607 index= SHOW_UBITS(name, gb, nb_bits) + code;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
608 code = table[index][0];\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
609 n = table[index][1];\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
610 }\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
611 }\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
612 SKIP_BITS(name, gb, n)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
613 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
614
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
615 #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
616 {\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
617 int n, index, nb_bits;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
618 \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
619 index= SHOW_UBITS(name, gb, bits);\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
620 level = table[index].level;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
621 n = table[index].len;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
622 \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
623 if(max_depth > 1 && n < 0){\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
624 LAST_SKIP_BITS(name, gb, bits)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
625 UPDATE_CACHE(name, gb)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
626 \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
627 nb_bits = -n;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
628 \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
629 index= SHOW_UBITS(name, gb, nb_bits) + level;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
630 level = table[index].level;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
631 n = table[index].len;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
632 }\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
633 run= table[index].run;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
634 SKIP_BITS(name, gb, n)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
635 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
636
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
637 // deprecated, dont use get_vlc for new code, use get_vlc2 instead or use GET_VLC directly
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
638 static inline int get_vlc(GetBitContext *s, VLC *vlc)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
639 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
640 int code;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
641 VLC_TYPE (*table)[2]= vlc->table;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
642
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
643 OPEN_READER(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
644 UPDATE_CACHE(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
645
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
646 GET_VLC(code, re, s, table, vlc->bits, 3)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
647
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
648 CLOSE_READER(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
649 return code;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
650 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
651
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
652 /**
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
653 * parses a vlc code, faster then get_vlc()
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
654 * @param bits is the number of bits which will be read at once, must be
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
655 * identical to nb_bits in init_vlc()
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
656 * @param max_depth is the number of times bits bits must be readed to completly
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
657 * read the longest vlc code
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
658 * = (max_vlc_length + bits - 1) / bits
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
659 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
660 static always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
661 int bits, int max_depth)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
662 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
663 int code;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
664
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
665 OPEN_READER(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
666 UPDATE_CACHE(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
667
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
668 GET_VLC(code, re, s, table, bits, max_depth)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
669
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
670 CLOSE_READER(re, s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
671 return code;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
672 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
673
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
674 //#define TRACE
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
675
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
676 #ifdef TRACE
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
677
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
678 static inline void print_bin(int bits, int n){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
679 int i;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
680
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
681 for(i=n-1; i>=0; i--){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
682 printf("%d", (bits>>i)&1);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
683 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
684 for(i=n; i<24; i++)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
685 printf(" ");
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
686 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
687
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
688 static inline int get_bits_trace(GetBitContext *s, int n, char *file, char *func, int line){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
689 int r= get_bits(s, n);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
690
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
691 print_bin(r, n);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
692 printf("%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
693 return r;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
694 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
695 static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, char *func, int line){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
696 int show= show_bits(s, 24);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
697 int pos= get_bits_count(s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
698 int r= get_vlc2(s, table, bits, max_depth);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
699 int len= get_bits_count(s) - pos;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
700 int bits2= show>>(24-len);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
701
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
702 print_bin(bits2, len);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
703
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
704 printf("%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
705 return r;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
706 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
707 static inline int get_xbits_trace(GetBitContext *s, int n, char *file, char *func, int line){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
708 int show= show_bits(s, n);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
709 int r= get_xbits(s, n);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
710
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
711 print_bin(show, n);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
712 printf("%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
713 return r;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
714 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
715
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
716 #define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
717 #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
718 #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
719 #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
720 #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
721
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
722 #define tprintf printf
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
723
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
724 #else //TRACE
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
725 #define tprintf(_arg...) {}
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
726 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
727
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
728 /* define it to include statistics code (useful only for optimizing
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
729 codec efficiency */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
730 //#define STATS
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
731
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
732 #ifdef STATS
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
733
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
734 enum {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
735 ST_UNKNOWN,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
736 ST_DC,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
737 ST_INTRA_AC,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
738 ST_INTER_AC,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
739 ST_INTRA_MB,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
740 ST_INTER_MB,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
741 ST_MV,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
742 ST_NB,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
743 };
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
744
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
745 extern int st_current_index;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
746 extern unsigned int st_bit_counts[ST_NB];
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
747 extern unsigned int st_out_bit_counts[ST_NB];
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
748
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
749 void print_stats(void);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
750 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
751
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
752 /* misc math functions */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
753 extern const uint8_t ff_log2_tab[256];
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
754
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
755 static inline int av_log2(unsigned int v)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
756 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
757 int n;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
758
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
759 n = 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
760 if (v & 0xffff0000) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
761 v >>= 16;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
762 n += 16;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
763 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
764 if (v & 0xff00) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
765 v >>= 8;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
766 n += 8;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
767 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
768 n += ff_log2_tab[v];
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
769
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
770 return n;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
771 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
772
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
773 static inline int av_log2_16bit(unsigned int v)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
774 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
775 int n;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
776
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
777 n = 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
778 if (v & 0xff00) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
779 v >>= 8;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
780 n += 8;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
781 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
782 n += ff_log2_tab[v];
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
783
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
784 return n;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
785 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
786
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
787 /* median of 3 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
788 static inline int mid_pred(int a, int b, int c)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
789 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
790 #if 0
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
791 int t= (a-b)&((a-b)>>31);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
792 a-=t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
793 b+=t;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
794 b-= (b-c)&((b-c)>>31);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
795 b+= (a-b)&((a-b)>>31);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
796
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
797 return b;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
798 #else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
799 if(a>b){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
800 if(c>b){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
801 if(c>a) b=a;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
802 else b=c;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
803 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
804 }else{
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
805 if(b>c){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
806 if(c>a) b=c;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
807 else b=a;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
808 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
809 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
810 return b;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
811 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
812 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
813
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
814 static inline int clip(int a, int amin, int amax)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
815 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
816 if (a < amin)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
817 return amin;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
818 else if (a > amax)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
819 return amax;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
820 else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
821 return a;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
822 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
823
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
824 /* math */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
825 extern const uint8_t ff_sqrt_tab[128];
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
826
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
827 int64_t ff_gcd(int64_t a, int64_t b);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
828
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
829 static inline int ff_sqrt(int a)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
830 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
831 int ret=0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
832 int s;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
833 int ret_sq=0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
834
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
835 if(a<128) return ff_sqrt_tab[a];
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
836
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
837 for(s=15; s>=0; s--){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
838 int b= ret_sq + (1<<(s*2)) + (ret<<s)*2;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
839 if(b<=a){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
840 ret_sq=b;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
841 ret+= 1<<s;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
842 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
843 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
844 return ret;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
845 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
846
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
847 /**
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
848 * converts fourcc string to int
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
849 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
850 static inline int ff_get_fourcc(const char *s){
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
851 assert( strlen(s)==4 );
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
852
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
853 return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
854 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
855
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
856 #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
857 #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
858
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
859
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
860 #ifdef ARCH_X86
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
861 #define MASK_ABS(mask, level)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
862 asm volatile(\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
863 "cdq \n\t"\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
864 "xorl %1, %0 \n\t"\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
865 "subl %1, %0 \n\t"\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
866 : "+a" (level), "=&d" (mask)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
867 );
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
868 #else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
869 #define MASK_ABS(mask, level)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
870 mask= level>>31;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
871 level= (level^mask)-mask;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
872 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
873
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
874
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
875 #if __CPU__ >= 686 && !defined(RUNTIME_CPUDETECT)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
876 #define COPY3_IF_LT(x,y,a,b,c,d)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
877 asm volatile (\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
878 "cmpl %0, %3 \n\t"\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
879 "cmovl %3, %0 \n\t"\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
880 "cmovl %4, %1 \n\t"\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
881 "cmovl %5, %2 \n\t"\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
882 : "+r" (x), "+r" (a), "+r" (c)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
883 : "r" (y), "r" (b), "r" (d)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
884 );
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
885 #else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
886 #define COPY3_IF_LT(x,y,a,b,c,d)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
887 if((y)<(x)){\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
888 (x)=(y);\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
889 (a)=(b);\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
890 (c)=(d);\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
891 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
892 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
893
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
894 #ifdef ARCH_X86
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
895 static inline long long rdtsc()
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
896 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
897 long long l;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
898 asm volatile( "rdtsc\n\t"
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
899 : "=A" (l)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
900 );
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
901 return l;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
902 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
903
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
904 #define START_TIMER \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
905 static uint64_t tsum=0;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
906 static int tcount=0;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
907 static int tskip_count=0;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
908 uint64_t tend;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
909 uint64_t tstart= rdtsc();\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
910
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
911 #define STOP_TIMER(id) \
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
912 tend= rdtsc();\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
913 if(tcount<2 || tend - tstart < 4*tsum/tcount){\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
914 tsum+= tend - tstart;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
915 tcount++;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
916 }else\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
917 tskip_count++;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
918 if(256*256*256*64%(tcount+tskip_count)==0){\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
919 fprintf(stderr, "%Ld dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
920 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
921 #endif
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
922
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
923 #define CLAMP_TO_8BIT(d) ((d > 0xff) ? 0xff : (d < 0) ? 0 : d)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
924
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
925 #define CHECKED_ALLOCZ(p, size)\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
926 {\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
927 p= av_mallocz(size);\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
928 if(p==NULL && (size)!=0){\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
929 perror("malloc");\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
930 goto fail;\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
931 }\
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
932 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
933
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
934
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
935
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
936
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
937 #endif /* HAVE_AV_CONFIG_H */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
938
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
939 #endif /* COMMON_H */