summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohamed Tarek <mt@rockbox.org>2010-04-27 18:04:34 +0000
committerMohamed Tarek <mt@rockbox.org>2010-04-27 18:04:34 +0000
commitdda7fab1d65e73a6bdbdac1b1d37330b8f0085aa (patch)
tree6446710d45643347d1f301bbfcb914e3ec4a39e4
parentf96406c5f3aca04f3c0ab95275d857288fd8c2ea (diff)
downloadrockbox-dda7fab1d65e73a6bdbdac1b1d37330b8f0085aa.tar.gz
rockbox-dda7fab1d65e73a6bdbdac1b1d37330b8f0085aa.zip
Add libwmapro to trunk.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25739 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/libwmapro/Makefile11
-rw-r--r--apps/codecs/libwmapro/avcodec.h3481
-rw-r--r--apps/codecs/libwmapro/avfft.h99
-rw-r--r--apps/codecs/libwmapro/bitstream.c338
-rw-r--r--apps/codecs/libwmapro/dsputil.c4572
-rw-r--r--apps/codecs/libwmapro/dsputil.h808
-rw-r--r--apps/codecs/libwmapro/fft.c385
-rw-r--r--apps/codecs/libwmapro/fft.h244
-rw-r--r--apps/codecs/libwmapro/get_bits.h692
-rw-r--r--apps/codecs/libwmapro/internal.h51
-rw-r--r--apps/codecs/libwmapro/libavutil/attributes.h113
-rw-r--r--apps/codecs/libwmapro/libavutil/avutil.h63
-rw-r--r--apps/codecs/libwmapro/libavutil/bswap.h99
-rw-r--r--apps/codecs/libwmapro/libavutil/common.h299
-rw-r--r--apps/codecs/libwmapro/libavutil/internal.h207
-rw-r--r--apps/codecs/libwmapro/libavutil/intreadwrite.h192
-rw-r--r--apps/codecs/libwmapro/libavutil/log.c89
-rw-r--r--apps/codecs/libwmapro/libavutil/log.h116
-rw-r--r--apps/codecs/libwmapro/libavutil/mathematics.c177
-rw-r--r--apps/codecs/libwmapro/libavutil/mathematics.h98
-rw-r--r--apps/codecs/libwmapro/libavutil/mem.c159
-rw-r--r--apps/codecs/libwmapro/libavutil/mem.h104
-rw-r--r--apps/codecs/libwmapro/mathops.h150
-rw-r--r--apps/codecs/libwmapro/mdct.c232
-rw-r--r--apps/codecs/libwmapro/mdct_tablegen.h60
-rw-r--r--apps/codecs/libwmapro/put_bits.h343
-rw-r--r--apps/codecs/libwmapro/wma.c525
-rw-r--r--apps/codecs/libwmapro/wma.h163
-rw-r--r--apps/codecs/libwmapro/wmaprodata.h604
-rw-r--r--apps/codecs/libwmapro/wmaprodec.c1594
30 files changed, 16068 insertions, 0 deletions
diff --git a/apps/codecs/libwmapro/Makefile b/apps/codecs/libwmapro/Makefile
new file mode 100644
index 0000000000..1fdd82090c
--- /dev/null
+++ b/apps/codecs/libwmapro/Makefile
@@ -0,0 +1,11 @@
1STD = c99
2LINK = -lm
3CFLAGS = -Wall -std=$(STD)
4TARGET = test
5OBJS = wmaprodec.c wma.c dsputil.c mdct.c fft.c bitstream.c libavutil/log.c libavutil/mem.c libavutil/mathematics.c
6$(TARGET): $(OBJS)
7 gcc $(CFLAGS) $(OBJS) $(LINK) -o $(TARGET)
8
9clean:
10 rm -f $(TARGET) *~
11
diff --git a/apps/codecs/libwmapro/avcodec.h b/apps/codecs/libwmapro/avcodec.h
new file mode 100644
index 0000000000..691dba725f
--- /dev/null
+++ b/apps/codecs/libwmapro/avcodec.h
@@ -0,0 +1,3481 @@
1/*
2 * copyright (c) 2001 Fabrice Bellard
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef AVCODEC_AVCODEC_H
22#define AVCODEC_AVCODEC_H
23
24/**
25 * @file libavcodec/avcodec.h
26 * external API header
27 */
28
29#include <errno.h>
30#include "libavutil/avutil.h"
31
32#define LIBAVCODEC_VERSION_MAJOR 52
33#define LIBAVCODEC_VERSION_MINOR 22
34#define LIBAVCODEC_VERSION_MICRO 0
35
36#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
37 LIBAVCODEC_VERSION_MINOR, \
38 LIBAVCODEC_VERSION_MICRO)
39#define LIBAVCODEC_VERSION AV_VERSION(LIBAVCODEC_VERSION_MAJOR, \
40 LIBAVCODEC_VERSION_MINOR, \
41 LIBAVCODEC_VERSION_MICRO)
42#define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT
43
44#define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
45
46#define AV_NOPTS_VALUE INT64_C(0x8000000000000000)
47#define AV_TIME_BASE 1000000
48#define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE}
49
50/**
51 * Identifies the syntax and semantics of the bitstream.
52 * The principle is roughly:
53 * Two decoders with the same ID can decode the same streams.
54 * Two encoders with the same ID can encode compatible streams.
55 * There may be slight deviations from the principle due to implementation
56 * details.
57 *
58 * If you add a codec ID to this list, add it so that
59 * 1. no value of a existing codec ID changes (that would break ABI),
60 * 2. it is as close as possible to similar codecs.
61 */
62enum CodecID {
63 CODEC_ID_NONE,
64
65 /* video codecs */
66 CODEC_ID_MPEG1VIDEO,
67 CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding
68 CODEC_ID_MPEG2VIDEO_XVMC,
69 CODEC_ID_H261,
70 CODEC_ID_H263,
71 CODEC_ID_RV10,
72 CODEC_ID_RV20,
73 CODEC_ID_MJPEG,
74 CODEC_ID_MJPEGB,
75 CODEC_ID_LJPEG,
76 CODEC_ID_SP5X,
77 CODEC_ID_JPEGLS,
78 CODEC_ID_MPEG4,
79 CODEC_ID_RAWVIDEO,
80 CODEC_ID_MSMPEG4V1,
81 CODEC_ID_MSMPEG4V2,
82 CODEC_ID_MSMPEG4V3,
83 CODEC_ID_WMV1,
84 CODEC_ID_WMV2,
85 CODEC_ID_H263P,
86 CODEC_ID_H263I,
87 CODEC_ID_FLV1,
88 CODEC_ID_SVQ1,
89 CODEC_ID_SVQ3,
90 CODEC_ID_DVVIDEO,
91 CODEC_ID_HUFFYUV,
92 CODEC_ID_CYUV,
93 CODEC_ID_H264,
94 CODEC_ID_INDEO3,
95 CODEC_ID_VP3,
96 CODEC_ID_THEORA,
97 CODEC_ID_ASV1,
98 CODEC_ID_ASV2,
99 CODEC_ID_FFV1,
100 CODEC_ID_4XM,
101 CODEC_ID_VCR1,
102 CODEC_ID_CLJR,
103 CODEC_ID_MDEC,
104 CODEC_ID_ROQ,
105 CODEC_ID_INTERPLAY_VIDEO,
106 CODEC_ID_XAN_WC3,
107 CODEC_ID_XAN_WC4,
108 CODEC_ID_RPZA,
109 CODEC_ID_CINEPAK,
110 CODEC_ID_WS_VQA,
111 CODEC_ID_MSRLE,
112 CODEC_ID_MSVIDEO1,
113 CODEC_ID_IDCIN,
114 CODEC_ID_8BPS,
115 CODEC_ID_SMC,
116 CODEC_ID_FLIC,
117 CODEC_ID_TRUEMOTION1,
118 CODEC_ID_VMDVIDEO,
119 CODEC_ID_MSZH,
120 CODEC_ID_ZLIB,
121 CODEC_ID_QTRLE,
122 CODEC_ID_SNOW,
123 CODEC_ID_TSCC,
124 CODEC_ID_ULTI,
125 CODEC_ID_QDRAW,
126 CODEC_ID_VIXL,
127 CODEC_ID_QPEG,
128 CODEC_ID_XVID,
129 CODEC_ID_PNG,
130 CODEC_ID_PPM,
131 CODEC_ID_PBM,
132 CODEC_ID_PGM,
133 CODEC_ID_PGMYUV,
134 CODEC_ID_PAM,
135 CODEC_ID_FFVHUFF,
136 CODEC_ID_RV30,
137 CODEC_ID_RV40,
138 CODEC_ID_VC1,
139 CODEC_ID_WMV3,
140 CODEC_ID_LOCO,
141 CODEC_ID_WNV1,
142 CODEC_ID_AASC,
143 CODEC_ID_INDEO2,
144 CODEC_ID_FRAPS,
145 CODEC_ID_TRUEMOTION2,
146 CODEC_ID_BMP,
147 CODEC_ID_CSCD,
148 CODEC_ID_MMVIDEO,
149 CODEC_ID_ZMBV,
150 CODEC_ID_AVS,
151 CODEC_ID_SMACKVIDEO,
152 CODEC_ID_NUV,
153 CODEC_ID_KMVC,
154 CODEC_ID_FLASHSV,
155 CODEC_ID_CAVS,
156 CODEC_ID_JPEG2000,
157 CODEC_ID_VMNC,
158 CODEC_ID_VP5,
159 CODEC_ID_VP6,
160 CODEC_ID_VP6F,
161 CODEC_ID_TARGA,
162 CODEC_ID_DSICINVIDEO,
163 CODEC_ID_TIERTEXSEQVIDEO,
164 CODEC_ID_TIFF,
165 CODEC_ID_GIF,
166 CODEC_ID_FFH264,
167 CODEC_ID_DXA,
168 CODEC_ID_DNXHD,
169 CODEC_ID_THP,
170 CODEC_ID_SGI,
171 CODEC_ID_C93,
172 CODEC_ID_BETHSOFTVID,
173 CODEC_ID_PTX,
174 CODEC_ID_TXD,
175 CODEC_ID_VP6A,
176 CODEC_ID_AMV,
177 CODEC_ID_VB,
178 CODEC_ID_PCX,
179 CODEC_ID_SUNRAST,
180 CODEC_ID_INDEO4,
181 CODEC_ID_INDEO5,
182 CODEC_ID_MIMIC,
183 CODEC_ID_RL2,
184 CODEC_ID_8SVX_EXP,
185 CODEC_ID_8SVX_FIB,
186 CODEC_ID_ESCAPE124,
187 CODEC_ID_DIRAC,
188 CODEC_ID_BFI,
189 CODEC_ID_CMV,
190 CODEC_ID_MOTIONPIXELS,
191 CODEC_ID_TGV,
192 CODEC_ID_TGQ,
193 CODEC_ID_TQI,
194
195 /* various PCM "codecs" */
196 CODEC_ID_PCM_S16LE= 0x10000,
197 CODEC_ID_PCM_S16BE,
198 CODEC_ID_PCM_U16LE,
199 CODEC_ID_PCM_U16BE,
200 CODEC_ID_PCM_S8,
201 CODEC_ID_PCM_U8,
202 CODEC_ID_PCM_MULAW,
203 CODEC_ID_PCM_ALAW,
204 CODEC_ID_PCM_S32LE,
205 CODEC_ID_PCM_S32BE,
206 CODEC_ID_PCM_U32LE,
207 CODEC_ID_PCM_U32BE,
208 CODEC_ID_PCM_S24LE,
209 CODEC_ID_PCM_S24BE,
210 CODEC_ID_PCM_U24LE,
211 CODEC_ID_PCM_U24BE,
212 CODEC_ID_PCM_S24DAUD,
213 CODEC_ID_PCM_ZORK,
214 CODEC_ID_PCM_S16LE_PLANAR,
215 CODEC_ID_PCM_DVD,
216 CODEC_ID_PCM_F32BE,
217 CODEC_ID_PCM_F32LE,
218 CODEC_ID_PCM_F64BE,
219 CODEC_ID_PCM_F64LE,
220
221 /* various ADPCM codecs */
222 CODEC_ID_ADPCM_IMA_QT= 0x11000,
223 CODEC_ID_ADPCM_IMA_WAV,
224 CODEC_ID_ADPCM_IMA_DK3,
225 CODEC_ID_ADPCM_IMA_DK4,
226 CODEC_ID_ADPCM_IMA_WS,
227 CODEC_ID_ADPCM_IMA_SMJPEG,
228 CODEC_ID_ADPCM_MS,
229 CODEC_ID_ADPCM_4XM,
230 CODEC_ID_ADPCM_XA,
231 CODEC_ID_ADPCM_ADX,
232 CODEC_ID_ADPCM_EA,
233 CODEC_ID_ADPCM_G726,
234 CODEC_ID_ADPCM_CT,
235 CODEC_ID_ADPCM_SWF,
236 CODEC_ID_ADPCM_YAMAHA,
237 CODEC_ID_ADPCM_SBPRO_4,
238 CODEC_ID_ADPCM_SBPRO_3,
239 CODEC_ID_ADPCM_SBPRO_2,
240 CODEC_ID_ADPCM_THP,
241 CODEC_ID_ADPCM_IMA_AMV,
242 CODEC_ID_ADPCM_EA_R1,
243 CODEC_ID_ADPCM_EA_R3,
244 CODEC_ID_ADPCM_EA_R2,
245 CODEC_ID_ADPCM_IMA_EA_SEAD,
246 CODEC_ID_ADPCM_IMA_EA_EACS,
247 CODEC_ID_ADPCM_EA_XAS,
248 CODEC_ID_ADPCM_EA_MAXIS_XA,
249 CODEC_ID_ADPCM_IMA_ISS,
250
251 /* AMR */
252 CODEC_ID_AMR_NB= 0x12000,
253 CODEC_ID_AMR_WB,
254
255 /* RealAudio codecs*/
256 CODEC_ID_RA_144= 0x13000,
257 CODEC_ID_RA_288,
258
259 /* various DPCM codecs */
260 CODEC_ID_ROQ_DPCM= 0x14000,
261 CODEC_ID_INTERPLAY_DPCM,
262 CODEC_ID_XAN_DPCM,
263 CODEC_ID_SOL_DPCM,
264
265 /* audio codecs */
266 CODEC_ID_MP2= 0x15000,
267 CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
268 CODEC_ID_AAC,
269 CODEC_ID_AC3,
270 CODEC_ID_DTS,
271 CODEC_ID_VORBIS,
272 CODEC_ID_DVAUDIO,
273 CODEC_ID_WMAV1,
274 CODEC_ID_WMAV2,
275 CODEC_ID_MACE3,
276 CODEC_ID_MACE6,
277 CODEC_ID_VMDAUDIO,
278 CODEC_ID_SONIC,
279 CODEC_ID_SONIC_LS,
280 CODEC_ID_FLAC,
281 CODEC_ID_MP3ADU,
282 CODEC_ID_MP3ON4,
283 CODEC_ID_SHORTEN,
284 CODEC_ID_ALAC,
285 CODEC_ID_WESTWOOD_SND1,
286 CODEC_ID_GSM, ///< as in Berlin toast format
287 CODEC_ID_QDM2,
288 CODEC_ID_COOK,
289 CODEC_ID_TRUESPEECH,
290 CODEC_ID_TTA,
291 CODEC_ID_SMACKAUDIO,
292 CODEC_ID_QCELP,
293 CODEC_ID_WAVPACK,
294 CODEC_ID_DSICINAUDIO,
295 CODEC_ID_IMC,
296 CODEC_ID_MUSEPACK7,
297 CODEC_ID_MLP,
298 CODEC_ID_GSM_MS, /* as found in WAV */
299 CODEC_ID_ATRAC3,
300 CODEC_ID_VOXWARE,
301 CODEC_ID_APE,
302 CODEC_ID_NELLYMOSER,
303 CODEC_ID_MUSEPACK8,
304 CODEC_ID_SPEEX,
305 CODEC_ID_WMAVOICE,
306 CODEC_ID_WMAPRO,
307 CODEC_ID_WMALOSSLESS,
308 CODEC_ID_ATRAC3P,
309 CODEC_ID_EAC3,
310 CODEC_ID_SIPR,
311 CODEC_ID_MP1,
312 CODEC_ID_TWINVQ,
313 CODEC_ID_TRUEHD,
314
315 /* subtitle codecs */
316 CODEC_ID_DVD_SUBTITLE= 0x17000,
317 CODEC_ID_DVB_SUBTITLE,
318 CODEC_ID_TEXT, ///< raw UTF-8 text
319 CODEC_ID_XSUB,
320 CODEC_ID_SSA,
321 CODEC_ID_MOV_TEXT,
322
323 /* other specific kind of codecs (generally used for attachments) */
324 CODEC_ID_TTF= 0x18000,
325
326 CODEC_ID_PROBE= 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it
327
328 CODEC_ID_MPEG2TS= 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
329 * stream (only used by libavformat) */
330};
331
332enum CodecType {
333 CODEC_TYPE_UNKNOWN = -1,
334 CODEC_TYPE_VIDEO,
335 CODEC_TYPE_AUDIO,
336 CODEC_TYPE_DATA,
337 CODEC_TYPE_SUBTITLE,
338 CODEC_TYPE_ATTACHMENT,
339 CODEC_TYPE_NB
340};
341
342/**
343 * all in native-endian format
344 */
345enum SampleFormat {
346 SAMPLE_FMT_NONE = -1,
347 SAMPLE_FMT_U8, ///< unsigned 8 bits
348 SAMPLE_FMT_S16, ///< signed 16 bits
349 SAMPLE_FMT_S32, ///< signed 32 bits
350 SAMPLE_FMT_FLT, ///< float
351 SAMPLE_FMT_DBL, ///< double
352 SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if dynamically linking to libavcodec
353};
354
355/* Audio channel masks */
356#define CH_FRONT_LEFT 0x00000001
357#define CH_FRONT_RIGHT 0x00000002
358#define CH_FRONT_CENTER 0x00000004
359#define CH_LOW_FREQUENCY 0x00000008
360#define CH_BACK_LEFT 0x00000010
361#define CH_BACK_RIGHT 0x00000020
362#define CH_FRONT_LEFT_OF_CENTER 0x00000040
363#define CH_FRONT_RIGHT_OF_CENTER 0x00000080
364#define CH_BACK_CENTER 0x00000100
365#define CH_SIDE_LEFT 0x00000200
366#define CH_SIDE_RIGHT 0x00000400
367#define CH_TOP_CENTER 0x00000800
368#define CH_TOP_FRONT_LEFT 0x00001000
369#define CH_TOP_FRONT_CENTER 0x00002000
370#define CH_TOP_FRONT_RIGHT 0x00004000
371#define CH_TOP_BACK_LEFT 0x00008000
372#define CH_TOP_BACK_CENTER 0x00010000
373#define CH_TOP_BACK_RIGHT 0x00020000
374#define CH_STEREO_LEFT 0x20000000 ///< Stereo downmix.
375#define CH_STEREO_RIGHT 0x40000000 ///< See CH_STEREO_LEFT.
376
377/* Audio channel convenience macros */
378#define CH_LAYOUT_MONO (CH_FRONT_CENTER)
379#define CH_LAYOUT_STEREO (CH_FRONT_LEFT|CH_FRONT_RIGHT)
380#define CH_LAYOUT_SURROUND (CH_LAYOUT_STEREO|CH_FRONT_CENTER)
381#define CH_LAYOUT_QUAD (CH_LAYOUT_STEREO|CH_BACK_LEFT|CH_BACK_RIGHT)
382#define CH_LAYOUT_5POINT0 (CH_LAYOUT_SURROUND|CH_SIDE_LEFT|CH_SIDE_RIGHT)
383#define CH_LAYOUT_5POINT1 (CH_LAYOUT_5POINT0|CH_LOW_FREQUENCY)
384#define CH_LAYOUT_7POINT1 (CH_LAYOUT_5POINT1|CH_BACK_LEFT|CH_BACK_RIGHT)
385#define CH_LAYOUT_7POINT1_WIDE (CH_LAYOUT_SURROUND|CH_LOW_FREQUENCY|\
386 CH_BACK_LEFT|CH_BACK_RIGHT|\
387 CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER)
388#define CH_LAYOUT_STEREO_DOWNMIX (CH_STEREO_LEFT|CH_STEREO_RIGHT)
389
390/* in bytes */
391#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
392
393/**
394 * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
395 * This is mainly needed because some optimized bitstream readers read
396 * 32 or 64 bit at once and could read over the end.<br>
397 * Note: If the first 23 bits of the additional bytes are not 0, then damaged
398 * MPEG bitstreams could cause overread and segfault.
399 */
400#define FF_INPUT_BUFFER_PADDING_SIZE 8
401
402/**
403 * minimum encoding buffer size
404 * Used to avoid some checks during header writing.
405 */
406#define FF_MIN_BUFFER_SIZE 16384
407
408#if 0/* MT : DELETE THIS LINE.*/
409/**
410 * motion estimation type.
411 */
412enum Motion_Est_ID {
413 ME_ZERO = 1, ///< no search, that is use 0,0 vector whenever one is needed
414 ME_FULL,
415 ME_LOG,
416 ME_PHODS,
417 ME_EPZS, ///< enhanced predictive zonal search
418 ME_X1, ///< reserved for experiments
419 ME_HEX, ///< hexagon based search
420 ME_UMH, ///< uneven multi-hexagon search
421 ME_ITER, ///< iterative search
422 ME_TESA, ///< transformed exhaustive search algorithm
423};
424
425enum AVDiscard{
426 /* We leave some space between them for extensions (drop some
427 * keyframes for intra-only or drop just some bidir frames). */
428 AVDISCARD_NONE =-16, ///< discard nothing
429 AVDISCARD_DEFAULT= 0, ///< discard useless packets like 0 size packets in avi
430 AVDISCARD_NONREF = 8, ///< discard all non reference
431 AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
432 AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
433 AVDISCARD_ALL = 48, ///< discard all
434};
435
436typedef struct RcOverride{
437 int start_frame;
438 int end_frame;
439 int qscale; // If this is 0 then quality_factor will be used instead.
440 float quality_factor;
441} RcOverride;
442
443#define FF_MAX_B_FRAMES 16
444
445/* encoding support
446 These flags can be passed in AVCodecContext.flags before initialization.
447 Note: Not everything is supported yet.
448*/
449
450#define CODEC_FLAG_QSCALE 0x0002 ///< Use fixed qscale.
451#define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / advanced prediction for H.263.
452#define CODEC_FLAG_QPEL 0x0010 ///< Use qpel MC.
453#define CODEC_FLAG_GMC 0x0020 ///< Use GMC.
454#define CODEC_FLAG_MV0 0x0040 ///< Always try a MB with MV=<0,0>.
455#define CODEC_FLAG_PART 0x0080 ///< Use data partitioning.
456/**
457 * The parent program guarantees that the input for B-frames containing
458 * streams is not written to for at least s->max_b_frames+1 frames, if
459 * this is not set the input will be copied.
460 */
461#define CODEC_FLAG_INPUT_PRESERVED 0x0100
462#define CODEC_FLAG_PASS1 0x0200 ///< Use internal 2pass ratecontrol in first pass mode.
463#define CODEC_FLAG_PASS2 0x0400 ///< Use internal 2pass ratecontrol in second pass mode.
464#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< Use external Huffman table (for MJPEG).
465#define CODEC_FLAG_GRAY 0x2000 ///< Only decode/encode grayscale.
466#define CODEC_FLAG_EMU_EDGE 0x4000 ///< Don't draw edges.
467#define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding.
468#define CODEC_FLAG_TRUNCATED 0x00010000 /** Input bitstream might be truncated at a random
469 location instead of only at frame boundaries. */
470#define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< Normalize adaptive quantization.
471#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT.
472#define CODEC_FLAG_LOW_DELAY 0x00080000 ///< Force low delay.
473#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< Use alternate scan.
474#define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< Place global headers in extradata instead of every keyframe.
475#define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT).
476/* Fx : Flag for h263+ extra options */
477#define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
478#define CODEC_FLAG_H263P_UMV 0x02000000 ///< unlimited motion vector
479#define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp.
480#define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon.
481#define CODEC_FLAG_H263P_AIV 0x00000008 ///< H.263 alternative inter VLC
482#define CODEC_FLAG_OBMC 0x00000001 ///< OBMC
483#define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter
484#define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000
485#define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
486#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< Will reserve space for SVCD scan offset user data.
487#define CODEC_FLAG_CLOSED_GOP 0x80000000
488#define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks.
489#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size.
490#define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding.
491#define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata.
492#define CODEC_FLAG2_BPYRAMID 0x00000010 ///< H.264 allow B-frames to be used as references.
493#define CODEC_FLAG2_WPRED 0x00000020 ///< H.264 weighted biprediction for B-frames
494#define CODEC_FLAG2_MIXED_REFS 0x00000040 ///< H.264 one reference per partition, as opposed to one reference per macroblock
495#define CODEC_FLAG2_8X8DCT 0x00000080 ///< H.264 high profile 8x8 transform
496#define CODEC_FLAG2_FASTPSKIP 0x00000100 ///< H.264 fast pskip
497#define CODEC_FLAG2_AUD 0x00000200 ///< H.264 access unit delimiters
498#define CODEC_FLAG2_BRDO 0x00000400 ///< B-frame rate-distortion optimization
499#define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< Use MPEG-2 intra VLC table.
500#define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC).
501#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format.
502#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping
503#define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
504#define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer.
505#define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible
506
507/* Unsupported options :
508 * Syntax Arithmetic coding (SAC)
509 * Reference Picture Selection
510 * Independent Segment Decoding */
511/* /Fx */
512/* codec capabilities */
513
514#define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback.
515/**
516 * Codec uses get_buffer() for allocating buffers.
517 * direct rendering method 1
518 */
519#define CODEC_CAP_DR1 0x0002
520/* If 'parse_only' field is true, then avcodec_parse_frame() can be used. */
521#define CODEC_CAP_PARSE_ONLY 0x0004
522#define CODEC_CAP_TRUNCATED 0x0008
523/* Codec can export data for HW decoding (XvMC). */
524#define CODEC_CAP_HWACCEL 0x0010
525/**
526 * Codec has a nonzero delay and needs to be fed with NULL at the end to get the delayed data.
527 * If this is not set, the codec is guaranteed to never be fed with NULL data.
528 */
529#define CODEC_CAP_DELAY 0x0020
530/**
531 * Codec can be fed a final frame with a smaller size.
532 * This can be used to prevent truncation of the last audio samples.
533 */
534#define CODEC_CAP_SMALL_LAST_FRAME 0x0040
535/**
536 * Codec can export data for HW decoding (VDPAU).
537 */
538#define CODEC_CAP_HWACCEL_VDPAU 0x0080
539
540//The following defines may change, don't expect compatibility if you use them.
541#define MB_TYPE_INTRA4x4 0x0001
542#define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific
543#define MB_TYPE_INTRA_PCM 0x0004 //FIXME H.264-specific
544#define MB_TYPE_16x16 0x0008
545#define MB_TYPE_16x8 0x0010
546#define MB_TYPE_8x16 0x0020
547#define MB_TYPE_8x8 0x0040
548#define MB_TYPE_INTERLACED 0x0080
549#define MB_TYPE_DIRECT2 0x0100 //FIXME
550#define MB_TYPE_ACPRED 0x0200
551#define MB_TYPE_GMC 0x0400
552#define MB_TYPE_SKIP 0x0800
553#define MB_TYPE_P0L0 0x1000
554#define MB_TYPE_P1L0 0x2000
555#define MB_TYPE_P0L1 0x4000
556#define MB_TYPE_P1L1 0x8000
557#define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
558#define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
559#define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
560#define MB_TYPE_QUANT 0x00010000
561#define MB_TYPE_CBP 0x00020000
562//Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...)
563
564/**
565 * Pan Scan area.
566 * This specifies the area which should be displayed.
567 * Note there may be multiple such areas for one frame.
568 */
569typedef struct AVPanScan{
570 /**
571 * id
572 * - encoding: Set by user.
573 * - decoding: Set by libavcodec.
574 */
575 int id;
576
577 /**
578 * width and height in 1/16 pel
579 * - encoding: Set by user.
580 * - decoding: Set by libavcodec.
581 */
582 int width;
583 int height;
584
585 /**
586 * position of the top left corner in 1/16 pel for up to 3 fields/frames
587 * - encoding: Set by user.
588 * - decoding: Set by libavcodec.
589 */
590 int16_t position[3][2];
591}AVPanScan;
592
593#define FF_COMMON_FRAME \
594 /**\
595 * pointer to the picture planes.\
596 * This might be different from the first allocated byte\
597 * - encoding: \
598 * - decoding: \
599 */\
600 uint8_t *data[4];\
601 int linesize[4];\
602 /**\
603 * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.\
604 * This isn't used by libavcodec unless the default get/release_buffer() is used.\
605 * - encoding: \
606 * - decoding: \
607 */\
608 uint8_t *base[4];\
609 /**\
610 * 1 -> keyframe, 0-> not\
611 * - encoding: Set by libavcodec.\
612 * - decoding: Set by libavcodec.\
613 */\
614 int key_frame;\
615\
616 /**\
617 * Picture type of the frame, see ?_TYPE below.\
618 * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\
619 * - decoding: Set by libavcodec.\
620 */\
621 int pict_type;\
622\
623 /**\
624 * presentation timestamp in time_base units (time when frame should be shown to user)\
625 * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.\
626 * - encoding: MUST be set by user.\
627 * - decoding: Set by libavcodec.\
628 */\
629 int64_t pts;\
630\
631 /**\
632 * picture number in bitstream order\
633 * - encoding: set by\
634 * - decoding: Set by libavcodec.\
635 */\
636 int coded_picture_number;\
637 /**\
638 * picture number in display order\
639 * - encoding: set by\
640 * - decoding: Set by libavcodec.\
641 */\
642 int display_picture_number;\
643\
644 /**\
645 * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \
646 * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\
647 * - decoding: Set by libavcodec.\
648 */\
649 int quality; \
650\
651 /**\
652 * buffer age (1->was last buffer and dint change, 2->..., ...).\
653 * Set to INT_MAX if the buffer has not been used yet.\
654 * - encoding: unused\
655 * - decoding: MUST be set by get_buffer().\
656 */\
657 int age;\
658\
659 /**\
660 * is this picture used as reference\
661 * The values for this are the same as the MpegEncContext.picture_structure\
662 * variable, that is 1->top field, 2->bottom field, 3->frame/both fields.\
663 * Set to 4 for delayed, non-reference frames.\
664 * - encoding: unused\
665 * - decoding: Set by libavcodec. (before get_buffer() call)).\
666 */\
667 int reference;\
668\
669 /**\
670 * QP table\
671 * - encoding: unused\
672 * - decoding: Set by libavcodec.\
673 */\
674 int8_t *qscale_table;\
675 /**\
676 * QP store stride\
677 * - encoding: unused\
678 * - decoding: Set by libavcodec.\
679 */\
680 int qstride;\
681\
682 /**\
683 * mbskip_table[mb]>=1 if MB didn't change\
684 * stride= mb_width = (width+15)>>4\
685 * - encoding: unused\
686 * - decoding: Set by libavcodec.\
687 */\
688 uint8_t *mbskip_table;\
689\
690 /**\
691 * motion vector table\
692 * @code\
693 * example:\
694 * int mv_sample_log2= 4 - motion_subsample_log2;\
695 * int mb_width= (width+15)>>4;\
696 * int mv_stride= (mb_width << mv_sample_log2) + 1;\
697 * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];\
698 * @endcode\
699 * - encoding: Set by user.\
700 * - decoding: Set by libavcodec.\
701 */\
702 int16_t (*motion_val[2])[2];\
703\
704 /**\
705 * macroblock type table\
706 * mb_type_base + mb_width + 2\
707 * - encoding: Set by user.\
708 * - decoding: Set by libavcodec.\
709 */\
710 uint32_t *mb_type;\
711\
712 /**\
713 * log2 of the size of the block which a single vector in motion_val represents: \
714 * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)\
715 * - encoding: unused\
716 * - decoding: Set by libavcodec.\
717 */\
718 uint8_t motion_subsample_log2;\
719\
720 /**\
721 * for some private data of the user\
722 * - encoding: unused\
723 * - decoding: Set by user.\
724 */\
725 void *opaque;\
726\
727 /**\
728 * error\
729 * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.\
730 * - decoding: unused\
731 */\
732 uint64_t error[4];\
733\
734 /**\
735 * type of the buffer (to keep track of who has to deallocate data[*])\
736 * - encoding: Set by the one who allocates it.\
737 * - decoding: Set by the one who allocates it.\
738 * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.\
739 */\
740 int type;\
741 \
742 /**\
743 * When decoding, this signals how much the picture must be delayed.\
744 * extra_delay = repeat_pict / (2*fps)\
745 * - encoding: unused\
746 * - decoding: Set by libavcodec.\
747 */\
748 int repeat_pict;\
749 \
750 /**\
751 * \
752 */\
753 int qscale_type;\
754 \
755 /**\
756 * The content of the picture is interlaced.\
757 * - encoding: Set by user.\
758 * - decoding: Set by libavcodec. (default 0)\
759 */\
760 int interlaced_frame;\
761 \
762 /**\
763 * If the content is interlaced, is top field displayed first.\
764 * - encoding: Set by user.\
765 * - decoding: Set by libavcodec.\
766 */\
767 int top_field_first;\
768 \
769 /**\
770 * Pan scan.\
771 * - encoding: Set by user.\
772 * - decoding: Set by libavcodec.\
773 */\
774 AVPanScan *pan_scan;\
775 \
776 /**\
777 * Tell user application that palette has changed from previous frame.\
778 * - encoding: ??? (no palette-enabled encoder yet)\
779 * - decoding: Set by libavcodec. (default 0).\
780 */\
781 int palette_has_changed;\
782 \
783 /**\
784 * codec suggestion on buffer type if != 0\
785 * - encoding: unused\
786 * - decoding: Set by libavcodec. (before get_buffer() call)).\
787 */\
788 int buffer_hints;\
789\
790 /**\
791 * DCT coefficients\
792 * - encoding: unused\
793 * - decoding: Set by libavcodec.\
794 */\
795 short *dct_coeff;\
796\
797 /**\
798 * motion referece frame index\
799 * - encoding: Set by user.\
800 * - decoding: Set by libavcodec.\
801 */\
802 int8_t *ref_index[2];\
803\
804 /**\
805 * reordered opaque 64bit number (generally a PTS) from AVCodecContext.reordered_opaque\
806 * output in AVFrame.reordered_opaque\
807 * - encoding: unused\
808 * - decoding: Read by user.\
809 */\
810 int64_t reordered_opaque;\
811\
812 /**\
813 * hardware accelerator private data (FFmpeg allocated)\
814 * - encoding: unused\
815 * - decoding: Set by libavcodec\
816 */\
817 void *hwaccel_picture_private;\
818
819
820#define FF_QSCALE_TYPE_MPEG1 0
821#define FF_QSCALE_TYPE_MPEG2 1
822#define FF_QSCALE_TYPE_H264 2
823
824#define FF_BUFFER_TYPE_INTERNAL 1
825#define FF_BUFFER_TYPE_USER 2 ///< direct rendering buffers (image is (de)allocated by user)
826#define FF_BUFFER_TYPE_SHARED 4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared.
827#define FF_BUFFER_TYPE_COPY 8 ///< Just a (modified) copy of some other buffer, don't deallocate anything.
828
829
830#define FF_I_TYPE 1 ///< Intra
831#define FF_P_TYPE 2 ///< Predicted
832#define FF_B_TYPE 3 ///< Bi-dir predicted
833#define FF_S_TYPE 4 ///< S(GMC)-VOP MPEG4
834#define FF_SI_TYPE 5 ///< Switching Intra
835#define FF_SP_TYPE 6 ///< Switching Predicted
836#define FF_BI_TYPE 7
837
838#define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore).
839#define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer.
840#define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content.
841#define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update).
842
843/**
844 * Audio Video Frame.
845 * New fields can be added to the end of FF_COMMON_FRAME with minor version
846 * bumps.
847 * Removal, reordering and changes to existing fields require a major
848 * version bump. No fields should be added into AVFrame before or after
849 * FF_COMMON_FRAME!
850 * sizeof(AVFrame) must not be used outside libav*.
851 */
852typedef struct AVFrame {
853 FF_COMMON_FRAME
854} AVFrame;
855#endif/* MT : DELETE THIS LINE.*/
856/**
857 * main external API structure.
858 * New fields can be added to the end with minor version bumps.
859 * Removal, reordering and changes to existing fields require a major
860 * version bump.
861 * sizeof(AVCodecContext) must not be used outside libav*.
862 */
863typedef struct AVCodecContext {
864 /**
865 * information on struct for av_log
866 * - set by avcodec_alloc_context
867 */
868 const AVClass *av_class;
869 /**
870 * the average bitrate
871 * - encoding: Set by user; unused for constant quantizer encoding.
872 * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream.
873 */
874 int bit_rate;
875
876 /**
877 * number of bits the bitstream is allowed to diverge from the reference.
878 * the reference can be CBR (for CBR pass1) or VBR (for pass2)
879 * - encoding: Set by user; unused for constant quantizer encoding.
880 * - decoding: unused
881 */
882//MT: int bit_rate_tolerance;
883
884 /**
885 * CODEC_FLAG_*.
886 * - encoding: Set by user.
887 * - decoding: Set by user.
888 */
889//MT: int flags;
890
891 /**
892 * Some codecs need additional format info. It is stored here.
893 * If any muxer uses this then ALL demuxers/parsers AND encoders for the
894 * specific codec MUST set it correctly otherwise stream copy breaks.
895 * In general use of this field by muxers is not recommanded.
896 * - encoding: Set by libavcodec.
897 * - decoding: Set by libavcodec. (FIXME: Is this OK?)
898 */
899//MT: int sub_id;
900
901 /**
902 * Motion estimation algorithm used for video coding.
903 * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
904 * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific]
905 * - encoding: MUST be set by user.
906 * - decoding: unused
907 */
908//MT: int me_method;
909
910 /**
911 * some codecs need / can use extradata like Huffman tables.
912 * mjpeg: Huffman tables
913 * rv10: additional flags
914 * mpeg4: global headers (they can be in the bitstream or here)
915 * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
916 * than extradata_size to avoid prolems if it is read with the bitstream reader.
917 * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
918 * - encoding: Set/allocated/freed by libavcodec.
919 * - decoding: Set/allocated/freed by user.
920 */
921 uint8_t *extradata;
922 int extradata_size;
923
924 /**
925 * This is the fundamental unit of time (in seconds) in terms
926 * of which frame timestamps are represented. For fixed-fps content,
927 * timebase should be 1/framerate and timestamp increments should be
928 * identically 1.
929 * - encoding: MUST be set by user.
930 * - decoding: Set by libavcodec.
931 */
932//MT: AVRational time_base;
933
934 /* video only */
935 /**
936 * picture width / height.
937 * - encoding: MUST be set by user.
938 * - decoding: Set by libavcodec.
939 * Note: For compatibility it is possible to set this instead of
940 * coded_width/height before decoding.
941 */
942//MT: int width, height;
943
944//MT:#define FF_ASPECT_EXTENDED 15
945
946 /**
947 * the number of pictures in a group of pictures, or 0 for intra_only
948 * - encoding: Set by user.
949 * - decoding: unused
950 */
951//MT: int gop_size;
952
953 /**
954 * Pixel format, see PIX_FMT_xxx.
955 * - encoding: Set by user.
956 * - decoding: Set by libavcodec.
957 */
958 //MT: enum PixelFormat pix_fmt;
959
960 /**
961 * Frame rate emulation. If not zero, the lower layer (i.e. format handler)
962 * has to read frames at native frame rate.
963 * - encoding: Set by user.
964 * - decoding: unused
965 */
966//MT: int rate_emu;
967
968 /**
969 * If non NULL, 'draw_horiz_band' is called by the libavcodec
970 * decoder to draw a horizontal band. It improves cache usage. Not
971 * all codecs can do that. You must check the codec capabilities
972 * beforehand.
973 * The function is also used by hardware acceleration APIs.
974 * It is called at least once during frame decoding to pass
975 * the data needed for hardware render.
976 * In that mode instead of pixel data, AVFrame points to
977 * a structure specific to the acceleration API. The application
978 * reads the structure and can change some fields to indicate progress
979 * or mark state.
980 * - encoding: unused
981 * - decoding: Set by user.
982 * @param height the height of the slice
983 * @param y the y position of the slice
984 * @param type 1->top field, 2->bottom field, 3->frame
985 * @param offset offset into the AVFrame.data from which the slice should be read
986 */
987 //MT: void (*draw_horiz_band)(struct AVCodecContext *s,
988 //Mt: const AVFrame *src, int offset[4],
989 //MT: int y, int type, int height);
990
991 /* audio only */
992 int sample_rate; ///< samples per second
993 int channels; ///< number of audio channels
994
995 /**
996 * audio sample format
997 * - encoding: Set by user.
998 * - decoding: Set by libavcodec.
999 */
1000 enum SampleFormat sample_fmt; ///< sample format, currently unused
1001
1002 /* The following data should not be initialized. */
1003 /**
1004 * Samples per packet, initialized when calling 'init'.
1005 */
1006 int frame_size;
1007 int frame_number; ///< audio or video frame number
1008//MT: int real_pict_num; ///< Returns the real picture number of previous encoded frame.
1009
1010 /**
1011 * Number of frames the decoded output will be delayed relative to
1012 * the encoded input.
1013 * - encoding: Set by libavcodec.
1014 * - decoding: unused
1015 */
1016//MT: int delay;
1017
1018 /* - encoding parameters */
1019//MT: float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
1020//MT: float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
1021
1022 /**
1023 * minimum quantizer
1024 * - encoding: Set by user.
1025 * - decoding: unused
1026 */
1027//MT: int qmin;
1028
1029 /**
1030 * maximum quantizer
1031 * - encoding: Set by user.
1032 * - decoding: unused
1033 */
1034//MT: int qmax;
1035
1036 /**
1037 * maximum quantizer difference between frames
1038 * - encoding: Set by user.
1039 * - decoding: unused
1040 */
1041//MT: int max_qdiff;
1042
1043 /**
1044 * maximum number of B-frames between non-B-frames
1045 * Note: The output will be delayed by max_b_frames+1 relative to the input.
1046 * - encoding: Set by user.
1047 * - decoding: unused
1048 */
1049//MT: int max_b_frames;
1050
1051 /**
1052 * qscale factor between IP and B-frames
1053 * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
1054 * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
1055 * - encoding: Set by user.
1056 * - decoding: unused
1057 */
1058//MT: float b_quant_factor;
1059
1060 /** obsolete FIXME remove */
1061//MT: int rc_strategy;
1062//MT:#define FF_RC_STRATEGY_XVID 1
1063
1064//MT: int b_frame_strategy;
1065
1066 /**
1067 * hurry up amount
1068 * - encoding: unused
1069 * - decoding: Set by user. 1-> Skip B-frames, 2-> Skip IDCT/dequant too, 5-> Skip everything except header
1070 * @deprecated Deprecated in favor of skip_idct and skip_frame.
1071 */
1072//MT: int hurry_up;
1073
1074 struct AVCodec *codec;
1075
1076 void *priv_data;
1077
1078//MT: int rtp_payload_size; /* The size of the RTP payload: the coder will */
1079 /* do its best to deliver a chunk with size */
1080 /* below rtp_payload_size, the chunk will start */
1081 /* with a start code on some codecs like H.263. */
1082 /* This doesn't take account of any particular */
1083 /* headers inside the transmitted RTP payload. */
1084
1085
1086 /* The RTP callback: This function is called */
1087 /* every time the encoder has a packet to send. */
1088 /* It depends on the encoder if the data starts */
1089 /* with a Start Code (it should). H.263 does. */
1090 /* mb_nb contains the number of macroblocks */
1091 /* encoded in the RTP payload. */
1092//MT: void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
1093
1094 /* statistics, used for 2-pass encoding */
1095//MT: int mv_bits;
1096//MT: int header_bits;
1097//MT: int i_tex_bits;
1098 //MT: int p_tex_bits;
1099//MT: int i_count;
1100 //MT: int p_count;
1101 //MT: int skip_count;
1102 //MT: int misc_bits;
1103
1104 /**
1105 * number of bits used for the previously encoded frame
1106 * - encoding: Set by libavcodec.
1107 * - decoding: unused
1108 */
1109//MT: int frame_bits;
1110
1111 /**
1112 * Private data of the user, can be used to carry app specific stuff.
1113 * - encoding: Set by user.
1114 * - decoding: Set by user.
1115 */
1116//MT: void *opaque;
1117
1118 char codec_name[32];
1119 enum CodecType codec_type; /* see CODEC_TYPE_xxx */
1120 enum CodecID codec_id; /* see CODEC_ID_xxx */
1121
1122 /**
1123 * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
1124 * This is used to work around some encoder bugs.
1125 * A demuxer should set this to what is stored in the field used to identify the codec.
1126 * If there are multiple such fields in a container then the demuxer should choose the one
1127 * which maximizes the information about the used codec.
1128 * If the codec tag field in a container is larger then 32 bits then the demuxer should
1129 * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
1130 * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
1131 * first.
1132 * - encoding: Set by user, if not then the default based on codec_id will be used.
1133 * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
1134 */
1135//MT: unsigned int codec_tag;
1136
1137 /**
1138 * Work around bugs in encoders which sometimes cannot be detected automatically.
1139 * - encoding: Set by user
1140 * - decoding: Set by user
1141 */
1142//MT: int workaround_bugs;
1143#define FF_BUG_AUTODETECT 1 ///< autodetection
1144#define FF_BUG_OLD_MSMPEG4 2
1145#define FF_BUG_XVID_ILACE 4
1146#define FF_BUG_UMP4 8
1147#define FF_BUG_NO_PADDING 16
1148#define FF_BUG_AMV 32
1149#define FF_BUG_AC_VLC 0 ///< Will be removed, libavcodec can now handle these non-compliant files by default.
1150#define FF_BUG_QPEL_CHROMA 64
1151#define FF_BUG_STD_QPEL 128
1152#define FF_BUG_QPEL_CHROMA2 256
1153#define FF_BUG_DIRECT_BLOCKSIZE 512
1154#define FF_BUG_EDGE 1024
1155#define FF_BUG_HPEL_CHROMA 2048
1156#define FF_BUG_DC_CLIP 4096
1157#define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders.
1158//#define FF_BUG_FAKE_SCALABILITY 16 //Autodetection should work 100%.
1159
1160 /**
1161 * luma single coefficient elimination threshold
1162 * - encoding: Set by user.
1163 * - decoding: unused
1164 */
1165//MT: int luma_elim_threshold;
1166
1167 /**
1168 * chroma single coeff elimination threshold
1169 * - encoding: Set by user.
1170 * - decoding: unused
1171 */
1172 //MT: int chroma_elim_threshold;
1173
1174 /**
1175 * strictly follow the standard (MPEG4, ...).
1176 * - encoding: Set by user.
1177 * - decoding: Set by user.
1178 * Setting this to STRICT or higher means the encoder and decoder will
1179 * generally do stupid things. While setting it to inofficial or lower
1180 * will mean the encoder might use things that are not supported by all
1181 * spec compliant decoders. Decoders make no difference between normal,
1182 * inofficial and experimental, that is they always try to decode things
1183 * when they can unless they are explicitly asked to behave stupid
1184 * (=strictly conform to the specs)
1185 */
1186//MT: int strict_std_compliance;
1187#define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to a older more strict version of the spec or reference software.
1188#define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences.
1189#define FF_COMPLIANCE_NORMAL 0
1190#define FF_COMPLIANCE_INOFFICIAL -1 ///< Allow inofficial extensions.
1191#define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
1192
1193 /**
1194 * qscale offset between IP and B-frames
1195 * - encoding: Set by user.
1196 * - decoding: unused
1197 */
1198//MT: float b_quant_offset;
1199
1200 /**
1201 * Error recognization; higher values will detect more errors but may
1202 * misdetect some more or less valid parts as errors.
1203 * - encoding: unused
1204 * - decoding: Set by user.
1205 */
1206//MT: int error_recognition;
1207#define FF_ER_CAREFUL 1
1208#define FF_ER_COMPLIANT 2
1209#define FF_ER_AGGRESSIVE 3
1210#define FF_ER_VERY_AGGRESSIVE 4
1211
1212 /**
1213 * Called at the beginning of each frame to get a buffer for it.
1214 * If pic.reference is set then the frame will be read later by libavcodec.
1215 * avcodec_align_dimensions() should be used to find the required width and
1216 * height, as they normally need to be rounded up to the next multiple of 16.
1217 * - encoding: unused
1218 * - decoding: Set by libavcodec., user can override.
1219 */
1220 //MT: int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
1221
1222 /**
1223 * Called to release buffers which were allocated with get_buffer.
1224 * A released buffer can be reused in get_buffer().
1225 * pic.data[*] must be set to NULL.
1226 * - encoding: unused
1227 * - decoding: Set by libavcodec., user can override.
1228 */
1229//MT: void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
1230
1231 /**
1232 * Size of the frame reordering buffer in the decoder.
1233 * For MPEG-2 it is 1 IPB or 0 low delay IP.
1234 * - encoding: Set by libavcodec.
1235 * - decoding: Set by libavcodec.
1236 */
1237//MT: int has_b_frames;
1238
1239 /**
1240 * number of bytes per packet if constant and known or 0
1241 * Used by some WAV based audio codecs.
1242 */
1243 int block_align;
1244
1245//MT: int parse_only; /* - decoding only: If true, only parsing is done
1246 /*(function avcodec_parse_frame()). The frame
1247 data is returned. Only MPEG codecs support this now. */
1248
1249 /**
1250 * 0-> h263 quant 1-> mpeg quant
1251 * - encoding: Set by user.
1252 * - decoding: unused
1253 */
1254//MT: int mpeg_quant;
1255
1256 /**
1257 * pass1 encoding statistics output buffer
1258 * - encoding: Set by libavcodec.
1259 * - decoding: unused
1260 */
1261//MT: char *stats_out;
1262
1263 /**
1264 * pass2 encoding statistics input buffer
1265 * Concatenated stuff from stats_out of pass1 should be placed here.
1266 * - encoding: Allocated/set/freed by user.
1267 * - decoding: unused
1268 */
1269//MT: char *stats_in;
1270
1271 /**
1272 * ratecontrol qmin qmax limiting method
1273 * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax.
1274 * - encoding: Set by user.
1275 * - decoding: unused
1276 */
1277//MT: float rc_qsquish;
1278
1279//MT: float rc_qmod_amp;
1280 //MT: int rc_qmod_freq;
1281
1282 /**
1283 * ratecontrol override, see RcOverride
1284 * - encoding: Allocated/set/freed by user.
1285 * - decoding: unused
1286 */
1287 //MT: RcOverride *rc_override;
1288 //MT: int rc_override_count;
1289
1290 /**
1291 * rate control equation
1292 * - encoding: Set by user
1293 * - decoding: unused
1294 */
1295//MT: const char *rc_eq;
1296
1297 /**
1298 * maximum bitrate
1299 * - encoding: Set by user.
1300 * - decoding: unused
1301 */
1302//MT: int rc_max_rate;
1303
1304 /**
1305 * minimum bitrate
1306 * - encoding: Set by user.
1307 * - decoding: unused
1308 */
1309//MT: int rc_min_rate;
1310
1311 /**
1312 * decoder bitstream buffer size
1313 * - encoding: Set by user.
1314 * - decoding: unused
1315 */
1316//MT: int rc_buffer_size;
1317 //MT: float rc_buffer_aggressivity;
1318
1319 /**
1320 * qscale factor between P and I-frames
1321 * If > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset).
1322 * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
1323 * - encoding: Set by user.
1324 * - decoding: unused
1325 */
1326//MT: float i_quant_factor;
1327
1328 /**
1329 * qscale offset between P and I-frames
1330 * - encoding: Set by user.
1331 * - decoding: unused
1332 */
1333//MT: float i_quant_offset;
1334
1335 /**
1336 * initial complexity for pass1 ratecontrol
1337 * - encoding: Set by user.
1338 * - decoding: unused
1339 */
1340//MT: float rc_initial_cplx;
1341
1342 /**
1343 * DCT algorithm, see FF_DCT_* below
1344 * - encoding: Set by user.
1345 * - decoding: unused
1346 */
1347 //MT: int dct_algo;
1348#define FF_DCT_AUTO 0
1349#define FF_DCT_FASTINT 1
1350#define FF_DCT_INT 2
1351#define FF_DCT_MMX 3
1352#define FF_DCT_MLIB 4
1353#define FF_DCT_ALTIVEC 5
1354#define FF_DCT_FAAN 6
1355
1356 /**
1357 * luminance masking (0-> disabled)
1358 * - encoding: Set by user.
1359 * - decoding: unused
1360 */
1361 //MT: float lumi_masking;
1362
1363 /**
1364 * temporary complexity masking (0-> disabled)
1365 * - encoding: Set by user.
1366 * - decoding: unused
1367 */
1368 //MT: float temporal_cplx_masking;
1369
1370 /**
1371 * spatial complexity masking (0-> disabled)
1372 * - encoding: Set by user.
1373 * - decoding: unused
1374 */
1375 //MT: float spatial_cplx_masking;
1376
1377 /**
1378 * p block masking (0-> disabled)
1379 * - encoding: Set by user.
1380 * - decoding: unused
1381 */
1382 //MT: float p_masking;
1383
1384 /**
1385 * darkness masking (0-> disabled)
1386 * - encoding: Set by user.
1387 * - decoding: unused
1388 */
1389 //MT: float dark_masking;
1390
1391 /**
1392 * IDCT algorithm, see FF_IDCT_* below.
1393 * - encoding: Set by user.
1394 * - decoding: Set by user.
1395 */
1396 //MT: int idct_algo;
1397#define FF_IDCT_AUTO 0
1398#define FF_IDCT_INT 1
1399#define FF_IDCT_SIMPLE 2
1400#define FF_IDCT_SIMPLEMMX 3
1401#define FF_IDCT_LIBMPEG2MMX 4
1402#define FF_IDCT_PS2 5
1403#define FF_IDCT_MLIB 6
1404#define FF_IDCT_ARM 7
1405#define FF_IDCT_ALTIVEC 8
1406#define FF_IDCT_SH4 9
1407#define FF_IDCT_SIMPLEARM 10
1408#define FF_IDCT_H264 11
1409#define FF_IDCT_VP3 12
1410#define FF_IDCT_IPP 13
1411#define FF_IDCT_XVIDMMX 14
1412#define FF_IDCT_CAVS 15
1413#define FF_IDCT_SIMPLEARMV5TE 16
1414#define FF_IDCT_SIMPLEARMV6 17
1415#define FF_IDCT_SIMPLEVIS 18
1416#define FF_IDCT_WMV2 19
1417#define FF_IDCT_FAAN 20
1418#define FF_IDCT_EA 21
1419#define FF_IDCT_SIMPLENEON 22
1420#define FF_IDCT_SIMPLEALPHA 23
1421
1422 /**
1423 * slice count
1424 * - encoding: Set by libavcodec.
1425 * - decoding: Set by user (or 0).
1426 */
1427//MT: int slice_count;
1428 /**
1429 * slice offsets in the frame in bytes
1430 * - encoding: Set/allocated by libavcodec.
1431 * - decoding: Set/allocated by user (or NULL).
1432 */
1433 //MT: int *slice_offset;
1434
1435 /**
1436 * error concealment flags
1437 * - encoding: unused
1438 * - decoding: Set by user.
1439 */
1440//MT: int error_concealment;
1441#define FF_EC_GUESS_MVS 1
1442#define FF_EC_DEBLOCK 2
1443
1444 /**
1445 * dsp_mask could be add used to disable unwanted CPU features
1446 * CPU features (i.e. MMX, SSE. ...)
1447 *
1448 * With the FORCE flag you may instead enable given CPU features.
1449 * (Dangerous: Usable in case of misdetection, improper usage however will
1450 * result into program crash.)
1451 */
1452 //MT: unsigned dsp_mask;
1453#define FF_MM_FORCE 0x80000000 /* Force usage of selected flags (OR) */
1454 /* lower 16 bits - CPU features */
1455#define FF_MM_MMX 0x0001 ///< standard MMX
1456#define FF_MM_3DNOW 0x0004 ///< AMD 3DNOW
1457#define FF_MM_MMXEXT 0x0002 ///< SSE integer functions or AMD MMX ext
1458#define FF_MM_SSE 0x0008 ///< SSE functions
1459#define FF_MM_SSE2 0x0010 ///< PIV SSE2 functions
1460#define FF_MM_3DNOWEXT 0x0020 ///< AMD 3DNowExt
1461#define FF_MM_SSE3 0x0040 ///< Prescott SSE3 functions
1462#define FF_MM_SSSE3 0x0080 ///< Conroe SSSE3 functions
1463#define FF_MM_IWMMXT 0x0100 ///< XScale IWMMXT
1464#define FF_MM_ALTIVEC 0x0001 ///< standard AltiVec
1465
1466 /**
1467 * bits per sample/pixel from the demuxer (needed for huffyuv).
1468 * - encoding: Set by libavcodec.
1469 * - decoding: Set by user.
1470 */
1471 //MT: int bits_per_coded_sample;
1472
1473 /**
1474 * prediction method (needed for huffyuv)
1475 * - encoding: Set by user.
1476 * - decoding: unused
1477 */
1478 //MT: int prediction_method;
1479#define FF_PRED_LEFT 0
1480#define FF_PRED_PLANE 1
1481#define FF_PRED_MEDIAN 2
1482
1483 /**
1484 * sample aspect ratio (0 if unknown)
1485 * That is the width of a pixel divided by the height of the pixel.
1486 * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
1487 * - encoding: Set by user.
1488 * - decoding: Set by libavcodec.
1489 */
1490 //MT: AVRational sample_aspect_ratio;
1491
1492 /**
1493 * the picture in the bitstream
1494 * - encoding: Set by libavcodec.
1495 * - decoding: Set by libavcodec.
1496 */
1497 //MT: AVFrame *coded_frame;
1498
1499 /**
1500 * debug
1501 * - encoding: Set by user.
1502 * - decoding: Set by user.
1503 */
1504 //MT: int debug;
1505#define FF_DEBUG_PICT_INFO 1
1506#define FF_DEBUG_RC 2
1507#define FF_DEBUG_BITSTREAM 4
1508#define FF_DEBUG_MB_TYPE 8
1509#define FF_DEBUG_QP 16
1510#define FF_DEBUG_MV 32
1511#define FF_DEBUG_DCT_COEFF 0x00000040
1512#define FF_DEBUG_SKIP 0x00000080
1513#define FF_DEBUG_STARTCODE 0x00000100
1514#define FF_DEBUG_PTS 0x00000200
1515#define FF_DEBUG_ER 0x00000400
1516#define FF_DEBUG_MMCO 0x00000800
1517#define FF_DEBUG_BUGS 0x00001000
1518#define FF_DEBUG_VIS_QP 0x00002000
1519#define FF_DEBUG_VIS_MB_TYPE 0x00004000
1520#define FF_DEBUG_BUFFERS 0x00008000
1521
1522 /**
1523 * debug
1524 * - encoding: Set by user.
1525 * - decoding: Set by user.
1526 */
1527 //MT: int debug_mv;
1528#define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames
1529#define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames
1530#define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
1531
1532 /**
1533 * error
1534 * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR.
1535 * - decoding: unused
1536 */
1537 uint64_t error[4];
1538
1539 /**
1540 * minimum MB quantizer
1541 * - encoding: unused
1542 * - decoding: unused
1543 */
1544//MT: int mb_qmin;
1545
1546 /**
1547 * maximum MB quantizer
1548 * - encoding: unused
1549 * - decoding: unused
1550 */
1551//MT: int mb_qmax;
1552
1553 /**
1554 * motion estimation comparison function
1555 * - encoding: Set by user.
1556 * - decoding: unused
1557 */
1558 //MT: int me_cmp;
1559 /**
1560 * subpixel motion estimation comparison function
1561 * - encoding: Set by user.
1562 * - decoding: unused
1563 */
1564 //MT: int me_sub_cmp;
1565 /**
1566 * macroblock comparison function (not supported yet)
1567 * - encoding: Set by user.
1568 * - decoding: unused
1569 */
1570 //MT: int mb_cmp;
1571 /**
1572 * interlaced DCT comparison function
1573 * - encoding: Set by user.
1574 * - decoding: unused
1575 */
1576 //MT: int ildct_cmp;
1577#define FF_CMP_SAD 0
1578#define FF_CMP_SSE 1
1579#define FF_CMP_SATD 2
1580#define FF_CMP_DCT 3
1581#define FF_CMP_PSNR 4
1582#define FF_CMP_BIT 5
1583#define FF_CMP_RD 6
1584#define FF_CMP_ZERO 7
1585#define FF_CMP_VSAD 8
1586#define FF_CMP_VSSE 9
1587#define FF_CMP_NSSE 10
1588#define FF_CMP_W53 11
1589#define FF_CMP_W97 12
1590#define FF_CMP_DCTMAX 13
1591#define FF_CMP_DCT264 14
1592#define FF_CMP_CHROMA 256
1593
1594 /**
1595 * ME diamond size & shape
1596 * - encoding: Set by user.
1597 * - decoding: unused
1598 */
1599//MT: int dia_size;
1600
1601 /**
1602 * amount of previous MV predictors (2a+1 x 2a+1 square)
1603 * - encoding: Set by user.
1604 * - decoding: unused
1605 */
1606 //MT: int last_predictor_count;
1607
1608 /**
1609 * prepass for motion estimation
1610 * - encoding: Set by user.
1611 * - decoding: unused
1612 */
1613 //MT: int pre_me;
1614
1615 /**
1616 * motion estimation prepass comparison function
1617 * - encoding: Set by user.
1618 * - decoding: unused
1619 */
1620 //MT: int me_pre_cmp;
1621
1622 /**
1623 * ME prepass diamond size & shape
1624 * - encoding: Set by user.
1625 * - decoding: unused
1626 */
1627 //MT: int pre_dia_size;
1628
1629 /**
1630 * subpel ME quality
1631 * - encoding: Set by user.
1632 * - decoding: unused
1633 */
1634 //MT: int me_subpel_quality;
1635
1636 /**
1637 * callback to negotiate the pixelFormat
1638 * @param fmt is the list of formats which are supported by the codec,
1639 * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
1640 * The first is always the native one.
1641 * @return the chosen format
1642 * - encoding: unused
1643 * - decoding: Set by user, if not set the native format will be chosen.
1644 */
1645 //MT: enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt);
1646
1647 /**
1648 * DTG active format information (additional aspect ratio
1649 * information only used in DVB MPEG-2 transport streams)
1650 * 0 if not set.
1651 *
1652 * - encoding: unused
1653 * - decoding: Set by decoder.
1654 */
1655 //MT: int dtg_active_format;
1656#define FF_DTG_AFD_SAME 8
1657#define FF_DTG_AFD_4_3 9
1658#define FF_DTG_AFD_16_9 10
1659#define FF_DTG_AFD_14_9 11
1660#define FF_DTG_AFD_4_3_SP_14_9 13
1661#define FF_DTG_AFD_16_9_SP_14_9 14
1662#define FF_DTG_AFD_SP_4_3 15
1663
1664 /**
1665 * maximum motion estimation search range in subpel units
1666 * If 0 then no limit.
1667 *
1668 * - encoding: Set by user.
1669 * - decoding: unused
1670 */
1671 //MT: int me_range;
1672
1673 /**
1674 * intra quantizer bias
1675 * - encoding: Set by user.
1676 * - decoding: unused
1677 */
1678 //MT: int intra_quant_bias;
1679#define FF_DEFAULT_QUANT_BIAS 999999
1680
1681 /**
1682 * inter quantizer bias
1683 * - encoding: Set by user.
1684 * - decoding: unused
1685 */
1686 //MT: int inter_quant_bias;
1687
1688 /**
1689 * color table ID
1690 * - encoding: unused
1691 * - decoding: Which clrtable should be used for 8bit RGB images.
1692 * Tables have to be stored somewhere. FIXME
1693 */
1694 //MT: int color_table_id;
1695
1696 /**
1697 * internal_buffer count
1698 * Don't touch, used by libavcodec default_get_buffer().
1699 */
1700 //MT: int internal_buffer_count;
1701
1702 /**
1703 * internal_buffers
1704 * Don't touch, used by libavcodec default_get_buffer().
1705 */
1706 void *internal_buffer;
1707
1708#define FF_LAMBDA_SHIFT 7
1709#define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT)
1710#define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
1711#define FF_LAMBDA_MAX (256*128-1)
1712
1713#define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove
1714 /**
1715 * Global quality for codecs which cannot change it per frame.
1716 * This should be proportional to MPEG-1/2/4 qscale.
1717 * - encoding: Set by user.
1718 * - decoding: unused
1719 */
1720 //MT: int global_quality;
1721
1722#define FF_CODER_TYPE_VLC 0
1723#define FF_CODER_TYPE_AC 1
1724#define FF_CODER_TYPE_RAW 2
1725#define FF_CODER_TYPE_RLE 3
1726#define FF_CODER_TYPE_DEFLATE 4
1727 /**
1728 * coder type
1729 * - encoding: Set by user.
1730 * - decoding: unused
1731 */
1732 //MT: int coder_type;
1733
1734 /**
1735 * context model
1736 * - encoding: Set by user.
1737 * - decoding: unused
1738 */
1739 //MT: int context_model;
1740#if 0
1741 /**
1742 *
1743 * - encoding: unused
1744 * - decoding: Set by user.
1745 */
1746 uint8_t * (*realloc)(struct AVCodecContext *s, uint8_t *buf, int buf_size);
1747#endif
1748
1749 /**
1750 * slice flags
1751 * - encoding: unused
1752 * - decoding: Set by user.
1753 */
1754 //MT: int slice_flags;
1755#define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
1756#define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
1757#define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
1758
1759 /**
1760 * XVideo Motion Acceleration
1761 * - encoding: forbidden
1762 * - decoding: set by decoder
1763 */
1764//MT: int xvmc_acceleration;
1765
1766 /**
1767 * macroblock decision mode
1768 * - encoding: Set by user.
1769 * - decoding: unused
1770 */
1771 //MT: int mb_decision;
1772#define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
1773#define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
1774#define FF_MB_DECISION_RD 2 ///< rate distortion
1775
1776 /**
1777 * custom intra quantization matrix
1778 * - encoding: Set by user, can be NULL.
1779 * - decoding: Set by libavcodec.
1780 */
1781 //MT: uint16_t *intra_matrix;
1782
1783 /**
1784 * custom inter quantization matrix
1785 * - encoding: Set by user, can be NULL.
1786 * - decoding: Set by libavcodec.
1787 */
1788 //MT: uint16_t *inter_matrix;
1789
1790 /**
1791 * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
1792 * This is used to work around some encoder bugs.
1793 * - encoding: unused
1794 * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
1795 */
1796 //MT: unsigned int stream_codec_tag;
1797
1798 /**
1799 * scene change detection threshold
1800 * 0 is default, larger means fewer detected scene changes.
1801 * - encoding: Set by user.
1802 * - decoding: unused
1803 */
1804//MT: int scenechange_threshold;
1805
1806 /**
1807 * minimum Lagrange multipler
1808 * - encoding: Set by user.
1809 * - decoding: unused
1810 */
1811//MT: int lmin;
1812
1813 /**
1814 * maximum Lagrange multipler
1815 * - encoding: Set by user.
1816 * - decoding: unused
1817 */
1818 //MT: int lmax;
1819
1820 /**
1821 * palette control structure
1822 * - encoding: ??? (no palette-enabled encoder yet)
1823 * - decoding: Set by user.
1824 */
1825 //MT: struct AVPaletteControl *palctrl;
1826
1827 /**
1828 * noise reduction strength
1829 * - encoding: Set by user.
1830 * - decoding: unused
1831 */
1832 //MT: int noise_reduction;
1833
1834 /**
1835 * Called at the beginning of a frame to get cr buffer for it.
1836 * Buffer type (size, hints) must be the same. libavcodec won't check it.
1837 * libavcodec will pass previous buffer in pic, function should return
1838 * same buffer or new buffer with old frame "painted" into it.
1839 * If pic.data[0] == NULL must behave like get_buffer().
1840 * - encoding: unused
1841 * - decoding: Set by libavcodec., user can override
1842 */
1843//MT: int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
1844
1845 /**
1846 * Number of bits which should be loaded into the rc buffer before decoding starts.
1847 * - encoding: Set by user.
1848 * - decoding: unused
1849 */
1850 //MT: int rc_initial_buffer_occupancy;
1851
1852 /**
1853 *
1854 * - encoding: Set by user.
1855 * - decoding: unused
1856 */
1857//MT: int inter_threshold;
1858
1859 /**
1860 * CODEC_FLAG2_*
1861 * - encoding: Set by user.
1862 * - decoding: Set by user.
1863 */
1864 //MT: int flags2;
1865
1866 /**
1867 * Simulates errors in the bitstream to test error concealment.
1868 * - encoding: Set by user.
1869 * - decoding: unused
1870 */
1871//MT: int error_rate;
1872
1873 /**
1874 * MP3 antialias algorithm, see FF_AA_* below.
1875 * - encoding: unused
1876 * - decoding: Set by user.
1877 */
1878 //MT: int antialias_algo;
1879#define FF_AA_AUTO 0
1880#define FF_AA_FASTINT 1 //not implemented yet
1881#define FF_AA_INT 2
1882#define FF_AA_FLOAT 3
1883 /**
1884 * quantizer noise shaping
1885 * - encoding: Set by user.
1886 * - decoding: unused
1887 */
1888 //MT: int quantizer_noise_shaping;
1889
1890 /**
1891 * thread count
1892 * is used to decide how many independent tasks should be passed to execute()
1893 * - encoding: Set by user.
1894 * - decoding: Set by user.
1895 */
1896 //MT: int thread_count;
1897
1898 /**
1899 * The codec may call this to execute several independent things.
1900 * It will return only after finishing all tasks.
1901 * The user may replace this with some multithreaded implementation,
1902 * the default implementation will execute the parts serially.
1903 * @param count the number of things to execute
1904 * - encoding: Set by libavcodec, user can override.
1905 * - decoding: Set by libavcodec, user can override.
1906 */
1907 //MT: int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
1908
1909 /**
1910 * thread opaque
1911 * Can be used by execute() to store some per AVCodecContext stuff.
1912 * - encoding: set by execute()
1913 * - decoding: set by execute()
1914 */
1915 //MT: void *thread_opaque;
1916
1917 /**
1918 * Motion estimation threshold below which no motion estimation is
1919 * performed, but instead the user specified motion vectors are used.
1920 *
1921 * - encoding: Set by user.
1922 * - decoding: unused
1923 */
1924//MT: int me_threshold;
1925
1926 /**
1927 * Macroblock threshold below which the user specified macroblock types will be used.
1928 * - encoding: Set by user.
1929 * - decoding: unused
1930 */
1931 //MT: int mb_threshold;
1932
1933 /**
1934 * precision of the intra DC coefficient - 8
1935 * - encoding: Set by user.
1936 * - decoding: unused
1937 */
1938//MT: int intra_dc_precision;
1939
1940 /**
1941 * noise vs. sse weight for the nsse comparsion function
1942 * - encoding: Set by user.
1943 * - decoding: unused
1944 */
1945//MT: int nsse_weight;
1946
1947 /**
1948 * Number of macroblock rows at the top which are skipped.
1949 * - encoding: unused
1950 * - decoding: Set by user.
1951 */
1952 //MT: int skip_top;
1953
1954 /**
1955 * Number of macroblock rows at the bottom which are skipped.
1956 * - encoding: unused
1957 * - decoding: Set by user.
1958 */
1959 //MT: int skip_bottom;
1960
1961 /**
1962 * profile
1963 * - encoding: Set by user.
1964 * - decoding: Set by libavcodec.
1965 */
1966 //MT: int profile;
1967#define FF_PROFILE_UNKNOWN -99
1968#define FF_PROFILE_AAC_MAIN 0
1969#define FF_PROFILE_AAC_LOW 1
1970#define FF_PROFILE_AAC_SSR 2
1971#define FF_PROFILE_AAC_LTP 3
1972
1973 /**
1974 * level
1975 * - encoding: Set by user.
1976 * - decoding: Set by libavcodec.
1977 */
1978 //MT: int level;
1979#define FF_LEVEL_UNKNOWN -99
1980
1981 /**
1982 * low resolution decoding, 1-> 1/2 size, 2->1/4 size
1983 * - encoding: unused
1984 * - decoding: Set by user.
1985 */
1986 //MT: int lowres;
1987
1988 /**
1989 * Bitstream width / height, may be different from width/height if lowres
1990 * or other things are used.
1991 * - encoding: unused
1992 * - decoding: Set by user before init if known. Codec should override / dynamically change if needed.
1993 */
1994 //MT: int coded_width, coded_height;
1995
1996 /**
1997 * frame skip threshold
1998 * - encoding: Set by user.
1999 * - decoding: unused
2000 */
2001//MT: int frame_skip_threshold;
2002
2003 /**
2004 * frame skip factor
2005 * - encoding: Set by user.
2006 * - decoding: unused
2007 */
2008 //MT: int frame_skip_factor;
2009
2010 /**
2011 * frame skip exponent
2012 * - encoding: Set by user.
2013 * - decoding: unused
2014 */
2015 //MT: int frame_skip_exp;
2016
2017 /**
2018 * frame skip comparison function
2019 * - encoding: Set by user.
2020 * - decoding: unused
2021 */
2022//MT: int frame_skip_cmp;
2023
2024 /**
2025 * Border processing masking, raises the quantizer for mbs on the borders
2026 * of the picture.
2027 * - encoding: Set by user.
2028 * - decoding: unused
2029 */
2030//MT: float border_masking;
2031
2032 /**
2033 * minimum MB lagrange multipler
2034 * - encoding: Set by user.
2035 * - decoding: unused
2036 */
2037//MT: int mb_lmin;
2038
2039 /**
2040 * maximum MB lagrange multipler
2041 * - encoding: Set by user.
2042 * - decoding: unused
2043 */
2044 //MT: int mb_lmax;
2045
2046 /**
2047 *
2048 * - encoding: Set by user.
2049 * - decoding: unused
2050 */
2051 //MT: int me_penalty_compensation;
2052
2053 /**
2054 *
2055 * - encoding: unused
2056 * - decoding: Set by user.
2057 */
2058 //MT: enum AVDiscard skip_loop_filter;
2059
2060 /**
2061 *
2062 * - encoding: unused
2063 * - decoding: Set by user.
2064 */
2065 //MT: enum AVDiscard skip_idct;
2066
2067 /**
2068 *
2069 * - encoding: unused
2070 * - decoding: Set by user.
2071 */
2072 //MT: enum AVDiscard skip_frame;
2073
2074 /**
2075 *
2076 * - encoding: Set by user.
2077 * - decoding: unused
2078 */
2079//MT: int bidir_refine;
2080
2081 /**
2082 *
2083 * - encoding: Set by user.
2084 * - decoding: unused
2085 */
2086 //MT: int brd_scale;
2087
2088 /**
2089 * constant rate factor - quality-based VBR - values ~correspond to qps
2090 * - encoding: Set by user.
2091 * - decoding: unused
2092 */
2093 //MT: float crf;
2094
2095 /**
2096 * constant quantization parameter rate control method
2097 * - encoding: Set by user.
2098 * - decoding: unused
2099 */
2100//MT: int cqp;
2101
2102 /**
2103 * minimum GOP size
2104 * - encoding: Set by user.
2105 * - decoding: unused
2106 */
2107 //MT: int keyint_min;
2108
2109 /**
2110 * number of reference frames
2111 * - encoding: Set by user.
2112 * - decoding: Set by lavc.
2113 */
2114 //MT: int refs;
2115
2116 /**
2117 * chroma qp offset from luma
2118 * - encoding: Set by user.
2119 * - decoding: unused
2120 */
2121 //MT: int chromaoffset;
2122
2123 /**
2124 * Influences how often B-frames are used.
2125 * - encoding: Set by user.
2126 * - decoding: unused
2127 */
2128 //MT: int bframebias;
2129
2130 /**
2131 * trellis RD quantization
2132 * - encoding: Set by user.
2133 * - decoding: unused
2134 */
2135 //MT: int trellis;
2136
2137 /**
2138 * Reduce fluctuations in qp (before curve compression).
2139 * - encoding: Set by user.
2140 * - decoding: unused
2141 */
2142//MT: float complexityblur;
2143
2144 /**
2145 * in-loop deblocking filter alphac0 parameter
2146 * alpha is in the range -6...6
2147 * - encoding: Set by user.
2148 * - decoding: unused
2149 */
2150 //MT: int deblockalpha;
2151
2152 /**
2153 * in-loop deblocking filter beta parameter
2154 * beta is in the range -6...6
2155 * - encoding: Set by user.
2156 * - decoding: unused
2157 */
2158 //MT: int deblockbeta;
2159
2160 /**
2161 * macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4
2162 * - encoding: Set by user.
2163 * - decoding: unused
2164 */
2165 //MT: int partitions;
2166#define X264_PART_I4X4 0x001 /* Analyze i4x4 */
2167#define X264_PART_I8X8 0x002 /* Analyze i8x8 (requires 8x8 transform) */
2168#define X264_PART_P8X8 0x010 /* Analyze p16x8, p8x16 and p8x8 */
2169#define X264_PART_P4X4 0x020 /* Analyze p8x4, p4x8, p4x4 */
2170#define X264_PART_B8X8 0x100 /* Analyze b16x8, b8x16 and b8x8 */
2171
2172 /**
2173 * direct MV prediction mode - 0 (none), 1 (spatial), 2 (temporal), 3 (auto)
2174 * - encoding: Set by user.
2175 * - decoding: unused
2176 */
2177 //MT: int directpred;
2178
2179 /**
2180 * Audio cutoff bandwidth (0 means "automatic")
2181 * - encoding: Set by user.
2182 * - decoding: unused
2183 */
2184 //MT: int cutoff;
2185
2186 /**
2187 * Multiplied by qscale for each frame and added to scene_change_score.
2188 * - encoding: Set by user.
2189 * - decoding: unused
2190 */
2191 //MT: int scenechange_factor;
2192
2193 /**
2194 *
2195 * Note: Value depends upon the compare function used for fullpel ME.
2196 * - encoding: Set by user.
2197 * - decoding: unused
2198 */
2199 //MT: int mv0_threshold;
2200
2201 /**
2202 * Adjusts sensitivity of b_frame_strategy 1.
2203 * - encoding: Set by user.
2204 * - decoding: unused
2205 */
2206 //MT: int b_sensitivity;
2207
2208 /**
2209 * - encoding: Set by user.
2210 * - decoding: unused
2211 */
2212 //MT: int compression_level;
2213#define FF_COMPRESSION_DEFAULT -1
2214
2215 /**
2216 * Sets whether to use LPC mode - used by FLAC encoder.
2217 * - encoding: Set by user.
2218 * - decoding: unused
2219 */
2220//MT: int use_lpc;
2221
2222 /**
2223 * LPC coefficient precision - used by FLAC encoder
2224 * - encoding: Set by user.
2225 * - decoding: unused
2226 */
2227 //MT: int lpc_coeff_precision;
2228
2229 /**
2230 * - encoding: Set by user.
2231 * - decoding: unused
2232 */
2233 //MT: int min_prediction_order;
2234
2235 /**
2236 * - encoding: Set by user.
2237 * - decoding: unused
2238 */
2239//MT: int max_prediction_order;
2240
2241 /**
2242 * search method for selecting prediction order
2243 * - encoding: Set by user.
2244 * - decoding: unused
2245 */
2246//MT: int prediction_order_method;
2247
2248 /**
2249 * - encoding: Set by user.
2250 * - decoding: unused
2251 */
2252 //MT: int min_partition_order;
2253
2254 /**
2255 * - encoding: Set by user.
2256 * - decoding: unused
2257 */
2258 //MT: int max_partition_order;
2259
2260 /**
2261 * GOP timecode frame start number, in non drop frame format
2262 * - encoding: Set by user.
2263 * - decoding: unused
2264 */
2265 //MT: int64_t timecode_frame_start;
2266
2267#if LIBAVCODEC_VERSION_MAJOR < 53
2268 /**
2269 * Decoder should decode to this many channels if it can (0 for default)
2270 * - encoding: unused
2271 * - decoding: Set by user.
2272 * @deprecated Deprecated in favor of request_channel_layout.
2273 */
2274 //MT: int request_channels;
2275#endif
2276
2277 /**
2278 * Percentage of dynamic range compression to be applied by the decoder.
2279 * The default value is 1.0, corresponding to full compression.
2280 * - encoding: unused
2281 * - decoding: Set by user.
2282 */
2283 //MT: float drc_scale;
2284
2285 /**
2286 * opaque 64bit number (generally a PTS) that will be reordered and
2287 * output in AVFrame.reordered_opaque
2288 * - encoding: unused
2289 * - decoding: Set by user.
2290 */
2291 //MT: int64_t reordered_opaque;
2292
2293 /**
2294 * Bits per sample/pixel of internal libavcodec pixel/sample format.
2295 * This field is applicable only when sample_fmt is SAMPLE_FMT_S32.
2296 * - encoding: set by user.
2297 * - decoding: set by libavcodec.
2298 */
2299 //MT: int bits_per_raw_sample;
2300
2301 /**
2302 * Audio channel layout.
2303 * - encoding: set by user.
2304 * - decoding: set by libavcodec.
2305 */
2306 int64_t channel_layout;
2307
2308 /**
2309 * Request decoder to use this channel layout if it can (0 for default)
2310 * - encoding: unused
2311 * - decoding: Set by user.
2312 */
2313//MT: int64_t request_channel_layout;
2314
2315 /**
2316 * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
2317 * - encoding: Set by user.
2318 * - decoding: unused.
2319 */
2320 //MT: float rc_max_available_vbv_use;
2321
2322 /**
2323 * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
2324 * - encoding: Set by user.
2325 * - decoding: unused.
2326 */
2327//MT: float rc_min_vbv_overflow_use;
2328
2329 /**
2330 * Hardware accelerator in use
2331 * - encoding: unused.
2332 * - decoding: Set by libavcodec
2333 */
2334//MT: struct AVHWAccel *hwaccel;
2335
2336 /**
2337 * For some codecs, the time base is closer to the field rate than the frame rate.
2338 * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
2339 * if no telecine is used ...
2340 *
2341 * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
2342 */
2343//MT: int ticks_per_frame;
2344
2345 /**
2346 * Hardware accelerator context.
2347 * For some hardware accelerators, a global context needs to be
2348 * provided by the user. In that case, this holds display-dependent
2349 * data FFmpeg cannot instantiate itself. Please refer to the
2350 * FFmpeg HW accelerator documentation to know how to fill this
2351 * is. e.g. for VA API, this is a struct vaapi_context.
2352 * - encoding: unused
2353 * - decoding: Set by user
2354 */
2355 //MT: void *hwaccel_context;
2356} AVCodecContext;
2357
2358/**
2359 * AVCodec.
2360 */
2361typedef struct AVCodec {
2362 /**
2363 * Name of the codec implementation.
2364 * The name is globally unique among encoders and among decoders (but an
2365 * encoder and a decoder can share the same name).
2366 * This is the primary way to find a codec from the user perspective.
2367 */
2368 const char *name;
2369 enum CodecType type;
2370 enum CodecID id;
2371 int priv_data_size;
2372 int (*init)(AVCodecContext *);
2373 int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
2374 int (*close)(AVCodecContext *);
2375 int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
2376 const uint8_t *buf, int buf_size);
2377 /**
2378 * Codec capabilities.
2379 * see CODEC_CAP_*
2380 */
2381//MT: int capabilities;
2382//MT: struct AVCodec *next;
2383 /**
2384 * Flush buffers.
2385 * Will be called when seeking
2386 */
2387//MT: void (*flush)(AVCodecContext *);
2388 //MT: const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
2389 //MT: const enum PixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
2390 /**
2391 * Descriptive name for the codec, meant to be more human readable than \p name.
2392 * You \e should use the NULL_IF_CONFIG_SMALL() macro to define it.
2393 */
2394 const char *long_name;
2395 const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
2396 const enum SampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
2397 const int64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
2398} AVCodec;
2399
2400typedef struct AVPacket {
2401 /**
2402 * Presentation timestamp in AVStream->time_base units; the time at which
2403 * the decompressed packet will be presented to the user.
2404 * Can be AV_NOPTS_VALUE if it is not stored in the file.
2405 * pts MUST be larger or equal to dts as presentation cannot happen before
2406 * decompression, unless one wants to view hex dumps. Some formats misuse
2407 * the terms dts and pts/cts to mean something different. Such timestamps
2408 * must be converted to true pts/dts before they are stored in AVPacket.
2409 */
2410 int64_t pts;
2411 /**
2412 * Decompression timestamp in AVStream->time_base units; the time at which
2413 * the packet is decompressed.
2414 * Can be AV_NOPTS_VALUE if it is not stored in the file.
2415 */
2416 int64_t dts;
2417 uint8_t *data;
2418 int size;
2419 int stream_index;
2420 int flags;
2421 /**
2422 * Duration of this packet in AVStream->time_base units, 0 if unknown.
2423 * Equals next_pts - this_pts in presentation order.
2424 */
2425 int duration;
2426 void (*destruct)(struct AVPacket *);
2427 void *priv;
2428 int64_t pos; ///< byte position in stream, -1 if unknown
2429
2430 /**
2431 * Time difference in AVStream->time_base units from the pts of this
2432 * packet to the point at which the output from the decoder has converged
2433 * independent from the availability of previous frames. That is, the
2434 * frames are virtually identical no matter if decoding started from
2435 * the very first frame or from this keyframe.
2436 * Is AV_NOPTS_VALUE if unknown.
2437 * This field is not the display duration of the current packet.
2438 *
2439 * The purpose of this field is to allow seeking in streams that have no
2440 * keyframes in the conventional sense. It corresponds to the
2441 * recovery point SEI in H.264 and match_time_delta in NUT. It is also
2442 * essential for some types of subtitle streams to ensure that all
2443 * subtitles are correctly displayed after seeking.
2444 */
2445 int64_t convergence_duration;
2446} AVPacket;
2447
2448#if 0 /* MT : DELETE THIS LINE ONLY. */
2449/**
2450 * AVHWAccel.
2451 */
2452typedef struct AVHWAccel {
2453 /**
2454 * Name of the hardware accelerated codec.
2455 * The name is globally unique among encoders and among decoders (but an
2456 * encoder and a decoder can share the same name).
2457 */
2458 const char *name;
2459
2460 /**
2461 * Type of codec implemented by the hardware accelerator.
2462 *
2463 * See CODEC_TYPE_xxx
2464 */
2465 enum CodecType type;
2466
2467 /**
2468 * Codec implemented by the hardware accelerator.
2469 *
2470 * See CODEC_ID_xxx
2471 */
2472 enum CodecID id;
2473
2474 /**
2475 * Supported pixel format.
2476 *
2477 * Only hardware accelerated formats are supported here.
2478 */
2479 enum PixelFormat pix_fmt;
2480
2481 /**
2482 * Hardware accelerated codec capabilities.
2483 * see FF_HWACCEL_CODEC_CAP_*
2484 */
2485 int capabilities;
2486
2487 struct AVHWAccel *next;
2488
2489 /**
2490 * Called at the beginning of each frame or field picture.
2491 *
2492 * Meaningful frame information (codec specific) is guaranteed to
2493 * be parsed at this point. This function is mandatory.
2494 *
2495 * Note that \p buf can be NULL along with \p buf_size set to 0.
2496 * Otherwise, this means the whole frame is available at this point.
2497 *
2498 * @param avctx the codec context
2499 * @param buf the frame data buffer base
2500 * @param buf_size the size of the frame in bytes
2501 * @return zero if successful, a negative value otherwise
2502 */
2503 int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
2504
2505 /**
2506 * Callback for each slice.
2507 *
2508 * Meaningful slice information (codec specific) is guaranteed to
2509 * be parsed at this point. This function is mandatory.
2510 *
2511 * @param avctx the codec context
2512 * @param buf the slice data buffer base
2513 * @param buf_size the size of the slice in bytes
2514 * @return zero if successful, a negative value otherwise
2515 */
2516 int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
2517
2518 /**
2519 * Called at the end of each frame or field picture.
2520 *
2521 * The whole picture is parsed at this point and can now be sent
2522 * to the hardware accelerator. This function is mandatory.
2523 *
2524 * @param avctx the codec context
2525 * @return zero if successful, a negative value otherwise
2526 */
2527 int (*end_frame)(AVCodecContext *avctx);
2528
2529 /**
2530 * Size of HW accelerator private data.
2531 *
2532 * Private data is allocated with av_mallocz() before
2533 * AVCodecContext.get_buffer() and deallocated after
2534 * AVCodecContext.release_buffer().
2535 */
2536 int priv_data_size;
2537} AVHWAccel;
2538
2539/**
2540 * four components are given, that's all.
2541 * the last component is alpha
2542 */
2543typedef struct AVPicture {
2544 uint8_t *data[4];
2545 int linesize[4]; ///< number of bytes per line
2546} AVPicture;
2547
2548/**
2549 * AVPaletteControl
2550 * This structure defines a method for communicating palette changes
2551 * between and demuxer and a decoder.
2552 *
2553 * @deprecated Use AVPacket to send palette changes instead.
2554 * This is totally broken.
2555 */
2556#define AVPALETTE_SIZE 1024
2557#define AVPALETTE_COUNT 256
2558typedef struct AVPaletteControl {
2559
2560 /* Demuxer sets this to 1 to indicate the palette has changed;
2561 * decoder resets to 0. */
2562 int palette_changed;
2563
2564 /* 4-byte ARGB palette entries, stored in native byte order; note that
2565 * the individual palette components should be on a 8-bit scale; if
2566 * the palette data comes from an IBM VGA native format, the component
2567 * data is probably 6 bits in size and needs to be scaled. */
2568 unsigned int palette[AVPALETTE_COUNT];
2569
2570} AVPaletteControl attribute_deprecated;
2571
2572enum AVSubtitleType {
2573 SUBTITLE_NONE,
2574
2575 SUBTITLE_BITMAP, ///< A bitmap, pict will be set
2576
2577 /**
2578 * Plain text, the text field must be set by the decoder and is
2579 * authoritative. ass and pict fields may contain approximations.
2580 */
2581 SUBTITLE_TEXT,
2582
2583 /**
2584 * Formatted text, the ass field must be set by the decoder and is
2585 * authoritative. pict and text fields may contain approximations.
2586 */
2587 SUBTITLE_ASS,
2588};
2589
2590typedef struct AVSubtitleRect {
2591 int x; ///< top left corner of pict, undefined when pict is not set
2592 int y; ///< top left corner of pict, undefined when pict is not set
2593 int w; ///< width of pict, undefined when pict is not set
2594 int h; ///< height of pict, undefined when pict is not set
2595 int nb_colors; ///< number of colors in pict, undefined when pict is not set
2596
2597 /**
2598 * data+linesize for the bitmap of this subtitle.
2599 * can be set for text/ass as well once they where rendered
2600 */
2601 AVPicture pict;
2602 enum AVSubtitleType type;
2603
2604 char *text; ///< 0 terminated plain UTF-8 text
2605
2606 /**
2607 * 0 terminated ASS/SSA compatible event line.
2608 * The pressentation of this is unaffected by the other values in this
2609 * struct.
2610 */
2611 char *ass;
2612} AVSubtitleRect;
2613
2614typedef struct AVSubtitle {
2615 uint16_t format; /* 0 = graphics */
2616 uint32_t start_display_time; /* relative to packet pts, in ms */
2617 uint32_t end_display_time; /* relative to packet pts, in ms */
2618 unsigned num_rects;
2619 AVSubtitleRect **rects;
2620} AVSubtitle;
2621
2622
2623/* resample.c */
2624
2625struct ReSampleContext;
2626struct AVResampleContext;
2627
2628typedef struct ReSampleContext ReSampleContext;
2629
2630#if LIBAVCODEC_VERSION_MAJOR < 53
2631/**
2632 * @deprecated Use av_audio_resample_init() instead.
2633 */
2634attribute_deprecated ReSampleContext *audio_resample_init(int output_channels, int input_channels,
2635 int output_rate, int input_rate);
2636#endif
2637/**
2638 * Initializes audio resampling context
2639 *
2640 * @param output_channels number of output channels
2641 * @param input_channels number of input channels
2642 * @param output_rate output sample rate
2643 * @param input_rate input sample rate
2644 * @param sample_fmt_out requested output sample format
2645 * @param sample_fmt_in input sample format
2646 * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq
2647 * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
2648 * @param linear If 1 then the used FIR filter will be linearly interpolated
2649 between the 2 closest, if 0 the closest will be used
2650 * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
2651 * @return allocated ReSampleContext, NULL if error occured
2652 */
2653ReSampleContext *av_audio_resample_init(int output_channels, int input_channels,
2654 int output_rate, int input_rate,
2655 enum SampleFormat sample_fmt_out,
2656 enum SampleFormat sample_fmt_in,
2657 int filter_length, int log2_phase_count,
2658 int linear, double cutoff);
2659
2660int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
2661void audio_resample_close(ReSampleContext *s);
2662
2663
2664/**
2665 * Initializes an audio resampler.
2666 * Note, if either rate is not an integer then simply scale both rates up so they are.
2667 * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq
2668 * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
2669 * @param linear If 1 then the used FIR filter will be linearly interpolated
2670 between the 2 closest, if 0 the closest will be used
2671 * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
2672 */
2673struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff);
2674
2675/**
2676 * resamples.
2677 * @param src an array of unconsumed samples
2678 * @param consumed the number of samples of src which have been consumed are returned here
2679 * @param src_size the number of unconsumed samples available
2680 * @param dst_size the amount of space in samples available in dst
2681 * @param update_ctx If this is 0 then the context will not be modified, that way several channels can be resampled with the same context.
2682 * @return the number of samples written in dst or -1 if an error occurred
2683 */
2684int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
2685
2686
2687/**
2688 * Compensates samplerate/timestamp drift. The compensation is done by changing
2689 * the resampler parameters, so no audible clicks or similar distortions occur
2690 * @param compensation_distance distance in output samples over which the compensation should be performed
2691 * @param sample_delta number of output samples which should be output less
2692 *
2693 * example: av_resample_compensate(c, 10, 500)
2694 * here instead of 510 samples only 500 samples would be output
2695 *
2696 * note, due to rounding the actual compensation might be slightly different,
2697 * especially if the compensation_distance is large and the in_rate used during init is small
2698 */
2699void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
2700void av_resample_close(struct AVResampleContext *c);
2701
2702/**
2703 * Allocate memory for a picture. Call avpicture_free to free it.
2704 *
2705 * @param picture the picture to be filled in
2706 * @param pix_fmt the format of the picture
2707 * @param width the width of the picture
2708 * @param height the height of the picture
2709 * @return zero if successful, a negative value if not
2710 */
2711int avpicture_alloc(AVPicture *picture, int pix_fmt, int width, int height);
2712
2713/**
2714 * Free a picture previously allocated by avpicture_alloc().
2715 *
2716 * @param picture the AVPicture to be freed
2717 */
2718void avpicture_free(AVPicture *picture);
2719
2720/**
2721 * Fill in the AVPicture fields.
2722 * The fields of the given AVPicture are filled in by using the 'ptr' address
2723 * which points to the image data buffer. Depending on the specified picture
2724 * format, one or multiple image data pointers and line sizes will be set.
2725 * If a planar format is specified, several pointers will be set pointing to
2726 * the different picture planes and the line sizes of the different planes
2727 * will be stored in the lines_sizes array.
2728 *
2729 * @param picture AVPicture whose fields are to be filled in
2730 * @param ptr Buffer which will contain or contains the actual image data
2731 * @param pix_fmt The format in which the picture data is stored.
2732 * @param width the width of the image in pixels
2733 * @param height the height of the image in pixels
2734 * @return size of the image data in bytes
2735 */
2736int avpicture_fill(AVPicture *picture, uint8_t *ptr,
2737 int pix_fmt, int width, int height);
2738int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
2739 unsigned char *dest, int dest_size);
2740
2741/**
2742 * Calculate the size in bytes that a picture of the given width and height
2743 * would occupy if stored in the given picture format.
2744 *
2745 * @param pix_fmt the given picture format
2746 * @param width the width of the image
2747 * @param height the height of the image
2748 * @return Image data size in bytes
2749 */
2750int avpicture_get_size(int pix_fmt, int width, int height);
2751void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
2752const char *avcodec_get_pix_fmt_name(int pix_fmt);
2753void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
2754enum PixelFormat avcodec_get_pix_fmt(const char* name);
2755unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat p);
2756
2757#define FF_LOSS_RESOLUTION 0x0001 /**< loss due to resolution change */
2758#define FF_LOSS_DEPTH 0x0002 /**< loss due to color depth change */
2759#define FF_LOSS_COLORSPACE 0x0004 /**< loss due to color space conversion */
2760#define FF_LOSS_ALPHA 0x0008 /**< loss of alpha bits */
2761#define FF_LOSS_COLORQUANT 0x0010 /**< loss due to color quantization */
2762#define FF_LOSS_CHROMA 0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */
2763
2764/**
2765 * Computes what kind of losses will occur when converting from one specific
2766 * pixel format to another.
2767 * When converting from one pixel format to another, information loss may occur.
2768 * For example, when converting from RGB24 to GRAY, the color information will
2769 * be lost. Similarly, other losses occur when converting from some formats to
2770 * other formats. These losses can involve loss of chroma, but also loss of
2771 * resolution, loss of color depth, loss due to the color space conversion, loss
2772 * of the alpha bits or loss due to color quantization.
2773 * avcodec_get_fix_fmt_loss() informs you about the various types of losses
2774 * which will occur when converting from one pixel format to another.
2775 *
2776 * @param[in] dst_pix_fmt destination pixel format
2777 * @param[in] src_pix_fmt source pixel format
2778 * @param[in] has_alpha Whether the source pixel format alpha channel is used.
2779 * @return Combination of flags informing you what kind of losses will occur.
2780 */
2781int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
2782 int has_alpha);
2783
2784/**
2785 * Finds the best pixel format to convert to given a certain source pixel
2786 * format. When converting from one pixel format to another, information loss
2787 * may occur. For example, when converting from RGB24 to GRAY, the color
2788 * information will be lost. Similarly, other losses occur when converting from
2789 * some formats to other formats. avcodec_find_best_pix_fmt() searches which of
2790 * the given pixel formats should be used to suffer the least amount of loss.
2791 * The pixel formats from which it chooses one, are determined by the
2792 * \p pix_fmt_mask parameter.
2793 *
2794 * @code
2795 * src_pix_fmt = PIX_FMT_YUV420P;
2796 * pix_fmt_mask = (1 << PIX_FMT_YUV422P) || (1 << PIX_FMT_RGB24);
2797 * dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss);
2798 * @endcode
2799 *
2800 * @param[in] pix_fmt_mask bitmask determining which pixel format to choose from
2801 * @param[in] src_pix_fmt source pixel format
2802 * @param[in] has_alpha Whether the source pixel format alpha channel is used.
2803 * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
2804 * @return The best pixel format to convert to or -1 if none was found.
2805 */
2806int avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, int src_pix_fmt,
2807 int has_alpha, int *loss_ptr);
2808
2809
2810/**
2811 * Print in buf the string corresponding to the pixel format with
2812 * number pix_fmt, or an header if pix_fmt is negative.
2813 *
2814 * @param[in] buf the buffer where to write the string
2815 * @param[in] buf_size the size of buf
2816 * @param[in] pix_fmt the number of the pixel format to print the corresponding info string, or
2817 * a negative value to print the corresponding header.
2818 * Meaningful values for obtaining a pixel format info vary from 0 to PIX_FMT_NB -1.
2819 */
2820void avcodec_pix_fmt_string (char *buf, int buf_size, int pix_fmt);
2821
2822#define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */
2823#define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */
2824
2825/**
2826 * Tell if an image really has transparent alpha values.
2827 * @return ored mask of FF_ALPHA_xxx constants
2828 */
2829int img_get_alpha_info(const AVPicture *src,
2830 int pix_fmt, int width, int height);
2831
2832/* deinterlace a picture */
2833/* deinterlace - if not supported return -1 */
2834int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
2835 int pix_fmt, int width, int height);
2836
2837/* external high level API */
2838
2839/**
2840 * If c is NULL, returns the first registered codec,
2841 * if c is non-NULL, returns the next registered codec after c,
2842 * or NULL if c is the last one.
2843 */
2844AVCodec *av_codec_next(AVCodec *c);
2845
2846/**
2847 * Returns the LIBAVCODEC_VERSION_INT constant.
2848 */
2849unsigned avcodec_version(void);
2850
2851/**
2852 * Initializes libavcodec.
2853 *
2854 * @warning This function \e must be called before any other libavcodec
2855 * function.
2856 */
2857void avcodec_init(void);
2858
2859#if LIBAVCODEC_VERSION_MAJOR < 53
2860/**
2861 * @deprecated Deprecated in favor of avcodec_register().
2862 */
2863attribute_deprecated void register_avcodec(AVCodec *codec);
2864#endif
2865
2866/**
2867 * Register the codec \p codec and initialize libavcodec.
2868 *
2869 * @see avcodec_init()
2870 */
2871void avcodec_register(AVCodec *codec);
2872
2873/**
2874 * Finds a registered encoder with a matching codec ID.
2875 *
2876 * @param id CodecID of the requested encoder
2877 * @return An encoder if one was found, NULL otherwise.
2878 */
2879AVCodec *avcodec_find_encoder(enum CodecID id);
2880
2881/**
2882 * Finds a registered encoder with the specified name.
2883 *
2884 * @param name name of the requested encoder
2885 * @return An encoder if one was found, NULL otherwise.
2886 */
2887AVCodec *avcodec_find_encoder_by_name(const char *name);
2888
2889/**
2890 * Finds a registered decoder with a matching codec ID.
2891 *
2892 * @param id CodecID of the requested decoder
2893 * @return A decoder if one was found, NULL otherwise.
2894 */
2895AVCodec *avcodec_find_decoder(enum CodecID id);
2896
2897/**
2898 * Finds a registered decoder with the specified name.
2899 *
2900 * @param name name of the requested decoder
2901 * @return A decoder if one was found, NULL otherwise.
2902 */
2903AVCodec *avcodec_find_decoder_by_name(const char *name);
2904void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
2905
2906/**
2907 * Sets the fields of the given AVCodecContext to default values.
2908 *
2909 * @param s The AVCodecContext of which the fields should be set to default values.
2910 */
2911void avcodec_get_context_defaults(AVCodecContext *s);
2912
2913/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
2914 * we WILL change its arguments and name a few times! */
2915void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType);
2916
2917/**
2918 * Allocates an AVCodecContext and sets its fields to default values. The
2919 * resulting struct can be deallocated by simply calling av_free().
2920 *
2921 * @return An AVCodecContext filled with default values or NULL on failure.
2922 * @see avcodec_get_context_defaults
2923 */
2924AVCodecContext *avcodec_alloc_context(void);
2925
2926/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
2927 * we WILL change its arguments and name a few times! */
2928AVCodecContext *avcodec_alloc_context2(enum CodecType);
2929
2930/**
2931 * Sets the fields of the given AVFrame to default values.
2932 *
2933 * @param pic The AVFrame of which the fields should be set to default values.
2934 */
2935void avcodec_get_frame_defaults(AVFrame *pic);
2936
2937/**
2938 * Allocates an AVFrame and sets its fields to default values. The resulting
2939 * struct can be deallocated by simply calling av_free().
2940 *
2941 * @return An AVFrame filled with default values or NULL on failure.
2942 * @see avcodec_get_frame_defaults
2943 */
2944AVFrame *avcodec_alloc_frame(void);
2945
2946int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
2947void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
2948int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
2949void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
2950
2951/**
2952 * Checks if the given dimension of a picture is valid, meaning that all
2953 * bytes of the picture can be addressed with a signed int.
2954 *
2955 * @param[in] w Width of the picture.
2956 * @param[in] h Height of the picture.
2957 * @return Zero if valid, a negative value if invalid.
2958 */
2959int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h);
2960enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt);
2961
2962int avcodec_thread_init(AVCodecContext *s, int thread_count);
2963void avcodec_thread_free(AVCodecContext *s);
2964int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
2965int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
2966//FIXME func typedef
2967
2968/**
2969 * Initializes the AVCodecContext to use the given AVCodec. Prior to using this
2970 * function the context has to be allocated.
2971 *
2972 * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
2973 * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
2974 * retrieving a codec.
2975 *
2976 * @warning This function is not thread safe!
2977 *
2978 * @code
2979 * avcodec_register_all();
2980 * codec = avcodec_find_decoder(CODEC_ID_H264);
2981 * if (!codec)
2982 * exit(1);
2983 *
2984 * context = avcodec_alloc_context();
2985 *
2986 * if (avcodec_open(context, codec) < 0)
2987 * exit(1);
2988 * @endcode
2989 *
2990 * @param avctx The context which will be set up to use the given codec.
2991 * @param codec The codec to use within the context.
2992 * @return zero on success, a negative value on error
2993 * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder
2994 */
2995int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
2996
2997/**
2998 * Decodes an audio frame from \p buf into \p samples.
2999 * The avcodec_decode_audio2() function decodes an audio frame from the input
3000 * buffer \p buf of size \p buf_size. To decode it, it makes use of the
3001 * audio codec which was coupled with \p avctx using avcodec_open(). The
3002 * resulting decoded frame is stored in output buffer \p samples. If no frame
3003 * could be decompressed, \p frame_size_ptr is zero. Otherwise, it is the
3004 * decompressed frame size in \e bytes.
3005 *
3006 * @warning You \e must set \p frame_size_ptr to the allocated size of the
3007 * output buffer before calling avcodec_decode_audio2().
3008 *
3009 * @warning The input buffer must be \c FF_INPUT_BUFFER_PADDING_SIZE larger than
3010 * the actual read bytes because some optimized bitstream readers read 32 or 64
3011 * bits at once and could read over the end.
3012 *
3013 * @warning The end of the input buffer \p buf should be set to 0 to ensure that
3014 * no overreading happens for damaged MPEG streams.
3015 *
3016 * @note You might have to align the input buffer \p buf and output buffer \p
3017 * samples. The alignment requirements depend on the CPU: On some CPUs it isn't
3018 * necessary at all, on others it won't work at all if not aligned and on others
3019 * it will work but it will have an impact on performance. In practice, the
3020 * bitstream should have 4 byte alignment at minimum and all sample data should
3021 * be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If
3022 * the linesize is not a multiple of 16 then there's no sense in aligning the
3023 * start of the buffer to 16.
3024 *
3025 * @param avctx the codec context
3026 * @param[out] samples the output buffer
3027 * @param[in,out] frame_size_ptr the output buffer size in bytes
3028 * @param[in] buf the input buffer
3029 * @param[in] buf_size the input buffer size in bytes
3030 * @return On error a negative value is returned, otherwise the number of bytes
3031 * used or zero if no frame could be decompressed.
3032 */
3033int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
3034 int *frame_size_ptr,
3035 const uint8_t *buf, int buf_size);
3036
3037/**
3038 * Decodes a video frame from \p buf into \p picture.
3039 * The avcodec_decode_video() function decodes a video frame from the input
3040 * buffer \p buf of size \p buf_size. To decode it, it makes use of the
3041 * video codec which was coupled with \p avctx using avcodec_open(). The
3042 * resulting decoded frame is stored in \p picture.
3043 *
3044 * @warning The input buffer must be \c FF_INPUT_BUFFER_PADDING_SIZE larger than
3045 * the actual read bytes because some optimized bitstream readers read 32 or 64
3046 * bits at once and could read over the end.
3047 *
3048 * @warning The end of the input buffer \p buf should be set to 0 to ensure that
3049 * no overreading happens for damaged MPEG streams.
3050 *
3051 * @note You might have to align the input buffer \p buf and output buffer \p
3052 * samples. The alignment requirements depend on the CPU: on some CPUs it isn't
3053 * necessary at all, on others it won't work at all if not aligned and on others
3054 * it will work but it will have an impact on performance. In practice, the
3055 * bitstream should have 4 byte alignment at minimum and all sample data should
3056 * be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If
3057 * the linesize is not a multiple of 16 then there's no sense in aligning the
3058 * start of the buffer to 16.
3059 *
3060 * @note Some codecs have a delay between input and output, these need to be
3061 * feeded with buf=NULL, buf_size=0 at the end to return the remaining frames.
3062 *
3063 * @param avctx the codec context
3064 * @param[out] picture The AVFrame in which the decoded video frame will be stored.
3065 * @param[in] buf the input buffer
3066 * @param[in] buf_size the size of the input buffer in bytes
3067 * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
3068 * @return On error a negative value is returned, otherwise the number of bytes
3069 * used or zero if no frame could be decompressed.
3070 */
3071int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
3072 int *got_picture_ptr,
3073 const uint8_t *buf, int buf_size);
3074
3075/* Decode a subtitle message. Return -1 if error, otherwise return the
3076 * number of bytes used. If no subtitle could be decompressed,
3077 * got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */
3078int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
3079 int *got_sub_ptr,
3080 const uint8_t *buf, int buf_size);
3081int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata,
3082 int *data_size_ptr,
3083 uint8_t *buf, int buf_size);
3084
3085/**
3086 * Encodes an audio frame from \p samples into \p buf.
3087 * The avcodec_encode_audio() function encodes an audio frame from the input
3088 * buffer \p samples. To encode it, it makes use of the audio codec which was
3089 * coupled with \p avctx using avcodec_open(). The resulting encoded frame is
3090 * stored in output buffer \p buf.
3091 *
3092 * @note The output buffer should be at least \c FF_MIN_BUFFER_SIZE bytes large.
3093 *
3094 * @param avctx the codec context
3095 * @param[out] buf the output buffer
3096 * @param[in] buf_size the output buffer size
3097 * @param[in] samples the input buffer containing the samples
3098 * The number of samples read from this buffer is frame_size*channels,
3099 * both of which are defined in \p avctx.
3100 * For PCM audio the number of samples read from \p samples is equal to
3101 * \p buf_size * input_sample_size / output_sample_size.
3102 * @return On error a negative value is returned, on success zero or the number
3103 * of bytes used to encode the data read from the input buffer.
3104 */
3105int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
3106 const short *samples);
3107
3108/**
3109 * Encodes a video frame from \p pict into \p buf.
3110 * The avcodec_encode_video() function encodes a video frame from the input
3111 * \p pict. To encode it, it makes use of the video codec which was coupled with
3112 * \p avctx using avcodec_open(). The resulting encoded bytes representing the
3113 * frame are stored in the output buffer \p buf. The input picture should be
3114 * stored using a specific format, namely \c avctx.pix_fmt.
3115 *
3116 * @param avctx the codec context
3117 * @param[out] buf the output buffer for the bitstream of encoded frame
3118 * @param[in] buf_size the size of the output buffer in bytes
3119 * @param[in] pict the input picture to encode
3120 * @return On error a negative value is returned, on success zero or the number
3121 * of bytes used from the output buffer.
3122 */
3123int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
3124 const AVFrame *pict);
3125int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
3126 const AVSubtitle *sub);
3127
3128int avcodec_close(AVCodecContext *avctx);
3129
3130/**
3131 * Register all the codecs, parsers and bitstream filters which were enabled at
3132 * configuration time. If you do not call this function you can select exactly
3133 * which formats you want to support, by using the individual registration
3134 * functions.
3135 *
3136 * @see avcodec_register
3137 * @see av_register_codec_parser
3138 * @see av_register_bitstream_filter
3139 */
3140void avcodec_register_all(void);
3141
3142/**
3143 * Flush buffers, should be called when seeking or when switching to a different stream.
3144 */
3145void avcodec_flush_buffers(AVCodecContext *avctx);
3146
3147void avcodec_default_free_buffers(AVCodecContext *s);
3148
3149/* misc useful functions */
3150
3151/**
3152 * Returns a single letter to describe the given picture type \p pict_type.
3153 *
3154 * @param[in] pict_type the picture type
3155 * @return A single character representing the picture type.
3156 */
3157char av_get_pict_type_char(int pict_type);
3158
3159/**
3160 * Returns codec bits per sample.
3161 *
3162 * @param[in] codec_id the codec
3163 * @return Number of bits per sample or zero if unknown for the given codec.
3164 */
3165int av_get_bits_per_sample(enum CodecID codec_id);
3166
3167/**
3168 * Returns sample format bits per sample.
3169 *
3170 * @param[in] sample_fmt the sample format
3171 * @return Number of bits per sample or zero if unknown for the given sample format.
3172 */
3173int av_get_bits_per_sample_format(enum SampleFormat sample_fmt);
3174
3175/* frame parsing */
3176typedef struct AVCodecParserContext {
3177 void *priv_data;
3178 struct AVCodecParser *parser;
3179 int64_t frame_offset; /* offset of the current frame */
3180 int64_t cur_offset; /* current offset
3181 (incremented by each av_parser_parse()) */
3182 int64_t next_frame_offset; /* offset of the next frame */
3183 /* video info */
3184 int pict_type; /* XXX: Put it back in AVCodecContext. */
3185 /**
3186 * This field is used for proper frame duration computation in lavf.
3187 * It signals, how much longer the frame duration of the current frame
3188 * is compared to normal frame duration.
3189 *
3190 * frame_duration = (1 + repeat_pict) * time_base
3191 *
3192 * It is used by codecs like H.264 to display telecined material.
3193 */
3194 int repeat_pict; /* XXX: Put it back in AVCodecContext. */
3195 int64_t pts; /* pts of the current frame */
3196 int64_t dts; /* dts of the current frame */
3197
3198 /* private data */
3199 int64_t last_pts;
3200 int64_t last_dts;
3201 int fetch_timestamp;
3202
3203#define AV_PARSER_PTS_NB 4
3204 int cur_frame_start_index;
3205 int64_t cur_frame_offset[AV_PARSER_PTS_NB];
3206 int64_t cur_frame_pts[AV_PARSER_PTS_NB];
3207 int64_t cur_frame_dts[AV_PARSER_PTS_NB];
3208
3209 int flags;
3210#define PARSER_FLAG_COMPLETE_FRAMES 0x0001
3211
3212 int64_t offset; ///< byte offset from starting packet start
3213 int64_t cur_frame_end[AV_PARSER_PTS_NB];
3214
3215 /*!
3216 * Set by parser to 1 for key frames and 0 for non-key frames.
3217 * It is initialized to -1, so if the parser doesn't set this flag,
3218 * old-style fallback using FF_I_TYPE picture type as key frames
3219 * will be used.
3220 */
3221 int key_frame;
3222
3223 /**
3224 * Time difference in stream time base units from the pts of this
3225 * packet to the point at which the output from the decoder has converged
3226 * independent from the availability of previous frames. That is, the
3227 * frames are virtually identical no matter if decoding started from
3228 * the very first frame or from this keyframe.
3229 * Is AV_NOPTS_VALUE if unknown.
3230 * This field is not the display duration of the current frame.
3231 *
3232 * The purpose of this field is to allow seeking in streams that have no
3233 * keyframes in the conventional sense. It corresponds to the
3234 * recovery point SEI in H.264 and match_time_delta in NUT. It is also
3235 * essential for some types of subtitle streams to ensure that all
3236 * subtitles are correctly displayed after seeking.
3237 */
3238 int64_t convergence_duration;
3239
3240 // Timestamp generation support:
3241 /**
3242 * Synchronization point for start of timestamp generation.
3243 *
3244 * Set to >0 for sync point, 0 for no sync point and <0 for undefined
3245 * (default).
3246 *
3247 * For example, this corresponds to presence of H.264 buffering period
3248 * SEI message.
3249 */
3250 int dts_sync_point;
3251
3252 /**
3253 * Offset of the current timestamp against last timestamp sync point in
3254 * units of AVCodecContext.time_base.
3255 *
3256 * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
3257 * contain a valid timestamp offset.
3258 *
3259 * Note that the timestamp of sync point has usually a nonzero
3260 * dts_ref_dts_delta, which refers to the previous sync point. Offset of
3261 * the next frame after timestamp sync point will be usually 1.
3262 *
3263 * For example, this corresponds to H.264 cpb_removal_delay.
3264 */
3265 int dts_ref_dts_delta;
3266
3267 /**
3268 * Presentation delay of current frame in units of AVCodecContext.time_base.
3269 *
3270 * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
3271 * contain valid non-negative timestamp delta (presentation time of a frame
3272 * must not lie in the past).
3273 *
3274 * This delay represents the difference between decoding and presentation
3275 * time of the frame.
3276 *
3277 * For example, this corresponds to H.264 dpb_output_delay.
3278 */
3279 int pts_dts_delta;
3280
3281 /**
3282 * Position of the packet in file.
3283 *
3284 * Analogous to cur_frame_pts/dts
3285 */
3286 int64_t cur_frame_pos[AV_PARSER_PTS_NB];
3287
3288 /**
3289 * Byte position of currently parsed frame in stream.
3290 */
3291 int64_t pos;
3292
3293 /**
3294 * Previous frame byte position.
3295 */
3296 int64_t last_pos;
3297} AVCodecParserContext;
3298
3299typedef struct AVCodecParser {
3300 int codec_ids[5]; /* several codec IDs are permitted */
3301 int priv_data_size;
3302 int (*parser_init)(AVCodecParserContext *s);
3303 int (*parser_parse)(AVCodecParserContext *s,
3304 AVCodecContext *avctx,
3305 const uint8_t **poutbuf, int *poutbuf_size,
3306 const uint8_t *buf, int buf_size);
3307 void (*parser_close)(AVCodecParserContext *s);
3308 int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
3309 struct AVCodecParser *next;
3310} AVCodecParser;
3311
3312AVCodecParser *av_parser_next(AVCodecParser *c);
3313
3314void av_register_codec_parser(AVCodecParser *parser);
3315AVCodecParserContext *av_parser_init(int codec_id);
3316
3317attribute_deprecated
3318int av_parser_parse(AVCodecParserContext *s,
3319 AVCodecContext *avctx,
3320 uint8_t **poutbuf, int *poutbuf_size,
3321 const uint8_t *buf, int buf_size,
3322 int64_t pts, int64_t dts);
3323
3324/**
3325 * Parse a packet.
3326 *
3327 * @param s parser context.
3328 * @param avctx codec context.
3329 * @param poutbuf set to pointer to parsed buffer or NULL if not yet finished.
3330 * @param poutbuf_size set to size of parsed buffer or zero if not yet finished.
3331 * @param buf input buffer.
3332 * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output).
3333 * @param pts input presentation timestamp.
3334 * @param dts input decoding timestamp.
3335 * @param pos input byte position in stream.
3336 * @return the number of bytes of the input bitstream used.
3337 *
3338 * Example:
3339 * @code
3340 * while(in_len){
3341 * len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
3342 * in_data, in_len,
3343 * pts, dts, pos);
3344 * in_data += len;
3345 * in_len -= len;
3346 *
3347 * if(size)
3348 * decode_frame(data, size);
3349 * }
3350 * @endcode
3351 */
3352int av_parser_parse2(AVCodecParserContext *s,
3353 AVCodecContext *avctx,
3354 uint8_t **poutbuf, int *poutbuf_size,
3355 const uint8_t *buf, int buf_size,
3356 int64_t pts, int64_t dts,
3357 int64_t pos);
3358
3359int av_parser_change(AVCodecParserContext *s,
3360 AVCodecContext *avctx,
3361 uint8_t **poutbuf, int *poutbuf_size,
3362 const uint8_t *buf, int buf_size, int keyframe);
3363void av_parser_close(AVCodecParserContext *s);
3364
3365
3366typedef struct AVBitStreamFilterContext {
3367 void *priv_data;
3368 struct AVBitStreamFilter *filter;
3369 AVCodecParserContext *parser;
3370 struct AVBitStreamFilterContext *next;
3371} AVBitStreamFilterContext;
3372
3373
3374typedef struct AVBitStreamFilter {
3375 const char *name;
3376 int priv_data_size;
3377 int (*filter)(AVBitStreamFilterContext *bsfc,
3378 AVCodecContext *avctx, const char *args,
3379 uint8_t **poutbuf, int *poutbuf_size,
3380 const uint8_t *buf, int buf_size, int keyframe);
3381 void (*close)(AVBitStreamFilterContext *bsfc);
3382 struct AVBitStreamFilter *next;
3383} AVBitStreamFilter;
3384
3385void av_register_bitstream_filter(AVBitStreamFilter *bsf);
3386AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
3387int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
3388 AVCodecContext *avctx, const char *args,
3389 uint8_t **poutbuf, int *poutbuf_size,
3390 const uint8_t *buf, int buf_size, int keyframe);
3391void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);
3392
3393AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f);
3394
3395/* memory */
3396
3397/**
3398 * Reallocates the given block if it is not large enough, otherwise it
3399 * does nothing.
3400 *
3401 * @see av_realloc
3402 */
3403void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
3404
3405/**
3406 * Copy image 'src' to 'dst'.
3407 */
3408void av_picture_copy(AVPicture *dst, const AVPicture *src,
3409 int pix_fmt, int width, int height);
3410
3411/**
3412 * Crop image top and left side.
3413 */
3414int av_picture_crop(AVPicture *dst, const AVPicture *src,
3415 int pix_fmt, int top_band, int left_band);
3416
3417/**
3418 * Pad image.
3419 */
3420int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, int pix_fmt,
3421 int padtop, int padbottom, int padleft, int padright, int *color);
3422
3423unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
3424
3425/**
3426 * Parses \p str and put in \p width_ptr and \p height_ptr the detected values.
3427 *
3428 * @return 0 in case of a successful parsing, a negative value otherwise
3429 * @param[in] str the string to parse: it has to be a string in the format
3430 * <width>x<height> or a valid video frame size abbreviation.
3431 * @param[in,out] width_ptr pointer to the variable which will contain the detected
3432 * frame width value
3433 * @param[in,out] height_ptr pointer to the variable which will contain the detected
3434 * frame height value
3435 */
3436int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str);
3437
3438/**
3439 * Parses \p str and put in \p frame_rate the detected values.
3440 *
3441 * @return 0 in case of a successful parsing, a negative value otherwise
3442 * @param[in] str the string to parse: it has to be a string in the format
3443 * <frame_rate_num>/<frame_rate_den>, a float number or a valid video rate abbreviation
3444 * @param[in,out] frame_rate pointer to the AVRational which will contain the detected
3445 * frame rate
3446 */
3447int av_parse_video_frame_rate(AVRational *frame_rate, const char *str);
3448
3449/* error handling */
3450#if EINVAL > 0
3451#define AVERROR(e) (-(e)) /**< Returns a negative error code from a POSIX error code, to return from library functions. */
3452#define AVUNERROR(e) (-(e)) /**< Returns a POSIX error code from a library function error return value. */
3453#else
3454/* Some platforms have E* and errno already negated. */
3455#define AVERROR(e) (e)
3456#define AVUNERROR(e) (e)
3457#endif
3458#define AVERROR_UNKNOWN AVERROR(EINVAL) /**< unknown error */
3459#define AVERROR_IO AVERROR(EIO) /**< I/O error */
3460#define AVERROR_NUMEXPECTED AVERROR(EDOM) /**< Number syntax expected in filename. */
3461#define AVERROR_INVALIDDATA AVERROR(EINVAL) /**< invalid data found */
3462#define AVERROR_NOMEM AVERROR(ENOMEM) /**< not enough memory */
3463#define AVERROR_NOFMT AVERROR(EILSEQ) /**< unknown format */
3464#define AVERROR_NOTSUPP AVERROR(ENOSYS) /**< Operation not supported. */
3465#define AVERROR_NOENT AVERROR(ENOENT) /**< No such file or directory. */
3466#define AVERROR_EOF AVERROR(EPIPE) /**< End of file. */
3467#define AVERROR_PATCHWELCOME -MKTAG('P','A','W','E') /**< Not yet implemented in FFmpeg. Patches welcome. */
3468
3469/**
3470 * Registers the hardware accelerator \p hwaccel.
3471 */
3472void av_register_hwaccel(AVHWAccel *hwaccel);
3473
3474/**
3475 * If hwaccel is NULL, returns the first registered hardware accelerator,
3476 * if hwaccel is non-NULL, returns the next registered hardware accelerator
3477 * after hwaccel, or NULL if hwaccel is the last one.
3478 */
3479AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel);
3480#endif /* MT : DELETE THIS LINE ONLY. */
3481#endif /* AVCODEC_AVCODEC_H */
diff --git a/apps/codecs/libwmapro/avfft.h b/apps/codecs/libwmapro/avfft.h
new file mode 100644
index 0000000000..623f0a33b5
--- /dev/null
+++ b/apps/codecs/libwmapro/avfft.h
@@ -0,0 +1,99 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVCODEC_AVFFT_H
20#define AVCODEC_AVFFT_H
21
22typedef float FFTSample;
23
24typedef struct FFTComplex {
25 FFTSample re, im;
26} FFTComplex;
27
28typedef struct FFTContext FFTContext;
29
30/**
31 * Set up a complex FFT.
32 * @param nbits log2 of the length of the input array
33 * @param inverse if 0 perform the forward transform, if 1 perform the inverse
34 */
35FFTContext *av_fft_init(int nbits, int inverse);
36
37/**
38 * Do the permutation needed BEFORE calling ff_fft_calc().
39 */
40void av_fft_permute(FFTContext *s, FFTComplex *z);
41
42/**
43 * Do a complex FFT with the parameters defined in av_fft_init(). The
44 * input data must be permuted before. No 1.0/sqrt(n) normalization is done.
45 */
46void av_fft_calc(FFTContext *s, FFTComplex *z);
47
48void av_fft_end(FFTContext *s);
49
50FFTContext *av_mdct_init(int nbits, int inverse, double scale);
51void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input);
52void av_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input);
53void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input);
54void av_mdct_end(FFTContext *s);
55
56/* Real Discrete Fourier Transform */
57
58enum RDFTransformType {
59 DFT_R2C,
60 IDFT_C2R,
61 IDFT_R2C,
62 DFT_C2R,
63};
64
65typedef struct RDFTContext RDFTContext;
66
67/**
68 * Set up a real FFT.
69 * @param nbits log2 of the length of the input array
70 * @param trans the type of transform
71 */
72RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans);
73void av_rdft_calc(RDFTContext *s, FFTSample *data);
74void av_rdft_end(RDFTContext *s);
75
76/* Discrete Cosine Transform */
77
78typedef struct DCTContext DCTContext;
79
80enum DCTTransformType {
81 DCT_II = 0,
82 DCT_III,
83 DCT_I,
84 DST_I,
85};
86
87/**
88 * Sets up DCT.
89 * @param nbits size of the input array:
90 * (1 << nbits) for DCT-II, DCT-III and DST-I
91 * (1 << nbits) + 1 for DCT-I
92 *
93 * @note the first element of the input of DST-I is ignored
94 */
95DCTContext *av_dct_init(int nbits, enum DCTTransformType type);
96void av_dct_calc(DCTContext *s, FFTSample *data);
97void av_dct_end (DCTContext *s);
98
99#endif /* AVCODEC_AVFFT_H */
diff --git a/apps/codecs/libwmapro/bitstream.c b/apps/codecs/libwmapro/bitstream.c
new file mode 100644
index 0000000000..a149ff0289
--- /dev/null
+++ b/apps/codecs/libwmapro/bitstream.c
@@ -0,0 +1,338 @@
1/*
2 * Common bit i/o utils
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 * Copyright (c) 2010 Loren Merritt
6 *
7 * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at>
8 *
9 * This file is part of FFmpeg.
10 *
11 * FFmpeg is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * FFmpeg is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with FFmpeg; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26/**
27 * @file libavcodec/bitstream.c
28 * bitstream api.
29 */
30
31#include "avcodec.h"
32#include "get_bits.h"
33#include "put_bits.h"
34
35#define CONFIG_SMALL 0 // added to make it compile
36
37const uint8_t ff_log2_run[32]={
38 0, 0, 0, 0, 1, 1, 1, 1,
39 2, 2, 2, 2, 3, 3, 3, 3,
40 4, 4, 5, 5, 6, 6, 7, 7,
41 8, 9,10,11,12,13,14,15
42};
43
44void align_put_bits(PutBitContext *s)
45{
46#ifdef ALT_BITSTREAM_WRITER
47 put_bits(s,( - s->index) & 7,0);
48#else
49 put_bits(s,s->bit_left & 7,0);
50#endif
51}
52
53void ff_put_string(PutBitContext *pb, const char *string, int terminate_string)
54{
55 while(*string){
56 put_bits(pb, 8, *string);
57 string++;
58 }
59 if(terminate_string)
60 put_bits(pb, 8, 0);
61}
62
63void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
64{
65 int words= length>>4;
66 int bits= length&15;
67 int i;
68
69 if(length==0) return;
70
71 if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){
72 for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(src + 2*i));
73 }else{
74 for(i=0; put_bits_count(pb)&31; i++)
75 put_bits(pb, 8, src[i]);
76 flush_put_bits(pb);
77 memcpy(put_bits_ptr(pb), src+i, 2*words-i);
78 skip_put_bytes(pb, 2*words-i);
79 }
80
81 put_bits(pb, bits, AV_RB16(src + 2*words)>>(16-bits));
82}
83
84/* VLC decoding */
85
86//#define DEBUG_VLC
87
88#define GET_DATA(v, table, i, wrap, size) \
89{\
90 const uint8_t *ptr = (const uint8_t *)table + i * wrap;\
91 switch(size) {\
92 case 1:\
93 v = *(const uint8_t *)ptr;\
94 break;\
95 case 2:\
96 v = *(const uint16_t *)ptr;\
97 break;\
98 default:\
99 v = *(const uint32_t *)ptr;\
100 break;\
101 }\
102}
103
104
105static int alloc_table(VLC *vlc, int size, int use_static)
106{
107 int index;
108 index = vlc->table_size;
109 vlc->table_size += size;
110 if (vlc->table_size > vlc->table_allocated) {
111 if(use_static)
112 abort(); //cant do anything, init_vlc() is used with too little memory
113 vlc->table_allocated += (1 << vlc->bits);
114 vlc->table = av_realloc(vlc->table,
115 sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
116 if (!vlc->table)
117 return -1;
118 }
119 return index;
120}
121
122static av_always_inline uint32_t bitswap_32(uint32_t x) {
123 return av_reverse[x&0xFF]<<24
124 | av_reverse[(x>>8)&0xFF]<<16
125 | av_reverse[(x>>16)&0xFF]<<8
126 | av_reverse[x>>24];
127}
128
129typedef struct {
130 uint8_t bits;
131 uint16_t symbol;
132 /** codeword, with the first bit-to-be-read in the msb
133 * (even if intended for a little-endian bitstream reader) */
134 uint32_t code;
135} VLCcode;
136
137static int compare_vlcspec(const void *a, const void *b)
138{
139 const VLCcode *sa=a, *sb=b;
140 return (sa->code >> 1) - (sb->code >> 1);
141}
142
143/**
144 * Build VLC decoding tables suitable for use with get_vlc().
145 *
146 * @param vlc the context to be initted
147 *
148 * @param table_nb_bits max length of vlc codes to store directly in this table
149 * (Longer codes are delegated to subtables.)
150 *
151 * @param nb_codes number of elements in codes[]
152 *
153 * @param codes descriptions of the vlc codes
154 * These must be ordered such that codes going into the same subtable are contiguous.
155 * Sorting by VLCcode.code is sufficient, though not necessary.
156 */
157static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
158 VLCcode *codes, int flags)
159{
160 int table_size, table_index, index, code_prefix, symbol, subtable_bits;
161 int i, j, k, n, nb, inc;
162 uint32_t code;
163 VLC_TYPE (*table)[2];
164
165 table_size = 1 << table_nb_bits;
166 table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC);
167#ifdef DEBUG_VLC
168 av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d\n",
169 table_index, table_size);
170#endif
171 if (table_index < 0)
172 return -1;
173 table = &vlc->table[table_index];
174
175 for (i = 0; i < table_size; i++) {
176 table[i][1] = 0; //bits
177 table[i][0] = -1; //codes
178 }
179
180 /* first pass: map codes and compute auxillary table sizes */
181 for (i = 0; i < nb_codes; i++) {
182 n = codes[i].bits;
183 code = codes[i].code;
184 symbol = codes[i].symbol;
185#if defined(DEBUG_VLC) && 0
186 av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code);
187#endif
188 if (n <= table_nb_bits) {
189 /* no need to add another table */
190 j = code >> (32 - table_nb_bits);
191 nb = 1 << (table_nb_bits - n);
192 inc = 1;
193 if (flags & INIT_VLC_LE) {
194 j = bitswap_32(code);
195 inc = 1 << n;
196 }
197 for (k = 0; k < nb; k++) {
198#ifdef DEBUG_VLC
199 av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n",
200 j, i, n);
201#endif
202 if (table[j][1] /*bits*/ != 0) {
203 av_log(NULL, AV_LOG_ERROR, "incorrect codes\n");
204 return -1;
205 }
206 table[j][1] = n; //bits
207 table[j][0] = symbol;
208 j += inc;
209 }
210 } else {
211 /* fill auxiliary table recursively */
212 n -= table_nb_bits;
213 code_prefix = code >> (32 - table_nb_bits);
214 subtable_bits = n;
215 codes[i].bits = n;
216 codes[i].code = code << table_nb_bits;
217 for (k = i+1; k < nb_codes; k++) {
218 n = codes[k].bits - table_nb_bits;
219 if (n <= 0)
220 break;
221 code = codes[k].code;
222 if (code >> (32 - table_nb_bits) != code_prefix)
223 break;
224 codes[k].bits = n;
225 codes[k].code = code << table_nb_bits;
226 subtable_bits = FFMAX(subtable_bits, n);
227 }
228 subtable_bits = FFMIN(subtable_bits, table_nb_bits);
229 j = (flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix;
230 table[j][1] = -subtable_bits;
231#ifdef DEBUG_VLC
232 av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n",
233 j, codes[i].bits + table_nb_bits);
234#endif
235 index = build_table(vlc, subtable_bits, k-i, codes+i, flags);
236 if (index < 0)
237 return -1;
238 /* note: realloc has been done, so reload tables */
239 table = &vlc->table[table_index];
240 table[j][0] = index; //code
241 i = k-1;
242 }
243 }
244 return table_index;
245}
246
247
248/* Build VLC decoding tables suitable for use with get_vlc().
249
250 'nb_bits' set thee decoding table size (2^nb_bits) entries. The
251 bigger it is, the faster is the decoding. But it should not be too
252 big to save memory and L1 cache. '9' is a good compromise.
253
254 'nb_codes' : number of vlcs codes
255
256 'bits' : table which gives the size (in bits) of each vlc code.
257
258 'codes' : table which gives the bit pattern of of each vlc code.
259
260 'symbols' : table which gives the values to be returned from get_vlc().
261
262 'xxx_wrap' : give the number of bytes between each entry of the
263 'bits' or 'codes' tables.
264
265 'xxx_size' : gives the number of bytes of each entry of the 'bits'
266 or 'codes' tables.
267
268 'wrap' and 'size' allows to use any memory configuration and types
269 (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables.
270
271 'use_static' should be set to 1 for tables, which should be freed
272 with av_free_static(), 0 if free_vlc() will be used.
273*/
274int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
275 const void *bits, int bits_wrap, int bits_size,
276 const void *codes, int codes_wrap, int codes_size,
277 const void *symbols, int symbols_wrap, int symbols_size,
278 int flags)
279{
280 VLCcode buf[nb_codes];
281 int i, j;
282
283 vlc->bits = nb_bits;
284 if(flags & INIT_VLC_USE_NEW_STATIC){
285 if(vlc->table_size && vlc->table_size == vlc->table_allocated){
286 return 0;
287 }else if(vlc->table_size){
288 abort(); // fatal error, we are called on a partially initialized table
289 }
290 }else {
291 vlc->table = NULL;
292 vlc->table_allocated = 0;
293 vlc->table_size = 0;
294 }
295
296#ifdef DEBUG_VLC
297 av_log(NULL,AV_LOG_DEBUG,"build table nb_codes=%d\n", nb_codes);
298#endif
299
300 assert(symbols_size <= 2 || !symbols);
301 j = 0;
302#define COPY(condition)\
303 for (i = 0; i < nb_codes; i++) {\
304 GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size);\
305 if (!(condition))\
306 continue;\
307 GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size);\
308 if (flags & INIT_VLC_LE)\
309 buf[j].code = bitswap_32(buf[j].code);\
310 else\
311 buf[j].code <<= 32 - buf[j].bits;\
312 if (symbols)\
313 GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size)\
314 else\
315 buf[j].symbol = i;\
316 j++;\
317 }
318 COPY(buf[j].bits > nb_bits);
319 // qsort is the slowest part of init_vlc, and could probably be improved or avoided
320 qsort(buf, j, sizeof(VLCcode), compare_vlcspec);
321 COPY(buf[j].bits && buf[j].bits <= nb_bits);
322 nb_codes = j;
323
324 if (build_table(vlc, nb_bits, nb_codes, buf, flags) < 0) {
325 av_freep(&vlc->table);
326 return -1;
327 }
328 if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size != vlc->table_allocated)
329 av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated);
330 return 0;
331}
332
333
334void free_vlc(VLC *vlc)
335{
336 av_freep(&vlc->table);
337}
338
diff --git a/apps/codecs/libwmapro/dsputil.c b/apps/codecs/libwmapro/dsputil.c
new file mode 100644
index 0000000000..b09311925a
--- /dev/null
+++ b/apps/codecs/libwmapro/dsputil.c
@@ -0,0 +1,4572 @@
1/*
2 * DSP utils
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25/**
26 * @file libavcodec/dsputil.c
27 * DSP utils
28 */
29
30#include "avcodec.h"
31#include "dsputil.h"
32//#include "simple_idct.h"
33//#include "faandct.h"
34//#include "faanidct.h"
35#include "mathops.h"
36//#include "mpegvideo.h"
37//#include "config.h"
38//#include "lpc.h"
39//#include "ac3dec.h"
40//#include "vorbis.h"
41//#include "png.h"
42
43#if 0
44uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, };
45uint32_t ff_squareTbl[512] = {0, };
46
47// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
48#define pb_7f (~0UL/255 * 0x7f)
49#define pb_80 (~0UL/255 * 0x80)
50
51const uint8_t ff_zigzag_direct[64] = {
52 0, 1, 8, 16, 9, 2, 3, 10,
53 17, 24, 32, 25, 18, 11, 4, 5,
54 12, 19, 26, 33, 40, 48, 41, 34,
55 27, 20, 13, 6, 7, 14, 21, 28,
56 35, 42, 49, 56, 57, 50, 43, 36,
57 29, 22, 15, 23, 30, 37, 44, 51,
58 58, 59, 52, 45, 38, 31, 39, 46,
59 53, 60, 61, 54, 47, 55, 62, 63
60};
61
62/* Specific zigzag scan for 248 idct. NOTE that unlike the
63 specification, we interleave the fields */
64const uint8_t ff_zigzag248_direct[64] = {
65 0, 8, 1, 9, 16, 24, 2, 10,
66 17, 25, 32, 40, 48, 56, 33, 41,
67 18, 26, 3, 11, 4, 12, 19, 27,
68 34, 42, 49, 57, 50, 58, 35, 43,
69 20, 28, 5, 13, 6, 14, 21, 29,
70 36, 44, 51, 59, 52, 60, 37, 45,
71 22, 30, 7, 15, 23, 31, 38, 46,
72 53, 61, 54, 62, 39, 47, 55, 63,
73};
74
75/* not permutated inverse zigzag_direct + 1 for MMX quantizer */
76DECLARE_ALIGNED(16, uint16_t, inv_zigzag_direct16)[64];
77
78const uint8_t ff_alternate_horizontal_scan[64] = {
79 0, 1, 2, 3, 8, 9, 16, 17,
80 10, 11, 4, 5, 6, 7, 15, 14,
81 13, 12, 19, 18, 24, 25, 32, 33,
82 26, 27, 20, 21, 22, 23, 28, 29,
83 30, 31, 34, 35, 40, 41, 48, 49,
84 42, 43, 36, 37, 38, 39, 44, 45,
85 46, 47, 50, 51, 56, 57, 58, 59,
86 52, 53, 54, 55, 60, 61, 62, 63,
87};
88
89const uint8_t ff_alternate_vertical_scan[64] = {
90 0, 8, 16, 24, 1, 9, 2, 10,
91 17, 25, 32, 40, 48, 56, 57, 49,
92 41, 33, 26, 18, 3, 11, 4, 12,
93 19, 27, 34, 42, 50, 58, 35, 43,
94 51, 59, 20, 28, 5, 13, 6, 14,
95 21, 29, 36, 44, 52, 60, 37, 45,
96 53, 61, 22, 30, 7, 15, 23, 31,
97 38, 46, 54, 62, 39, 47, 55, 63,
98};
99
100/* a*inverse[b]>>32 == a/b for all 0<=a<=16909558 && 2<=b<=256
101 * for a>16909558, is an overestimate by less than 1 part in 1<<24 */
102const uint32_t ff_inverse[257]={
103 0, 4294967295U,2147483648U,1431655766, 1073741824, 858993460, 715827883, 613566757,
104 536870912, 477218589, 429496730, 390451573, 357913942, 330382100, 306783379, 286331154,
105 268435456, 252645136, 238609295, 226050911, 214748365, 204522253, 195225787, 186737709,
106 178956971, 171798692, 165191050, 159072863, 153391690, 148102321, 143165577, 138547333,
107 134217728, 130150525, 126322568, 122713352, 119304648, 116080198, 113025456, 110127367,
108 107374183, 104755300, 102261127, 99882961, 97612894, 95443718, 93368855, 91382283,
109 89478486, 87652394, 85899346, 84215046, 82595525, 81037119, 79536432, 78090315,
110 76695845, 75350304, 74051161, 72796056, 71582789, 70409300, 69273667, 68174085,
111 67108864, 66076420, 65075263, 64103990, 63161284, 62245903, 61356676, 60492498,
112 59652324, 58835169, 58040099, 57266231, 56512728, 55778797, 55063684, 54366675,
113 53687092, 53024288, 52377650, 51746594, 51130564, 50529028, 49941481, 49367441,
114 48806447, 48258060, 47721859, 47197443, 46684428, 46182445, 45691142, 45210183,
115 44739243, 44278014, 43826197, 43383509, 42949673, 42524429, 42107523, 41698712,
116 41297763, 40904451, 40518560, 40139882, 39768216, 39403370, 39045158, 38693400,
117 38347923, 38008561, 37675152, 37347542, 37025581, 36709123, 36398028, 36092163,
118 35791395, 35495598, 35204650, 34918434, 34636834, 34359739, 34087043, 33818641,
119 33554432, 33294321, 33038210, 32786010, 32537632, 32292988, 32051995, 31814573,
120 31580642, 31350127, 31122952, 30899046, 30678338, 30460761, 30246249, 30034737,
121 29826162, 29620465, 29417585, 29217465, 29020050, 28825284, 28633116, 28443493,
122 28256364, 28071682, 27889399, 27709467, 27531842, 27356480, 27183338, 27012373,
123 26843546, 26676816, 26512144, 26349493, 26188825, 26030105, 25873297, 25718368,
124 25565282, 25414008, 25264514, 25116768, 24970741, 24826401, 24683721, 24542671,
125 24403224, 24265352, 24129030, 23994231, 23860930, 23729102, 23598722, 23469767,
126 23342214, 23216040, 23091223, 22967740, 22845571, 22724695, 22605092, 22486740,
127 22369622, 22253717, 22139007, 22025474, 21913099, 21801865, 21691755, 21582751,
128 21474837, 21367997, 21262215, 21157475, 21053762, 20951060, 20849356, 20748635,
129 20648882, 20550083, 20452226, 20355296, 20259280, 20164166, 20069941, 19976593,
130 19884108, 19792477, 19701685, 19611723, 19522579, 19434242, 19346700, 19259944,
131 19173962, 19088744, 19004281, 18920561, 18837576, 18755316, 18673771, 18592933,
132 18512791, 18433337, 18354562, 18276457, 18199014, 18122225, 18046082, 17970575,
133 17895698, 17821442, 17747799, 17674763, 17602325, 17530479, 17459217, 17388532,
134 17318417, 17248865, 17179870, 17111424, 17043522, 16976156, 16909321, 16843010,
135 16777216
136};
137
138/* Input permutation for the simple_idct_mmx */
139static const uint8_t simple_mmx_permutation[64]={
140 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
141 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
142 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
143 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
144 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
145 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
146 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
147 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
148};
149
150static const uint8_t idct_sse2_row_perm[8] = {0, 4, 1, 5, 2, 6, 3, 7};
151
152void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){
153 int i;
154 int end;
155
156 st->scantable= src_scantable;
157
158 for(i=0; i<64; i++){
159 int j;
160 j = src_scantable[i];
161 st->permutated[i] = permutation[j];
162#if ARCH_PPC
163 st->inverse[j] = i;
164#endif
165 }
166
167 end=-1;
168 for(i=0; i<64; i++){
169 int j;
170 j = st->permutated[i];
171 if(j>end) end=j;
172 st->raster_end[i]= end;
173 }
174}
175
176static int pix_sum_c(uint8_t * pix, int line_size)
177{
178 int s, i, j;
179
180 s = 0;
181 for (i = 0; i < 16; i++) {
182 for (j = 0; j < 16; j += 8) {
183 s += pix[0];
184 s += pix[1];
185 s += pix[2];
186 s += pix[3];
187 s += pix[4];
188 s += pix[5];
189 s += pix[6];
190 s += pix[7];
191 pix += 8;
192 }
193 pix += line_size - 16;
194 }
195 return s;
196}
197
198static int pix_norm1_c(uint8_t * pix, int line_size)
199{
200 int s, i, j;
201 uint32_t *sq = ff_squareTbl + 256;
202
203 s = 0;
204 for (i = 0; i < 16; i++) {
205 for (j = 0; j < 16; j += 8) {
206#if 0
207 s += sq[pix[0]];
208 s += sq[pix[1]];
209 s += sq[pix[2]];
210 s += sq[pix[3]];
211 s += sq[pix[4]];
212 s += sq[pix[5]];
213 s += sq[pix[6]];
214 s += sq[pix[7]];
215#else
216#if LONG_MAX > 2147483647
217 register uint64_t x=*(uint64_t*)pix;
218 s += sq[x&0xff];
219 s += sq[(x>>8)&0xff];
220 s += sq[(x>>16)&0xff];
221 s += sq[(x>>24)&0xff];
222 s += sq[(x>>32)&0xff];
223 s += sq[(x>>40)&0xff];
224 s += sq[(x>>48)&0xff];
225 s += sq[(x>>56)&0xff];
226#else
227 register uint32_t x=*(uint32_t*)pix;
228 s += sq[x&0xff];
229 s += sq[(x>>8)&0xff];
230 s += sq[(x>>16)&0xff];
231 s += sq[(x>>24)&0xff];
232 x=*(uint32_t*)(pix+4);
233 s += sq[x&0xff];
234 s += sq[(x>>8)&0xff];
235 s += sq[(x>>16)&0xff];
236 s += sq[(x>>24)&0xff];
237#endif
238#endif
239 pix += 8;
240 }
241 pix += line_size - 16;
242 }
243 return s;
244}
245
246static void bswap_buf(uint32_t *dst, const uint32_t *src, int w){
247 int i;
248
249 for(i=0; i+8<=w; i+=8){
250 dst[i+0]= bswap_32(src[i+0]);
251 dst[i+1]= bswap_32(src[i+1]);
252 dst[i+2]= bswap_32(src[i+2]);
253 dst[i+3]= bswap_32(src[i+3]);
254 dst[i+4]= bswap_32(src[i+4]);
255 dst[i+5]= bswap_32(src[i+5]);
256 dst[i+6]= bswap_32(src[i+6]);
257 dst[i+7]= bswap_32(src[i+7]);
258 }
259 for(;i<w; i++){
260 dst[i+0]= bswap_32(src[i+0]);
261 }
262}
263
264static int sse4_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
265{
266 int s, i;
267 uint32_t *sq = ff_squareTbl + 256;
268
269 s = 0;
270 for (i = 0; i < h; i++) {
271 s += sq[pix1[0] - pix2[0]];
272 s += sq[pix1[1] - pix2[1]];
273 s += sq[pix1[2] - pix2[2]];
274 s += sq[pix1[3] - pix2[3]];
275 pix1 += line_size;
276 pix2 += line_size;
277 }
278 return s;
279}
280
281static int sse8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
282{
283 int s, i;
284 uint32_t *sq = ff_squareTbl + 256;
285
286 s = 0;
287 for (i = 0; i < h; i++) {
288 s += sq[pix1[0] - pix2[0]];
289 s += sq[pix1[1] - pix2[1]];
290 s += sq[pix1[2] - pix2[2]];
291 s += sq[pix1[3] - pix2[3]];
292 s += sq[pix1[4] - pix2[4]];
293 s += sq[pix1[5] - pix2[5]];
294 s += sq[pix1[6] - pix2[6]];
295 s += sq[pix1[7] - pix2[7]];
296 pix1 += line_size;
297 pix2 += line_size;
298 }
299 return s;
300}
301
302static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
303{
304 int s, i;
305 uint32_t *sq = ff_squareTbl + 256;
306
307 s = 0;
308 for (i = 0; i < h; i++) {
309 s += sq[pix1[ 0] - pix2[ 0]];
310 s += sq[pix1[ 1] - pix2[ 1]];
311 s += sq[pix1[ 2] - pix2[ 2]];
312 s += sq[pix1[ 3] - pix2[ 3]];
313 s += sq[pix1[ 4] - pix2[ 4]];
314 s += sq[pix1[ 5] - pix2[ 5]];
315 s += sq[pix1[ 6] - pix2[ 6]];
316 s += sq[pix1[ 7] - pix2[ 7]];
317 s += sq[pix1[ 8] - pix2[ 8]];
318 s += sq[pix1[ 9] - pix2[ 9]];
319 s += sq[pix1[10] - pix2[10]];
320 s += sq[pix1[11] - pix2[11]];
321 s += sq[pix1[12] - pix2[12]];
322 s += sq[pix1[13] - pix2[13]];
323 s += sq[pix1[14] - pix2[14]];
324 s += sq[pix1[15] - pix2[15]];
325
326 pix1 += line_size;
327 pix2 += line_size;
328 }
329 return s;
330}
331
332/* draw the edges of width 'w' of an image of size width, height */
333//FIXME check that this is ok for mpeg4 interlaced
334static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w)
335{
336 uint8_t *ptr, *last_line;
337 int i;
338
339 last_line = buf + (height - 1) * wrap;
340 for(i=0;i<w;i++) {
341 /* top and bottom */
342 memcpy(buf - (i + 1) * wrap, buf, width);
343 memcpy(last_line + (i + 1) * wrap, last_line, width);
344 }
345 /* left and right */
346 ptr = buf;
347 for(i=0;i<height;i++) {
348 memset(ptr - w, ptr[0], w);
349 memset(ptr + width, ptr[width-1], w);
350 ptr += wrap;
351 }
352 /* corners */
353 for(i=0;i<w;i++) {
354 memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */
355 memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */
356 memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */
357 memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */
358 }
359}
360
361/**
362 * Copies a rectangular area of samples to a temporary buffer and replicates the boarder samples.
363 * @param buf destination buffer
364 * @param src source buffer
365 * @param linesize number of bytes between 2 vertically adjacent samples in both the source and destination buffers
366 * @param block_w width of block
367 * @param block_h height of block
368 * @param src_x x coordinate of the top left sample of the block in the source buffer
369 * @param src_y y coordinate of the top left sample of the block in the source buffer
370 * @param w width of the source buffer
371 * @param h height of the source buffer
372 */
373void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, int block_h,
374 int src_x, int src_y, int w, int h){
375 int x, y;
376 int start_y, start_x, end_y, end_x;
377
378 if(src_y>= h){
379 src+= (h-1-src_y)*linesize;
380 src_y=h-1;
381 }else if(src_y<=-block_h){
382 src+= (1-block_h-src_y)*linesize;
383 src_y=1-block_h;
384 }
385 if(src_x>= w){
386 src+= (w-1-src_x);
387 src_x=w-1;
388 }else if(src_x<=-block_w){
389 src+= (1-block_w-src_x);
390 src_x=1-block_w;
391 }
392
393 start_y= FFMAX(0, -src_y);
394 start_x= FFMAX(0, -src_x);
395 end_y= FFMIN(block_h, h-src_y);
396 end_x= FFMIN(block_w, w-src_x);
397
398 // copy existing part
399 for(y=start_y; y<end_y; y++){
400 for(x=start_x; x<end_x; x++){
401 buf[x + y*linesize]= src[x + y*linesize];
402 }
403 }
404
405 //top
406 for(y=0; y<start_y; y++){
407 for(x=start_x; x<end_x; x++){
408 buf[x + y*linesize]= buf[x + start_y*linesize];
409 }
410 }
411
412 //bottom
413 for(y=end_y; y<block_h; y++){
414 for(x=start_x; x<end_x; x++){
415 buf[x + y*linesize]= buf[x + (end_y-1)*linesize];
416 }
417 }
418
419 for(y=0; y<block_h; y++){
420 //left
421 for(x=0; x<start_x; x++){
422 buf[x + y*linesize]= buf[start_x + y*linesize];
423 }
424
425 //right
426 for(x=end_x; x<block_w; x++){
427 buf[x + y*linesize]= buf[end_x - 1 + y*linesize];
428 }
429 }
430}
431
432static void get_pixels_c(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
433{
434 int i;
435
436 /* read the pixels */
437 for(i=0;i<8;i++) {
438 block[0] = pixels[0];
439 block[1] = pixels[1];
440 block[2] = pixels[2];
441 block[3] = pixels[3];
442 block[4] = pixels[4];
443 block[5] = pixels[5];
444 block[6] = pixels[6];
445 block[7] = pixels[7];
446 pixels += line_size;
447 block += 8;
448 }
449}
450
451static void diff_pixels_c(DCTELEM *restrict block, const uint8_t *s1,
452 const uint8_t *s2, int stride){
453 int i;
454
455 /* read the pixels */
456 for(i=0;i<8;i++) {
457 block[0] = s1[0] - s2[0];
458 block[1] = s1[1] - s2[1];
459 block[2] = s1[2] - s2[2];
460 block[3] = s1[3] - s2[3];
461 block[4] = s1[4] - s2[4];
462 block[5] = s1[5] - s2[5];
463 block[6] = s1[6] - s2[6];
464 block[7] = s1[7] - s2[7];
465 s1 += stride;
466 s2 += stride;
467 block += 8;
468 }
469}
470
471
472static void put_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
473 int line_size)
474{
475 int i;
476 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
477
478 /* read the pixels */
479 for(i=0;i<8;i++) {
480 pixels[0] = cm[block[0]];
481 pixels[1] = cm[block[1]];
482 pixels[2] = cm[block[2]];
483 pixels[3] = cm[block[3]];
484 pixels[4] = cm[block[4]];
485 pixels[5] = cm[block[5]];
486 pixels[6] = cm[block[6]];
487 pixels[7] = cm[block[7]];
488
489 pixels += line_size;
490 block += 8;
491 }
492}
493
494static void put_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
495 int line_size)
496{
497 int i;
498 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
499
500 /* read the pixels */
501 for(i=0;i<4;i++) {
502 pixels[0] = cm[block[0]];
503 pixels[1] = cm[block[1]];
504 pixels[2] = cm[block[2]];
505 pixels[3] = cm[block[3]];
506
507 pixels += line_size;
508 block += 8;
509 }
510}
511
512static void put_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
513 int line_size)
514{
515 int i;
516 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
517
518 /* read the pixels */
519 for(i=0;i<2;i++) {
520 pixels[0] = cm[block[0]];
521 pixels[1] = cm[block[1]];
522
523 pixels += line_size;
524 block += 8;
525 }
526}
527
528static void put_signed_pixels_clamped_c(const DCTELEM *block,
529 uint8_t *restrict pixels,
530 int line_size)
531{
532 int i, j;
533
534 for (i = 0; i < 8; i++) {
535 for (j = 0; j < 8; j++) {
536 if (*block < -128)
537 *pixels = 0;
538 else if (*block > 127)
539 *pixels = 255;
540 else
541 *pixels = (uint8_t)(*block + 128);
542 block++;
543 pixels++;
544 }
545 pixels += (line_size - 8);
546 }
547}
548
549static void put_pixels_nonclamped_c(const DCTELEM *block, uint8_t *restrict pixels,
550 int line_size)
551{
552 int i;
553
554 /* read the pixels */
555 for(i=0;i<8;i++) {
556 pixels[0] = block[0];
557 pixels[1] = block[1];
558 pixels[2] = block[2];
559 pixels[3] = block[3];
560 pixels[4] = block[4];
561 pixels[5] = block[5];
562 pixels[6] = block[6];
563 pixels[7] = block[7];
564
565 pixels += line_size;
566 block += 8;
567 }
568}
569
570static void add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
571 int line_size)
572{
573 int i;
574 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
575
576 /* read the pixels */
577 for(i=0;i<8;i++) {
578 pixels[0] = cm[pixels[0] + block[0]];
579 pixels[1] = cm[pixels[1] + block[1]];
580 pixels[2] = cm[pixels[2] + block[2]];
581 pixels[3] = cm[pixels[3] + block[3]];
582 pixels[4] = cm[pixels[4] + block[4]];
583 pixels[5] = cm[pixels[5] + block[5]];
584 pixels[6] = cm[pixels[6] + block[6]];
585 pixels[7] = cm[pixels[7] + block[7]];
586 pixels += line_size;
587 block += 8;
588 }
589}
590
591static void add_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
592 int line_size)
593{
594 int i;
595 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
596
597 /* read the pixels */
598 for(i=0;i<4;i++) {
599 pixels[0] = cm[pixels[0] + block[0]];
600 pixels[1] = cm[pixels[1] + block[1]];
601 pixels[2] = cm[pixels[2] + block[2]];
602 pixels[3] = cm[pixels[3] + block[3]];
603 pixels += line_size;
604 block += 8;
605 }
606}
607
608static void add_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
609 int line_size)
610{
611 int i;
612 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
613
614 /* read the pixels */
615 for(i=0;i<2;i++) {
616 pixels[0] = cm[pixels[0] + block[0]];
617 pixels[1] = cm[pixels[1] + block[1]];
618 pixels += line_size;
619 block += 8;
620 }
621}
622
623static void add_pixels8_c(uint8_t *restrict pixels, DCTELEM *block, int line_size)
624{
625 int i;
626 for(i=0;i<8;i++) {
627 pixels[0] += block[0];
628 pixels[1] += block[1];
629 pixels[2] += block[2];
630 pixels[3] += block[3];
631 pixels[4] += block[4];
632 pixels[5] += block[5];
633 pixels[6] += block[6];
634 pixels[7] += block[7];
635 pixels += line_size;
636 block += 8;
637 }
638}
639
640static void add_pixels4_c(uint8_t *restrict pixels, DCTELEM *block, int line_size)
641{
642 int i;
643 for(i=0;i<4;i++) {
644 pixels[0] += block[0];
645 pixels[1] += block[1];
646 pixels[2] += block[2];
647 pixels[3] += block[3];
648 pixels += line_size;
649 block += 4;
650 }
651}
652
653static int sum_abs_dctelem_c(DCTELEM *block)
654{
655 int sum=0, i;
656 for(i=0; i<64; i++)
657 sum+= FFABS(block[i]);
658 return sum;
659}
660
661static void fill_block16_c(uint8_t *block, uint8_t value, int line_size, int h)
662{
663 int i;
664
665 for (i = 0; i < h; i++) {
666 memset(block, value, 16);
667 block += line_size;
668 }
669}
670
671static void fill_block8_c(uint8_t *block, uint8_t value, int line_size, int h)
672{
673 int i;
674
675 for (i = 0; i < h; i++) {
676 memset(block, value, 8);
677 block += line_size;
678 }
679}
680
681static void scale_block_c(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize)
682{
683 int i, j;
684 uint16_t *dst1 = (uint16_t *) dst;
685 uint16_t *dst2 = (uint16_t *)(dst + linesize);
686
687 for (j = 0; j < 8; j++) {
688 for (i = 0; i < 8; i++) {
689 dst1[i] = dst2[i] = src[i] * 0x0101;
690 }
691 src += 8;
692 dst1 += linesize;
693 dst2 += linesize;
694 }
695}
696
697#if 0
698
699#define PIXOP2(OPNAME, OP) \
700static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
701{\
702 int i;\
703 for(i=0; i<h; i++){\
704 OP(*((uint64_t*)block), AV_RN64(pixels));\
705 pixels+=line_size;\
706 block +=line_size;\
707 }\
708}\
709\
710static void OPNAME ## _no_rnd_pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
711{\
712 int i;\
713 for(i=0; i<h; i++){\
714 const uint64_t a= AV_RN64(pixels );\
715 const uint64_t b= AV_RN64(pixels+1);\
716 OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
717 pixels+=line_size;\
718 block +=line_size;\
719 }\
720}\
721\
722static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
723{\
724 int i;\
725 for(i=0; i<h; i++){\
726 const uint64_t a= AV_RN64(pixels );\
727 const uint64_t b= AV_RN64(pixels+1);\
728 OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
729 pixels+=line_size;\
730 block +=line_size;\
731 }\
732}\
733\
734static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
735{\
736 int i;\
737 for(i=0; i<h; i++){\
738 const uint64_t a= AV_RN64(pixels );\
739 const uint64_t b= AV_RN64(pixels+line_size);\
740 OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
741 pixels+=line_size;\
742 block +=line_size;\
743 }\
744}\
745\
746static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
747{\
748 int i;\
749 for(i=0; i<h; i++){\
750 const uint64_t a= AV_RN64(pixels );\
751 const uint64_t b= AV_RN64(pixels+line_size);\
752 OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
753 pixels+=line_size;\
754 block +=line_size;\
755 }\
756}\
757\
758static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
759{\
760 int i;\
761 const uint64_t a= AV_RN64(pixels );\
762 const uint64_t b= AV_RN64(pixels+1);\
763 uint64_t l0= (a&0x0303030303030303ULL)\
764 + (b&0x0303030303030303ULL)\
765 + 0x0202020202020202ULL;\
766 uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
767 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
768 uint64_t l1,h1;\
769\
770 pixels+=line_size;\
771 for(i=0; i<h; i+=2){\
772 uint64_t a= AV_RN64(pixels );\
773 uint64_t b= AV_RN64(pixels+1);\
774 l1= (a&0x0303030303030303ULL)\
775 + (b&0x0303030303030303ULL);\
776 h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
777 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
778 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
779 pixels+=line_size;\
780 block +=line_size;\
781 a= AV_RN64(pixels );\
782 b= AV_RN64(pixels+1);\
783 l0= (a&0x0303030303030303ULL)\
784 + (b&0x0303030303030303ULL)\
785 + 0x0202020202020202ULL;\
786 h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
787 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
788 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
789 pixels+=line_size;\
790 block +=line_size;\
791 }\
792}\
793\
794static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
795{\
796 int i;\
797 const uint64_t a= AV_RN64(pixels );\
798 const uint64_t b= AV_RN64(pixels+1);\
799 uint64_t l0= (a&0x0303030303030303ULL)\
800 + (b&0x0303030303030303ULL)\
801 + 0x0101010101010101ULL;\
802 uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
803 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
804 uint64_t l1,h1;\
805\
806 pixels+=line_size;\
807 for(i=0; i<h; i+=2){\
808 uint64_t a= AV_RN64(pixels );\
809 uint64_t b= AV_RN64(pixels+1);\
810 l1= (a&0x0303030303030303ULL)\
811 + (b&0x0303030303030303ULL);\
812 h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
813 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
814 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
815 pixels+=line_size;\
816 block +=line_size;\
817 a= AV_RN64(pixels );\
818 b= AV_RN64(pixels+1);\
819 l0= (a&0x0303030303030303ULL)\
820 + (b&0x0303030303030303ULL)\
821 + 0x0101010101010101ULL;\
822 h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
823 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
824 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
825 pixels+=line_size;\
826 block +=line_size;\
827 }\
828}\
829\
830CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8)\
831CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8)\
832CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8)\
833CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8)\
834CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8)\
835CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8)\
836CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8)
837
838#define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) )
839#else // 64 bit variant
840
841#define PIXOP2(OPNAME, OP) \
842static void OPNAME ## _pixels2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
843 int i;\
844 for(i=0; i<h; i++){\
845 OP(*((uint16_t*)(block )), AV_RN16(pixels ));\
846 pixels+=line_size;\
847 block +=line_size;\
848 }\
849}\
850static void OPNAME ## _pixels4_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
851 int i;\
852 for(i=0; i<h; i++){\
853 OP(*((uint32_t*)(block )), AV_RN32(pixels ));\
854 pixels+=line_size;\
855 block +=line_size;\
856 }\
857}\
858static void OPNAME ## _pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
859 int i;\
860 for(i=0; i<h; i++){\
861 OP(*((uint32_t*)(block )), AV_RN32(pixels ));\
862 OP(*((uint32_t*)(block+4)), AV_RN32(pixels+4));\
863 pixels+=line_size;\
864 block +=line_size;\
865 }\
866}\
867static inline void OPNAME ## _no_rnd_pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
868 OPNAME ## _pixels8_c(block, pixels, line_size, h);\
869}\
870\
871static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
872 int src_stride1, int src_stride2, int h){\
873 int i;\
874 for(i=0; i<h; i++){\
875 uint32_t a,b;\
876 a= AV_RN32(&src1[i*src_stride1 ]);\
877 b= AV_RN32(&src2[i*src_stride2 ]);\
878 OP(*((uint32_t*)&dst[i*dst_stride ]), no_rnd_avg32(a, b));\
879 a= AV_RN32(&src1[i*src_stride1+4]);\
880 b= AV_RN32(&src2[i*src_stride2+4]);\
881 OP(*((uint32_t*)&dst[i*dst_stride+4]), no_rnd_avg32(a, b));\
882 }\
883}\
884\
885static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
886 int src_stride1, int src_stride2, int h){\
887 int i;\
888 for(i=0; i<h; i++){\
889 uint32_t a,b;\
890 a= AV_RN32(&src1[i*src_stride1 ]);\
891 b= AV_RN32(&src2[i*src_stride2 ]);\
892 OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
893 a= AV_RN32(&src1[i*src_stride1+4]);\
894 b= AV_RN32(&src2[i*src_stride2+4]);\
895 OP(*((uint32_t*)&dst[i*dst_stride+4]), rnd_avg32(a, b));\
896 }\
897}\
898\
899static inline void OPNAME ## _pixels4_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
900 int src_stride1, int src_stride2, int h){\
901 int i;\
902 for(i=0; i<h; i++){\
903 uint32_t a,b;\
904 a= AV_RN32(&src1[i*src_stride1 ]);\
905 b= AV_RN32(&src2[i*src_stride2 ]);\
906 OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
907 }\
908}\
909\
910static inline void OPNAME ## _pixels2_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
911 int src_stride1, int src_stride2, int h){\
912 int i;\
913 for(i=0; i<h; i++){\
914 uint32_t a,b;\
915 a= AV_RN16(&src1[i*src_stride1 ]);\
916 b= AV_RN16(&src2[i*src_stride2 ]);\
917 OP(*((uint16_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
918 }\
919}\
920\
921static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
922 int src_stride1, int src_stride2, int h){\
923 OPNAME ## _pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
924 OPNAME ## _pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
925}\
926\
927static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
928 int src_stride1, int src_stride2, int h){\
929 OPNAME ## _no_rnd_pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
930 OPNAME ## _no_rnd_pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
931}\
932\
933static inline void OPNAME ## _no_rnd_pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
934 OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
935}\
936\
937static inline void OPNAME ## _pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
938 OPNAME ## _pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
939}\
940\
941static inline void OPNAME ## _no_rnd_pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
942 OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
943}\
944\
945static inline void OPNAME ## _pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
946 OPNAME ## _pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
947}\
948\
949static inline void OPNAME ## _pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
950 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
951 int i;\
952 for(i=0; i<h; i++){\
953 uint32_t a, b, c, d, l0, l1, h0, h1;\
954 a= AV_RN32(&src1[i*src_stride1]);\
955 b= AV_RN32(&src2[i*src_stride2]);\
956 c= AV_RN32(&src3[i*src_stride3]);\
957 d= AV_RN32(&src4[i*src_stride4]);\
958 l0= (a&0x03030303UL)\
959 + (b&0x03030303UL)\
960 + 0x02020202UL;\
961 h0= ((a&0xFCFCFCFCUL)>>2)\
962 + ((b&0xFCFCFCFCUL)>>2);\
963 l1= (c&0x03030303UL)\
964 + (d&0x03030303UL);\
965 h1= ((c&0xFCFCFCFCUL)>>2)\
966 + ((d&0xFCFCFCFCUL)>>2);\
967 OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
968 a= AV_RN32(&src1[i*src_stride1+4]);\
969 b= AV_RN32(&src2[i*src_stride2+4]);\
970 c= AV_RN32(&src3[i*src_stride3+4]);\
971 d= AV_RN32(&src4[i*src_stride4+4]);\
972 l0= (a&0x03030303UL)\
973 + (b&0x03030303UL)\
974 + 0x02020202UL;\
975 h0= ((a&0xFCFCFCFCUL)>>2)\
976 + ((b&0xFCFCFCFCUL)>>2);\
977 l1= (c&0x03030303UL)\
978 + (d&0x03030303UL);\
979 h1= ((c&0xFCFCFCFCUL)>>2)\
980 + ((d&0xFCFCFCFCUL)>>2);\
981 OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
982 }\
983}\
984\
985static inline void OPNAME ## _pixels4_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
986 OPNAME ## _pixels4_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
987}\
988\
989static inline void OPNAME ## _pixels4_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
990 OPNAME ## _pixels4_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
991}\
992\
993static inline void OPNAME ## _pixels2_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
994 OPNAME ## _pixels2_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
995}\
996\
997static inline void OPNAME ## _pixels2_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
998 OPNAME ## _pixels2_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
999}\
1000\
1001static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
1002 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
1003 int i;\
1004 for(i=0; i<h; i++){\
1005 uint32_t a, b, c, d, l0, l1, h0, h1;\
1006 a= AV_RN32(&src1[i*src_stride1]);\
1007 b= AV_RN32(&src2[i*src_stride2]);\
1008 c= AV_RN32(&src3[i*src_stride3]);\
1009 d= AV_RN32(&src4[i*src_stride4]);\
1010 l0= (a&0x03030303UL)\
1011 + (b&0x03030303UL)\
1012 + 0x01010101UL;\
1013 h0= ((a&0xFCFCFCFCUL)>>2)\
1014 + ((b&0xFCFCFCFCUL)>>2);\
1015 l1= (c&0x03030303UL)\
1016 + (d&0x03030303UL);\
1017 h1= ((c&0xFCFCFCFCUL)>>2)\
1018 + ((d&0xFCFCFCFCUL)>>2);\
1019 OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1020 a= AV_RN32(&src1[i*src_stride1+4]);\
1021 b= AV_RN32(&src2[i*src_stride2+4]);\
1022 c= AV_RN32(&src3[i*src_stride3+4]);\
1023 d= AV_RN32(&src4[i*src_stride4+4]);\
1024 l0= (a&0x03030303UL)\
1025 + (b&0x03030303UL)\
1026 + 0x01010101UL;\
1027 h0= ((a&0xFCFCFCFCUL)>>2)\
1028 + ((b&0xFCFCFCFCUL)>>2);\
1029 l1= (c&0x03030303UL)\
1030 + (d&0x03030303UL);\
1031 h1= ((c&0xFCFCFCFCUL)>>2)\
1032 + ((d&0xFCFCFCFCUL)>>2);\
1033 OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1034 }\
1035}\
1036static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
1037 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
1038 OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
1039 OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
1040}\
1041static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
1042 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
1043 OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
1044 OPNAME ## _no_rnd_pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
1045}\
1046\
1047static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
1048{\
1049 int i, a0, b0, a1, b1;\
1050 a0= pixels[0];\
1051 b0= pixels[1] + 2;\
1052 a0 += b0;\
1053 b0 += pixels[2];\
1054\
1055 pixels+=line_size;\
1056 for(i=0; i<h; i+=2){\
1057 a1= pixels[0];\
1058 b1= pixels[1];\
1059 a1 += b1;\
1060 b1 += pixels[2];\
1061\
1062 block[0]= (a1+a0)>>2; /* FIXME non put */\
1063 block[1]= (b1+b0)>>2;\
1064\
1065 pixels+=line_size;\
1066 block +=line_size;\
1067\
1068 a0= pixels[0];\
1069 b0= pixels[1] + 2;\
1070 a0 += b0;\
1071 b0 += pixels[2];\
1072\
1073 block[0]= (a1+a0)>>2;\
1074 block[1]= (b1+b0)>>2;\
1075 pixels+=line_size;\
1076 block +=line_size;\
1077 }\
1078}\
1079\
1080static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
1081{\
1082 int i;\
1083 const uint32_t a= AV_RN32(pixels );\
1084 const uint32_t b= AV_RN32(pixels+1);\
1085 uint32_t l0= (a&0x03030303UL)\
1086 + (b&0x03030303UL)\
1087 + 0x02020202UL;\
1088 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
1089 + ((b&0xFCFCFCFCUL)>>2);\
1090 uint32_t l1,h1;\
1091\
1092 pixels+=line_size;\
1093 for(i=0; i<h; i+=2){\
1094 uint32_t a= AV_RN32(pixels );\
1095 uint32_t b= AV_RN32(pixels+1);\
1096 l1= (a&0x03030303UL)\
1097 + (b&0x03030303UL);\
1098 h1= ((a&0xFCFCFCFCUL)>>2)\
1099 + ((b&0xFCFCFCFCUL)>>2);\
1100 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1101 pixels+=line_size;\
1102 block +=line_size;\
1103 a= AV_RN32(pixels );\
1104 b= AV_RN32(pixels+1);\
1105 l0= (a&0x03030303UL)\
1106 + (b&0x03030303UL)\
1107 + 0x02020202UL;\
1108 h0= ((a&0xFCFCFCFCUL)>>2)\
1109 + ((b&0xFCFCFCFCUL)>>2);\
1110 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1111 pixels+=line_size;\
1112 block +=line_size;\
1113 }\
1114}\
1115\
1116static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
1117{\
1118 int j;\
1119 for(j=0; j<2; j++){\
1120 int i;\
1121 const uint32_t a= AV_RN32(pixels );\
1122 const uint32_t b= AV_RN32(pixels+1);\
1123 uint32_t l0= (a&0x03030303UL)\
1124 + (b&0x03030303UL)\
1125 + 0x02020202UL;\
1126 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
1127 + ((b&0xFCFCFCFCUL)>>2);\
1128 uint32_t l1,h1;\
1129\
1130 pixels+=line_size;\
1131 for(i=0; i<h; i+=2){\
1132 uint32_t a= AV_RN32(pixels );\
1133 uint32_t b= AV_RN32(pixels+1);\
1134 l1= (a&0x03030303UL)\
1135 + (b&0x03030303UL);\
1136 h1= ((a&0xFCFCFCFCUL)>>2)\
1137 + ((b&0xFCFCFCFCUL)>>2);\
1138 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1139 pixels+=line_size;\
1140 block +=line_size;\
1141 a= AV_RN32(pixels );\
1142 b= AV_RN32(pixels+1);\
1143 l0= (a&0x03030303UL)\
1144 + (b&0x03030303UL)\
1145 + 0x02020202UL;\
1146 h0= ((a&0xFCFCFCFCUL)>>2)\
1147 + ((b&0xFCFCFCFCUL)>>2);\
1148 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1149 pixels+=line_size;\
1150 block +=line_size;\
1151 }\
1152 pixels+=4-line_size*(h+1);\
1153 block +=4-line_size*h;\
1154 }\
1155}\
1156\
1157static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
1158{\
1159 int j;\
1160 for(j=0; j<2; j++){\
1161 int i;\
1162 const uint32_t a= AV_RN32(pixels );\
1163 const uint32_t b= AV_RN32(pixels+1);\
1164 uint32_t l0= (a&0x03030303UL)\
1165 + (b&0x03030303UL)\
1166 + 0x01010101UL;\
1167 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
1168 + ((b&0xFCFCFCFCUL)>>2);\
1169 uint32_t l1,h1;\
1170\
1171 pixels+=line_size;\
1172 for(i=0; i<h; i+=2){\
1173 uint32_t a= AV_RN32(pixels );\
1174 uint32_t b= AV_RN32(pixels+1);\
1175 l1= (a&0x03030303UL)\
1176 + (b&0x03030303UL);\
1177 h1= ((a&0xFCFCFCFCUL)>>2)\
1178 + ((b&0xFCFCFCFCUL)>>2);\
1179 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1180 pixels+=line_size;\
1181 block +=line_size;\
1182 a= AV_RN32(pixels );\
1183 b= AV_RN32(pixels+1);\
1184 l0= (a&0x03030303UL)\
1185 + (b&0x03030303UL)\
1186 + 0x01010101UL;\
1187 h0= ((a&0xFCFCFCFCUL)>>2)\
1188 + ((b&0xFCFCFCFCUL)>>2);\
1189 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1190 pixels+=line_size;\
1191 block +=line_size;\
1192 }\
1193 pixels+=4-line_size*(h+1);\
1194 block +=4-line_size*h;\
1195 }\
1196}\
1197\
1198CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\
1199CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels8_x2_c , 8)\
1200CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels8_y2_c , 8)\
1201CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels8_xy2_c, 8)\
1202CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_c , OPNAME ## _pixels8_c , 8)\
1203CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels8_x2_c , 8)\
1204CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels8_y2_c , 8)\
1205CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels8_xy2_c, 8)\
1206
1207#define op_avg(a, b) a = rnd_avg32(a, b)
1208#endif
1209#define op_put(a, b) a = b
1210
1211PIXOP2(avg, op_avg)
1212PIXOP2(put, op_put)
1213#undef op_avg
1214#undef op_put
1215
1216#define avg2(a,b) ((a+b+1)>>1)
1217#define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
1218
1219static void put_no_rnd_pixels16_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
1220 put_no_rnd_pixels16_l2(dst, a, b, stride, stride, stride, h);
1221}
1222
1223static void put_no_rnd_pixels8_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
1224 put_no_rnd_pixels8_l2(dst, a, b, stride, stride, stride, h);
1225}
1226
1227static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
1228{
1229 const int A=(16-x16)*(16-y16);
1230 const int B=( x16)*(16-y16);
1231 const int C=(16-x16)*( y16);
1232 const int D=( x16)*( y16);
1233 int i;
1234
1235 for(i=0; i<h; i++)
1236 {
1237 dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
1238 dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
1239 dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
1240 dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
1241 dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
1242 dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
1243 dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
1244 dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
1245 dst+= stride;
1246 src+= stride;
1247 }
1248}
1249
1250void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
1251 int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
1252{
1253 int y, vx, vy;
1254 const int s= 1<<shift;
1255
1256 width--;
1257 height--;
1258
1259 for(y=0; y<h; y++){
1260 int x;
1261
1262 vx= ox;
1263 vy= oy;
1264 for(x=0; x<8; x++){ //XXX FIXME optimize
1265 int src_x, src_y, frac_x, frac_y, index;
1266
1267 src_x= vx>>16;
1268 src_y= vy>>16;
1269 frac_x= src_x&(s-1);
1270 frac_y= src_y&(s-1);
1271 src_x>>=shift;
1272 src_y>>=shift;
1273
1274 if((unsigned)src_x < width){
1275 if((unsigned)src_y < height){
1276 index= src_x + src_y*stride;
1277 dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
1278 + src[index +1]* frac_x )*(s-frac_y)
1279 + ( src[index+stride ]*(s-frac_x)
1280 + src[index+stride+1]* frac_x )* frac_y
1281 + r)>>(shift*2);
1282 }else{
1283 index= src_x + av_clip(src_y, 0, height)*stride;
1284 dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
1285 + src[index +1]* frac_x )*s
1286 + r)>>(shift*2);
1287 }
1288 }else{
1289 if((unsigned)src_y < height){
1290 index= av_clip(src_x, 0, width) + src_y*stride;
1291 dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
1292 + src[index+stride ]* frac_y )*s
1293 + r)>>(shift*2);
1294 }else{
1295 index= av_clip(src_x, 0, width) + av_clip(src_y, 0, height)*stride;
1296 dst[y*stride + x]= src[index ];
1297 }
1298 }
1299
1300 vx+= dxx;
1301 vy+= dyx;
1302 }
1303 ox += dxy;
1304 oy += dyy;
1305 }
1306}
1307
1308static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1309 switch(width){
1310 case 2: put_pixels2_c (dst, src, stride, height); break;
1311 case 4: put_pixels4_c (dst, src, stride, height); break;
1312 case 8: put_pixels8_c (dst, src, stride, height); break;
1313 case 16:put_pixels16_c(dst, src, stride, height); break;
1314 }
1315}
1316
1317static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1318 int i,j;
1319 for (i=0; i < height; i++) {
1320 for (j=0; j < width; j++) {
1321 dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11;
1322 }
1323 src += stride;
1324 dst += stride;
1325 }
1326}
1327
1328static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1329 int i,j;
1330 for (i=0; i < height; i++) {
1331 for (j=0; j < width; j++) {
1332 dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11;
1333 }
1334 src += stride;
1335 dst += stride;
1336 }
1337}
1338
1339static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1340 int i,j;
1341 for (i=0; i < height; i++) {
1342 for (j=0; j < width; j++) {
1343 dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11;
1344 }
1345 src += stride;
1346 dst += stride;
1347 }
1348}
1349
1350static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1351 int i,j;
1352 for (i=0; i < height; i++) {
1353 for (j=0; j < width; j++) {
1354 dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15;
1355 }
1356 src += stride;
1357 dst += stride;
1358 }
1359}
1360
1361static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1362 int i,j;
1363 for (i=0; i < height; i++) {
1364 for (j=0; j < width; j++) {
1365 dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
1366 }
1367 src += stride;
1368 dst += stride;
1369 }
1370}
1371
1372static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1373 int i,j;
1374 for (i=0; i < height; i++) {
1375 for (j=0; j < width; j++) {
1376 dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11;
1377 }
1378 src += stride;
1379 dst += stride;
1380 }
1381}
1382
1383static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1384 int i,j;
1385 for (i=0; i < height; i++) {
1386 for (j=0; j < width; j++) {
1387 dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
1388 }
1389 src += stride;
1390 dst += stride;
1391 }
1392}
1393
1394static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1395 int i,j;
1396 for (i=0; i < height; i++) {
1397 for (j=0; j < width; j++) {
1398 dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15;
1399 }
1400 src += stride;
1401 dst += stride;
1402 }
1403}
1404
1405static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1406 switch(width){
1407 case 2: avg_pixels2_c (dst, src, stride, height); break;
1408 case 4: avg_pixels4_c (dst, src, stride, height); break;
1409 case 8: avg_pixels8_c (dst, src, stride, height); break;
1410 case 16:avg_pixels16_c(dst, src, stride, height); break;
1411 }
1412}
1413
1414static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1415 int i,j;
1416 for (i=0; i < height; i++) {
1417 for (j=0; j < width; j++) {
1418 dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1;
1419 }
1420 src += stride;
1421 dst += stride;
1422 }
1423}
1424
1425static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1426 int i,j;
1427 for (i=0; i < height; i++) {
1428 for (j=0; j < width; j++) {
1429 dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1;
1430 }
1431 src += stride;
1432 dst += stride;
1433 }
1434}
1435
1436static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1437 int i,j;
1438 for (i=0; i < height; i++) {
1439 for (j=0; j < width; j++) {
1440 dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1;
1441 }
1442 src += stride;
1443 dst += stride;
1444 }
1445}
1446
1447static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1448 int i,j;
1449 for (i=0; i < height; i++) {
1450 for (j=0; j < width; j++) {
1451 dst[j] = (dst[j] + ((2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
1452 }
1453 src += stride;
1454 dst += stride;
1455 }
1456}
1457
1458static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1459 int i,j;
1460 for (i=0; i < height; i++) {
1461 for (j=0; j < width; j++) {
1462 dst[j] = (dst[j] + ((2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
1463 }
1464 src += stride;
1465 dst += stride;
1466 }
1467}
1468
1469static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1470 int i,j;
1471 for (i=0; i < height; i++) {
1472 for (j=0; j < width; j++) {
1473 dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1;
1474 }
1475 src += stride;
1476 dst += stride;
1477 }
1478}
1479
1480static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1481 int i,j;
1482 for (i=0; i < height; i++) {
1483 for (j=0; j < width; j++) {
1484 dst[j] = (dst[j] + ((2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
1485 }
1486 src += stride;
1487 dst += stride;
1488 }
1489}
1490
1491static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1492 int i,j;
1493 for (i=0; i < height; i++) {
1494 for (j=0; j < width; j++) {
1495 dst[j] = (dst[j] + ((2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
1496 }
1497 src += stride;
1498 dst += stride;
1499 }
1500}
1501#if 0
1502#define TPEL_WIDTH(width)\
1503static void put_tpel_pixels ## width ## _mc00_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1504 void put_tpel_pixels_mc00_c(dst, src, stride, width, height);}\
1505static void put_tpel_pixels ## width ## _mc10_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1506 void put_tpel_pixels_mc10_c(dst, src, stride, width, height);}\
1507static void put_tpel_pixels ## width ## _mc20_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1508 void put_tpel_pixels_mc20_c(dst, src, stride, width, height);}\
1509static void put_tpel_pixels ## width ## _mc01_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1510 void put_tpel_pixels_mc01_c(dst, src, stride, width, height);}\
1511static void put_tpel_pixels ## width ## _mc11_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1512 void put_tpel_pixels_mc11_c(dst, src, stride, width, height);}\
1513static void put_tpel_pixels ## width ## _mc21_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1514 void put_tpel_pixels_mc21_c(dst, src, stride, width, height);}\
1515static void put_tpel_pixels ## width ## _mc02_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1516 void put_tpel_pixels_mc02_c(dst, src, stride, width, height);}\
1517static void put_tpel_pixels ## width ## _mc12_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1518 void put_tpel_pixels_mc12_c(dst, src, stride, width, height);}\
1519static void put_tpel_pixels ## width ## _mc22_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1520 void put_tpel_pixels_mc22_c(dst, src, stride, width, height);}
1521#endif
1522
1523#define H264_CHROMA_MC(OPNAME, OP)\
1524static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
1525 const int A=(8-x)*(8-y);\
1526 const int B=( x)*(8-y);\
1527 const int C=(8-x)*( y);\
1528 const int D=( x)*( y);\
1529 int i;\
1530 \
1531 assert(x<8 && y<8 && x>=0 && y>=0);\
1532\
1533 if(D){\
1534 for(i=0; i<h; i++){\
1535 OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
1536 OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
1537 dst+= stride;\
1538 src+= stride;\
1539 }\
1540 }else{\
1541 const int E= B+C;\
1542 const int step= C ? stride : 1;\
1543 for(i=0; i<h; i++){\
1544 OP(dst[0], (A*src[0] + E*src[step+0]));\
1545 OP(dst[1], (A*src[1] + E*src[step+1]));\
1546 dst+= stride;\
1547 src+= stride;\
1548 }\
1549 }\
1550}\
1551\
1552static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
1553 const int A=(8-x)*(8-y);\
1554 const int B=( x)*(8-y);\
1555 const int C=(8-x)*( y);\
1556 const int D=( x)*( y);\
1557 int i;\
1558 \
1559 assert(x<8 && y<8 && x>=0 && y>=0);\
1560\
1561 if(D){\
1562 for(i=0; i<h; i++){\
1563 OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
1564 OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
1565 OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
1566 OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
1567 dst+= stride;\
1568 src+= stride;\
1569 }\
1570 }else{\
1571 const int E= B+C;\
1572 const int step= C ? stride : 1;\
1573 for(i=0; i<h; i++){\
1574 OP(dst[0], (A*src[0] + E*src[step+0]));\
1575 OP(dst[1], (A*src[1] + E*src[step+1]));\
1576 OP(dst[2], (A*src[2] + E*src[step+2]));\
1577 OP(dst[3], (A*src[3] + E*src[step+3]));\
1578 dst+= stride;\
1579 src+= stride;\
1580 }\
1581 }\
1582}\
1583\
1584static void OPNAME ## h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
1585 const int A=(8-x)*(8-y);\
1586 const int B=( x)*(8-y);\
1587 const int C=(8-x)*( y);\
1588 const int D=( x)*( y);\
1589 int i;\
1590 \
1591 assert(x<8 && y<8 && x>=0 && y>=0);\
1592\
1593 if(D){\
1594 for(i=0; i<h; i++){\
1595 OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
1596 OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
1597 OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
1598 OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
1599 OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
1600 OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
1601 OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
1602 OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
1603 dst+= stride;\
1604 src+= stride;\
1605 }\
1606 }else{\
1607 const int E= B+C;\
1608 const int step= C ? stride : 1;\
1609 for(i=0; i<h; i++){\
1610 OP(dst[0], (A*src[0] + E*src[step+0]));\
1611 OP(dst[1], (A*src[1] + E*src[step+1]));\
1612 OP(dst[2], (A*src[2] + E*src[step+2]));\
1613 OP(dst[3], (A*src[3] + E*src[step+3]));\
1614 OP(dst[4], (A*src[4] + E*src[step+4]));\
1615 OP(dst[5], (A*src[5] + E*src[step+5]));\
1616 OP(dst[6], (A*src[6] + E*src[step+6]));\
1617 OP(dst[7], (A*src[7] + E*src[step+7]));\
1618 dst+= stride;\
1619 src+= stride;\
1620 }\
1621 }\
1622}
1623
1624#define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
1625#define op_put(a, b) a = (((b) + 32)>>6)
1626
1627H264_CHROMA_MC(put_ , op_put)
1628H264_CHROMA_MC(avg_ , op_avg)
1629#undef op_avg
1630#undef op_put
1631
1632static void put_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){
1633 const int A=(8-x)*(8-y);
1634 const int B=( x)*(8-y);
1635 const int C=(8-x)*( y);
1636 const int D=( x)*( y);
1637 int i;
1638
1639 assert(x<8 && y<8 && x>=0 && y>=0);
1640
1641 for(i=0; i<h; i++)
1642 {
1643 dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
1644 dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
1645 dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
1646 dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
1647 dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6;
1648 dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6;
1649 dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6;
1650 dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6;
1651 dst+= stride;
1652 src+= stride;
1653 }
1654}
1655
1656static void avg_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){
1657 const int A=(8-x)*(8-y);
1658 const int B=( x)*(8-y);
1659 const int C=(8-x)*( y);
1660 const int D=( x)*( y);
1661 int i;
1662
1663 assert(x<8 && y<8 && x>=0 && y>=0);
1664
1665 for(i=0; i<h; i++)
1666 {
1667 dst[0] = avg2(dst[0], ((A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6));
1668 dst[1] = avg2(dst[1], ((A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6));
1669 dst[2] = avg2(dst[2], ((A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6));
1670 dst[3] = avg2(dst[3], ((A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6));
1671 dst[4] = avg2(dst[4], ((A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6));
1672 dst[5] = avg2(dst[5], ((A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6));
1673 dst[6] = avg2(dst[6], ((A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6));
1674 dst[7] = avg2(dst[7], ((A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6));
1675 dst+= stride;
1676 src+= stride;
1677 }
1678}
1679
1680#define QPEL_MC(r, OPNAME, RND, OP) \
1681static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1682 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
1683 int i;\
1684 for(i=0; i<h; i++)\
1685 {\
1686 OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
1687 OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
1688 OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
1689 OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
1690 OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
1691 OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
1692 OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
1693 OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
1694 dst+=dstStride;\
1695 src+=srcStride;\
1696 }\
1697}\
1698\
1699static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1700 const int w=8;\
1701 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
1702 int i;\
1703 for(i=0; i<w; i++)\
1704 {\
1705 const int src0= src[0*srcStride];\
1706 const int src1= src[1*srcStride];\
1707 const int src2= src[2*srcStride];\
1708 const int src3= src[3*srcStride];\
1709 const int src4= src[4*srcStride];\
1710 const int src5= src[5*srcStride];\
1711 const int src6= src[6*srcStride];\
1712 const int src7= src[7*srcStride];\
1713 const int src8= src[8*srcStride];\
1714 OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
1715 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
1716 OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
1717 OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
1718 OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
1719 OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
1720 OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
1721 OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
1722 dst++;\
1723 src++;\
1724 }\
1725}\
1726\
1727static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1728 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
1729 int i;\
1730 \
1731 for(i=0; i<h; i++)\
1732 {\
1733 OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
1734 OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
1735 OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
1736 OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
1737 OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
1738 OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
1739 OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
1740 OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
1741 OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
1742 OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
1743 OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
1744 OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
1745 OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
1746 OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
1747 OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
1748 OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
1749 dst+=dstStride;\
1750 src+=srcStride;\
1751 }\
1752}\
1753\
1754static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1755 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
1756 int i;\
1757 const int w=16;\
1758 for(i=0; i<w; i++)\
1759 {\
1760 const int src0= src[0*srcStride];\
1761 const int src1= src[1*srcStride];\
1762 const int src2= src[2*srcStride];\
1763 const int src3= src[3*srcStride];\
1764 const int src4= src[4*srcStride];\
1765 const int src5= src[5*srcStride];\
1766 const int src6= src[6*srcStride];\
1767 const int src7= src[7*srcStride];\
1768 const int src8= src[8*srcStride];\
1769 const int src9= src[9*srcStride];\
1770 const int src10= src[10*srcStride];\
1771 const int src11= src[11*srcStride];\
1772 const int src12= src[12*srcStride];\
1773 const int src13= src[13*srcStride];\
1774 const int src14= src[14*srcStride];\
1775 const int src15= src[15*srcStride];\
1776 const int src16= src[16*srcStride];\
1777 OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
1778 OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
1779 OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
1780 OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
1781 OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
1782 OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
1783 OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
1784 OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
1785 OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
1786 OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
1787 OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
1788 OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
1789 OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
1790 OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
1791 OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
1792 OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
1793 dst++;\
1794 src++;\
1795 }\
1796}\
1797\
1798static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
1799 OPNAME ## pixels8_c(dst, src, stride, 8);\
1800}\
1801\
1802static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
1803 uint8_t half[64];\
1804 put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
1805 OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
1806}\
1807\
1808static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
1809 OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
1810}\
1811\
1812static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
1813 uint8_t half[64];\
1814 put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
1815 OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
1816}\
1817\
1818static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
1819 uint8_t full[16*9];\
1820 uint8_t half[64];\
1821 copy_block9(full, src, 16, stride, 9);\
1822 put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
1823 OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
1824}\
1825\
1826static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
1827 uint8_t full[16*9];\
1828 copy_block9(full, src, 16, stride, 9);\
1829 OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
1830}\
1831\
1832static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
1833 uint8_t full[16*9];\
1834 uint8_t half[64];\
1835 copy_block9(full, src, 16, stride, 9);\
1836 put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
1837 OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
1838}\
1839void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
1840 uint8_t full[16*9];\
1841 uint8_t halfH[72];\
1842 uint8_t halfV[64];\
1843 uint8_t halfHV[64];\
1844 copy_block9(full, src, 16, stride, 9);\
1845 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1846 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
1847 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1848 OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
1849}\
1850static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
1851 uint8_t full[16*9];\
1852 uint8_t halfH[72];\
1853 uint8_t halfHV[64];\
1854 copy_block9(full, src, 16, stride, 9);\
1855 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1856 put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
1857 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1858 OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
1859}\
1860void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
1861 uint8_t full[16*9];\
1862 uint8_t halfH[72];\
1863 uint8_t halfV[64];\
1864 uint8_t halfHV[64];\
1865 copy_block9(full, src, 16, stride, 9);\
1866 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1867 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
1868 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1869 OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
1870}\
1871static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
1872 uint8_t full[16*9];\
1873 uint8_t halfH[72];\
1874 uint8_t halfHV[64];\
1875 copy_block9(full, src, 16, stride, 9);\
1876 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1877 put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
1878 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1879 OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
1880}\
1881void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
1882 uint8_t full[16*9];\
1883 uint8_t halfH[72];\
1884 uint8_t halfV[64];\
1885 uint8_t halfHV[64];\
1886 copy_block9(full, src, 16, stride, 9);\
1887 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1888 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
1889 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1890 OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
1891}\
1892static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
1893 uint8_t full[16*9];\
1894 uint8_t halfH[72];\
1895 uint8_t halfHV[64];\
1896 copy_block9(full, src, 16, stride, 9);\
1897 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1898 put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
1899 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1900 OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
1901}\
1902void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
1903 uint8_t full[16*9];\
1904 uint8_t halfH[72];\
1905 uint8_t halfV[64];\
1906 uint8_t halfHV[64];\
1907 copy_block9(full, src, 16, stride, 9);\
1908 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
1909 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
1910 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1911 OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
1912}\
1913static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
1914 uint8_t full[16*9];\
1915 uint8_t halfH[72];\
1916 uint8_t halfHV[64];\
1917 copy_block9(full, src, 16, stride, 9);\
1918 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1919 put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
1920 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1921 OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
1922}\
1923static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
1924 uint8_t halfH[72];\
1925 uint8_t halfHV[64];\
1926 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
1927 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1928 OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
1929}\
1930static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
1931 uint8_t halfH[72];\
1932 uint8_t halfHV[64];\
1933 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
1934 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1935 OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
1936}\
1937void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
1938 uint8_t full[16*9];\
1939 uint8_t halfH[72];\
1940 uint8_t halfV[64];\
1941 uint8_t halfHV[64];\
1942 copy_block9(full, src, 16, stride, 9);\
1943 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1944 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
1945 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1946 OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
1947}\
1948static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
1949 uint8_t full[16*9];\
1950 uint8_t halfH[72];\
1951 copy_block9(full, src, 16, stride, 9);\
1952 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1953 put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
1954 OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
1955}\
1956void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
1957 uint8_t full[16*9];\
1958 uint8_t halfH[72];\
1959 uint8_t halfV[64];\
1960 uint8_t halfHV[64];\
1961 copy_block9(full, src, 16, stride, 9);\
1962 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1963 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
1964 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1965 OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
1966}\
1967static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
1968 uint8_t full[16*9];\
1969 uint8_t halfH[72];\
1970 copy_block9(full, src, 16, stride, 9);\
1971 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1972 put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
1973 OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
1974}\
1975static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
1976 uint8_t halfH[72];\
1977 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
1978 OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
1979}\
1980static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
1981 OPNAME ## pixels16_c(dst, src, stride, 16);\
1982}\
1983\
1984static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
1985 uint8_t half[256];\
1986 put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
1987 OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
1988}\
1989\
1990static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
1991 OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
1992}\
1993\
1994static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
1995 uint8_t half[256];\
1996 put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
1997 OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
1998}\
1999\
2000static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
2001 uint8_t full[24*17];\
2002 uint8_t half[256];\
2003 copy_block17(full, src, 24, stride, 17);\
2004 put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
2005 OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
2006}\
2007\
2008static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
2009 uint8_t full[24*17];\
2010 copy_block17(full, src, 24, stride, 17);\
2011 OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
2012}\
2013\
2014static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
2015 uint8_t full[24*17];\
2016 uint8_t half[256];\
2017 copy_block17(full, src, 24, stride, 17);\
2018 put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
2019 OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
2020}\
2021void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
2022 uint8_t full[24*17];\
2023 uint8_t halfH[272];\
2024 uint8_t halfV[256];\
2025 uint8_t halfHV[256];\
2026 copy_block17(full, src, 24, stride, 17);\
2027 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2028 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
2029 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2030 OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
2031}\
2032static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
2033 uint8_t full[24*17];\
2034 uint8_t halfH[272];\
2035 uint8_t halfHV[256];\
2036 copy_block17(full, src, 24, stride, 17);\
2037 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2038 put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
2039 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2040 OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
2041}\
2042void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
2043 uint8_t full[24*17];\
2044 uint8_t halfH[272];\
2045 uint8_t halfV[256];\
2046 uint8_t halfHV[256];\
2047 copy_block17(full, src, 24, stride, 17);\
2048 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2049 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
2050 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2051 OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
2052}\
2053static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
2054 uint8_t full[24*17];\
2055 uint8_t halfH[272];\
2056 uint8_t halfHV[256];\
2057 copy_block17(full, src, 24, stride, 17);\
2058 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2059 put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
2060 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2061 OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
2062}\
2063void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
2064 uint8_t full[24*17];\
2065 uint8_t halfH[272];\
2066 uint8_t halfV[256];\
2067 uint8_t halfHV[256];\
2068 copy_block17(full, src, 24, stride, 17);\
2069 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2070 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
2071 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2072 OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
2073}\
2074static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
2075 uint8_t full[24*17];\
2076 uint8_t halfH[272];\
2077 uint8_t halfHV[256];\
2078 copy_block17(full, src, 24, stride, 17);\
2079 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2080 put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
2081 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2082 OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
2083}\
2084void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
2085 uint8_t full[24*17];\
2086 uint8_t halfH[272];\
2087 uint8_t halfV[256];\
2088 uint8_t halfHV[256];\
2089 copy_block17(full, src, 24, stride, 17);\
2090 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
2091 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
2092 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2093 OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
2094}\
2095static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
2096 uint8_t full[24*17];\
2097 uint8_t halfH[272];\
2098 uint8_t halfHV[256];\
2099 copy_block17(full, src, 24, stride, 17);\
2100 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2101 put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
2102 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2103 OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
2104}\
2105static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
2106 uint8_t halfH[272];\
2107 uint8_t halfHV[256];\
2108 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
2109 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2110 OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
2111}\
2112static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
2113 uint8_t halfH[272];\
2114 uint8_t halfHV[256];\
2115 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
2116 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2117 OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
2118}\
2119void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
2120 uint8_t full[24*17];\
2121 uint8_t halfH[272];\
2122 uint8_t halfV[256];\
2123 uint8_t halfHV[256];\
2124 copy_block17(full, src, 24, stride, 17);\
2125 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2126 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
2127 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2128 OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
2129}\
2130static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
2131 uint8_t full[24*17];\
2132 uint8_t halfH[272];\
2133 copy_block17(full, src, 24, stride, 17);\
2134 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2135 put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
2136 OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
2137}\
2138void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
2139 uint8_t full[24*17];\
2140 uint8_t halfH[272];\
2141 uint8_t halfV[256];\
2142 uint8_t halfHV[256];\
2143 copy_block17(full, src, 24, stride, 17);\
2144 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2145 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
2146 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2147 OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
2148}\
2149static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
2150 uint8_t full[24*17];\
2151 uint8_t halfH[272];\
2152 copy_block17(full, src, 24, stride, 17);\
2153 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2154 put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
2155 OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
2156}\
2157static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
2158 uint8_t halfH[272];\
2159 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
2160 OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
2161}
2162
2163#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
2164#define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
2165#define op_put(a, b) a = cm[((b) + 16)>>5]
2166#define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
2167
2168QPEL_MC(0, put_ , _ , op_put)
2169QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
2170QPEL_MC(0, avg_ , _ , op_avg)
2171//QPEL_MC(1, avg_no_rnd , _ , op_avg)
2172#undef op_avg
2173#undef op_avg_no_rnd
2174#undef op_put
2175#undef op_put_no_rnd
2176
2177#if 1
2178#define H264_LOWPASS(OPNAME, OP, OP2) \
2179static av_unused void OPNAME ## h264_qpel2_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2180 const int h=2;\
2181 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2182 int i;\
2183 for(i=0; i<h; i++)\
2184 {\
2185 OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
2186 OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
2187 dst+=dstStride;\
2188 src+=srcStride;\
2189 }\
2190}\
2191\
2192static av_unused void OPNAME ## h264_qpel2_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2193 const int w=2;\
2194 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2195 int i;\
2196 for(i=0; i<w; i++)\
2197 {\
2198 const int srcB= src[-2*srcStride];\
2199 const int srcA= src[-1*srcStride];\
2200 const int src0= src[0 *srcStride];\
2201 const int src1= src[1 *srcStride];\
2202 const int src2= src[2 *srcStride];\
2203 const int src3= src[3 *srcStride];\
2204 const int src4= src[4 *srcStride];\
2205 OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
2206 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
2207 dst++;\
2208 src++;\
2209 }\
2210}\
2211\
2212static av_unused void OPNAME ## h264_qpel2_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
2213 const int h=2;\
2214 const int w=2;\
2215 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2216 int i;\
2217 src -= 2*srcStride;\
2218 for(i=0; i<h+5; i++)\
2219 {\
2220 tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
2221 tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
2222 tmp+=tmpStride;\
2223 src+=srcStride;\
2224 }\
2225 tmp -= tmpStride*(h+5-2);\
2226 for(i=0; i<w; i++)\
2227 {\
2228 const int tmpB= tmp[-2*tmpStride];\
2229 const int tmpA= tmp[-1*tmpStride];\
2230 const int tmp0= tmp[0 *tmpStride];\
2231 const int tmp1= tmp[1 *tmpStride];\
2232 const int tmp2= tmp[2 *tmpStride];\
2233 const int tmp3= tmp[3 *tmpStride];\
2234 const int tmp4= tmp[4 *tmpStride];\
2235 OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
2236 OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
2237 dst++;\
2238 tmp++;\
2239 }\
2240}\
2241static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2242 const int h=4;\
2243 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2244 int i;\
2245 for(i=0; i<h; i++)\
2246 {\
2247 OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
2248 OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
2249 OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
2250 OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
2251 dst+=dstStride;\
2252 src+=srcStride;\
2253 }\
2254}\
2255\
2256static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2257 const int w=4;\
2258 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2259 int i;\
2260 for(i=0; i<w; i++)\
2261 {\
2262 const int srcB= src[-2*srcStride];\
2263 const int srcA= src[-1*srcStride];\
2264 const int src0= src[0 *srcStride];\
2265 const int src1= src[1 *srcStride];\
2266 const int src2= src[2 *srcStride];\
2267 const int src3= src[3 *srcStride];\
2268 const int src4= src[4 *srcStride];\
2269 const int src5= src[5 *srcStride];\
2270 const int src6= src[6 *srcStride];\
2271 OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
2272 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
2273 OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
2274 OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
2275 dst++;\
2276 src++;\
2277 }\
2278}\
2279\
2280static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
2281 const int h=4;\
2282 const int w=4;\
2283 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2284 int i;\
2285 src -= 2*srcStride;\
2286 for(i=0; i<h+5; i++)\
2287 {\
2288 tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
2289 tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
2290 tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\
2291 tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\
2292 tmp+=tmpStride;\
2293 src+=srcStride;\
2294 }\
2295 tmp -= tmpStride*(h+5-2);\
2296 for(i=0; i<w; i++)\
2297 {\
2298 const int tmpB= tmp[-2*tmpStride];\
2299 const int tmpA= tmp[-1*tmpStride];\
2300 const int tmp0= tmp[0 *tmpStride];\
2301 const int tmp1= tmp[1 *tmpStride];\
2302 const int tmp2= tmp[2 *tmpStride];\
2303 const int tmp3= tmp[3 *tmpStride];\
2304 const int tmp4= tmp[4 *tmpStride];\
2305 const int tmp5= tmp[5 *tmpStride];\
2306 const int tmp6= tmp[6 *tmpStride];\
2307 OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
2308 OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
2309 OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
2310 OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
2311 dst++;\
2312 tmp++;\
2313 }\
2314}\
2315\
2316static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2317 const int h=8;\
2318 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2319 int i;\
2320 for(i=0; i<h; i++)\
2321 {\
2322 OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
2323 OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
2324 OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
2325 OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
2326 OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
2327 OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
2328 OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
2329 OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
2330 dst+=dstStride;\
2331 src+=srcStride;\
2332 }\
2333}\
2334\
2335static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2336 const int w=8;\
2337 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2338 int i;\
2339 for(i=0; i<w; i++)\
2340 {\
2341 const int srcB= src[-2*srcStride];\
2342 const int srcA= src[-1*srcStride];\
2343 const int src0= src[0 *srcStride];\
2344 const int src1= src[1 *srcStride];\
2345 const int src2= src[2 *srcStride];\
2346 const int src3= src[3 *srcStride];\
2347 const int src4= src[4 *srcStride];\
2348 const int src5= src[5 *srcStride];\
2349 const int src6= src[6 *srcStride];\
2350 const int src7= src[7 *srcStride];\
2351 const int src8= src[8 *srcStride];\
2352 const int src9= src[9 *srcStride];\
2353 const int src10=src[10*srcStride];\
2354 OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
2355 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
2356 OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
2357 OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
2358 OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
2359 OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
2360 OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
2361 OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
2362 dst++;\
2363 src++;\
2364 }\
2365}\
2366\
2367static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
2368 const int h=8;\
2369 const int w=8;\
2370 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2371 int i;\
2372 src -= 2*srcStride;\
2373 for(i=0; i<h+5; i++)\
2374 {\
2375 tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\
2376 tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\
2377 tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\
2378 tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\
2379 tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\
2380 tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\
2381 tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\
2382 tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\
2383 tmp+=tmpStride;\
2384 src+=srcStride;\
2385 }\
2386 tmp -= tmpStride*(h+5-2);\
2387 for(i=0; i<w; i++)\
2388 {\
2389 const int tmpB= tmp[-2*tmpStride];\
2390 const int tmpA= tmp[-1*tmpStride];\
2391 const int tmp0= tmp[0 *tmpStride];\
2392 const int tmp1= tmp[1 *tmpStride];\
2393 const int tmp2= tmp[2 *tmpStride];\
2394 const int tmp3= tmp[3 *tmpStride];\
2395 const int tmp4= tmp[4 *tmpStride];\
2396 const int tmp5= tmp[5 *tmpStride];\
2397 const int tmp6= tmp[6 *tmpStride];\
2398 const int tmp7= tmp[7 *tmpStride];\
2399 const int tmp8= tmp[8 *tmpStride];\
2400 const int tmp9= tmp[9 *tmpStride];\
2401 const int tmp10=tmp[10*tmpStride];\
2402 OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
2403 OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
2404 OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
2405 OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
2406 OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
2407 OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
2408 OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
2409 OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
2410 dst++;\
2411 tmp++;\
2412 }\
2413}\
2414\
2415static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2416 OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
2417 OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
2418 src += 8*srcStride;\
2419 dst += 8*dstStride;\
2420 OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
2421 OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
2422}\
2423\
2424static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2425 OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
2426 OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
2427 src += 8*srcStride;\
2428 dst += 8*dstStride;\
2429 OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
2430 OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
2431}\
2432\
2433static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
2434 OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
2435 OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
2436 src += 8*srcStride;\
2437 dst += 8*dstStride;\
2438 OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
2439 OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
2440}\
2441
2442#define H264_MC(OPNAME, SIZE) \
2443static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
2444 OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
2445}\
2446\
2447static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
2448 uint8_t half[SIZE*SIZE];\
2449 put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
2450 OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\
2451}\
2452\
2453static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
2454 OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
2455}\
2456\
2457static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
2458 uint8_t half[SIZE*SIZE];\
2459 put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
2460 OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\
2461}\
2462\
2463static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
2464 uint8_t full[SIZE*(SIZE+5)];\
2465 uint8_t * const full_mid= full + SIZE*2;\
2466 uint8_t half[SIZE*SIZE];\
2467 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
2468 put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
2469 OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
2470}\
2471\
2472static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
2473 uint8_t full[SIZE*(SIZE+5)];\
2474 uint8_t * const full_mid= full + SIZE*2;\
2475 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
2476 OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
2477}\
2478\
2479static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
2480 uint8_t full[SIZE*(SIZE+5)];\
2481 uint8_t * const full_mid= full + SIZE*2;\
2482 uint8_t half[SIZE*SIZE];\
2483 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
2484 put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
2485 OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
2486}\
2487\
2488static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
2489 uint8_t full[SIZE*(SIZE+5)];\
2490 uint8_t * const full_mid= full + SIZE*2;\
2491 uint8_t halfH[SIZE*SIZE];\
2492 uint8_t halfV[SIZE*SIZE];\
2493 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
2494 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
2495 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
2496 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
2497}\
2498\
2499static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
2500 uint8_t full[SIZE*(SIZE+5)];\
2501 uint8_t * const full_mid= full + SIZE*2;\
2502 uint8_t halfH[SIZE*SIZE];\
2503 uint8_t halfV[SIZE*SIZE];\
2504 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
2505 copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
2506 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
2507 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
2508}\
2509\
2510static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
2511 uint8_t full[SIZE*(SIZE+5)];\
2512 uint8_t * const full_mid= full + SIZE*2;\
2513 uint8_t halfH[SIZE*SIZE];\
2514 uint8_t halfV[SIZE*SIZE];\
2515 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
2516 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
2517 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
2518 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
2519}\
2520\
2521static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
2522 uint8_t full[SIZE*(SIZE+5)];\
2523 uint8_t * const full_mid= full + SIZE*2;\
2524 uint8_t halfH[SIZE*SIZE];\
2525 uint8_t halfV[SIZE*SIZE];\
2526 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
2527 copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
2528 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
2529 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
2530}\
2531\
2532static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
2533 int16_t tmp[SIZE*(SIZE+5)];\
2534 OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
2535}\
2536\
2537static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
2538 int16_t tmp[SIZE*(SIZE+5)];\
2539 uint8_t halfH[SIZE*SIZE];\
2540 uint8_t halfHV[SIZE*SIZE];\
2541 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
2542 put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
2543 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
2544}\
2545\
2546static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
2547 int16_t tmp[SIZE*(SIZE+5)];\
2548 uint8_t halfH[SIZE*SIZE];\
2549 uint8_t halfHV[SIZE*SIZE];\
2550 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
2551 put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
2552 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
2553}\
2554\
2555static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
2556 uint8_t full[SIZE*(SIZE+5)];\
2557 uint8_t * const full_mid= full + SIZE*2;\
2558 int16_t tmp[SIZE*(SIZE+5)];\
2559 uint8_t halfV[SIZE*SIZE];\
2560 uint8_t halfHV[SIZE*SIZE];\
2561 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
2562 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
2563 put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
2564 OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
2565}\
2566\
2567static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
2568 uint8_t full[SIZE*(SIZE+5)];\
2569 uint8_t * const full_mid= full + SIZE*2;\
2570 int16_t tmp[SIZE*(SIZE+5)];\
2571 uint8_t halfV[SIZE*SIZE];\
2572 uint8_t halfHV[SIZE*SIZE];\
2573 copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
2574 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
2575 put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
2576 OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
2577}\
2578
2579#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
2580//#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
2581#define op_put(a, b) a = cm[((b) + 16)>>5]
2582#define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1)
2583#define op2_put(a, b) a = cm[((b) + 512)>>10]
2584
2585H264_LOWPASS(put_ , op_put, op2_put)
2586H264_LOWPASS(avg_ , op_avg, op2_avg)
2587H264_MC(put_, 2)
2588H264_MC(put_, 4)
2589H264_MC(put_, 8)
2590H264_MC(put_, 16)
2591H264_MC(avg_, 4)
2592H264_MC(avg_, 8)
2593H264_MC(avg_, 16)
2594
2595#undef op_avg
2596#undef op_put
2597#undef op2_avg
2598#undef op2_put
2599#endif
2600
2601static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
2602 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
2603 int i;
2604
2605 for(i=0; i<h; i++){
2606 dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
2607 dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
2608 dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
2609 dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
2610 dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
2611 dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
2612 dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
2613 dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
2614 dst+=dstStride;
2615 src+=srcStride;
2616 }
2617}
2618
2619#if CONFIG_CAVS_DECODER
2620/* AVS specific */
2621void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
2622 put_pixels8_c(dst, src, stride, 8);
2623}
2624void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
2625 avg_pixels8_c(dst, src, stride, 8);
2626}
2627void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
2628 put_pixels16_c(dst, src, stride, 16);
2629}
2630void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
2631 avg_pixels16_c(dst, src, stride, 16);
2632}
2633#endif /* CONFIG_CAVS_DECODER */
2634
2635#if CONFIG_VC1_DECODER
2636/* VC-1 specific */
2637void ff_put_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
2638 put_pixels8_c(dst, src, stride, 8);
2639}
2640void ff_avg_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
2641 avg_pixels8_c(dst, src, stride, 8);
2642}
2643#endif /* CONFIG_VC1_DECODER */
2644
2645#if CONFIG_RV40_DECODER
2646static void put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
2647 put_pixels16_xy2_c(dst, src, stride, 16);
2648}
2649static void avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
2650 avg_pixels16_xy2_c(dst, src, stride, 16);
2651}
2652static void put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
2653 put_pixels8_xy2_c(dst, src, stride, 8);
2654}
2655static void avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
2656 avg_pixels8_xy2_c(dst, src, stride, 8);
2657}
2658#endif /* CONFIG_RV40_DECODER */
2659
2660static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
2661 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
2662 int i;
2663
2664 for(i=0; i<w; i++){
2665 const int src_1= src[ -srcStride];
2666 const int src0 = src[0 ];
2667 const int src1 = src[ srcStride];
2668 const int src2 = src[2*srcStride];
2669 const int src3 = src[3*srcStride];
2670 const int src4 = src[4*srcStride];
2671 const int src5 = src[5*srcStride];
2672 const int src6 = src[6*srcStride];
2673 const int src7 = src[7*srcStride];
2674 const int src8 = src[8*srcStride];
2675 const int src9 = src[9*srcStride];
2676 dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
2677 dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
2678 dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
2679 dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
2680 dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
2681 dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
2682 dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
2683 dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
2684 src++;
2685 dst++;
2686 }
2687}
2688
2689static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
2690 put_pixels8_c(dst, src, stride, 8);
2691}
2692
2693static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
2694 uint8_t half[64];
2695 wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
2696 put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
2697}
2698
2699static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
2700 wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
2701}
2702
2703static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
2704 uint8_t half[64];
2705 wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
2706 put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
2707}
2708
2709static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
2710 wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
2711}
2712
2713static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
2714 uint8_t halfH[88];
2715 uint8_t halfV[64];
2716 uint8_t halfHV[64];
2717 wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
2718 wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
2719 wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
2720 put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
2721}
2722static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
2723 uint8_t halfH[88];
2724 uint8_t halfV[64];
2725 uint8_t halfHV[64];
2726 wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
2727 wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
2728 wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
2729 put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
2730}
2731static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
2732 uint8_t halfH[88];
2733 wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
2734 wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
2735}
2736
2737static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
2738 if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
2739 int x;
2740 const int strength= ff_h263_loop_filter_strength[qscale];
2741
2742 for(x=0; x<8; x++){
2743 int d1, d2, ad1;
2744 int p0= src[x-2*stride];
2745 int p1= src[x-1*stride];
2746 int p2= src[x+0*stride];
2747 int p3= src[x+1*stride];
2748 int d = (p0 - p3 + 4*(p2 - p1)) / 8;
2749
2750 if (d<-2*strength) d1= 0;
2751 else if(d<- strength) d1=-2*strength - d;
2752 else if(d< strength) d1= d;
2753 else if(d< 2*strength) d1= 2*strength - d;
2754 else d1= 0;
2755
2756 p1 += d1;
2757 p2 -= d1;
2758 if(p1&256) p1= ~(p1>>31);
2759 if(p2&256) p2= ~(p2>>31);
2760
2761 src[x-1*stride] = p1;
2762 src[x+0*stride] = p2;
2763
2764 ad1= FFABS(d1)>>1;
2765
2766 d2= av_clip((p0-p3)/4, -ad1, ad1);
2767
2768 src[x-2*stride] = p0 - d2;
2769 src[x+ stride] = p3 + d2;
2770 }
2771 }
2772}
2773
2774static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
2775 if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
2776 int y;
2777 const int strength= ff_h263_loop_filter_strength[qscale];
2778
2779 for(y=0; y<8; y++){
2780 int d1, d2, ad1;
2781 int p0= src[y*stride-2];
2782 int p1= src[y*stride-1];
2783 int p2= src[y*stride+0];
2784 int p3= src[y*stride+1];
2785 int d = (p0 - p3 + 4*(p2 - p1)) / 8;
2786
2787 if (d<-2*strength) d1= 0;
2788 else if(d<- strength) d1=-2*strength - d;
2789 else if(d< strength) d1= d;
2790 else if(d< 2*strength) d1= 2*strength - d;
2791 else d1= 0;
2792
2793 p1 += d1;
2794 p2 -= d1;
2795 if(p1&256) p1= ~(p1>>31);
2796 if(p2&256) p2= ~(p2>>31);
2797
2798 src[y*stride-1] = p1;
2799 src[y*stride+0] = p2;
2800
2801 ad1= FFABS(d1)>>1;
2802
2803 d2= av_clip((p0-p3)/4, -ad1, ad1);
2804
2805 src[y*stride-2] = p0 - d2;
2806 src[y*stride+1] = p3 + d2;
2807 }
2808 }
2809}
2810
2811static void h261_loop_filter_c(uint8_t *src, int stride){
2812 int x,y,xy,yz;
2813 int temp[64];
2814
2815 for(x=0; x<8; x++){
2816 temp[x ] = 4*src[x ];
2817 temp[x + 7*8] = 4*src[x + 7*stride];
2818 }
2819 for(y=1; y<7; y++){
2820 for(x=0; x<8; x++){
2821 xy = y * stride + x;
2822 yz = y * 8 + x;
2823 temp[yz] = src[xy - stride] + 2*src[xy] + src[xy + stride];
2824 }
2825 }
2826
2827 for(y=0; y<8; y++){
2828 src[ y*stride] = (temp[ y*8] + 2)>>2;
2829 src[7+y*stride] = (temp[7+y*8] + 2)>>2;
2830 for(x=1; x<7; x++){
2831 xy = y * stride + x;
2832 yz = y * 8 + x;
2833 src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4;
2834 }
2835 }
2836}
2837
2838static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
2839{
2840 int s, i;
2841
2842 s = 0;
2843 for(i=0;i<h;i++) {
2844 s += abs(pix1[0] - pix2[0]);
2845 s += abs(pix1[1] - pix2[1]);
2846 s += abs(pix1[2] - pix2[2]);
2847 s += abs(pix1[3] - pix2[3]);
2848 s += abs(pix1[4] - pix2[4]);
2849 s += abs(pix1[5] - pix2[5]);
2850 s += abs(pix1[6] - pix2[6]);
2851 s += abs(pix1[7] - pix2[7]);
2852 s += abs(pix1[8] - pix2[8]);
2853 s += abs(pix1[9] - pix2[9]);
2854 s += abs(pix1[10] - pix2[10]);
2855 s += abs(pix1[11] - pix2[11]);
2856 s += abs(pix1[12] - pix2[12]);
2857 s += abs(pix1[13] - pix2[13]);
2858 s += abs(pix1[14] - pix2[14]);
2859 s += abs(pix1[15] - pix2[15]);
2860 pix1 += line_size;
2861 pix2 += line_size;
2862 }
2863 return s;
2864}
2865
2866static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
2867{
2868 int s, i;
2869
2870 s = 0;
2871 for(i=0;i<h;i++) {
2872 s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
2873 s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
2874 s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
2875 s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
2876 s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
2877 s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
2878 s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
2879 s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
2880 s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
2881 s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
2882 s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
2883 s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
2884 s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
2885 s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
2886 s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
2887 s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
2888 pix1 += line_size;
2889 pix2 += line_size;
2890 }
2891 return s;
2892}
2893
2894static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
2895{
2896 int s, i;
2897 uint8_t *pix3 = pix2 + line_size;
2898
2899 s = 0;
2900 for(i=0;i<h;i++) {
2901 s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
2902 s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
2903 s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
2904 s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
2905 s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
2906 s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
2907 s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
2908 s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
2909 s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
2910 s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
2911 s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
2912 s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
2913 s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
2914 s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
2915 s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
2916 s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
2917 pix1 += line_size;
2918 pix2 += line_size;
2919 pix3 += line_size;
2920 }
2921 return s;
2922}
2923
2924static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
2925{
2926 int s, i;
2927 uint8_t *pix3 = pix2 + line_size;
2928
2929 s = 0;
2930 for(i=0;i<h;i++) {
2931 s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
2932 s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
2933 s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
2934 s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
2935 s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
2936 s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
2937 s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
2938 s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
2939 s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
2940 s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
2941 s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
2942 s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
2943 s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
2944 s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
2945 s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
2946 s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
2947 pix1 += line_size;
2948 pix2 += line_size;
2949 pix3 += line_size;
2950 }
2951 return s;
2952}
2953
2954static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
2955{
2956 int s, i;
2957
2958 s = 0;
2959 for(i=0;i<h;i++) {
2960 s += abs(pix1[0] - pix2[0]);
2961 s += abs(pix1[1] - pix2[1]);
2962 s += abs(pix1[2] - pix2[2]);
2963 s += abs(pix1[3] - pix2[3]);
2964 s += abs(pix1[4] - pix2[4]);
2965 s += abs(pix1[5] - pix2[5]);
2966 s += abs(pix1[6] - pix2[6]);
2967 s += abs(pix1[7] - pix2[7]);
2968 pix1 += line_size;
2969 pix2 += line_size;
2970 }
2971 return s;
2972}
2973
2974static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
2975{
2976 int s, i;
2977
2978 s = 0;
2979 for(i=0;i<h;i++) {
2980 s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
2981 s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
2982 s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
2983 s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
2984 s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
2985 s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
2986 s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
2987 s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
2988 pix1 += line_size;
2989 pix2 += line_size;
2990 }
2991 return s;
2992}
2993
2994static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
2995{
2996 int s, i;
2997 uint8_t *pix3 = pix2 + line_size;
2998
2999 s = 0;
3000 for(i=0;i<h;i++) {
3001 s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
3002 s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
3003 s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
3004 s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
3005 s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
3006 s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
3007 s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
3008 s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
3009 pix1 += line_size;
3010 pix2 += line_size;
3011 pix3 += line_size;
3012 }
3013 return s;
3014}
3015
3016static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
3017{
3018 int s, i;
3019 uint8_t *pix3 = pix2 + line_size;
3020
3021 s = 0;
3022 for(i=0;i<h;i++) {
3023 s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
3024 s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
3025 s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
3026 s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
3027 s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
3028 s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
3029 s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
3030 s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
3031 pix1 += line_size;
3032 pix2 += line_size;
3033 pix3 += line_size;
3034 }
3035 return s;
3036}
3037
3038static int nsse16_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
3039 MpegEncContext *c = v;
3040 int score1=0;
3041 int score2=0;
3042 int x,y;
3043
3044 for(y=0; y<h; y++){
3045 for(x=0; x<16; x++){
3046 score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
3047 }
3048 if(y+1<h){
3049 for(x=0; x<15; x++){
3050 score2+= FFABS( s1[x ] - s1[x +stride]
3051 - s1[x+1] + s1[x+1+stride])
3052 -FFABS( s2[x ] - s2[x +stride]
3053 - s2[x+1] + s2[x+1+stride]);
3054 }
3055 }
3056 s1+= stride;
3057 s2+= stride;
3058 }
3059
3060 if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
3061 else return score1 + FFABS(score2)*8;
3062}
3063
3064static int nsse8_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
3065 MpegEncContext *c = v;
3066 int score1=0;
3067 int score2=0;
3068 int x,y;
3069
3070 for(y=0; y<h; y++){
3071 for(x=0; x<8; x++){
3072 score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
3073 }
3074 if(y+1<h){
3075 for(x=0; x<7; x++){
3076 score2+= FFABS( s1[x ] - s1[x +stride]
3077 - s1[x+1] + s1[x+1+stride])
3078 -FFABS( s2[x ] - s2[x +stride]
3079 - s2[x+1] + s2[x+1+stride]);
3080 }
3081 }
3082 s1+= stride;
3083 s2+= stride;
3084 }
3085
3086 if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
3087 else return score1 + FFABS(score2)*8;
3088}
3089
3090static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
3091 int i;
3092 unsigned int sum=0;
3093
3094 for(i=0; i<8*8; i++){
3095 int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
3096 int w= weight[i];
3097 b>>= RECON_SHIFT;
3098 assert(-512<b && b<512);
3099
3100 sum += (w*b)*(w*b)>>4;
3101 }
3102 return sum>>2;
3103}
3104
3105static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
3106 int i;
3107
3108 for(i=0; i<8*8; i++){
3109 rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
3110 }
3111}
3112
3113/**
3114 * permutes an 8x8 block.
3115 * @param block the block which will be permuted according to the given permutation vector
3116 * @param permutation the permutation vector
3117 * @param last the last non zero coefficient in scantable order, used to speed the permutation up
3118 * @param scantable the used scantable, this is only used to speed the permutation up, the block is not
3119 * (inverse) permutated to scantable order!
3120 */
3121void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
3122{
3123 int i;
3124 DCTELEM temp[64];
3125
3126 if(last<=0) return;
3127 //if(permutation[1]==1) return; //FIXME it is ok but not clean and might fail for some permutations
3128
3129 for(i=0; i<=last; i++){
3130 const int j= scantable[i];
3131 temp[j]= block[j];
3132 block[j]=0;
3133 }
3134
3135 for(i=0; i<=last; i++){
3136 const int j= scantable[i];
3137 const int perm_j= permutation[j];
3138 block[perm_j]= temp[j];
3139 }
3140}
3141
3142static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
3143 return 0;
3144}
3145
3146void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
3147 int i;
3148
3149 memset(cmp, 0, sizeof(void*)*6);
3150
3151 for(i=0; i<6; i++){
3152 switch(type&0xFF){
3153 case FF_CMP_SAD:
3154 cmp[i]= c->sad[i];
3155 break;
3156 case FF_CMP_SATD:
3157 cmp[i]= c->hadamard8_diff[i];
3158 break;
3159 case FF_CMP_SSE:
3160 cmp[i]= c->sse[i];
3161 break;
3162 case FF_CMP_DCT:
3163 cmp[i]= c->dct_sad[i];
3164 break;
3165 case FF_CMP_DCT264:
3166 cmp[i]= c->dct264_sad[i];
3167 break;
3168 case FF_CMP_DCTMAX:
3169 cmp[i]= c->dct_max[i];
3170 break;
3171 case FF_CMP_PSNR:
3172 cmp[i]= c->quant_psnr[i];
3173 break;
3174 case FF_CMP_BIT:
3175 cmp[i]= c->bit[i];
3176 break;
3177 case FF_CMP_RD:
3178 cmp[i]= c->rd[i];
3179 break;
3180 case FF_CMP_VSAD:
3181 cmp[i]= c->vsad[i];
3182 break;
3183 case FF_CMP_VSSE:
3184 cmp[i]= c->vsse[i];
3185 break;
3186 case FF_CMP_ZERO:
3187 cmp[i]= zero_cmp;
3188 break;
3189 case FF_CMP_NSSE:
3190 cmp[i]= c->nsse[i];
3191 break;
3192#if CONFIG_DWT
3193 case FF_CMP_W53:
3194 cmp[i]= c->w53[i];
3195 break;
3196 case FF_CMP_W97:
3197 cmp[i]= c->w97[i];
3198 break;
3199#endif
3200 default:
3201 av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
3202 }
3203 }
3204}
3205
3206static void clear_block_c(DCTELEM *block)
3207{
3208 memset(block, 0, sizeof(DCTELEM)*64);
3209}
3210
3211/**
3212 * memset(blocks, 0, sizeof(DCTELEM)*6*64)
3213 */
3214static void clear_blocks_c(DCTELEM *blocks)
3215{
3216 memset(blocks, 0, sizeof(DCTELEM)*6*64);
3217}
3218
3219static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
3220 long i;
3221 for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
3222 long a = *(long*)(src+i);
3223 long b = *(long*)(dst+i);
3224 *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
3225 }
3226 for(; i<w; i++)
3227 dst[i+0] += src[i+0];
3228}
3229
3230static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
3231 long i;
3232 for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
3233 long a = *(long*)(src1+i);
3234 long b = *(long*)(src2+i);
3235 *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
3236 }
3237 for(; i<w; i++)
3238 dst[i] = src1[i]+src2[i];
3239}
3240
3241static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
3242 long i;
3243#if !HAVE_FAST_UNALIGNED
3244 if((long)src2 & (sizeof(long)-1)){
3245 for(i=0; i+7<w; i+=8){
3246 dst[i+0] = src1[i+0]-src2[i+0];
3247 dst[i+1] = src1[i+1]-src2[i+1];
3248 dst[i+2] = src1[i+2]-src2[i+2];
3249 dst[i+3] = src1[i+3]-src2[i+3];
3250 dst[i+4] = src1[i+4]-src2[i+4];
3251 dst[i+5] = src1[i+5]-src2[i+5];
3252 dst[i+6] = src1[i+6]-src2[i+6];
3253 dst[i+7] = src1[i+7]-src2[i+7];
3254 }
3255 }else
3256#endif
3257 for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
3258 long a = *(long*)(src1+i);
3259 long b = *(long*)(src2+i);
3260 *(long*)(dst+i) = ((a|pb_80) - (b&pb_7f)) ^ ((a^b^pb_80)&pb_80);
3261 }
3262 for(; i<w; i++)
3263 dst[i+0] = src1[i+0]-src2[i+0];
3264}
3265
3266static void add_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const uint8_t *diff, int w, int *left, int *left_top){
3267 int i;
3268 uint8_t l, lt;
3269
3270 l= *left;
3271 lt= *left_top;
3272
3273 for(i=0; i<w; i++){
3274 l= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF) + diff[i];
3275 lt= src1[i];
3276 dst[i]= l;
3277 }
3278
3279 *left= l;
3280 *left_top= lt;
3281}
3282
3283static void sub_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top){
3284 int i;
3285 uint8_t l, lt;
3286
3287 l= *left;
3288 lt= *left_top;
3289
3290 for(i=0; i<w; i++){
3291 const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
3292 lt= src1[i];
3293 l= src2[i];
3294 dst[i]= l - pred;
3295 }
3296
3297 *left= l;
3298 *left_top= lt;
3299}
3300
3301static int add_hfyu_left_prediction_c(uint8_t *dst, const uint8_t *src, int w, int acc){
3302 int i;
3303
3304 for(i=0; i<w-1; i++){
3305 acc+= src[i];
3306 dst[i]= acc;
3307 i++;
3308 acc+= src[i];
3309 dst[i]= acc;
3310 }
3311
3312 for(; i<w; i++){
3313 acc+= src[i];
3314 dst[i]= acc;
3315 }
3316
3317 return acc;
3318}
3319
3320#if HAVE_BIGENDIAN
3321#define B 3
3322#define G 2
3323#define R 1
3324#define A 0
3325#else
3326#define B 0
3327#define G 1
3328#define R 2
3329#define A 3
3330#endif
3331static void add_hfyu_left_prediction_bgr32_c(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha){
3332 int i;
3333 int r,g,b,a;
3334 r= *red;
3335 g= *green;
3336 b= *blue;
3337 a= *alpha;
3338
3339 for(i=0; i<w; i++){
3340 b+= src[4*i+B];
3341 g+= src[4*i+G];
3342 r+= src[4*i+R];
3343 a+= src[4*i+A];
3344
3345 dst[4*i+B]= b;
3346 dst[4*i+G]= g;
3347 dst[4*i+R]= r;
3348 dst[4*i+A]= a;
3349 }
3350
3351 *red= r;
3352 *green= g;
3353 *blue= b;
3354 *alpha= a;
3355}
3356#undef B
3357#undef G
3358#undef R
3359#undef A
3360
3361#define BUTTERFLY2(o1,o2,i1,i2) \
3362o1= (i1)+(i2);\
3363o2= (i1)-(i2);
3364
3365#define BUTTERFLY1(x,y) \
3366{\
3367 int a,b;\
3368 a= x;\
3369 b= y;\
3370 x= a+b;\
3371 y= a-b;\
3372}
3373
3374#define BUTTERFLYA(x,y) (FFABS((x)+(y)) + FFABS((x)-(y)))
3375
3376static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
3377 int i;
3378 int temp[64];
3379 int sum=0;
3380
3381 assert(h==8);
3382
3383 for(i=0; i<8; i++){
3384 //FIXME try pointer walks
3385 BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0]-dst[stride*i+0],src[stride*i+1]-dst[stride*i+1]);
3386 BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2]-dst[stride*i+2],src[stride*i+3]-dst[stride*i+3]);
3387 BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4]-dst[stride*i+4],src[stride*i+5]-dst[stride*i+5]);
3388 BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6]-dst[stride*i+6],src[stride*i+7]-dst[stride*i+7]);
3389
3390 BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
3391 BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
3392 BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
3393 BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
3394
3395 BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
3396 BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
3397 BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
3398 BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
3399 }
3400
3401 for(i=0; i<8; i++){
3402 BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
3403 BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
3404 BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
3405 BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
3406
3407 BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
3408 BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
3409 BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
3410 BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
3411
3412 sum +=
3413 BUTTERFLYA(temp[8*0+i], temp[8*4+i])
3414 +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
3415 +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
3416 +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
3417 }
3418#if 0
3419static int maxi=0;
3420if(sum>maxi){
3421 maxi=sum;
3422 printf("MAX:%d\n", maxi);
3423}
3424#endif
3425 return sum;
3426}
3427
3428static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
3429 int i;
3430 int temp[64];
3431 int sum=0;
3432
3433 assert(h==8);
3434
3435 for(i=0; i<8; i++){
3436 //FIXME try pointer walks
3437 BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
3438 BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
3439 BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
3440 BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]);
3441
3442 BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
3443 BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
3444 BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
3445 BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
3446
3447 BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
3448 BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
3449 BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
3450 BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
3451 }
3452
3453 for(i=0; i<8; i++){
3454 BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
3455 BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
3456 BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
3457 BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
3458
3459 BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
3460 BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
3461 BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
3462 BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
3463
3464 sum +=
3465 BUTTERFLYA(temp[8*0+i], temp[8*4+i])
3466 +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
3467 +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
3468 +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
3469 }
3470
3471 sum -= FFABS(temp[8*0] + temp[8*4]); // -mean
3472
3473 return sum;
3474}
3475
3476static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
3477 MpegEncContext * const s= (MpegEncContext *)c;
3478 LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
3479
3480 assert(h==8);
3481
3482 s->dsp.diff_pixels(temp, src1, src2, stride);
3483 s->dsp.fdct(temp);
3484 return s->dsp.sum_abs_dctelem(temp);
3485}
3486
3487#if CONFIG_GPL
3488#define DCT8_1D {\
3489 const int s07 = SRC(0) + SRC(7);\
3490 const int s16 = SRC(1) + SRC(6);\
3491 const int s25 = SRC(2) + SRC(5);\
3492 const int s34 = SRC(3) + SRC(4);\
3493 const int a0 = s07 + s34;\
3494 const int a1 = s16 + s25;\
3495 const int a2 = s07 - s34;\
3496 const int a3 = s16 - s25;\
3497 const int d07 = SRC(0) - SRC(7);\
3498 const int d16 = SRC(1) - SRC(6);\
3499 const int d25 = SRC(2) - SRC(5);\
3500 const int d34 = SRC(3) - SRC(4);\
3501 const int a4 = d16 + d25 + (d07 + (d07>>1));\
3502 const int a5 = d07 - d34 - (d25 + (d25>>1));\
3503 const int a6 = d07 + d34 - (d16 + (d16>>1));\
3504 const int a7 = d16 - d25 + (d34 + (d34>>1));\
3505 DST(0, a0 + a1 ) ;\
3506 DST(1, a4 + (a7>>2)) ;\
3507 DST(2, a2 + (a3>>1)) ;\
3508 DST(3, a5 + (a6>>2)) ;\
3509 DST(4, a0 - a1 ) ;\
3510 DST(5, a6 - (a5>>2)) ;\
3511 DST(6, (a2>>1) - a3 ) ;\
3512 DST(7, (a4>>2) - a7 ) ;\
3513}
3514
3515static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
3516 MpegEncContext * const s= (MpegEncContext *)c;
3517 DCTELEM dct[8][8];
3518 int i;
3519 int sum=0;
3520
3521 s->dsp.diff_pixels(dct[0], src1, src2, stride);
3522
3523#define SRC(x) dct[i][x]
3524#define DST(x,v) dct[i][x]= v
3525 for( i = 0; i < 8; i++ )
3526 DCT8_1D
3527#undef SRC
3528#undef DST
3529
3530#define SRC(x) dct[x][i]
3531#define DST(x,v) sum += FFABS(v)
3532 for( i = 0; i < 8; i++ )
3533 DCT8_1D
3534#undef SRC
3535#undef DST
3536 return sum;
3537}
3538#endif
3539
3540static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
3541 MpegEncContext * const s= (MpegEncContext *)c;
3542 LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
3543 int sum=0, i;
3544
3545 assert(h==8);
3546
3547 s->dsp.diff_pixels(temp, src1, src2, stride);
3548 s->dsp.fdct(temp);
3549
3550 for(i=0; i<64; i++)
3551 sum= FFMAX(sum, FFABS(temp[i]));
3552
3553 return sum;
3554}
3555
3556static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
3557 MpegEncContext * const s= (MpegEncContext *)c;
3558 LOCAL_ALIGNED_16(DCTELEM, temp, [64*2]);
3559 DCTELEM * const bak = temp+64;
3560 int sum=0, i;
3561
3562 assert(h==8);
3563 s->mb_intra=0;
3564
3565 s->dsp.diff_pixels(temp, src1, src2, stride);
3566
3567 memcpy(bak, temp, 64*sizeof(DCTELEM));
3568
3569 s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
3570 s->dct_unquantize_inter(s, temp, 0, s->qscale);
3571 ff_simple_idct(temp); //FIXME
3572
3573 for(i=0; i<64; i++)
3574 sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
3575
3576 return sum;
3577}
3578
3579static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
3580 MpegEncContext * const s= (MpegEncContext *)c;
3581 const uint8_t *scantable= s->intra_scantable.permutated;
3582 LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
3583 LOCAL_ALIGNED_16(uint8_t, lsrc1, [64]);
3584 LOCAL_ALIGNED_16(uint8_t, lsrc2, [64]);
3585 int i, last, run, bits, level, distortion, start_i;
3586 const int esc_length= s->ac_esc_length;
3587 uint8_t * length;
3588 uint8_t * last_length;
3589
3590 assert(h==8);
3591
3592 copy_block8(lsrc1, src1, 8, stride, 8);
3593 copy_block8(lsrc2, src2, 8, stride, 8);
3594
3595 s->dsp.diff_pixels(temp, lsrc1, lsrc2, 8);
3596
3597 s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
3598
3599 bits=0;
3600
3601 if (s->mb_intra) {
3602 start_i = 1;
3603 length = s->intra_ac_vlc_length;
3604 last_length= s->intra_ac_vlc_last_length;
3605 bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
3606 } else {
3607 start_i = 0;
3608 length = s->inter_ac_vlc_length;
3609 last_length= s->inter_ac_vlc_last_length;
3610 }
3611
3612 if(last>=start_i){
3613 run=0;
3614 for(i=start_i; i<last; i++){
3615 int j= scantable[i];
3616 level= temp[j];
3617
3618 if(level){
3619 level+=64;
3620 if((level&(~127)) == 0){
3621 bits+= length[UNI_AC_ENC_INDEX(run, level)];
3622 }else
3623 bits+= esc_length;
3624 run=0;
3625 }else
3626 run++;
3627 }
3628 i= scantable[last];
3629
3630 level= temp[i] + 64;
3631
3632 assert(level - 64);
3633
3634 if((level&(~127)) == 0){
3635 bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
3636 }else
3637 bits+= esc_length;
3638
3639 }
3640
3641 if(last>=0){
3642 if(s->mb_intra)
3643 s->dct_unquantize_intra(s, temp, 0, s->qscale);
3644 else
3645 s->dct_unquantize_inter(s, temp, 0, s->qscale);
3646 }
3647
3648 s->dsp.idct_add(lsrc2, 8, temp);
3649
3650 distortion= s->dsp.sse[1](NULL, lsrc2, lsrc1, 8, 8);
3651
3652 return distortion + ((bits*s->qscale*s->qscale*109 + 64)>>7);
3653}
3654
3655static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
3656 MpegEncContext * const s= (MpegEncContext *)c;
3657 const uint8_t *scantable= s->intra_scantable.permutated;
3658 LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
3659 int i, last, run, bits, level, start_i;
3660 const int esc_length= s->ac_esc_length;
3661 uint8_t * length;
3662 uint8_t * last_length;
3663
3664 assert(h==8);
3665
3666 s->dsp.diff_pixels(temp, src1, src2, stride);
3667
3668 s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
3669
3670 bits=0;
3671
3672 if (s->mb_intra) {
3673 start_i = 1;
3674 length = s->intra_ac_vlc_length;
3675 last_length= s->intra_ac_vlc_last_length;
3676 bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
3677 } else {
3678 start_i = 0;
3679 length = s->inter_ac_vlc_length;
3680 last_length= s->inter_ac_vlc_last_length;
3681 }
3682
3683 if(last>=start_i){
3684 run=0;
3685 for(i=start_i; i<last; i++){
3686 int j= scantable[i];
3687 level= temp[j];
3688
3689 if(level){
3690 level+=64;
3691 if((level&(~127)) == 0){
3692 bits+= length[UNI_AC_ENC_INDEX(run, level)];
3693 }else
3694 bits+= esc_length;
3695 run=0;
3696 }else
3697 run++;
3698 }
3699 i= scantable[last];
3700
3701 level= temp[i] + 64;
3702
3703 assert(level - 64);
3704
3705 if((level&(~127)) == 0){
3706 bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
3707 }else
3708 bits+= esc_length;
3709 }
3710
3711 return bits;
3712}
3713
3714#define VSAD_INTRA(size) \
3715static int vsad_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
3716 int score=0; \
3717 int x,y; \
3718 \
3719 for(y=1; y<h; y++){ \
3720 for(x=0; x<size; x+=4){ \
3721 score+= FFABS(s[x ] - s[x +stride]) + FFABS(s[x+1] - s[x+1+stride]) \
3722 +FFABS(s[x+2] - s[x+2+stride]) + FFABS(s[x+3] - s[x+3+stride]); \
3723 } \
3724 s+= stride; \
3725 } \
3726 \
3727 return score; \
3728}
3729VSAD_INTRA(8)
3730VSAD_INTRA(16)
3731
3732static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
3733 int score=0;
3734 int x,y;
3735
3736 for(y=1; y<h; y++){
3737 for(x=0; x<16; x++){
3738 score+= FFABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
3739 }
3740 s1+= stride;
3741 s2+= stride;
3742 }
3743
3744 return score;
3745}
3746
3747#define SQ(a) ((a)*(a))
3748#define VSSE_INTRA(size) \
3749static int vsse_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
3750 int score=0; \
3751 int x,y; \
3752 \
3753 for(y=1; y<h; y++){ \
3754 for(x=0; x<size; x+=4){ \
3755 score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride]) \
3756 +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]); \
3757 } \
3758 s+= stride; \
3759 } \
3760 \
3761 return score; \
3762}
3763VSSE_INTRA(8)
3764VSSE_INTRA(16)
3765
3766static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
3767 int score=0;
3768 int x,y;
3769
3770 for(y=1; y<h; y++){
3771 for(x=0; x<16; x++){
3772 score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
3773 }
3774 s1+= stride;
3775 s2+= stride;
3776 }
3777
3778 return score;
3779}
3780
3781static int ssd_int8_vs_int16_c(const int8_t *pix1, const int16_t *pix2,
3782 int size){
3783 int score=0;
3784 int i;
3785 for(i=0; i<size; i++)
3786 score += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]);
3787 return score;
3788}
3789
3790WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
3791WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
3792WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
3793#if CONFIG_GPL
3794WRAPPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
3795#endif
3796WRAPPER8_16_SQ(dct_max8x8_c, dct_max16_c)
3797WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
3798WRAPPER8_16_SQ(rd8x8_c, rd16_c)
3799WRAPPER8_16_SQ(bit8x8_c, bit16_c)
3800
3801#endif /* 0 */
3802
3803static void vector_fmul_c(float *dst, const float *src, int len){
3804 int i;
3805 for(i=0; i<len; i++)
3806 dst[i] *= src[i];
3807}
3808
3809static void vector_fmul_reverse_c(float *dst, const float *src0, const float *src1, int len){
3810 int i;
3811 src1 += len-1;
3812 for(i=0; i<len; i++)
3813 dst[i] = src0[i] * src1[-i];
3814}
3815
3816static void vector_fmul_add_c(float *dst, const float *src0, const float *src1, const float *src2, int len){
3817 int i;
3818 for(i=0; i<len; i++)
3819 dst[i] = src0[i] * src1[i] + src2[i];
3820}
3821
3822void ff_vector_fmul_window_c(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len){
3823 int i,j;
3824 dst += len;
3825 win += len;
3826 src0+= len;
3827 for(i=-len, j=len-1; i<0; i++, j--) {
3828 float s0 = src0[i];
3829 float s1 = src1[j];
3830 float wi = win[i];
3831 float wj = win[j];
3832 dst[i] = s0*wj - s1*wi + add_bias;
3833 dst[j] = s0*wi + s1*wj + add_bias;
3834 }
3835}
3836
3837static void vector_fmul_scalar_c(float *dst, const float *src, float mul,
3838 int len)
3839{
3840 int i;
3841 for (i = 0; i < len; i++)
3842 dst[i] = src[i] * mul;
3843}
3844#if 0
3845static void vector_fmul_sv_scalar_2_c(float *dst, const float *src,
3846 const float **sv, float mul, int len)
3847{
3848 int i;
3849 for (i = 0; i < len; i += 2, sv++) {
3850 dst[i ] = src[i ] * sv[0][0] * mul;
3851 dst[i+1] = src[i+1] * sv[0][1] * mul;
3852 }
3853}
3854
3855static void vector_fmul_sv_scalar_4_c(float *dst, const float *src,
3856 const float **sv, float mul, int len)
3857{
3858 int i;
3859 for (i = 0; i < len; i += 4, sv++) {
3860 dst[i ] = src[i ] * sv[0][0] * mul;
3861 dst[i+1] = src[i+1] * sv[0][1] * mul;
3862 dst[i+2] = src[i+2] * sv[0][2] * mul;
3863 dst[i+3] = src[i+3] * sv[0][3] * mul;
3864 }
3865}
3866
3867static void sv_fmul_scalar_2_c(float *dst, const float **sv, float mul,
3868 int len)
3869{
3870 int i;
3871 for (i = 0; i < len; i += 2, sv++) {
3872 dst[i ] = sv[0][0] * mul;
3873 dst[i+1] = sv[0][1] * mul;
3874 }
3875}
3876
3877static void sv_fmul_scalar_4_c(float *dst, const float **sv, float mul,
3878 int len)
3879{
3880 int i;
3881 for (i = 0; i < len; i += 4, sv++) {
3882 dst[i ] = sv[0][0] * mul;
3883 dst[i+1] = sv[0][1] * mul;
3884 dst[i+2] = sv[0][2] * mul;
3885 dst[i+3] = sv[0][3] * mul;
3886 }
3887}
3888
3889static void butterflies_float_c(float *restrict v1, float *restrict v2,
3890 int len)
3891{
3892 int i;
3893 for (i = 0; i < len; i++) {
3894 float t = v1[i] - v2[i];
3895 v1[i] += v2[i];
3896 v2[i] = t;
3897 }
3898}
3899
3900static float scalarproduct_float_c(const float *v1, const float *v2, int len)
3901{
3902 float p = 0.0;
3903 int i;
3904
3905 for (i = 0; i < len; i++)
3906 p += v1[i] * v2[i];
3907
3908 return p;
3909}
3910
3911static void int32_to_float_fmul_scalar_c(float *dst, const int *src, float mul, int len){
3912 int i;
3913 for(i=0; i<len; i++)
3914 dst[i] = src[i] * mul;
3915}
3916
3917
3918static inline uint32_t clipf_c_one(uint32_t a, uint32_t mini,
3919 uint32_t maxi, uint32_t maxisign)
3920{
3921
3922 if(a > mini) return mini;
3923 else if((a^(1<<31)) > maxisign) return maxi;
3924 else return a;
3925}
3926
3927static void vector_clipf_c_opposite_sign(float *dst, const float *src, float *min, float *max, int len){
3928 int i;
3929 uint32_t mini = *(uint32_t*)min;
3930 uint32_t maxi = *(uint32_t*)max;
3931 uint32_t maxisign = maxi ^ (1<<31);
3932 uint32_t *dsti = (uint32_t*)dst;
3933 const uint32_t *srci = (const uint32_t*)src;
3934 for(i=0; i<len; i+=8) {
3935 dsti[i + 0] = clipf_c_one(srci[i + 0], mini, maxi, maxisign);
3936 dsti[i + 1] = clipf_c_one(srci[i + 1], mini, maxi, maxisign);
3937 dsti[i + 2] = clipf_c_one(srci[i + 2], mini, maxi, maxisign);
3938 dsti[i + 3] = clipf_c_one(srci[i + 3], mini, maxi, maxisign);
3939 dsti[i + 4] = clipf_c_one(srci[i + 4], mini, maxi, maxisign);
3940 dsti[i + 5] = clipf_c_one(srci[i + 5], mini, maxi, maxisign);
3941 dsti[i + 6] = clipf_c_one(srci[i + 6], mini, maxi, maxisign);
3942 dsti[i + 7] = clipf_c_one(srci[i + 7], mini, maxi, maxisign);
3943 }
3944}
3945static void vector_clipf_c(float *dst, const float *src, float min, float max, int len){
3946 int i;
3947 if(min < 0 && max > 0) {
3948 vector_clipf_c_opposite_sign(dst, src, &min, &max, len);
3949 } else {
3950 for(i=0; i < len; i+=8) {
3951 dst[i ] = av_clipf(src[i ], min, max);
3952 dst[i + 1] = av_clipf(src[i + 1], min, max);
3953 dst[i + 2] = av_clipf(src[i + 2], min, max);
3954 dst[i + 3] = av_clipf(src[i + 3], min, max);
3955 dst[i + 4] = av_clipf(src[i + 4], min, max);
3956 dst[i + 5] = av_clipf(src[i + 5], min, max);
3957 dst[i + 6] = av_clipf(src[i + 6], min, max);
3958 dst[i + 7] = av_clipf(src[i + 7], min, max);
3959 }
3960 }
3961}
3962
3963static av_always_inline int float_to_int16_one(const float *src){
3964 int_fast32_t tmp = *(const int32_t*)src;
3965 if(tmp & 0xf0000){
3966 tmp = (0x43c0ffff - tmp)>>31;
3967 // is this faster on some gcc/cpu combinations?
3968// if(tmp > 0x43c0ffff) tmp = 0xFFFF;
3969// else tmp = 0;
3970 }
3971 return tmp - 0x8000;
3972}
3973
3974void ff_float_to_int16_c(int16_t *dst, const float *src, long len){
3975 int i;
3976 for(i=0; i<len; i++)
3977 dst[i] = float_to_int16_one(src+i);
3978}
3979
3980void ff_float_to_int16_interleave_c(int16_t *dst, const float **src, long len, int channels){
3981 int i,j,c;
3982 if(channels==2){
3983 for(i=0; i<len; i++){
3984 dst[2*i] = float_to_int16_one(src[0]+i);
3985 dst[2*i+1] = float_to_int16_one(src[1]+i);
3986 }
3987 }else{
3988 for(c=0; c<channels; c++)
3989 for(i=0, j=c; i<len; i++, j+=channels)
3990 dst[j] = float_to_int16_one(src[c]+i);
3991 }
3992}
3993
3994static int32_t scalarproduct_int16_c(int16_t * v1, int16_t * v2, int order, int shift)
3995{
3996 int res = 0;
3997
3998 while (order--)
3999 res += (*v1++ * *v2++) >> shift;
4000
4001 return res;
4002}
4003
4004static int32_t scalarproduct_and_madd_int16_c(int16_t *v1, int16_t *v2, int16_t *v3, int order, int mul)
4005{
4006 int res = 0;
4007 while (order--) {
4008 res += *v1 * *v2++;
4009 *v1++ += mul * *v3++;
4010 }
4011 return res;
4012}
4013
4014#define W0 2048
4015#define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
4016#define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
4017#define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
4018#define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
4019#define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
4020#define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
4021#define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
4022
4023static void wmv2_idct_row(short * b)
4024{
4025 int s1,s2;
4026 int a0,a1,a2,a3,a4,a5,a6,a7;
4027 /*step 1*/
4028 a1 = W1*b[1]+W7*b[7];
4029 a7 = W7*b[1]-W1*b[7];
4030 a5 = W5*b[5]+W3*b[3];
4031 a3 = W3*b[5]-W5*b[3];
4032 a2 = W2*b[2]+W6*b[6];
4033 a6 = W6*b[2]-W2*b[6];
4034 a0 = W0*b[0]+W0*b[4];
4035 a4 = W0*b[0]-W0*b[4];
4036 /*step 2*/
4037 s1 = (181*(a1-a5+a7-a3)+128)>>8;//1,3,5,7,
4038 s2 = (181*(a1-a5-a7+a3)+128)>>8;
4039 /*step 3*/
4040 b[0] = (a0+a2+a1+a5 + (1<<7))>>8;
4041 b[1] = (a4+a6 +s1 + (1<<7))>>8;
4042 b[2] = (a4-a6 +s2 + (1<<7))>>8;
4043 b[3] = (a0-a2+a7+a3 + (1<<7))>>8;
4044 b[4] = (a0-a2-a7-a3 + (1<<7))>>8;
4045 b[5] = (a4-a6 -s2 + (1<<7))>>8;
4046 b[6] = (a4+a6 -s1 + (1<<7))>>8;
4047 b[7] = (a0+a2-a1-a5 + (1<<7))>>8;
4048}
4049static void wmv2_idct_col(short * b)
4050{
4051 int s1,s2;
4052 int a0,a1,a2,a3,a4,a5,a6,a7;
4053 /*step 1, with extended precision*/
4054 a1 = (W1*b[8*1]+W7*b[8*7] + 4)>>3;
4055 a7 = (W7*b[8*1]-W1*b[8*7] + 4)>>3;
4056 a5 = (W5*b[8*5]+W3*b[8*3] + 4)>>3;
4057 a3 = (W3*b[8*5]-W5*b[8*3] + 4)>>3;
4058 a2 = (W2*b[8*2]+W6*b[8*6] + 4)>>3;
4059 a6 = (W6*b[8*2]-W2*b[8*6] + 4)>>3;
4060 a0 = (W0*b[8*0]+W0*b[8*4] )>>3;
4061 a4 = (W0*b[8*0]-W0*b[8*4] )>>3;
4062 /*step 2*/
4063 s1 = (181*(a1-a5+a7-a3)+128)>>8;
4064 s2 = (181*(a1-a5-a7+a3)+128)>>8;
4065 /*step 3*/
4066 b[8*0] = (a0+a2+a1+a5 + (1<<13))>>14;
4067 b[8*1] = (a4+a6 +s1 + (1<<13))>>14;
4068 b[8*2] = (a4-a6 +s2 + (1<<13))>>14;
4069 b[8*3] = (a0-a2+a7+a3 + (1<<13))>>14;
4070
4071 b[8*4] = (a0-a2-a7-a3 + (1<<13))>>14;
4072 b[8*5] = (a4-a6 -s2 + (1<<13))>>14;
4073 b[8*6] = (a4+a6 -s1 + (1<<13))>>14;
4074 b[8*7] = (a0+a2-a1-a5 + (1<<13))>>14;
4075}
4076void ff_wmv2_idct_c(short * block){
4077 int i;
4078
4079 for(i=0;i<64;i+=8){
4080 wmv2_idct_row(block+i);
4081 }
4082 for(i=0;i<8;i++){
4083 wmv2_idct_col(block+i);
4084 }
4085}
4086/* XXX: those functions should be suppressed ASAP when all IDCTs are
4087 converted */
4088static void ff_wmv2_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block)
4089{
4090 ff_wmv2_idct_c(block);
4091 put_pixels_clamped_c(block, dest, line_size);
4092}
4093static void ff_wmv2_idct_add_c(uint8_t *dest, int line_size, DCTELEM *block)
4094{
4095 ff_wmv2_idct_c(block);
4096 add_pixels_clamped_c(block, dest, line_size);
4097}
4098static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
4099{
4100 j_rev_dct (block);
4101 put_pixels_clamped_c(block, dest, line_size);
4102}
4103static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
4104{
4105 j_rev_dct (block);
4106 add_pixels_clamped_c(block, dest, line_size);
4107}
4108
4109static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block)
4110{
4111 j_rev_dct4 (block);
4112 put_pixels_clamped4_c(block, dest, line_size);
4113}
4114static void ff_jref_idct4_add(uint8_t *dest, int line_size, DCTELEM *block)
4115{
4116 j_rev_dct4 (block);
4117 add_pixels_clamped4_c(block, dest, line_size);
4118}
4119
4120static void ff_jref_idct2_put(uint8_t *dest, int line_size, DCTELEM *block)
4121{
4122 j_rev_dct2 (block);
4123 put_pixels_clamped2_c(block, dest, line_size);
4124}
4125static void ff_jref_idct2_add(uint8_t *dest, int line_size, DCTELEM *block)
4126{
4127 j_rev_dct2 (block);
4128 add_pixels_clamped2_c(block, dest, line_size);
4129}
4130
4131static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block)
4132{
4133 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
4134
4135 dest[0] = cm[(block[0] + 4)>>3];
4136}
4137static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block)
4138{
4139 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
4140
4141 dest[0] = cm[dest[0] + ((block[0] + 4)>>3)];
4142}
4143
4144static void just_return(void *mem av_unused, int stride av_unused, int h av_unused) { return; }
4145
4146/* init static data */
4147av_cold void dsputil_static_init(void)
4148{
4149 int i;
4150
4151 for(i=0;i<256;i++) ff_cropTbl[i + MAX_NEG_CROP] = i;
4152 for(i=0;i<MAX_NEG_CROP;i++) {
4153 ff_cropTbl[i] = 0;
4154 ff_cropTbl[i + MAX_NEG_CROP + 256] = 255;
4155 }
4156
4157 for(i=0;i<512;i++) {
4158 ff_squareTbl[i] = (i - 256) * (i - 256);
4159 }
4160
4161 for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
4162}
4163
4164int ff_check_alignment(void){
4165 static int did_fail=0;
4166 DECLARE_ALIGNED(16, int, aligned);
4167
4168 if((intptr_t)&aligned & 15){
4169 if(!did_fail){
4170#if HAVE_MMX || HAVE_ALTIVEC
4171 av_log(NULL, AV_LOG_ERROR,
4172 "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
4173 "and may be very slow or crash. This is not a bug in libavcodec,\n"
4174 "but in the compiler. You may try recompiling using gcc >= 4.2.\n"
4175 "Do not report crashes to FFmpeg developers.\n");
4176#endif
4177 did_fail=1;
4178 }
4179 return -1;
4180 }
4181 return 0;
4182}
4183#endif
4184av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
4185{
4186#if 0
4187 int i;
4188
4189 ff_check_alignment();
4190
4191#if CONFIG_ENCODERS
4192 if(avctx->dct_algo==FF_DCT_FASTINT) {
4193 c->fdct = fdct_ifast;
4194 c->fdct248 = fdct_ifast248;
4195 }
4196 else if(avctx->dct_algo==FF_DCT_FAAN) {
4197 c->fdct = ff_faandct;
4198 c->fdct248 = ff_faandct248;
4199 }
4200 else {
4201 c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
4202 c->fdct248 = ff_fdct248_islow;
4203 }
4204#endif //CONFIG_ENCODERS
4205
4206 if(avctx->lowres==1){
4207 if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO || !CONFIG_H264_DECODER){
4208 c->idct_put= ff_jref_idct4_put;
4209 c->idct_add= ff_jref_idct4_add;
4210 }else{
4211 c->idct_put= ff_h264_lowres_idct_put_c;
4212 c->idct_add= ff_h264_lowres_idct_add_c;
4213 }
4214 c->idct = j_rev_dct4;
4215 c->idct_permutation_type= FF_NO_IDCT_PERM;
4216 }else if(avctx->lowres==2){
4217 c->idct_put= ff_jref_idct2_put;
4218 c->idct_add= ff_jref_idct2_add;
4219 c->idct = j_rev_dct2;
4220 c->idct_permutation_type= FF_NO_IDCT_PERM;
4221 }else if(avctx->lowres==3){
4222 c->idct_put= ff_jref_idct1_put;
4223 c->idct_add= ff_jref_idct1_add;
4224 c->idct = j_rev_dct1;
4225 c->idct_permutation_type= FF_NO_IDCT_PERM;
4226 }else{
4227 if(avctx->idct_algo==FF_IDCT_INT){
4228 c->idct_put= ff_jref_idct_put;
4229 c->idct_add= ff_jref_idct_add;
4230 c->idct = j_rev_dct;
4231 c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
4232 }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER ) &&
4233 avctx->idct_algo==FF_IDCT_VP3){
4234 c->idct_put= ff_vp3_idct_put_c;
4235 c->idct_add= ff_vp3_idct_add_c;
4236 c->idct = ff_vp3_idct_c;
4237 c->idct_permutation_type= FF_NO_IDCT_PERM;
4238 }else if(avctx->idct_algo==FF_IDCT_WMV2){
4239 c->idct_put= ff_wmv2_idct_put_c;
4240 c->idct_add= ff_wmv2_idct_add_c;
4241 c->idct = ff_wmv2_idct_c;
4242 c->idct_permutation_type= FF_NO_IDCT_PERM;
4243 }else if(avctx->idct_algo==FF_IDCT_FAAN){
4244 c->idct_put= ff_faanidct_put;
4245 c->idct_add= ff_faanidct_add;
4246 c->idct = ff_faanidct;
4247 c->idct_permutation_type= FF_NO_IDCT_PERM;
4248 }else if(CONFIG_EATGQ_DECODER && avctx->idct_algo==FF_IDCT_EA) {
4249 c->idct_put= ff_ea_idct_put_c;
4250 c->idct_permutation_type= FF_NO_IDCT_PERM;
4251 }else if(CONFIG_BINK_DECODER && avctx->idct_algo==FF_IDCT_BINK) {
4252 c->idct = ff_bink_idct_c;
4253 c->idct_add = ff_bink_idct_add_c;
4254 c->idct_put = ff_bink_idct_put_c;
4255 c->idct_permutation_type = FF_NO_IDCT_PERM;
4256 }else{ //accurate/default
4257 c->idct_put= ff_simple_idct_put;
4258 c->idct_add= ff_simple_idct_add;
4259 c->idct = ff_simple_idct;
4260 c->idct_permutation_type= FF_NO_IDCT_PERM;
4261 }
4262 }
4263
4264 c->get_pixels = get_pixels_c;
4265 c->diff_pixels = diff_pixels_c;
4266 c->put_pixels_clamped = put_pixels_clamped_c;
4267 c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
4268 c->put_pixels_nonclamped = put_pixels_nonclamped_c;
4269 c->add_pixels_clamped = add_pixels_clamped_c;
4270 c->add_pixels8 = add_pixels8_c;
4271 c->add_pixels4 = add_pixels4_c;
4272 c->sum_abs_dctelem = sum_abs_dctelem_c;
4273 c->gmc1 = gmc1_c;
4274 c->gmc = ff_gmc_c;
4275 c->clear_block = clear_block_c;
4276 c->clear_blocks = clear_blocks_c;
4277 c->pix_sum = pix_sum_c;
4278 c->pix_norm1 = pix_norm1_c;
4279
4280 c->fill_block_tab[0] = fill_block16_c;
4281 c->fill_block_tab[1] = fill_block8_c;
4282 c->scale_block = scale_block_c;
4283
4284 /* TODO [0] 16 [1] 8 */
4285 c->pix_abs[0][0] = pix_abs16_c;
4286 c->pix_abs[0][1] = pix_abs16_x2_c;
4287 c->pix_abs[0][2] = pix_abs16_y2_c;
4288 c->pix_abs[0][3] = pix_abs16_xy2_c;
4289 c->pix_abs[1][0] = pix_abs8_c;
4290 c->pix_abs[1][1] = pix_abs8_x2_c;
4291 c->pix_abs[1][2] = pix_abs8_y2_c;
4292 c->pix_abs[1][3] = pix_abs8_xy2_c;
4293
4294#define dspfunc(PFX, IDX, NUM) \
4295 c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \
4296 c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \
4297 c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \
4298 c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
4299
4300 dspfunc(put, 0, 16);
4301 dspfunc(put_no_rnd, 0, 16);
4302 dspfunc(put, 1, 8);
4303 dspfunc(put_no_rnd, 1, 8);
4304 dspfunc(put, 2, 4);
4305 dspfunc(put, 3, 2);
4306
4307 dspfunc(avg, 0, 16);
4308 dspfunc(avg_no_rnd, 0, 16);
4309 dspfunc(avg, 1, 8);
4310 dspfunc(avg_no_rnd, 1, 8);
4311 dspfunc(avg, 2, 4);
4312 dspfunc(avg, 3, 2);
4313#undef dspfunc
4314
4315 c->put_no_rnd_pixels_l2[0]= put_no_rnd_pixels16_l2_c;
4316 c->put_no_rnd_pixels_l2[1]= put_no_rnd_pixels8_l2_c;
4317
4318 c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
4319 c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
4320 c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
4321 c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
4322 c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
4323 c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
4324 c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
4325 c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
4326 c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
4327
4328 c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
4329 c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
4330 c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
4331 c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
4332 c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
4333 c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
4334 c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
4335 c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
4336 c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
4337
4338#define dspfunc(PFX, IDX, NUM) \
4339 c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
4340 c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
4341 c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
4342 c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
4343 c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
4344 c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
4345 c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
4346 c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
4347 c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
4348 c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
4349 c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
4350 c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
4351 c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
4352 c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
4353 c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
4354 c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
4355
4356 dspfunc(put_qpel, 0, 16);
4357 dspfunc(put_no_rnd_qpel, 0, 16);
4358
4359 dspfunc(avg_qpel, 0, 16);
4360 /* dspfunc(avg_no_rnd_qpel, 0, 16); */
4361
4362 dspfunc(put_qpel, 1, 8);
4363 dspfunc(put_no_rnd_qpel, 1, 8);
4364
4365 dspfunc(avg_qpel, 1, 8);
4366 /* dspfunc(avg_no_rnd_qpel, 1, 8); */
4367
4368 dspfunc(put_h264_qpel, 0, 16);
4369 dspfunc(put_h264_qpel, 1, 8);
4370 dspfunc(put_h264_qpel, 2, 4);
4371 dspfunc(put_h264_qpel, 3, 2);
4372 dspfunc(avg_h264_qpel, 0, 16);
4373 dspfunc(avg_h264_qpel, 1, 8);
4374 dspfunc(avg_h264_qpel, 2, 4);
4375
4376#undef dspfunc
4377 c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
4378 c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
4379 c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
4380 c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
4381 c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
4382 c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
4383 c->put_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c;
4384 c->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c;
4385
4386 c->draw_edges = draw_edges_c;
4387
4388#if CONFIG_CAVS_DECODER
4389 ff_cavsdsp_init(c,avctx);
4390#endif
4391
4392#if CONFIG_MLP_DECODER || CONFIG_TRUEHD_DECODER
4393 ff_mlp_init(c, avctx);
4394#endif
4395#if CONFIG_VC1_DECODER
4396 ff_vc1dsp_init(c,avctx);
4397#endif
4398#if CONFIG_WMV2_DECODER || CONFIG_VC1_DECODER
4399 ff_intrax8dsp_init(c,avctx);
4400#endif
4401#if CONFIG_RV30_DECODER
4402 ff_rv30dsp_init(c,avctx);
4403#endif
4404#if CONFIG_RV40_DECODER
4405 ff_rv40dsp_init(c,avctx);
4406 c->put_rv40_qpel_pixels_tab[0][15] = put_rv40_qpel16_mc33_c;
4407 c->avg_rv40_qpel_pixels_tab[0][15] = avg_rv40_qpel16_mc33_c;
4408 c->put_rv40_qpel_pixels_tab[1][15] = put_rv40_qpel8_mc33_c;
4409 c->avg_rv40_qpel_pixels_tab[1][15] = avg_rv40_qpel8_mc33_c;
4410#endif
4411
4412 c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
4413 c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
4414 c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
4415 c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
4416 c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
4417 c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
4418 c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
4419 c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
4420
4421#define SET_CMP_FUNC(name) \
4422 c->name[0]= name ## 16_c;\
4423 c->name[1]= name ## 8x8_c;
4424
4425 SET_CMP_FUNC(hadamard8_diff)
4426 c->hadamard8_diff[4]= hadamard8_intra16_c;
4427 c->hadamard8_diff[5]= hadamard8_intra8x8_c;
4428 SET_CMP_FUNC(dct_sad)
4429 SET_CMP_FUNC(dct_max)
4430#if CONFIG_GPL
4431 SET_CMP_FUNC(dct264_sad)
4432#endif
4433 c->sad[0]= pix_abs16_c;
4434 c->sad[1]= pix_abs8_c;
4435 c->sse[0]= sse16_c;
4436 c->sse[1]= sse8_c;
4437 c->sse[2]= sse4_c;
4438 SET_CMP_FUNC(quant_psnr)
4439 SET_CMP_FUNC(rd)
4440 SET_CMP_FUNC(bit)
4441 c->vsad[0]= vsad16_c;
4442 c->vsad[4]= vsad_intra16_c;
4443 c->vsad[5]= vsad_intra8_c;
4444 c->vsse[0]= vsse16_c;
4445 c->vsse[4]= vsse_intra16_c;
4446 c->vsse[5]= vsse_intra8_c;
4447 c->nsse[0]= nsse16_c;
4448 c->nsse[1]= nsse8_c;
4449#if CONFIG_DWT
4450 ff_dsputil_init_dwt(c);
4451#endif
4452
4453 c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
4454
4455 c->add_bytes= add_bytes_c;
4456 c->add_bytes_l2= add_bytes_l2_c;
4457 c->diff_bytes= diff_bytes_c;
4458 c->add_hfyu_median_prediction= add_hfyu_median_prediction_c;
4459 c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
4460 c->add_hfyu_left_prediction = add_hfyu_left_prediction_c;
4461 c->add_hfyu_left_prediction_bgr32 = add_hfyu_left_prediction_bgr32_c;
4462 c->bswap_buf= bswap_buf;
4463#if CONFIG_PNG_DECODER
4464 c->add_png_paeth_prediction= ff_add_png_paeth_prediction;
4465#endif
4466
4467 if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
4468 c->h263_h_loop_filter= h263_h_loop_filter_c;
4469 c->h263_v_loop_filter= h263_v_loop_filter_c;
4470 }
4471
4472 if (CONFIG_VP3_DECODER) {
4473 c->vp3_h_loop_filter= ff_vp3_h_loop_filter_c;
4474 c->vp3_v_loop_filter= ff_vp3_v_loop_filter_c;
4475 }
4476 if (CONFIG_VP6_DECODER) {
4477 c->vp6_filter_diag4= ff_vp6_filter_diag4_c;
4478 }
4479
4480 c->h261_loop_filter= h261_loop_filter_c;
4481
4482 c->try_8x8basis= try_8x8basis_c;
4483 c->add_8x8basis= add_8x8basis_c;
4484
4485#if CONFIG_VORBIS_DECODER
4486 c->vorbis_inverse_coupling = vorbis_inverse_coupling;
4487#endif
4488#if CONFIG_AC3_DECODER
4489 c->ac3_downmix = ff_ac3_downmix_c;
4490#endif
4491#if CONFIG_LPC
4492 c->lpc_compute_autocorr = ff_lpc_compute_autocorr;
4493#endif
4494
4495#endif /* 0 */
4496 c->vector_fmul = vector_fmul_c;
4497 c->vector_fmul_reverse = vector_fmul_reverse_c;
4498 c->vector_fmul_add = vector_fmul_add_c;
4499 c->vector_fmul_window = ff_vector_fmul_window_c;
4500 //c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_c;
4501 //c->vector_clipf = vector_clipf_c;
4502 //c->float_to_int16 = ff_float_to_int16_c;
4503 //c->float_to_int16_interleave = ff_float_to_int16_interleave_c;
4504 //c->scalarproduct_int16 = scalarproduct_int16_c;
4505 //c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_c;
4506 //c->scalarproduct_float = scalarproduct_float_c;
4507 //c->butterflies_float = butterflies_float_c;
4508 c->vector_fmul_scalar = vector_fmul_scalar_c;
4509#if 0
4510 c->vector_fmul_sv_scalar[0] = vector_fmul_sv_scalar_2_c;
4511 c->vector_fmul_sv_scalar[1] = vector_fmul_sv_scalar_4_c;
4512
4513 c->sv_fmul_scalar[0] = sv_fmul_scalar_2_c;
4514 c->sv_fmul_scalar[1] = sv_fmul_scalar_4_c;
4515
4516 c->shrink[0]= ff_img_copy_plane;
4517 c->shrink[1]= ff_shrink22;
4518 c->shrink[2]= ff_shrink44;
4519 c->shrink[3]= ff_shrink88;
4520
4521 c->prefetch= just_return;
4522
4523 memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab));
4524 memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab));
4525
4526 if (HAVE_MMX) dsputil_init_mmx (c, avctx);
4527 if (ARCH_ARM) dsputil_init_arm (c, avctx);
4528 if (CONFIG_MLIB) dsputil_init_mlib (c, avctx);
4529 if (HAVE_VIS) dsputil_init_vis (c, avctx);
4530 if (ARCH_ALPHA) dsputil_init_alpha (c, avctx);
4531 if (ARCH_PPC) dsputil_init_ppc (c, avctx);
4532 if (HAVE_MMI) dsputil_init_mmi (c, avctx);
4533 if (ARCH_SH4) dsputil_init_sh4 (c, avctx);
4534 if (ARCH_BFIN) dsputil_init_bfin (c, avctx);
4535
4536 for(i=0; i<64; i++){
4537 if(!c->put_2tap_qpel_pixels_tab[0][i])
4538 c->put_2tap_qpel_pixels_tab[0][i]= c->put_h264_qpel_pixels_tab[0][i];
4539 if(!c->avg_2tap_qpel_pixels_tab[0][i])
4540 c->avg_2tap_qpel_pixels_tab[0][i]= c->avg_h264_qpel_pixels_tab[0][i];
4541 }
4542
4543 switch(c->idct_permutation_type){
4544 case FF_NO_IDCT_PERM:
4545 for(i=0; i<64; i++)
4546 c->idct_permutation[i]= i;
4547 break;
4548 case FF_LIBMPEG2_IDCT_PERM:
4549 for(i=0; i<64; i++)
4550 c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
4551 break;
4552 case FF_SIMPLE_IDCT_PERM:
4553 for(i=0; i<64; i++)
4554 c->idct_permutation[i]= simple_mmx_permutation[i];
4555 break;
4556 case FF_TRANSPOSE_IDCT_PERM:
4557 for(i=0; i<64; i++)
4558 c->idct_permutation[i]= ((i&7)<<3) | (i>>3);
4559 break;
4560 case FF_PARTTRANS_IDCT_PERM:
4561 for(i=0; i<64; i++)
4562 c->idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);
4563 break;
4564 case FF_SSE2_IDCT_PERM:
4565 for(i=0; i<64; i++)
4566 c->idct_permutation[i]= (i&0x38) | idct_sse2_row_perm[i&7];
4567 break;
4568 default:
4569 av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
4570 }
4571#endif /* 0 */
4572}
diff --git a/apps/codecs/libwmapro/dsputil.h b/apps/codecs/libwmapro/dsputil.h
new file mode 100644
index 0000000000..d1816e66ba
--- /dev/null
+++ b/apps/codecs/libwmapro/dsputil.h
@@ -0,0 +1,808 @@
1/*
2 * DSP utils
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23/**
24 * @file libavcodec/dsputil.h
25 * DSP utils.
26 * note, many functions in here may use MMX which trashes the FPU state, it is
27 * absolutely necessary to call emms_c() between dsp & float/double code
28 */
29
30#ifndef AVCODEC_DSPUTIL_H
31#define AVCODEC_DSPUTIL_H
32
33#include "libavutil/intreadwrite.h"
34#include "avcodec.h"
35
36
37//#define DEBUG
38/* dct code */
39typedef short DCTELEM;
40
41void fdct_ifast (DCTELEM *data);
42void fdct_ifast248 (DCTELEM *data);
43void ff_jpeg_fdct_islow (DCTELEM *data);
44void ff_fdct248_islow (DCTELEM *data);
45
46void j_rev_dct (DCTELEM *data);
47void j_rev_dct4 (DCTELEM *data);
48void j_rev_dct2 (DCTELEM *data);
49void j_rev_dct1 (DCTELEM *data);
50void ff_wmv2_idct_c(DCTELEM *data);
51
52void ff_fdct_mmx(DCTELEM *block);
53void ff_fdct_mmx2(DCTELEM *block);
54void ff_fdct_sse2(DCTELEM *block);
55
56void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride);
57void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride);
58void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
59void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
60void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block);
61void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block);
62void ff_h264_idct_add16_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
63void ff_h264_idct_add16intra_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
64void ff_h264_idct8_add4_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
65void ff_h264_idct_add8_c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
66
67void ff_vector_fmul_window_c(float *dst, const float *src0, const float *src1,
68 const float *win, float add_bias, int len);
69void ff_float_to_int16_c(int16_t *dst, const float *src, long len);
70void ff_float_to_int16_interleave_c(int16_t *dst, const float **src, long len, int channels);
71
72/* encoding scans */
73extern const uint8_t ff_alternate_horizontal_scan[64];
74extern const uint8_t ff_alternate_vertical_scan[64];
75extern const uint8_t ff_zigzag_direct[64];
76extern const uint8_t ff_zigzag248_direct[64];
77
78/* pixel operations */
79#define MAX_NEG_CROP 1024
80
81/* temporary */
82extern uint32_t ff_squareTbl[512];
83extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP];
84
85/* VP3 DSP functions */
86void ff_vp3_idct_c(DCTELEM *block/* align 16*/);
87void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
88void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
89
90void ff_vp3_v_loop_filter_c(uint8_t *src, int stride, int *bounding_values);
91void ff_vp3_h_loop_filter_c(uint8_t *src, int stride, int *bounding_values);
92
93/* VP6 DSP functions */
94void ff_vp6_filter_diag4_c(uint8_t *dst, uint8_t *src, int stride,
95 const int16_t *h_weights, const int16_t *v_weights);
96
97/* Bink functions */
98void ff_bink_idct_c (DCTELEM *block);
99void ff_bink_idct_add_c(uint8_t *dest, int linesize, DCTELEM *block);
100void ff_bink_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block);
101
102/* CAVS functions */
103void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride);
104void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride);
105void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride);
106void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride);
107
108/* VC1 functions */
109void ff_put_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd);
110void ff_avg_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd);
111
112/* EA functions */
113void ff_ea_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block);
114
115/* 1/2^n downscaling functions from imgconvert.c */
116void ff_img_copy_plane(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
117void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
118void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
119void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
120
121void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
122 int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
123
124/* minimum alignment rules ;)
125If you notice errors in the align stuff, need more alignment for some ASM code
126for some CPU or need to use a function with less aligned data then send a mail
127to the ffmpeg-devel mailing list, ...
128
129!warning These alignments might not match reality, (missing attribute((align))
130stuff somewhere possible).
131I (Michael) did not check them, these are just the alignments which I think
132could be reached easily ...
133
134!future video codecs might need functions with less strict alignment
135*/
136
137/*
138void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
139void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
140void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
141void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
142void clear_blocks_c(DCTELEM *blocks);
143*/
144
145/* add and put pixel (decoding) */
146// blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
147//h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4
148typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
149typedef void (*tpel_mc_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int w, int h);
150typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
151typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y);
152
153typedef void (*op_fill_func)(uint8_t *block/*align width (8 or 16)*/, uint8_t value, int line_size, int h);
154
155#define DEF_OLD_QPEL(name)\
156void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
157void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
158void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
159
160DEF_OLD_QPEL(qpel16_mc11_old_c)
161DEF_OLD_QPEL(qpel16_mc31_old_c)
162DEF_OLD_QPEL(qpel16_mc12_old_c)
163DEF_OLD_QPEL(qpel16_mc32_old_c)
164DEF_OLD_QPEL(qpel16_mc13_old_c)
165DEF_OLD_QPEL(qpel16_mc33_old_c)
166DEF_OLD_QPEL(qpel8_mc11_old_c)
167DEF_OLD_QPEL(qpel8_mc31_old_c)
168DEF_OLD_QPEL(qpel8_mc12_old_c)
169DEF_OLD_QPEL(qpel8_mc32_old_c)
170DEF_OLD_QPEL(qpel8_mc13_old_c)
171DEF_OLD_QPEL(qpel8_mc33_old_c)
172
173#define CALL_2X_PIXELS(a, b, n)\
174static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
175 b(block , pixels , line_size, h);\
176 b(block+n, pixels+n, line_size, h);\
177}
178
179/* motion estimation */
180// h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2
181// although currently h<4 is not used as functions with width <8 are neither used nor implemented
182typedef int (*me_cmp_func)(void /*MpegEncContext*/ *s, uint8_t *blk1/*align width (8 or 16)*/, uint8_t *blk2/*align 1*/, int line_size, int h)/* __attribute__ ((const))*/;
183
184/**
185 * Scantable.
186 */
187typedef struct ScanTable{
188 const uint8_t *scantable;
189 uint8_t permutated[64];
190 uint8_t raster_end[64];
191#if ARCH_PPC
192 /** Used by dct_quantize_altivec to find last-non-zero */
193 DECLARE_ALIGNED(16, uint8_t, inverse)[64];
194#endif
195} ScanTable;
196
197void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);
198
199void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize,
200 int block_w, int block_h,
201 int src_x, int src_y, int w, int h);
202
203/**
204 * DSPContext.
205 */
206typedef struct DSPContext {
207 /* pixel ops : interface with DCT */
208 void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
209 void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
210 void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
211 void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
212 void (*put_pixels_nonclamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
213 void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
214 void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size);
215 void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size);
216 int (*sum_abs_dctelem)(DCTELEM *block/*align 16*/);
217 /**
218 * translational global motion compensation.
219 */
220 void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder);
221 /**
222 * global motion compensation.
223 */
224 void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy,
225 int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
226 void (*clear_block)(DCTELEM *block/*align 16*/);
227 void (*clear_blocks)(DCTELEM *blocks/*align 16*/);
228 int (*pix_sum)(uint8_t * pix, int line_size);
229 int (*pix_norm1)(uint8_t * pix, int line_size);
230// 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4
231
232 me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
233 me_cmp_func sse[6];
234 me_cmp_func hadamard8_diff[6];
235 me_cmp_func dct_sad[6];
236 me_cmp_func quant_psnr[6];
237 me_cmp_func bit[6];
238 me_cmp_func rd[6];
239 me_cmp_func vsad[6];
240 me_cmp_func vsse[6];
241 me_cmp_func nsse[6];
242 me_cmp_func w53[6];
243 me_cmp_func w97[6];
244 me_cmp_func dct_max[6];
245 me_cmp_func dct264_sad[6];
246
247 me_cmp_func me_pre_cmp[6];
248 me_cmp_func me_cmp[6];
249 me_cmp_func me_sub_cmp[6];
250 me_cmp_func mb_cmp[6];
251 me_cmp_func ildct_cmp[6]; //only width 16 used
252 me_cmp_func frame_skip_cmp[6]; //only width 8 used
253
254 int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2,
255 int size);
256
257 /**
258 * Halfpel motion compensation with rounding (a+b+1)>>1.
259 * this is an array[4][4] of motion compensation functions for 4
260 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
261 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
262 * @param block destination where the result is stored
263 * @param pixels source
264 * @param line_size number of bytes in a horizontal line of block
265 * @param h height
266 */
267 op_pixels_func put_pixels_tab[4][4];
268
269 /**
270 * Halfpel motion compensation with rounding (a+b+1)>>1.
271 * This is an array[4][4] of motion compensation functions for 4
272 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
273 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
274 * @param block destination into which the result is averaged (a+b+1)>>1
275 * @param pixels source
276 * @param line_size number of bytes in a horizontal line of block
277 * @param h height
278 */
279 op_pixels_func avg_pixels_tab[4][4];
280
281 /**
282 * Halfpel motion compensation with no rounding (a+b)>>1.
283 * this is an array[2][4] of motion compensation functions for 2
284 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
285 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
286 * @param block destination where the result is stored
287 * @param pixels source
288 * @param line_size number of bytes in a horizontal line of block
289 * @param h height
290 */
291 op_pixels_func put_no_rnd_pixels_tab[4][4];
292
293 /**
294 * Halfpel motion compensation with no rounding (a+b)>>1.
295 * this is an array[2][4] of motion compensation functions for 2
296 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
297 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
298 * @param block destination into which the result is averaged (a+b)>>1
299 * @param pixels source
300 * @param line_size number of bytes in a horizontal line of block
301 * @param h height
302 */
303 op_pixels_func avg_no_rnd_pixels_tab[4][4];
304
305 void (*put_no_rnd_pixels_l2[2])(uint8_t *block/*align width (8 or 16)*/, const uint8_t *a/*align 1*/, const uint8_t *b/*align 1*/, int line_size, int h);
306
307 /**
308 * Thirdpel motion compensation with rounding (a+b+1)>>1.
309 * this is an array[12] of motion compensation functions for the 9 thirdpe
310 * positions<br>
311 * *pixels_tab[ xthirdpel + 4*ythirdpel ]
312 * @param block destination where the result is stored
313 * @param pixels source
314 * @param line_size number of bytes in a horizontal line of block
315 * @param h height
316 */
317 tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
318 tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
319
320 qpel_mc_func put_qpel_pixels_tab[2][16];
321 qpel_mc_func avg_qpel_pixels_tab[2][16];
322 qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
323 qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
324 qpel_mc_func put_mspel_pixels_tab[8];
325
326 /**
327 * h264 Chroma MC
328 */
329 h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
330 h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
331 /* This is really one func used in VC-1 decoding */
332 h264_chroma_mc_func put_no_rnd_vc1_chroma_pixels_tab[3];
333 h264_chroma_mc_func avg_no_rnd_vc1_chroma_pixels_tab[3];
334
335 qpel_mc_func put_h264_qpel_pixels_tab[4][16];
336 qpel_mc_func avg_h264_qpel_pixels_tab[4][16];
337
338 qpel_mc_func put_2tap_qpel_pixels_tab[4][16];
339 qpel_mc_func avg_2tap_qpel_pixels_tab[4][16];
340
341 /* AVS specific */
342 qpel_mc_func put_cavs_qpel_pixels_tab[2][16];
343 qpel_mc_func avg_cavs_qpel_pixels_tab[2][16];
344 void (*cavs_filter_lv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
345 void (*cavs_filter_lh)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
346 void (*cavs_filter_cv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
347 void (*cavs_filter_ch)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
348 void (*cavs_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
349
350 me_cmp_func pix_abs[2][4];
351
352 /* huffyuv specific */
353 void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
354 void (*add_bytes_l2)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 16*/, int w);
355 void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w);
356 /**
357 * subtract huffyuv's variant of median prediction
358 * note, this might read from src1[-1], src2[-1]
359 */
360 void (*sub_hfyu_median_prediction)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top);
361 void (*add_hfyu_median_prediction)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top);
362 int (*add_hfyu_left_prediction)(uint8_t *dst, const uint8_t *src, int w, int left);
363 void (*add_hfyu_left_prediction_bgr32)(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha);
364 /* this might write to dst[w] */
365 void (*add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp);
366 void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
367
368 void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
369 void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
370
371 void (*h261_loop_filter)(uint8_t *src, int stride);
372
373 void (*x8_v_loop_filter)(uint8_t *src, int stride, int qscale);
374 void (*x8_h_loop_filter)(uint8_t *src, int stride, int qscale);
375
376 void (*vp3_v_loop_filter)(uint8_t *src, int stride, int *bounding_values);
377 void (*vp3_h_loop_filter)(uint8_t *src, int stride, int *bounding_values);
378
379 void (*vp6_filter_diag4)(uint8_t *dst, uint8_t *src, int stride,
380 const int16_t *h_weights,const int16_t *v_weights);
381
382 /* assume len is a multiple of 4, and arrays are 16-byte aligned */
383 void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize);
384 void (*ac3_downmix)(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len);
385 /* no alignment needed */
386 void (*lpc_compute_autocorr)(const int32_t *data, int len, int lag, double *autoc);
387 /* assume len is a multiple of 8, and arrays are 16-byte aligned */
388 void (*vector_fmul)(float *dst, const float *src, int len);
389 void (*vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len);
390 /* assume len is a multiple of 8, and src arrays are 16-byte aligned */
391 void (*vector_fmul_add)(float *dst, const float *src0, const float *src1, const float *src2, int len);
392 /* assume len is a multiple of 4, and arrays are 16-byte aligned */
393 void (*vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len);
394 /* assume len is a multiple of 8, and arrays are 16-byte aligned */
395 void (*int32_to_float_fmul_scalar)(float *dst, const int *src, float mul, int len);
396 void (*vector_clipf)(float *dst /* align 16 */, const float *src /* align 16 */, float min, float max, int len /* align 16 */);
397 /**
398 * Multiply a vector of floats by a scalar float. Source and
399 * destination vectors must overlap exactly or not at all.
400 * @param dst result vector, 16-byte aligned
401 * @param src input vector, 16-byte aligned
402 * @param mul scalar value
403 * @param len length of vector, multiple of 4
404 */
405 void (*vector_fmul_scalar)(float *dst, const float *src, float mul,
406 int len);
407 /**
408 * Multiply a vector of floats by concatenated short vectors of
409 * floats and by a scalar float. Source and destination vectors
410 * must overlap exactly or not at all.
411 * [0]: short vectors of length 2, 8-byte aligned
412 * [1]: short vectors of length 4, 16-byte aligned
413 * @param dst output vector, 16-byte aligned
414 * @param src input vector, 16-byte aligned
415 * @param sv array of pointers to short vectors
416 * @param mul scalar value
417 * @param len number of elements in src and dst, multiple of 4
418 */
419 void (*vector_fmul_sv_scalar[2])(float *dst, const float *src,
420 const float **sv, float mul, int len);
421 /**
422 * Multiply short vectors of floats by a scalar float, store
423 * concatenated result.
424 * [0]: short vectors of length 2, 8-byte aligned
425 * [1]: short vectors of length 4, 16-byte aligned
426 * @param dst output vector, 16-byte aligned
427 * @param sv array of pointers to short vectors
428 * @param mul scalar value
429 * @param len number of output elements, multiple of 4
430 */
431 void (*sv_fmul_scalar[2])(float *dst, const float **sv,
432 float mul, int len);
433 /**
434 * Calculate the scalar product of two vectors of floats.
435 * @param v1 first vector, 16-byte aligned
436 * @param v2 second vector, 16-byte aligned
437 * @param len length of vectors, multiple of 4
438 */
439 float (*scalarproduct_float)(const float *v1, const float *v2, int len);
440 /**
441 * Calculate the sum and difference of two vectors of floats.
442 * @param v1 first input vector, sum output, 16-byte aligned
443 * @param v2 second input vector, difference output, 16-byte aligned
444 * @param len length of vectors, multiple of 4
445 */
446 void (*butterflies_float)(float *restrict v1, float *restrict v2, int len);
447
448 /* C version: convert floats from the range [384.0,386.0] to ints in [-32768,32767]
449 * simd versions: convert floats from [-32768.0,32767.0] without rescaling and arrays are 16byte aligned */
450 void (*float_to_int16)(int16_t *dst, const float *src, long len);
451 void (*float_to_int16_interleave)(int16_t *dst, const float **src, long len, int channels);
452
453 /* (I)DCT */
454 void (*fdct)(DCTELEM *block/* align 16*/);
455 void (*fdct248)(DCTELEM *block/* align 16*/);
456
457 /* IDCT really*/
458 void (*idct)(DCTELEM *block/* align 16*/);
459
460 /**
461 * block -> idct -> clip to unsigned 8 bit -> dest.
462 * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
463 * @param line_size size in bytes of a horizontal line of dest
464 */
465 void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
466
467 /**
468 * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
469 * @param line_size size in bytes of a horizontal line of dest
470 */
471 void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
472
473 /**
474 * idct input permutation.
475 * several optimized IDCTs need a permutated input (relative to the normal order of the reference
476 * IDCT)
477 * this permutation must be performed before the idct_put/add, note, normally this can be merged
478 * with the zigzag/alternate scan<br>
479 * an example to avoid confusion:
480 * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...)
481 * - (x -> referece dct -> reference idct -> x)
482 * - (x -> referece dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x)
483 * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...)
484 */
485 uint8_t idct_permutation[64];
486 int idct_permutation_type;
487#define FF_NO_IDCT_PERM 1
488#define FF_LIBMPEG2_IDCT_PERM 2
489#define FF_SIMPLE_IDCT_PERM 3
490#define FF_TRANSPOSE_IDCT_PERM 4
491#define FF_PARTTRANS_IDCT_PERM 5
492#define FF_SSE2_IDCT_PERM 6
493
494 int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale);
495 void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
496#define BASIS_SHIFT 16
497#define RECON_SHIFT 6
498
499 void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w);
500#define EDGE_WIDTH 16
501
502 void (*prefetch)(void *mem, int stride, int h);
503
504 void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
505
506 /* mlp/truehd functions */
507 void (*mlp_filter_channel)(int32_t *state, const int32_t *coeff,
508 int firorder, int iirorder,
509 unsigned int filter_shift, int32_t mask, int blocksize,
510 int32_t *sample_buffer);
511
512 /* vc1 functions */
513 void (*vc1_inv_trans_8x8)(DCTELEM *b);
514 void (*vc1_inv_trans_8x4)(uint8_t *dest, int line_size, DCTELEM *block);
515 void (*vc1_inv_trans_4x8)(uint8_t *dest, int line_size, DCTELEM *block);
516 void (*vc1_inv_trans_4x4)(uint8_t *dest, int line_size, DCTELEM *block);
517 void (*vc1_inv_trans_8x8_dc)(uint8_t *dest, int line_size, DCTELEM *block);
518 void (*vc1_inv_trans_8x4_dc)(uint8_t *dest, int line_size, DCTELEM *block);
519 void (*vc1_inv_trans_4x8_dc)(uint8_t *dest, int line_size, DCTELEM *block);
520 void (*vc1_inv_trans_4x4_dc)(uint8_t *dest, int line_size, DCTELEM *block);
521 void (*vc1_v_overlap)(uint8_t* src, int stride);
522 void (*vc1_h_overlap)(uint8_t* src, int stride);
523 void (*vc1_v_loop_filter4)(uint8_t *src, int stride, int pq);
524 void (*vc1_h_loop_filter4)(uint8_t *src, int stride, int pq);
525 void (*vc1_v_loop_filter8)(uint8_t *src, int stride, int pq);
526 void (*vc1_h_loop_filter8)(uint8_t *src, int stride, int pq);
527 void (*vc1_v_loop_filter16)(uint8_t *src, int stride, int pq);
528 void (*vc1_h_loop_filter16)(uint8_t *src, int stride, int pq);
529 /* put 8x8 block with bicubic interpolation and quarterpel precision
530 * last argument is actually round value instead of height
531 */
532 op_pixels_func put_vc1_mspel_pixels_tab[16];
533 op_pixels_func avg_vc1_mspel_pixels_tab[16];
534
535 /* intrax8 functions */
536 void (*x8_spatial_compensation[12])(uint8_t *src , uint8_t *dst, int linesize);
537 void (*x8_setup_spatial_compensation)(uint8_t *src, uint8_t *dst, int linesize,
538 int * range, int * sum, int edges);
539
540 /**
541 * Calculate scalar product of two vectors.
542 * @param len length of vectors, should be multiple of 16
543 * @param shift number of bits to discard from product
544 */
545 int32_t (*scalarproduct_int16)(int16_t *v1, int16_t *v2/*align 16*/, int len, int shift);
546 /* ape functions */
547 /**
548 * Calculate scalar product of v1 and v2,
549 * and v1[i] += v3[i] * mul
550 * @param len length of vectors, should be multiple of 16
551 */
552 int32_t (*scalarproduct_and_madd_int16)(int16_t *v1/*align 16*/, int16_t *v2, int16_t *v3, int len, int mul);
553
554 /* rv30 functions */
555 qpel_mc_func put_rv30_tpel_pixels_tab[4][16];
556 qpel_mc_func avg_rv30_tpel_pixels_tab[4][16];
557
558 /* rv40 functions */
559 qpel_mc_func put_rv40_qpel_pixels_tab[4][16];
560 qpel_mc_func avg_rv40_qpel_pixels_tab[4][16];
561 h264_chroma_mc_func put_rv40_chroma_pixels_tab[3];
562 h264_chroma_mc_func avg_rv40_chroma_pixels_tab[3];
563
564 /* bink functions */
565 op_fill_func fill_block_tab[2];
566 void (*scale_block)(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize);
567} DSPContext;
568
569void dsputil_static_init(void);
570void dsputil_init(DSPContext* p, AVCodecContext *avctx);
571
572int ff_check_alignment(void);
573
574/**
575 * permute block according to permuatation.
576 * @param last last non zero element in scantable order
577 */
578void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
579
580void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
581
582#define BYTE_VEC32(c) ((c)*0x01010101UL)
583
584static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
585{
586 return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
587}
588
589static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
590{
591 return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
592}
593
594static inline int get_penalty_factor(int lambda, int lambda2, int type){
595 switch(type&0xFF){
596 default:
597 case FF_CMP_SAD:
598 return lambda>>FF_LAMBDA_SHIFT;
599 case FF_CMP_DCT:
600 return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
601 case FF_CMP_W53:
602 return (4*lambda)>>(FF_LAMBDA_SHIFT);
603 case FF_CMP_W97:
604 return (2*lambda)>>(FF_LAMBDA_SHIFT);
605 case FF_CMP_SATD:
606 case FF_CMP_DCT264:
607 return (2*lambda)>>FF_LAMBDA_SHIFT;
608 case FF_CMP_RD:
609 case FF_CMP_PSNR:
610 case FF_CMP_SSE:
611 case FF_CMP_NSSE:
612 return lambda2>>FF_LAMBDA_SHIFT;
613 case FF_CMP_BIT:
614 return 1;
615 }
616}
617
618/**
619 * Empty mmx state.
620 * this must be called between any dsp function and float/double code.
621 * for example sin(); dsp->idct_put(); emms_c(); cos()
622 */
623#define emms_c()
624
625/* should be defined by architectures supporting
626 one or more MultiMedia extension */
627int mm_support(void);
628extern int mm_flags;
629
630void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
631void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx);
632void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx);
633void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx);
634void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx);
635void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
636void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
637void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
638void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
639
640void ff_dsputil_init_dwt(DSPContext *c);
641void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx);
642void ff_rv30dsp_init(DSPContext* c, AVCodecContext *avctx);
643void ff_rv40dsp_init(DSPContext* c, AVCodecContext *avctx);
644void ff_vc1dsp_init(DSPContext* c, AVCodecContext *avctx);
645void ff_intrax8dsp_init(DSPContext* c, AVCodecContext *avctx);
646void ff_mlp_init(DSPContext* c, AVCodecContext *avctx);
647void ff_mlp_init_x86(DSPContext* c, AVCodecContext *avctx);
648
649#if HAVE_MMX
650
651#undef emms_c
652
653static inline void emms(void)
654{
655 __asm__ volatile ("emms;":::"memory");
656}
657
658
659#define emms_c() \
660{\
661 if (mm_flags & FF_MM_MMX)\
662 emms();\
663}
664
665#elif ARCH_ARM
666
667#if HAVE_NEON
668# define STRIDE_ALIGN 16
669#endif
670
671#elif ARCH_PPC
672
673#define STRIDE_ALIGN 16
674
675#elif HAVE_MMI
676
677#define STRIDE_ALIGN 16
678
679#else
680
681#define mm_flags 0
682#define mm_support() 0
683
684#endif
685
686#ifndef STRIDE_ALIGN
687# define STRIDE_ALIGN 8
688#endif
689
690#define LOCAL_ALIGNED(a, t, v, s, ...) \
691 uint8_t la_##v[sizeof(t s __VA_ARGS__) + (a)]; \
692 t (*v) __VA_ARGS__ = (void *)FFALIGN((uintptr_t)la_##v, a)
693
694#if HAVE_LOCAL_ALIGNED_8
695# define LOCAL_ALIGNED_8(t, v, s, ...) DECLARE_ALIGNED(8, t, v) s __VA_ARGS__
696#else
697# define LOCAL_ALIGNED_8(t, v, s, ...) LOCAL_ALIGNED(8, t, v, s, __VA_ARGS__)
698#endif
699
700#if HAVE_LOCAL_ALIGNED_16
701# define LOCAL_ALIGNED_16(t, v, s, ...) DECLARE_ALIGNED(16, t, v) s __VA_ARGS__
702#else
703# define LOCAL_ALIGNED_16(t, v, s, ...) LOCAL_ALIGNED(16, t, v, s, __VA_ARGS__)
704#endif
705
706/* PSNR */
707void get_psnr(uint8_t *orig_image[3], uint8_t *coded_image[3],
708 int orig_linesize[3], int coded_linesize,
709 AVCodecContext *avctx);
710
711#define WRAPPER8_16(name8, name16)\
712static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
713 return name8(s, dst , src , stride, h)\
714 +name8(s, dst+8 , src+8 , stride, h);\
715}
716
717#define WRAPPER8_16_SQ(name8, name16)\
718static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
719 int score=0;\
720 score +=name8(s, dst , src , stride, 8);\
721 score +=name8(s, dst+8 , src+8 , stride, 8);\
722 if(h==16){\
723 dst += 8*stride;\
724 src += 8*stride;\
725 score +=name8(s, dst , src , stride, 8);\
726 score +=name8(s, dst+8 , src+8 , stride, 8);\
727 }\
728 return score;\
729}
730
731
732static inline void copy_block2(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
733{
734 int i;
735 for(i=0; i<h; i++)
736 {
737 AV_WN16(dst , AV_RN16(src ));
738 dst+=dstStride;
739 src+=srcStride;
740 }
741}
742
743static inline void copy_block4(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
744{
745 int i;
746 for(i=0; i<h; i++)
747 {
748 AV_WN32(dst , AV_RN32(src ));
749 dst+=dstStride;
750 src+=srcStride;
751 }
752}
753
754static inline void copy_block8(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
755{
756 int i;
757 for(i=0; i<h; i++)
758 {
759 AV_WN32(dst , AV_RN32(src ));
760 AV_WN32(dst+4 , AV_RN32(src+4 ));
761 dst+=dstStride;
762 src+=srcStride;
763 }
764}
765
766static inline void copy_block9(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
767{
768 int i;
769 for(i=0; i<h; i++)
770 {
771 AV_WN32(dst , AV_RN32(src ));
772 AV_WN32(dst+4 , AV_RN32(src+4 ));
773 dst[8]= src[8];
774 dst+=dstStride;
775 src+=srcStride;
776 }
777}
778
779static inline void copy_block16(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
780{
781 int i;
782 for(i=0; i<h; i++)
783 {
784 AV_WN32(dst , AV_RN32(src ));
785 AV_WN32(dst+4 , AV_RN32(src+4 ));
786 AV_WN32(dst+8 , AV_RN32(src+8 ));
787 AV_WN32(dst+12, AV_RN32(src+12));
788 dst+=dstStride;
789 src+=srcStride;
790 }
791}
792
793static inline void copy_block17(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
794{
795 int i;
796 for(i=0; i<h; i++)
797 {
798 AV_WN32(dst , AV_RN32(src ));
799 AV_WN32(dst+4 , AV_RN32(src+4 ));
800 AV_WN32(dst+8 , AV_RN32(src+8 ));
801 AV_WN32(dst+12, AV_RN32(src+12));
802 dst[16]= src[16];
803 dst+=dstStride;
804 src+=srcStride;
805 }
806}
807
808#endif /* AVCODEC_DSPUTIL_H */
diff --git a/apps/codecs/libwmapro/fft.c b/apps/codecs/libwmapro/fft.c
new file mode 100644
index 0000000000..80dd35b2b6
--- /dev/null
+++ b/apps/codecs/libwmapro/fft.c
@@ -0,0 +1,385 @@
1/*
2 * FFT/IFFT transforms
3 * Copyright (c) 2008 Loren Merritt
4 * Copyright (c) 2002 Fabrice Bellard
5 * Partly based on libdjbfft by D. J. Bernstein
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24/**
25 * @file libavcodec/fft.c
26 * FFT/IFFT transforms.
27 */
28
29#include "dsputil.h"
30#include "fft.h"
31#ifndef M_PI
32#define M_PI 3.14159265358979323846 /* pi */
33#endif
34#ifndef M_SQRT1_2
35#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
36#endif
37#ifndef M_SQRT2
38#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
39#endif
40
41/* cos(2*pi*x/n) for 0<=x<=n/4, followed by its reverse */
42DECLARE_ALIGNED_16(FFTSample, ff_cos_16[8]);
43DECLARE_ALIGNED_16(FFTSample, ff_cos_32[16]);
44DECLARE_ALIGNED_16(FFTSample, ff_cos_64[32]);
45DECLARE_ALIGNED_16(FFTSample, ff_cos_128[64]);
46DECLARE_ALIGNED_16(FFTSample, ff_cos_256[128]);
47DECLARE_ALIGNED_16(FFTSample, ff_cos_512[256]);
48DECLARE_ALIGNED_16(FFTSample, ff_cos_1024[512]);
49DECLARE_ALIGNED_16(FFTSample, ff_cos_2048[1024]);
50DECLARE_ALIGNED_16(FFTSample, ff_cos_4096[2048]);
51DECLARE_ALIGNED_16(FFTSample, ff_cos_8192[4096]);
52DECLARE_ALIGNED_16(FFTSample, ff_cos_16384[8192]);
53DECLARE_ALIGNED_16(FFTSample, ff_cos_32768[16384]);
54DECLARE_ALIGNED_16(FFTSample, ff_cos_65536[32768]);
55
56FFTSample *ff_cos_tabs[] = {
57 ff_cos_16, ff_cos_32, ff_cos_64, ff_cos_128, ff_cos_256, ff_cos_512, ff_cos_1024,
58 ff_cos_2048, ff_cos_4096, ff_cos_8192, ff_cos_16384, ff_cos_32768, ff_cos_65536,
59};
60
61static int split_radix_permutation(int i, int n, int inverse)
62{
63 int m;
64 if(n <= 2) return i&1;
65 m = n >> 1;
66 if(!(i&m)) return split_radix_permutation(i, m, inverse)*2;
67 m >>= 1;
68 if(inverse == !(i&m)) return split_radix_permutation(i, m, inverse)*4 + 1;
69 else return split_radix_permutation(i, m, inverse)*4 - 1;
70}
71
72av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse)
73{
74 int i, j, m, n;
75 float alpha, c1, s1, s2;
76 int split_radix = 1;
77 int av_unused has_vectors;
78
79 if (nbits < 2 || nbits > 16)
80 goto fail;
81 s->nbits = nbits;
82 n = 1 << nbits;
83
84 s->tmp_buf = NULL;
85 s->exptab = av_malloc((n / 2) * sizeof(FFTComplex));
86 if (!s->exptab)
87 goto fail;
88 s->revtab = av_malloc(n * sizeof(uint16_t));
89 if (!s->revtab)
90 goto fail;
91 s->inverse = inverse;
92
93 s2 = inverse ? 1.0 : -1.0;
94
95 s->fft_permute = ff_fft_permute_c;
96 s->fft_calc = ff_fft_calc_c;
97 s->imdct_calc = ff_imdct_calc_c;
98 s->imdct_half = ff_imdct_half_c;
99 s->exptab1 = NULL;
100
101#if HAVE_MMX && HAVE_YASM
102 has_vectors = mm_support();
103 if (has_vectors & FF_MM_SSE && HAVE_SSE) {
104 /* SSE for P3/P4/K8 */
105 s->imdct_calc = ff_imdct_calc_sse;
106 s->imdct_half = ff_imdct_half_sse;
107 s->fft_permute = ff_fft_permute_sse;
108 s->fft_calc = ff_fft_calc_sse;
109 } else if (has_vectors & FF_MM_3DNOWEXT && HAVE_AMD3DNOWEXT) {
110 /* 3DNowEx for K7 */
111 s->imdct_calc = ff_imdct_calc_3dn2;
112 s->imdct_half = ff_imdct_half_3dn2;
113 s->fft_calc = ff_fft_calc_3dn2;
114 } else if (has_vectors & FF_MM_3DNOW && HAVE_AMD3DNOW) {
115 /* 3DNow! for K6-2/3 */
116 s->imdct_calc = ff_imdct_calc_3dn;
117 s->imdct_half = ff_imdct_half_3dn;
118 s->fft_calc = ff_fft_calc_3dn;
119 }
120#elif HAVE_ALTIVEC
121 has_vectors = mm_support();
122 if (has_vectors & FF_MM_ALTIVEC) {
123 s->fft_calc = ff_fft_calc_altivec;
124 split_radix = 0;
125 }
126#endif
127
128 if (split_radix) {
129 for(j=4; j<=nbits; j++) {
130 int m = 1<<j;
131 double freq = 2*M_PI/m;
132 FFTSample *tab = ff_cos_tabs[j-4];
133 for(i=0; i<=m/4; i++)
134 tab[i] = cos(i*freq);
135 for(i=1; i<m/4; i++)
136 tab[m/2-i] = tab[i];
137 }
138 for(i=0; i<n; i++)
139 s->revtab[-split_radix_permutation(i, n, s->inverse) & (n-1)] = i;
140 s->tmp_buf = av_malloc(n * sizeof(FFTComplex));
141 } else {
142 int np, nblocks, np2, l;
143 FFTComplex *q;
144
145 for(i=0; i<(n/2); i++) {
146 alpha = 2 * M_PI * (float)i / (float)n;
147 c1 = cos(alpha);
148 s1 = sin(alpha) * s2;
149 s->exptab[i].re = c1;
150 s->exptab[i].im = s1;
151 }
152
153 np = 1 << nbits;
154 nblocks = np >> 3;
155 np2 = np >> 1;
156 s->exptab1 = av_malloc(np * 2 * sizeof(FFTComplex));
157 if (!s->exptab1)
158 goto fail;
159 q = s->exptab1;
160 do {
161 for(l = 0; l < np2; l += 2 * nblocks) {
162 *q++ = s->exptab[l];
163 *q++ = s->exptab[l + nblocks];
164
165 q->re = -s->exptab[l].im;
166 q->im = s->exptab[l].re;
167 q++;
168 q->re = -s->exptab[l + nblocks].im;
169 q->im = s->exptab[l + nblocks].re;
170 q++;
171 }
172 nblocks = nblocks >> 1;
173 } while (nblocks != 0);
174 av_freep(&s->exptab);
175
176 /* compute bit reverse table */
177 for(i=0;i<n;i++) {
178 m=0;
179 for(j=0;j<nbits;j++) {
180 m |= ((i >> j) & 1) << (nbits-j-1);
181 }
182 s->revtab[i]=m;
183 }
184 }
185
186 return 0;
187 fail:
188 av_freep(&s->revtab);
189 av_freep(&s->exptab);
190 av_freep(&s->exptab1);
191 av_freep(&s->tmp_buf);
192 return -1;
193}
194
195void ff_fft_permute_c(FFTContext *s, FFTComplex *z)
196{
197 int j, k, np;
198 FFTComplex tmp;
199 const uint16_t *revtab = s->revtab;
200 np = 1 << s->nbits;
201
202 if (s->tmp_buf) {
203 /* TODO: handle split-radix permute in a more optimal way, probably in-place */
204 for(j=0;j<np;j++) s->tmp_buf[revtab[j]] = z[j];
205 memcpy(z, s->tmp_buf, np * sizeof(FFTComplex));
206 return;
207 }
208
209 /* reverse */
210 for(j=0;j<np;j++) {
211 k = revtab[j];
212 if (k < j) {
213 tmp = z[k];
214 z[k] = z[j];
215 z[j] = tmp;
216 }
217 }
218}
219
220av_cold void ff_fft_end(FFTContext *s)
221{
222 av_freep(&s->revtab);
223 av_freep(&s->exptab);
224 av_freep(&s->exptab1);
225 av_freep(&s->tmp_buf);
226}
227
228#define sqrthalf (float)M_SQRT1_2
229
230#define BF(x,y,a,b) {\
231 x = a - b;\
232 y = a + b;\
233}
234
235#define BUTTERFLIES(a0,a1,a2,a3) {\
236 BF(t3, t5, t5, t1);\
237 BF(a2.re, a0.re, a0.re, t5);\
238 BF(a3.im, a1.im, a1.im, t3);\
239 BF(t4, t6, t2, t6);\
240 BF(a3.re, a1.re, a1.re, t4);\
241 BF(a2.im, a0.im, a0.im, t6);\
242}
243
244// force loading all the inputs before storing any.
245// this is slightly slower for small data, but avoids store->load aliasing
246// for addresses separated by large powers of 2.
247#define BUTTERFLIES_BIG(a0,a1,a2,a3) {\
248 FFTSample r0=a0.re, i0=a0.im, r1=a1.re, i1=a1.im;\
249 BF(t3, t5, t5, t1);\
250 BF(a2.re, a0.re, r0, t5);\
251 BF(a3.im, a1.im, i1, t3);\
252 BF(t4, t6, t2, t6);\
253 BF(a3.re, a1.re, r1, t4);\
254 BF(a2.im, a0.im, i0, t6);\
255}
256
257#define TRANSFORM(a0,a1,a2,a3,wre,wim) {\
258 t1 = a2.re * wre + a2.im * wim;\
259 t2 = a2.im * wre - a2.re * wim;\
260 t5 = a3.re * wre - a3.im * wim;\
261 t6 = a3.im * wre + a3.re * wim;\
262 BUTTERFLIES(a0,a1,a2,a3)\
263}
264
265#define TRANSFORM_ZERO(a0,a1,a2,a3) {\
266 t1 = a2.re;\
267 t2 = a2.im;\
268 t5 = a3.re;\
269 t6 = a3.im;\
270 BUTTERFLIES(a0,a1,a2,a3)\
271}
272
273/* z[0...8n-1], w[1...2n-1] */
274#define PASS(name)\
275static void name(FFTComplex *z, const FFTSample *wre, unsigned int n)\
276{\
277 FFTSample t1, t2, t3, t4, t5, t6;\
278 int o1 = 2*n;\
279 int o2 = 4*n;\
280 int o3 = 6*n;\
281 const FFTSample *wim = wre+o1;\
282 n--;\
283\
284 TRANSFORM_ZERO(z[0],z[o1],z[o2],z[o3]);\
285 TRANSFORM(z[1],z[o1+1],z[o2+1],z[o3+1],wre[1],wim[-1]);\
286 do {\
287 z += 2;\
288 wre += 2;\
289 wim -= 2;\
290 TRANSFORM(z[0],z[o1],z[o2],z[o3],wre[0],wim[0]);\
291 TRANSFORM(z[1],z[o1+1],z[o2+1],z[o3+1],wre[1],wim[-1]);\
292 } while(--n);\
293}
294
295PASS(pass)
296#undef BUTTERFLIES
297#define BUTTERFLIES BUTTERFLIES_BIG
298PASS(pass_big)
299
300#define DECL_FFT(n,n2,n4)\
301static void fft##n(FFTComplex *z)\
302{\
303 fft##n2(z);\
304 fft##n4(z+n4*2);\
305 fft##n4(z+n4*3);\
306 pass(z,ff_cos_##n,n4/2);\
307}
308
309static void fft4(FFTComplex *z)
310{
311 FFTSample t1, t2, t3, t4, t5, t6, t7, t8;
312
313 BF(t3, t1, z[0].re, z[1].re);
314 BF(t8, t6, z[3].re, z[2].re);
315 BF(z[2].re, z[0].re, t1, t6);
316 BF(t4, t2, z[0].im, z[1].im);
317 BF(t7, t5, z[2].im, z[3].im);
318 BF(z[3].im, z[1].im, t4, t8);
319 BF(z[3].re, z[1].re, t3, t7);
320 BF(z[2].im, z[0].im, t2, t5);
321}
322
323static void fft8(FFTComplex *z)
324{
325 FFTSample t1, t2, t3, t4, t5, t6, t7, t8;
326
327 fft4(z);
328
329 BF(t1, z[5].re, z[4].re, -z[5].re);
330 BF(t2, z[5].im, z[4].im, -z[5].im);
331 BF(t3, z[7].re, z[6].re, -z[7].re);
332 BF(t4, z[7].im, z[6].im, -z[7].im);
333 BF(t8, t1, t3, t1);
334 BF(t7, t2, t2, t4);
335 BF(z[4].re, z[0].re, z[0].re, t1);
336 BF(z[4].im, z[0].im, z[0].im, t2);
337 BF(z[6].re, z[2].re, z[2].re, t7);
338 BF(z[6].im, z[2].im, z[2].im, t8);
339
340 TRANSFORM(z[1],z[3],z[5],z[7],sqrthalf,sqrthalf);
341}
342
343#if !CONFIG_SMALL
344static void fft16(FFTComplex *z)
345{
346 FFTSample t1, t2, t3, t4, t5, t6;
347
348 fft8(z);
349 fft4(z+8);
350 fft4(z+12);
351
352 TRANSFORM_ZERO(z[0],z[4],z[8],z[12]);
353 TRANSFORM(z[2],z[6],z[10],z[14],sqrthalf,sqrthalf);
354 TRANSFORM(z[1],z[5],z[9],z[13],ff_cos_16[1],ff_cos_16[3]);
355 TRANSFORM(z[3],z[7],z[11],z[15],ff_cos_16[3],ff_cos_16[1]);
356}
357#else
358DECL_FFT(16,8,4)
359#endif
360DECL_FFT(32,16,8)
361DECL_FFT(64,32,16)
362DECL_FFT(128,64,32)
363DECL_FFT(256,128,64)
364DECL_FFT(512,256,128)
365#if !CONFIG_SMALL
366#define pass pass_big
367#endif
368DECL_FFT(1024,512,256)
369DECL_FFT(2048,1024,512)
370DECL_FFT(4096,2048,1024)
371DECL_FFT(8192,4096,2048)
372DECL_FFT(16384,8192,4096)
373DECL_FFT(32768,16384,8192)
374DECL_FFT(65536,32768,16384)
375
376static void (*fft_dispatch[])(FFTComplex*) = {
377 fft4, fft8, fft16, fft32, fft64, fft128, fft256, fft512, fft1024,
378 fft2048, fft4096, fft8192, fft16384, fft32768, fft65536,
379};
380
381void ff_fft_calc_c(FFTContext *s, FFTComplex *z)
382{
383 fft_dispatch[s->nbits-2](z);
384}
385
diff --git a/apps/codecs/libwmapro/fft.h b/apps/codecs/libwmapro/fft.h
new file mode 100644
index 0000000000..541a46bbba
--- /dev/null
+++ b/apps/codecs/libwmapro/fft.h
@@ -0,0 +1,244 @@
1/*
2 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
3 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#ifndef AVCODEC_FFT_H
23#define AVCODEC_FFT_H
24
25#include <stdint.h>
26//#include "config.h"
27#include "libavutil/mem.h"
28#include "avfft.h"
29
30/* DECLARE_ALIGNED - Taken from libavutil/internal.h */
31#define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
32#define DECLARE_ALIGNED_16(t,v) DECLARE_ALIGNED(16,t,v)
33
34/* FFT computation */
35
36struct FFTContext {
37 int nbits;
38 int inverse;
39 uint16_t *revtab;
40 FFTComplex *exptab;
41 FFTComplex *exptab1; /* only used by SSE code */
42 FFTComplex *tmp_buf;
43 int mdct_size; /* size of MDCT (i.e. number of input data * 2) */
44 int mdct_bits; /* n = 2^nbits */
45 /* pre/post rotation tables */
46 FFTSample *tcos;
47 FFTSample *tsin;
48 void (*fft_permute)(struct FFTContext *s, FFTComplex *z);
49 void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
50 void (*imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input);
51 void (*imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input);
52 void (*mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input);
53 int split_radix;
54 int permutation;
55#define FF_MDCT_PERM_NONE 0
56#define FF_MDCT_PERM_INTERLEAVE 1
57};
58
59#if CONFIG_HARDCODED_TABLES
60#define COSTABLE_CONST const
61#define SINTABLE_CONST const
62#define SINETABLE_CONST const
63#else
64#define COSTABLE_CONST
65#define SINTABLE_CONST
66#define SINETABLE_CONST
67#endif
68
69#define COSTABLE(size) \
70 COSTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_cos_##size)[size/2]
71#define SINTABLE(size) \
72 SINTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_sin_##size)[size/2]
73#define SINETABLE(size) \
74 SINETABLE_CONST DECLARE_ALIGNED(16, float, ff_sine_##size)[size]
75extern COSTABLE(16);
76extern COSTABLE(32);
77extern COSTABLE(64);
78extern COSTABLE(128);
79extern COSTABLE(256);
80extern COSTABLE(512);
81extern COSTABLE(1024);
82extern COSTABLE(2048);
83extern COSTABLE(4096);
84extern COSTABLE(8192);
85extern COSTABLE(16384);
86extern COSTABLE(32768);
87extern COSTABLE(65536);
88//extern COSTABLE_CONST FFTSample* const ff_cos_tabs[17];
89
90/**
91 * Initializes the cosine table in ff_cos_tabs[index]
92 * \param index index in ff_cos_tabs array of the table to initialize
93 */
94void ff_init_ff_cos_tabs(int index);
95
96extern SINTABLE(16);
97extern SINTABLE(32);
98extern SINTABLE(64);
99extern SINTABLE(128);
100extern SINTABLE(256);
101extern SINTABLE(512);
102extern SINTABLE(1024);
103extern SINTABLE(2048);
104extern SINTABLE(4096);
105extern SINTABLE(8192);
106extern SINTABLE(16384);
107extern SINTABLE(32768);
108extern SINTABLE(65536);
109
110/**
111 * Sets up a complex FFT.
112 * @param nbits log2 of the length of the input array
113 * @param inverse if 0 perform the forward transform, if 1 perform the inverse
114 */
115int ff_fft_init(FFTContext *s, int nbits, int inverse);
116void ff_fft_permute_c(FFTContext *s, FFTComplex *z);
117void ff_fft_calc_c(FFTContext *s, FFTComplex *z);
118
119void ff_fft_init_altivec(FFTContext *s);
120void ff_fft_init_mmx(FFTContext *s);
121void ff_fft_init_arm(FFTContext *s);
122
123/**
124 * Do the permutation needed BEFORE calling ff_fft_calc().
125 */
126static inline void ff_fft_permute(FFTContext *s, FFTComplex *z)
127{
128 s->fft_permute(s, z);
129}
130/**
131 * Do a complex FFT with the parameters defined in ff_fft_init(). The
132 * input data must be permuted before. No 1.0/sqrt(n) normalization is done.
133 */
134static inline void ff_fft_calc(FFTContext *s, FFTComplex *z)
135{
136 s->fft_calc(s, z);
137}
138void ff_fft_end(FFTContext *s);
139
140/* MDCT computation */
141
142static inline void ff_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
143{
144 s->imdct_calc(s, output, input);
145}
146static inline void ff_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input)
147{
148 s->imdct_half(s, output, input);
149}
150
151static inline void ff_mdct_calc(FFTContext *s, FFTSample *output,
152 const FFTSample *input)
153{
154 s->mdct_calc(s, output, input);
155}
156
157/**
158 * Generate a Kaiser-Bessel Derived Window.
159 * @param window pointer to half window
160 * @param alpha determines window shape
161 * @param n size of half window
162 */
163void ff_kbd_window_init(float *window, float alpha, int n);
164
165/**
166 * Generate a sine window.
167 * @param window pointer to half window
168 * @param n size of half window
169 */
170void ff_sine_window_init(float *window, int n);
171
172/**
173 * initialize the specified entry of ff_sine_windows
174 */
175void ff_init_ff_sine_windows(int index);
176extern SINETABLE( 32);
177extern SINETABLE( 64);
178extern SINETABLE( 128);
179extern SINETABLE( 256);
180extern SINETABLE( 512);
181extern SINETABLE(1024);
182extern SINETABLE(2048);
183extern SINETABLE(4096);
184extern SINETABLE_CONST float * const ff_sine_windows[13];
185
186int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale);
187void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input);
188void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input);
189void ff_mdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input);
190void ff_mdct_end(FFTContext *s);
191
192/* Real Discrete Fourier Transform */
193
194struct RDFTContext {
195 int nbits;
196 int inverse;
197 int sign_convention;
198
199 /* pre/post rotation tables */
200 const FFTSample *tcos;
201 SINTABLE_CONST FFTSample *tsin;
202 FFTContext fft;
203 void (*rdft_calc)(struct RDFTContext *s, FFTSample *z);
204};
205
206/**
207 * Sets up a real FFT.
208 * @param nbits log2 of the length of the input array
209 * @param trans the type of transform
210 */
211int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans);
212void ff_rdft_end(RDFTContext *s);
213
214void ff_rdft_init_arm(RDFTContext *s);
215
216static av_always_inline void ff_rdft_calc(RDFTContext *s, FFTSample *data)
217{
218 s->rdft_calc(s, data);
219}
220
221/* Discrete Cosine Transform */
222
223struct DCTContext {
224 int nbits;
225 int inverse;
226 RDFTContext rdft;
227 const float *costab;
228 FFTSample *csc2;
229 void (*dct_calc)(struct DCTContext *s, FFTSample *data);
230};
231
232/**
233 * Sets up DCT.
234 * @param nbits size of the input array:
235 * (1 << nbits) for DCT-II, DCT-III and DST-I
236 * (1 << nbits) + 1 for DCT-I
237 *
238 * @note the first element of the input of DST-I is ignored
239 */
240int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType type);
241void ff_dct_calc(DCTContext *s, FFTSample *data);
242void ff_dct_end (DCTContext *s);
243
244#endif /* AVCODEC_FFT_H */
diff --git a/apps/codecs/libwmapro/get_bits.h b/apps/codecs/libwmapro/get_bits.h
new file mode 100644
index 0000000000..ca84ea61c0
--- /dev/null
+++ b/apps/codecs/libwmapro/get_bits.h
@@ -0,0 +1,692 @@
1/*
2 * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file libavcodec/get_bits.h
23 * bitstream reader API header.
24 */
25
26#ifndef AVCODEC_GET_BITS_H
27#define AVCODEC_GET_BITS_H
28
29#include <stdint.h>
30#include <stdlib.h>
31#include <assert.h>
32#include "libavutil/bswap.h"
33#include "libavutil/common.h"
34#include "libavutil/intreadwrite.h"
35#include "libavutil/log.h"
36#include "mathops.h"
37
38#if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER)
39# define ALT_BITSTREAM_READER
40#endif
41
42#if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
43# if ARCH_ARM && !HAVE_FAST_UNALIGNED
44# define A32_BITSTREAM_READER
45# else
46# define ALT_BITSTREAM_READER
47//#define LIBMPEG2_BITSTREAM_READER
48//#define A32_BITSTREAM_READER
49# endif
50#endif
51
52/* bit input */
53/* buffer, buffer_end and size_in_bits must be present and used by every reader */
54typedef struct GetBitContext {
55 const uint8_t *buffer, *buffer_end;
56#ifdef ALT_BITSTREAM_READER
57 int index;
58#elif defined LIBMPEG2_BITSTREAM_READER
59 uint8_t *buffer_ptr;
60 uint32_t cache;
61 int bit_count;
62#elif defined A32_BITSTREAM_READER
63 uint32_t *buffer_ptr;
64 uint32_t cache0;
65 uint32_t cache1;
66 int bit_count;
67#endif
68 int size_in_bits;
69} GetBitContext;
70
71#define VLC_TYPE int16_t
72
73typedef struct VLC {
74 int bits;
75 VLC_TYPE (*table)[2]; ///< code, bits
76 int table_size, table_allocated;
77} VLC;
78
79typedef struct RL_VLC_ELEM {
80 int16_t level;
81 int8_t len;
82 uint8_t run;
83} RL_VLC_ELEM;
84
85/* Bitstream reader API docs:
86name
87 arbitrary name which is used as prefix for the internal variables
88
89gb
90 getbitcontext
91
92OPEN_READER(name, gb)
93 loads gb into local variables
94
95CLOSE_READER(name, gb)
96 stores local vars in gb
97
98UPDATE_CACHE(name, gb)
99 refills the internal cache from the bitstream
100 after this call at least MIN_CACHE_BITS will be available,
101
102GET_CACHE(name, gb)
103 will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit)
104
105SHOW_UBITS(name, gb, num)
106 will return the next num bits
107
108SHOW_SBITS(name, gb, num)
109 will return the next num bits and do sign extension
110
111SKIP_BITS(name, gb, num)
112 will skip over the next num bits
113 note, this is equivalent to SKIP_CACHE; SKIP_COUNTER
114
115SKIP_CACHE(name, gb, num)
116 will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER)
117
118SKIP_COUNTER(name, gb, num)
119 will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS)
120
121LAST_SKIP_CACHE(name, gb, num)
122 will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing
123
124LAST_SKIP_BITS(name, gb, num)
125 is equivalent to LAST_SKIP_CACHE; SKIP_COUNTER
126
127for examples see get_bits, show_bits, skip_bits, get_vlc
128*/
129
130#ifdef ALT_BITSTREAM_READER
131# define MIN_CACHE_BITS 25
132
133# define OPEN_READER(name, gb)\
134 unsigned int name##_index= (gb)->index;\
135 int name##_cache= 0;\
136
137# define CLOSE_READER(name, gb)\
138 (gb)->index= name##_index;\
139
140# ifdef ALT_BITSTREAM_READER_LE
141# define UPDATE_CACHE(name, gb)\
142 name##_cache= AV_RL32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\
143
144# define SKIP_CACHE(name, gb, num)\
145 name##_cache >>= (num);
146# else
147# define UPDATE_CACHE(name, gb)\
148 name##_cache= AV_RB32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
149
150# define SKIP_CACHE(name, gb, num)\
151 name##_cache <<= (num);
152# endif
153
154// FIXME name?
155# define SKIP_COUNTER(name, gb, num)\
156 name##_index += (num);\
157
158# define SKIP_BITS(name, gb, num)\
159 {\
160 SKIP_CACHE(name, gb, num)\
161 SKIP_COUNTER(name, gb, num)\
162 }\
163
164# define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
165# define LAST_SKIP_CACHE(name, gb, num) ;
166
167# ifdef ALT_BITSTREAM_READER_LE
168# define SHOW_UBITS(name, gb, num)\
169 zero_extend(name##_cache, num)
170
171# define SHOW_SBITS(name, gb, num)\
172 sign_extend(name##_cache, num)
173# else
174# define SHOW_UBITS(name, gb, num)\
175 NEG_USR32(name##_cache, num)
176
177# define SHOW_SBITS(name, gb, num)\
178 NEG_SSR32(name##_cache, num)
179# endif
180
181# define GET_CACHE(name, gb)\
182 ((uint32_t)name##_cache)
183
184static inline int get_bits_count(const GetBitContext *s){
185 return s->index;
186}
187
188static inline void skip_bits_long(GetBitContext *s, int n){
189 s->index += n;
190}
191
192#elif defined LIBMPEG2_BITSTREAM_READER
193//libmpeg2 like reader
194
195# define MIN_CACHE_BITS 17
196
197# define OPEN_READER(name, gb)\
198 int name##_bit_count=(gb)->bit_count;\
199 int name##_cache= (gb)->cache;\
200 uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\
201
202# define CLOSE_READER(name, gb)\
203 (gb)->bit_count= name##_bit_count;\
204 (gb)->cache= name##_cache;\
205 (gb)->buffer_ptr= name##_buffer_ptr;\
206
207# define UPDATE_CACHE(name, gb)\
208 if(name##_bit_count >= 0){\
209 name##_cache+= AV_RB16(name##_buffer_ptr) << name##_bit_count; \
210 name##_buffer_ptr+=2;\
211 name##_bit_count-= 16;\
212 }\
213
214# define SKIP_CACHE(name, gb, num)\
215 name##_cache <<= (num);\
216
217# define SKIP_COUNTER(name, gb, num)\
218 name##_bit_count += (num);\
219
220# define SKIP_BITS(name, gb, num)\
221 {\
222 SKIP_CACHE(name, gb, num)\
223 SKIP_COUNTER(name, gb, num)\
224 }\
225
226# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
227# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
228
229# define SHOW_UBITS(name, gb, num)\
230 NEG_USR32(name##_cache, num)
231
232# define SHOW_SBITS(name, gb, num)\
233 NEG_SSR32(name##_cache, num)
234
235# define GET_CACHE(name, gb)\
236 ((uint32_t)name##_cache)
237
238static inline int get_bits_count(const GetBitContext *s){
239 return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count;
240}
241
242static inline void skip_bits_long(GetBitContext *s, int n){
243 OPEN_READER(re, s)
244 re_bit_count += n;
245 re_buffer_ptr += 2*(re_bit_count>>4);
246 re_bit_count &= 15;
247 re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count);
248 UPDATE_CACHE(re, s)
249 CLOSE_READER(re, s)
250}
251
252#elif defined A32_BITSTREAM_READER
253
254# define MIN_CACHE_BITS 32
255
256# define OPEN_READER(name, gb)\
257 int name##_bit_count=(gb)->bit_count;\
258 uint32_t name##_cache0= (gb)->cache0;\
259 uint32_t name##_cache1= (gb)->cache1;\
260 uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\
261
262# define CLOSE_READER(name, gb)\
263 (gb)->bit_count= name##_bit_count;\
264 (gb)->cache0= name##_cache0;\
265 (gb)->cache1= name##_cache1;\
266 (gb)->buffer_ptr= name##_buffer_ptr;\
267
268# define UPDATE_CACHE(name, gb)\
269 if(name##_bit_count > 0){\
270 const uint32_t next= be2me_32( *name##_buffer_ptr );\
271 name##_cache0 |= NEG_USR32(next,name##_bit_count);\
272 name##_cache1 |= next<<name##_bit_count;\
273 name##_buffer_ptr++;\
274 name##_bit_count-= 32;\
275 }\
276
277#if ARCH_X86
278# define SKIP_CACHE(name, gb, num)\
279 __asm__(\
280 "shldl %2, %1, %0 \n\t"\
281 "shll %2, %1 \n\t"\
282 : "+r" (name##_cache0), "+r" (name##_cache1)\
283 : "Ic" ((uint8_t)(num))\
284 );
285#else
286# define SKIP_CACHE(name, gb, num)\
287 name##_cache0 <<= (num);\
288 name##_cache0 |= NEG_USR32(name##_cache1,num);\
289 name##_cache1 <<= (num);
290#endif
291
292# define SKIP_COUNTER(name, gb, num)\
293 name##_bit_count += (num);\
294
295# define SKIP_BITS(name, gb, num)\
296 {\
297 SKIP_CACHE(name, gb, num)\
298 SKIP_COUNTER(name, gb, num)\
299 }\
300
301# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
302# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
303
304# define SHOW_UBITS(name, gb, num)\
305 NEG_USR32(name##_cache0, num)
306
307# define SHOW_SBITS(name, gb, num)\
308 NEG_SSR32(name##_cache0, num)
309
310# define GET_CACHE(name, gb)\
311 (name##_cache0)
312
313static inline int get_bits_count(const GetBitContext *s){
314 return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count;
315}
316
317static inline void skip_bits_long(GetBitContext *s, int n){
318 OPEN_READER(re, s)
319 re_bit_count += n;
320 re_buffer_ptr += re_bit_count>>5;
321 re_bit_count &= 31;
322 re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count;
323 re_cache1 = 0;
324 UPDATE_CACHE(re, s)
325 CLOSE_READER(re, s)
326}
327
328#endif
329
330/**
331 * read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
332 * if MSB not set it is negative
333 * @param n length in bits
334 * @author BERO
335 */
336static inline int get_xbits(GetBitContext *s, int n){
337 register int sign;
338 register int32_t cache;
339 OPEN_READER(re, s)
340 UPDATE_CACHE(re, s)
341 cache = GET_CACHE(re,s);
342 sign=(~cache)>>31;
343 LAST_SKIP_BITS(re, s, n)
344 CLOSE_READER(re, s)
345 return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
346}
347
348static inline int get_sbits(GetBitContext *s, int n){
349 register int tmp;
350 OPEN_READER(re, s)
351 UPDATE_CACHE(re, s)
352 tmp= SHOW_SBITS(re, s, n);
353 LAST_SKIP_BITS(re, s, n)
354 CLOSE_READER(re, s)
355 return tmp;
356}
357
358/**
359 * reads 1-17 bits.
360 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
361 */
362static inline unsigned int get_bits(GetBitContext *s, int n){
363 register int tmp;
364 OPEN_READER(re, s)
365 UPDATE_CACHE(re, s)
366 tmp= SHOW_UBITS(re, s, n);
367 LAST_SKIP_BITS(re, s, n)
368 CLOSE_READER(re, s)
369 return tmp;
370}
371
372/**
373 * shows 1-17 bits.
374 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
375 */
376static inline unsigned int show_bits(GetBitContext *s, int n){
377 register int tmp;
378 OPEN_READER(re, s)
379 UPDATE_CACHE(re, s)
380 tmp= SHOW_UBITS(re, s, n);
381// CLOSE_READER(re, s)
382 return tmp;
383}
384
385static inline void skip_bits(GetBitContext *s, int n){
386 //Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
387 OPEN_READER(re, s)
388 UPDATE_CACHE(re, s)
389 LAST_SKIP_BITS(re, s, n)
390 CLOSE_READER(re, s)
391}
392
393static inline unsigned int get_bits1(GetBitContext *s){
394#ifdef ALT_BITSTREAM_READER
395 unsigned int index= s->index;
396 uint8_t result= s->buffer[ index>>3 ];
397#ifdef ALT_BITSTREAM_READER_LE
398 result>>= (index&0x07);
399 result&= 1;
400#else
401 result<<= (index&0x07);
402 result>>= 8 - 1;
403#endif
404 index++;
405 s->index= index;
406
407 return result;
408#else
409 return get_bits(s, 1);
410#endif
411}
412
413static inline unsigned int show_bits1(GetBitContext *s){
414 return show_bits(s, 1);
415}
416
417static inline void skip_bits1(GetBitContext *s){
418 skip_bits(s, 1);
419}
420
421/**
422 * reads 0-32 bits.
423 */
424static inline unsigned int get_bits_long(GetBitContext *s, int n){
425 if(n<=MIN_CACHE_BITS) return get_bits(s, n);
426 else{
427#ifdef ALT_BITSTREAM_READER_LE
428 int ret= get_bits(s, 16);
429 return ret | (get_bits(s, n-16) << 16);
430#else
431 int ret= get_bits(s, 16) << (n-16);
432 return ret | get_bits(s, n-16);
433#endif
434 }
435}
436#if 0
437/* mt : switched those off */
438/**
439 * reads 0-32 bits as a signed integer.
440 */
441static inline int get_sbits_long(GetBitContext *s, int n) {
442 return sign_extend(get_bits_long(s, n), n);
443}
444#endif
445/**
446 * shows 0-32 bits.
447 */
448static inline unsigned int show_bits_long(GetBitContext *s, int n){
449 if(n<=MIN_CACHE_BITS) return show_bits(s, n);
450 else{
451 GetBitContext gb= *s;
452 return get_bits_long(&gb, n);
453 }
454}
455
456static inline int check_marker(GetBitContext *s, const char *msg)
457{
458 int bit= get_bits1(s);
459 if(!bit)
460 av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg);
461
462 return bit;
463}
464
465/**
466 * init GetBitContext.
467 * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits
468 * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
469 * @param bit_size the size of the buffer in bits
470 *
471 * While GetBitContext stores the buffer size, for performance reasons you are
472 * responsible for checking for the buffer end yourself (take advantage of the padding)!
473 */
474static inline void init_get_bits(GetBitContext *s,
475 const uint8_t *buffer, int bit_size)
476{
477 int buffer_size= (bit_size+7)>>3;
478 if(buffer_size < 0 || bit_size < 0) {
479 buffer_size = bit_size = 0;
480 buffer = NULL;
481 }
482
483 s->buffer= buffer;
484 s->size_in_bits= bit_size;
485 s->buffer_end= buffer + buffer_size;
486#ifdef ALT_BITSTREAM_READER
487 s->index=0;
488#elif defined LIBMPEG2_BITSTREAM_READER
489 s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));
490 s->bit_count = 16 + 8*((intptr_t)buffer&1);
491 skip_bits_long(s, 0);
492#elif defined A32_BITSTREAM_READER
493 s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));
494 s->bit_count = 32 + 8*((intptr_t)buffer&3);
495 skip_bits_long(s, 0);
496#endif
497}
498
499static inline void align_get_bits(GetBitContext *s)
500{
501 int n= (-get_bits_count(s)) & 7;
502 if(n) skip_bits(s, n);
503}
504
505#define init_vlc(vlc, nb_bits, nb_codes,\
506 bits, bits_wrap, bits_size,\
507 codes, codes_wrap, codes_size,\
508 flags)\
509 init_vlc_sparse(vlc, nb_bits, nb_codes,\
510 bits, bits_wrap, bits_size,\
511 codes, codes_wrap, codes_size,\
512 NULL, 0, 0, flags)
513
514int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
515 const void *bits, int bits_wrap, int bits_size,
516 const void *codes, int codes_wrap, int codes_size,
517 const void *symbols, int symbols_wrap, int symbols_size,
518 int flags);
519#define INIT_VLC_LE 2
520#define INIT_VLC_USE_NEW_STATIC 4
521void free_vlc(VLC *vlc);
522
523#define INIT_VLC_STATIC(vlc, bits, a,b,c,d,e,f,g, static_size)\
524{\
525 static VLC_TYPE table[static_size][2];\
526 (vlc)->table= table;\
527 (vlc)->table_allocated= static_size;\
528 init_vlc(vlc, bits, a,b,c,d,e,f,g, INIT_VLC_USE_NEW_STATIC);\
529}
530
531
532/**
533 *
534 * If the vlc code is invalid and max_depth=1, then no bits will be removed.
535 * If the vlc code is invalid and max_depth>1, then the number of bits removed
536 * is undefined.
537 */
538#define GET_VLC(code, name, gb, table, bits, max_depth)\
539{\
540 int n, nb_bits;\
541 unsigned int index;\
542\
543 index= SHOW_UBITS(name, gb, bits);\
544 code = table[index][0];\
545 n = table[index][1];\
546\
547 if(max_depth > 1 && n < 0){\
548 LAST_SKIP_BITS(name, gb, bits)\
549 UPDATE_CACHE(name, gb)\
550\
551 nb_bits = -n;\
552\
553 index= SHOW_UBITS(name, gb, nb_bits) + code;\
554 code = table[index][0];\
555 n = table[index][1];\
556 if(max_depth > 2 && n < 0){\
557 LAST_SKIP_BITS(name, gb, nb_bits)\
558 UPDATE_CACHE(name, gb)\
559\
560 nb_bits = -n;\
561\
562 index= SHOW_UBITS(name, gb, nb_bits) + code;\
563 code = table[index][0];\
564 n = table[index][1];\
565 }\
566 }\
567 SKIP_BITS(name, gb, n)\
568}
569
570#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\
571{\
572 int n, nb_bits;\
573 unsigned int index;\
574\
575 index= SHOW_UBITS(name, gb, bits);\
576 level = table[index].level;\
577 n = table[index].len;\
578\
579 if(max_depth > 1 && n < 0){\
580 SKIP_BITS(name, gb, bits)\
581 if(need_update){\
582 UPDATE_CACHE(name, gb)\
583 }\
584\
585 nb_bits = -n;\
586\
587 index= SHOW_UBITS(name, gb, nb_bits) + level;\
588 level = table[index].level;\
589 n = table[index].len;\
590 }\
591 run= table[index].run;\
592 SKIP_BITS(name, gb, n)\
593}
594
595
596/**
597 * parses a vlc code, faster then get_vlc()
598 * @param bits is the number of bits which will be read at once, must be
599 * identical to nb_bits in init_vlc()
600 * @param max_depth is the number of times bits bits must be read to completely
601 * read the longest vlc code
602 * = (max_vlc_length + bits - 1) / bits
603 */
604static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
605 int bits, int max_depth)
606{
607 int code;
608
609 OPEN_READER(re, s)
610 UPDATE_CACHE(re, s)
611
612 GET_VLC(code, re, s, table, bits, max_depth)
613
614 CLOSE_READER(re, s)
615 return code;
616}
617
618//#define TRACE
619
620#ifdef TRACE
621static inline void print_bin(int bits, int n){
622 int i;
623
624 for(i=n-1; i>=0; i--){
625 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1);
626 }
627 for(i=n; i<24; i++)
628 av_log(NULL, AV_LOG_DEBUG, " ");
629}
630
631static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
632 int r= get_bits(s, n);
633
634 print_bin(r, n);
635 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line);
636 return r;
637}
638static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){
639 int show= show_bits(s, 24);
640 int pos= get_bits_count(s);
641 int r= get_vlc2(s, table, bits, max_depth);
642 int len= get_bits_count(s) - pos;
643 int bits2= show>>(24-len);
644
645 print_bin(bits2, len);
646
647 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
648 return r;
649}
650static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
651 int show= show_bits(s, n);
652 int r= get_xbits(s, n);
653
654 print_bin(show, n);
655 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line);
656 return r;
657}
658
659#define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
660#define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
661#define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
662#define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
663#define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
664
665#define tprintf(p, ...) av_log(p, AV_LOG_DEBUG, __VA_ARGS__)
666
667#else //TRACE
668#define tprintf(p, ...) {}
669#endif
670
671static inline int decode012(GetBitContext *gb){
672 int n;
673 n = get_bits1(gb);
674 if (n == 0)
675 return 0;
676 else
677 return get_bits1(gb) + 1;
678}
679
680static inline int decode210(GetBitContext *gb){
681 if (get_bits1(gb))
682 return 0;
683 else
684 return 2 - get_bits1(gb);
685}
686
687static inline int get_bits_left(GetBitContext *gb)
688{
689 return gb->size_in_bits - get_bits_count(gb);
690}
691
692#endif /* AVCODEC_GET_BITS_H */
diff --git a/apps/codecs/libwmapro/internal.h b/apps/codecs/libwmapro/internal.h
new file mode 100644
index 0000000000..b813480be9
--- /dev/null
+++ b/apps/codecs/libwmapro/internal.h
@@ -0,0 +1,51 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19/**
20 * @file libavcodec/internal.h
21 * common internal api header.
22 */
23
24#ifndef AVCODEC_INTERNAL_H
25#define AVCODEC_INTERNAL_H
26
27#include <stdint.h>
28#include "avcodec.h"
29
30/**
31 * Determines whether pix_fmt is a hardware accelerated format.
32 */
33//int ff_is_hwaccel_pix_fmt(enum PixelFormat pix_fmt);
34
35/**
36 * Returns the hardware accelerated codec for codec codec_id and
37 * pixel format pix_fmt.
38 *
39 * @param codec_id the codec to match
40 * @param pix_fmt the pixel format to match
41 * @return the hardware accelerated codec, or NULL if none was found.
42 */
43//AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt);
44
45/**
46 * Return the index into tab at which {a,b} match elements {[0],[1]} of tab.
47 * If there is no such matching pair then size is returned.
48 */
49int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b);
50
51#endif /* AVCODEC_INTERNAL_H */
diff --git a/apps/codecs/libwmapro/libavutil/attributes.h b/apps/codecs/libwmapro/libavutil/attributes.h
new file mode 100644
index 0000000000..1208bc0c72
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/attributes.h
@@ -0,0 +1,113 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file libavutil/attributes.h
23 * Macro definitions for various function/variable attributes
24 */
25
26#ifndef AVUTIL_ATTRIBUTES_H
27#define AVUTIL_ATTRIBUTES_H
28
29#ifdef __GNUC__
30# define AV_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNUC_MINOR__ >= y)
31#else
32# define AV_GCC_VERSION_AT_LEAST(x,y) 0
33#endif
34
35#ifndef av_always_inline
36#if AV_GCC_VERSION_AT_LEAST(3,1)
37# define av_always_inline __attribute__((always_inline)) inline
38#else
39# define av_always_inline inline
40#endif
41#endif
42
43#ifndef av_noinline
44#if AV_GCC_VERSION_AT_LEAST(3,1)
45# define av_noinline __attribute__((noinline))
46#else
47# define av_noinline
48#endif
49#endif
50
51#ifndef av_pure
52#if AV_GCC_VERSION_AT_LEAST(3,1)
53# define av_pure __attribute__((pure))
54#else
55# define av_pure
56#endif
57#endif
58
59#ifndef av_const
60#if AV_GCC_VERSION_AT_LEAST(2,6)
61# define av_const __attribute__((const))
62#else
63# define av_const
64#endif
65#endif
66
67#ifndef av_cold
68#if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,3)
69# define av_cold __attribute__((cold))
70#else
71# define av_cold
72#endif
73#endif
74
75#ifndef av_flatten
76#if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,1)
77# define av_flatten __attribute__((flatten))
78#else
79# define av_flatten
80#endif
81#endif
82
83#ifndef attribute_deprecated
84#if AV_GCC_VERSION_AT_LEAST(3,1)
85# define attribute_deprecated __attribute__((deprecated))
86#else
87# define attribute_deprecated
88#endif
89#endif
90
91#ifndef av_unused
92#if defined(__GNUC__)
93# define av_unused __attribute__((unused))
94#else
95# define av_unused
96#endif
97#endif
98
99#ifndef av_uninit
100#if defined(__GNUC__) && !defined(__ICC)
101# define av_uninit(x) x=x
102#else
103# define av_uninit(x) x
104#endif
105#endif
106
107#ifdef __GNUC__
108# define av_builtin_constant_p __builtin_constant_p
109#else
110# define av_builtin_constant_p(x) 0
111#endif
112
113#endif /* AVUTIL_ATTRIBUTES_H */
diff --git a/apps/codecs/libwmapro/libavutil/avutil.h b/apps/codecs/libwmapro/libavutil/avutil.h
new file mode 100644
index 0000000000..c07e44d660
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/avutil.h
@@ -0,0 +1,63 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef AVUTIL_AVUTIL_H
22#define AVUTIL_AVUTIL_H
23
24/**
25 * @file libavutil/avutil.h
26 * external API header
27 */
28
29
30#define AV_STRINGIFY(s) AV_TOSTRING(s)
31#define AV_TOSTRING(s) #s
32
33#define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c)
34#define AV_VERSION_DOT(a, b, c) a ##.## b ##.## c
35#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
36
37#define LIBAVUTIL_VERSION_MAJOR 50
38#define LIBAVUTIL_VERSION_MINOR 0
39#define LIBAVUTIL_VERSION_MICRO 0
40
41#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
42 LIBAVUTIL_VERSION_MINOR, \
43 LIBAVUTIL_VERSION_MICRO)
44#define LIBAVUTIL_VERSION AV_VERSION(LIBAVUTIL_VERSION_MAJOR, \
45 LIBAVUTIL_VERSION_MINOR, \
46 LIBAVUTIL_VERSION_MICRO)
47#define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT
48
49#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION)
50
51/**
52 * Returns the LIBAVUTIL_VERSION_INT constant.
53 */
54unsigned avutil_version(void);
55
56#include "common.h"
57//#include "mathematics.h"
58//#include "rational.h"
59//#include "intfloat_readwrite.h"
60#include "log.h"
61//#include "pixfmt.h"
62
63#endif /* AVUTIL_AVUTIL_H */
diff --git a/apps/codecs/libwmapro/libavutil/bswap.h b/apps/codecs/libwmapro/libavutil/bswap.h
new file mode 100644
index 0000000000..9175cb24a5
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/bswap.h
@@ -0,0 +1,99 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file libavutil/bswap.h
23 * byte swapping routines
24 */
25
26#ifndef AVUTIL_BSWAP_H
27#define AVUTIL_BSWAP_H
28
29#include <stdint.h>
30//#include "ffmpeg_config.h"
31#include "common.h"
32
33#if ARCH_ARM
34# include "arm/bswap.h"
35#elif ARCH_BFIN
36# include "bfin/bswap.h"
37#elif ARCH_SH4
38# include "sh4/bswap.h"
39#elif ARCH_X86
40# include "x86/bswap.h"
41#endif
42
43#ifndef bswap_16
44static av_always_inline av_const uint16_t bswap_16(uint16_t x)
45{
46 x= (x>>8) | (x<<8);
47 return x;
48}
49#endif
50
51#ifndef bswap_32
52static av_always_inline av_const uint32_t bswap_32(uint32_t x)
53{
54 x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
55 x= (x>>16) | (x<<16);
56 return x;
57}
58#endif
59
60#ifndef bswap_64
61static inline uint64_t av_const bswap_64(uint64_t x)
62{
63#if 0
64 x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
65 x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
66 return (x>>32) | (x<<32);
67#else
68 union {
69 uint64_t ll;
70 uint32_t l[2];
71 } w, r;
72 w.ll = x;
73 r.l[0] = bswap_32 (w.l[1]);
74 r.l[1] = bswap_32 (w.l[0]);
75 return r.ll;
76#endif
77}
78#endif
79
80// be2me ... big-endian to machine-endian
81// le2me ... little-endian to machine-endian
82
83#ifdef WORDS_BIGENDIAN
84#define be2me_16(x) (x)
85#define be2me_32(x) (x)
86#define be2me_64(x) (x)
87#define le2me_16(x) bswap_16(x)
88#define le2me_32(x) bswap_32(x)
89#define le2me_64(x) bswap_64(x)
90#else
91#define be2me_16(x) bswap_16(x)
92#define be2me_32(x) bswap_32(x)
93#define be2me_64(x) bswap_64(x)
94#define le2me_16(x) (x)
95#define le2me_32(x) (x)
96#define le2me_64(x) (x)
97#endif
98
99#endif /* AVUTIL_BSWAP_H */
diff --git a/apps/codecs/libwmapro/libavutil/common.h b/apps/codecs/libwmapro/libavutil/common.h
new file mode 100644
index 0000000000..f3bc4ba44b
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/common.h
@@ -0,0 +1,299 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file libavutil/common.h
23 * common internal and external API header
24 */
25
26#ifndef AVUTIL_COMMON_H
27#define AVUTIL_COMMON_H
28
29#include <ctype.h>
30#include <errno.h>
31#include <inttypes.h>
32#include <limits.h>
33#include <math.h>
34#include <stdio.h>
35#include <stdlib.h>
36#include <string.h>
37#include "attributes.h"
38#include "internal.h"
39
40//rounded division & shift
41#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
42/* assume b>0 */
43#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
44#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
45#define FFSIGN(a) ((a) > 0 ? 1 : -1)
46
47#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
48#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
49#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
50#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
51
52#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
53#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
54#define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))
55
56/* misc math functions */
57extern const uint8_t ff_log2_tab[256];
58
59extern const uint8_t av_reverse[256];
60
61static inline av_const int av_log2_c(unsigned int v)
62{
63 int n = 0;
64 if (v & 0xffff0000) {
65 v >>= 16;
66 n += 16;
67 }
68 if (v & 0xff00) {
69 v >>= 8;
70 n += 8;
71 }
72 n += ff_log2_tab[v];
73
74 return n;
75}
76
77static inline av_const int av_log2_16bit_c(unsigned int v)
78{
79 int n = 0;
80 if (v & 0xff00) {
81 v >>= 8;
82 n += 8;
83 }
84 n += ff_log2_tab[v];
85
86 return n;
87}
88
89#ifdef HAVE_AV_CONFIG_H
90# include "config.h"
91# include "intmath.h"
92#endif
93
94#ifndef av_log2
95# define av_log2 av_log2_c
96#endif
97#ifndef av_log2_16bit
98# define av_log2_16bit av_log2_16bit_c
99#endif
100
101/**
102 * Clips a signed integer value into the amin-amax range.
103 * @param a value to clip
104 * @param amin minimum value of the clip range
105 * @param amax maximum value of the clip range
106 * @return clipped value
107 */
108static inline av_const int av_clip(int a, int amin, int amax)
109{
110 if (a < amin) return amin;
111 else if (a > amax) return amax;
112 else return a;
113}
114
115/**
116 * Clips a signed integer value into the 0-255 range.
117 * @param a value to clip
118 * @return clipped value
119 */
120static inline av_const uint8_t av_clip_uint8(int a)
121{
122 if (a&(~255)) return (-a)>>31;
123 else return a;
124}
125
126/**
127 * Clips a signed integer value into the 0-65535 range.
128 * @param a value to clip
129 * @return clipped value
130 */
131static inline av_const uint16_t av_clip_uint16(int a)
132{
133 if (a&(~65535)) return (-a)>>31;
134 else return a;
135}
136
137/**
138 * Clips a signed integer value into the -32768,32767 range.
139 * @param a value to clip
140 * @return clipped value
141 */
142static inline av_const int16_t av_clip_int16(int a)
143{
144 if ((a+32768) & ~65535) return (a>>31) ^ 32767;
145 else return a;
146}
147
148/**
149 * Clips a float value into the amin-amax range.
150 * @param a value to clip
151 * @param amin minimum value of the clip range
152 * @param amax maximum value of the clip range
153 * @return clipped value
154 */
155static inline av_const float av_clipf(float a, float amin, float amax)
156{
157 if (a < amin) return amin;
158 else if (a > amax) return amax;
159 else return a;
160}
161
162/** Computes ceil(log2(x)).
163 * @param x value used to compute ceil(log2(x))
164 * @return computed ceiling of log2(x)
165 */
166static inline av_const int av_ceil_log2(int x)
167{
168 return av_log2((x - 1) << 1);
169}
170
171#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
172#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
173
174/*!
175 * \def GET_UTF8(val, GET_BYTE, ERROR)
176 * Converts a UTF-8 character (up to 4 bytes long) to its 32-bit UCS-4 encoded form
177 * \param val is the output and should be of type uint32_t. It holds the converted
178 * UCS-4 character and should be a left value.
179 * \param GET_BYTE gets UTF-8 encoded bytes from any proper source. It can be
180 * a function or a statement whose return value or evaluated value is of type
181 * uint8_t. It will be executed up to 4 times for values in the valid UTF-8 range,
182 * and up to 7 times in the general case.
183 * \param ERROR action that should be taken when an invalid UTF-8 byte is returned
184 * from GET_BYTE. It should be a statement that jumps out of the macro,
185 * like exit(), goto, return, break, or continue.
186 */
187#define GET_UTF8(val, GET_BYTE, ERROR)\
188 val= GET_BYTE;\
189 {\
190 int ones= 7 - av_log2(val ^ 255);\
191 if(ones==1)\
192 ERROR\
193 val&= 127>>ones;\
194 while(--ones > 0){\
195 int tmp= GET_BYTE - 128;\
196 if(tmp>>6)\
197 ERROR\
198 val= (val<<6) + tmp;\
199 }\
200 }
201
202/*!
203 * \def GET_UTF16(val, GET_16BIT, ERROR)
204 * Converts a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form
205 * \param val is the output and should be of type uint32_t. It holds the converted
206 * UCS-4 character and should be a left value.
207 * \param GET_16BIT gets two bytes of UTF-16 encoded data converted to native endianness.
208 * It can be a function or a statement whose return value or evaluated value is of type
209 * uint16_t. It will be executed up to 2 times.
210 * \param ERROR action that should be taken when an invalid UTF-16 surrogate is
211 * returned from GET_BYTE. It should be a statement that jumps out of the macro,
212 * like exit(), goto, return, break, or continue.
213 */
214#define GET_UTF16(val, GET_16BIT, ERROR)\
215 val = GET_16BIT;\
216 {\
217 unsigned int hi = val - 0xD800;\
218 if (hi < 0x800) {\
219 val = GET_16BIT - 0xDC00;\
220 if (val > 0x3FFU || hi > 0x3FFU)\
221 ERROR\
222 val += (hi<<10) + 0x10000;\
223 }\
224 }\
225
226/*!
227 * \def PUT_UTF8(val, tmp, PUT_BYTE)
228 * Converts a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long).
229 * \param val is an input-only argument and should be of type uint32_t. It holds
230 * a UCS-4 encoded Unicode character that is to be converted to UTF-8. If
231 * val is given as a function it is executed only once.
232 * \param tmp is a temporary variable and should be of type uint8_t. It
233 * represents an intermediate value during conversion that is to be
234 * output by PUT_BYTE.
235 * \param PUT_BYTE writes the converted UTF-8 bytes to any proper destination.
236 * It could be a function or a statement, and uses tmp as the input byte.
237 * For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be
238 * executed up to 4 times for values in the valid UTF-8 range and up to
239 * 7 times in the general case, depending on the length of the converted
240 * Unicode character.
241 */
242#define PUT_UTF8(val, tmp, PUT_BYTE)\
243 {\
244 int bytes, shift;\
245 uint32_t in = val;\
246 if (in < 0x80) {\
247 tmp = in;\
248 PUT_BYTE\
249 } else {\
250 bytes = (av_log2(in) + 4) / 5;\
251 shift = (bytes - 1) * 6;\
252 tmp = (256 - (256 >> bytes)) | (in >> shift);\
253 PUT_BYTE\
254 while (shift >= 6) {\
255 shift -= 6;\
256 tmp = 0x80 | ((in >> shift) & 0x3f);\
257 PUT_BYTE\
258 }\
259 }\
260 }
261
262/*!
263 * \def PUT_UTF16(val, tmp, PUT_16BIT)
264 * Converts a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes).
265 * \param val is an input-only argument and should be of type uint32_t. It holds
266 * a UCS-4 encoded Unicode character that is to be converted to UTF-16. If
267 * val is given as a function it is executed only once.
268 * \param tmp is a temporary variable and should be of type uint16_t. It
269 * represents an intermediate value during conversion that is to be
270 * output by PUT_16BIT.
271 * \param PUT_16BIT writes the converted UTF-16 data to any proper destination
272 * in desired endianness. It could be a function or a statement, and uses tmp
273 * as the input byte. For example, PUT_BYTE could be "*output++ = tmp;"
274 * PUT_BYTE will be executed 1 or 2 times depending on input character.
275 */
276#define PUT_UTF16(val, tmp, PUT_16BIT)\
277 {\
278 uint32_t in = val;\
279 if (in < 0x10000) {\
280 tmp = in;\
281 PUT_16BIT\
282 } else {\
283 tmp = 0xD800 | ((in - 0x10000) >> 10);\
284 PUT_16BIT\
285 tmp = 0xDC00 | ((in - 0x10000) & 0x3FF);\
286 PUT_16BIT\
287 }\
288 }\
289
290
291
292#include "mem.h"
293
294#if 0
295#ifdef HAVE_AV_CONFIG_H
296# include "internal.h"
297#endif /* HAVE_AV_CONFIG_H */
298#endif
299#endif /* AVUTIL_COMMON_H */
diff --git a/apps/codecs/libwmapro/libavutil/internal.h b/apps/codecs/libwmapro/libavutil/internal.h
new file mode 100644
index 0000000000..2b8da1d8c2
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/internal.h
@@ -0,0 +1,207 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file libavutil/internal.h
23 * common internal API header
24 */
25
26#ifndef AVUTIL_INTERNAL_H
27#define AVUTIL_INTERNAL_H
28
29#if !defined(DEBUG) && !defined(NDEBUG)
30# define NDEBUG
31#endif
32
33#include <limits.h>
34#include <stdint.h>
35#include <stddef.h>
36#include <assert.h>
37//#include "config.h"
38#include "attributes.h"
39//#include "timer.h"
40
41#ifndef attribute_align_arg
42#if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,2)
43# define attribute_align_arg __attribute__((force_align_arg_pointer))
44#else
45# define attribute_align_arg
46#endif
47#endif
48
49#ifndef attribute_used
50#if AV_GCC_VERSION_AT_LEAST(3,1)
51# define attribute_used __attribute__((used))
52#else
53# define attribute_used
54#endif
55#endif
56
57#ifndef av_alias
58#if HAVE_ATTRIBUTE_MAY_ALIAS && (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(3,3)
59# define av_alias __attribute__((may_alias))
60#else
61# define av_alias
62#endif
63#endif
64
65#ifndef INT16_MIN
66#define INT16_MIN (-0x7fff - 1)
67#endif
68
69#ifndef INT16_MAX
70#define INT16_MAX 0x7fff
71#endif
72
73#ifndef INT32_MIN
74#define INT32_MIN (-0x7fffffff - 1)
75#endif
76
77#ifndef INT32_MAX
78#define INT32_MAX 0x7fffffff
79#endif
80
81#ifndef UINT32_MAX
82#define UINT32_MAX 0xffffffff
83#endif
84
85#ifndef INT64_MIN
86#define INT64_MIN (-0x7fffffffffffffffLL - 1)
87#endif
88
89#ifndef INT64_MAX
90#define INT64_MAX INT64_C(9223372036854775807)
91#endif
92
93#ifndef UINT64_MAX
94#define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
95#endif
96
97#ifndef INT_BIT
98# define INT_BIT (CHAR_BIT * sizeof(int))
99#endif
100
101#ifndef offsetof
102# define offsetof(T, F) ((unsigned int)((char *)&((T *)0)->F))
103#endif
104
105/* Use to export labels from asm. */
106#define LABEL_MANGLE(a) EXTERN_PREFIX #a
107
108// Use rip-relative addressing if compiling PIC code on x86-64.
109#if ARCH_X86_64 && defined(PIC)
110# define LOCAL_MANGLE(a) #a "(%%rip)"
111#else
112# define LOCAL_MANGLE(a) #a
113#endif
114
115#define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
116
117/* debug stuff */
118
119/* dprintf macros */
120#ifdef DEBUG
121# define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
122#else
123# define dprintf(pctx, ...)
124#endif
125
126#define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
127
128/* math */
129
130#if ARCH_X86
131#define MASK_ABS(mask, level)\
132 __asm__ volatile(\
133 "cltd \n\t"\
134 "xorl %1, %0 \n\t"\
135 "subl %1, %0 \n\t"\
136 : "+a" (level), "=&d" (mask)\
137 );
138#else
139#define MASK_ABS(mask, level)\
140 mask = level >> 31;\
141 level = (level ^ mask) - mask;
142#endif
143
144/* avoid usage of dangerous/inappropriate system functions */
145#undef malloc
146#define malloc please_use_av_malloc
147#undef free
148#define free please_use_av_free
149#undef realloc
150#define realloc please_use_av_realloc
151#undef time
152#define time time_is_forbidden_due_to_security_issues
153#undef rand
154#define rand rand_is_forbidden_due_to_state_trashing_use_av_lfg_get
155#undef srand
156#define srand srand_is_forbidden_due_to_state_trashing_use_av_lfg_init
157#undef random
158#define random random_is_forbidden_due_to_state_trashing_use_av_lfg_get
159#undef sprintf
160#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
161#undef strcat
162#define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
163#undef exit
164#define exit exit_is_forbidden
165#ifndef LIBAVFORMAT_BUILD
166#undef printf
167#define printf please_use_av_log_instead_of_printf
168#undef fprintf
169#define fprintf please_use_av_log_instead_of_fprintf
170#undef puts
171#define puts please_use_av_log_instead_of_puts
172#undef perror
173#define perror please_use_av_log_instead_of_perror
174#endif
175
176#define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
177{\
178 p = av_malloc(size);\
179 if (p == NULL && (size) != 0) {\
180 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
181 goto label;\
182 }\
183}
184
185#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
186{\
187 p = av_mallocz(size);\
188 if (p == NULL && (size) != 0) {\
189 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
190 goto label;\
191 }\
192}
193
194//#include "libm.h"
195
196/**
197 * Returns NULL if CONFIG_SMALL is true, otherwise the argument
198 * without modification. Used to disable the definition of strings
199 * (for example AVCodec long_names).
200 */
201#if CONFIG_SMALL
202# define NULL_IF_CONFIG_SMALL(x) NULL
203#else
204# define NULL_IF_CONFIG_SMALL(x) x
205#endif
206
207#endif /* AVUTIL_INTERNAL_H */
diff --git a/apps/codecs/libwmapro/libavutil/intreadwrite.h b/apps/codecs/libwmapro/libavutil/intreadwrite.h
new file mode 100644
index 0000000000..d27a50061e
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/intreadwrite.h
@@ -0,0 +1,192 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVUTIL_INTREADWRITE_H
20#define AVUTIL_INTREADWRITE_H
21
22#include <stdint.h>
23//#include "ffmpeg_config.h"
24#include "bswap.h"
25
26#ifdef __GNUC__
27
28struct unaligned_64 { uint64_t l; } __attribute__((packed));
29struct unaligned_32 { uint32_t l; } __attribute__((packed));
30struct unaligned_16 { uint16_t l; } __attribute__((packed));
31
32#define AV_RN16(a) (((const struct unaligned_16 *) (a))->l)
33#define AV_RN32(a) (((const struct unaligned_32 *) (a))->l)
34#define AV_RN64(a) (((const struct unaligned_64 *) (a))->l)
35
36#define AV_WN16(a, b) (((struct unaligned_16 *) (a))->l) = (b)
37#define AV_WN32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
38#define AV_WN64(a, b) (((struct unaligned_64 *) (a))->l) = (b)
39
40#elif defined(__DECC)
41
42#define AV_RN16(a) (*((const __unaligned uint16_t*)(a)))
43#define AV_RN32(a) (*((const __unaligned uint32_t*)(a)))
44#define AV_RN64(a) (*((const __unaligned uint64_t*)(a)))
45
46#define AV_WN16(a, b) *((__unaligned uint16_t*)(a)) = (b)
47#define AV_WN32(a, b) *((__unaligned uint32_t*)(a)) = (b)
48#define AV_WN64(a, b) *((__unaligned uint64_t*)(a)) = (b)
49
50#else
51
52#define AV_RN16(a) (*((const uint16_t*)(a)))
53#define AV_RN32(a) (*((const uint32_t*)(a)))
54#define AV_RN64(a) (*((const uint64_t*)(a)))
55
56#define AV_WN16(a, b) *((uint16_t*)(a)) = (b)
57#define AV_WN32(a, b) *((uint32_t*)(a)) = (b)
58#define AV_WN64(a, b) *((uint64_t*)(a)) = (b)
59
60#endif /* !__GNUC__ */
61
62/* endian macros */
63#define AV_RB8(x) (((const uint8_t*)(x))[0])
64#define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0)
65
66#define AV_RL8(x) AV_RB8(x)
67#define AV_WL8(p, d) AV_WB8(p, d)
68
69#if HAVE_FAST_UNALIGNED
70# ifdef WORDS_BIGENDIAN
71# define AV_RB16(x) AV_RN16(x)
72# define AV_WB16(p, d) AV_WN16(p, d)
73
74# define AV_RL16(x) bswap_16(AV_RN16(x))
75# define AV_WL16(p, d) AV_WN16(p, bswap_16(d))
76
77# define AV_RB32(x) AV_RN32(x)
78# define AV_WB32(p, d) AV_WN32(p, d)
79
80# define AV_RL32(x) bswap_32(AV_RN32(x))
81# define AV_WL32(p, d) AV_WN32(p, bswap_32(d))
82
83# define AV_RB64(x) AV_RN64(x)
84# define AV_WB64(p, d) AV_WN64(p, d)
85
86# define AV_RL64(x) bswap_64(AV_RN64(x))
87# define AV_WL64(p, d) AV_WN64(p, bswap_64(d))
88# else /* WORDS_BIGENDIAN */
89# define AV_RB16(x) bswap_16(AV_RN16(x))
90# define AV_WB16(p, d) AV_WN16(p, bswap_16(d))
91
92# define AV_RL16(x) AV_RN16(x)
93# define AV_WL16(p, d) AV_WN16(p, d)
94
95# define AV_RB32(x) bswap_32(AV_RN32(x))
96# define AV_WB32(p, d) AV_WN32(p, bswap_32(d))
97
98# define AV_RL32(x) AV_RN32(x)
99# define AV_WL32(p, d) AV_WN32(p, d)
100
101# define AV_RB64(x) bswap_64(AV_RN64(x))
102# define AV_WB64(p, d) AV_WN64(p, bswap_64(d))
103
104# define AV_RL64(x) AV_RN64(x)
105# define AV_WL64(p, d) AV_WN64(p, d)
106# endif
107#else /* HAVE_FAST_UNALIGNED */
108#define AV_RB16(x) ((((const uint8_t*)(x))[0] << 8) | ((const uint8_t*)(x))[1])
109#define AV_WB16(p, d) do { \
110 ((uint8_t*)(p))[1] = (d); \
111 ((uint8_t*)(p))[0] = (d)>>8; } while(0)
112
113#define AV_RL16(x) ((((const uint8_t*)(x))[1] << 8) | \
114 ((const uint8_t*)(x))[0])
115#define AV_WL16(p, d) do { \
116 ((uint8_t*)(p))[0] = (d); \
117 ((uint8_t*)(p))[1] = (d)>>8; } while(0)
118
119#define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \
120 (((const uint8_t*)(x))[1] << 16) | \
121 (((const uint8_t*)(x))[2] << 8) | \
122 ((const uint8_t*)(x))[3])
123#define AV_WB32(p, d) do { \
124 ((uint8_t*)(p))[3] = (d); \
125 ((uint8_t*)(p))[2] = (d)>>8; \
126 ((uint8_t*)(p))[1] = (d)>>16; \
127 ((uint8_t*)(p))[0] = (d)>>24; } while(0)
128
129#define AV_RL32(x) ((((const uint8_t*)(x))[3] << 24) | \
130 (((const uint8_t*)(x))[2] << 16) | \
131 (((const uint8_t*)(x))[1] << 8) | \
132 ((const uint8_t*)(x))[0])
133#define AV_WL32(p, d) do { \
134 ((uint8_t*)(p))[0] = (d); \
135 ((uint8_t*)(p))[1] = (d)>>8; \
136 ((uint8_t*)(p))[2] = (d)>>16; \
137 ((uint8_t*)(p))[3] = (d)>>24; } while(0)
138
139#define AV_RB64(x) (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
140 ((uint64_t)((const uint8_t*)(x))[1] << 48) | \
141 ((uint64_t)((const uint8_t*)(x))[2] << 40) | \
142 ((uint64_t)((const uint8_t*)(x))[3] << 32) | \
143 ((uint64_t)((const uint8_t*)(x))[4] << 24) | \
144 ((uint64_t)((const uint8_t*)(x))[5] << 16) | \
145 ((uint64_t)((const uint8_t*)(x))[6] << 8) | \
146 (uint64_t)((const uint8_t*)(x))[7])
147#define AV_WB64(p, d) do { \
148 ((uint8_t*)(p))[7] = (d); \
149 ((uint8_t*)(p))[6] = (d)>>8; \
150 ((uint8_t*)(p))[5] = (d)>>16; \
151 ((uint8_t*)(p))[4] = (d)>>24; \
152 ((uint8_t*)(p))[3] = (d)>>32; \
153 ((uint8_t*)(p))[2] = (d)>>40; \
154 ((uint8_t*)(p))[1] = (d)>>48; \
155 ((uint8_t*)(p))[0] = (d)>>56; } while(0)
156
157#define AV_RL64(x) (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
158 ((uint64_t)((const uint8_t*)(x))[6] << 48) | \
159 ((uint64_t)((const uint8_t*)(x))[5] << 40) | \
160 ((uint64_t)((const uint8_t*)(x))[4] << 32) | \
161 ((uint64_t)((const uint8_t*)(x))[3] << 24) | \
162 ((uint64_t)((const uint8_t*)(x))[2] << 16) | \
163 ((uint64_t)((const uint8_t*)(x))[1] << 8) | \
164 (uint64_t)((const uint8_t*)(x))[0])
165#define AV_WL64(p, d) do { \
166 ((uint8_t*)(p))[0] = (d); \
167 ((uint8_t*)(p))[1] = (d)>>8; \
168 ((uint8_t*)(p))[2] = (d)>>16; \
169 ((uint8_t*)(p))[3] = (d)>>24; \
170 ((uint8_t*)(p))[4] = (d)>>32; \
171 ((uint8_t*)(p))[5] = (d)>>40; \
172 ((uint8_t*)(p))[6] = (d)>>48; \
173 ((uint8_t*)(p))[7] = (d)>>56; } while(0)
174#endif /* HAVE_FAST_UNALIGNED */
175
176#define AV_RB24(x) ((((const uint8_t*)(x))[0] << 16) | \
177 (((const uint8_t*)(x))[1] << 8) | \
178 ((const uint8_t*)(x))[2])
179#define AV_WB24(p, d) do { \
180 ((uint8_t*)(p))[2] = (d); \
181 ((uint8_t*)(p))[1] = (d)>>8; \
182 ((uint8_t*)(p))[0] = (d)>>16; } while(0)
183
184#define AV_RL24(x) ((((const uint8_t*)(x))[2] << 16) | \
185 (((const uint8_t*)(x))[1] << 8) | \
186 ((const uint8_t*)(x))[0])
187#define AV_WL24(p, d) do { \
188 ((uint8_t*)(p))[0] = (d); \
189 ((uint8_t*)(p))[1] = (d)>>8; \
190 ((uint8_t*)(p))[2] = (d)>>16; } while(0)
191
192#endif /* AVUTIL_INTREADWRITE_H */
diff --git a/apps/codecs/libwmapro/libavutil/log.c b/apps/codecs/libwmapro/libavutil/log.c
new file mode 100644
index 0000000000..4bb9652c2c
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/log.c
@@ -0,0 +1,89 @@
1/*
2 * log functions
3 * Copyright (c) 2003 Michel Bardiaux
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
23 * @file libavutil/log.c
24 * logging functions
25 */
26
27#include "avutil.h"
28#include "log.h"
29
30int av_log_level = AV_LOG_INFO;
31
32void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
33{
34 static int print_prefix=1;
35 static int count;
36 static char line[1024], prev[1024];
37 AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
38 if(level>av_log_level)
39 return;
40#undef fprintf
41 if(print_prefix && avc) {
42 snprintf(line, sizeof(line), "[%s @ %p]", avc->item_name(ptr), ptr);
43 }else
44 line[0]=0;
45
46 vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);
47
48 print_prefix= line[strlen(line)-1] == '\n';
49 if(print_prefix && !strcmp(line, prev)){
50 count++;
51 return;
52 }
53 if(count>0){
54 fprintf(stderr, " Last message repeated %d times\n", count);
55 count=0;
56 }
57 fputs(line, stderr);
58 strcpy(prev, line);
59}
60
61static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
62
63void av_log(void* avcl, int level, const char *fmt, ...)
64{
65 va_list vl;
66 va_start(vl, fmt);
67 av_vlog(avcl, level, fmt, vl);
68 va_end(vl);
69}
70
71void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
72{
73 av_log_callback(avcl, level, fmt, vl);
74}
75
76int av_log_get_level(void)
77{
78 return av_log_level;
79}
80
81void av_log_set_level(int level)
82{
83 av_log_level = level;
84}
85
86void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
87{
88 av_log_callback = callback;
89}
diff --git a/apps/codecs/libwmapro/libavutil/log.h b/apps/codecs/libwmapro/libavutil/log.h
new file mode 100644
index 0000000000..1206a2fc38
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/log.h
@@ -0,0 +1,116 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef AVUTIL_LOG_H
22#define AVUTIL_LOG_H
23
24#include <stdarg.h>
25#include "avutil.h"
26
27/**
28 * Describes the class of an AVClass context structure. That is an
29 * arbitrary struct of which the first field is a pointer to an
30 * AVClass struct (e.g. AVCodecContext, AVFormatContext etc.).
31 */
32typedef struct AVCLASS AVClass;
33struct AVCLASS {
34 /**
35 * The name of the class; usually it is the same name as the
36 * context structure type to which the AVClass is associated.
37 */
38 const char* class_name;
39
40 /**
41 * A pointer to a function which returns the name of a context
42 * instance \p ctx associated with the class.
43 */
44 const char* (*item_name)(void* ctx);
45
46 /**
47 * a pointer to the first option specified in the class if any or NULL
48 *
49 * @see av_set_default_options()
50 */
51 const struct AVOption *option;
52};
53
54/* av_log API */
55
56#define AV_LOG_QUIET -8
57
58/**
59 * Something went really wrong and we will crash now.
60 */
61#define AV_LOG_PANIC 0
62
63/**
64 * Something went wrong and recovery is not possible.
65 * For example, no header was found for a format which depends
66 * on headers or an illegal combination of parameters is used.
67 */
68#define AV_LOG_FATAL 8
69
70/**
71 * Something went wrong and cannot losslessly be recovered.
72 * However, not all future data is affected.
73 */
74#define AV_LOG_ERROR 16
75
76/**
77 * Something somehow does not look correct. This may or may not
78 * lead to problems. An example would be the use of '-vstrict -2'.
79 */
80#define AV_LOG_WARNING 24
81
82#define AV_LOG_INFO 32
83#define AV_LOG_VERBOSE 40
84
85/**
86 * Stuff which is only useful for libav* developers.
87 */
88#define AV_LOG_DEBUG 48
89
90/**
91 * Sends the specified message to the log if the level is less than or equal
92 * to the current av_log_level. By default, all logging messages are sent to
93 * stderr. This behavior can be altered by setting a different av_vlog callback
94 * function.
95 *
96 * @param avcl A pointer to an arbitrary struct of which the first field is a
97 * pointer to an AVClass struct.
98 * @param level The importance level of the message, lower values signifying
99 * higher importance.
100 * @param fmt The format string (printf-compatible) that specifies how
101 * subsequent arguments are converted to output.
102 * @see av_vlog
103 */
104#ifdef __GNUC__
105void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
106#else
107void av_log(void*, int level, const char *fmt, ...);
108#endif
109
110void av_vlog(void*, int level, const char *fmt, va_list);
111int av_log_get_level(void);
112void av_log_set_level(int);
113void av_log_set_callback(void (*)(void*, int, const char*, va_list));
114void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl);
115
116#endif /* AVUTIL_LOG_H */
diff --git a/apps/codecs/libwmapro/libavutil/mathematics.c b/apps/codecs/libwmapro/libavutil/mathematics.c
new file mode 100644
index 0000000000..6c04db78af
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/mathematics.c
@@ -0,0 +1,177 @@
1/*
2 * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file libavutil/mathematics.c
23 * miscellaneous math routines and tables
24 */
25
26#include <assert.h>
27#include <stdint.h>
28#include <limits.h>
29#include "mathematics.h"
30
31const uint8_t ff_sqrt_tab[256]={
32 0, 16, 23, 28, 32, 36, 40, 43, 46, 48, 51, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 77, 79, 80, 82, 84, 85, 87, 88, 90,
33 91, 92, 94, 95, 96, 98, 99,100,102,103,104,105,107,108,109,110,111,112,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
34128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,144,145,146,147,148,149,150,151,151,152,153,154,155,156,156,
35157,158,159,160,160,161,162,163,164,164,165,166,167,168,168,169,170,171,171,172,173,174,174,175,176,176,177,178,179,179,180,181,
36182,182,183,184,184,185,186,186,187,188,188,189,190,190,191,192,192,193,194,194,195,196,196,197,198,198,199,200,200,201,202,202,
37203,204,204,205,205,206,207,207,208,208,209,210,210,211,212,212,213,213,214,215,215,216,216,217,218,218,219,219,220,220,221,222,
38222,223,223,224,224,225,226,226,227,227,228,228,229,230,230,231,231,232,232,233,233,234,235,235,236,236,237,237,238,238,239,239,
39240,240,241,242,242,243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251,251,252,252,253,253,254,254,255,255,255
40};
41
42const uint8_t ff_log2_tab[256]={
43 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
44 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
45 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
46 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
47 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
48 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
49 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
50 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
51};
52
53const uint8_t av_reverse[256]={
540x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0,
550x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8,
560x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4,
570x0C,0x8C,0x4C,0xCC,0x2C,0xAC,0x6C,0xEC,0x1C,0x9C,0x5C,0xDC,0x3C,0xBC,0x7C,0xFC,
580x02,0x82,0x42,0xC2,0x22,0xA2,0x62,0xE2,0x12,0x92,0x52,0xD2,0x32,0xB2,0x72,0xF2,
590x0A,0x8A,0x4A,0xCA,0x2A,0xAA,0x6A,0xEA,0x1A,0x9A,0x5A,0xDA,0x3A,0xBA,0x7A,0xFA,
600x06,0x86,0x46,0xC6,0x26,0xA6,0x66,0xE6,0x16,0x96,0x56,0xD6,0x36,0xB6,0x76,0xF6,
610x0E,0x8E,0x4E,0xCE,0x2E,0xAE,0x6E,0xEE,0x1E,0x9E,0x5E,0xDE,0x3E,0xBE,0x7E,0xFE,
620x01,0x81,0x41,0xC1,0x21,0xA1,0x61,0xE1,0x11,0x91,0x51,0xD1,0x31,0xB1,0x71,0xF1,
630x09,0x89,0x49,0xC9,0x29,0xA9,0x69,0xE9,0x19,0x99,0x59,0xD9,0x39,0xB9,0x79,0xF9,
640x05,0x85,0x45,0xC5,0x25,0xA5,0x65,0xE5,0x15,0x95,0x55,0xD5,0x35,0xB5,0x75,0xF5,
650x0D,0x8D,0x4D,0xCD,0x2D,0xAD,0x6D,0xED,0x1D,0x9D,0x5D,0xDD,0x3D,0xBD,0x7D,0xFD,
660x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3,
670x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB,
680x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7,
690x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF,
70};
71
72int64_t av_gcd(int64_t a, int64_t b){
73 if(b) return av_gcd(b, a%b);
74 else return a;
75}
76
77int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){
78 int64_t r=0;
79 assert(c > 0);
80 assert(b >=0);
81 assert(rnd >=0 && rnd<=5 && rnd!=4);
82
83 if(a<0 && a != INT64_MIN) return -av_rescale_rnd(-a, b, c, rnd ^ ((rnd>>1)&1));
84
85 if(rnd==AV_ROUND_NEAR_INF) r= c/2;
86 else if(rnd&1) r= c-1;
87
88 if(b<=INT_MAX && c<=INT_MAX){
89 if(a<=INT_MAX)
90 return (a * b + r)/c;
91 else
92 return a/c*b + (a%c*b + r)/c;
93 }else{
94#if 1
95 uint64_t a0= a&0xFFFFFFFF;
96 uint64_t a1= a>>32;
97 uint64_t b0= b&0xFFFFFFFF;
98 uint64_t b1= b>>32;
99 uint64_t t1= a0*b1 + a1*b0;
100 uint64_t t1a= t1<<32;
101 int i;
102
103 a0 = a0*b0 + t1a;
104 a1 = a1*b1 + (t1>>32) + (a0<t1a);
105 a0 += r;
106 a1 += a0<r;
107
108 for(i=63; i>=0; i--){
109// int o= a1 & 0x8000000000000000ULL;
110 a1+= a1 + ((a0>>i)&1);
111 t1+=t1;
112 if(/*o || */c <= a1){
113 a1 -= c;
114 t1++;
115 }
116 }
117 return t1;
118 }
119#else
120 AVInteger ai;
121 ai= av_mul_i(av_int2i(a), av_int2i(b));
122 ai= av_add_i(ai, av_int2i(r));
123
124 return av_i2int(av_div_i(ai, av_int2i(c)));
125 }
126#endif
127}
128
129int64_t av_rescale(int64_t a, int64_t b, int64_t c){
130 return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
131}
132
133#if 0
134int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
135 int64_t b= bq.num * (int64_t)cq.den;
136 int64_t c= cq.num * (int64_t)bq.den;
137 return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
138}
139
140int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){
141 int64_t a= tb_a.num * (int64_t)tb_b.den;
142 int64_t b= tb_b.num * (int64_t)tb_a.den;
143 if (av_rescale_rnd(ts_a, a, b, AV_ROUND_DOWN) < ts_b) return -1;
144 if (av_rescale_rnd(ts_b, b, a, AV_ROUND_DOWN) < ts_a) return 1;
145 return 0;
146}
147
148#ifdef TEST
149#include "integer.h"
150#undef printf
151int main(void){
152 int64_t a,b,c,d,e;
153
154 for(a=7; a<(1LL<<62); a+=a/3+1){
155 for(b=3; b<(1LL<<62); b+=b/4+1){
156 for(c=9; c<(1LL<<62); c+=(c*2)/5+3){
157 int64_t r= c/2;
158 AVInteger ai;
159 ai= av_mul_i(av_int2i(a), av_int2i(b));
160 ai= av_add_i(ai, av_int2i(r));
161
162 d= av_i2int(av_div_i(ai, av_int2i(c)));
163
164 e= av_rescale(a,b,c);
165
166 if((double)a * (double)b / (double)c > (1LL<<63))
167 continue;
168
169 if(d!=e) printf("%"PRId64"*%"PRId64"/%"PRId64"= %"PRId64"=%"PRId64"\n", a, b, c, d, e);
170 }
171 }
172 }
173 return 0;
174}
175#endif
176
177#endif /* 0 */
diff --git a/apps/codecs/libwmapro/libavutil/mathematics.h b/apps/codecs/libwmapro/libavutil/mathematics.h
new file mode 100644
index 0000000000..a09d3e9ad8
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/mathematics.h
@@ -0,0 +1,98 @@
1/*
2 * copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef AVUTIL_MATHEMATICS_H
22#define AVUTIL_MATHEMATICS_H
23
24#include <stdint.h>
25#include <math.h>
26#include "attributes.h"
27//#include "rational.h"
28
29#ifndef M_E
30#define M_E 2.7182818284590452354 /* e */
31#endif
32#ifndef M_LN2
33#define M_LN2 0.69314718055994530942 /* log_e 2 */
34#endif
35#ifndef M_LN10
36#define M_LN10 2.30258509299404568402 /* log_e 10 */
37#endif
38#ifndef M_LOG2_10
39#define M_LOG2_10 3.32192809488736234787 /* log_2 10 */
40#endif
41#ifndef M_PI
42#define M_PI 3.14159265358979323846 /* pi */
43#endif
44#ifndef M_SQRT1_2
45#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
46#endif
47#ifndef M_SQRT2
48#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
49#endif
50#ifndef NAN
51#define NAN (0.0/0.0)
52#endif
53#ifndef INFINITY
54#define INFINITY (1.0/0.0)
55#endif
56
57enum AVRounding {
58 AV_ROUND_ZERO = 0, ///< Round toward zero.
59 AV_ROUND_INF = 1, ///< Round away from zero.
60 AV_ROUND_DOWN = 2, ///< Round toward -infinity.
61 AV_ROUND_UP = 3, ///< Round toward +infinity.
62 AV_ROUND_NEAR_INF = 5, ///< Round to nearest and halfway cases away from zero.
63};
64
65/**
66 * Returns the greatest common divisor of a and b.
67 * If both a and b are 0 or either or both are <0 then behavior is
68 * undefined.
69 */
70int64_t av_const av_gcd(int64_t a, int64_t b);
71
72/**
73 * Rescales a 64-bit integer with rounding to nearest.
74 * A simple a*b/c isn't possible as it can overflow.
75 */
76int64_t av_rescale(int64_t a, int64_t b, int64_t c) av_const;
77
78/**
79 * Rescales a 64-bit integer with specified rounding.
80 * A simple a*b/c isn't possible as it can overflow.
81 */
82int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_const;
83
84/**
85 * Rescales a 64-bit integer by 2 rational numbers.
86 */
87//int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const;
88
89/**
90 * Compares 2 timestamps each in its own timebases.
91 * The result of the function is undefined if one of the timestamps
92 * is outside the int64_t range when represented in the others timebase.
93 * @return -1 if ts_a is before ts_b, 1 if ts_a is after ts_b or 0 if they represent the same position
94 */
95//int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b);
96
97
98#endif /* AVUTIL_MATHEMATICS_H */
diff --git a/apps/codecs/libwmapro/libavutil/mem.c b/apps/codecs/libwmapro/libavutil/mem.c
new file mode 100644
index 0000000000..9721222e50
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/mem.c
@@ -0,0 +1,159 @@
1/*
2 * default memory allocator for libavutil
3 * Copyright (c) 2002 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
23 * @file libavutil/mem.c
24 * default memory allocator for libavutil
25 */
26
27//#include "ffmpeg_config.h"
28
29#include <limits.h>
30#include <stdlib.h>
31#include <string.h>
32#if HAVE_MALLOC_H
33#include <malloc.h>
34#endif
35
36#include "mem.h"
37
38/* here we can use OS-dependent allocation functions */
39#undef free
40#undef malloc
41#undef realloc
42
43/* You can redefine av_malloc and av_free in your project to use your
44 memory allocator. You do not need to suppress this file because the
45 linker will do it automatically. */
46
47void *av_malloc(unsigned int size)
48{
49 void *ptr = NULL;
50#if CONFIG_MEMALIGN_HACK
51 long diff;
52#endif
53
54 /* let's disallow possible ambiguous cases */
55 if(size > (INT_MAX-16) )
56 return NULL;
57
58#if CONFIG_MEMALIGN_HACK
59 ptr = malloc(size+16);
60 if(!ptr)
61 return ptr;
62 diff= ((-(long)ptr - 1)&15) + 1;
63 ptr = (char*)ptr + diff;
64 ((char*)ptr)[-1]= diff;
65#elif HAVE_POSIX_MEMALIGN
66 if (posix_memalign(&ptr,16,size))
67 ptr = NULL;
68#elif HAVE_MEMALIGN
69 ptr = memalign(16,size);
70 /* Why 64?
71 Indeed, we should align it:
72 on 4 for 386
73 on 16 for 486
74 on 32 for 586, PPro - K6-III
75 on 64 for K7 (maybe for P3 too).
76 Because L1 and L2 caches are aligned on those values.
77 But I don't want to code such logic here!
78 */
79 /* Why 16?
80 Because some CPUs need alignment, for example SSE2 on P4, & most RISC CPUs
81 it will just trigger an exception and the unaligned load will be done in the
82 exception handler or it will just segfault (SSE2 on P4).
83 Why not larger? Because I did not see a difference in benchmarks ...
84 */
85 /* benchmarks with P3
86 memalign(64)+1 3071,3051,3032
87 memalign(64)+2 3051,3032,3041
88 memalign(64)+4 2911,2896,2915
89 memalign(64)+8 2545,2554,2550
90 memalign(64)+16 2543,2572,2563
91 memalign(64)+32 2546,2545,2571
92 memalign(64)+64 2570,2533,2558
93
94 BTW, malloc seems to do 8-byte alignment by default here.
95 */
96#else
97 ptr = malloc(size);
98#endif
99 return ptr;
100}
101
102void *av_realloc(void *ptr, unsigned int size)
103{
104#if CONFIG_MEMALIGN_HACK
105 int diff;
106#endif
107
108 /* let's disallow possible ambiguous cases */
109 if(size > (INT_MAX-16) )
110 return NULL;
111
112#if CONFIG_MEMALIGN_HACK
113 //FIXME this isn't aligned correctly, though it probably isn't needed
114 if(!ptr) return av_malloc(size);
115 diff= ((char*)ptr)[-1];
116 return (char*)realloc((char*)ptr - diff, size + diff) + diff;
117#else
118 return realloc(ptr, size);
119#endif
120}
121
122void av_free(void *ptr)
123{
124 /* XXX: this test should not be needed on most libcs */
125 if (ptr)
126#if CONFIG_MEMALIGN_HACK
127 free((char*)ptr - ((char*)ptr)[-1]);
128#else
129 free(ptr);
130#endif
131}
132
133void av_freep(void *arg)
134{
135 void **ptr= (void**)arg;
136 av_free(*ptr);
137 *ptr = NULL;
138}
139
140void *av_mallocz(unsigned int size)
141{
142 void *ptr = av_malloc(size);
143 if (ptr)
144 memset(ptr, 0, size);
145 return ptr;
146}
147
148char *av_strdup(const char *s)
149{
150 char *ptr= NULL;
151 if(s){
152 int len = strlen(s) + 1;
153 ptr = av_malloc(len);
154 if (ptr)
155 memcpy(ptr, s, len);
156 }
157 return ptr;
158}
159
diff --git a/apps/codecs/libwmapro/libavutil/mem.h b/apps/codecs/libwmapro/libavutil/mem.h
new file mode 100644
index 0000000000..e50553aefe
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/mem.h
@@ -0,0 +1,104 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file libavutil/mem.h
23 * memory handling functions
24 */
25
26#ifndef AVUTIL_MEM_H
27#define AVUTIL_MEM_H
28
29#include "common.h"
30
31#if AV_GCC_VERSION_AT_LEAST(3,1)
32 #define av_malloc_attrib __attribute__((__malloc__))
33#else
34 #define av_malloc_attrib
35#endif
36
37#if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,3)
38 #define av_alloc_size(n) __attribute__((alloc_size(n)))
39#else
40 #define av_alloc_size(n)
41#endif
42
43/**
44 * Allocates a block of \p size bytes with alignment suitable for all
45 * memory accesses (including vectors if available on the CPU).
46 * @param size Size in bytes for the memory block to be allocated.
47 * @return Pointer to the allocated block, NULL if the block cannot
48 * be allocated.
49 * @see av_mallocz()
50 */
51void *av_malloc(unsigned int size) av_malloc_attrib av_alloc_size(1);
52
53/**
54 * Allocates or reallocates a block of memory.
55 * If \p ptr is NULL and \p size > 0, allocates a new block. If \p
56 * size is zero, frees the memory block pointed to by \p ptr.
57 * @param size Size in bytes for the memory block to be allocated or
58 * reallocated.
59 * @param ptr Pointer to a memory block already allocated with
60 * av_malloc(z)() or av_realloc() or NULL.
61 * @return Pointer to a newly reallocated block or NULL if the block
62 * cannot be reallocated or the function is used to free the memory block.
63 * @see av_fast_realloc()
64 */
65void *av_realloc(void *ptr, unsigned int size) av_alloc_size(2);
66
67/**
68 * Frees a memory block which has been allocated with av_malloc(z)() or
69 * av_realloc().
70 * @param ptr Pointer to the memory block which should be freed.
71 * @note ptr = NULL is explicitly allowed.
72 * @note It is recommended that you use av_freep() instead.
73 * @see av_freep()
74 */
75void av_free(void *ptr);
76
77/**
78 * Allocates a block of \p size bytes with alignment suitable for all
79 * memory accesses (including vectors if available on the CPU) and
80 * zeroes all the bytes of the block.
81 * @param size Size in bytes for the memory block to be allocated.
82 * @return Pointer to the allocated block, NULL if it cannot be allocated.
83 * @see av_malloc()
84 */
85void *av_mallocz(unsigned int size) av_malloc_attrib av_alloc_size(1);
86
87/**
88 * Duplicates the string \p s.
89 * @param s string to be duplicated
90 * @return Pointer to a newly allocated string containing a
91 * copy of \p s or NULL if the string cannot be allocated.
92 */
93char *av_strdup(const char *s) av_malloc_attrib;
94
95/**
96 * Frees a memory block which has been allocated with av_malloc(z)() or
97 * av_realloc() and set the pointer pointing to it to NULL.
98 * @param ptr Pointer to the pointer to the memory block which should
99 * be freed.
100 * @see av_free()
101 */
102void av_freep(void *ptr);
103
104#endif /* AVUTIL_MEM_H */
diff --git a/apps/codecs/libwmapro/mathops.h b/apps/codecs/libwmapro/mathops.h
new file mode 100644
index 0000000000..149910bb1d
--- /dev/null
+++ b/apps/codecs/libwmapro/mathops.h
@@ -0,0 +1,150 @@
1/*
2 * simple math operations
3 * Copyright (c) 2001, 2002 Fabrice Bellard
4 * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22#ifndef AVCODEC_MATHOPS_H
23#define AVCODEC_MATHOPS_H
24
25#include "libavutil/common.h"
26
27#if ARCH_ARM
28# include "arm/mathops.h"
29#elif ARCH_AVR32
30# include "avr32/mathops.h"
31#elif ARCH_BFIN
32# include "bfin/mathops.h"
33#elif ARCH_MIPS
34# include "mips/mathops.h"
35#elif ARCH_PPC
36# include "ppc/mathops.h"
37#elif ARCH_X86
38# include "x86/mathops.h"
39#endif
40
41/* generic implementation */
42
43#ifndef MULL
44# define MULL(a,b,s) (((int64_t)(a) * (int64_t)(b)) >> (s))
45#endif
46
47#ifndef MULH
48//gcc 3.4 creates an incredibly bloated mess out of this
49//# define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32)
50
51static av_always_inline int MULH(int a, int b){
52 return ((int64_t)(a) * (int64_t)(b))>>32;
53}
54#endif
55
56#ifndef UMULH
57static av_always_inline unsigned UMULH(unsigned a, unsigned b){
58 return ((uint64_t)(a) * (uint64_t)(b))>>32;
59}
60#endif
61
62#ifndef MUL64
63# define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
64#endif
65
66#ifndef MAC64
67# define MAC64(d, a, b) ((d) += MUL64(a, b))
68#endif
69
70#ifndef MLS64
71# define MLS64(d, a, b) ((d) -= MUL64(a, b))
72#endif
73
74/* signed 16x16 -> 32 multiply add accumulate */
75#ifndef MAC16
76# define MAC16(rt, ra, rb) rt += (ra) * (rb)
77#endif
78
79/* signed 16x16 -> 32 multiply */
80#ifndef MUL16
81# define MUL16(ra, rb) ((ra) * (rb))
82#endif
83
84#ifndef MLS16
85# define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb))
86#endif
87
88/* median of 3 */
89#ifndef mid_pred
90#define mid_pred mid_pred
91static inline av_const int mid_pred(int a, int b, int c)
92{
93#if 0
94 int t= (a-b)&((a-b)>>31);
95 a-=t;
96 b+=t;
97 b-= (b-c)&((b-c)>>31);
98 b+= (a-b)&((a-b)>>31);
99
100 return b;
101#else
102 if(a>b){
103 if(c>b){
104 if(c>a) b=a;
105 else b=c;
106 }
107 }else{
108 if(b>c){
109 if(c>a) b=c;
110 else b=a;
111 }
112 }
113 return b;
114#endif
115}
116#endif
117
118#ifndef sign_extend
119static inline av_const int sign_extend(int val, unsigned bits)
120{
121 return (val << (INT_BIT - bits)) >> (INT_BIT - bits);
122}
123#endif
124
125#ifndef zero_extend
126static inline av_const unsigned zero_extend(unsigned val, unsigned bits)
127{
128 return (val << (INT_BIT - bits)) >> (INT_BIT - bits);
129}
130#endif
131
132#ifndef COPY3_IF_LT
133#define COPY3_IF_LT(x, y, a, b, c, d)\
134if ((y) < (x)) {\
135 (x) = (y);\
136 (a) = (b);\
137 (c) = (d);\
138}
139#endif
140
141#ifndef NEG_SSR32
142# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
143#endif
144
145#ifndef NEG_USR32
146# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
147#endif
148
149#endif /* AVCODEC_MATHOPS_H */
150
diff --git a/apps/codecs/libwmapro/mdct.c b/apps/codecs/libwmapro/mdct.c
new file mode 100644
index 0000000000..9d0a59dc84
--- /dev/null
+++ b/apps/codecs/libwmapro/mdct.c
@@ -0,0 +1,232 @@
1/*
2 * MDCT/IMDCT transforms
3 * Copyright (c) 2002 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <stdlib.h>
23#include <string.h>
24#include "libavutil/common.h"
25#include "libavutil/mathematics.h"
26#include "fft.h"
27
28/**
29 * @file libavcodec/mdct.c
30 * MDCT/IMDCT transforms.
31 */
32
33// Generate a Kaiser-Bessel Derived Window.
34#define BESSEL_I0_ITER 50 // default: 50 iterations of Bessel I0 approximation
35av_cold void ff_kbd_window_init(float *window, float alpha, int n)
36{
37 int i, j;
38 double sum = 0.0, bessel, tmp;
39 double local_window[n];
40 double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n);
41
42 for (i = 0; i < n; i++) {
43 tmp = i * (n - i) * alpha2;
44 bessel = 1.0;
45 for (j = BESSEL_I0_ITER; j > 0; j--)
46 bessel = bessel * tmp / (j * j) + 1;
47 sum += bessel;
48 local_window[i] = sum;
49 }
50
51 sum++;
52 for (i = 0; i < n; i++)
53 window[i] = sqrt(local_window[i] / sum);
54}
55
56#include "mdct_tablegen.h"
57
58/**
59 * init MDCT or IMDCT computation.
60 */
61av_cold int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale)
62{
63 int n, n4, i;
64 double alpha, theta;
65 int tstep;
66
67 memset(s, 0, sizeof(*s));
68 n = 1 << nbits;
69 s->mdct_bits = nbits;
70 s->mdct_size = n;
71 n4 = n >> 2;
72 s->permutation = FF_MDCT_PERM_NONE;
73
74 if (ff_fft_init(s, s->mdct_bits - 2, inverse) < 0)
75 goto fail;
76
77 s->tcos = av_malloc(n/2 * sizeof(FFTSample));
78 if (!s->tcos)
79 goto fail;
80
81 switch (s->permutation) {
82 case FF_MDCT_PERM_NONE:
83 s->tsin = s->tcos + n4;
84 tstep = 1;
85 break;
86 case FF_MDCT_PERM_INTERLEAVE:
87 s->tsin = s->tcos + 1;
88 tstep = 2;
89 break;
90 default:
91 goto fail;
92 }
93
94 theta = 1.0 / 8.0 + (scale < 0 ? n4 : 0);
95 scale = sqrt(fabs(scale));
96 for(i=0;i<n4;i++) {
97 alpha = 2 * M_PI * (i + theta) / n;
98 s->tcos[i*tstep] = -cos(alpha) * scale;
99 s->tsin[i*tstep] = -sin(alpha) * scale;
100 }
101 return 0;
102 fail:
103 ff_mdct_end(s);
104 return -1;
105}
106
107/* complex multiplication: p = a * b */
108#define CMUL(pre, pim, are, aim, bre, bim) \
109{\
110 FFTSample _are = (are);\
111 FFTSample _aim = (aim);\
112 FFTSample _bre = (bre);\
113 FFTSample _bim = (bim);\
114 (pre) = _are * _bre - _aim * _bim;\
115 (pim) = _are * _bim + _aim * _bre;\
116}
117
118/**
119 * Compute the middle half of the inverse MDCT of size N = 2^nbits,
120 * thus excluding the parts that can be derived by symmetry
121 * @param output N/2 samples
122 * @param input N/2 samples
123 */
124void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input)
125{
126 int k, n8, n4, n2, n, j;
127 const uint16_t *revtab = s->revtab;
128 const FFTSample *tcos = s->tcos;
129 const FFTSample *tsin = s->tsin;
130 const FFTSample *in1, *in2;
131 FFTComplex *z = (FFTComplex *)output;
132
133 n = 1 << s->mdct_bits;
134 n2 = n >> 1;
135 n4 = n >> 2;
136 n8 = n >> 3;
137
138 /* pre rotation */
139 in1 = input;
140 in2 = input + n2 - 1;
141 for(k = 0; k < n4; k++) {
142 j=revtab[k];
143 CMUL(z[j].re, z[j].im, *in2, *in1, tcos[k], tsin[k]);
144 in1 += 2;
145 in2 -= 2;
146 }
147 ff_fft_calc(s, z);
148
149 /* post rotation + reordering */
150 for(k = 0; k < n8; k++) {
151 FFTSample r0, i0, r1, i1;
152 CMUL(r0, i1, z[n8-k-1].im, z[n8-k-1].re, tsin[n8-k-1], tcos[n8-k-1]);
153 CMUL(r1, i0, z[n8+k ].im, z[n8+k ].re, tsin[n8+k ], tcos[n8+k ]);
154 z[n8-k-1].re = r0;
155 z[n8-k-1].im = i0;
156 z[n8+k ].re = r1;
157 z[n8+k ].im = i1;
158 }
159}
160
161/**
162 * Compute inverse MDCT of size N = 2^nbits
163 * @param output N samples
164 * @param input N/2 samples
165 */
166void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input)
167{
168 int k;
169 int n = 1 << s->mdct_bits;
170 int n2 = n >> 1;
171 int n4 = n >> 2;
172
173 ff_imdct_half_c(s, output+n4, input);
174
175 for(k = 0; k < n4; k++) {
176 output[k] = -output[n2-k-1];
177 output[n-k-1] = output[n2+k];
178 }
179}
180
181/**
182 * Compute MDCT of size N = 2^nbits
183 * @param input N samples
184 * @param out N/2 samples
185 */
186void ff_mdct_calc_c(FFTContext *s, FFTSample *out, const FFTSample *input)
187{
188 int i, j, n, n8, n4, n2, n3;
189 FFTSample re, im;
190 const uint16_t *revtab = s->revtab;
191 const FFTSample *tcos = s->tcos;
192 const FFTSample *tsin = s->tsin;
193 FFTComplex *x = (FFTComplex *)out;
194
195 n = 1 << s->mdct_bits;
196 n2 = n >> 1;
197 n4 = n >> 2;
198 n8 = n >> 3;
199 n3 = 3 * n4;
200
201 /* pre rotation */
202 for(i=0;i<n8;i++) {
203 re = -input[2*i+3*n4] - input[n3-1-2*i];
204 im = -input[n4+2*i] + input[n4-1-2*i];
205 j = revtab[i];
206 CMUL(x[j].re, x[j].im, re, im, -tcos[i], tsin[i]);
207
208 re = input[2*i] - input[n2-1-2*i];
209 im = -(input[n2+2*i] + input[n-1-2*i]);
210 j = revtab[n8 + i];
211 CMUL(x[j].re, x[j].im, re, im, -tcos[n8 + i], tsin[n8 + i]);
212 }
213
214 ff_fft_calc(s, x);
215
216 /* post rotation */
217 for(i=0;i<n8;i++) {
218 FFTSample r0, i0, r1, i1;
219 CMUL(i1, r0, x[n8-i-1].re, x[n8-i-1].im, -tsin[n8-i-1], -tcos[n8-i-1]);
220 CMUL(i0, r1, x[n8+i ].re, x[n8+i ].im, -tsin[n8+i ], -tcos[n8+i ]);
221 x[n8-i-1].re = r0;
222 x[n8-i-1].im = i0;
223 x[n8+i ].re = r1;
224 x[n8+i ].im = i1;
225 }
226}
227
228av_cold void ff_mdct_end(FFTContext *s)
229{
230 av_freep(&s->tcos);
231 ff_fft_end(s);
232}
diff --git a/apps/codecs/libwmapro/mdct_tablegen.h b/apps/codecs/libwmapro/mdct_tablegen.h
new file mode 100644
index 0000000000..c4c3f95618
--- /dev/null
+++ b/apps/codecs/libwmapro/mdct_tablegen.h
@@ -0,0 +1,60 @@
1/*
2 * Header file for hardcoded MDCT tables
3 *
4 * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <assert.h>
24// do not use libavutil/mathematics.h since this is compiled both
25// for the host and the target and config.h is only valid for the target
26#include <math.h>
27//#include "../libavutil/attributes.h"
28
29#if !CONFIG_HARDCODED_TABLES
30SINETABLE( 32);
31SINETABLE( 64);
32SINETABLE( 128);
33SINETABLE( 256);
34SINETABLE( 512);
35SINETABLE(1024);
36SINETABLE(2048);
37SINETABLE(4096);
38#else
39#include "libavcodec/mdct_tables.h"
40#endif
41
42SINETABLE_CONST float * const ff_sine_windows[] = {
43 NULL, NULL, NULL, NULL, NULL, // unused
44 ff_sine_32 , ff_sine_64 ,
45 ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096
46};
47
48// Generate a sine window.
49av_cold void ff_sine_window_init(float *window, int n) {
50 int i;
51 for(i = 0; i < n; i++)
52 window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n)));
53}
54
55av_cold void ff_init_ff_sine_windows(int index) {
56 assert(index >= 0 && index < FF_ARRAY_ELEMS(ff_sine_windows));
57#if !CONFIG_HARDCODED_TABLES
58 ff_sine_window_init(ff_sine_windows[index], 1 << index);
59#endif
60}
diff --git a/apps/codecs/libwmapro/put_bits.h b/apps/codecs/libwmapro/put_bits.h
new file mode 100644
index 0000000000..c0139661a5
--- /dev/null
+++ b/apps/codecs/libwmapro/put_bits.h
@@ -0,0 +1,343 @@
1/*
2 * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file libavcodec/put_bits.h
23 * bitstream writer API
24 */
25
26#ifndef AVCODEC_PUT_BITS_H
27#define AVCODEC_PUT_BITS_H
28
29#include <stdint.h>
30#include <stdlib.h>
31#include <assert.h>
32#include "libavutil/bswap.h"
33#include "libavutil/common.h"
34#include "libavutil/intreadwrite.h"
35#include "libavutil/log.h"
36#include "mathops.h"
37
38//#define ALT_BITSTREAM_WRITER
39//#define ALIGNED_BITSTREAM_WRITER
40
41/* buf and buf_end must be present and used by every alternative writer. */
42typedef struct PutBitContext {
43#ifdef ALT_BITSTREAM_WRITER
44 uint8_t *buf, *buf_end;
45 int index;
46#else
47 uint32_t bit_buf;
48 int bit_left;
49 uint8_t *buf, *buf_ptr, *buf_end;
50#endif
51 int size_in_bits;
52} PutBitContext;
53
54/**
55 * Initializes the PutBitContext s.
56 *
57 * @param buffer the buffer where to put bits
58 * @param buffer_size the size in bytes of buffer
59 */
60static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
61{
62 if(buffer_size < 0) {
63 buffer_size = 0;
64 buffer = NULL;
65 }
66
67 s->size_in_bits= 8*buffer_size;
68 s->buf = buffer;
69 s->buf_end = s->buf + buffer_size;
70#ifdef ALT_BITSTREAM_WRITER
71 s->index=0;
72 ((uint32_t*)(s->buf))[0]=0;
73// memset(buffer, 0, buffer_size);
74#else
75 s->buf_ptr = s->buf;
76 s->bit_left=32;
77 s->bit_buf=0;
78#endif
79}
80
81/**
82 * Returns the total number of bits written to the bitstream.
83 */
84static inline int put_bits_count(PutBitContext *s)
85{
86#ifdef ALT_BITSTREAM_WRITER
87 return s->index;
88#else
89 return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left;
90#endif
91}
92
93/**
94 * Pads the end of the output stream with zeros.
95 */
96static inline void flush_put_bits(PutBitContext *s)
97{
98#ifdef ALT_BITSTREAM_WRITER
99 align_put_bits(s);
100#else
101#ifndef BITSTREAM_WRITER_LE
102 s->bit_buf<<= s->bit_left;
103#endif
104 while (s->bit_left < 32) {
105 /* XXX: should test end of buffer */
106#ifdef BITSTREAM_WRITER_LE
107 *s->buf_ptr++=s->bit_buf;
108 s->bit_buf>>=8;
109#else
110 *s->buf_ptr++=s->bit_buf >> 24;
111 s->bit_buf<<=8;
112#endif
113 s->bit_left+=8;
114 }
115 s->bit_left=32;
116 s->bit_buf=0;
117#endif
118}
119
120#if defined(ALT_BITSTREAM_WRITER) || defined(BITSTREAM_WRITER_LE)
121#define align_put_bits align_put_bits_unsupported_here
122#define ff_put_string ff_put_string_unsupported_here
123#define ff_copy_bits ff_copy_bits_unsupported_here
124#else
125/**
126 * Pads the bitstream with zeros up to the next byte boundary.
127 */
128void align_put_bits(PutBitContext *s);
129
130/**
131 * Puts the string string in the bitstream.
132 *
133 * @param terminate_string 0-terminates the written string if value is 1
134 */
135void ff_put_string(PutBitContext *pb, const char *string, int terminate_string);
136
137/**
138 * Copies the content of src to the bitstream.
139 *
140 * @param length the number of bits of src to copy
141 */
142void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length);
143#endif
144
145/**
146 * Writes up to 31 bits into a bitstream.
147 * Use put_bits32 to write 32 bits.
148 */
149static inline void put_bits(PutBitContext *s, int n, unsigned int value)
150#ifndef ALT_BITSTREAM_WRITER
151{
152 unsigned int bit_buf;
153 int bit_left;
154
155 // printf("put_bits=%d %x\n", n, value);
156 assert(n <= 31 && value < (1U << n));
157
158 bit_buf = s->bit_buf;
159 bit_left = s->bit_left;
160
161 // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
162 /* XXX: optimize */
163#ifdef BITSTREAM_WRITER_LE
164 bit_buf |= value << (32 - bit_left);
165 if (n >= bit_left) {
166#if !HAVE_FAST_UNALIGNED
167 if (3 & (intptr_t) s->buf_ptr) {
168 AV_WL32(s->buf_ptr, bit_buf);
169 } else
170#endif
171 *(uint32_t *)s->buf_ptr = le2me_32(bit_buf);
172 s->buf_ptr+=4;
173 bit_buf = (bit_left==32)?0:value >> bit_left;
174 bit_left+=32;
175 }
176 bit_left-=n;
177#else
178 if (n < bit_left) {
179 bit_buf = (bit_buf<<n) | value;
180 bit_left-=n;
181 } else {
182 bit_buf<<=bit_left;
183 bit_buf |= value >> (n - bit_left);
184#if !HAVE_FAST_UNALIGNED
185 if (3 & (intptr_t) s->buf_ptr) {
186 AV_WB32(s->buf_ptr, bit_buf);
187 } else
188#endif
189 *(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
190 //printf("bitbuf = %08x\n", bit_buf);
191 s->buf_ptr+=4;
192 bit_left+=32 - n;
193 bit_buf = value;
194 }
195#endif
196
197 s->bit_buf = bit_buf;
198 s->bit_left = bit_left;
199}
200#else /* ALT_BITSTREAM_WRITER defined */
201{
202# ifdef ALIGNED_BITSTREAM_WRITER
203# if ARCH_X86
204 __asm__ volatile(
205 "movl %0, %%ecx \n\t"
206 "xorl %%eax, %%eax \n\t"
207 "shrdl %%cl, %1, %%eax \n\t"
208 "shrl %%cl, %1 \n\t"
209 "movl %0, %%ecx \n\t"
210 "shrl $3, %%ecx \n\t"
211 "andl $0xFFFFFFFC, %%ecx \n\t"
212 "bswapl %1 \n\t"
213 "orl %1, (%2, %%ecx) \n\t"
214 "bswapl %%eax \n\t"
215 "addl %3, %0 \n\t"
216 "movl %%eax, 4(%2, %%ecx) \n\t"
217 : "=&r" (s->index), "=&r" (value)
218 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n))
219 : "%eax", "%ecx"
220 );
221# else
222 int index= s->index;
223 uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5);
224
225 value<<= 32-n;
226
227 ptr[0] |= be2me_32(value>>(index&31));
228 ptr[1] = be2me_32(value<<(32-(index&31)));
229//if(n>24) printf("%d %d\n", n, value);
230 index+= n;
231 s->index= index;
232# endif
233# else //ALIGNED_BITSTREAM_WRITER
234# if ARCH_X86
235 __asm__ volatile(
236 "movl $7, %%ecx \n\t"
237 "andl %0, %%ecx \n\t"
238 "addl %3, %%ecx \n\t"
239 "negl %%ecx \n\t"
240 "shll %%cl, %1 \n\t"
241 "bswapl %1 \n\t"
242 "movl %0, %%ecx \n\t"
243 "shrl $3, %%ecx \n\t"
244 "orl %1, (%%ecx, %2) \n\t"
245 "addl %3, %0 \n\t"
246 "movl $0, 4(%%ecx, %2) \n\t"
247 : "=&r" (s->index), "=&r" (value)
248 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value)
249 : "%ecx"
250 );
251# else
252 int index= s->index;
253 uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
254
255 ptr[0] |= be2me_32(value<<(32-n-(index&7) ));
256 ptr[1] = 0;
257//if(n>24) printf("%d %d\n", n, value);
258 index+= n;
259 s->index= index;
260# endif
261# endif //!ALIGNED_BITSTREAM_WRITER
262}
263#endif
264
265static inline void put_sbits(PutBitContext *pb, int n, int32_t value)
266{
267 assert(n >= 0 && n <= 31);
268
269 put_bits(pb, n, value & ((1<<n)-1));
270}
271
272/**
273 * Writes exactly 32 bits into a bitstream.
274 */
275static void av_unused put_bits32(PutBitContext *s, uint32_t value)
276{
277 int lo = value & 0xffff;
278 int hi = value >> 16;
279#ifdef BITSTREAM_WRITER_LE
280 put_bits(s, 16, lo);
281 put_bits(s, 16, hi);
282#else
283 put_bits(s, 16, hi);
284 put_bits(s, 16, lo);
285#endif
286}
287
288/**
289 * Returns the pointer to the byte where the bitstream writer will put
290 * the next bit.
291 */
292static inline uint8_t* put_bits_ptr(PutBitContext *s)
293{
294#ifdef ALT_BITSTREAM_WRITER
295 return s->buf + (s->index>>3);
296#else
297 return s->buf_ptr;
298#endif
299}
300
301/**
302 * Skips the given number of bytes.
303 * PutBitContext must be flushed & aligned to a byte boundary before calling this.
304 */
305static inline void skip_put_bytes(PutBitContext *s, int n)
306{
307 assert((put_bits_count(s)&7)==0);
308#ifdef ALT_BITSTREAM_WRITER
309 FIXME may need some cleaning of the buffer
310 s->index += n<<3;
311#else
312 assert(s->bit_left==32);
313 s->buf_ptr += n;
314#endif
315}
316
317/**
318 * Skips the given number of bits.
319 * Must only be used if the actual values in the bitstream do not matter.
320 * If n is 0 the behavior is undefined.
321 */
322static inline void skip_put_bits(PutBitContext *s, int n)
323{
324#ifdef ALT_BITSTREAM_WRITER
325 s->index += n;
326#else
327 s->bit_left -= n;
328 s->buf_ptr-= 4*(s->bit_left>>5);
329 s->bit_left &= 31;
330#endif
331}
332
333/**
334 * Changes the end of the buffer.
335 *
336 * @param size the new size in bytes of the buffer where to put bits
337 */
338static inline void set_put_bits_buffer_size(PutBitContext *s, int size)
339{
340 s->buf_end= s->buf + size;
341}
342
343#endif /* AVCODEC_PUT_BITS_H */
diff --git a/apps/codecs/libwmapro/wma.c b/apps/codecs/libwmapro/wma.c
new file mode 100644
index 0000000000..5306634c7c
--- /dev/null
+++ b/apps/codecs/libwmapro/wma.c
@@ -0,0 +1,525 @@
1/*
2 * WMA compatible codec
3 * Copyright (c) 2002-2007 The FFmpeg Project
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "avcodec.h"
23#include "wma.h"
24//#include "wmadata.h"
25
26#undef NDEBUG
27#include <assert.h>
28#if 0
29/* XXX: use same run/length optimization as mpeg decoders */
30//FIXME maybe split decode / encode or pass flag
31static void init_coef_vlc(VLC *vlc, uint16_t **prun_table,
32 float **plevel_table, uint16_t **pint_table,
33 const CoefVLCTable *vlc_table)
34{
35 int n = vlc_table->n;
36 const uint8_t *table_bits = vlc_table->huffbits;
37 const uint32_t *table_codes = vlc_table->huffcodes;
38 const uint16_t *levels_table = vlc_table->levels;
39 uint16_t *run_table, *level_table, *int_table;
40 float *flevel_table;
41 int i, l, j, k, level;
42
43 init_vlc(vlc, VLCBITS, n, table_bits, 1, 1, table_codes, 4, 4, 0);
44
45 run_table = av_malloc(n * sizeof(uint16_t));
46 level_table = av_malloc(n * sizeof(uint16_t));
47 flevel_table= av_malloc(n * sizeof(*flevel_table));
48 int_table = av_malloc(n * sizeof(uint16_t));
49 i = 2;
50 level = 1;
51 k = 0;
52 while (i < n) {
53 int_table[k] = i;
54 l = levels_table[k++];
55 for (j = 0; j < l; j++) {
56 run_table[i] = j;
57 level_table[i] = level;
58 flevel_table[i]= level;
59 i++;
60 }
61 level++;
62 }
63 *prun_table = run_table;
64 *plevel_table = flevel_table;
65 *pint_table = int_table;
66 av_free(level_table);
67}
68#endif /* 0 */
69
70/**
71 *@brief Get the samples per frame for this stream.
72 *@param sample_rate output sample_rate
73 *@param version wma version
74 *@param decode_flags codec compression features
75 *@return log2 of the number of output samples per frame
76 */
77int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version,
78 unsigned int decode_flags)
79{
80
81 int frame_len_bits;
82
83 if (sample_rate <= 16000) {
84 frame_len_bits = 9;
85 } else if (sample_rate <= 22050 ||
86 (sample_rate <= 32000 && version == 1)) {
87 frame_len_bits = 10;
88 } else if (sample_rate <= 48000) {
89 frame_len_bits = 11;
90 } else if (sample_rate <= 96000) {
91 frame_len_bits = 12;
92 } else {
93 frame_len_bits = 13;
94 }
95
96 if (version == 3) {
97 int tmp = decode_flags & 0x6;
98 if (tmp == 0x2) {
99 ++frame_len_bits;
100 } else if (tmp == 0x4) {
101 --frame_len_bits;
102 } else if (tmp == 0x6) {
103 frame_len_bits -= 2;
104 }
105 }
106
107 return frame_len_bits;
108}
109
110#if 0
111int ff_wma_init(AVCodecContext *avctx, int flags2)
112{
113 WMACodecContext *s = avctx->priv_data;
114 int i;
115 float bps1, high_freq;
116 volatile float bps;
117 int sample_rate1;
118 int coef_vlc_table;
119
120 if ( avctx->sample_rate <= 0 || avctx->sample_rate > 50000
121 || avctx->channels <= 0 || avctx->channels > 8
122 || avctx->bit_rate <= 0)
123 return -1;
124
125 s->sample_rate = avctx->sample_rate;
126 s->nb_channels = avctx->channels;
127 s->bit_rate = avctx->bit_rate;
128 s->block_align = avctx->block_align;
129
130 dsputil_init(&s->dsp, avctx);
131
132 if (avctx->codec->id == CODEC_ID_WMAV1) {
133 s->version = 1;
134 } else {
135 s->version = 2;
136 }
137
138 /* compute MDCT block size */
139 s->frame_len_bits = ff_wma_get_frame_len_bits(s->sample_rate, s->version, 0);
140
141 s->frame_len = 1 << s->frame_len_bits;
142 if (s->use_variable_block_len) {
143 int nb_max, nb;
144 nb = ((flags2 >> 3) & 3) + 1;
145 if ((s->bit_rate / s->nb_channels) >= 32000)
146 nb += 2;
147 nb_max = s->frame_len_bits - BLOCK_MIN_BITS;
148 if (nb > nb_max)
149 nb = nb_max;
150 s->nb_block_sizes = nb + 1;
151 } else {
152 s->nb_block_sizes = 1;
153 }
154
155 /* init rate dependent parameters */
156 s->use_noise_coding = 1;
157 high_freq = s->sample_rate * 0.5;
158
159 /* if version 2, then the rates are normalized */
160 sample_rate1 = s->sample_rate;
161 if (s->version == 2) {
162 if (sample_rate1 >= 44100) {
163 sample_rate1 = 44100;
164 } else if (sample_rate1 >= 22050) {
165 sample_rate1 = 22050;
166 } else if (sample_rate1 >= 16000) {
167 sample_rate1 = 16000;
168 } else if (sample_rate1 >= 11025) {
169 sample_rate1 = 11025;
170 } else if (sample_rate1 >= 8000) {
171 sample_rate1 = 8000;
172 }
173 }
174
175 bps = (float)s->bit_rate / (float)(s->nb_channels * s->sample_rate);
176 s->byte_offset_bits = av_log2((int)(bps * s->frame_len / 8.0 + 0.5)) + 2;
177
178 /* compute high frequency value and choose if noise coding should
179 be activated */
180 bps1 = bps;
181 if (s->nb_channels == 2)
182 bps1 = bps * 1.6;
183 if (sample_rate1 == 44100) {
184 if (bps1 >= 0.61) {
185 s->use_noise_coding = 0;
186 } else {
187 high_freq = high_freq * 0.4;
188 }
189 } else if (sample_rate1 == 22050) {
190 if (bps1 >= 1.16) {
191 s->use_noise_coding = 0;
192 } else if (bps1 >= 0.72) {
193 high_freq = high_freq * 0.7;
194 } else {
195 high_freq = high_freq * 0.6;
196 }
197 } else if (sample_rate1 == 16000) {
198 if (bps > 0.5) {
199 high_freq = high_freq * 0.5;
200 } else {
201 high_freq = high_freq * 0.3;
202 }
203 } else if (sample_rate1 == 11025) {
204 high_freq = high_freq * 0.7;
205 } else if (sample_rate1 == 8000) {
206 if (bps <= 0.625) {
207 high_freq = high_freq * 0.5;
208 } else if (bps > 0.75) {
209 s->use_noise_coding = 0;
210 } else {
211 high_freq = high_freq * 0.65;
212 }
213 } else {
214 if (bps >= 0.8) {
215 high_freq = high_freq * 0.75;
216 } else if (bps >= 0.6) {
217 high_freq = high_freq * 0.6;
218 } else {
219 high_freq = high_freq * 0.5;
220 }
221 }
222 dprintf(s->avctx, "flags2=0x%x\n", flags2);
223 dprintf(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n",
224 s->version, s->nb_channels, s->sample_rate, s->bit_rate,
225 s->block_align);
226 dprintf(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
227 bps, bps1, high_freq, s->byte_offset_bits);
228 dprintf(s->avctx, "use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n",
229 s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes);
230
231 /* compute the scale factor band sizes for each MDCT block size */
232 {
233 int a, b, pos, lpos, k, block_len, i, j, n;
234 const uint8_t *table;
235
236 if (s->version == 1) {
237 s->coefs_start = 3;
238 } else {
239 s->coefs_start = 0;
240 }
241 for (k = 0; k < s->nb_block_sizes; k++) {
242 block_len = s->frame_len >> k;
243
244 if (s->version == 1) {
245 lpos = 0;
246 for (i = 0; i < 25; i++) {
247 a = ff_wma_critical_freqs[i];
248 b = s->sample_rate;
249 pos = ((block_len * 2 * a) + (b >> 1)) / b;
250 if (pos > block_len)
251 pos = block_len;
252 s->exponent_bands[0][i] = pos - lpos;
253 if (pos >= block_len) {
254 i++;
255 break;
256 }
257 lpos = pos;
258 }
259 s->exponent_sizes[0] = i;
260 } else {
261 /* hardcoded tables */
262 table = NULL;
263 a = s->frame_len_bits - BLOCK_MIN_BITS - k;
264 if (a < 3) {
265 if (s->sample_rate >= 44100) {
266 table = exponent_band_44100[a];
267 } else if (s->sample_rate >= 32000) {
268 table = exponent_band_32000[a];
269 } else if (s->sample_rate >= 22050) {
270 table = exponent_band_22050[a];
271 }
272 }
273 if (table) {
274 n = *table++;
275 for (i = 0; i < n; i++)
276 s->exponent_bands[k][i] = table[i];
277 s->exponent_sizes[k] = n;
278 } else {
279 j = 0;
280 lpos = 0;
281 for (i = 0; i < 25; i++) {
282 a = ff_wma_critical_freqs[i];
283 b = s->sample_rate;
284 pos = ((block_len * 2 * a) + (b << 1)) / (4 * b);
285 pos <<= 2;
286 if (pos > block_len)
287 pos = block_len;
288 if (pos > lpos)
289 s->exponent_bands[k][j++] = pos - lpos;
290 if (pos >= block_len)
291 break;
292 lpos = pos;
293 }
294 s->exponent_sizes[k] = j;
295 }
296 }
297
298 /* max number of coefs */
299 s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k;
300 /* high freq computation */
301 s->high_band_start[k] = (int)((block_len * 2 * high_freq) /
302 s->sample_rate + 0.5);
303 n = s->exponent_sizes[k];
304 j = 0;
305 pos = 0;
306 for (i = 0; i < n; i++) {
307 int start, end;
308 start = pos;
309 pos += s->exponent_bands[k][i];
310 end = pos;
311 if (start < s->high_band_start[k])
312 start = s->high_band_start[k];
313 if (end > s->coefs_end[k])
314 end = s->coefs_end[k];
315 if (end > start)
316 s->exponent_high_bands[k][j++] = end - start;
317 }
318 s->exponent_high_sizes[k] = j;
319#if 0
320 tprintf(s->avctx, "%5d: coefs_end=%d high_band_start=%d nb_high_bands=%d: ",
321 s->frame_len >> k,
322 s->coefs_end[k],
323 s->high_band_start[k],
324 s->exponent_high_sizes[k]);
325 for (j = 0; j < s->exponent_high_sizes[k]; j++)
326 tprintf(s->avctx, " %d", s->exponent_high_bands[k][j]);
327 tprintf(s->avctx, "\n");
328#endif
329 }
330 }
331
332#ifdef TRACE
333 {
334 int i, j;
335 for (i = 0; i < s->nb_block_sizes; i++) {
336 tprintf(s->avctx, "%5d: n=%2d:",
337 s->frame_len >> i,
338 s->exponent_sizes[i]);
339 for (j = 0; j < s->exponent_sizes[i]; j++)
340 tprintf(s->avctx, " %d", s->exponent_bands[i][j]);
341 tprintf(s->avctx, "\n");
342 }
343 }
344#endif
345
346 /* init MDCT windows : simple sinus window */
347 for (i = 0; i < s->nb_block_sizes; i++) {
348 ff_init_ff_sine_windows(s->frame_len_bits - i);
349 s->windows[i] = ff_sine_windows[s->frame_len_bits - i];
350 }
351
352 s->reset_block_lengths = 1;
353
354 if (s->use_noise_coding) {
355
356 /* init the noise generator */
357 if (s->use_exp_vlc) {
358 s->noise_mult = 0.02;
359 } else {
360 s->noise_mult = 0.04;
361 }
362
363#ifdef TRACE
364 for (i = 0; i < NOISE_TAB_SIZE; i++)
365 s->noise_table[i] = 1.0 * s->noise_mult;
366#else
367 {
368 unsigned int seed;
369 float norm;
370 seed = 1;
371 norm = (1.0 / (float)(1LL << 31)) * sqrt(3) * s->noise_mult;
372 for (i = 0; i < NOISE_TAB_SIZE; i++) {
373 seed = seed * 314159 + 1;
374 s->noise_table[i] = (float)((int)seed) * norm;
375 }
376 }
377#endif
378 }
379
380 /* choose the VLC tables for the coefficients */
381 coef_vlc_table = 2;
382 if (s->sample_rate >= 32000) {
383 if (bps1 < 0.72) {
384 coef_vlc_table = 0;
385 } else if (bps1 < 1.16) {
386 coef_vlc_table = 1;
387 }
388 }
389 s->coef_vlcs[0]= &coef_vlcs[coef_vlc_table * 2 ];
390 s->coef_vlcs[1]= &coef_vlcs[coef_vlc_table * 2 + 1];
391 init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0], &s->int_table[0],
392 s->coef_vlcs[0]);
393 init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1], &s->int_table[1],
394 s->coef_vlcs[1]);
395
396 return 0;
397}
398
399int ff_wma_total_gain_to_bits(int total_gain)
400{
401 if (total_gain < 15) return 13;
402 else if (total_gain < 32) return 12;
403 else if (total_gain < 40) return 11;
404 else if (total_gain < 45) return 10;
405 else return 9;
406}
407
408int ff_wma_end(AVCodecContext *avctx)
409{
410 WMACodecContext *s = avctx->priv_data;
411 int i;
412
413 for (i = 0; i < s->nb_block_sizes; i++)
414 ff_mdct_end(&s->mdct_ctx[i]);
415
416 if (s->use_exp_vlc) {
417 free_vlc(&s->exp_vlc);
418 }
419 if (s->use_noise_coding) {
420 free_vlc(&s->hgain_vlc);
421 }
422 for (i = 0; i < 2; i++) {
423 free_vlc(&s->coef_vlc[i]);
424 av_free(s->run_table[i]);
425 av_free(s->level_table[i]);
426 av_free(s->int_table[i]);
427 }
428
429 return 0;
430}
431#endif /* 0 */
432/**
433 * Decode an uncompressed coefficient.
434 * @param s codec context
435 * @return the decoded coefficient
436 */
437unsigned int ff_wma_get_large_val(GetBitContext* gb)
438{
439 /** consumes up to 34 bits */
440 int n_bits = 8;
441 /** decode length */
442 if (get_bits1(gb)) {
443 n_bits += 8;
444 if (get_bits1(gb)) {
445 n_bits += 8;
446 if (get_bits1(gb)) {
447 n_bits += 7;
448 }
449 }
450 }
451 return get_bits_long(gb, n_bits);
452}
453
454/**
455 * Decode run level compressed coefficients.
456 * @param avctx codec context
457 * @param gb bitstream reader context
458 * @param vlc vlc table for get_vlc2
459 * @param level_table level codes
460 * @param run_table run codes
461 * @param version 0 for wma1,2 1 for wmapro
462 * @param ptr output buffer
463 * @param offset offset in the output buffer
464 * @param num_coefs number of input coefficents
465 * @param block_len input buffer length (2^n)
466 * @param frame_len_bits number of bits for escaped run codes
467 * @param coef_nb_bits number of bits for escaped level codes
468 * @return 0 on success, -1 otherwise
469 */
470int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
471 VLC *vlc,
472 const float *level_table, const uint16_t *run_table,
473 int version, WMACoef *ptr, int offset,
474 int num_coefs, int block_len, int frame_len_bits,
475 int coef_nb_bits)
476{
477 int code, level, sign;
478 const uint32_t *ilvl = (const uint32_t*)level_table;
479 uint32_t *iptr = (uint32_t*)ptr;
480 const unsigned int coef_mask = block_len - 1;
481 for (; offset < num_coefs; offset++) {
482 code = get_vlc2(gb, vlc->table, VLCBITS, VLCMAX);
483 if (code > 1) {
484 /** normal code */
485 offset += run_table[code];
486 sign = get_bits1(gb) - 1;
487 iptr[offset & coef_mask] = ilvl[code] ^ sign<<31;
488 } else if (code == 1) {
489 /** EOB */
490 break;
491 } else {
492 /** escape */
493 if (!version) {
494 level = get_bits(gb, coef_nb_bits);
495 /** NOTE: this is rather suboptimal. reading
496 block_len_bits would be better */
497 offset += get_bits(gb, frame_len_bits);
498 } else {
499 level = ff_wma_get_large_val(gb);
500 /** escape decode */
501 if (get_bits1(gb)) {
502 if (get_bits1(gb)) {
503 if (get_bits1(gb)) {
504 av_log(avctx,AV_LOG_ERROR,
505 "broken escape sequence\n");
506 return -1;
507 } else
508 offset += get_bits(gb, frame_len_bits) + 4;
509 } else
510 offset += get_bits(gb, 2) + 1;
511 }
512 }
513 sign = get_bits1(gb) - 1;
514 ptr[offset & coef_mask] = (level^sign) - sign;
515 }
516 }
517 /** NOTE: EOB can be omitted */
518 if (offset > num_coefs) {
519 av_log(avctx, AV_LOG_ERROR, "overflow in spectral RLE, ignoring\n");
520 return -1;
521 }
522
523 return 0;
524}
525
diff --git a/apps/codecs/libwmapro/wma.h b/apps/codecs/libwmapro/wma.h
new file mode 100644
index 0000000000..11274ad970
--- /dev/null
+++ b/apps/codecs/libwmapro/wma.h
@@ -0,0 +1,163 @@
1/*
2 * WMA compatible codec
3 * Copyright (c) 2002-2007 The FFmpeg Project
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#ifndef AVCODEC_WMA_H
23#define AVCODEC_WMA_H
24
25#include "get_bits.h"
26#include "put_bits.h"
27#include "dsputil.h"
28#include "fft.h"
29
30/* size of blocks */
31#define BLOCK_MIN_BITS 7
32#define BLOCK_MAX_BITS 11
33#define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
34
35#define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
36
37/* XXX: find exact max size */
38#define HIGH_BAND_MAX_SIZE 16
39
40#define NB_LSP_COEFS 10
41
42/* XXX: is it a suitable value ? */
43#define MAX_CODED_SUPERFRAME_SIZE 16384
44
45#define MAX_CHANNELS 2
46
47#define NOISE_TAB_SIZE 8192
48
49#define LSP_POW_BITS 7
50
51//FIXME should be in wmadec
52#define VLCBITS 9
53#define VLCMAX ((22+VLCBITS-1)/VLCBITS)
54
55typedef float WMACoef; ///< type for decoded coefficients, int16_t would be enough for wma 1/2
56
57typedef struct CoefVLCTable {
58 int n; ///< total number of codes
59 int max_level;
60 const uint32_t *huffcodes; ///< VLC bit values
61 const uint8_t *huffbits; ///< VLC bit size
62 const uint16_t *levels; ///< table to build run/level tables
63} CoefVLCTable;
64
65typedef struct WMACodecContext {
66 AVCodecContext* avctx;
67 GetBitContext gb;
68 PutBitContext pb;
69 int sample_rate;
70 int nb_channels;
71 int bit_rate;
72 int version; ///< 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
73 int block_align;
74 int use_bit_reservoir;
75 int use_variable_block_len;
76 int use_exp_vlc; ///< exponent coding: 0 = lsp, 1 = vlc + delta
77 int use_noise_coding; ///< true if perceptual noise is added
78 int byte_offset_bits;
79 VLC exp_vlc;
80 int exponent_sizes[BLOCK_NB_SIZES];
81 uint16_t exponent_bands[BLOCK_NB_SIZES][25];
82 int high_band_start[BLOCK_NB_SIZES]; ///< index of first coef in high band
83 int coefs_start; ///< first coded coef
84 int coefs_end[BLOCK_NB_SIZES]; ///< max number of coded coefficients
85 int exponent_high_sizes[BLOCK_NB_SIZES];
86 int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
87 VLC hgain_vlc;
88
89 /* coded values in high bands */
90 int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
91 int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
92
93 /* there are two possible tables for spectral coefficients */
94//FIXME the following 3 tables should be shared between decoders
95 VLC coef_vlc[2];
96 uint16_t *run_table[2];
97 float *level_table[2];
98 uint16_t *int_table[2];
99 const CoefVLCTable *coef_vlcs[2];
100 /* frame info */
101 int frame_len; ///< frame length in samples
102 int frame_len_bits; ///< frame_len = 1 << frame_len_bits
103 int nb_block_sizes; ///< number of block sizes
104 /* block info */
105 int reset_block_lengths;
106 int block_len_bits; ///< log2 of current block length
107 int next_block_len_bits; ///< log2 of next block length
108 int prev_block_len_bits; ///< log2 of prev block length
109 int block_len; ///< block length in samples
110 int block_num; ///< block number in current frame
111 int block_pos; ///< current position in frame
112 uint8_t ms_stereo; ///< true if mid/side stereo mode
113 uint8_t channel_coded[MAX_CHANNELS]; ///< true if channel is coded
114 int exponents_bsize[MAX_CHANNELS]; ///< log2 ratio frame/exp. length
115 DECLARE_ALIGNED(16, float, exponents)[MAX_CHANNELS][BLOCK_MAX_SIZE];
116 float max_exponent[MAX_CHANNELS];
117 WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
118 DECLARE_ALIGNED(16, float, coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE];
119 DECLARE_ALIGNED(16, FFTSample, output)[BLOCK_MAX_SIZE * 2];
120 FFTContext mdct_ctx[BLOCK_NB_SIZES];
121 float *windows[BLOCK_NB_SIZES];
122 /* output buffer for one frame and the last for IMDCT windowing */
123 DECLARE_ALIGNED(16, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2];
124 /* last frame info */
125 uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
126 int last_bitoffset;
127 int last_superframe_len;
128 float noise_table[NOISE_TAB_SIZE];
129 int noise_index;
130 float noise_mult; /* XXX: suppress that and integrate it in the noise array */
131 /* lsp_to_curve tables */
132 float lsp_cos_table[BLOCK_MAX_SIZE];
133 float lsp_pow_e_table[256];
134 float lsp_pow_m_table1[(1 << LSP_POW_BITS)];
135 float lsp_pow_m_table2[(1 << LSP_POW_BITS)];
136 DSPContext dsp;
137
138#ifdef TRACE
139 int frame_count;
140#endif
141} WMACodecContext;
142
143extern const uint16_t ff_wma_critical_freqs[25];
144extern const uint16_t ff_wma_hgain_huffcodes[37];
145extern const uint8_t ff_wma_hgain_huffbits[37];
146extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16];
147extern const uint32_t ff_aac_scalefactor_code[121];
148extern const uint8_t ff_aac_scalefactor_bits[121];
149
150int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version,
151 unsigned int decode_flags);
152int ff_wma_init(AVCodecContext * avctx, int flags2);
153int ff_wma_total_gain_to_bits(int total_gain);
154int ff_wma_end(AVCodecContext *avctx);
155unsigned int ff_wma_get_large_val(GetBitContext* gb);
156int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
157 VLC *vlc,
158 const float *level_table, const uint16_t *run_table,
159 int version, WMACoef *ptr, int offset,
160 int num_coefs, int block_len, int frame_len_bits,
161 int coef_nb_bits);
162
163#endif /* AVCODEC_WMA_H */
diff --git a/apps/codecs/libwmapro/wmaprodata.h b/apps/codecs/libwmapro/wmaprodata.h
new file mode 100644
index 0000000000..a1d186e0c2
--- /dev/null
+++ b/apps/codecs/libwmapro/wmaprodata.h
@@ -0,0 +1,604 @@
1/*
2 * WMA 9/3/PRO compatible decoder
3 * Copyright (c) 2007 Baptiste Coudurier, Benjamin Larsson, Ulion
4 * Copyright (c) 2008 - 2009 Sascha Sommer
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23/**
24 * @file libavcodec/wmaprodata.h
25 * @brief tables for wmapro decoding
26 */
27
28#ifndef AVCODEC_WMAPRODATA_H
29#define AVCODEC_WMAPRODATA_H
30
31#include <stddef.h>
32#include <stdint.h>
33
34/**
35 * @brief frequencies to divide the frequency spectrum into scale factor bands
36 */
37static const uint16_t critical_freq[] = {
38 100, 200, 300, 400, 510, 630, 770,
39 920, 1080, 1270, 1480, 1720, 2000, 2320,
40 2700, 3150, 3700, 4400, 5300, 6400, 7700,
41 9500, 12000, 15500, 20675, 28575, 41375, 63875,
42};
43
44
45/**
46 * @name Huffman tables for DPCM-coded scale factors
47 * @{
48 */
49#define HUFF_SCALE_SIZE 121
50#define HUFF_SCALE_MAXBITS 19
51static const uint16_t scale_huffcodes[HUFF_SCALE_SIZE] = {
52 0xE639, 0xE6C2, 0xE6C1, 0xE6C0, 0xE63F, 0xE63E, 0xE63D, 0xE63C,
53 0xE63B, 0xE63A, 0xE638, 0xE637, 0xE636, 0xE635, 0xE634, 0xE632,
54 0xE633, 0xE620, 0x737B, 0xE610, 0xE611, 0xE612, 0xE613, 0xE614,
55 0xE615, 0xE616, 0xE617, 0xE618, 0xE619, 0xE61A, 0xE61B, 0xE61C,
56 0xE61D, 0xE61E, 0xE61F, 0xE6C3, 0xE621, 0xE622, 0xE623, 0xE624,
57 0xE625, 0xE626, 0xE627, 0xE628, 0xE629, 0xE62A, 0xE62B, 0xE62C,
58 0xE62D, 0xE62E, 0xE62F, 0xE630, 0xE631, 0x1CDF, 0x0E60, 0x0399,
59 0x00E7, 0x001D, 0x0000, 0x0001, 0x0001, 0x0001, 0x0002, 0x0006,
60 0x0002, 0x0007, 0x0006, 0x000F, 0x0038, 0x0072, 0x039A, 0xE6C4,
61 0xE6C5, 0xE6C6, 0xE6C7, 0xE6C8, 0xE6C9, 0xE6CA, 0xE6CB, 0xE6CC,
62 0xE6CD, 0xE6CE, 0xE6CF, 0xE6D0, 0xE6D1, 0xE6D2, 0xE6D3, 0xE6D4,
63 0xE6D5, 0xE6D6, 0xE6D7, 0xE6D8, 0xE6D9, 0xE6DA, 0xE6DB, 0xE6DC,
64 0xE6DD, 0xE6DE, 0xE6DF, 0xE6E0, 0xE6E1, 0xE6E2, 0xE6E3, 0xE6E4,
65 0xE6E5, 0xE6E6, 0xE6E7, 0xE6E8, 0xE6E9, 0xE6EA, 0xE6EB, 0xE6EC,
66 0xE6ED, 0xE6EE, 0xE6EF, 0xE6F0, 0xE6F1, 0xE6F2, 0xE6F3, 0xE6F4,
67 0xE6F5,
68};
69
70static const uint8_t scale_huffbits[HUFF_SCALE_SIZE] = {
71 19, 19, 19, 19, 19, 19, 19, 19,
72 19, 19, 19, 19, 19, 19, 19, 19,
73 19, 19, 18, 19, 19, 19, 19, 19,
74 19, 19, 19, 19, 19, 19, 19, 19,
75 19, 19, 19, 19, 19, 19, 19, 19,
76 19, 19, 19, 19, 19, 19, 19, 19,
77 19, 19, 19, 19, 19, 16, 15, 13,
78 11, 8, 5, 2, 1, 3, 5, 6,
79 6, 7, 7, 7, 9, 10, 13, 19,
80 19, 19, 19, 19, 19, 19, 19, 19,
81 19, 19, 19, 19, 19, 19, 19, 19,
82 19, 19, 19, 19, 19, 19, 19, 19,
83 19, 19, 19, 19, 19, 19, 19, 19,
84 19, 19, 19, 19, 19, 19, 19, 19,
85 19, 19, 19, 19, 19, 19, 19, 19,
86 19,
87};
88/** @} */
89
90
91/**
92 * @name Huffman, run and level tables for runlevel-coded scale factors
93 * @{
94 */
95#define HUFF_SCALE_RL_SIZE 120
96#define HUFF_SCALE_RL_MAXBITS 21
97static const uint32_t scale_rl_huffcodes[HUFF_SCALE_RL_SIZE] = {
98 0x00010C, 0x000001, 0x10FE2A, 0x000003, 0x000003, 0x000001, 0x000013,
99 0x000020, 0x000029, 0x000014, 0x000016, 0x000045, 0x000049, 0x00002F,
100 0x000042, 0x00008E, 0x00008F, 0x000129, 0x000009, 0x00000D, 0x0004AC,
101 0x00002C, 0x000561, 0x0002E6, 0x00087C, 0x0002E2, 0x00095C, 0x000018,
102 0x000001, 0x000016, 0x000044, 0x00002A, 0x000007, 0x000159, 0x000143,
103 0x000128, 0x00015A, 0x00012D, 0x00002B, 0x0000A0, 0x000142, 0x00012A,
104 0x0002EF, 0x0004AF, 0x00087D, 0x004AE9, 0x0043F9, 0x000067, 0x000199,
105 0x002B05, 0x001583, 0x0021FE, 0x10FE2C, 0x000004, 0x00002E, 0x00010D,
106 0x00000A, 0x000244, 0x000017, 0x000245, 0x000011, 0x00010E, 0x00012C,
107 0x00002A, 0x00002F, 0x000121, 0x000046, 0x00087E, 0x0000BA, 0x000032,
108 0x0087F0, 0x0056DC, 0x0002EC, 0x0043FA, 0x002B6F, 0x004AE8, 0x0002B7,
109 0x10FE2B, 0x000001, 0x000051, 0x000010, 0x0002EE, 0x000B9C, 0x002576,
110 0x000198, 0x0056DD, 0x0000CD, 0x000AC0, 0x000170, 0x004AEF, 0x00002D,
111 0x0004AD, 0x0021FF, 0x0005CF, 0x002B04, 0x10FE29, 0x10FE28, 0x0002ED,
112 0x002E74, 0x021FC4, 0x004AEE, 0x010FE3, 0x087F17, 0x000000, 0x000097,
113 0x0002E3, 0x000ADA, 0x002575, 0x00173B, 0x0043FB, 0x002E75, 0x10FE2D,
114 0x0015B6, 0x00056C, 0x000057, 0x000123, 0x000120, 0x00021E, 0x000172,
115 0x0002B1,
116};
117
118static const uint8_t scale_rl_huffbits[HUFF_SCALE_RL_SIZE] = {
119 9, 2, 21, 2, 4, 5, 5,
120 6, 6, 7, 7, 7, 7, 6,
121 7, 8, 8, 9, 10, 10, 11,
122 12, 11, 12, 12, 12, 12, 11,
123 4, 5, 7, 8, 9, 9, 9,
124 9, 9, 9, 8, 8, 9, 9,
125 12, 11, 12, 15, 15, 13, 15,
126 14, 13, 14, 21, 5, 6, 9,
127 10, 10, 11, 10, 11, 9, 9,
128 6, 8, 9, 7, 12, 10, 12,
129 16, 15, 12, 15, 14, 15, 10,
130 21, 6, 7, 11, 12, 14, 14,
131 15, 15, 14, 12, 11, 15, 12,
132 11, 14, 13, 14, 21, 21, 12,
133 16, 18, 15, 17, 20, 7, 8,
134 12, 12, 14, 15, 15, 16, 21,
135 13, 11, 7, 9, 9, 10, 11,
136 10,
137};
138
139
140static const uint8_t scale_rl_run[HUFF_SCALE_RL_SIZE] = {
141 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
142 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
143 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3,
144 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
145 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
146 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
147 0, 1, 0, 1, 0, 1,
148};
149
150static const uint8_t scale_rl_level[HUFF_SCALE_RL_SIZE] = {
151 0, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
152 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
153 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
154 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
155 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
156 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
157 7, 7, 8, 8, 9, 9,
158};
159/** @} */
160
161
162/**
163 * @name Huffman, run and level codes for runlevel-coded coefficients
164 * @{
165 */
166#define HUFF_COEF0_SIZE 272
167#define HUFF_COEF0_MAXBITS 21
168static const uint32_t coef0_huffcodes[HUFF_COEF0_SIZE] = {
169 0x00004A, 0x00002B, 0x000000, 0x000003, 0x000006, 0x000009, 0x00000F,
170 0x000010, 0x000016, 0x000011, 0x000016, 0x000028, 0x00002F, 0x000026,
171 0x000029, 0x000045, 0x000055, 0x00005D, 0x000042, 0x00004E, 0x000051,
172 0x00005E, 0x00008D, 0x0000A8, 0x0000AD, 0x000080, 0x000096, 0x00009F,
173 0x0000AA, 0x0000BE, 0x00011C, 0x000153, 0x000158, 0x000170, 0x000104,
174 0x00010D, 0x000105, 0x000103, 0x00012F, 0x000177, 0x000175, 0x000157,
175 0x000174, 0x000225, 0x00023B, 0x00020D, 0x00021F, 0x000281, 0x00027B,
176 0x000282, 0x0002AC, 0x0002FD, 0x00044F, 0x000478, 0x00044D, 0x0002EC,
177 0x00044E, 0x000564, 0x000409, 0x00040B, 0x000501, 0x000545, 0x0004F3,
178 0x000541, 0x00043B, 0x0004F1, 0x0004F4, 0x0008FD, 0x000A94, 0x000811,
179 0x000B88, 0x000B91, 0x000B93, 0x0008EA, 0x000899, 0x000B8A, 0x000972,
180 0x0009E5, 0x000A8F, 0x000A84, 0x000A8E, 0x000A00, 0x000830, 0x0008E8,
181 0x000B95, 0x000871, 0x00083A, 0x000814, 0x000873, 0x000BFE, 0x001728,
182 0x001595, 0x001712, 0x00102A, 0x001021, 0x001729, 0x00152E, 0x0013C3,
183 0x001721, 0x001597, 0x00151B, 0x0010F2, 0x001403, 0x001703, 0x001503,
184 0x001708, 0x0013C1, 0x00170E, 0x00170C, 0x0010E1, 0x0011EA, 0x001020,
185 0x001500, 0x0017FA, 0x001704, 0x001705, 0x0017F0, 0x0017FB, 0x0021E6,
186 0x002B2D, 0x0020C6, 0x002B29, 0x002E4A, 0x0023AC, 0x001519, 0x0023F3,
187 0x002B2C, 0x0021C0, 0x0017FE, 0x0023D7, 0x0017F9, 0x0012E7, 0x0013C0,
188 0x002261, 0x0023D3, 0x002057, 0x002056, 0x0021D2, 0x0020C7, 0x0023D2,
189 0x0020EC, 0x0044C0, 0x002FE2, 0x00475B, 0x002A03, 0x002FE3, 0x0021E2,
190 0x0021D0, 0x002A31, 0x002E13, 0x002E05, 0x0047E5, 0x00000E, 0x000024,
191 0x000088, 0x0000B9, 0x00010C, 0x000224, 0x0002B3, 0x000283, 0x0002ED,
192 0x00047B, 0x00041E, 0x00043D, 0x0004F5, 0x0005FD, 0x000A92, 0x000B96,
193 0x000838, 0x000971, 0x000B83, 0x000B80, 0x000BF9, 0x0011D3, 0x0011E8,
194 0x0011D7, 0x001527, 0x0011F8, 0x001073, 0x0010F0, 0x0010E4, 0x0017F8,
195 0x001062, 0x001402, 0x0017E3, 0x00151A, 0x001077, 0x00152B, 0x00170D,
196 0x0021D3, 0x002E41, 0x0013C2, 0x000029, 0x0000A9, 0x00025D, 0x000419,
197 0x000544, 0x000B8B, 0x0009E4, 0x0011D2, 0x001526, 0x001724, 0x0012E6,
198 0x00150B, 0x0017FF, 0x002E26, 0x002E4B, 0x002B28, 0x0021E3, 0x002A14,
199 0x00475A, 0x002E12, 0x000057, 0x00023E, 0x000A90, 0x000BF0, 0x001072,
200 0x001502, 0x0023D6, 0x0020ED, 0x002A30, 0x0044C7, 0x00008C, 0x00047F,
201 0x00152A, 0x002262, 0x002E04, 0x0000A1, 0x0005F9, 0x000173, 0x000875,
202 0x000171, 0x00152D, 0x0002E3, 0x0017E2, 0x0002AD, 0x0021C1, 0x000479,
203 0x0021E7, 0x00041F, 0x005C4E, 0x000543, 0x005C4F, 0x000A91, 0x00898D,
204 0x000B97, 0x008746, 0x000970, 0x008745, 0x000B85, 0x00A856, 0x00152F,
205 0x010E8E, 0x0010E5, 0x00A857, 0x00170F, 0x021D11, 0x002A58, 0x010E8F,
206 0x002E40, 0x021D13, 0x002A59, 0x043A25, 0x002A02, 0x043A21, 0x0044C1,
207 0x087448, 0x0047E4, 0x043A20, 0x00542A, 0x087449, 0x00898C,
208};
209
210static const uint8_t coef0_huffbits[HUFF_COEF0_SIZE] = {
211 8, 7, 2, 3, 3, 4, 4,
212 5, 5, 6, 6, 6, 6, 7,
213 7, 7, 7, 7, 8, 8, 8,
214 8, 8, 8, 8, 9, 9, 9,
215 9, 9, 9, 9, 9, 9, 10,
216 10, 10, 10, 10, 10, 10, 10,
217 10, 10, 10, 11, 11, 11, 11,
218 11, 11, 11, 11, 11, 11, 11,
219 11, 11, 12, 12, 12, 12, 12,
220 12, 12, 12, 12, 12, 12, 13,
221 12, 12, 12, 12, 12, 12, 13,
222 13, 13, 13, 13, 13, 13, 12,
223 12, 13, 13, 13, 13, 13, 13,
224 13, 13, 14, 14, 13, 13, 14,
225 13, 13, 14, 14, 14, 14, 14,
226 14, 14, 14, 14, 14, 13, 14,
227 14, 14, 14, 14, 14, 14, 15,
228 14, 15, 14, 14, 14, 14, 14,
229 14, 15, 14, 14, 14, 14, 14,
230 14, 14, 15, 15, 15, 15, 14,
231 15, 15, 15, 15, 15, 15, 15,
232 15, 15, 15, 15, 15, 4, 7,
233 8, 9, 10, 10, 10, 11, 11,
234 11, 12, 12, 12, 12, 12, 12,
235 13, 13, 13, 13, 13, 13, 13,
236 13, 13, 13, 14, 14, 14, 14,
237 14, 14, 14, 14, 14, 13, 14,
238 15, 14, 14, 6, 9, 11, 12,
239 12, 12, 13, 13, 13, 13, 14,
240 14, 14, 14, 14, 14, 15, 15,
241 15, 15, 7, 10, 12, 13, 14,
242 14, 14, 15, 15, 15, 8, 11,
243 13, 14, 15, 9, 12, 9, 13,
244 10, 13, 10, 14, 11, 15, 11,
245 15, 12, 15, 12, 15, 12, 16,
246 12, 17, 13, 17, 13, 17, 13,
247 18, 14, 17, 14, 19, 14, 18,
248 14, 19, 14, 20, 15, 20, 15,
249 21, 15, 20, 16, 21, 16,
250};
251
252
253#define HUFF_COEF1_SIZE 244
254#define HUFF_COEF1_MAXBITS 22
255static const uint32_t coef1_huffcodes[HUFF_COEF1_SIZE] = {
256 0x0001E2, 0x00007F, 0x000000, 0x000002, 0x000008, 0x00000E, 0x000019,
257 0x00002F, 0x000037, 0x000060, 0x00006C, 0x000095, 0x0000C6, 0x0000F0,
258 0x00012E, 0x000189, 0x0001A5, 0x0001F8, 0x000253, 0x00030A, 0x000344,
259 0x00034D, 0x0003F2, 0x0004BD, 0x0005D7, 0x00062A, 0x00068B, 0x000693,
260 0x000797, 0x00097D, 0x000BAB, 0x000C52, 0x000C5E, 0x000D21, 0x000D20,
261 0x000F1A, 0x000FCE, 0x000FD1, 0x0012F1, 0x001759, 0x0018AC, 0x0018A7,
262 0x0018BF, 0x001A2B, 0x001E52, 0x001E50, 0x001E31, 0x001FB8, 0x0025E6,
263 0x0025E7, 0x002EB4, 0x002EB7, 0x003169, 0x00315B, 0x00317C, 0x00316C,
264 0x0034CA, 0x00348D, 0x003F40, 0x003CA2, 0x003F76, 0x004BC3, 0x004BE5,
265 0x003F73, 0x004BF8, 0x004BF9, 0x006131, 0x00628B, 0x006289, 0x0062DA,
266 0x00628A, 0x0062D4, 0x006997, 0x0062B4, 0x006918, 0x00794D, 0x007E7B,
267 0x007E87, 0x007EEA, 0x00794E, 0x00699D, 0x007967, 0x00699F, 0x0062DB,
268 0x007E7A, 0x007EEB, 0x00BAC0, 0x0097C9, 0x00C537, 0x00C5AB, 0x00D233,
269 0x00D338, 0x00BAC1, 0x00D23D, 0x012F91, 0x00D339, 0x00FDC8, 0x00D23C,
270 0x00FDDC, 0x00FDC9, 0x00FDDD, 0x00D33C, 0x000003, 0x000016, 0x00003E,
271 0x0000C3, 0x0001A1, 0x000347, 0x00062E, 0x000BAA, 0x000F2D, 0x001A2A,
272 0x001E58, 0x00309B, 0x003CA3, 0x005D6A, 0x00629A, 0x006996, 0x00794F,
273 0x007EE5, 0x00BAD7, 0x00C5AA, 0x00C5F4, 0x00FDDF, 0x00FDDE, 0x018A20,
274 0x018A6D, 0x01A67B, 0x01A464, 0x025F21, 0x01F9E2, 0x01F9E3, 0x00000A,
275 0x00003D, 0x000128, 0x0003C7, 0x000C24, 0x0018A3, 0x002EB1, 0x003CB2,
276 0x00691F, 0x007E79, 0x000013, 0x0000BB, 0x00034E, 0x000D14, 0x0025FD,
277 0x004BE7, 0x000024, 0x000188, 0x0007EF, 0x000035, 0x000308, 0x0012F2,
278 0x00005C, 0x0003F6, 0x0025E0, 0x00006D, 0x000698, 0x000096, 0x000C25,
279 0x0000C7, 0x000F1B, 0x0000F3, 0x0012FF, 0x000174, 0x001A66, 0x0001A0,
280 0x003099, 0x0001E4, 0x00316B, 0x000252, 0x003F31, 0x00030B, 0x004BE6,
281 0x000346, 0x0062FB, 0x00034F, 0x007966, 0x0003F5, 0x007E86, 0x0005D4,
282 0x00C511, 0x00062C, 0x00C5F5, 0x000692, 0x00F299, 0x000795, 0x00F298,
283 0x0007E9, 0x018A21, 0x00097E, 0x0175AD, 0x000C27, 0x01A67A, 0x000C57,
284 0x02EB59, 0x000D22, 0x0314D9, 0x000F19, 0x03F3C2, 0x000FCD, 0x0348CB,
285 0x0012F8, 0x04BE41, 0x0018A0, 0x03F3C1, 0x0018A1, 0x04BE40, 0x0018B7,
286 0x0629B0, 0x001A64, 0x0D2329, 0x001E30, 0x03F3C3, 0x001F9F, 0x0BAD62,
287 0x001F99, 0x0FCF00, 0x00309A, 0x0629B1, 0x002EB6, 0x175AC3, 0x00314C,
288 0x069195, 0x003168, 0x0BAD63, 0x00348E, 0x175AC1, 0x003F30, 0x07E781,
289 0x003F41, 0x0D2328, 0x003F42, 0x1F9E03, 0x004BC2, 0x175AC2, 0x003F74,
290 0x175AC0, 0x005D61, 0x3F3C05, 0x006130, 0x3F3C04, 0x0062B5,
291};
292
293static const uint8_t coef1_huffbits[HUFF_COEF1_SIZE] = {
294 9, 7, 2, 3, 4, 4, 5,
295 6, 6, 7, 7, 8, 8, 8,
296 9, 9, 9, 9, 10, 10, 10,
297 10, 10, 11, 11, 11, 11, 11,
298 11, 12, 12, 12, 12, 12, 12,
299 12, 12, 12, 13, 13, 13, 13,
300 13, 13, 13, 13, 13, 13, 14,
301 14, 14, 14, 14, 14, 14, 14,
302 14, 14, 14, 14, 14, 15, 15,
303 14, 15, 15, 15, 15, 15, 15,
304 15, 15, 15, 15, 15, 15, 15,
305 15, 15, 15, 15, 15, 15, 15,
306 15, 15, 16, 16, 16, 16, 16,
307 16, 16, 16, 17, 16, 16, 16,
308 16, 16, 16, 16, 3, 5, 6,
309 8, 9, 10, 11, 12, 12, 13,
310 13, 14, 14, 15, 15, 15, 15,
311 15, 16, 16, 16, 16, 16, 17,
312 17, 17, 17, 18, 17, 17, 4,
313 6, 9, 10, 12, 13, 14, 14,
314 15, 15, 5, 8, 10, 12, 14,
315 15, 6, 9, 11, 6, 10, 13,
316 7, 10, 14, 7, 11, 8, 12,
317 8, 12, 8, 13, 9, 13, 9,
318 14, 9, 14, 10, 14, 10, 15,
319 10, 15, 10, 15, 10, 15, 11,
320 16, 11, 16, 11, 16, 11, 16,
321 11, 17, 12, 17, 12, 17, 12,
322 18, 12, 18, 12, 18, 12, 18,
323 13, 19, 13, 18, 13, 19, 13,
324 19, 13, 20, 13, 18, 13, 20,
325 13, 20, 14, 19, 14, 21, 14,
326 19, 14, 20, 14, 21, 14, 19,
327 14, 20, 14, 21, 15, 21, 14,
328 21, 15, 22, 15, 22, 15,
329};
330
331
332static const uint16_t coef0_run[HUFF_COEF0_SIZE] = {
333 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
334 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
335 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
336 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
337 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
338 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
339 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
340 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
341 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123,
342 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137,
343 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 0, 1,
344 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
345 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
346 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 0, 1, 2, 3,
347 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
348 18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
349 2, 3, 4, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
350 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
351 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
352 1, 0, 1, 0, 1, 0,
353};
354
355static const float coef0_level[HUFF_COEF0_SIZE] = {
356 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
357 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
358 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
359 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
360 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
361 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
362 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
363 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
364 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
365 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
366 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
367 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
368 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
369 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
370 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
371 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5,
372 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11,
373 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18,
374 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25,
375 25, 26, 26, 27, 27, 28,
376};
377
378
379static const uint16_t coef1_run[HUFF_COEF1_SIZE] = {
380 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
381 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
382 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
383 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
384 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
385 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5,
386 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
387 24, 25, 26, 27, 28, 29, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
388 2, 3, 4, 5, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 0, 1, 0,
389 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
390 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
391 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
392 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
393 1, 0, 1, 0, 1, 0, 1, 0, 0, 0,
394};
395
396static const float coef1_level[HUFF_COEF1_SIZE] = {
397 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
398 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
399 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
400 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
401 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
402 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
403 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
404 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4,
405 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10,
406 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19,
407 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28,
408 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37,
409 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 45, 45, 46,
410 46, 47, 47, 48, 48, 49, 49, 50, 51, 52,
411};
412/** @} */
413
414
415/**
416 * @name Huffman and vector lookup tables for vector-coded coefficients
417 * @{
418 */
419#define HUFF_VEC4_SIZE 127
420#define HUFF_VEC4_MAXBITS 14
421static const uint16_t vec4_huffcodes[HUFF_VEC4_SIZE] = {
422 0x0019, 0x0027, 0x00F2, 0x03BA, 0x0930, 0x1267, 0x0031, 0x0030,
423 0x0097, 0x0221, 0x058B, 0x0124, 0x00EB, 0x01D4, 0x03D8, 0x0584,
424 0x0364, 0x045F, 0x0F66, 0x0931, 0x24CD, 0x002F, 0x0039, 0x00E8,
425 0x02C3, 0x078A, 0x0037, 0x0029, 0x0084, 0x01B1, 0x00ED, 0x0086,
426 0x00F9, 0x03AB, 0x01EB, 0x08BC, 0x011E, 0x00F3, 0x0220, 0x058A,
427 0x00EC, 0x008E, 0x012B, 0x01EA, 0x0119, 0x04B0, 0x04B1, 0x03B8,
428 0x0691, 0x0365, 0x01ED, 0x049A, 0x0EA9, 0x0EA8, 0x08BD, 0x24CC,
429 0x0026, 0x0035, 0x00DB, 0x02C4, 0x07B2, 0x0038, 0x002B, 0x007F,
430 0x01B3, 0x00F4, 0x0091, 0x0116, 0x03BB, 0x0215, 0x0932, 0x002D,
431 0x002A, 0x008A, 0x01DE, 0x0028, 0x0020, 0x005C, 0x0090, 0x0068,
432 0x01EE, 0x00E9, 0x008D, 0x012A, 0x0087, 0x005D, 0x0118, 0x0349,
433 0x01EF, 0x01E3, 0x08B9, 0x00F0, 0x00D3, 0x0214, 0x049B, 0x00DA,
434 0x0089, 0x0125, 0x0217, 0x012D, 0x0690, 0x0094, 0x007D, 0x011F,
435 0x007E, 0x0059, 0x0127, 0x01A5, 0x0111, 0x00F8, 0x045D, 0x03B9,
436 0x0259, 0x0580, 0x02C1, 0x01DF, 0x0585, 0x0216, 0x0163, 0x01B0,
437 0x03C4, 0x08B8, 0x078B, 0x0755, 0x0581, 0x0F67, 0x0000,
438};
439
440static const uint8_t vec4_huffbits[HUFF_VEC4_SIZE] = {
441 5, 6, 8, 10, 12, 13, 6, 6,
442 8, 10, 11, 9, 8, 9, 10, 11,
443 10, 11, 12, 12, 14, 6, 6, 8,
444 10, 11, 6, 6, 8, 9, 8, 8,
445 8, 10, 9, 12, 9, 8, 10, 11,
446 8, 8, 9, 9, 9, 11, 11, 10,
447 11, 10, 9, 11, 12, 12, 12, 14,
448 6, 6, 8, 10, 11, 6, 6, 7,
449 9, 8, 8, 9, 10, 10, 12, 6,
450 6, 8, 9, 6, 6, 7, 8, 7,
451 9, 8, 8, 9, 8, 7, 9, 10,
452 9, 9, 12, 8, 8, 10, 11, 8,
453 8, 9, 10, 9, 11, 8, 7, 9,
454 7, 7, 9, 9, 9, 8, 11, 10,
455 10, 11, 10, 9, 11, 10, 9, 9,
456 10, 12, 11, 11, 11, 12, 1,
457};
458
459
460#define HUFF_VEC2_SIZE 137
461#define HUFF_VEC2_MAXBITS 12
462static const uint16_t vec2_huffcodes[HUFF_VEC2_SIZE] = {
463 0x055, 0x01C, 0x01A, 0x02B, 0x028, 0x067, 0x08B, 0x039,
464 0x170, 0x10D, 0x2A5, 0x047, 0x464, 0x697, 0x523, 0x8CB,
465 0x01B, 0x00E, 0x000, 0x010, 0x012, 0x036, 0x048, 0x04C,
466 0x0C2, 0x09B, 0x171, 0x03B, 0x224, 0x34A, 0x2D6, 0x019,
467 0x00F, 0x002, 0x014, 0x017, 0x006, 0x05D, 0x054, 0x0C7,
468 0x0B4, 0x192, 0x10E, 0x233, 0x043, 0x02C, 0x00F, 0x013,
469 0x006, 0x02F, 0x02C, 0x068, 0x077, 0x0DF, 0x111, 0x1A4,
470 0x16A, 0x2A4, 0x027, 0x011, 0x018, 0x02D, 0x00F, 0x04A,
471 0x040, 0x097, 0x01F, 0x11B, 0x022, 0x16D, 0x066, 0x035,
472 0x005, 0x02B, 0x049, 0x009, 0x075, 0x0CB, 0x0AA, 0x187,
473 0x106, 0x08A, 0x047, 0x060, 0x06E, 0x01D, 0x074, 0x0C4,
474 0x01E, 0x118, 0x1A7, 0x038, 0x042, 0x053, 0x076, 0x0A8,
475 0x0CA, 0x082, 0x110, 0x18D, 0x12D, 0x0B9, 0x0C8, 0x0DE,
476 0x01C, 0x0AB, 0x113, 0x18C, 0x10F, 0x09A, 0x0A5, 0x0B7,
477 0x11A, 0x186, 0x1A6, 0x259, 0x153, 0x18A, 0x193, 0x020,
478 0x10C, 0x046, 0x03A, 0x107, 0x149, 0x16C, 0x2D7, 0x225,
479 0x258, 0x316, 0x696, 0x317, 0x042, 0x522, 0x290, 0x8CA,
480 0x001,
481};
482
483static const uint8_t vec2_huffbits[HUFF_VEC2_SIZE] = {
484 7, 6, 6, 6, 7, 7, 8, 9,
485 9, 10, 10, 11, 11, 11, 12, 12,
486 6, 4, 5, 5, 6, 6, 7, 8,
487 8, 9, 9, 10, 10, 10, 11, 6,
488 4, 5, 5, 6, 7, 7, 8, 8,
489 9, 9, 10, 10, 11, 6, 5, 5,
490 6, 6, 7, 7, 8, 8, 9, 9,
491 10, 10, 7, 6, 6, 6, 7, 7,
492 8, 8, 9, 9, 10, 10, 7, 6,
493 7, 7, 7, 8, 8, 8, 9, 9,
494 10, 8, 7, 7, 7, 8, 8, 8,
495 9, 9, 9, 9, 8, 8, 8, 8,
496 8, 9, 9, 9, 9, 8, 8, 8,
497 9, 9, 9, 9, 10, 9, 9, 9,
498 9, 9, 9, 10, 9, 9, 9, 10,
499 10, 11, 10, 10, 10, 10, 11, 10,
500 10, 10, 11, 10, 11, 12, 11, 12,
501 3,
502};
503
504
505#define HUFF_VEC1_SIZE 101
506#define HUFF_VEC1_MAXBITS 11
507static const uint16_t vec1_huffcodes[HUFF_VEC1_SIZE] = {
508 0x01A, 0x003, 0x017, 0x010, 0x00C, 0x009, 0x005, 0x000,
509 0x00D, 0x00A, 0x009, 0x00C, 0x00F, 0x002, 0x004, 0x007,
510 0x00B, 0x00F, 0x01C, 0x006, 0x010, 0x015, 0x01C, 0x022,
511 0x03B, 0x00E, 0x019, 0x023, 0x034, 0x036, 0x03A, 0x047,
512 0x008, 0x00A, 0x01E, 0x031, 0x037, 0x050, 0x053, 0x06B,
513 0x06F, 0x08C, 0x0E8, 0x0EA, 0x0EB, 0x016, 0x03E, 0x03F,
514 0x06C, 0x089, 0x08A, 0x0A3, 0x0A4, 0x0D4, 0x0DD, 0x0EC,
515 0x0EE, 0x11A, 0x1D2, 0x024, 0x025, 0x02E, 0x027, 0x0C2,
516 0x0C0, 0x0DA, 0x0DB, 0x111, 0x144, 0x116, 0x14A, 0x145,
517 0x1B8, 0x1AB, 0x1DA, 0x1DE, 0x1DB, 0x1DF, 0x236, 0x237,
518 0x3A6, 0x3A7, 0x04D, 0x04C, 0x05E, 0x05F, 0x183, 0x182,
519 0x186, 0x221, 0x187, 0x220, 0x22E, 0x22F, 0x296, 0x354,
520 0x297, 0x355, 0x372, 0x373, 0x016,
521};
522
523static const uint8_t vec1_huffbits[HUFF_VEC1_SIZE] = {
524 7, 6, 5, 5, 5, 5, 5, 5,
525 4, 4, 4, 4, 4, 5, 5, 5,
526 5, 5, 5, 6, 6, 6, 6, 6,
527 6, 7, 7, 7, 7, 7, 7, 7,
528 8, 8, 8, 8, 8, 8, 8, 8,
529 8, 8, 8, 8, 8, 9, 9, 9,
530 9, 9, 9, 9, 9, 9, 9, 9,
531 9, 9, 9, 10, 10, 10, 10, 10,
532 10, 10, 10, 10, 10, 10, 10, 10,
533 10, 10, 10, 10, 10, 10, 10, 10,
534 10, 10, 11, 11, 11, 11, 11, 11,
535 11, 11, 11, 11, 11, 11, 11, 11,
536 11, 11, 11, 11, 5,
537};
538
539
540static const uint16_t symbol_to_vec4[HUFF_VEC4_SIZE] = {
541 0, 1, 2, 3, 4, 5, 16, 17, 18, 19,
542 20, 32, 33, 34, 35, 48, 49, 50, 64, 65,
543 80, 256, 257, 258, 259, 260, 272, 273, 274, 275,
544 288, 289, 290, 304, 305, 320, 512, 513, 514, 515,
545 528, 529, 530, 544, 545, 560, 768, 769, 770, 784,
546 785, 800, 1024, 1025, 1040, 1280, 4096, 4097, 4098, 4099,
547 4100, 4112, 4113, 4114, 4115, 4128, 4129, 4130, 4144, 4145,
548 4160, 4352, 4353, 4354, 4355, 4368, 4369, 4370, 4384, 4385,
549 4400, 4608, 4609, 4610, 4624, 4625, 4640, 4864, 4865, 4880,
550 5120, 8192, 8193, 8194, 8195, 8208, 8209, 8210, 8224, 8225,
551 8240, 8448, 8449, 8450, 8464, 8465, 8480, 8704, 8705, 8720,
552 8960, 12288, 12289, 12290, 12304, 12305, 12320, 12544, 12545, 12560,
553 12800, 16384, 16385, 16400, 16640, 20480, 0,
554};
555
556
557static const uint8_t symbol_to_vec2[HUFF_VEC2_SIZE] = {
558 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
559 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
560 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
561 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 64, 65,
562 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 80, 81, 82, 83, 84,
563 85, 86, 87, 88, 89, 90, 96, 97, 98, 99, 100, 101, 102, 103, 104,
564 105, 112, 113, 114, 115, 116, 117, 118, 119, 120, 128, 129, 130, 131, 132,
565 133, 134, 135, 144, 145, 146, 147, 148, 149, 150, 160, 161, 162, 163, 164,
566 165, 176, 177, 178, 179, 180, 192, 193, 194, 195, 208, 209, 210, 224, 225,
567 240, 0,
568};
569/** @} */
570
571
572/**
573 * @brief decorrelation matrix for multichannel streams
574 **/
575static const float default_decorrelation_matrices[] = {
576 1.000000, 0.707031, -0.707031, 0.707031, 0.707031, 0.578125, 0.707031,
577 0.410156, 0.578125, -0.707031, 0.410156, 0.578125, 0.000000, -0.816406,
578 0.500000, 0.652344, 0.500000, 0.269531, 0.500000, 0.269531, -0.500000,
579 -0.652344, 0.500000, -0.269531, -0.500000, 0.652344, 0.500000, -0.652344,
580 0.500000, -0.269531, 0.445312, 0.601562, 0.511719, 0.371094, 0.195312,
581 0.445312, 0.371094, -0.195312, -0.601562, -0.511719, 0.445312, 0.000000,
582 -0.632812, 0.000000, 0.632812, 0.445312, -0.371094, -0.195312, 0.601562,
583 -0.511719, 0.445312, -0.601562, 0.511719, -0.371094, 0.195312, 0.410156,
584 0.558594, 0.500000, 0.410156, 0.289062, 0.148438, 0.410156, 0.410156,
585 0.000000, -0.410156, -0.578125, -0.410156, 0.410156, 0.148438, -0.500000,
586 -0.410156, 0.289062, 0.558594, 0.410156, -0.148438, -0.500000, 0.410156,
587 0.289062, -0.558594, 0.410156, -0.410156, 0.000000, 0.410156, -0.578125,
588 0.410156, 0.410156, -0.558594, 0.500000, -0.410156, 0.289062, -0.148438,
589};
590
591/**
592 * @brief default decorrelation matrix offsets
593 */
594static const float * const default_decorrelation[] = {
595 NULL,
596 &default_decorrelation_matrices[0],
597 &default_decorrelation_matrices[1],
598 &default_decorrelation_matrices[5],
599 &default_decorrelation_matrices[14],
600 &default_decorrelation_matrices[30],
601 &default_decorrelation_matrices[55]
602};
603
604#endif /* AVCODEC_WMAPRODATA_H */
diff --git a/apps/codecs/libwmapro/wmaprodec.c b/apps/codecs/libwmapro/wmaprodec.c
new file mode 100644
index 0000000000..66d926d813
--- /dev/null
+++ b/apps/codecs/libwmapro/wmaprodec.c
@@ -0,0 +1,1594 @@
1/*
2 * Wmapro compatible decoder
3 * Copyright (c) 2007 Baptiste Coudurier, Benjamin Larsson, Ulion
4 * Copyright (c) 2008 - 2009 Sascha Sommer, Benjamin Larsson
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23/**
24 * @file libavcodec/wmaprodec.c
25 * @brief wmapro decoder implementation
26 * Wmapro is an MDCT based codec comparable to wma standard or AAC.
27 * The decoding therefore consists of the following steps:
28 * - bitstream decoding
29 * - reconstruction of per-channel data
30 * - rescaling and inverse quantization
31 * - IMDCT
32 * - windowing and overlapp-add
33 *
34 * The compressed wmapro bitstream is split into individual packets.
35 * Every such packet contains one or more wma frames.
36 * The compressed frames may have a variable length and frames may
37 * cross packet boundaries.
38 * Common to all wmapro frames is the number of samples that are stored in
39 * a frame.
40 * The number of samples and a few other decode flags are stored
41 * as extradata that has to be passed to the decoder.
42 *
43 * The wmapro frames themselves are again split into a variable number of
44 * subframes. Every subframe contains the data for 2^N time domain samples
45 * where N varies between 7 and 12.
46 *
47 * Example wmapro bitstream (in samples):
48 *
49 * || packet 0 || packet 1 || packet 2 packets
50 * ---------------------------------------------------
51 * || frame 0 || frame 1 || frame 2 || frames
52 * ---------------------------------------------------
53 * || | | || | | | || || subframes of channel 0
54 * ---------------------------------------------------
55 * || | | || | | | || || subframes of channel 1
56 * ---------------------------------------------------
57 *
58 * The frame layouts for the individual channels of a wma frame does not need
59 * to be the same.
60 *
61 * However, if the offsets and lengths of several subframes of a frame are the
62 * same, the subframes of the channels can be grouped.
63 * Every group may then use special coding techniques like M/S stereo coding
64 * to improve the compression ratio. These channel transformations do not
65 * need to be applied to a whole subframe. Instead, they can also work on
66 * individual scale factor bands (see below).
67 * The coefficients that carry the audio signal in the frequency domain
68 * are transmitted as huffman-coded vectors with 4, 2 and 1 elements.
69 * In addition to that, the encoder can switch to a runlevel coding scheme
70 * by transmitting subframe_length / 128 zero coefficients.
71 *
72 * Before the audio signal can be converted to the time domain, the
73 * coefficients have to be rescaled and inverse quantized.
74 * A subframe is therefore split into several scale factor bands that get
75 * scaled individually.
76 * Scale factors are submitted for every frame but they might be shared
77 * between the subframes of a channel. Scale factors are initially DPCM-coded.
78 * Once scale factors are shared, the differences are transmitted as runlevel
79 * codes.
80 * Every subframe length and offset combination in the frame layout shares a
81 * common quantization factor that can be adjusted for every channel by a
82 * modifier.
83 * After the inverse quantization, the coefficients get processed by an IMDCT.
84 * The resulting values are then windowed with a sine window and the first half
85 * of the values are added to the second half of the output from the previous
86 * subframe in order to reconstruct the output samples.
87 */
88
89#include "avcodec.h"
90#include "internal.h"
91#include "get_bits.h"
92#include "put_bits.h"
93#include "wmaprodata.h"
94#include "dsputil.h"
95#include "wma.h"
96
97/* Some defines to make it compile */
98#define AVERROR_INVALIDDATA -1
99#define AVERROR_PATCHWELCOME -2
100#ifndef M_PI
101#define M_PI 3.14159265358979323846 /* pi */
102#endif
103#define av_log_ask_for_sample(...)
104
105/** current decoder limitations */
106#define WMAPRO_MAX_CHANNELS 8 ///< max number of handled channels
107#define MAX_SUBFRAMES 32 ///< max number of subframes per channel
108#define MAX_BANDS 29 ///< max number of scale factor bands
109#define MAX_FRAMESIZE 32768 ///< maximum compressed frame size
110
111#define WMAPRO_BLOCK_MAX_BITS 12 ///< log2 of max block size
112#define WMAPRO_BLOCK_MAX_SIZE (1 << WMAPRO_BLOCK_MAX_BITS) ///< maximum block size
113#define WMAPRO_BLOCK_SIZES (WMAPRO_BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1) ///< possible block sizes
114
115
116#define VLCBITS 9
117#define SCALEVLCBITS 8
118#define VEC4MAXDEPTH ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS)
119#define VEC2MAXDEPTH ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS)
120#define VEC1MAXDEPTH ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS)
121#define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)
122#define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS)
123
124static VLC sf_vlc; ///< scale factor DPCM vlc
125static VLC sf_rl_vlc; ///< scale factor run length vlc
126static VLC vec4_vlc; ///< 4 coefficients per symbol
127static VLC vec2_vlc; ///< 2 coefficients per symbol
128static VLC vec1_vlc; ///< 1 coefficient per symbol
129static VLC coef_vlc[2]; ///< coefficient run length vlc codes
130static float sin64[33]; ///< sinus table for decorrelation
131
132/**
133 * @brief frame specific decoder context for a single channel
134 */
135typedef struct {
136 int16_t prev_block_len; ///< length of the previous block
137 uint8_t transmit_coefs;
138 uint8_t num_subframes;
139 uint16_t subframe_len[MAX_SUBFRAMES]; ///< subframe length in samples
140 uint16_t subframe_offset[MAX_SUBFRAMES]; ///< subframe positions in the current frame
141 uint8_t cur_subframe; ///< current subframe number
142 uint16_t decoded_samples; ///< number of already processed samples
143 uint8_t grouped; ///< channel is part of a group
144 int quant_step; ///< quantization step for the current subframe
145 int8_t reuse_sf; ///< share scale factors between subframes
146 int8_t scale_factor_step; ///< scaling step for the current subframe
147 int max_scale_factor; ///< maximum scale factor for the current subframe
148 int saved_scale_factors[2][MAX_BANDS]; ///< resampled and (previously) transmitted scale factor values
149 int8_t scale_factor_idx; ///< index for the transmitted scale factor values (used for resampling)
150 int* scale_factors; ///< pointer to the scale factor values used for decoding
151 uint8_t table_idx; ///< index in sf_offsets for the scale factor reference block
152 float* coeffs; ///< pointer to the subframe decode buffer
153 DECLARE_ALIGNED(16, float, out)[WMAPRO_BLOCK_MAX_SIZE + WMAPRO_BLOCK_MAX_SIZE / 2]; ///< output buffer
154} WMAProChannelCtx;
155
156/**
157 * @brief channel group for channel transformations
158 */
159typedef struct {
160 uint8_t num_channels; ///< number of channels in the group
161 int8_t transform; ///< transform on / off
162 int8_t transform_band[MAX_BANDS]; ///< controls if the transform is enabled for a certain band
163 float decorrelation_matrix[WMAPRO_MAX_CHANNELS*WMAPRO_MAX_CHANNELS];
164 float* channel_data[WMAPRO_MAX_CHANNELS]; ///< transformation coefficients
165} WMAProChannelGrp;
166
167/**
168 * @brief main decoder context
169 */
170typedef struct WMAProDecodeCtx {
171 /* generic decoder variables */
172 AVCodecContext* avctx; ///< codec context for av_log
173 DSPContext dsp; ///< accelerated DSP functions
174 uint8_t frame_data[MAX_FRAMESIZE +
175 FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data
176 PutBitContext pb; ///< context for filling the frame_data buffer
177 FFTContext mdct_ctx[WMAPRO_BLOCK_SIZES]; ///< MDCT context per block size
178 DECLARE_ALIGNED(16, float, tmp)[WMAPRO_BLOCK_MAX_SIZE]; ///< IMDCT output buffer
179 float* windows[WMAPRO_BLOCK_SIZES]; ///< windows for the different block sizes
180
181 /* frame size dependent frame information (set during initialization) */
182 uint32_t decode_flags; ///< used compression features
183 uint8_t len_prefix; ///< frame is prefixed with its length
184 uint8_t dynamic_range_compression; ///< frame contains DRC data
185 uint8_t bits_per_sample; ///< integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1.0])
186 uint16_t samples_per_frame; ///< number of samples to output
187 uint16_t log2_frame_size;
188 int8_t num_channels; ///< number of channels in the stream (same as AVCodecContext.num_channels)
189 int8_t lfe_channel; ///< lfe channel index
190 uint8_t max_num_subframes;
191 uint8_t subframe_len_bits; ///< number of bits used for the subframe length
192 uint8_t max_subframe_len_bit; ///< flag indicating that the subframe is of maximum size when the first subframe length bit is 1
193 uint16_t min_samples_per_subframe;
194 int8_t num_sfb[WMAPRO_BLOCK_SIZES]; ///< scale factor bands per block size
195 int16_t sfb_offsets[WMAPRO_BLOCK_SIZES][MAX_BANDS]; ///< scale factor band offsets (multiples of 4)
196 int8_t sf_offsets[WMAPRO_BLOCK_SIZES][WMAPRO_BLOCK_SIZES][MAX_BANDS]; ///< scale factor resample matrix
197 int16_t subwoofer_cutoffs[WMAPRO_BLOCK_SIZES]; ///< subwoofer cutoff values
198
199 /* packet decode state */
200 GetBitContext pgb; ///< bitstream reader context for the packet
201 uint8_t packet_offset; ///< frame offset in the packet
202 uint8_t packet_sequence_number; ///< current packet number
203 int num_saved_bits; ///< saved number of bits
204 int frame_offset; ///< frame offset in the bit reservoir
205 int subframe_offset; ///< subframe offset in the bit reservoir
206 uint8_t packet_loss; ///< set in case of bitstream error
207 uint8_t packet_done; ///< set when a packet is fully decoded
208
209 /* frame decode state */
210 uint32_t frame_num; ///< current frame number (not used for decoding)
211 GetBitContext gb; ///< bitstream reader context
212 int buf_bit_size; ///< buffer size in bits
213 float* samples; ///< current samplebuffer pointer
214 float* samples_end; ///< maximum samplebuffer pointer
215 uint8_t drc_gain; ///< gain for the DRC tool
216 int8_t skip_frame; ///< skip output step
217 int8_t parsed_all_subframes; ///< all subframes decoded?
218
219 /* subframe/block decode state */
220 int16_t subframe_len; ///< current subframe length
221 int8_t channels_for_cur_subframe; ///< number of channels that contain the subframe
222 int8_t channel_indexes_for_cur_subframe[WMAPRO_MAX_CHANNELS];
223 int8_t num_bands; ///< number of scale factor bands
224 int16_t* cur_sfb_offsets; ///< sfb offsets for the current block
225 uint8_t table_idx; ///< index for the num_sfb, sfb_offsets, sf_offsets and subwoofer_cutoffs tables
226 int8_t esc_len; ///< length of escaped coefficients
227
228 uint8_t num_chgroups; ///< number of channel groups
229 WMAProChannelGrp chgroup[WMAPRO_MAX_CHANNELS]; ///< channel group information
230
231 WMAProChannelCtx channel[WMAPRO_MAX_CHANNELS]; ///< per channel data
232} WMAProDecodeCtx;
233
234
235/**
236 *@brief helper function to print the most important members of the context
237 *@param s context
238 */
239static void av_cold dump_context(WMAProDecodeCtx *s)
240{
241#define PRINT(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b);
242#define PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %x\n", a, b);
243
244 PRINT("ed sample bit depth", s->bits_per_sample);
245 PRINT_HEX("ed decode flags", s->decode_flags);
246 PRINT("samples per frame", s->samples_per_frame);
247 PRINT("log2 frame size", s->log2_frame_size);
248 PRINT("max num subframes", s->max_num_subframes);
249 PRINT("len prefix", s->len_prefix);
250 PRINT("num channels", s->num_channels);
251}
252
253/**
254 *@brief Uninitialize the decoder and free all resources.
255 *@param avctx codec context
256 *@return 0 on success, < 0 otherwise
257 */
258static av_cold int decode_end(AVCodecContext *avctx)
259{
260 WMAProDecodeCtx *s = avctx->priv_data;
261 int i;
262
263 for (i = 0; i < WMAPRO_BLOCK_SIZES; i++)
264 ff_mdct_end(&s->mdct_ctx[i]);
265
266 return 0;
267}
268
269/**
270 *@brief Initialize the decoder.
271 *@param avctx codec context
272 *@return 0 on success, -1 otherwise
273 */
274static av_cold int decode_init(AVCodecContext *avctx)
275{
276 WMAProDecodeCtx *s = avctx->priv_data;
277 uint8_t *edata_ptr = avctx->extradata;
278 unsigned int channel_mask;
279 int i;
280 int log2_max_num_subframes;
281 int num_possible_block_sizes;
282
283 s->avctx = avctx;
284 dsputil_init(&s->dsp, avctx);
285 init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
286
287 avctx->sample_fmt = SAMPLE_FMT_FLT;
288
289 if (avctx->extradata_size >= 18) {
290 s->decode_flags = AV_RL16(edata_ptr+14);
291 channel_mask = AV_RL32(edata_ptr+2);
292 s->bits_per_sample = AV_RL16(edata_ptr);
293 /** dump the extradata */
294 for (i = 0; i < avctx->extradata_size; i++)
295 dprintf(avctx, "[%x] ", avctx->extradata[i]);
296 dprintf(avctx, "\n");
297
298 } else {
299 av_log_ask_for_sample(avctx, "Unknown extradata size\n");
300 return AVERROR_INVALIDDATA;
301 }
302
303 /** generic init */
304 s->log2_frame_size = av_log2(avctx->block_align) + 4;
305
306 /** frame info */
307 s->skip_frame = 1; /** skip first frame */
308 s->packet_loss = 1;
309 s->len_prefix = (s->decode_flags & 0x40);
310
311 if (!s->len_prefix) {
312 av_log_ask_for_sample(avctx, "no length prefix\n");
313 return AVERROR_INVALIDDATA;
314 }
315
316 /** get frame len */
317 s->samples_per_frame = 1 << ff_wma_get_frame_len_bits(avctx->sample_rate,
318 3, s->decode_flags);
319
320 /** init previous block len */
321 for (i = 0; i < avctx->channels; i++)
322 s->channel[i].prev_block_len = s->samples_per_frame;
323
324 /** subframe info */
325 log2_max_num_subframes = ((s->decode_flags & 0x38) >> 3);
326 s->max_num_subframes = 1 << log2_max_num_subframes;
327 if (s->max_num_subframes == 16)
328 s->max_subframe_len_bit = 1;
329 s->subframe_len_bits = av_log2(log2_max_num_subframes) + 1;
330
331 num_possible_block_sizes = log2_max_num_subframes + 1;
332 s->min_samples_per_subframe = s->samples_per_frame / s->max_num_subframes;
333 s->dynamic_range_compression = (s->decode_flags & 0x80);
334
335 if (s->max_num_subframes > MAX_SUBFRAMES) {
336 av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %i\n",
337 s->max_num_subframes);
338 return AVERROR_INVALIDDATA;
339 }
340
341 s->num_channels = avctx->channels;
342
343 /** extract lfe channel position */
344 s->lfe_channel = -1;
345
346 if (channel_mask & 8) {
347 unsigned int mask;
348 for (mask = 1; mask < 16; mask <<= 1) {
349 if (channel_mask & mask)
350 ++s->lfe_channel;
351 }
352 }
353
354 if (s->num_channels < 0) {
355 av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n", s->num_channels);
356 return AVERROR_INVALIDDATA;
357 } else if (s->num_channels > WMAPRO_MAX_CHANNELS) {
358 av_log_ask_for_sample(avctx, "unsupported number of channels\n");
359 return AVERROR_PATCHWELCOME;
360 }
361
362 INIT_VLC_STATIC(&sf_vlc, SCALEVLCBITS, HUFF_SCALE_SIZE,
363 scale_huffbits, 1, 1,
364 scale_huffcodes, 2, 2, 616);
365
366 INIT_VLC_STATIC(&sf_rl_vlc, VLCBITS, HUFF_SCALE_RL_SIZE,
367 scale_rl_huffbits, 1, 1,
368 scale_rl_huffcodes, 4, 4, 1406);
369
370 INIT_VLC_STATIC(&coef_vlc[0], VLCBITS, HUFF_COEF0_SIZE,
371 coef0_huffbits, 1, 1,
372 coef0_huffcodes, 4, 4, 2108);
373
374 INIT_VLC_STATIC(&coef_vlc[1], VLCBITS, HUFF_COEF1_SIZE,
375 coef1_huffbits, 1, 1,
376 coef1_huffcodes, 4, 4, 3912);
377
378 INIT_VLC_STATIC(&vec4_vlc, VLCBITS, HUFF_VEC4_SIZE,
379 vec4_huffbits, 1, 1,
380 vec4_huffcodes, 2, 2, 604);
381
382 INIT_VLC_STATIC(&vec2_vlc, VLCBITS, HUFF_VEC2_SIZE,
383 vec2_huffbits, 1, 1,
384 vec2_huffcodes, 2, 2, 562);
385
386 INIT_VLC_STATIC(&vec1_vlc, VLCBITS, HUFF_VEC1_SIZE,
387 vec1_huffbits, 1, 1,
388 vec1_huffcodes, 2, 2, 562);
389
390 /** calculate number of scale factor bands and their offsets
391 for every possible block size */
392 for (i = 0; i < num_possible_block_sizes; i++) {
393 int subframe_len = s->samples_per_frame >> i;
394 int x;
395 int band = 1;
396
397 s->sfb_offsets[i][0] = 0;
398
399 for (x = 0; x < MAX_BANDS-1 && s->sfb_offsets[i][band - 1] < subframe_len; x++) {
400 int offset = (subframe_len * 2 * critical_freq[x])
401 / s->avctx->sample_rate + 2;
402 offset &= ~3;
403 if (offset > s->sfb_offsets[i][band - 1])
404 s->sfb_offsets[i][band++] = offset;
405 }
406 s->sfb_offsets[i][band - 1] = subframe_len;
407 s->num_sfb[i] = band - 1;
408 }
409
410
411 /** Scale factors can be shared between blocks of different size
412 as every block has a different scale factor band layout.
413 The matrix sf_offsets is needed to find the correct scale factor.
414 */
415
416 for (i = 0; i < num_possible_block_sizes; i++) {
417 int b;
418 for (b = 0; b < s->num_sfb[i]; b++) {
419 int x;
420 int offset = ((s->sfb_offsets[i][b]
421 + s->sfb_offsets[i][b + 1] - 1) << i) >> 1;
422 for (x = 0; x < num_possible_block_sizes; x++) {
423 int v = 0;
424 while (s->sfb_offsets[x][v + 1] << x < offset)
425 ++v;
426 s->sf_offsets[i][x][b] = v;
427 }
428 }
429 }
430
431 /** init MDCT, FIXME: only init needed sizes */
432 for (i = 0; i < WMAPRO_BLOCK_SIZES; i++)
433 ff_mdct_init(&s->mdct_ctx[i], BLOCK_MIN_BITS+1+i, 1,
434 1.0 / (1 << (BLOCK_MIN_BITS + i - 1))
435 / (1 << (s->bits_per_sample - 1)));
436
437 /** init MDCT windows: simple sinus window */
438 for (i = 0; i < WMAPRO_BLOCK_SIZES; i++) {
439 const int win_idx = WMAPRO_BLOCK_MAX_BITS - i;
440 ff_init_ff_sine_windows(win_idx);
441 s->windows[WMAPRO_BLOCK_SIZES - i - 1] = ff_sine_windows[win_idx];
442 }
443
444 /** calculate subwoofer cutoff values */
445 for (i = 0; i < num_possible_block_sizes; i++) {
446 int block_size = s->samples_per_frame >> i;
447 int cutoff = (440*block_size + 3 * (s->avctx->sample_rate >> 1) - 1)
448 / s->avctx->sample_rate;
449 s->subwoofer_cutoffs[i] = av_clip(cutoff, 4, block_size);
450 }
451
452 /** calculate sine values for the decorrelation matrix */
453 for (i = 0; i < 33; i++)
454 sin64[i] = sin(i*M_PI / 64.0);
455#if 0
456 if (avctx->debug & FF_DEBUG_BITSTREAM)
457 dump_context(s);
458#endif
459
460 avctx->channel_layout = channel_mask;
461 return 0;
462}
463
464/**
465 *@brief Decode the subframe length.
466 *@param s context
467 *@param offset sample offset in the frame
468 *@return decoded subframe length on success, < 0 in case of an error
469 */
470static int decode_subframe_length(WMAProDecodeCtx *s, int offset)
471{
472 int frame_len_shift = 0;
473 int subframe_len;
474
475 /** no need to read from the bitstream when only one length is possible */
476 if (offset == s->samples_per_frame - s->min_samples_per_subframe)
477 return s->min_samples_per_subframe;
478
479 /** 1 bit indicates if the subframe is of maximum length */
480 if (s->max_subframe_len_bit) {
481 if (get_bits1(&s->gb))
482 frame_len_shift = 1 + get_bits(&s->gb, s->subframe_len_bits-1);
483 } else
484 frame_len_shift = get_bits(&s->gb, s->subframe_len_bits);
485
486 subframe_len = s->samples_per_frame >> frame_len_shift;
487
488 /** sanity check the length */
489 if (subframe_len < s->min_samples_per_subframe ||
490 subframe_len > s->samples_per_frame) {
491 av_log(s->avctx, AV_LOG_ERROR, "broken frame: subframe_len %i\n",
492 subframe_len);
493 return AVERROR_INVALIDDATA;
494 }
495 return subframe_len;
496}
497
498/**
499 *@brief Decode how the data in the frame is split into subframes.
500 * Every WMA frame contains the encoded data for a fixed number of
501 * samples per channel. The data for every channel might be split
502 * into several subframes. This function will reconstruct the list of
503 * subframes for every channel.
504 *
505 * If the subframes are not evenly split, the algorithm estimates the
506 * channels with the lowest number of total samples.
507 * Afterwards, for each of these channels a bit is read from the
508 * bitstream that indicates if the channel contains a subframe with the
509 * next subframe size that is going to be read from the bitstream or not.
510 * If a channel contains such a subframe, the subframe size gets added to
511 * the channel's subframe list.
512 * The algorithm repeats these steps until the frame is properly divided
513 * between the individual channels.
514 *
515 *@param s context
516 *@return 0 on success, < 0 in case of an error
517 */
518static int decode_tilehdr(WMAProDecodeCtx *s)
519{
520 uint16_t num_samples[WMAPRO_MAX_CHANNELS]; /** sum of samples for all currently known subframes of a channel */
521 uint8_t contains_subframe[WMAPRO_MAX_CHANNELS]; /** flag indicating if a channel contains the current subframe */
522 int channels_for_cur_subframe = s->num_channels; /** number of channels that contain the current subframe */
523 int fixed_channel_layout = 0; /** flag indicating that all channels use the same subframe offsets and sizes */
524 int min_channel_len = 0; /** smallest sum of samples (channels with this length will be processed first) */
525 int c;
526
527 /* Should never consume more than 3073 bits (256 iterations for the
528 * while loop when always the minimum amount of 128 samples is substracted
529 * from missing samples in the 8 channel case).
530 * 1 + BLOCK_MAX_SIZE * MAX_CHANNELS / BLOCK_MIN_SIZE * (MAX_CHANNELS + 4)
531 */
532
533 /** reset tiling information */
534 for (c = 0; c < s->num_channels; c++)
535 s->channel[c].num_subframes = 0;
536
537 memset(num_samples, 0, sizeof(num_samples));
538
539 if (s->max_num_subframes == 1 || get_bits1(&s->gb))
540 fixed_channel_layout = 1;
541
542 /** loop until the frame data is split between the subframes */
543 do {
544 int subframe_len;
545
546 /** check which channels contain the subframe */
547 for (c = 0; c < s->num_channels; c++) {
548 if (num_samples[c] == min_channel_len) {
549 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
550 (min_channel_len == s->samples_per_frame - s->min_samples_per_subframe))
551 contains_subframe[c] = 1;
552 else
553 contains_subframe[c] = get_bits1(&s->gb);
554 } else
555 contains_subframe[c] = 0;
556 }
557
558 /** get subframe length, subframe_len == 0 is not allowed */
559 if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0)
560 return AVERROR_INVALIDDATA;
561
562 /** add subframes to the individual channels and find new min_channel_len */
563 min_channel_len += subframe_len;
564 for (c = 0; c < s->num_channels; c++) {
565 WMAProChannelCtx* chan = &s->channel[c];
566
567 if (contains_subframe[c]) {
568 if (chan->num_subframes >= MAX_SUBFRAMES) {
569 av_log(s->avctx, AV_LOG_ERROR,
570 "broken frame: num subframes > 31\n");
571 return AVERROR_INVALIDDATA;
572 }
573 chan->subframe_len[chan->num_subframes] = subframe_len;
574 num_samples[c] += subframe_len;
575 ++chan->num_subframes;
576 if (num_samples[c] > s->samples_per_frame) {
577 av_log(s->avctx, AV_LOG_ERROR, "broken frame: "
578 "channel len > samples_per_frame\n");
579 return AVERROR_INVALIDDATA;
580 }
581 } else if (num_samples[c] <= min_channel_len) {
582 if (num_samples[c] < min_channel_len) {
583 channels_for_cur_subframe = 0;
584 min_channel_len = num_samples[c];
585 }
586 ++channels_for_cur_subframe;
587 }
588 }
589 } while (min_channel_len < s->samples_per_frame);
590
591 for (c = 0; c < s->num_channels; c++) {
592 int i;
593 int offset = 0;
594 for (i = 0; i < s->channel[c].num_subframes; i++) {
595 dprintf(s->avctx, "frame[%i] channel[%i] subframe[%i]"
596 " len %i\n", s->frame_num, c, i,
597 s->channel[c].subframe_len[i]);
598 s->channel[c].subframe_offset[i] = offset;
599 offset += s->channel[c].subframe_len[i];
600 }
601 }
602
603 return 0;
604}
605
606/**
607 *@brief Calculate a decorrelation matrix from the bitstream parameters.
608 *@param s codec context
609 *@param chgroup channel group for which the matrix needs to be calculated
610 */
611static void decode_decorrelation_matrix(WMAProDecodeCtx *s,
612 WMAProChannelGrp *chgroup)
613{
614 int i;
615 int offset = 0;
616 int8_t rotation_offset[WMAPRO_MAX_CHANNELS * WMAPRO_MAX_CHANNELS];
617 memset(chgroup->decorrelation_matrix, 0, s->num_channels *
618 s->num_channels * sizeof(*chgroup->decorrelation_matrix));
619
620 for (i = 0; i < chgroup->num_channels * (chgroup->num_channels - 1) >> 1; i++)
621 rotation_offset[i] = get_bits(&s->gb, 6);
622
623 for (i = 0; i < chgroup->num_channels; i++)
624 chgroup->decorrelation_matrix[chgroup->num_channels * i + i] =
625 get_bits1(&s->gb) ? 1.0 : -1.0;
626
627 for (i = 1; i < chgroup->num_channels; i++) {
628 int x;
629 for (x = 0; x < i; x++) {
630 int y;
631 for (y = 0; y < i + 1; y++) {
632 float v1 = chgroup->decorrelation_matrix[x * chgroup->num_channels + y];
633 float v2 = chgroup->decorrelation_matrix[i * chgroup->num_channels + y];
634 int n = rotation_offset[offset + x];
635 float sinv;
636 float cosv;
637
638 if (n < 32) {
639 sinv = sin64[n];
640 cosv = sin64[32 - n];
641 } else {
642 sinv = sin64[64 - n];
643 cosv = -sin64[n - 32];
644 }
645
646 chgroup->decorrelation_matrix[y + x * chgroup->num_channels] =
647 (v1 * sinv) - (v2 * cosv);
648 chgroup->decorrelation_matrix[y + i * chgroup->num_channels] =
649 (v1 * cosv) + (v2 * sinv);
650 }
651 }
652 offset += i;
653 }
654}
655
656/**
657 *@brief Decode channel transformation parameters
658 *@param s codec context
659 *@return 0 in case of success, < 0 in case of bitstream errors
660 */
661static int decode_channel_transform(WMAProDecodeCtx* s)
662{
663 int i;
664 /* should never consume more than 1921 bits for the 8 channel case
665 * 1 + MAX_CHANNELS * (MAX_CHANNELS + 2 + 3 * MAX_CHANNELS * MAX_CHANNELS
666 * + MAX_CHANNELS + MAX_BANDS + 1)
667 */
668
669 /** in the one channel case channel transforms are pointless */
670 s->num_chgroups = 0;
671 if (s->num_channels > 1) {
672 int remaining_channels = s->channels_for_cur_subframe;
673
674 if (get_bits1(&s->gb)) {
675 av_log_ask_for_sample(s->avctx,
676 "unsupported channel transform bit\n");
677 return AVERROR_INVALIDDATA;
678 }
679
680 for (s->num_chgroups = 0; remaining_channels &&
681 s->num_chgroups < s->channels_for_cur_subframe; s->num_chgroups++) {
682 WMAProChannelGrp* chgroup = &s->chgroup[s->num_chgroups];
683 float** channel_data = chgroup->channel_data;
684 chgroup->num_channels = 0;
685 chgroup->transform = 0;
686
687 /** decode channel mask */
688 if (remaining_channels > 2) {
689 for (i = 0; i < s->channels_for_cur_subframe; i++) {
690 int channel_idx = s->channel_indexes_for_cur_subframe[i];
691 if (!s->channel[channel_idx].grouped
692 && get_bits1(&s->gb)) {
693 ++chgroup->num_channels;
694 s->channel[channel_idx].grouped = 1;
695 *channel_data++ = s->channel[channel_idx].coeffs;
696 }
697 }
698 } else {
699 chgroup->num_channels = remaining_channels;
700 for (i = 0; i < s->channels_for_cur_subframe; i++) {
701 int channel_idx = s->channel_indexes_for_cur_subframe[i];
702 if (!s->channel[channel_idx].grouped)
703 *channel_data++ = s->channel[channel_idx].coeffs;
704 s->channel[channel_idx].grouped = 1;
705 }
706 }
707
708 /** decode transform type */
709 if (chgroup->num_channels == 2) {
710 if (get_bits1(&s->gb)) {
711 if (get_bits1(&s->gb)) {
712 av_log_ask_for_sample(s->avctx,
713 "unsupported channel transform type\n");
714 }
715 } else {
716 chgroup->transform = 1;
717 if (s->num_channels == 2) {
718 chgroup->decorrelation_matrix[0] = 1.0;
719 chgroup->decorrelation_matrix[1] = -1.0;
720 chgroup->decorrelation_matrix[2] = 1.0;
721 chgroup->decorrelation_matrix[3] = 1.0;
722 } else {
723 /** cos(pi/4) */
724 chgroup->decorrelation_matrix[0] = 0.70703125;
725 chgroup->decorrelation_matrix[1] = -0.70703125;
726 chgroup->decorrelation_matrix[2] = 0.70703125;
727 chgroup->decorrelation_matrix[3] = 0.70703125;
728 }
729 }
730 } else if (chgroup->num_channels > 2) {
731 if (get_bits1(&s->gb)) {
732 chgroup->transform = 1;
733 if (get_bits1(&s->gb)) {
734 decode_decorrelation_matrix(s, chgroup);
735 } else {
736 /** FIXME: more than 6 coupled channels not supported */
737 if (chgroup->num_channels > 6) {
738 av_log_ask_for_sample(s->avctx,
739 "coupled channels > 6\n");
740 } else {
741 memcpy(chgroup->decorrelation_matrix,
742 default_decorrelation[chgroup->num_channels],
743 chgroup->num_channels * chgroup->num_channels *
744 sizeof(*chgroup->decorrelation_matrix));
745 }
746 }
747 }
748 }
749
750 /** decode transform on / off */
751 if (chgroup->transform) {
752 if (!get_bits1(&s->gb)) {
753 int i;
754 /** transform can be enabled for individual bands */
755 for (i = 0; i < s->num_bands; i++) {
756 chgroup->transform_band[i] = get_bits1(&s->gb);
757 }
758 } else {
759 memset(chgroup->transform_band, 1, s->num_bands);
760 }
761 }
762 remaining_channels -= chgroup->num_channels;
763 }
764 }
765 return 0;
766}
767
768/**
769 *@brief Extract the coefficients from the bitstream.
770 *@param s codec context
771 *@param c current channel number
772 *@return 0 on success, < 0 in case of bitstream errors
773 */
774static int decode_coeffs(WMAProDecodeCtx *s, int c)
775{
776 /* Integers 0..15 as single-precision floats. The table saves a
777 costly int to float conversion, and storing the values as
778 integers allows fast sign-flipping. */
779 static const int fval_tab[16] = {
780 0x00000000, 0x3f800000, 0x40000000, 0x40400000,
781 0x40800000, 0x40a00000, 0x40c00000, 0x40e00000,
782 0x41000000, 0x41100000, 0x41200000, 0x41300000,
783 0x41400000, 0x41500000, 0x41600000, 0x41700000,
784 };
785 int vlctable;
786 VLC* vlc;
787 WMAProChannelCtx* ci = &s->channel[c];
788 int rl_mode = 0;
789 int cur_coeff = 0;
790 int num_zeros = 0;
791 const uint16_t* run;
792 const float* level;
793
794 dprintf(s->avctx, "decode coefficients for channel %i\n", c);
795
796 vlctable = get_bits1(&s->gb);
797 vlc = &coef_vlc[vlctable];
798
799 if (vlctable) {
800 run = coef1_run;
801 level = coef1_level;
802 } else {
803 run = coef0_run;
804 level = coef0_level;
805 }
806
807 /** decode vector coefficients (consumes up to 167 bits per iteration for
808 4 vector coded large values) */
809 while (!rl_mode && cur_coeff + 3 < s->subframe_len) {
810 int vals[4];
811 int i;
812 unsigned int idx;
813
814 idx = get_vlc2(&s->gb, vec4_vlc.table, VLCBITS, VEC4MAXDEPTH);
815
816 if (idx == HUFF_VEC4_SIZE - 1) {
817 for (i = 0; i < 4; i += 2) {
818 idx = get_vlc2(&s->gb, vec2_vlc.table, VLCBITS, VEC2MAXDEPTH);
819 if (idx == HUFF_VEC2_SIZE - 1) {
820 int v0, v1;
821 v0 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);
822 if (v0 == HUFF_VEC1_SIZE - 1)
823 v0 += ff_wma_get_large_val(&s->gb);
824 v1 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);
825 if (v1 == HUFF_VEC1_SIZE - 1)
826 v1 += ff_wma_get_large_val(&s->gb);
827 ((float*)vals)[i ] = v0;
828 ((float*)vals)[i+1] = v1;
829 } else {
830 vals[i] = fval_tab[symbol_to_vec2[idx] >> 4 ];
831 vals[i+1] = fval_tab[symbol_to_vec2[idx] & 0xF];
832 }
833 }
834 } else {
835 vals[0] = fval_tab[ symbol_to_vec4[idx] >> 12 ];
836 vals[1] = fval_tab[(symbol_to_vec4[idx] >> 8) & 0xF];
837 vals[2] = fval_tab[(symbol_to_vec4[idx] >> 4) & 0xF];
838 vals[3] = fval_tab[ symbol_to_vec4[idx] & 0xF];
839 }
840
841 /** decode sign */
842 for (i = 0; i < 4; i++) {
843 if (vals[i]) {
844 int sign = get_bits1(&s->gb) - 1;
845 *(uint32_t*)&ci->coeffs[cur_coeff] = vals[i] ^ sign<<31;
846 num_zeros = 0;
847 } else {
848 ci->coeffs[cur_coeff] = 0;
849 /** switch to run level mode when subframe_len / 128 zeros
850 were found in a row */
851 rl_mode |= (++num_zeros > s->subframe_len >> 8);
852 }
853 ++cur_coeff;
854 }
855 }
856
857 /** decode run level coded coefficients */
858 if (rl_mode) {
859 memset(&ci->coeffs[cur_coeff], 0,
860 sizeof(*ci->coeffs) * (s->subframe_len - cur_coeff));
861 if (ff_wma_run_level_decode(s->avctx, &s->gb, vlc,
862 level, run, 1, ci->coeffs,
863 cur_coeff, s->subframe_len,
864 s->subframe_len, s->esc_len, 0))
865 return AVERROR_INVALIDDATA;
866 }
867
868 return 0;
869}
870
871/**
872 *@brief Extract scale factors from the bitstream.
873 *@param s codec context
874 *@return 0 on success, < 0 in case of bitstream errors
875 */
876static int decode_scale_factors(WMAProDecodeCtx* s)
877{
878 int i;
879
880 /** should never consume more than 5344 bits
881 * MAX_CHANNELS * (1 + MAX_BANDS * 23)
882 */
883
884 for (i = 0; i < s->channels_for_cur_subframe; i++) {
885 int c = s->channel_indexes_for_cur_subframe[i];
886 int* sf;
887 int* sf_end;
888 s->channel[c].scale_factors = s->channel[c].saved_scale_factors[!s->channel[c].scale_factor_idx];
889 sf_end = s->channel[c].scale_factors + s->num_bands;
890
891 /** resample scale factors for the new block size
892 * as the scale factors might need to be resampled several times
893 * before some new values are transmitted, a backup of the last
894 * transmitted scale factors is kept in saved_scale_factors
895 */
896 if (s->channel[c].reuse_sf) {
897 const int8_t* sf_offsets = s->sf_offsets[s->table_idx][s->channel[c].table_idx];
898 int b;
899 for (b = 0; b < s->num_bands; b++)
900 s->channel[c].scale_factors[b] =
901 s->channel[c].saved_scale_factors[s->channel[c].scale_factor_idx][*sf_offsets++];
902 }
903
904 if (!s->channel[c].cur_subframe || get_bits1(&s->gb)) {
905
906 if (!s->channel[c].reuse_sf) {
907 int val;
908 /** decode DPCM coded scale factors */
909 s->channel[c].scale_factor_step = get_bits(&s->gb, 2) + 1;
910 val = 45 / s->channel[c].scale_factor_step;
911 for (sf = s->channel[c].scale_factors; sf < sf_end; sf++) {
912 val += get_vlc2(&s->gb, sf_vlc.table, SCALEVLCBITS, SCALEMAXDEPTH) - 60;
913 *sf = val;
914 }
915 } else {
916 int i;
917 /** run level decode differences to the resampled factors */
918 for (i = 0; i < s->num_bands; i++) {
919 int idx;
920 int skip;
921 int val;
922 int sign;
923
924 idx = get_vlc2(&s->gb, sf_rl_vlc.table, VLCBITS, SCALERLMAXDEPTH);
925
926 if (!idx) {
927 uint32_t code = get_bits(&s->gb, 14);
928 val = code >> 6;
929 sign = (code & 1) - 1;
930 skip = (code & 0x3f) >> 1;
931 } else if (idx == 1) {
932 break;
933 } else {
934 skip = scale_rl_run[idx];
935 val = scale_rl_level[idx];
936 sign = get_bits1(&s->gb)-1;
937 }
938
939 i += skip;
940 if (i >= s->num_bands) {
941 av_log(s->avctx, AV_LOG_ERROR,
942 "invalid scale factor coding\n");
943 return AVERROR_INVALIDDATA;
944 }
945 s->channel[c].scale_factors[i] += (val ^ sign) - sign;
946 }
947 }
948 /** swap buffers */
949 s->channel[c].scale_factor_idx = !s->channel[c].scale_factor_idx;
950 s->channel[c].table_idx = s->table_idx;
951 s->channel[c].reuse_sf = 1;
952 }
953
954 /** calculate new scale factor maximum */
955 s->channel[c].max_scale_factor = s->channel[c].scale_factors[0];
956 for (sf = s->channel[c].scale_factors + 1; sf < sf_end; sf++) {
957 s->channel[c].max_scale_factor =
958 FFMAX(s->channel[c].max_scale_factor, *sf);
959 }
960
961 }
962 return 0;
963}
964
965/**
966 *@brief Reconstruct the individual channel data.
967 *@param s codec context
968 */
969static void inverse_channel_transform(WMAProDecodeCtx *s)
970{
971 int i;
972
973 for (i = 0; i < s->num_chgroups; i++) {
974 if (s->chgroup[i].transform) {
975 float data[WMAPRO_MAX_CHANNELS];
976 const int num_channels = s->chgroup[i].num_channels;
977 float** ch_data = s->chgroup[i].channel_data;
978 float** ch_end = ch_data + num_channels;
979 const int8_t* tb = s->chgroup[i].transform_band;
980 int16_t* sfb;
981
982 /** multichannel decorrelation */
983 for (sfb = s->cur_sfb_offsets;
984 sfb < s->cur_sfb_offsets + s->num_bands; sfb++) {
985 int y;
986 if (*tb++ == 1) {
987 /** multiply values with the decorrelation_matrix */
988 for (y = sfb[0]; y < FFMIN(sfb[1], s->subframe_len); y++) {
989 const float* mat = s->chgroup[i].decorrelation_matrix;
990 const float* data_end = data + num_channels;
991 float* data_ptr = data;
992 float** ch;
993
994 for (ch = ch_data; ch < ch_end; ch++)
995 *data_ptr++ = (*ch)[y];
996
997 for (ch = ch_data; ch < ch_end; ch++) {
998 float sum = 0;
999 data_ptr = data;
1000 while (data_ptr < data_end)
1001 sum += *data_ptr++ * *mat++;
1002
1003 (*ch)[y] = sum;
1004 }
1005 }
1006 } else if (s->num_channels == 2) {
1007 int len = FFMIN(sfb[1], s->subframe_len) - sfb[0];
1008 s->dsp.vector_fmul_scalar(ch_data[0] + sfb[0],
1009 ch_data[0] + sfb[0],
1010 181.0 / 128, len);
1011 s->dsp.vector_fmul_scalar(ch_data[1] + sfb[0],
1012 ch_data[1] + sfb[0],
1013 181.0 / 128, len);
1014 }
1015 }
1016 }
1017 }
1018}
1019
1020/**
1021 *@brief Apply sine window and reconstruct the output buffer.
1022 *@param s codec context
1023 */
1024static void wmapro_window(WMAProDecodeCtx *s)
1025{
1026 int i;
1027 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1028 int c = s->channel_indexes_for_cur_subframe[i];
1029 float* window;
1030 int winlen = s->channel[c].prev_block_len;
1031 float* start = s->channel[c].coeffs - (winlen >> 1);
1032
1033 if (s->subframe_len < winlen) {
1034 start += (winlen - s->subframe_len) >> 1;
1035 winlen = s->subframe_len;
1036 }
1037
1038 window = s->windows[av_log2(winlen) - BLOCK_MIN_BITS];
1039
1040 winlen >>= 1;
1041
1042 s->dsp.vector_fmul_window(start, start, start + winlen,
1043 window, 0, winlen);
1044
1045 s->channel[c].prev_block_len = s->subframe_len;
1046 }
1047}
1048
1049/**
1050 *@brief Decode a single subframe (block).
1051 *@param s codec context
1052 *@return 0 on success, < 0 when decoding failed
1053 */
1054static int decode_subframe(WMAProDecodeCtx *s)
1055{
1056 int offset = s->samples_per_frame;
1057 int subframe_len = s->samples_per_frame;
1058 int i;
1059 int total_samples = s->samples_per_frame * s->num_channels;
1060 int transmit_coeffs = 0;
1061 int cur_subwoofer_cutoff;
1062
1063 s->subframe_offset = get_bits_count(&s->gb);
1064
1065 /** reset channel context and find the next block offset and size
1066 == the next block of the channel with the smallest number of
1067 decoded samples
1068 */
1069 for (i = 0; i < s->num_channels; i++) {
1070 s->channel[i].grouped = 0;
1071 if (offset > s->channel[i].decoded_samples) {
1072 offset = s->channel[i].decoded_samples;
1073 subframe_len =
1074 s->channel[i].subframe_len[s->channel[i].cur_subframe];
1075 }
1076 }
1077
1078 dprintf(s->avctx,
1079 "processing subframe with offset %i len %i\n", offset, subframe_len);
1080
1081 /** get a list of all channels that contain the estimated block */
1082 s->channels_for_cur_subframe = 0;
1083 for (i = 0; i < s->num_channels; i++) {
1084 const int cur_subframe = s->channel[i].cur_subframe;
1085 /** substract already processed samples */
1086 total_samples -= s->channel[i].decoded_samples;
1087
1088 /** and count if there are multiple subframes that match our profile */
1089 if (offset == s->channel[i].decoded_samples &&
1090 subframe_len == s->channel[i].subframe_len[cur_subframe]) {
1091 total_samples -= s->channel[i].subframe_len[cur_subframe];
1092 s->channel[i].decoded_samples +=
1093 s->channel[i].subframe_len[cur_subframe];
1094 s->channel_indexes_for_cur_subframe[s->channels_for_cur_subframe] = i;
1095 ++s->channels_for_cur_subframe;
1096 }
1097 }
1098
1099 /** check if the frame will be complete after processing the
1100 estimated block */
1101 if (!total_samples)
1102 s->parsed_all_subframes = 1;
1103
1104
1105 dprintf(s->avctx, "subframe is part of %i channels\n",
1106 s->channels_for_cur_subframe);
1107
1108 /** calculate number of scale factor bands and their offsets */
1109 s->table_idx = av_log2(s->samples_per_frame/subframe_len);
1110 s->num_bands = s->num_sfb[s->table_idx];
1111 s->cur_sfb_offsets = s->sfb_offsets[s->table_idx];
1112 cur_subwoofer_cutoff = s->subwoofer_cutoffs[s->table_idx];
1113
1114 /** configure the decoder for the current subframe */
1115 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1116 int c = s->channel_indexes_for_cur_subframe[i];
1117
1118 s->channel[c].coeffs = &s->channel[c].out[(s->samples_per_frame >> 1)
1119 + offset];
1120 }
1121
1122 s->subframe_len = subframe_len;
1123 s->esc_len = av_log2(s->subframe_len - 1) + 1;
1124
1125 /** skip extended header if any */
1126 if (get_bits1(&s->gb)) {
1127 int num_fill_bits;
1128 if (!(num_fill_bits = get_bits(&s->gb, 2))) {
1129 int len = get_bits(&s->gb, 4);
1130 num_fill_bits = get_bits(&s->gb, len) + 1;
1131 }
1132
1133 if (num_fill_bits >= 0) {
1134 if (get_bits_count(&s->gb) + num_fill_bits > s->num_saved_bits) {
1135 av_log(s->avctx, AV_LOG_ERROR, "invalid number of fill bits\n");
1136 return AVERROR_INVALIDDATA;
1137 }
1138
1139 skip_bits_long(&s->gb, num_fill_bits);
1140 }
1141 }
1142
1143 /** no idea for what the following bit is used */
1144 if (get_bits1(&s->gb)) {
1145 av_log_ask_for_sample(s->avctx, "reserved bit set\n");
1146 return AVERROR_INVALIDDATA;
1147 }
1148
1149
1150 if (decode_channel_transform(s) < 0)
1151 return AVERROR_INVALIDDATA;
1152
1153
1154 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1155 int c = s->channel_indexes_for_cur_subframe[i];
1156 if ((s->channel[c].transmit_coefs = get_bits1(&s->gb)))
1157 transmit_coeffs = 1;
1158 }
1159
1160 if (transmit_coeffs) {
1161 int step;
1162 int quant_step = 90 * s->bits_per_sample >> 4;
1163 if ((get_bits1(&s->gb))) {
1164 /** FIXME: might change run level mode decision */
1165 av_log_ask_for_sample(s->avctx, "unsupported quant step coding\n");
1166 return AVERROR_INVALIDDATA;
1167 }
1168 /** decode quantization step */
1169 step = get_sbits(&s->gb, 6);
1170 quant_step += step;
1171 if (step == -32 || step == 31) {
1172 const int sign = (step == 31) - 1;
1173 int quant = 0;
1174 while (get_bits_count(&s->gb) + 5 < s->num_saved_bits &&
1175 (step = get_bits(&s->gb, 5)) == 31) {
1176 quant += 31;
1177 }
1178 quant_step += ((quant + step) ^ sign) - sign;
1179 }
1180 if (quant_step < 0) {
1181 av_log(s->avctx, AV_LOG_DEBUG, "negative quant step\n");
1182 }
1183
1184 /** decode quantization step modifiers for every channel */
1185
1186 if (s->channels_for_cur_subframe == 1) {
1187 s->channel[s->channel_indexes_for_cur_subframe[0]].quant_step = quant_step;
1188 } else {
1189 int modifier_len = get_bits(&s->gb, 3);
1190 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1191 int c = s->channel_indexes_for_cur_subframe[i];
1192 s->channel[c].quant_step = quant_step;
1193 if (get_bits1(&s->gb)) {
1194 if (modifier_len) {
1195 s->channel[c].quant_step += get_bits(&s->gb, modifier_len) + 1;
1196 } else
1197 ++s->channel[c].quant_step;
1198 }
1199 }
1200 }
1201
1202 /** decode scale factors */
1203 if (decode_scale_factors(s) < 0)
1204 return AVERROR_INVALIDDATA;
1205 }
1206
1207 dprintf(s->avctx, "BITSTREAM: subframe header length was %i\n",
1208 get_bits_count(&s->gb) - s->subframe_offset);
1209
1210 /** parse coefficients */
1211 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1212 int c = s->channel_indexes_for_cur_subframe[i];
1213 if (s->channel[c].transmit_coefs &&
1214 get_bits_count(&s->gb) < s->num_saved_bits) {
1215 decode_coeffs(s, c);
1216 } else
1217 memset(s->channel[c].coeffs, 0,
1218 sizeof(*s->channel[c].coeffs) * subframe_len);
1219 }
1220
1221 dprintf(s->avctx, "BITSTREAM: subframe length was %i\n",
1222 get_bits_count(&s->gb) - s->subframe_offset);
1223
1224 if (transmit_coeffs) {
1225 /** reconstruct the per channel data */
1226 inverse_channel_transform(s);
1227 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1228 int c = s->channel_indexes_for_cur_subframe[i];
1229 const int* sf = s->channel[c].scale_factors;
1230 int b;
1231
1232 if (c == s->lfe_channel)
1233 memset(&s->tmp[cur_subwoofer_cutoff], 0, sizeof(*s->tmp) *
1234 (subframe_len - cur_subwoofer_cutoff));
1235
1236 /** inverse quantization and rescaling */
1237 for (b = 0; b < s->num_bands; b++) {
1238 const int end = FFMIN(s->cur_sfb_offsets[b+1], s->subframe_len);
1239 const int exp = s->channel[c].quant_step -
1240 (s->channel[c].max_scale_factor - *sf++) *
1241 s->channel[c].scale_factor_step;
1242 const float quant = pow(10.0, exp / 20.0);
1243 int start = s->cur_sfb_offsets[b];
1244 s->dsp.vector_fmul_scalar(s->tmp + start,
1245 s->channel[c].coeffs + start,
1246 quant, end - start);
1247 }
1248
1249 /** apply imdct (ff_imdct_half == DCTIV with reverse) */
1250 ff_imdct_half(&s->mdct_ctx[av_log2(subframe_len) - BLOCK_MIN_BITS],
1251 s->channel[c].coeffs, s->tmp);
1252 }
1253 }
1254
1255 /** window and overlapp-add */
1256 wmapro_window(s);
1257
1258 /** handled one subframe */
1259 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1260 int c = s->channel_indexes_for_cur_subframe[i];
1261 if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) {
1262 av_log(s->avctx, AV_LOG_ERROR, "broken subframe\n");
1263 return AVERROR_INVALIDDATA;
1264 }
1265 ++s->channel[c].cur_subframe;
1266 }
1267
1268 return 0;
1269}
1270
1271/**
1272 *@brief Decode one WMA frame.
1273 *@param s codec context
1274 *@return 0 if the trailer bit indicates that this is the last frame,
1275 * 1 if there are additional frames
1276 */
1277static int decode_frame(WMAProDecodeCtx *s)
1278{
1279 GetBitContext* gb = &s->gb;
1280 int more_frames = 0;
1281 int len = 0;
1282 int i;
1283
1284 /** check for potential output buffer overflow */
1285 if (s->num_channels * s->samples_per_frame > s->samples_end - s->samples) {
1286 /** return an error if no frame could be decoded at all */
1287 av_log(s->avctx, AV_LOG_ERROR,
1288 "not enough space for the output samples\n");
1289 s->packet_loss = 1;
1290 return 0;
1291 }
1292
1293 /** get frame length */
1294 if (s->len_prefix)
1295 len = get_bits(gb, s->log2_frame_size);
1296
1297 dprintf(s->avctx, "decoding frame with length %x\n", len);
1298
1299 /** decode tile information */
1300 if (decode_tilehdr(s)) {
1301 s->packet_loss = 1;
1302 return 0;
1303 }
1304
1305 /** read postproc transform */
1306 if (s->num_channels > 1 && get_bits1(gb)) {
1307 av_log_ask_for_sample(s->avctx, "Unsupported postproc transform found\n");
1308 s->packet_loss = 1;
1309 return 0;
1310 }
1311
1312 /** read drc info */
1313 if (s->dynamic_range_compression) {
1314 s->drc_gain = get_bits(gb, 8);
1315 dprintf(s->avctx, "drc_gain %i\n", s->drc_gain);
1316 }
1317
1318 /** no idea what these are for, might be the number of samples
1319 that need to be skipped at the beginning or end of a stream */
1320 if (get_bits1(gb)) {
1321 int skip;
1322
1323 /** usually true for the first frame */
1324 if (get_bits1(gb)) {
1325 skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
1326 dprintf(s->avctx, "start skip: %i\n", skip);
1327 }
1328
1329 /** sometimes true for the last frame */
1330 if (get_bits1(gb)) {
1331 skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
1332 dprintf(s->avctx, "end skip: %i\n", skip);
1333 }
1334
1335 }
1336
1337 dprintf(s->avctx, "BITSTREAM: frame header length was %i\n",
1338 get_bits_count(gb) - s->frame_offset);
1339
1340 /** reset subframe states */
1341 s->parsed_all_subframes = 0;
1342 for (i = 0; i < s->num_channels; i++) {
1343 s->channel[i].decoded_samples = 0;
1344 s->channel[i].cur_subframe = 0;
1345 s->channel[i].reuse_sf = 0;
1346 }
1347
1348 /** decode all subframes */
1349 while (!s->parsed_all_subframes) {
1350 if (decode_subframe(s) < 0) {
1351 s->packet_loss = 1;
1352 return 0;
1353 }
1354 }
1355
1356 /** interleave samples and write them to the output buffer */
1357 for (i = 0; i < s->num_channels; i++) {
1358 float* ptr = s->samples + i;
1359 int incr = s->num_channels;
1360 float* iptr = s->channel[i].out;
1361 float* iend = iptr + s->samples_per_frame;
1362
1363 while (iptr < iend) {
1364 *ptr = av_clipf(*iptr++, -1.0, 32767.0 / 32768.0);
1365 ptr += incr;
1366 }
1367
1368 /** reuse second half of the IMDCT output for the next frame */
1369 memcpy(&s->channel[i].out[0],
1370 &s->channel[i].out[s->samples_per_frame],
1371 s->samples_per_frame * sizeof(*s->channel[i].out) >> 1);
1372 }
1373
1374 if (s->skip_frame) {
1375 s->skip_frame = 0;
1376 } else
1377 s->samples += s->num_channels * s->samples_per_frame;
1378
1379 if (len != (get_bits_count(gb) - s->frame_offset) + 2) {
1380 /** FIXME: not sure if this is always an error */
1381 av_log(s->avctx, AV_LOG_ERROR, "frame[%i] would have to skip %i bits\n",
1382 s->frame_num, len - (get_bits_count(gb) - s->frame_offset) - 1);
1383 s->packet_loss = 1;
1384 return 0;
1385 }
1386
1387 /** skip the rest of the frame data */
1388 skip_bits_long(gb, len - (get_bits_count(gb) - s->frame_offset) - 1);
1389
1390 /** decode trailer bit */
1391 more_frames = get_bits1(gb);
1392
1393 ++s->frame_num;
1394 return more_frames;
1395}
1396
1397/**
1398 *@brief Calculate remaining input buffer length.
1399 *@param s codec context
1400 *@param gb bitstream reader context
1401 *@return remaining size in bits
1402 */
1403static int remaining_bits(WMAProDecodeCtx *s, GetBitContext *gb)
1404{
1405 return s->buf_bit_size - get_bits_count(gb);
1406}
1407
1408/**
1409 *@brief Fill the bit reservoir with a (partial) frame.
1410 *@param s codec context
1411 *@param gb bitstream reader context
1412 *@param len length of the partial frame
1413 *@param append decides wether to reset the buffer or not
1414 */
1415static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len,
1416 int append)
1417{
1418 int buflen;
1419
1420 /** when the frame data does not need to be concatenated, the input buffer
1421 is resetted and additional bits from the previous frame are copyed
1422 and skipped later so that a fast byte copy is possible */
1423
1424 if (!append) {
1425 s->frame_offset = get_bits_count(gb) & 7;
1426 s->num_saved_bits = s->frame_offset;
1427 init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
1428 }
1429
1430 buflen = (s->num_saved_bits + len + 8) >> 3;
1431
1432 if (len <= 0 || buflen > MAX_FRAMESIZE) {
1433 av_log_ask_for_sample(s->avctx, "input buffer too small\n");
1434 s->packet_loss = 1;
1435 return;
1436 }
1437
1438 s->num_saved_bits += len;
1439 if (!append) {
1440 ff_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3),
1441 s->num_saved_bits);
1442 } else {
1443 int align = 8 - (get_bits_count(gb) & 7);
1444 align = FFMIN(align, len);
1445 put_bits(&s->pb, align, get_bits(gb, align));
1446 len -= align;
1447 ff_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), len);
1448 }
1449 skip_bits_long(gb, len);
1450
1451 {
1452 PutBitContext tmp = s->pb;
1453 flush_put_bits(&tmp);
1454 }
1455
1456 init_get_bits(&s->gb, s->frame_data, s->num_saved_bits);
1457 skip_bits(&s->gb, s->frame_offset);
1458}
1459
1460/**
1461 *@brief Decode a single WMA packet.
1462 *@param avctx codec context
1463 *@param data the output buffer
1464 *@param data_size number of bytes that were written to the output buffer
1465 *@param avpkt input packet
1466 *@return number of bytes that were read from the input buffer
1467 */
1468static int decode_packet(AVCodecContext *avctx,
1469 void *data, int *data_size, AVPacket* avpkt)
1470{
1471 WMAProDecodeCtx *s = avctx->priv_data;
1472 GetBitContext* gb = &s->pgb;
1473 const uint8_t* buf = avpkt->data;
1474 int buf_size = avpkt->size;
1475 int num_bits_prev_frame;
1476 int packet_sequence_number;
1477
1478 s->samples = data;
1479 s->samples_end = (float*)((int8_t*)data + *data_size);
1480 *data_size = 0;
1481
1482 if (s->packet_done || s->packet_loss) {
1483 s->packet_done = 0;
1484 s->buf_bit_size = buf_size << 3;
1485
1486 /** sanity check for the buffer length */
1487 if (buf_size < avctx->block_align)
1488 return 0;
1489
1490 buf_size = avctx->block_align;
1491
1492 /** parse packet header */
1493 init_get_bits(gb, buf, s->buf_bit_size);
1494 packet_sequence_number = get_bits(gb, 4);
1495 skip_bits(gb, 2);
1496
1497 /** get number of bits that need to be added to the previous frame */
1498 num_bits_prev_frame = get_bits(gb, s->log2_frame_size);
1499 dprintf(avctx, "packet[%d]: nbpf %x\n", avctx->frame_number,
1500 num_bits_prev_frame);
1501
1502 /** check for packet loss */
1503 if (!s->packet_loss &&
1504 ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1505 s->packet_loss = 1;
1506 av_log(avctx, AV_LOG_ERROR, "Packet loss detected! seq %x vs %x\n",
1507 s->packet_sequence_number, packet_sequence_number);
1508 }
1509 s->packet_sequence_number = packet_sequence_number;
1510
1511 if (num_bits_prev_frame > 0) {
1512 /** append the previous frame data to the remaining data from the
1513 previous packet to create a full frame */
1514 save_bits(s, gb, num_bits_prev_frame, 1);
1515 dprintf(avctx, "accumulated %x bits of frame data\n",
1516 s->num_saved_bits - s->frame_offset);
1517
1518 /** decode the cross packet frame if it is valid */
1519 if (!s->packet_loss)
1520 decode_frame(s);
1521 } else if (s->num_saved_bits - s->frame_offset) {
1522 dprintf(avctx, "ignoring %x previously saved bits\n",
1523 s->num_saved_bits - s->frame_offset);
1524 }
1525
1526 s->packet_loss = 0;
1527
1528 } else {
1529 int frame_size;
1530 s->buf_bit_size = avpkt->size << 3;
1531 init_get_bits(gb, avpkt->data, s->buf_bit_size);
1532 skip_bits(gb, s->packet_offset);
1533 if (remaining_bits(s, gb) > s->log2_frame_size &&
1534 (frame_size = show_bits(gb, s->log2_frame_size)) &&
1535 frame_size <= remaining_bits(s, gb)) {
1536 save_bits(s, gb, frame_size, 0);
1537 s->packet_done = !decode_frame(s);
1538 } else
1539 s->packet_done = 1;
1540 }
1541
1542 if (s->packet_done && !s->packet_loss &&
1543 remaining_bits(s, gb) > 0) {
1544 /** save the rest of the data so that it can be decoded
1545 with the next packet */
1546 save_bits(s, gb, remaining_bits(s, gb), 0);
1547 }
1548
1549 *data_size = (int8_t *)s->samples - (int8_t *)data;
1550 s->packet_offset = get_bits_count(gb) & 7;
1551
1552 return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3;
1553}
1554
1555/**
1556 *@brief Clear decoder buffers (for seeking).
1557 *@param avctx codec context
1558 */
1559static void flush(AVCodecContext *avctx)
1560{
1561 WMAProDecodeCtx *s = avctx->priv_data;
1562 int i;
1563 /** reset output buffer as a part of it is used during the windowing of a
1564 new frame */
1565 for (i = 0; i < s->num_channels; i++)
1566 memset(s->channel[i].out, 0, s->samples_per_frame *
1567 sizeof(*s->channel[i].out));
1568 s->packet_loss = 1;
1569}
1570
1571#if 0
1572/**
1573 *@brief wmapro decoder
1574 */
1575AVCodec wmapro_decoder = {
1576 "wmapro",
1577 AVMEDIA_TYPE_AUDIO,
1578 CODEC_ID_WMAPRO,
1579 sizeof(WMAProDecodeCtx),
1580 decode_init,
1581 NULL,
1582 decode_end,
1583 decode_packet,
1584 .capabilities = CODEC_CAP_SUBFRAMES,
1585 .flush= flush,
1586 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 9 Professional"),
1587};
1588#endif
1589
1590int main(void)
1591{
1592 /* possible test program - just here now to silence the linker */
1593 return 0;
1594}