summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohamed Tarek <mt@rockbox.org>2010-04-30 11:11:56 +0000
committerMohamed Tarek <mt@rockbox.org>2010-04-30 11:11:56 +0000
commitcf43e5083b9e0f87de262ea31fd8067225ebfcda (patch)
tree073e6f4cd9561564d85e410a35432e1f4ead5b11
parentbc3c5c16571487bf71fed8c22b30ee40481e156e (diff)
downloadrockbox-cf43e5083b9e0f87de262ea31fd8067225ebfcda.tar.gz
rockbox-cf43e5083b9e0f87de262ea31fd8067225ebfcda.zip
Add libwmapro to apps/codecs. These files comprise a set of unmodified files needed from ffmpeg's libavcodec and libavutil to compile and use the wma pro decoder standalone. The files were taken from ffmpeg's svn r22886 dated 15 April 2010.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25763 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/libwmapro/avcodec.h3952
-rw-r--r--apps/codecs/libwmapro/avfft.h99
-rw-r--r--apps/codecs/libwmapro/bitstream.c336
-rw-r--r--apps/codecs/libwmapro/dsputil.c4565
-rw-r--r--apps/codecs/libwmapro/dsputil.h808
-rw-r--r--apps/codecs/libwmapro/fft.c368
-rw-r--r--apps/codecs/libwmapro/fft.h240
-rw-r--r--apps/codecs/libwmapro/get_bits.h691
-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.h89
-rw-r--r--apps/codecs/libwmapro/libavutil/bswap.h101
-rw-r--r--apps/codecs/libwmapro/libavutil/common.h297
-rw-r--r--apps/codecs/libwmapro/libavutil/internal.h207
-rw-r--r--apps/codecs/libwmapro/libavutil/intreadwrite.h516
-rw-r--r--apps/codecs/libwmapro/libavutil/log.c92
-rw-r--r--apps/codecs/libwmapro/libavutil/log.h115
-rw-r--r--apps/codecs/libwmapro/libavutil/mathematics.c174
-rw-r--r--apps/codecs/libwmapro/libavutil/mathematics.h98
-rw-r--r--apps/codecs/libwmapro/libavutil/mem.c176
-rw-r--r--apps/codecs/libwmapro/libavutil/mem.h125
-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.c523
-rw-r--r--apps/codecs/libwmapro/wma.h163
-rw-r--r--apps/codecs/libwmapro/wmaprodata.h604
-rw-r--r--apps/codecs/libwmapro/wmaprodec.c1578
29 files changed, 16866 insertions, 0 deletions
diff --git a/apps/codecs/libwmapro/avcodec.h b/apps/codecs/libwmapro/avcodec.h
new file mode 100644
index 0000000000..add4b100ae
--- /dev/null
+++ b/apps/codecs/libwmapro/avcodec.h
@@ -0,0 +1,3952 @@
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 66
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#if LIBAVCODEC_VERSION_MAJOR < 53
129 CODEC_ID_XVID,
130#endif
131 CODEC_ID_PNG,
132 CODEC_ID_PPM,
133 CODEC_ID_PBM,
134 CODEC_ID_PGM,
135 CODEC_ID_PGMYUV,
136 CODEC_ID_PAM,
137 CODEC_ID_FFVHUFF,
138 CODEC_ID_RV30,
139 CODEC_ID_RV40,
140 CODEC_ID_VC1,
141 CODEC_ID_WMV3,
142 CODEC_ID_LOCO,
143 CODEC_ID_WNV1,
144 CODEC_ID_AASC,
145 CODEC_ID_INDEO2,
146 CODEC_ID_FRAPS,
147 CODEC_ID_TRUEMOTION2,
148 CODEC_ID_BMP,
149 CODEC_ID_CSCD,
150 CODEC_ID_MMVIDEO,
151 CODEC_ID_ZMBV,
152 CODEC_ID_AVS,
153 CODEC_ID_SMACKVIDEO,
154 CODEC_ID_NUV,
155 CODEC_ID_KMVC,
156 CODEC_ID_FLASHSV,
157 CODEC_ID_CAVS,
158 CODEC_ID_JPEG2000,
159 CODEC_ID_VMNC,
160 CODEC_ID_VP5,
161 CODEC_ID_VP6,
162 CODEC_ID_VP6F,
163 CODEC_ID_TARGA,
164 CODEC_ID_DSICINVIDEO,
165 CODEC_ID_TIERTEXSEQVIDEO,
166 CODEC_ID_TIFF,
167 CODEC_ID_GIF,
168 CODEC_ID_FFH264,
169 CODEC_ID_DXA,
170 CODEC_ID_DNXHD,
171 CODEC_ID_THP,
172 CODEC_ID_SGI,
173 CODEC_ID_C93,
174 CODEC_ID_BETHSOFTVID,
175 CODEC_ID_PTX,
176 CODEC_ID_TXD,
177 CODEC_ID_VP6A,
178 CODEC_ID_AMV,
179 CODEC_ID_VB,
180 CODEC_ID_PCX,
181 CODEC_ID_SUNRAST,
182 CODEC_ID_INDEO4,
183 CODEC_ID_INDEO5,
184 CODEC_ID_MIMIC,
185 CODEC_ID_RL2,
186 CODEC_ID_8SVX_EXP,
187 CODEC_ID_8SVX_FIB,
188 CODEC_ID_ESCAPE124,
189 CODEC_ID_DIRAC,
190 CODEC_ID_BFI,
191 CODEC_ID_CMV,
192 CODEC_ID_MOTIONPIXELS,
193 CODEC_ID_TGV,
194 CODEC_ID_TGQ,
195 CODEC_ID_TQI,
196 CODEC_ID_AURA,
197 CODEC_ID_AURA2,
198 CODEC_ID_V210X,
199 CODEC_ID_TMV,
200 CODEC_ID_V210,
201 CODEC_ID_DPX,
202 CODEC_ID_MAD,
203 CODEC_ID_FRWU,
204 CODEC_ID_FLASHSV2,
205 CODEC_ID_CDGRAPHICS,
206 CODEC_ID_R210,
207 CODEC_ID_ANM,
208 CODEC_ID_BINKVIDEO,
209 CODEC_ID_IFF_ILBM,
210 CODEC_ID_IFF_BYTERUN1,
211 CODEC_ID_KGV1,
212 CODEC_ID_YOP,
213
214 /* various PCM "codecs" */
215 CODEC_ID_PCM_S16LE= 0x10000,
216 CODEC_ID_PCM_S16BE,
217 CODEC_ID_PCM_U16LE,
218 CODEC_ID_PCM_U16BE,
219 CODEC_ID_PCM_S8,
220 CODEC_ID_PCM_U8,
221 CODEC_ID_PCM_MULAW,
222 CODEC_ID_PCM_ALAW,
223 CODEC_ID_PCM_S32LE,
224 CODEC_ID_PCM_S32BE,
225 CODEC_ID_PCM_U32LE,
226 CODEC_ID_PCM_U32BE,
227 CODEC_ID_PCM_S24LE,
228 CODEC_ID_PCM_S24BE,
229 CODEC_ID_PCM_U24LE,
230 CODEC_ID_PCM_U24BE,
231 CODEC_ID_PCM_S24DAUD,
232 CODEC_ID_PCM_ZORK,
233 CODEC_ID_PCM_S16LE_PLANAR,
234 CODEC_ID_PCM_DVD,
235 CODEC_ID_PCM_F32BE,
236 CODEC_ID_PCM_F32LE,
237 CODEC_ID_PCM_F64BE,
238 CODEC_ID_PCM_F64LE,
239 CODEC_ID_PCM_BLURAY,
240
241 /* various ADPCM codecs */
242 CODEC_ID_ADPCM_IMA_QT= 0x11000,
243 CODEC_ID_ADPCM_IMA_WAV,
244 CODEC_ID_ADPCM_IMA_DK3,
245 CODEC_ID_ADPCM_IMA_DK4,
246 CODEC_ID_ADPCM_IMA_WS,
247 CODEC_ID_ADPCM_IMA_SMJPEG,
248 CODEC_ID_ADPCM_MS,
249 CODEC_ID_ADPCM_4XM,
250 CODEC_ID_ADPCM_XA,
251 CODEC_ID_ADPCM_ADX,
252 CODEC_ID_ADPCM_EA,
253 CODEC_ID_ADPCM_G726,
254 CODEC_ID_ADPCM_CT,
255 CODEC_ID_ADPCM_SWF,
256 CODEC_ID_ADPCM_YAMAHA,
257 CODEC_ID_ADPCM_SBPRO_4,
258 CODEC_ID_ADPCM_SBPRO_3,
259 CODEC_ID_ADPCM_SBPRO_2,
260 CODEC_ID_ADPCM_THP,
261 CODEC_ID_ADPCM_IMA_AMV,
262 CODEC_ID_ADPCM_EA_R1,
263 CODEC_ID_ADPCM_EA_R3,
264 CODEC_ID_ADPCM_EA_R2,
265 CODEC_ID_ADPCM_IMA_EA_SEAD,
266 CODEC_ID_ADPCM_IMA_EA_EACS,
267 CODEC_ID_ADPCM_EA_XAS,
268 CODEC_ID_ADPCM_EA_MAXIS_XA,
269 CODEC_ID_ADPCM_IMA_ISS,
270
271 /* AMR */
272 CODEC_ID_AMR_NB= 0x12000,
273 CODEC_ID_AMR_WB,
274
275 /* RealAudio codecs*/
276 CODEC_ID_RA_144= 0x13000,
277 CODEC_ID_RA_288,
278
279 /* various DPCM codecs */
280 CODEC_ID_ROQ_DPCM= 0x14000,
281 CODEC_ID_INTERPLAY_DPCM,
282 CODEC_ID_XAN_DPCM,
283 CODEC_ID_SOL_DPCM,
284
285 /* audio codecs */
286 CODEC_ID_MP2= 0x15000,
287 CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
288 CODEC_ID_AAC,
289 CODEC_ID_AC3,
290 CODEC_ID_DTS,
291 CODEC_ID_VORBIS,
292 CODEC_ID_DVAUDIO,
293 CODEC_ID_WMAV1,
294 CODEC_ID_WMAV2,
295 CODEC_ID_MACE3,
296 CODEC_ID_MACE6,
297 CODEC_ID_VMDAUDIO,
298 CODEC_ID_SONIC,
299 CODEC_ID_SONIC_LS,
300 CODEC_ID_FLAC,
301 CODEC_ID_MP3ADU,
302 CODEC_ID_MP3ON4,
303 CODEC_ID_SHORTEN,
304 CODEC_ID_ALAC,
305 CODEC_ID_WESTWOOD_SND1,
306 CODEC_ID_GSM, ///< as in Berlin toast format
307 CODEC_ID_QDM2,
308 CODEC_ID_COOK,
309 CODEC_ID_TRUESPEECH,
310 CODEC_ID_TTA,
311 CODEC_ID_SMACKAUDIO,
312 CODEC_ID_QCELP,
313 CODEC_ID_WAVPACK,
314 CODEC_ID_DSICINAUDIO,
315 CODEC_ID_IMC,
316 CODEC_ID_MUSEPACK7,
317 CODEC_ID_MLP,
318 CODEC_ID_GSM_MS, /* as found in WAV */
319 CODEC_ID_ATRAC3,
320 CODEC_ID_VOXWARE,
321 CODEC_ID_APE,
322 CODEC_ID_NELLYMOSER,
323 CODEC_ID_MUSEPACK8,
324 CODEC_ID_SPEEX,
325 CODEC_ID_WMAVOICE,
326 CODEC_ID_WMAPRO,
327 CODEC_ID_WMALOSSLESS,
328 CODEC_ID_ATRAC3P,
329 CODEC_ID_EAC3,
330 CODEC_ID_SIPR,
331 CODEC_ID_MP1,
332 CODEC_ID_TWINVQ,
333 CODEC_ID_TRUEHD,
334 CODEC_ID_MP4ALS,
335 CODEC_ID_ATRAC1,
336 CODEC_ID_BINKAUDIO_RDFT,
337 CODEC_ID_BINKAUDIO_DCT,
338
339 /* subtitle codecs */
340 CODEC_ID_DVD_SUBTITLE= 0x17000,
341 CODEC_ID_DVB_SUBTITLE,
342 CODEC_ID_TEXT, ///< raw UTF-8 text
343 CODEC_ID_XSUB,
344 CODEC_ID_SSA,
345 CODEC_ID_MOV_TEXT,
346 CODEC_ID_HDMV_PGS_SUBTITLE,
347 CODEC_ID_DVB_TELETEXT,
348
349 /* other specific kind of codecs (generally used for attachments) */
350 CODEC_ID_TTF= 0x18000,
351
352 CODEC_ID_PROBE= 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it
353
354 CODEC_ID_MPEG2TS= 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
355 * stream (only used by libavformat) */
356};
357
358#if LIBAVCODEC_VERSION_MAJOR < 53
359#define CodecType AVMediaType
360
361#define CODEC_TYPE_UNKNOWN AVMEDIA_TYPE_UNKNOWN
362#define CODEC_TYPE_VIDEO AVMEDIA_TYPE_VIDEO
363#define CODEC_TYPE_AUDIO AVMEDIA_TYPE_AUDIO
364#define CODEC_TYPE_DATA AVMEDIA_TYPE_DATA
365#define CODEC_TYPE_SUBTITLE AVMEDIA_TYPE_SUBTITLE
366#define CODEC_TYPE_ATTACHMENT AVMEDIA_TYPE_ATTACHMENT
367#define CODEC_TYPE_NB AVMEDIA_TYPE_NB
368#endif
369
370/**
371 * all in native-endian format
372 */
373enum SampleFormat {
374 SAMPLE_FMT_NONE = -1,
375 SAMPLE_FMT_U8, ///< unsigned 8 bits
376 SAMPLE_FMT_S16, ///< signed 16 bits
377 SAMPLE_FMT_S32, ///< signed 32 bits
378 SAMPLE_FMT_FLT, ///< float
379 SAMPLE_FMT_DBL, ///< double
380 SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if dynamically linking to libavcodec
381};
382
383/* Audio channel masks */
384#define CH_FRONT_LEFT 0x00000001
385#define CH_FRONT_RIGHT 0x00000002
386#define CH_FRONT_CENTER 0x00000004
387#define CH_LOW_FREQUENCY 0x00000008
388#define CH_BACK_LEFT 0x00000010
389#define CH_BACK_RIGHT 0x00000020
390#define CH_FRONT_LEFT_OF_CENTER 0x00000040
391#define CH_FRONT_RIGHT_OF_CENTER 0x00000080
392#define CH_BACK_CENTER 0x00000100
393#define CH_SIDE_LEFT 0x00000200
394#define CH_SIDE_RIGHT 0x00000400
395#define CH_TOP_CENTER 0x00000800
396#define CH_TOP_FRONT_LEFT 0x00001000
397#define CH_TOP_FRONT_CENTER 0x00002000
398#define CH_TOP_FRONT_RIGHT 0x00004000
399#define CH_TOP_BACK_LEFT 0x00008000
400#define CH_TOP_BACK_CENTER 0x00010000
401#define CH_TOP_BACK_RIGHT 0x00020000
402#define CH_STEREO_LEFT 0x20000000 ///< Stereo downmix.
403#define CH_STEREO_RIGHT 0x40000000 ///< See CH_STEREO_LEFT.
404
405/** Channel mask value used for AVCodecContext.request_channel_layout
406 to indicate that the user requests the channel order of the decoder output
407 to be the native codec channel order. */
408#define CH_LAYOUT_NATIVE 0x8000000000000000LL
409
410/* Audio channel convenience macros */
411#define CH_LAYOUT_MONO (CH_FRONT_CENTER)
412#define CH_LAYOUT_STEREO (CH_FRONT_LEFT|CH_FRONT_RIGHT)
413#define CH_LAYOUT_2_1 (CH_LAYOUT_STEREO|CH_BACK_CENTER)
414#define CH_LAYOUT_SURROUND (CH_LAYOUT_STEREO|CH_FRONT_CENTER)
415#define CH_LAYOUT_4POINT0 (CH_LAYOUT_SURROUND|CH_BACK_CENTER)
416#define CH_LAYOUT_2_2 (CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT)
417#define CH_LAYOUT_QUAD (CH_LAYOUT_STEREO|CH_BACK_LEFT|CH_BACK_RIGHT)
418#define CH_LAYOUT_5POINT0 (CH_LAYOUT_SURROUND|CH_SIDE_LEFT|CH_SIDE_RIGHT)
419#define CH_LAYOUT_5POINT1 (CH_LAYOUT_5POINT0|CH_LOW_FREQUENCY)
420#define CH_LAYOUT_5POINT0_BACK (CH_LAYOUT_SURROUND|CH_BACK_LEFT|CH_BACK_RIGHT)
421#define CH_LAYOUT_5POINT1_BACK (CH_LAYOUT_5POINT0_BACK|CH_LOW_FREQUENCY)
422#define CH_LAYOUT_7POINT0 (CH_LAYOUT_5POINT0|CH_BACK_LEFT|CH_BACK_RIGHT)
423#define CH_LAYOUT_7POINT1 (CH_LAYOUT_5POINT1|CH_BACK_LEFT|CH_BACK_RIGHT)
424#define CH_LAYOUT_7POINT1_WIDE (CH_LAYOUT_5POINT1_BACK|\
425 CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER)
426#define CH_LAYOUT_STEREO_DOWNMIX (CH_STEREO_LEFT|CH_STEREO_RIGHT)
427
428/* in bytes */
429#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
430
431/**
432 * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
433 * This is mainly needed because some optimized bitstream readers read
434 * 32 or 64 bit at once and could read over the end.<br>
435 * Note: If the first 23 bits of the additional bytes are not 0, then damaged
436 * MPEG bitstreams could cause overread and segfault.
437 */
438#define FF_INPUT_BUFFER_PADDING_SIZE 8
439
440/**
441 * minimum encoding buffer size
442 * Used to avoid some checks during header writing.
443 */
444#define FF_MIN_BUFFER_SIZE 16384
445
446
447/**
448 * motion estimation type.
449 */
450enum Motion_Est_ID {
451 ME_ZERO = 1, ///< no search, that is use 0,0 vector whenever one is needed
452 ME_FULL,
453 ME_LOG,
454 ME_PHODS,
455 ME_EPZS, ///< enhanced predictive zonal search
456 ME_X1, ///< reserved for experiments
457 ME_HEX, ///< hexagon based search
458 ME_UMH, ///< uneven multi-hexagon search
459 ME_ITER, ///< iterative search
460 ME_TESA, ///< transformed exhaustive search algorithm
461};
462
463enum AVDiscard{
464 /* We leave some space between them for extensions (drop some
465 * keyframes for intra-only or drop just some bidir frames). */
466 AVDISCARD_NONE =-16, ///< discard nothing
467 AVDISCARD_DEFAULT= 0, ///< discard useless packets like 0 size packets in avi
468 AVDISCARD_NONREF = 8, ///< discard all non reference
469 AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
470 AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
471 AVDISCARD_ALL = 48, ///< discard all
472};
473
474enum AVColorPrimaries{
475 AVCOL_PRI_BT709 =1, ///< also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
476 AVCOL_PRI_UNSPECIFIED=2,
477 AVCOL_PRI_BT470M =4,
478 AVCOL_PRI_BT470BG =5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
479 AVCOL_PRI_SMPTE170M =6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
480 AVCOL_PRI_SMPTE240M =7, ///< functionally identical to above
481 AVCOL_PRI_FILM =8,
482 AVCOL_PRI_NB , ///< Not part of ABI
483};
484
485enum AVColorTransferCharacteristic{
486 AVCOL_TRC_BT709 =1, ///< also ITU-R BT1361
487 AVCOL_TRC_UNSPECIFIED=2,
488 AVCOL_TRC_GAMMA22 =4, ///< also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
489 AVCOL_TRC_GAMMA28 =5, ///< also ITU-R BT470BG
490 AVCOL_TRC_NB , ///< Not part of ABI
491};
492
493enum AVColorSpace{
494 AVCOL_SPC_RGB =0,
495 AVCOL_SPC_BT709 =1, ///< also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
496 AVCOL_SPC_UNSPECIFIED=2,
497 AVCOL_SPC_FCC =4,
498 AVCOL_SPC_BT470BG =5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
499 AVCOL_SPC_SMPTE170M =6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
500 AVCOL_SPC_SMPTE240M =7,
501 AVCOL_SPC_NB , ///< Not part of ABI
502};
503
504enum AVColorRange{
505 AVCOL_RANGE_UNSPECIFIED=0,
506 AVCOL_RANGE_MPEG =1, ///< the normal 219*2^(n-8) "MPEG" YUV ranges
507 AVCOL_RANGE_JPEG =2, ///< the normal 2^n-1 "JPEG" YUV ranges
508 AVCOL_RANGE_NB , ///< Not part of ABI
509};
510
511/**
512 * X X 3 4 X X are luma samples,
513 * 1 2 1-6 are possible chroma positions
514 * X X 5 6 X 0 is undefined/unknown position
515 */
516enum AVChromaLocation{
517 AVCHROMA_LOC_UNSPECIFIED=0,
518 AVCHROMA_LOC_LEFT =1, ///< mpeg2/4, h264 default
519 AVCHROMA_LOC_CENTER =2, ///< mpeg1, jpeg, h263
520 AVCHROMA_LOC_TOPLEFT =3, ///< DV
521 AVCHROMA_LOC_TOP =4,
522 AVCHROMA_LOC_BOTTOMLEFT =5,
523 AVCHROMA_LOC_BOTTOM =6,
524 AVCHROMA_LOC_NB , ///< Not part of ABI
525};
526
527typedef struct RcOverride{
528 int start_frame;
529 int end_frame;
530 int qscale; // If this is 0 then quality_factor will be used instead.
531 float quality_factor;
532} RcOverride;
533
534#define FF_MAX_B_FRAMES 16
535
536/* encoding support
537 These flags can be passed in AVCodecContext.flags before initialization.
538 Note: Not everything is supported yet.
539*/
540
541#define CODEC_FLAG_QSCALE 0x0002 ///< Use fixed qscale.
542#define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / advanced prediction for H.263.
543#define CODEC_FLAG_QPEL 0x0010 ///< Use qpel MC.
544#define CODEC_FLAG_GMC 0x0020 ///< Use GMC.
545#define CODEC_FLAG_MV0 0x0040 ///< Always try a MB with MV=<0,0>.
546#define CODEC_FLAG_PART 0x0080 ///< Use data partitioning.
547/**
548 * The parent program guarantees that the input for B-frames containing
549 * streams is not written to for at least s->max_b_frames+1 frames, if
550 * this is not set the input will be copied.
551 */
552#define CODEC_FLAG_INPUT_PRESERVED 0x0100
553#define CODEC_FLAG_PASS1 0x0200 ///< Use internal 2pass ratecontrol in first pass mode.
554#define CODEC_FLAG_PASS2 0x0400 ///< Use internal 2pass ratecontrol in second pass mode.
555#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< Use external Huffman table (for MJPEG).
556#define CODEC_FLAG_GRAY 0x2000 ///< Only decode/encode grayscale.
557#define CODEC_FLAG_EMU_EDGE 0x4000 ///< Don't draw edges.
558#define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding.
559#define CODEC_FLAG_TRUNCATED 0x00010000 /** Input bitstream might be truncated at a random
560 location instead of only at frame boundaries. */
561#define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< Normalize adaptive quantization.
562#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT.
563#define CODEC_FLAG_LOW_DELAY 0x00080000 ///< Force low delay.
564#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< Use alternate scan.
565#define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< Place global headers in extradata instead of every keyframe.
566#define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT).
567/* Fx : Flag for h263+ extra options */
568#define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
569#define CODEC_FLAG_H263P_UMV 0x02000000 ///< unlimited motion vector
570#define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp.
571#define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon.
572#define CODEC_FLAG_H263P_AIV 0x00000008 ///< H.263 alternative inter VLC
573#define CODEC_FLAG_OBMC 0x00000001 ///< OBMC
574#define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter
575#define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000
576#define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
577#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< Will reserve space for SVCD scan offset user data.
578#define CODEC_FLAG_CLOSED_GOP 0x80000000
579#define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks.
580#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size.
581#define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding.
582#define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata.
583#define CODEC_FLAG2_BPYRAMID 0x00000010 ///< H.264 allow B-frames to be used as references.
584#define CODEC_FLAG2_WPRED 0x00000020 ///< H.264 weighted biprediction for B-frames
585#define CODEC_FLAG2_MIXED_REFS 0x00000040 ///< H.264 one reference per partition, as opposed to one reference per macroblock
586#define CODEC_FLAG2_8X8DCT 0x00000080 ///< H.264 high profile 8x8 transform
587#define CODEC_FLAG2_FASTPSKIP 0x00000100 ///< H.264 fast pskip
588#define CODEC_FLAG2_AUD 0x00000200 ///< H.264 access unit delimiters
589#define CODEC_FLAG2_BRDO 0x00000400 ///< B-frame rate-distortion optimization
590#define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< Use MPEG-2 intra VLC table.
591#define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC).
592#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format.
593#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping
594#define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
595#define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer.
596#define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible
597#define CODEC_FLAG2_MBTREE 0x00040000 ///< Use macroblock tree ratecontrol (x264 only)
598#define CODEC_FLAG2_PSY 0x00080000 ///< Use psycho visual optimizations.
599#define CODEC_FLAG2_SSIM 0x00100000 ///< Compute SSIM during encoding, error[] values are undefined.
600
601/* Unsupported options :
602 * Syntax Arithmetic coding (SAC)
603 * Reference Picture Selection
604 * Independent Segment Decoding */
605/* /Fx */
606/* codec capabilities */
607
608#define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback.
609/**
610 * Codec uses get_buffer() for allocating buffers and supports custom allocators.
611 * If not set, it might not use get_buffer() at all or use operations that
612 * assume the buffer was allocated by avcodec_default_get_buffer.
613 */
614#define CODEC_CAP_DR1 0x0002
615/* If 'parse_only' field is true, then avcodec_parse_frame() can be used. */
616#define CODEC_CAP_PARSE_ONLY 0x0004
617#define CODEC_CAP_TRUNCATED 0x0008
618/* Codec can export data for HW decoding (XvMC). */
619#define CODEC_CAP_HWACCEL 0x0010
620/**
621 * Codec has a nonzero delay and needs to be fed with NULL at the end to get the delayed data.
622 * If this is not set, the codec is guaranteed to never be fed with NULL data.
623 */
624#define CODEC_CAP_DELAY 0x0020
625/**
626 * Codec can be fed a final frame with a smaller size.
627 * This can be used to prevent truncation of the last audio samples.
628 */
629#define CODEC_CAP_SMALL_LAST_FRAME 0x0040
630/**
631 * Codec can export data for HW decoding (VDPAU).
632 */
633#define CODEC_CAP_HWACCEL_VDPAU 0x0080
634/**
635 * Codec can output multiple frames per AVPacket
636 * Normally demuxers return one frame at a time, demuxers which do not do
637 * are connected to a parser to split what they return into proper frames.
638 * This flag is reserved to the very rare category of codecs which have a
639 * bitstream that cannot be split into frames without timeconsuming
640 * operations like full decoding. Demuxers carring such bitstreams thus
641 * may return multiple frames in a packet. This has many disadvantages like
642 * prohibiting stream copy in many cases thus it should only be considered
643 * as a last resort.
644 */
645#define CODEC_CAP_SUBFRAMES 0x0100
646
647//The following defines may change, don't expect compatibility if you use them.
648#define MB_TYPE_INTRA4x4 0x0001
649#define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific
650#define MB_TYPE_INTRA_PCM 0x0004 //FIXME H.264-specific
651#define MB_TYPE_16x16 0x0008
652#define MB_TYPE_16x8 0x0010
653#define MB_TYPE_8x16 0x0020
654#define MB_TYPE_8x8 0x0040
655#define MB_TYPE_INTERLACED 0x0080
656#define MB_TYPE_DIRECT2 0x0100 //FIXME
657#define MB_TYPE_ACPRED 0x0200
658#define MB_TYPE_GMC 0x0400
659#define MB_TYPE_SKIP 0x0800
660#define MB_TYPE_P0L0 0x1000
661#define MB_TYPE_P1L0 0x2000
662#define MB_TYPE_P0L1 0x4000
663#define MB_TYPE_P1L1 0x8000
664#define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
665#define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
666#define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
667#define MB_TYPE_QUANT 0x00010000
668#define MB_TYPE_CBP 0x00020000
669//Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...)
670
671/**
672 * Pan Scan area.
673 * This specifies the area which should be displayed.
674 * Note there may be multiple such areas for one frame.
675 */
676typedef struct AVPanScan{
677 /**
678 * id
679 * - encoding: Set by user.
680 * - decoding: Set by libavcodec.
681 */
682 int id;
683
684 /**
685 * width and height in 1/16 pel
686 * - encoding: Set by user.
687 * - decoding: Set by libavcodec.
688 */
689 int width;
690 int height;
691
692 /**
693 * position of the top left corner in 1/16 pel for up to 3 fields/frames
694 * - encoding: Set by user.
695 * - decoding: Set by libavcodec.
696 */
697 int16_t position[3][2];
698}AVPanScan;
699
700#define FF_COMMON_FRAME \
701 /**\
702 * pointer to the picture planes.\
703 * This might be different from the first allocated byte\
704 * - encoding: \
705 * - decoding: \
706 */\
707 uint8_t *data[4];\
708 int linesize[4];\
709 /**\
710 * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.\
711 * This isn't used by libavcodec unless the default get/release_buffer() is used.\
712 * - encoding: \
713 * - decoding: \
714 */\
715 uint8_t *base[4];\
716 /**\
717 * 1 -> keyframe, 0-> not\
718 * - encoding: Set by libavcodec.\
719 * - decoding: Set by libavcodec.\
720 */\
721 int key_frame;\
722\
723 /**\
724 * Picture type of the frame, see ?_TYPE below.\
725 * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\
726 * - decoding: Set by libavcodec.\
727 */\
728 int pict_type;\
729\
730 /**\
731 * presentation timestamp in time_base units (time when frame should be shown to user)\
732 * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.\
733 * - encoding: MUST be set by user.\
734 * - decoding: Set by libavcodec.\
735 */\
736 int64_t pts;\
737\
738 /**\
739 * picture number in bitstream order\
740 * - encoding: set by\
741 * - decoding: Set by libavcodec.\
742 */\
743 int coded_picture_number;\
744 /**\
745 * picture number in display order\
746 * - encoding: set by\
747 * - decoding: Set by libavcodec.\
748 */\
749 int display_picture_number;\
750\
751 /**\
752 * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \
753 * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\
754 * - decoding: Set by libavcodec.\
755 */\
756 int quality; \
757\
758 /**\
759 * buffer age (1->was last buffer and dint change, 2->..., ...).\
760 * Set to INT_MAX if the buffer has not been used yet.\
761 * - encoding: unused\
762 * - decoding: MUST be set by get_buffer().\
763 */\
764 int age;\
765\
766 /**\
767 * is this picture used as reference\
768 * The values for this are the same as the MpegEncContext.picture_structure\
769 * variable, that is 1->top field, 2->bottom field, 3->frame/both fields.\
770 * Set to 4 for delayed, non-reference frames.\
771 * - encoding: unused\
772 * - decoding: Set by libavcodec. (before get_buffer() call)).\
773 */\
774 int reference;\
775\
776 /**\
777 * QP table\
778 * - encoding: unused\
779 * - decoding: Set by libavcodec.\
780 */\
781 int8_t *qscale_table;\
782 /**\
783 * QP store stride\
784 * - encoding: unused\
785 * - decoding: Set by libavcodec.\
786 */\
787 int qstride;\
788\
789 /**\
790 * mbskip_table[mb]>=1 if MB didn't change\
791 * stride= mb_width = (width+15)>>4\
792 * - encoding: unused\
793 * - decoding: Set by libavcodec.\
794 */\
795 uint8_t *mbskip_table;\
796\
797 /**\
798 * motion vector table\
799 * @code\
800 * example:\
801 * int mv_sample_log2= 4 - motion_subsample_log2;\
802 * int mb_width= (width+15)>>4;\
803 * int mv_stride= (mb_width << mv_sample_log2) + 1;\
804 * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];\
805 * @endcode\
806 * - encoding: Set by user.\
807 * - decoding: Set by libavcodec.\
808 */\
809 int16_t (*motion_val[2])[2];\
810\
811 /**\
812 * macroblock type table\
813 * mb_type_base + mb_width + 2\
814 * - encoding: Set by user.\
815 * - decoding: Set by libavcodec.\
816 */\
817 uint32_t *mb_type;\
818\
819 /**\
820 * log2 of the size of the block which a single vector in motion_val represents: \
821 * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)\
822 * - encoding: unused\
823 * - decoding: Set by libavcodec.\
824 */\
825 uint8_t motion_subsample_log2;\
826\
827 /**\
828 * for some private data of the user\
829 * - encoding: unused\
830 * - decoding: Set by user.\
831 */\
832 void *opaque;\
833\
834 /**\
835 * error\
836 * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.\
837 * - decoding: unused\
838 */\
839 uint64_t error[4];\
840\
841 /**\
842 * type of the buffer (to keep track of who has to deallocate data[*])\
843 * - encoding: Set by the one who allocates it.\
844 * - decoding: Set by the one who allocates it.\
845 * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.\
846 */\
847 int type;\
848 \
849 /**\
850 * When decoding, this signals how much the picture must be delayed.\
851 * extra_delay = repeat_pict / (2*fps)\
852 * - encoding: unused\
853 * - decoding: Set by libavcodec.\
854 */\
855 int repeat_pict;\
856 \
857 /**\
858 * \
859 */\
860 int qscale_type;\
861 \
862 /**\
863 * The content of the picture is interlaced.\
864 * - encoding: Set by user.\
865 * - decoding: Set by libavcodec. (default 0)\
866 */\
867 int interlaced_frame;\
868 \
869 /**\
870 * If the content is interlaced, is top field displayed first.\
871 * - encoding: Set by user.\
872 * - decoding: Set by libavcodec.\
873 */\
874 int top_field_first;\
875 \
876 /**\
877 * Pan scan.\
878 * - encoding: Set by user.\
879 * - decoding: Set by libavcodec.\
880 */\
881 AVPanScan *pan_scan;\
882 \
883 /**\
884 * Tell user application that palette has changed from previous frame.\
885 * - encoding: ??? (no palette-enabled encoder yet)\
886 * - decoding: Set by libavcodec. (default 0).\
887 */\
888 int palette_has_changed;\
889 \
890 /**\
891 * codec suggestion on buffer type if != 0\
892 * - encoding: unused\
893 * - decoding: Set by libavcodec. (before get_buffer() call)).\
894 */\
895 int buffer_hints;\
896\
897 /**\
898 * DCT coefficients\
899 * - encoding: unused\
900 * - decoding: Set by libavcodec.\
901 */\
902 short *dct_coeff;\
903\
904 /**\
905 * motion reference frame index\
906 * the order in which these are stored can depend on the codec.\
907 * - encoding: Set by user.\
908 * - decoding: Set by libavcodec.\
909 */\
910 int8_t *ref_index[2];\
911\
912 /**\
913 * reordered opaque 64bit number (generally a PTS) from AVCodecContext.reordered_opaque\
914 * output in AVFrame.reordered_opaque\
915 * - encoding: unused\
916 * - decoding: Read by user.\
917 */\
918 int64_t reordered_opaque;\
919\
920 /**\
921 * hardware accelerator private data (FFmpeg allocated)\
922 * - encoding: unused\
923 * - decoding: Set by libavcodec\
924 */\
925 void *hwaccel_picture_private;\
926
927
928#define FF_QSCALE_TYPE_MPEG1 0
929#define FF_QSCALE_TYPE_MPEG2 1
930#define FF_QSCALE_TYPE_H264 2
931#define FF_QSCALE_TYPE_VP56 3
932
933#define FF_BUFFER_TYPE_INTERNAL 1
934#define FF_BUFFER_TYPE_USER 2 ///< direct rendering buffers (image is (de)allocated by user)
935#define FF_BUFFER_TYPE_SHARED 4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared.
936#define FF_BUFFER_TYPE_COPY 8 ///< Just a (modified) copy of some other buffer, don't deallocate anything.
937
938
939#define FF_I_TYPE 1 ///< Intra
940#define FF_P_TYPE 2 ///< Predicted
941#define FF_B_TYPE 3 ///< Bi-dir predicted
942#define FF_S_TYPE 4 ///< S(GMC)-VOP MPEG4
943#define FF_SI_TYPE 5 ///< Switching Intra
944#define FF_SP_TYPE 6 ///< Switching Predicted
945#define FF_BI_TYPE 7
946
947#define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore).
948#define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer.
949#define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content.
950#define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update).
951
952typedef struct AVPacket {
953 /**
954 * Presentation timestamp in AVStream->time_base units; the time at which
955 * the decompressed packet will be presented to the user.
956 * Can be AV_NOPTS_VALUE if it is not stored in the file.
957 * pts MUST be larger or equal to dts as presentation cannot happen before
958 * decompression, unless one wants to view hex dumps. Some formats misuse
959 * the terms dts and pts/cts to mean something different. Such timestamps
960 * must be converted to true pts/dts before they are stored in AVPacket.
961 */
962 int64_t pts;
963 /**
964 * Decompression timestamp in AVStream->time_base units; the time at which
965 * the packet is decompressed.
966 * Can be AV_NOPTS_VALUE if it is not stored in the file.
967 */
968 int64_t dts;
969 uint8_t *data;
970 int size;
971 int stream_index;
972 int flags;
973 /**
974 * Duration of this packet in AVStream->time_base units, 0 if unknown.
975 * Equals next_pts - this_pts in presentation order.
976 */
977 int duration;
978 void (*destruct)(struct AVPacket *);
979 void *priv;
980 int64_t pos; ///< byte position in stream, -1 if unknown
981
982 /**
983 * Time difference in AVStream->time_base units from the pts of this
984 * packet to the point at which the output from the decoder has converged
985 * independent from the availability of previous frames. That is, the
986 * frames are virtually identical no matter if decoding started from
987 * the very first frame or from this keyframe.
988 * Is AV_NOPTS_VALUE if unknown.
989 * This field is not the display duration of the current packet.
990 *
991 * The purpose of this field is to allow seeking in streams that have no
992 * keyframes in the conventional sense. It corresponds to the
993 * recovery point SEI in H.264 and match_time_delta in NUT. It is also
994 * essential for some types of subtitle streams to ensure that all
995 * subtitles are correctly displayed after seeking.
996 */
997 int64_t convergence_duration;
998} AVPacket;
999#define AV_PKT_FLAG_KEY 0x0001
1000#if LIBAVCODEC_VERSION_MAJOR < 53
1001#define PKT_FLAG_KEY AV_PKT_FLAG_KEY
1002#endif
1003
1004/**
1005 * Audio Video Frame.
1006 * New fields can be added to the end of FF_COMMON_FRAME with minor version
1007 * bumps.
1008 * Removal, reordering and changes to existing fields require a major
1009 * version bump. No fields should be added into AVFrame before or after
1010 * FF_COMMON_FRAME!
1011 * sizeof(AVFrame) must not be used outside libav*.
1012 */
1013typedef struct AVFrame {
1014 FF_COMMON_FRAME
1015} AVFrame;
1016
1017/**
1018 * main external API structure.
1019 * New fields can be added to the end with minor version bumps.
1020 * Removal, reordering and changes to existing fields require a major
1021 * version bump.
1022 * sizeof(AVCodecContext) must not be used outside libav*.
1023 */
1024typedef struct AVCodecContext {
1025 /**
1026 * information on struct for av_log
1027 * - set by avcodec_alloc_context
1028 */
1029 const AVClass *av_class;
1030 /**
1031 * the average bitrate
1032 * - encoding: Set by user; unused for constant quantizer encoding.
1033 * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream.
1034 */
1035 int bit_rate;
1036
1037 /**
1038 * number of bits the bitstream is allowed to diverge from the reference.
1039 * the reference can be CBR (for CBR pass1) or VBR (for pass2)
1040 * - encoding: Set by user; unused for constant quantizer encoding.
1041 * - decoding: unused
1042 */
1043 int bit_rate_tolerance;
1044
1045 /**
1046 * CODEC_FLAG_*.
1047 * - encoding: Set by user.
1048 * - decoding: Set by user.
1049 */
1050 int flags;
1051
1052 /**
1053 * Some codecs need additional format info. It is stored here.
1054 * If any muxer uses this then ALL demuxers/parsers AND encoders for the
1055 * specific codec MUST set it correctly otherwise stream copy breaks.
1056 * In general use of this field by muxers is not recommanded.
1057 * - encoding: Set by libavcodec.
1058 * - decoding: Set by libavcodec. (FIXME: Is this OK?)
1059 */
1060 int sub_id;
1061
1062 /**
1063 * Motion estimation algorithm used for video coding.
1064 * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
1065 * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific]
1066 * - encoding: MUST be set by user.
1067 * - decoding: unused
1068 */
1069 int me_method;
1070
1071 /**
1072 * some codecs need / can use extradata like Huffman tables.
1073 * mjpeg: Huffman tables
1074 * rv10: additional flags
1075 * mpeg4: global headers (they can be in the bitstream or here)
1076 * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
1077 * than extradata_size to avoid prolems if it is read with the bitstream reader.
1078 * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
1079 * - encoding: Set/allocated/freed by libavcodec.
1080 * - decoding: Set/allocated/freed by user.
1081 */
1082 uint8_t *extradata;
1083 int extradata_size;
1084
1085 /**
1086 * This is the fundamental unit of time (in seconds) in terms
1087 * of which frame timestamps are represented. For fixed-fps content,
1088 * timebase should be 1/framerate and timestamp increments should be
1089 * identically 1.
1090 * - encoding: MUST be set by user.
1091 * - decoding: Set by libavcodec.
1092 */
1093 AVRational time_base;
1094
1095 /* video only */
1096 /**
1097 * picture width / height.
1098 * - encoding: MUST be set by user.
1099 * - decoding: Set by libavcodec.
1100 * Note: For compatibility it is possible to set this instead of
1101 * coded_width/height before decoding.
1102 */
1103 int width, height;
1104
1105#define FF_ASPECT_EXTENDED 15
1106
1107 /**
1108 * the number of pictures in a group of pictures, or 0 for intra_only
1109 * - encoding: Set by user.
1110 * - decoding: unused
1111 */
1112 int gop_size;
1113
1114 /**
1115 * Pixel format, see PIX_FMT_xxx.
1116 * - encoding: Set by user.
1117 * - decoding: Set by libavcodec.
1118 */
1119 enum PixelFormat pix_fmt;
1120
1121 /**
1122 * Frame rate emulation. If not zero, the lower layer (i.e. format handler)
1123 * has to read frames at native frame rate.
1124 * - encoding: Set by user.
1125 * - decoding: unused
1126 */
1127 int rate_emu;
1128
1129 /**
1130 * If non NULL, 'draw_horiz_band' is called by the libavcodec
1131 * decoder to draw a horizontal band. It improves cache usage. Not
1132 * all codecs can do that. You must check the codec capabilities
1133 * beforehand.
1134 * The function is also used by hardware acceleration APIs.
1135 * It is called at least once during frame decoding to pass
1136 * the data needed for hardware render.
1137 * In that mode instead of pixel data, AVFrame points to
1138 * a structure specific to the acceleration API. The application
1139 * reads the structure and can change some fields to indicate progress
1140 * or mark state.
1141 * - encoding: unused
1142 * - decoding: Set by user.
1143 * @param height the height of the slice
1144 * @param y the y position of the slice
1145 * @param type 1->top field, 2->bottom field, 3->frame
1146 * @param offset offset into the AVFrame.data from which the slice should be read
1147 */
1148 void (*draw_horiz_band)(struct AVCodecContext *s,
1149 const AVFrame *src, int offset[4],
1150 int y, int type, int height);
1151
1152 /* audio only */
1153 int sample_rate; ///< samples per second
1154 int channels; ///< number of audio channels
1155
1156 /**
1157 * audio sample format
1158 * - encoding: Set by user.
1159 * - decoding: Set by libavcodec.
1160 */
1161 enum SampleFormat sample_fmt; ///< sample format
1162
1163 /* The following data should not be initialized. */
1164 /**
1165 * Samples per packet, initialized when calling 'init'.
1166 */
1167 int frame_size;
1168 int frame_number; ///< audio or video frame number
1169#if LIBAVCODEC_VERSION_MAJOR < 53
1170 int real_pict_num; ///< Returns the real picture number of previous encoded frame.
1171#endif
1172
1173 /**
1174 * Number of frames the decoded output will be delayed relative to
1175 * the encoded input.
1176 * - encoding: Set by libavcodec.
1177 * - decoding: unused
1178 */
1179 int delay;
1180
1181 /* - encoding parameters */
1182 float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
1183 float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
1184
1185 /**
1186 * minimum quantizer
1187 * - encoding: Set by user.
1188 * - decoding: unused
1189 */
1190 int qmin;
1191
1192 /**
1193 * maximum quantizer
1194 * - encoding: Set by user.
1195 * - decoding: unused
1196 */
1197 int qmax;
1198
1199 /**
1200 * maximum quantizer difference between frames
1201 * - encoding: Set by user.
1202 * - decoding: unused
1203 */
1204 int max_qdiff;
1205
1206 /**
1207 * maximum number of B-frames between non-B-frames
1208 * Note: The output will be delayed by max_b_frames+1 relative to the input.
1209 * - encoding: Set by user.
1210 * - decoding: unused
1211 */
1212 int max_b_frames;
1213
1214 /**
1215 * qscale factor between IP and B-frames
1216 * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
1217 * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
1218 * - encoding: Set by user.
1219 * - decoding: unused
1220 */
1221 float b_quant_factor;
1222
1223 /** obsolete FIXME remove */
1224 int rc_strategy;
1225#define FF_RC_STRATEGY_XVID 1
1226
1227 int b_frame_strategy;
1228
1229 /**
1230 * hurry up amount
1231 * - encoding: unused
1232 * - decoding: Set by user. 1-> Skip B-frames, 2-> Skip IDCT/dequant too, 5-> Skip everything except header
1233 * @deprecated Deprecated in favor of skip_idct and skip_frame.
1234 */
1235 int hurry_up;
1236
1237 struct AVCodec *codec;
1238
1239 void *priv_data;
1240
1241 int rtp_payload_size; /* The size of the RTP payload: the coder will */
1242 /* do its best to deliver a chunk with size */
1243 /* below rtp_payload_size, the chunk will start */
1244 /* with a start code on some codecs like H.263. */
1245 /* This doesn't take account of any particular */
1246 /* headers inside the transmitted RTP payload. */
1247
1248
1249 /* The RTP callback: This function is called */
1250 /* every time the encoder has a packet to send. */
1251 /* It depends on the encoder if the data starts */
1252 /* with a Start Code (it should). H.263 does. */
1253 /* mb_nb contains the number of macroblocks */
1254 /* encoded in the RTP payload. */
1255 void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
1256
1257 /* statistics, used for 2-pass encoding */
1258 int mv_bits;
1259 int header_bits;
1260 int i_tex_bits;
1261 int p_tex_bits;
1262 int i_count;
1263 int p_count;
1264 int skip_count;
1265 int misc_bits;
1266
1267 /**
1268 * number of bits used for the previously encoded frame
1269 * - encoding: Set by libavcodec.
1270 * - decoding: unused
1271 */
1272 int frame_bits;
1273
1274 /**
1275 * Private data of the user, can be used to carry app specific stuff.
1276 * - encoding: Set by user.
1277 * - decoding: Set by user.
1278 */
1279 void *opaque;
1280
1281 char codec_name[32];
1282 enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
1283 enum CodecID codec_id; /* see CODEC_ID_xxx */
1284
1285 /**
1286 * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
1287 * This is used to work around some encoder bugs.
1288 * A demuxer should set this to what is stored in the field used to identify the codec.
1289 * If there are multiple such fields in a container then the demuxer should choose the one
1290 * which maximizes the information about the used codec.
1291 * If the codec tag field in a container is larger then 32 bits then the demuxer should
1292 * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
1293 * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
1294 * first.
1295 * - encoding: Set by user, if not then the default based on codec_id will be used.
1296 * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
1297 */
1298 unsigned int codec_tag;
1299
1300 /**
1301 * Work around bugs in encoders which sometimes cannot be detected automatically.
1302 * - encoding: Set by user
1303 * - decoding: Set by user
1304 */
1305 int workaround_bugs;
1306#define FF_BUG_AUTODETECT 1 ///< autodetection
1307#define FF_BUG_OLD_MSMPEG4 2
1308#define FF_BUG_XVID_ILACE 4
1309#define FF_BUG_UMP4 8
1310#define FF_BUG_NO_PADDING 16
1311#define FF_BUG_AMV 32
1312#define FF_BUG_AC_VLC 0 ///< Will be removed, libavcodec can now handle these non-compliant files by default.
1313#define FF_BUG_QPEL_CHROMA 64
1314#define FF_BUG_STD_QPEL 128
1315#define FF_BUG_QPEL_CHROMA2 256
1316#define FF_BUG_DIRECT_BLOCKSIZE 512
1317#define FF_BUG_EDGE 1024
1318#define FF_BUG_HPEL_CHROMA 2048
1319#define FF_BUG_DC_CLIP 4096
1320#define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders.
1321#define FF_BUG_TRUNCATED 16384
1322//#define FF_BUG_FAKE_SCALABILITY 16 //Autodetection should work 100%.
1323
1324 /**
1325 * luma single coefficient elimination threshold
1326 * - encoding: Set by user.
1327 * - decoding: unused
1328 */
1329 int luma_elim_threshold;
1330
1331 /**
1332 * chroma single coeff elimination threshold
1333 * - encoding: Set by user.
1334 * - decoding: unused
1335 */
1336 int chroma_elim_threshold;
1337
1338 /**
1339 * strictly follow the standard (MPEG4, ...).
1340 * - encoding: Set by user.
1341 * - decoding: Set by user.
1342 * Setting this to STRICT or higher means the encoder and decoder will
1343 * generally do stupid things. While setting it to inofficial or lower
1344 * will mean the encoder might use things that are not supported by all
1345 * spec compliant decoders. Decoders make no difference between normal,
1346 * inofficial and experimental, that is they always try to decode things
1347 * when they can unless they are explicitly asked to behave stupid
1348 * (=strictly conform to the specs)
1349 */
1350 int strict_std_compliance;
1351#define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to a older more strict version of the spec or reference software.
1352#define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences.
1353#define FF_COMPLIANCE_NORMAL 0
1354#define FF_COMPLIANCE_INOFFICIAL -1 ///< Allow inofficial extensions.
1355#define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
1356
1357 /**
1358 * qscale offset between IP and B-frames
1359 * - encoding: Set by user.
1360 * - decoding: unused
1361 */
1362 float b_quant_offset;
1363
1364 /**
1365 * Error recognization; higher values will detect more errors but may
1366 * misdetect some more or less valid parts as errors.
1367 * - encoding: unused
1368 * - decoding: Set by user.
1369 */
1370 int error_recognition;
1371#define FF_ER_CAREFUL 1
1372#define FF_ER_COMPLIANT 2
1373#define FF_ER_AGGRESSIVE 3
1374#define FF_ER_VERY_AGGRESSIVE 4
1375
1376 /**
1377 * Called at the beginning of each frame to get a buffer for it.
1378 * If pic.reference is set then the frame will be read later by libavcodec.
1379 * avcodec_align_dimensions2() should be used to find the required width and
1380 * height, as they normally need to be rounded up to the next multiple of 16.
1381 * if CODEC_CAP_DR1 is not set then get_buffer() must call
1382 * avcodec_default_get_buffer() instead of providing buffers allocated by
1383 * some other means.
1384 * - encoding: unused
1385 * - decoding: Set by libavcodec., user can override.
1386 */
1387 int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
1388
1389 /**
1390 * Called to release buffers which were allocated with get_buffer.
1391 * A released buffer can be reused in get_buffer().
1392 * pic.data[*] must be set to NULL.
1393 * - encoding: unused
1394 * - decoding: Set by libavcodec., user can override.
1395 */
1396 void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
1397
1398 /**
1399 * Size of the frame reordering buffer in the decoder.
1400 * For MPEG-2 it is 1 IPB or 0 low delay IP.
1401 * - encoding: Set by libavcodec.
1402 * - decoding: Set by libavcodec.
1403 */
1404 int has_b_frames;
1405
1406 /**
1407 * number of bytes per packet if constant and known or 0
1408 * Used by some WAV based audio codecs.
1409 */
1410 int block_align;
1411
1412 int parse_only; /* - decoding only: If true, only parsing is done
1413 (function avcodec_parse_frame()). The frame
1414 data is returned. Only MPEG codecs support this now. */
1415
1416 /**
1417 * 0-> h263 quant 1-> mpeg quant
1418 * - encoding: Set by user.
1419 * - decoding: unused
1420 */
1421 int mpeg_quant;
1422
1423 /**
1424 * pass1 encoding statistics output buffer
1425 * - encoding: Set by libavcodec.
1426 * - decoding: unused
1427 */
1428 char *stats_out;
1429
1430 /**
1431 * pass2 encoding statistics input buffer
1432 * Concatenated stuff from stats_out of pass1 should be placed here.
1433 * - encoding: Allocated/set/freed by user.
1434 * - decoding: unused
1435 */
1436 char *stats_in;
1437
1438 /**
1439 * ratecontrol qmin qmax limiting method
1440 * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax.
1441 * - encoding: Set by user.
1442 * - decoding: unused
1443 */
1444 float rc_qsquish;
1445
1446 float rc_qmod_amp;
1447 int rc_qmod_freq;
1448
1449 /**
1450 * ratecontrol override, see RcOverride
1451 * - encoding: Allocated/set/freed by user.
1452 * - decoding: unused
1453 */
1454 RcOverride *rc_override;
1455 int rc_override_count;
1456
1457 /**
1458 * rate control equation
1459 * - encoding: Set by user
1460 * - decoding: unused
1461 */
1462 const char *rc_eq;
1463
1464 /**
1465 * maximum bitrate
1466 * - encoding: Set by user.
1467 * - decoding: unused
1468 */
1469 int rc_max_rate;
1470
1471 /**
1472 * minimum bitrate
1473 * - encoding: Set by user.
1474 * - decoding: unused
1475 */
1476 int rc_min_rate;
1477
1478 /**
1479 * decoder bitstream buffer size
1480 * - encoding: Set by user.
1481 * - decoding: unused
1482 */
1483 int rc_buffer_size;
1484 float rc_buffer_aggressivity;
1485
1486 /**
1487 * qscale factor between P and I-frames
1488 * If > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset).
1489 * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
1490 * - encoding: Set by user.
1491 * - decoding: unused
1492 */
1493 float i_quant_factor;
1494
1495 /**
1496 * qscale offset between P and I-frames
1497 * - encoding: Set by user.
1498 * - decoding: unused
1499 */
1500 float i_quant_offset;
1501
1502 /**
1503 * initial complexity for pass1 ratecontrol
1504 * - encoding: Set by user.
1505 * - decoding: unused
1506 */
1507 float rc_initial_cplx;
1508
1509 /**
1510 * DCT algorithm, see FF_DCT_* below
1511 * - encoding: Set by user.
1512 * - decoding: unused
1513 */
1514 int dct_algo;
1515#define FF_DCT_AUTO 0
1516#define FF_DCT_FASTINT 1
1517#define FF_DCT_INT 2
1518#define FF_DCT_MMX 3
1519#define FF_DCT_MLIB 4
1520#define FF_DCT_ALTIVEC 5
1521#define FF_DCT_FAAN 6
1522
1523 /**
1524 * luminance masking (0-> disabled)
1525 * - encoding: Set by user.
1526 * - decoding: unused
1527 */
1528 float lumi_masking;
1529
1530 /**
1531 * temporary complexity masking (0-> disabled)
1532 * - encoding: Set by user.
1533 * - decoding: unused
1534 */
1535 float temporal_cplx_masking;
1536
1537 /**
1538 * spatial complexity masking (0-> disabled)
1539 * - encoding: Set by user.
1540 * - decoding: unused
1541 */
1542 float spatial_cplx_masking;
1543
1544 /**
1545 * p block masking (0-> disabled)
1546 * - encoding: Set by user.
1547 * - decoding: unused
1548 */
1549 float p_masking;
1550
1551 /**
1552 * darkness masking (0-> disabled)
1553 * - encoding: Set by user.
1554 * - decoding: unused
1555 */
1556 float dark_masking;
1557
1558 /**
1559 * IDCT algorithm, see FF_IDCT_* below.
1560 * - encoding: Set by user.
1561 * - decoding: Set by user.
1562 */
1563 int idct_algo;
1564#define FF_IDCT_AUTO 0
1565#define FF_IDCT_INT 1
1566#define FF_IDCT_SIMPLE 2
1567#define FF_IDCT_SIMPLEMMX 3
1568#define FF_IDCT_LIBMPEG2MMX 4
1569#define FF_IDCT_PS2 5
1570#define FF_IDCT_MLIB 6
1571#define FF_IDCT_ARM 7
1572#define FF_IDCT_ALTIVEC 8
1573#define FF_IDCT_SH4 9
1574#define FF_IDCT_SIMPLEARM 10
1575#define FF_IDCT_H264 11
1576#define FF_IDCT_VP3 12
1577#define FF_IDCT_IPP 13
1578#define FF_IDCT_XVIDMMX 14
1579#define FF_IDCT_CAVS 15
1580#define FF_IDCT_SIMPLEARMV5TE 16
1581#define FF_IDCT_SIMPLEARMV6 17
1582#define FF_IDCT_SIMPLEVIS 18
1583#define FF_IDCT_WMV2 19
1584#define FF_IDCT_FAAN 20
1585#define FF_IDCT_EA 21
1586#define FF_IDCT_SIMPLENEON 22
1587#define FF_IDCT_SIMPLEALPHA 23
1588#define FF_IDCT_BINK 24
1589
1590 /**
1591 * slice count
1592 * - encoding: Set by libavcodec.
1593 * - decoding: Set by user (or 0).
1594 */
1595 int slice_count;
1596 /**
1597 * slice offsets in the frame in bytes
1598 * - encoding: Set/allocated by libavcodec.
1599 * - decoding: Set/allocated by user (or NULL).
1600 */
1601 int *slice_offset;
1602
1603 /**
1604 * error concealment flags
1605 * - encoding: unused
1606 * - decoding: Set by user.
1607 */
1608 int error_concealment;
1609#define FF_EC_GUESS_MVS 1
1610#define FF_EC_DEBLOCK 2
1611
1612 /**
1613 * dsp_mask could be add used to disable unwanted CPU features
1614 * CPU features (i.e. MMX, SSE. ...)
1615 *
1616 * With the FORCE flag you may instead enable given CPU features.
1617 * (Dangerous: Usable in case of misdetection, improper usage however will
1618 * result into program crash.)
1619 */
1620 unsigned dsp_mask;
1621#define FF_MM_FORCE 0x80000000 /* Force usage of selected flags (OR) */
1622 /* lower 16 bits - CPU features */
1623#define FF_MM_MMX 0x0001 ///< standard MMX
1624#define FF_MM_3DNOW 0x0004 ///< AMD 3DNOW
1625#if LIBAVCODEC_VERSION_MAJOR < 53
1626#define FF_MM_MMXEXT 0x0002 ///< SSE integer functions or AMD MMX ext
1627#endif
1628#define FF_MM_MMX2 0x0002 ///< SSE integer functions or AMD MMX ext
1629#define FF_MM_SSE 0x0008 ///< SSE functions
1630#define FF_MM_SSE2 0x0010 ///< PIV SSE2 functions
1631#define FF_MM_3DNOWEXT 0x0020 ///< AMD 3DNowExt
1632#define FF_MM_SSE3 0x0040 ///< Prescott SSE3 functions
1633#define FF_MM_SSSE3 0x0080 ///< Conroe SSSE3 functions
1634#define FF_MM_SSE4 0x0100 ///< Penryn SSE4.1 functions
1635#define FF_MM_SSE42 0x0200 ///< Nehalem SSE4.2 functions
1636#define FF_MM_IWMMXT 0x0100 ///< XScale IWMMXT
1637#define FF_MM_ALTIVEC 0x0001 ///< standard AltiVec
1638
1639 /**
1640 * bits per sample/pixel from the demuxer (needed for huffyuv).
1641 * - encoding: Set by libavcodec.
1642 * - decoding: Set by user.
1643 */
1644 int bits_per_coded_sample;
1645
1646 /**
1647 * prediction method (needed for huffyuv)
1648 * - encoding: Set by user.
1649 * - decoding: unused
1650 */
1651 int prediction_method;
1652#define FF_PRED_LEFT 0
1653#define FF_PRED_PLANE 1
1654#define FF_PRED_MEDIAN 2
1655
1656 /**
1657 * sample aspect ratio (0 if unknown)
1658 * That is the width of a pixel divided by the height of the pixel.
1659 * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
1660 * - encoding: Set by user.
1661 * - decoding: Set by libavcodec.
1662 */
1663 AVRational sample_aspect_ratio;
1664
1665 /**
1666 * the picture in the bitstream
1667 * - encoding: Set by libavcodec.
1668 * - decoding: Set by libavcodec.
1669 */
1670 AVFrame *coded_frame;
1671
1672 /**
1673 * debug
1674 * - encoding: Set by user.
1675 * - decoding: Set by user.
1676 */
1677 int debug;
1678#define FF_DEBUG_PICT_INFO 1
1679#define FF_DEBUG_RC 2
1680#define FF_DEBUG_BITSTREAM 4
1681#define FF_DEBUG_MB_TYPE 8
1682#define FF_DEBUG_QP 16
1683#define FF_DEBUG_MV 32
1684#define FF_DEBUG_DCT_COEFF 0x00000040
1685#define FF_DEBUG_SKIP 0x00000080
1686#define FF_DEBUG_STARTCODE 0x00000100
1687#define FF_DEBUG_PTS 0x00000200
1688#define FF_DEBUG_ER 0x00000400
1689#define FF_DEBUG_MMCO 0x00000800
1690#define FF_DEBUG_BUGS 0x00001000
1691#define FF_DEBUG_VIS_QP 0x00002000
1692#define FF_DEBUG_VIS_MB_TYPE 0x00004000
1693#define FF_DEBUG_BUFFERS 0x00008000
1694
1695 /**
1696 * debug
1697 * - encoding: Set by user.
1698 * - decoding: Set by user.
1699 */
1700 int debug_mv;
1701#define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames
1702#define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames
1703#define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
1704
1705 /**
1706 * error
1707 * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR.
1708 * - decoding: unused
1709 */
1710 uint64_t error[4];
1711
1712 /**
1713 * minimum MB quantizer
1714 * - encoding: unused
1715 * - decoding: unused
1716 */
1717 int mb_qmin;
1718
1719 /**
1720 * maximum MB quantizer
1721 * - encoding: unused
1722 * - decoding: unused
1723 */
1724 int mb_qmax;
1725
1726 /**
1727 * motion estimation comparison function
1728 * - encoding: Set by user.
1729 * - decoding: unused
1730 */
1731 int me_cmp;
1732 /**
1733 * subpixel motion estimation comparison function
1734 * - encoding: Set by user.
1735 * - decoding: unused
1736 */
1737 int me_sub_cmp;
1738 /**
1739 * macroblock comparison function (not supported yet)
1740 * - encoding: Set by user.
1741 * - decoding: unused
1742 */
1743 int mb_cmp;
1744 /**
1745 * interlaced DCT comparison function
1746 * - encoding: Set by user.
1747 * - decoding: unused
1748 */
1749 int ildct_cmp;
1750#define FF_CMP_SAD 0
1751#define FF_CMP_SSE 1
1752#define FF_CMP_SATD 2
1753#define FF_CMP_DCT 3
1754#define FF_CMP_PSNR 4
1755#define FF_CMP_BIT 5
1756#define FF_CMP_RD 6
1757#define FF_CMP_ZERO 7
1758#define FF_CMP_VSAD 8
1759#define FF_CMP_VSSE 9
1760#define FF_CMP_NSSE 10
1761#define FF_CMP_W53 11
1762#define FF_CMP_W97 12
1763#define FF_CMP_DCTMAX 13
1764#define FF_CMP_DCT264 14
1765#define FF_CMP_CHROMA 256
1766
1767 /**
1768 * ME diamond size & shape
1769 * - encoding: Set by user.
1770 * - decoding: unused
1771 */
1772 int dia_size;
1773
1774 /**
1775 * amount of previous MV predictors (2a+1 x 2a+1 square)
1776 * - encoding: Set by user.
1777 * - decoding: unused
1778 */
1779 int last_predictor_count;
1780
1781 /**
1782 * prepass for motion estimation
1783 * - encoding: Set by user.
1784 * - decoding: unused
1785 */
1786 int pre_me;
1787
1788 /**
1789 * motion estimation prepass comparison function
1790 * - encoding: Set by user.
1791 * - decoding: unused
1792 */
1793 int me_pre_cmp;
1794
1795 /**
1796 * ME prepass diamond size & shape
1797 * - encoding: Set by user.
1798 * - decoding: unused
1799 */
1800 int pre_dia_size;
1801
1802 /**
1803 * subpel ME quality
1804 * - encoding: Set by user.
1805 * - decoding: unused
1806 */
1807 int me_subpel_quality;
1808
1809 /**
1810 * callback to negotiate the pixelFormat
1811 * @param fmt is the list of formats which are supported by the codec,
1812 * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
1813 * The first is always the native one.
1814 * @return the chosen format
1815 * - encoding: unused
1816 * - decoding: Set by user, if not set the native format will be chosen.
1817 */
1818 enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt);
1819
1820 /**
1821 * DTG active format information (additional aspect ratio
1822 * information only used in DVB MPEG-2 transport streams)
1823 * 0 if not set.
1824 *
1825 * - encoding: unused
1826 * - decoding: Set by decoder.
1827 */
1828 int dtg_active_format;
1829#define FF_DTG_AFD_SAME 8
1830#define FF_DTG_AFD_4_3 9
1831#define FF_DTG_AFD_16_9 10
1832#define FF_DTG_AFD_14_9 11
1833#define FF_DTG_AFD_4_3_SP_14_9 13
1834#define FF_DTG_AFD_16_9_SP_14_9 14
1835#define FF_DTG_AFD_SP_4_3 15
1836
1837 /**
1838 * maximum motion estimation search range in subpel units
1839 * If 0 then no limit.
1840 *
1841 * - encoding: Set by user.
1842 * - decoding: unused
1843 */
1844 int me_range;
1845
1846 /**
1847 * intra quantizer bias
1848 * - encoding: Set by user.
1849 * - decoding: unused
1850 */
1851 int intra_quant_bias;
1852#define FF_DEFAULT_QUANT_BIAS 999999
1853
1854 /**
1855 * inter quantizer bias
1856 * - encoding: Set by user.
1857 * - decoding: unused
1858 */
1859 int inter_quant_bias;
1860
1861 /**
1862 * color table ID
1863 * - encoding: unused
1864 * - decoding: Which clrtable should be used for 8bit RGB images.
1865 * Tables have to be stored somewhere. FIXME
1866 */
1867 int color_table_id;
1868
1869 /**
1870 * internal_buffer count
1871 * Don't touch, used by libavcodec default_get_buffer().
1872 */
1873 int internal_buffer_count;
1874
1875 /**
1876 * internal_buffers
1877 * Don't touch, used by libavcodec default_get_buffer().
1878 */
1879 void *internal_buffer;
1880
1881#define FF_LAMBDA_SHIFT 7
1882#define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT)
1883#define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
1884#define FF_LAMBDA_MAX (256*128-1)
1885
1886#define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove
1887 /**
1888 * Global quality for codecs which cannot change it per frame.
1889 * This should be proportional to MPEG-1/2/4 qscale.
1890 * - encoding: Set by user.
1891 * - decoding: unused
1892 */
1893 int global_quality;
1894
1895#define FF_CODER_TYPE_VLC 0
1896#define FF_CODER_TYPE_AC 1
1897#define FF_CODER_TYPE_RAW 2
1898#define FF_CODER_TYPE_RLE 3
1899#define FF_CODER_TYPE_DEFLATE 4
1900 /**
1901 * coder type
1902 * - encoding: Set by user.
1903 * - decoding: unused
1904 */
1905 int coder_type;
1906
1907 /**
1908 * context model
1909 * - encoding: Set by user.
1910 * - decoding: unused
1911 */
1912 int context_model;
1913#if 0
1914 /**
1915 *
1916 * - encoding: unused
1917 * - decoding: Set by user.
1918 */
1919 uint8_t * (*realloc)(struct AVCodecContext *s, uint8_t *buf, int buf_size);
1920#endif
1921
1922 /**
1923 * slice flags
1924 * - encoding: unused
1925 * - decoding: Set by user.
1926 */
1927 int slice_flags;
1928#define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
1929#define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
1930#define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
1931
1932 /**
1933 * XVideo Motion Acceleration
1934 * - encoding: forbidden
1935 * - decoding: set by decoder
1936 */
1937 int xvmc_acceleration;
1938
1939 /**
1940 * macroblock decision mode
1941 * - encoding: Set by user.
1942 * - decoding: unused
1943 */
1944 int mb_decision;
1945#define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
1946#define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
1947#define FF_MB_DECISION_RD 2 ///< rate distortion
1948
1949 /**
1950 * custom intra quantization matrix
1951 * - encoding: Set by user, can be NULL.
1952 * - decoding: Set by libavcodec.
1953 */
1954 uint16_t *intra_matrix;
1955
1956 /**
1957 * custom inter quantization matrix
1958 * - encoding: Set by user, can be NULL.
1959 * - decoding: Set by libavcodec.
1960 */
1961 uint16_t *inter_matrix;
1962
1963 /**
1964 * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
1965 * This is used to work around some encoder bugs.
1966 * - encoding: unused
1967 * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
1968 */
1969 unsigned int stream_codec_tag;
1970
1971 /**
1972 * scene change detection threshold
1973 * 0 is default, larger means fewer detected scene changes.
1974 * - encoding: Set by user.
1975 * - decoding: unused
1976 */
1977 int scenechange_threshold;
1978
1979 /**
1980 * minimum Lagrange multipler
1981 * - encoding: Set by user.
1982 * - decoding: unused
1983 */
1984 int lmin;
1985
1986 /**
1987 * maximum Lagrange multipler
1988 * - encoding: Set by user.
1989 * - decoding: unused
1990 */
1991 int lmax;
1992
1993 /**
1994 * palette control structure
1995 * - encoding: ??? (no palette-enabled encoder yet)
1996 * - decoding: Set by user.
1997 */
1998 struct AVPaletteControl *palctrl;
1999
2000 /**
2001 * noise reduction strength
2002 * - encoding: Set by user.
2003 * - decoding: unused
2004 */
2005 int noise_reduction;
2006
2007 /**
2008 * Called at the beginning of a frame to get cr buffer for it.
2009 * Buffer type (size, hints) must be the same. libavcodec won't check it.
2010 * libavcodec will pass previous buffer in pic, function should return
2011 * same buffer or new buffer with old frame "painted" into it.
2012 * If pic.data[0] == NULL must behave like get_buffer().
2013 * if CODEC_CAP_DR1 is not set then reget_buffer() must call
2014 * avcodec_default_reget_buffer() instead of providing buffers allocated by
2015 * some other means.
2016 * - encoding: unused
2017 * - decoding: Set by libavcodec., user can override
2018 */
2019 int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
2020
2021 /**
2022 * Number of bits which should be loaded into the rc buffer before decoding starts.
2023 * - encoding: Set by user.
2024 * - decoding: unused
2025 */
2026 int rc_initial_buffer_occupancy;
2027
2028 /**
2029 *
2030 * - encoding: Set by user.
2031 * - decoding: unused
2032 */
2033 int inter_threshold;
2034
2035 /**
2036 * CODEC_FLAG2_*
2037 * - encoding: Set by user.
2038 * - decoding: Set by user.
2039 */
2040 int flags2;
2041
2042 /**
2043 * Simulates errors in the bitstream to test error concealment.
2044 * - encoding: Set by user.
2045 * - decoding: unused
2046 */
2047 int error_rate;
2048
2049 /**
2050 * MP3 antialias algorithm, see FF_AA_* below.
2051 * - encoding: unused
2052 * - decoding: Set by user.
2053 */
2054 int antialias_algo;
2055#define FF_AA_AUTO 0
2056#define FF_AA_FASTINT 1 //not implemented yet
2057#define FF_AA_INT 2
2058#define FF_AA_FLOAT 3
2059 /**
2060 * quantizer noise shaping
2061 * - encoding: Set by user.
2062 * - decoding: unused
2063 */
2064 int quantizer_noise_shaping;
2065
2066 /**
2067 * thread count
2068 * is used to decide how many independent tasks should be passed to execute()
2069 * - encoding: Set by user.
2070 * - decoding: Set by user.
2071 */
2072 int thread_count;
2073
2074 /**
2075 * The codec may call this to execute several independent things.
2076 * It will return only after finishing all tasks.
2077 * The user may replace this with some multithreaded implementation,
2078 * the default implementation will execute the parts serially.
2079 * @param count the number of things to execute
2080 * - encoding: Set by libavcodec, user can override.
2081 * - decoding: Set by libavcodec, user can override.
2082 */
2083 int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
2084
2085 /**
2086 * thread opaque
2087 * Can be used by execute() to store some per AVCodecContext stuff.
2088 * - encoding: set by execute()
2089 * - decoding: set by execute()
2090 */
2091 void *thread_opaque;
2092
2093 /**
2094 * Motion estimation threshold below which no motion estimation is
2095 * performed, but instead the user specified motion vectors are used.
2096 *
2097 * - encoding: Set by user.
2098 * - decoding: unused
2099 */
2100 int me_threshold;
2101
2102 /**
2103 * Macroblock threshold below which the user specified macroblock types will be used.
2104 * - encoding: Set by user.
2105 * - decoding: unused
2106 */
2107 int mb_threshold;
2108
2109 /**
2110 * precision of the intra DC coefficient - 8
2111 * - encoding: Set by user.
2112 * - decoding: unused
2113 */
2114 int intra_dc_precision;
2115
2116 /**
2117 * noise vs. sse weight for the nsse comparsion function
2118 * - encoding: Set by user.
2119 * - decoding: unused
2120 */
2121 int nsse_weight;
2122
2123 /**
2124 * Number of macroblock rows at the top which are skipped.
2125 * - encoding: unused
2126 * - decoding: Set by user.
2127 */
2128 int skip_top;
2129
2130 /**
2131 * Number of macroblock rows at the bottom which are skipped.
2132 * - encoding: unused
2133 * - decoding: Set by user.
2134 */
2135 int skip_bottom;
2136
2137 /**
2138 * profile
2139 * - encoding: Set by user.
2140 * - decoding: Set by libavcodec.
2141 */
2142 int profile;
2143#define FF_PROFILE_UNKNOWN -99
2144
2145#define FF_PROFILE_AAC_MAIN 0
2146#define FF_PROFILE_AAC_LOW 1
2147#define FF_PROFILE_AAC_SSR 2
2148#define FF_PROFILE_AAC_LTP 3
2149
2150#define FF_PROFILE_H264_BASELINE 66
2151#define FF_PROFILE_H264_MAIN 77
2152#define FF_PROFILE_H264_EXTENDED 88
2153#define FF_PROFILE_H264_HIGH 100
2154#define FF_PROFILE_H264_HIGH_10 110
2155#define FF_PROFILE_H264_HIGH_422 122
2156#define FF_PROFILE_H264_HIGH_444 244
2157#define FF_PROFILE_H264_CAVLC_444 44
2158
2159 /**
2160 * level
2161 * - encoding: Set by user.
2162 * - decoding: Set by libavcodec.
2163 */
2164 int level;
2165#define FF_LEVEL_UNKNOWN -99
2166
2167 /**
2168 * low resolution decoding, 1-> 1/2 size, 2->1/4 size
2169 * - encoding: unused
2170 * - decoding: Set by user.
2171 */
2172 int lowres;
2173
2174 /**
2175 * Bitstream width / height, may be different from width/height if lowres
2176 * or other things are used.
2177 * - encoding: unused
2178 * - decoding: Set by user before init if known. Codec should override / dynamically change if needed.
2179 */
2180 int coded_width, coded_height;
2181
2182 /**
2183 * frame skip threshold
2184 * - encoding: Set by user.
2185 * - decoding: unused
2186 */
2187 int frame_skip_threshold;
2188
2189 /**
2190 * frame skip factor
2191 * - encoding: Set by user.
2192 * - decoding: unused
2193 */
2194 int frame_skip_factor;
2195
2196 /**
2197 * frame skip exponent
2198 * - encoding: Set by user.
2199 * - decoding: unused
2200 */
2201 int frame_skip_exp;
2202
2203 /**
2204 * frame skip comparison function
2205 * - encoding: Set by user.
2206 * - decoding: unused
2207 */
2208 int frame_skip_cmp;
2209
2210 /**
2211 * Border processing masking, raises the quantizer for mbs on the borders
2212 * of the picture.
2213 * - encoding: Set by user.
2214 * - decoding: unused
2215 */
2216 float border_masking;
2217
2218 /**
2219 * minimum MB lagrange multipler
2220 * - encoding: Set by user.
2221 * - decoding: unused
2222 */
2223 int mb_lmin;
2224
2225 /**
2226 * maximum MB lagrange multipler
2227 * - encoding: Set by user.
2228 * - decoding: unused
2229 */
2230 int mb_lmax;
2231
2232 /**
2233 *
2234 * - encoding: Set by user.
2235 * - decoding: unused
2236 */
2237 int me_penalty_compensation;
2238
2239 /**
2240 *
2241 * - encoding: unused
2242 * - decoding: Set by user.
2243 */
2244 enum AVDiscard skip_loop_filter;
2245
2246 /**
2247 *
2248 * - encoding: unused
2249 * - decoding: Set by user.
2250 */
2251 enum AVDiscard skip_idct;
2252
2253 /**
2254 *
2255 * - encoding: unused
2256 * - decoding: Set by user.
2257 */
2258 enum AVDiscard skip_frame;
2259
2260 /**
2261 *
2262 * - encoding: Set by user.
2263 * - decoding: unused
2264 */
2265 int bidir_refine;
2266
2267 /**
2268 *
2269 * - encoding: Set by user.
2270 * - decoding: unused
2271 */
2272 int brd_scale;
2273
2274 /**
2275 * constant rate factor - quality-based VBR - values ~correspond to qps
2276 * - encoding: Set by user.
2277 * - decoding: unused
2278 */
2279 float crf;
2280
2281 /**
2282 * constant quantization parameter rate control method
2283 * - encoding: Set by user.
2284 * - decoding: unused
2285 */
2286 int cqp;
2287
2288 /**
2289 * minimum GOP size
2290 * - encoding: Set by user.
2291 * - decoding: unused
2292 */
2293 int keyint_min;
2294
2295 /**
2296 * number of reference frames
2297 * - encoding: Set by user.
2298 * - decoding: Set by lavc.
2299 */
2300 int refs;
2301
2302 /**
2303 * chroma qp offset from luma
2304 * - encoding: Set by user.
2305 * - decoding: unused
2306 */
2307 int chromaoffset;
2308
2309 /**
2310 * Influences how often B-frames are used.
2311 * - encoding: Set by user.
2312 * - decoding: unused
2313 */
2314 int bframebias;
2315
2316 /**
2317 * trellis RD quantization
2318 * - encoding: Set by user.
2319 * - decoding: unused
2320 */
2321 int trellis;
2322
2323 /**
2324 * Reduce fluctuations in qp (before curve compression).
2325 * - encoding: Set by user.
2326 * - decoding: unused
2327 */
2328 float complexityblur;
2329
2330 /**
2331 * in-loop deblocking filter alphac0 parameter
2332 * alpha is in the range -6...6
2333 * - encoding: Set by user.
2334 * - decoding: unused
2335 */
2336 int deblockalpha;
2337
2338 /**
2339 * in-loop deblocking filter beta parameter
2340 * beta is in the range -6...6
2341 * - encoding: Set by user.
2342 * - decoding: unused
2343 */
2344 int deblockbeta;
2345
2346 /**
2347 * macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4
2348 * - encoding: Set by user.
2349 * - decoding: unused
2350 */
2351 int partitions;
2352#define X264_PART_I4X4 0x001 /* Analyze i4x4 */
2353#define X264_PART_I8X8 0x002 /* Analyze i8x8 (requires 8x8 transform) */
2354#define X264_PART_P8X8 0x010 /* Analyze p16x8, p8x16 and p8x8 */
2355#define X264_PART_P4X4 0x020 /* Analyze p8x4, p4x8, p4x4 */
2356#define X264_PART_B8X8 0x100 /* Analyze b16x8, b8x16 and b8x8 */
2357
2358 /**
2359 * direct MV prediction mode - 0 (none), 1 (spatial), 2 (temporal), 3 (auto)
2360 * - encoding: Set by user.
2361 * - decoding: unused
2362 */
2363 int directpred;
2364
2365 /**
2366 * Audio cutoff bandwidth (0 means "automatic")
2367 * - encoding: Set by user.
2368 * - decoding: unused
2369 */
2370 int cutoff;
2371
2372 /**
2373 * Multiplied by qscale for each frame and added to scene_change_score.
2374 * - encoding: Set by user.
2375 * - decoding: unused
2376 */
2377 int scenechange_factor;
2378
2379 /**
2380 *
2381 * Note: Value depends upon the compare function used for fullpel ME.
2382 * - encoding: Set by user.
2383 * - decoding: unused
2384 */
2385 int mv0_threshold;
2386
2387 /**
2388 * Adjusts sensitivity of b_frame_strategy 1.
2389 * - encoding: Set by user.
2390 * - decoding: unused
2391 */
2392 int b_sensitivity;
2393
2394 /**
2395 * - encoding: Set by user.
2396 * - decoding: unused
2397 */
2398 int compression_level;
2399#define FF_COMPRESSION_DEFAULT -1
2400
2401 /**
2402 * Sets whether to use LPC mode - used by FLAC encoder.
2403 * - encoding: Set by user.
2404 * - decoding: unused
2405 */
2406 int use_lpc;
2407
2408 /**
2409 * LPC coefficient precision - used by FLAC encoder
2410 * - encoding: Set by user.
2411 * - decoding: unused
2412 */
2413 int lpc_coeff_precision;
2414
2415 /**
2416 * - encoding: Set by user.
2417 * - decoding: unused
2418 */
2419 int min_prediction_order;
2420
2421 /**
2422 * - encoding: Set by user.
2423 * - decoding: unused
2424 */
2425 int max_prediction_order;
2426
2427 /**
2428 * search method for selecting prediction order
2429 * - encoding: Set by user.
2430 * - decoding: unused
2431 */
2432 int prediction_order_method;
2433
2434 /**
2435 * - encoding: Set by user.
2436 * - decoding: unused
2437 */
2438 int min_partition_order;
2439
2440 /**
2441 * - encoding: Set by user.
2442 * - decoding: unused
2443 */
2444 int max_partition_order;
2445
2446 /**
2447 * GOP timecode frame start number, in non drop frame format
2448 * - encoding: Set by user.
2449 * - decoding: unused
2450 */
2451 int64_t timecode_frame_start;
2452
2453#if LIBAVCODEC_VERSION_MAJOR < 53
2454 /**
2455 * Decoder should decode to this many channels if it can (0 for default)
2456 * - encoding: unused
2457 * - decoding: Set by user.
2458 * @deprecated Deprecated in favor of request_channel_layout.
2459 */
2460 int request_channels;
2461#endif
2462
2463 /**
2464 * Percentage of dynamic range compression to be applied by the decoder.
2465 * The default value is 1.0, corresponding to full compression.
2466 * - encoding: unused
2467 * - decoding: Set by user.
2468 */
2469 float drc_scale;
2470
2471 /**
2472 * opaque 64bit number (generally a PTS) that will be reordered and
2473 * output in AVFrame.reordered_opaque
2474 * - encoding: unused
2475 * - decoding: Set by user.
2476 */
2477 int64_t reordered_opaque;
2478
2479 /**
2480 * Bits per sample/pixel of internal libavcodec pixel/sample format.
2481 * This field is applicable only when sample_fmt is SAMPLE_FMT_S32.
2482 * - encoding: set by user.
2483 * - decoding: set by libavcodec.
2484 */
2485 int bits_per_raw_sample;
2486
2487 /**
2488 * Audio channel layout.
2489 * - encoding: set by user.
2490 * - decoding: set by libavcodec.
2491 */
2492 int64_t channel_layout;
2493
2494 /**
2495 * Request decoder to use this channel layout if it can (0 for default)
2496 * - encoding: unused
2497 * - decoding: Set by user.
2498 */
2499 int64_t request_channel_layout;
2500
2501 /**
2502 * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
2503 * - encoding: Set by user.
2504 * - decoding: unused.
2505 */
2506 float rc_max_available_vbv_use;
2507
2508 /**
2509 * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
2510 * - encoding: Set by user.
2511 * - decoding: unused.
2512 */
2513 float rc_min_vbv_overflow_use;
2514
2515 /**
2516 * Hardware accelerator in use
2517 * - encoding: unused.
2518 * - decoding: Set by libavcodec
2519 */
2520 struct AVHWAccel *hwaccel;
2521
2522 /**
2523 * For some codecs, the time base is closer to the field rate than the frame rate.
2524 * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
2525 * if no telecine is used ...
2526 *
2527 * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
2528 */
2529 int ticks_per_frame;
2530
2531 /**
2532 * Hardware accelerator context.
2533 * For some hardware accelerators, a global context needs to be
2534 * provided by the user. In that case, this holds display-dependent
2535 * data FFmpeg cannot instantiate itself. Please refer to the
2536 * FFmpeg HW accelerator documentation to know how to fill this
2537 * is. e.g. for VA API, this is a struct vaapi_context.
2538 * - encoding: unused
2539 * - decoding: Set by user
2540 */
2541 void *hwaccel_context;
2542
2543 /**
2544 * Chromaticity coordinates of the source primaries.
2545 * - encoding: Set by user
2546 * - decoding: Set by libavcodec
2547 */
2548 enum AVColorPrimaries color_primaries;
2549
2550 /**
2551 * Color Transfer Characteristic.
2552 * - encoding: Set by user
2553 * - decoding: Set by libavcodec
2554 */
2555 enum AVColorTransferCharacteristic color_trc;
2556
2557 /**
2558 * YUV colorspace type.
2559 * - encoding: Set by user
2560 * - decoding: Set by libavcodec
2561 */
2562 enum AVColorSpace colorspace;
2563
2564 /**
2565 * MPEG vs JPEG YUV range.
2566 * - encoding: Set by user
2567 * - decoding: Set by libavcodec
2568 */
2569 enum AVColorRange color_range;
2570
2571 /**
2572 * This defines the location of chroma samples.
2573 * - encoding: Set by user
2574 * - decoding: Set by libavcodec
2575 */
2576 enum AVChromaLocation chroma_sample_location;
2577
2578 /**
2579 * The codec may call this to execute several independent things.
2580 * It will return only after finishing all tasks.
2581 * The user may replace this with some multithreaded implementation,
2582 * the default implementation will execute the parts serially.
2583 * Also see avcodec_thread_init and e.g. the --enable-pthread configure option.
2584 * @param c context passed also to func
2585 * @param count the number of things to execute
2586 * @param arg2 argument passed unchanged to func
2587 * @param ret return values of executed functions, must have space for "count" values. May be NULL.
2588 * @param func function that will be called count times, with jobnr from 0 to count-1.
2589 * threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no
2590 * two instances of func executing at the same time will have the same threadnr.
2591 * @return always 0 currently, but code should handle a future improvement where when any call to func
2592 * returns < 0 no further calls to func may be done and < 0 is returned.
2593 * - encoding: Set by libavcodec, user can override.
2594 * - decoding: Set by libavcodec, user can override.
2595 */
2596 int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count);
2597
2598 /**
2599 * explicit P-frame weighted prediction analysis method
2600 * 0: off
2601 * 1: fast blind weighting (one reference duplicate with -1 offset)
2602 * 2: smart weighting (full fade detection analysis)
2603 * - encoding: Set by user.
2604 * - decoding: unused
2605 */
2606 int weighted_p_pred;
2607
2608 /**
2609 * AQ mode
2610 * 0: Disabled
2611 * 1: Variance AQ (complexity mask)
2612 * 2: Auto-variance AQ (experimental)
2613 * - encoding: Set by user
2614 * - decoding: unused
2615 */
2616 int aq_mode;
2617
2618 /**
2619 * AQ strength
2620 * Reduces blocking and blurring in flat and textured areas.
2621 * - encoding: Set by user
2622 * - decoding: unused
2623 */
2624 float aq_strength;
2625
2626 /**
2627 * PSY RD
2628 * Strength of psychovisual optimization
2629 * - encoding: Set by user
2630 * - decoding: unused
2631 */
2632 float psy_rd;
2633
2634 /**
2635 * PSY trellis
2636 * Strength of psychovisual optimization
2637 * - encoding: Set by user
2638 * - decoding: unused
2639 */
2640 float psy_trellis;
2641
2642 /**
2643 * RC lookahead
2644 * Number of frames for frametype and ratecontrol lookahead
2645 * - encoding: Set by user
2646 * - decoding: unused
2647 */
2648 int rc_lookahead;
2649} AVCodecContext;
2650
2651/**
2652 * AVCodec.
2653 */
2654typedef struct AVCodec {
2655 /**
2656 * Name of the codec implementation.
2657 * The name is globally unique among encoders and among decoders (but an
2658 * encoder and a decoder can share the same name).
2659 * This is the primary way to find a codec from the user perspective.
2660 */
2661 const char *name;
2662 enum AVMediaType type;
2663 enum CodecID id;
2664 int priv_data_size;
2665 int (*init)(AVCodecContext *);
2666 int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
2667 int (*close)(AVCodecContext *);
2668 int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
2669 /**
2670 * Codec capabilities.
2671 * see CODEC_CAP_*
2672 */
2673 int capabilities;
2674 struct AVCodec *next;
2675 /**
2676 * Flush buffers.
2677 * Will be called when seeking
2678 */
2679 void (*flush)(AVCodecContext *);
2680 const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
2681 const enum PixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
2682 /**
2683 * Descriptive name for the codec, meant to be more human readable than name.
2684 * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
2685 */
2686 const char *long_name;
2687 const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
2688 const enum SampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
2689 const int64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
2690} AVCodec;
2691
2692/**
2693 * AVHWAccel.
2694 */
2695typedef struct AVHWAccel {
2696 /**
2697 * Name of the hardware accelerated codec.
2698 * The name is globally unique among encoders and among decoders (but an
2699 * encoder and a decoder can share the same name).
2700 */
2701 const char *name;
2702
2703 /**
2704 * Type of codec implemented by the hardware accelerator.
2705 *
2706 * See AVMEDIA_TYPE_xxx
2707 */
2708 enum AVMediaType type;
2709
2710 /**
2711 * Codec implemented by the hardware accelerator.
2712 *
2713 * See CODEC_ID_xxx
2714 */
2715 enum CodecID id;
2716
2717 /**
2718 * Supported pixel format.
2719 *
2720 * Only hardware accelerated formats are supported here.
2721 */
2722 enum PixelFormat pix_fmt;
2723
2724 /**
2725 * Hardware accelerated codec capabilities.
2726 * see FF_HWACCEL_CODEC_CAP_*
2727 */
2728 int capabilities;
2729
2730 struct AVHWAccel *next;
2731
2732 /**
2733 * Called at the beginning of each frame or field picture.
2734 *
2735 * Meaningful frame information (codec specific) is guaranteed to
2736 * be parsed at this point. This function is mandatory.
2737 *
2738 * Note that buf can be NULL along with buf_size set to 0.
2739 * Otherwise, this means the whole frame is available at this point.
2740 *
2741 * @param avctx the codec context
2742 * @param buf the frame data buffer base
2743 * @param buf_size the size of the frame in bytes
2744 * @return zero if successful, a negative value otherwise
2745 */
2746 int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
2747
2748 /**
2749 * Callback for each slice.
2750 *
2751 * Meaningful slice information (codec specific) is guaranteed to
2752 * be parsed at this point. This function is mandatory.
2753 *
2754 * @param avctx the codec context
2755 * @param buf the slice data buffer base
2756 * @param buf_size the size of the slice in bytes
2757 * @return zero if successful, a negative value otherwise
2758 */
2759 int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
2760
2761 /**
2762 * Called at the end of each frame or field picture.
2763 *
2764 * The whole picture is parsed at this point and can now be sent
2765 * to the hardware accelerator. This function is mandatory.
2766 *
2767 * @param avctx the codec context
2768 * @return zero if successful, a negative value otherwise
2769 */
2770 int (*end_frame)(AVCodecContext *avctx);
2771
2772 /**
2773 * Size of HW accelerator private data.
2774 *
2775 * Private data is allocated with av_mallocz() before
2776 * AVCodecContext.get_buffer() and deallocated after
2777 * AVCodecContext.release_buffer().
2778 */
2779 int priv_data_size;
2780} AVHWAccel;
2781
2782/**
2783 * four components are given, that's all.
2784 * the last component is alpha
2785 */
2786typedef struct AVPicture {
2787 uint8_t *data[4];
2788 int linesize[4]; ///< number of bytes per line
2789} AVPicture;
2790
2791#if LIBAVCODEC_VERSION_MAJOR < 53
2792/**
2793 * AVPaletteControl
2794 * This structure defines a method for communicating palette changes
2795 * between and demuxer and a decoder.
2796 *
2797 * @deprecated Use AVPacket to send palette changes instead.
2798 * This is totally broken.
2799 */
2800#define AVPALETTE_SIZE 1024
2801#define AVPALETTE_COUNT 256
2802typedef struct AVPaletteControl {
2803
2804 /* Demuxer sets this to 1 to indicate the palette has changed;
2805 * decoder resets to 0. */
2806 int palette_changed;
2807
2808 /* 4-byte ARGB palette entries, stored in native byte order; note that
2809 * the individual palette components should be on a 8-bit scale; if
2810 * the palette data comes from an IBM VGA native format, the component
2811 * data is probably 6 bits in size and needs to be scaled. */
2812 unsigned int palette[AVPALETTE_COUNT];
2813
2814} AVPaletteControl attribute_deprecated;
2815#endif
2816
2817enum AVSubtitleType {
2818 SUBTITLE_NONE,
2819
2820 SUBTITLE_BITMAP, ///< A bitmap, pict will be set
2821
2822 /**
2823 * Plain text, the text field must be set by the decoder and is
2824 * authoritative. ass and pict fields may contain approximations.
2825 */
2826 SUBTITLE_TEXT,
2827
2828 /**
2829 * Formatted text, the ass field must be set by the decoder and is
2830 * authoritative. pict and text fields may contain approximations.
2831 */
2832 SUBTITLE_ASS,
2833};
2834
2835typedef struct AVSubtitleRect {
2836 int x; ///< top left corner of pict, undefined when pict is not set
2837 int y; ///< top left corner of pict, undefined when pict is not set
2838 int w; ///< width of pict, undefined when pict is not set
2839 int h; ///< height of pict, undefined when pict is not set
2840 int nb_colors; ///< number of colors in pict, undefined when pict is not set
2841
2842 /**
2843 * data+linesize for the bitmap of this subtitle.
2844 * can be set for text/ass as well once they where rendered
2845 */
2846 AVPicture pict;
2847 enum AVSubtitleType type;
2848
2849 char *text; ///< 0 terminated plain UTF-8 text
2850
2851 /**
2852 * 0 terminated ASS/SSA compatible event line.
2853 * The pressentation of this is unaffected by the other values in this
2854 * struct.
2855 */
2856 char *ass;
2857} AVSubtitleRect;
2858
2859typedef struct AVSubtitle {
2860 uint16_t format; /* 0 = graphics */
2861 uint32_t start_display_time; /* relative to packet pts, in ms */
2862 uint32_t end_display_time; /* relative to packet pts, in ms */
2863 unsigned num_rects;
2864 AVSubtitleRect **rects;
2865 int64_t pts; ///< Same as packet pts, in AV_TIME_BASE
2866} AVSubtitle;
2867
2868/* packet functions */
2869
2870/**
2871 * @deprecated use NULL instead
2872 */
2873attribute_deprecated void av_destruct_packet_nofree(AVPacket *pkt);
2874
2875/**
2876 * Default packet destructor.
2877 */
2878void av_destruct_packet(AVPacket *pkt);
2879
2880/**
2881 * Initialize optional fields of a packet with default values.
2882 *
2883 * @param pkt packet
2884 */
2885void av_init_packet(AVPacket *pkt);
2886
2887/**
2888 * Allocate the payload of a packet and initialize its fields with
2889 * default values.
2890 *
2891 * @param pkt packet
2892 * @param size wanted payload size
2893 * @return 0 if OK, AVERROR_xxx otherwise
2894 */
2895int av_new_packet(AVPacket *pkt, int size);
2896
2897/**
2898 * Reduce packet size, correctly zeroing padding
2899 *
2900 * @param pkt packet
2901 * @param size new size
2902 */
2903void av_shrink_packet(AVPacket *pkt, int size);
2904
2905/**
2906 * @warning This is a hack - the packet memory allocation stuff is broken. The
2907 * packet is allocated if it was not really allocated.
2908 */
2909int av_dup_packet(AVPacket *pkt);
2910
2911/**
2912 * Free a packet.
2913 *
2914 * @param pkt packet to free
2915 */
2916void av_free_packet(AVPacket *pkt);
2917
2918/* resample.c */
2919
2920struct ReSampleContext;
2921struct AVResampleContext;
2922
2923typedef struct ReSampleContext ReSampleContext;
2924
2925#if LIBAVCODEC_VERSION_MAJOR < 53
2926/**
2927 * @deprecated Use av_audio_resample_init() instead.
2928 */
2929attribute_deprecated ReSampleContext *audio_resample_init(int output_channels, int input_channels,
2930 int output_rate, int input_rate);
2931#endif
2932/**
2933 * Initializes audio resampling context
2934 *
2935 * @param output_channels number of output channels
2936 * @param input_channels number of input channels
2937 * @param output_rate output sample rate
2938 * @param input_rate input sample rate
2939 * @param sample_fmt_out requested output sample format
2940 * @param sample_fmt_in input sample format
2941 * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq
2942 * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
2943 * @param linear If 1 then the used FIR filter will be linearly interpolated
2944 between the 2 closest, if 0 the closest will be used
2945 * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
2946 * @return allocated ReSampleContext, NULL if error occured
2947 */
2948ReSampleContext *av_audio_resample_init(int output_channels, int input_channels,
2949 int output_rate, int input_rate,
2950 enum SampleFormat sample_fmt_out,
2951 enum SampleFormat sample_fmt_in,
2952 int filter_length, int log2_phase_count,
2953 int linear, double cutoff);
2954
2955int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
2956void audio_resample_close(ReSampleContext *s);
2957
2958
2959/**
2960 * Initializes an audio resampler.
2961 * Note, if either rate is not an integer then simply scale both rates up so they are.
2962 * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq
2963 * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
2964 * @param linear If 1 then the used FIR filter will be linearly interpolated
2965 between the 2 closest, if 0 the closest will be used
2966 * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
2967 */
2968struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff);
2969
2970/**
2971 * resamples.
2972 * @param src an array of unconsumed samples
2973 * @param consumed the number of samples of src which have been consumed are returned here
2974 * @param src_size the number of unconsumed samples available
2975 * @param dst_size the amount of space in samples available in dst
2976 * @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.
2977 * @return the number of samples written in dst or -1 if an error occurred
2978 */
2979int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
2980
2981
2982/**
2983 * Compensates samplerate/timestamp drift. The compensation is done by changing
2984 * the resampler parameters, so no audible clicks or similar distortions occur
2985 * @param compensation_distance distance in output samples over which the compensation should be performed
2986 * @param sample_delta number of output samples which should be output less
2987 *
2988 * example: av_resample_compensate(c, 10, 500)
2989 * here instead of 510 samples only 500 samples would be output
2990 *
2991 * note, due to rounding the actual compensation might be slightly different,
2992 * especially if the compensation_distance is large and the in_rate used during init is small
2993 */
2994void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
2995void av_resample_close(struct AVResampleContext *c);
2996
2997/**
2998 * Allocate memory for a picture. Call avpicture_free to free it.
2999 *
3000 * @param picture the picture to be filled in
3001 * @param pix_fmt the format of the picture
3002 * @param width the width of the picture
3003 * @param height the height of the picture
3004 * @return zero if successful, a negative value if not
3005 */
3006int avpicture_alloc(AVPicture *picture, enum PixelFormat pix_fmt, int width, int height);
3007
3008/**
3009 * Free a picture previously allocated by avpicture_alloc().
3010 *
3011 * @param picture the AVPicture to be freed
3012 */
3013void avpicture_free(AVPicture *picture);
3014
3015/**
3016 * Fill in the AVPicture fields.
3017 * The fields of the given AVPicture are filled in by using the 'ptr' address
3018 * which points to the image data buffer. Depending on the specified picture
3019 * format, one or multiple image data pointers and line sizes will be set.
3020 * If a planar format is specified, several pointers will be set pointing to
3021 * the different picture planes and the line sizes of the different planes
3022 * will be stored in the lines_sizes array.
3023 * Call with ptr == NULL to get the required size for the ptr buffer.
3024 *
3025 * @param picture AVPicture whose fields are to be filled in
3026 * @param ptr Buffer which will contain or contains the actual image data
3027 * @param pix_fmt The format in which the picture data is stored.
3028 * @param width the width of the image in pixels
3029 * @param height the height of the image in pixels
3030 * @return size of the image data in bytes
3031 */
3032int avpicture_fill(AVPicture *picture, uint8_t *ptr,
3033 enum PixelFormat pix_fmt, int width, int height);
3034int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, int height,
3035 unsigned char *dest, int dest_size);
3036
3037/**
3038 * Calculate the size in bytes that a picture of the given width and height
3039 * would occupy if stored in the given picture format.
3040 * Note that this returns the size of a compact representation as generated
3041 * by avpicture_layout, which can be smaller than the size required for e.g.
3042 * avpicture_fill.
3043 *
3044 * @param pix_fmt the given picture format
3045 * @param width the width of the image
3046 * @param height the height of the image
3047 * @return Image data size in bytes or -1 on error (e.g. too large dimensions).
3048 */
3049int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height);
3050void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift);
3051const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt);
3052void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
3053
3054#if LIBAVCODEC_VERSION_MAJOR < 53
3055/**
3056 * Returns the pixel format corresponding to the name name.
3057 *
3058 * If there is no pixel format with name name, then looks for a
3059 * pixel format with the name corresponding to the native endian
3060 * format of name.
3061 * For example in a little-endian system, first looks for "gray16",
3062 * then for "gray16le".
3063 *
3064 * Finally if no pixel format has been found, returns PIX_FMT_NONE.
3065 *
3066 * @deprecated Deprecated in favor of av_get_pix_fmt().
3067 */
3068attribute_deprecated enum PixelFormat avcodec_get_pix_fmt(const char* name);
3069#endif
3070
3071/**
3072 * Returns a value representing the fourCC code associated to the
3073 * pixel format pix_fmt, or 0 if no associated fourCC code can be
3074 * found.
3075 */
3076unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat pix_fmt);
3077
3078#define FF_LOSS_RESOLUTION 0x0001 /**< loss due to resolution change */
3079#define FF_LOSS_DEPTH 0x0002 /**< loss due to color depth change */
3080#define FF_LOSS_COLORSPACE 0x0004 /**< loss due to color space conversion */
3081#define FF_LOSS_ALPHA 0x0008 /**< loss of alpha bits */
3082#define FF_LOSS_COLORQUANT 0x0010 /**< loss due to color quantization */
3083#define FF_LOSS_CHROMA 0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */
3084
3085/**
3086 * Computes what kind of losses will occur when converting from one specific
3087 * pixel format to another.
3088 * When converting from one pixel format to another, information loss may occur.
3089 * For example, when converting from RGB24 to GRAY, the color information will
3090 * be lost. Similarly, other losses occur when converting from some formats to
3091 * other formats. These losses can involve loss of chroma, but also loss of
3092 * resolution, loss of color depth, loss due to the color space conversion, loss
3093 * of the alpha bits or loss due to color quantization.
3094 * avcodec_get_fix_fmt_loss() informs you about the various types of losses
3095 * which will occur when converting from one pixel format to another.
3096 *
3097 * @param[in] dst_pix_fmt destination pixel format
3098 * @param[in] src_pix_fmt source pixel format
3099 * @param[in] has_alpha Whether the source pixel format alpha channel is used.
3100 * @return Combination of flags informing you what kind of losses will occur.
3101 */
3102int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_pix_fmt,
3103 int has_alpha);
3104
3105/**
3106 * Finds the best pixel format to convert to given a certain source pixel
3107 * format. When converting from one pixel format to another, information loss
3108 * may occur. For example, when converting from RGB24 to GRAY, the color
3109 * information will be lost. Similarly, other losses occur when converting from
3110 * some formats to other formats. avcodec_find_best_pix_fmt() searches which of
3111 * the given pixel formats should be used to suffer the least amount of loss.
3112 * The pixel formats from which it chooses one, are determined by the
3113 * pix_fmt_mask parameter.
3114 *
3115 * @code
3116 * src_pix_fmt = PIX_FMT_YUV420P;
3117 * pix_fmt_mask = (1 << PIX_FMT_YUV422P) || (1 << PIX_FMT_RGB24);
3118 * dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss);
3119 * @endcode
3120 *
3121 * @param[in] pix_fmt_mask bitmask determining which pixel format to choose from
3122 * @param[in] src_pix_fmt source pixel format
3123 * @param[in] has_alpha Whether the source pixel format alpha channel is used.
3124 * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
3125 * @return The best pixel format to convert to or -1 if none was found.
3126 */
3127enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt,
3128 int has_alpha, int *loss_ptr);
3129
3130
3131/**
3132 * Print in buf the string corresponding to the pixel format with
3133 * number pix_fmt, or an header if pix_fmt is negative.
3134 *
3135 * @param[in] buf the buffer where to write the string
3136 * @param[in] buf_size the size of buf
3137 * @param[in] pix_fmt the number of the pixel format to print the corresponding info string, or
3138 * a negative value to print the corresponding header.
3139 * Meaningful values for obtaining a pixel format info vary from 0 to PIX_FMT_NB -1.
3140 */
3141void avcodec_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt);
3142
3143#define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */
3144#define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */
3145
3146/**
3147 * Tell if an image really has transparent alpha values.
3148 * @return ored mask of FF_ALPHA_xxx constants
3149 */
3150int img_get_alpha_info(const AVPicture *src,
3151 enum PixelFormat pix_fmt, int width, int height);
3152
3153/* deinterlace a picture */
3154/* deinterlace - if not supported return -1 */
3155int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
3156 enum PixelFormat pix_fmt, int width, int height);
3157
3158/* external high level API */
3159
3160/**
3161 * If c is NULL, returns the first registered codec,
3162 * if c is non-NULL, returns the next registered codec after c,
3163 * or NULL if c is the last one.
3164 */
3165AVCodec *av_codec_next(AVCodec *c);
3166
3167/**
3168 * Returns the LIBAVCODEC_VERSION_INT constant.
3169 */
3170unsigned avcodec_version(void);
3171
3172/**
3173 * Returns the libavcodec build-time configuration.
3174 */
3175const char *avcodec_configuration(void);
3176
3177/**
3178 * Returns the libavcodec license.
3179 */
3180const char *avcodec_license(void);
3181
3182/**
3183 * Initializes libavcodec.
3184 *
3185 * @warning This function must be called before any other libavcodec
3186 * function.
3187 */
3188void avcodec_init(void);
3189
3190#if LIBAVCODEC_VERSION_MAJOR < 53
3191/**
3192 * @deprecated Deprecated in favor of avcodec_register().
3193 */
3194attribute_deprecated void register_avcodec(AVCodec *codec);
3195#endif
3196
3197/**
3198 * Register the codec codec and initialize libavcodec.
3199 *
3200 * @see avcodec_init()
3201 */
3202void avcodec_register(AVCodec *codec);
3203
3204/**
3205 * Finds a registered encoder with a matching codec ID.
3206 *
3207 * @param id CodecID of the requested encoder
3208 * @return An encoder if one was found, NULL otherwise.
3209 */
3210AVCodec *avcodec_find_encoder(enum CodecID id);
3211
3212/**
3213 * Finds a registered encoder with the specified name.
3214 *
3215 * @param name name of the requested encoder
3216 * @return An encoder if one was found, NULL otherwise.
3217 */
3218AVCodec *avcodec_find_encoder_by_name(const char *name);
3219
3220/**
3221 * Finds a registered decoder with a matching codec ID.
3222 *
3223 * @param id CodecID of the requested decoder
3224 * @return A decoder if one was found, NULL otherwise.
3225 */
3226AVCodec *avcodec_find_decoder(enum CodecID id);
3227
3228/**
3229 * Finds a registered decoder with the specified name.
3230 *
3231 * @param name name of the requested decoder
3232 * @return A decoder if one was found, NULL otherwise.
3233 */
3234AVCodec *avcodec_find_decoder_by_name(const char *name);
3235void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
3236
3237/**
3238 * Sets the fields of the given AVCodecContext to default values.
3239 *
3240 * @param s The AVCodecContext of which the fields should be set to default values.
3241 */
3242void avcodec_get_context_defaults(AVCodecContext *s);
3243
3244/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
3245 * we WILL change its arguments and name a few times! */
3246void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType);
3247
3248/**
3249 * Allocates an AVCodecContext and sets its fields to default values. The
3250 * resulting struct can be deallocated by simply calling av_free().
3251 *
3252 * @return An AVCodecContext filled with default values or NULL on failure.
3253 * @see avcodec_get_context_defaults
3254 */
3255AVCodecContext *avcodec_alloc_context(void);
3256
3257/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
3258 * we WILL change its arguments and name a few times! */
3259AVCodecContext *avcodec_alloc_context2(enum AVMediaType);
3260
3261/**
3262 * Copy the settings of the source AVCodecContext into the destination
3263 * AVCodecContext. The resulting destination codec context will be
3264 * unopened, i.e. you are required to call avcodec_open() before you
3265 * can use this AVCodecContext to decode/encode video/audio data.
3266 *
3267 * @param dest target codec context, should be initialized with
3268 * avcodec_alloc_context(), but otherwise uninitialized
3269 * @param src source codec context
3270 * @return AVERROR() on error (e.g. memory allocation error), 0 on success
3271 */
3272int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
3273
3274/**
3275 * Sets the fields of the given AVFrame to default values.
3276 *
3277 * @param pic The AVFrame of which the fields should be set to default values.
3278 */
3279void avcodec_get_frame_defaults(AVFrame *pic);
3280
3281/**
3282 * Allocates an AVFrame and sets its fields to default values. The resulting
3283 * struct can be deallocated by simply calling av_free().
3284 *
3285 * @return An AVFrame filled with default values or NULL on failure.
3286 * @see avcodec_get_frame_defaults
3287 */
3288AVFrame *avcodec_alloc_frame(void);
3289
3290int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
3291void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
3292int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
3293
3294/**
3295 * Returns the amount of padding in pixels which the get_buffer callback must
3296 * provide around the edge of the image for codecs which do not have the
3297 * CODEC_FLAG_EMU_EDGE flag.
3298 *
3299 * @return Required padding in pixels.
3300 */
3301unsigned avcodec_get_edge_width(void);
3302/**
3303 * Modifies width and height values so that they will result in a memory
3304 * buffer that is acceptable for the codec if you do not use any horizontal
3305 * padding.
3306 */
3307void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
3308/**
3309 * Modifies width and height values so that they will result in a memory
3310 * buffer that is acceptable for the codec if you also ensure that all
3311 * line sizes are a multiple of the respective linesize_align[i].
3312 */
3313void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
3314 int linesize_align[4]);
3315
3316/**
3317 * Checks if the given dimension of a picture is valid, meaning that all
3318 * bytes of the picture can be addressed with a signed int.
3319 *
3320 * @param[in] w Width of the picture.
3321 * @param[in] h Height of the picture.
3322 * @return Zero if valid, a negative value if invalid.
3323 */
3324int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h);
3325enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt);
3326
3327int avcodec_thread_init(AVCodecContext *s, int thread_count);
3328void avcodec_thread_free(AVCodecContext *s);
3329int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
3330int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
3331//FIXME func typedef
3332
3333/**
3334 * Initializes the AVCodecContext to use the given AVCodec. Prior to using this
3335 * function the context has to be allocated.
3336 *
3337 * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
3338 * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
3339 * retrieving a codec.
3340 *
3341 * @warning This function is not thread safe!
3342 *
3343 * @code
3344 * avcodec_register_all();
3345 * codec = avcodec_find_decoder(CODEC_ID_H264);
3346 * if (!codec)
3347 * exit(1);
3348 *
3349 * context = avcodec_alloc_context();
3350 *
3351 * if (avcodec_open(context, codec) < 0)
3352 * exit(1);
3353 * @endcode
3354 *
3355 * @param avctx The context which will be set up to use the given codec.
3356 * @param codec The codec to use within the context.
3357 * @return zero on success, a negative value on error
3358 * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder
3359 */
3360int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
3361
3362#if LIBAVCODEC_VERSION_MAJOR < 53
3363/**
3364 * Decodes an audio frame from buf into samples.
3365 * Wrapper function which calls avcodec_decode_audio3.
3366 *
3367 * @deprecated Use avcodec_decode_audio3 instead.
3368 * @param avctx the codec context
3369 * @param[out] samples the output buffer
3370 * @param[in,out] frame_size_ptr the output buffer size in bytes
3371 * @param[in] buf the input buffer
3372 * @param[in] buf_size the input buffer size in bytes
3373 * @return On error a negative value is returned, otherwise the number of bytes
3374 * used or zero if no frame could be decompressed.
3375 */
3376attribute_deprecated int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
3377 int *frame_size_ptr,
3378 const uint8_t *buf, int buf_size);
3379#endif
3380
3381/**
3382 * Decodes the audio frame of size avpkt->size from avpkt->data into samples.
3383 * Some decoders may support multiple frames in a single AVPacket, such
3384 * decoders would then just decode the first frame. In this case,
3385 * avcodec_decode_audio3 has to be called again with an AVPacket that contains
3386 * the remaining data in order to decode the second frame etc.
3387 * If no frame
3388 * could be outputted, frame_size_ptr is zero. Otherwise, it is the
3389 * decompressed frame size in bytes.
3390 *
3391 * @warning You must set frame_size_ptr to the allocated size of the
3392 * output buffer before calling avcodec_decode_audio3().
3393 *
3394 * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
3395 * the actual read bytes because some optimized bitstream readers read 32 or 64
3396 * bits at once and could read over the end.
3397 *
3398 * @warning The end of the input buffer avpkt->data should be set to 0 to ensure that
3399 * no overreading happens for damaged MPEG streams.
3400 *
3401 * @note You might have to align the input buffer avpkt->data and output buffer
3402 * samples. The alignment requirements depend on the CPU: On some CPUs it isn't
3403 * necessary at all, on others it won't work at all if not aligned and on others
3404 * it will work but it will have an impact on performance.
3405 *
3406 * In practice, avpkt->data should have 4 byte alignment at minimum and
3407 * samples should be 16 byte aligned unless the CPU doesn't need it
3408 * (AltiVec and SSE do).
3409 *
3410 * @param avctx the codec context
3411 * @param[out] samples the output buffer, sample type in avctx->sample_fmt
3412 * @param[in,out] frame_size_ptr the output buffer size in bytes
3413 * @param[in] avpkt The input AVPacket containing the input buffer.
3414 * You can create such packet with av_init_packet() and by then setting
3415 * data and size, some decoders might in addition need other fields.
3416 * All decoders are designed to use the least fields possible though.
3417 * @return On error a negative value is returned, otherwise the number of bytes
3418 * used or zero if no frame data was decompressed (used) from the input AVPacket.
3419 */
3420int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
3421 int *frame_size_ptr,
3422 AVPacket *avpkt);
3423
3424#if LIBAVCODEC_VERSION_MAJOR < 53
3425/**
3426 * Decodes a video frame from buf into picture.
3427 * Wrapper function which calls avcodec_decode_video2.
3428 *
3429 * @deprecated Use avcodec_decode_video2 instead.
3430 * @param avctx the codec context
3431 * @param[out] picture The AVFrame in which the decoded video frame will be stored.
3432 * @param[in] buf the input buffer
3433 * @param[in] buf_size the size of the input buffer in bytes
3434 * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
3435 * @return On error a negative value is returned, otherwise the number of bytes
3436 * used or zero if no frame could be decompressed.
3437 */
3438attribute_deprecated int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
3439 int *got_picture_ptr,
3440 const uint8_t *buf, int buf_size);
3441#endif
3442
3443/**
3444 * Decodes the video frame of size avpkt->size from avpkt->data into picture.
3445 * Some decoders may support multiple frames in a single AVPacket, such
3446 * decoders would then just decode the first frame.
3447 *
3448 * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
3449 * the actual read bytes because some optimized bitstream readers read 32 or 64
3450 * bits at once and could read over the end.
3451 *
3452 * @warning The end of the input buffer buf should be set to 0 to ensure that
3453 * no overreading happens for damaged MPEG streams.
3454 *
3455 * @note You might have to align the input buffer avpkt->data.
3456 * The alignment requirements depend on the CPU: on some CPUs it isn't
3457 * necessary at all, on others it won't work at all if not aligned and on others
3458 * it will work but it will have an impact on performance.
3459 *
3460 * In practice, avpkt->data should have 4 byte alignment at minimum.
3461 *
3462 * @note Some codecs have a delay between input and output, these need to be
3463 * fed with avpkt->data=NULL, avpkt->size=0 at the end to return the remaining frames.
3464 *
3465 * @param avctx the codec context
3466 * @param[out] picture The AVFrame in which the decoded video frame will be stored.
3467 * @param[in] avpkt The input AVpacket containing the input buffer.
3468 * You can create such packet with av_init_packet() and by then setting
3469 * data and size, some decoders might in addition need other fields like
3470 * flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least
3471 * fields possible.
3472 * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
3473 * @return On error a negative value is returned, otherwise the number of bytes
3474 * used or zero if no frame could be decompressed.
3475 */
3476int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
3477 int *got_picture_ptr,
3478 AVPacket *avpkt);
3479
3480#if LIBAVCODEC_VERSION_MAJOR < 53
3481/* Decode a subtitle message. Return -1 if error, otherwise return the
3482 * number of bytes used. If no subtitle could be decompressed,
3483 * got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */
3484attribute_deprecated int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
3485 int *got_sub_ptr,
3486 const uint8_t *buf, int buf_size);
3487#endif
3488
3489/**
3490 * Decodes a subtitle message.
3491 * Returns a negative value on error, otherwise returns the number of bytes used.
3492 * If no subtitle could be decompressed, got_sub_ptr is zero.
3493 * Otherwise, the subtitle is stored in *sub.
3494 *
3495 * @param avctx the codec context
3496 * @param[out] sub The AVSubtitle in which the decoded subtitle will be stored.
3497 * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero.
3498 * @param[in] avpkt The input AVPacket containing the input buffer.
3499 */
3500int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
3501 int *got_sub_ptr,
3502 AVPacket *avpkt);
3503int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata,
3504 int *data_size_ptr,
3505 uint8_t *buf, int buf_size);
3506
3507/**
3508 * Encodes an audio frame from samples into buf.
3509 *
3510 * @note The output buffer should be at least FF_MIN_BUFFER_SIZE bytes large.
3511 * However, for PCM audio the user will know how much space is needed
3512 * because it depends on the value passed in buf_size as described
3513 * below. In that case a lower value can be used.
3514 *
3515 * @param avctx the codec context
3516 * @param[out] buf the output buffer
3517 * @param[in] buf_size the output buffer size
3518 * @param[in] samples the input buffer containing the samples
3519 * The number of samples read from this buffer is frame_size*channels,
3520 * both of which are defined in avctx.
3521 * For PCM audio the number of samples read from samples is equal to
3522 * buf_size * input_sample_size / output_sample_size.
3523 * @return On error a negative value is returned, on success zero or the number
3524 * of bytes used to encode the data read from the input buffer.
3525 */
3526int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
3527 const short *samples);
3528
3529/**
3530 * Encodes a video frame from pict into buf.
3531 * The input picture should be
3532 * stored using a specific format, namely avctx.pix_fmt.
3533 *
3534 * @param avctx the codec context
3535 * @param[out] buf the output buffer for the bitstream of encoded frame
3536 * @param[in] buf_size the size of the output buffer in bytes
3537 * @param[in] pict the input picture to encode
3538 * @return On error a negative value is returned, on success zero or the number
3539 * of bytes used from the output buffer.
3540 */
3541int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
3542 const AVFrame *pict);
3543int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
3544 const AVSubtitle *sub);
3545
3546int avcodec_close(AVCodecContext *avctx);
3547
3548/**
3549 * Register all the codecs, parsers and bitstream filters which were enabled at
3550 * configuration time. If you do not call this function you can select exactly
3551 * which formats you want to support, by using the individual registration
3552 * functions.
3553 *
3554 * @see avcodec_register
3555 * @see av_register_codec_parser
3556 * @see av_register_bitstream_filter
3557 */
3558void avcodec_register_all(void);
3559
3560/**
3561 * Flush buffers, should be called when seeking or when switching to a different stream.
3562 */
3563void avcodec_flush_buffers(AVCodecContext *avctx);
3564
3565void avcodec_default_free_buffers(AVCodecContext *s);
3566
3567/* misc useful functions */
3568
3569/**
3570 * Returns a single letter to describe the given picture type pict_type.
3571 *
3572 * @param[in] pict_type the picture type
3573 * @return A single character representing the picture type.
3574 */
3575char av_get_pict_type_char(int pict_type);
3576
3577/**
3578 * Returns codec bits per sample.
3579 *
3580 * @param[in] codec_id the codec
3581 * @return Number of bits per sample or zero if unknown for the given codec.
3582 */
3583int av_get_bits_per_sample(enum CodecID codec_id);
3584
3585/**
3586 * Returns sample format bits per sample.
3587 *
3588 * @param[in] sample_fmt the sample format
3589 * @return Number of bits per sample or zero if unknown for the given sample format.
3590 */
3591int av_get_bits_per_sample_format(enum SampleFormat sample_fmt);
3592
3593/* frame parsing */
3594typedef struct AVCodecParserContext {
3595 void *priv_data;
3596 struct AVCodecParser *parser;
3597 int64_t frame_offset; /* offset of the current frame */
3598 int64_t cur_offset; /* current offset
3599 (incremented by each av_parser_parse()) */
3600 int64_t next_frame_offset; /* offset of the next frame */
3601 /* video info */
3602 int pict_type; /* XXX: Put it back in AVCodecContext. */
3603 /**
3604 * This field is used for proper frame duration computation in lavf.
3605 * It signals, how much longer the frame duration of the current frame
3606 * is compared to normal frame duration.
3607 *
3608 * frame_duration = (1 + repeat_pict) * time_base
3609 *
3610 * It is used by codecs like H.264 to display telecined material.
3611 */
3612 int repeat_pict; /* XXX: Put it back in AVCodecContext. */
3613 int64_t pts; /* pts of the current frame */
3614 int64_t dts; /* dts of the current frame */
3615
3616 /* private data */
3617 int64_t last_pts;
3618 int64_t last_dts;
3619 int fetch_timestamp;
3620
3621#define AV_PARSER_PTS_NB 4
3622 int cur_frame_start_index;
3623 int64_t cur_frame_offset[AV_PARSER_PTS_NB];
3624 int64_t cur_frame_pts[AV_PARSER_PTS_NB];
3625 int64_t cur_frame_dts[AV_PARSER_PTS_NB];
3626
3627 int flags;
3628#define PARSER_FLAG_COMPLETE_FRAMES 0x0001
3629
3630 int64_t offset; ///< byte offset from starting packet start
3631 int64_t cur_frame_end[AV_PARSER_PTS_NB];
3632
3633 /*!
3634 * Set by parser to 1 for key frames and 0 for non-key frames.
3635 * It is initialized to -1, so if the parser doesn't set this flag,
3636 * old-style fallback using FF_I_TYPE picture type as key frames
3637 * will be used.
3638 */
3639 int key_frame;
3640
3641 /**
3642 * Time difference in stream time base units from the pts of this
3643 * packet to the point at which the output from the decoder has converged
3644 * independent from the availability of previous frames. That is, the
3645 * frames are virtually identical no matter if decoding started from
3646 * the very first frame or from this keyframe.
3647 * Is AV_NOPTS_VALUE if unknown.
3648 * This field is not the display duration of the current frame.
3649 *
3650 * The purpose of this field is to allow seeking in streams that have no
3651 * keyframes in the conventional sense. It corresponds to the
3652 * recovery point SEI in H.264 and match_time_delta in NUT. It is also
3653 * essential for some types of subtitle streams to ensure that all
3654 * subtitles are correctly displayed after seeking.
3655 */
3656 int64_t convergence_duration;
3657
3658 // Timestamp generation support:
3659 /**
3660 * Synchronization point for start of timestamp generation.
3661 *
3662 * Set to >0 for sync point, 0 for no sync point and <0 for undefined
3663 * (default).
3664 *
3665 * For example, this corresponds to presence of H.264 buffering period
3666 * SEI message.
3667 */
3668 int dts_sync_point;
3669
3670 /**
3671 * Offset of the current timestamp against last timestamp sync point in
3672 * units of AVCodecContext.time_base.
3673 *
3674 * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
3675 * contain a valid timestamp offset.
3676 *
3677 * Note that the timestamp of sync point has usually a nonzero
3678 * dts_ref_dts_delta, which refers to the previous sync point. Offset of
3679 * the next frame after timestamp sync point will be usually 1.
3680 *
3681 * For example, this corresponds to H.264 cpb_removal_delay.
3682 */
3683 int dts_ref_dts_delta;
3684
3685 /**
3686 * Presentation delay of current frame in units of AVCodecContext.time_base.
3687 *
3688 * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
3689 * contain valid non-negative timestamp delta (presentation time of a frame
3690 * must not lie in the past).
3691 *
3692 * This delay represents the difference between decoding and presentation
3693 * time of the frame.
3694 *
3695 * For example, this corresponds to H.264 dpb_output_delay.
3696 */
3697 int pts_dts_delta;
3698
3699 /**
3700 * Position of the packet in file.
3701 *
3702 * Analogous to cur_frame_pts/dts
3703 */
3704 int64_t cur_frame_pos[AV_PARSER_PTS_NB];
3705
3706 /**
3707 * Byte position of currently parsed frame in stream.
3708 */
3709 int64_t pos;
3710
3711 /**
3712 * Previous frame byte position.
3713 */
3714 int64_t last_pos;
3715} AVCodecParserContext;
3716
3717typedef struct AVCodecParser {
3718 int codec_ids[5]; /* several codec IDs are permitted */
3719 int priv_data_size;
3720 int (*parser_init)(AVCodecParserContext *s);
3721 int (*parser_parse)(AVCodecParserContext *s,
3722 AVCodecContext *avctx,
3723 const uint8_t **poutbuf, int *poutbuf_size,
3724 const uint8_t *buf, int buf_size);
3725 void (*parser_close)(AVCodecParserContext *s);
3726 int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
3727 struct AVCodecParser *next;
3728} AVCodecParser;
3729
3730AVCodecParser *av_parser_next(AVCodecParser *c);
3731
3732void av_register_codec_parser(AVCodecParser *parser);
3733AVCodecParserContext *av_parser_init(int codec_id);
3734
3735#if LIBAVCODEC_VERSION_MAJOR < 53
3736attribute_deprecated
3737int av_parser_parse(AVCodecParserContext *s,
3738 AVCodecContext *avctx,
3739 uint8_t **poutbuf, int *poutbuf_size,
3740 const uint8_t *buf, int buf_size,
3741 int64_t pts, int64_t dts);
3742#endif
3743
3744/**
3745 * Parse a packet.
3746 *
3747 * @param s parser context.
3748 * @param avctx codec context.
3749 * @param poutbuf set to pointer to parsed buffer or NULL if not yet finished.
3750 * @param poutbuf_size set to size of parsed buffer or zero if not yet finished.
3751 * @param buf input buffer.
3752 * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output).
3753 * @param pts input presentation timestamp.
3754 * @param dts input decoding timestamp.
3755 * @param pos input byte position in stream.
3756 * @return the number of bytes of the input bitstream used.
3757 *
3758 * Example:
3759 * @code
3760 * while(in_len){
3761 * len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
3762 * in_data, in_len,
3763 * pts, dts, pos);
3764 * in_data += len;
3765 * in_len -= len;
3766 *
3767 * if(size)
3768 * decode_frame(data, size);
3769 * }
3770 * @endcode
3771 */
3772int av_parser_parse2(AVCodecParserContext *s,
3773 AVCodecContext *avctx,
3774 uint8_t **poutbuf, int *poutbuf_size,
3775 const uint8_t *buf, int buf_size,
3776 int64_t pts, int64_t dts,
3777 int64_t pos);
3778
3779int av_parser_change(AVCodecParserContext *s,
3780 AVCodecContext *avctx,
3781 uint8_t **poutbuf, int *poutbuf_size,
3782 const uint8_t *buf, int buf_size, int keyframe);
3783void av_parser_close(AVCodecParserContext *s);
3784
3785
3786typedef struct AVBitStreamFilterContext {
3787 void *priv_data;
3788 struct AVBitStreamFilter *filter;
3789 AVCodecParserContext *parser;
3790 struct AVBitStreamFilterContext *next;
3791} AVBitStreamFilterContext;
3792
3793
3794typedef struct AVBitStreamFilter {
3795 const char *name;
3796 int priv_data_size;
3797 int (*filter)(AVBitStreamFilterContext *bsfc,
3798 AVCodecContext *avctx, const char *args,
3799 uint8_t **poutbuf, int *poutbuf_size,
3800 const uint8_t *buf, int buf_size, int keyframe);
3801 void (*close)(AVBitStreamFilterContext *bsfc);
3802 struct AVBitStreamFilter *next;
3803} AVBitStreamFilter;
3804
3805void av_register_bitstream_filter(AVBitStreamFilter *bsf);
3806AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
3807int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
3808 AVCodecContext *avctx, const char *args,
3809 uint8_t **poutbuf, int *poutbuf_size,
3810 const uint8_t *buf, int buf_size, int keyframe);
3811void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);
3812
3813AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f);
3814
3815/* memory */
3816
3817/**
3818 * Reallocates the given block if it is not large enough, otherwise it
3819 * does nothing.
3820 *
3821 * @see av_realloc
3822 */
3823void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
3824
3825/**
3826 * Allocates a buffer, reusing the given one if large enough.
3827 *
3828 * Contrary to av_fast_realloc the current buffer contents might not be
3829 * preserved and on error the old buffer is freed, thus no special
3830 * handling to avoid memleaks is necessary.
3831 *
3832 * @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer
3833 * @param size size of the buffer *ptr points to
3834 * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
3835 * *size 0 if an error occurred.
3836 */
3837void av_fast_malloc(void *ptr, unsigned int *size, unsigned int min_size);
3838
3839/**
3840 * Copy image 'src' to 'dst'.
3841 */
3842void av_picture_copy(AVPicture *dst, const AVPicture *src,
3843 enum PixelFormat pix_fmt, int width, int height);
3844
3845/**
3846 * Crop image top and left side.
3847 */
3848int av_picture_crop(AVPicture *dst, const AVPicture *src,
3849 enum PixelFormat pix_fmt, int top_band, int left_band);
3850
3851/**
3852 * Pad image.
3853 */
3854int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, enum PixelFormat pix_fmt,
3855 int padtop, int padbottom, int padleft, int padright, int *color);
3856
3857/**
3858 * Encodes extradata length to a buffer. Used by xiph codecs.
3859 *
3860 * @param s buffer to write to; must be at least (v/255+1) bytes long
3861 * @param v size of extradata in bytes
3862 * @return number of bytes written to the buffer.
3863 */
3864unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
3865
3866/**
3867 * Parses str and put in width_ptr and height_ptr the detected values.
3868 *
3869 * @return 0 in case of a successful parsing, a negative value otherwise
3870 * @param[in] str the string to parse: it has to be a string in the format
3871 * <width>x<height> or a valid video frame size abbreviation.
3872 * @param[in,out] width_ptr pointer to the variable which will contain the detected
3873 * frame width value
3874 * @param[in,out] height_ptr pointer to the variable which will contain the detected
3875 * frame height value
3876 */
3877int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str);
3878
3879/**
3880 * Parses str and put in frame_rate the detected values.
3881 *
3882 * @return 0 in case of a successful parsing, a negative value otherwise
3883 * @param[in] str the string to parse: it has to be a string in the format
3884 * <frame_rate_num>/<frame_rate_den>, a float number or a valid video rate abbreviation
3885 * @param[in,out] frame_rate pointer to the AVRational which will contain the detected
3886 * frame rate
3887 */
3888int av_parse_video_frame_rate(AVRational *frame_rate, const char *str);
3889
3890/**
3891 * Logs a generic warning message about a missing feature. This function is
3892 * intended to be used internally by FFmpeg (libavcodec, libavformat, etc.)
3893 * only, and would normally not be used by applications.
3894 * @param[in] avc a pointer to an arbitrary struct of which the first field is
3895 * a pointer to an AVClass struct
3896 * @param[in] feature string containing the name of the missing feature
3897 * @param[in] want_sample indicates if samples are wanted which exhibit this feature.
3898 * If want_sample is non-zero, additional verbage will be added to the log
3899 * message which tells the user how to report samples to the development
3900 * mailing list.
3901 */
3902void av_log_missing_feature(void *avc, const char *feature, int want_sample);
3903
3904/**
3905 * Logs a generic warning message asking for a sample. This function is
3906 * intended to be used internally by FFmpeg (libavcodec, libavformat, etc.)
3907 * only, and would normally not be used by applications.
3908 * @param[in] avc a pointer to an arbitrary struct of which the first field is
3909 * a pointer to an AVClass struct
3910 * @param[in] msg string containing an optional message, or NULL if no message
3911 */
3912void av_log_ask_for_sample(void *avc, const char *msg);
3913
3914/**
3915 * Registers the hardware accelerator hwaccel.
3916 */
3917void av_register_hwaccel(AVHWAccel *hwaccel);
3918
3919/**
3920 * If hwaccel is NULL, returns the first registered hardware accelerator,
3921 * if hwaccel is non-NULL, returns the next registered hardware accelerator
3922 * after hwaccel, or NULL if hwaccel is the last one.
3923 */
3924AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel);
3925
3926
3927/**
3928 * Lock operation used by lockmgr
3929 */
3930enum AVLockOp {
3931 AV_LOCK_CREATE, ///< Create a mutex
3932 AV_LOCK_OBTAIN, ///< Lock the mutex
3933 AV_LOCK_RELEASE, ///< Unlock the mutex
3934 AV_LOCK_DESTROY, ///< Free mutex resources
3935};
3936
3937/**
3938 * Register a user provided lock manager supporting the operations
3939 * specified by AVLockOp. mutex points to a (void *) where the
3940 * lockmgr should store/get a pointer to a user allocated mutex. It's
3941 * NULL upon AV_LOCK_CREATE and != NULL for all other ops.
3942 *
3943 * @param cb User defined callback. Note: FFmpeg may invoke calls to this
3944 * callback during the call to av_lockmgr_register().
3945 * Thus, the application must be prepared to handle that.
3946 * If cb is set to NULL the lockmgr will be unregistered.
3947 * Also note that during unregistration the previously registered
3948 * lockmgr callback may also be invoked.
3949 */
3950int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op));
3951
3952#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..1e24099cc8
--- /dev/null
+++ b/apps/codecs/libwmapro/bitstream.c
@@ -0,0 +1,336 @@
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
35const uint8_t ff_log2_run[32]={
36 0, 0, 0, 0, 1, 1, 1, 1,
37 2, 2, 2, 2, 3, 3, 3, 3,
38 4, 4, 5, 5, 6, 6, 7, 7,
39 8, 9,10,11,12,13,14,15
40};
41
42void align_put_bits(PutBitContext *s)
43{
44#ifdef ALT_BITSTREAM_WRITER
45 put_bits(s,( - s->index) & 7,0);
46#else
47 put_bits(s,s->bit_left & 7,0);
48#endif
49}
50
51void ff_put_string(PutBitContext *pb, const char *string, int terminate_string)
52{
53 while(*string){
54 put_bits(pb, 8, *string);
55 string++;
56 }
57 if(terminate_string)
58 put_bits(pb, 8, 0);
59}
60
61void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
62{
63 int words= length>>4;
64 int bits= length&15;
65 int i;
66
67 if(length==0) return;
68
69 if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){
70 for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(src + 2*i));
71 }else{
72 for(i=0; put_bits_count(pb)&31; i++)
73 put_bits(pb, 8, src[i]);
74 flush_put_bits(pb);
75 memcpy(put_bits_ptr(pb), src+i, 2*words-i);
76 skip_put_bytes(pb, 2*words-i);
77 }
78
79 put_bits(pb, bits, AV_RB16(src + 2*words)>>(16-bits));
80}
81
82/* VLC decoding */
83
84//#define DEBUG_VLC
85
86#define GET_DATA(v, table, i, wrap, size) \
87{\
88 const uint8_t *ptr = (const uint8_t *)table + i * wrap;\
89 switch(size) {\
90 case 1:\
91 v = *(const uint8_t *)ptr;\
92 break;\
93 case 2:\
94 v = *(const uint16_t *)ptr;\
95 break;\
96 default:\
97 v = *(const uint32_t *)ptr;\
98 break;\
99 }\
100}
101
102
103static int alloc_table(VLC *vlc, int size, int use_static)
104{
105 int index;
106 index = vlc->table_size;
107 vlc->table_size += size;
108 if (vlc->table_size > vlc->table_allocated) {
109 if(use_static)
110 abort(); //cant do anything, init_vlc() is used with too little memory
111 vlc->table_allocated += (1 << vlc->bits);
112 vlc->table = av_realloc(vlc->table,
113 sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
114 if (!vlc->table)
115 return -1;
116 }
117 return index;
118}
119
120static av_always_inline uint32_t bitswap_32(uint32_t x) {
121 return av_reverse[x&0xFF]<<24
122 | av_reverse[(x>>8)&0xFF]<<16
123 | av_reverse[(x>>16)&0xFF]<<8
124 | av_reverse[x>>24];
125}
126
127typedef struct {
128 uint8_t bits;
129 uint16_t symbol;
130 /** codeword, with the first bit-to-be-read in the msb
131 * (even if intended for a little-endian bitstream reader) */
132 uint32_t code;
133} VLCcode;
134
135static int compare_vlcspec(const void *a, const void *b)
136{
137 const VLCcode *sa=a, *sb=b;
138 return (sa->code >> 1) - (sb->code >> 1);
139}
140
141/**
142 * Build VLC decoding tables suitable for use with get_vlc().
143 *
144 * @param vlc the context to be initted
145 *
146 * @param table_nb_bits max length of vlc codes to store directly in this table
147 * (Longer codes are delegated to subtables.)
148 *
149 * @param nb_codes number of elements in codes[]
150 *
151 * @param codes descriptions of the vlc codes
152 * These must be ordered such that codes going into the same subtable are contiguous.
153 * Sorting by VLCcode.code is sufficient, though not necessary.
154 */
155static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
156 VLCcode *codes, int flags)
157{
158 int table_size, table_index, index, code_prefix, symbol, subtable_bits;
159 int i, j, k, n, nb, inc;
160 uint32_t code;
161 VLC_TYPE (*table)[2];
162
163 table_size = 1 << table_nb_bits;
164 table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC);
165#ifdef DEBUG_VLC
166 av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d\n",
167 table_index, table_size);
168#endif
169 if (table_index < 0)
170 return -1;
171 table = &vlc->table[table_index];
172
173 for (i = 0; i < table_size; i++) {
174 table[i][1] = 0; //bits
175 table[i][0] = -1; //codes
176 }
177
178 /* first pass: map codes and compute auxillary table sizes */
179 for (i = 0; i < nb_codes; i++) {
180 n = codes[i].bits;
181 code = codes[i].code;
182 symbol = codes[i].symbol;
183#if defined(DEBUG_VLC) && 0
184 av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code);
185#endif
186 if (n <= table_nb_bits) {
187 /* no need to add another table */
188 j = code >> (32 - table_nb_bits);
189 nb = 1 << (table_nb_bits - n);
190 inc = 1;
191 if (flags & INIT_VLC_LE) {
192 j = bitswap_32(code);
193 inc = 1 << n;
194 }
195 for (k = 0; k < nb; k++) {
196#ifdef DEBUG_VLC
197 av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n",
198 j, i, n);
199#endif
200 if (table[j][1] /*bits*/ != 0) {
201 av_log(NULL, AV_LOG_ERROR, "incorrect codes\n");
202 return -1;
203 }
204 table[j][1] = n; //bits
205 table[j][0] = symbol;
206 j += inc;
207 }
208 } else {
209 /* fill auxiliary table recursively */
210 n -= table_nb_bits;
211 code_prefix = code >> (32 - table_nb_bits);
212 subtable_bits = n;
213 codes[i].bits = n;
214 codes[i].code = code << table_nb_bits;
215 for (k = i+1; k < nb_codes; k++) {
216 n = codes[k].bits - table_nb_bits;
217 if (n <= 0)
218 break;
219 code = codes[k].code;
220 if (code >> (32 - table_nb_bits) != code_prefix)
221 break;
222 codes[k].bits = n;
223 codes[k].code = code << table_nb_bits;
224 subtable_bits = FFMAX(subtable_bits, n);
225 }
226 subtable_bits = FFMIN(subtable_bits, table_nb_bits);
227 j = (flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix;
228 table[j][1] = -subtable_bits;
229#ifdef DEBUG_VLC
230 av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n",
231 j, codes[i].bits + table_nb_bits);
232#endif
233 index = build_table(vlc, subtable_bits, k-i, codes+i, flags);
234 if (index < 0)
235 return -1;
236 /* note: realloc has been done, so reload tables */
237 table = &vlc->table[table_index];
238 table[j][0] = index; //code
239 i = k-1;
240 }
241 }
242 return table_index;
243}
244
245
246/* Build VLC decoding tables suitable for use with get_vlc().
247
248 'nb_bits' set thee decoding table size (2^nb_bits) entries. The
249 bigger it is, the faster is the decoding. But it should not be too
250 big to save memory and L1 cache. '9' is a good compromise.
251
252 'nb_codes' : number of vlcs codes
253
254 'bits' : table which gives the size (in bits) of each vlc code.
255
256 'codes' : table which gives the bit pattern of of each vlc code.
257
258 'symbols' : table which gives the values to be returned from get_vlc().
259
260 'xxx_wrap' : give the number of bytes between each entry of the
261 'bits' or 'codes' tables.
262
263 'xxx_size' : gives the number of bytes of each entry of the 'bits'
264 or 'codes' tables.
265
266 'wrap' and 'size' allows to use any memory configuration and types
267 (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables.
268
269 'use_static' should be set to 1 for tables, which should be freed
270 with av_free_static(), 0 if free_vlc() will be used.
271*/
272int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
273 const void *bits, int bits_wrap, int bits_size,
274 const void *codes, int codes_wrap, int codes_size,
275 const void *symbols, int symbols_wrap, int symbols_size,
276 int flags)
277{
278 VLCcode buf[nb_codes];
279 int i, j;
280
281 vlc->bits = nb_bits;
282 if(flags & INIT_VLC_USE_NEW_STATIC){
283 if(vlc->table_size && vlc->table_size == vlc->table_allocated){
284 return 0;
285 }else if(vlc->table_size){
286 abort(); // fatal error, we are called on a partially initialized table
287 }
288 }else {
289 vlc->table = NULL;
290 vlc->table_allocated = 0;
291 vlc->table_size = 0;
292 }
293
294#ifdef DEBUG_VLC
295 av_log(NULL,AV_LOG_DEBUG,"build table nb_codes=%d\n", nb_codes);
296#endif
297
298 assert(symbols_size <= 2 || !symbols);
299 j = 0;
300#define COPY(condition)\
301 for (i = 0; i < nb_codes; i++) {\
302 GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size);\
303 if (!(condition))\
304 continue;\
305 GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size);\
306 if (flags & INIT_VLC_LE)\
307 buf[j].code = bitswap_32(buf[j].code);\
308 else\
309 buf[j].code <<= 32 - buf[j].bits;\
310 if (symbols)\
311 GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size)\
312 else\
313 buf[j].symbol = i;\
314 j++;\
315 }
316 COPY(buf[j].bits > nb_bits);
317 // qsort is the slowest part of init_vlc, and could probably be improved or avoided
318 qsort(buf, j, sizeof(VLCcode), compare_vlcspec);
319 COPY(buf[j].bits && buf[j].bits <= nb_bits);
320 nb_codes = j;
321
322 if (build_table(vlc, nb_bits, nb_codes, buf, flags) < 0) {
323 av_freep(&vlc->table);
324 return -1;
325 }
326 if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size != vlc->table_allocated)
327 av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated);
328 return 0;
329}
330
331
332void free_vlc(VLC *vlc)
333{
334 av_freep(&vlc->table);
335}
336
diff --git a/apps/codecs/libwmapro/dsputil.c b/apps/codecs/libwmapro/dsputil.c
new file mode 100644
index 0000000000..bbfdb6ae8d
--- /dev/null
+++ b/apps/codecs/libwmapro/dsputil.c
@@ -0,0 +1,4565 @@
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
43uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, };
44uint32_t ff_squareTbl[512] = {0, };
45
46// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
47#define pb_7f (~0UL/255 * 0x7f)
48#define pb_80 (~0UL/255 * 0x80)
49
50const uint8_t ff_zigzag_direct[64] = {
51 0, 1, 8, 16, 9, 2, 3, 10,
52 17, 24, 32, 25, 18, 11, 4, 5,
53 12, 19, 26, 33, 40, 48, 41, 34,
54 27, 20, 13, 6, 7, 14, 21, 28,
55 35, 42, 49, 56, 57, 50, 43, 36,
56 29, 22, 15, 23, 30, 37, 44, 51,
57 58, 59, 52, 45, 38, 31, 39, 46,
58 53, 60, 61, 54, 47, 55, 62, 63
59};
60
61/* Specific zigzag scan for 248 idct. NOTE that unlike the
62 specification, we interleave the fields */
63const uint8_t ff_zigzag248_direct[64] = {
64 0, 8, 1, 9, 16, 24, 2, 10,
65 17, 25, 32, 40, 48, 56, 33, 41,
66 18, 26, 3, 11, 4, 12, 19, 27,
67 34, 42, 49, 57, 50, 58, 35, 43,
68 20, 28, 5, 13, 6, 14, 21, 29,
69 36, 44, 51, 59, 52, 60, 37, 45,
70 22, 30, 7, 15, 23, 31, 38, 46,
71 53, 61, 54, 62, 39, 47, 55, 63,
72};
73
74/* not permutated inverse zigzag_direct + 1 for MMX quantizer */
75DECLARE_ALIGNED(16, uint16_t, inv_zigzag_direct16)[64];
76
77const uint8_t ff_alternate_horizontal_scan[64] = {
78 0, 1, 2, 3, 8, 9, 16, 17,
79 10, 11, 4, 5, 6, 7, 15, 14,
80 13, 12, 19, 18, 24, 25, 32, 33,
81 26, 27, 20, 21, 22, 23, 28, 29,
82 30, 31, 34, 35, 40, 41, 48, 49,
83 42, 43, 36, 37, 38, 39, 44, 45,
84 46, 47, 50, 51, 56, 57, 58, 59,
85 52, 53, 54, 55, 60, 61, 62, 63,
86};
87
88const uint8_t ff_alternate_vertical_scan[64] = {
89 0, 8, 16, 24, 1, 9, 2, 10,
90 17, 25, 32, 40, 48, 56, 57, 49,
91 41, 33, 26, 18, 3, 11, 4, 12,
92 19, 27, 34, 42, 50, 58, 35, 43,
93 51, 59, 20, 28, 5, 13, 6, 14,
94 21, 29, 36, 44, 52, 60, 37, 45,
95 53, 61, 22, 30, 7, 15, 23, 31,
96 38, 46, 54, 62, 39, 47, 55, 63,
97};
98
99/* a*inverse[b]>>32 == a/b for all 0<=a<=16909558 && 2<=b<=256
100 * for a>16909558, is an overestimate by less than 1 part in 1<<24 */
101const uint32_t ff_inverse[257]={
102 0, 4294967295U,2147483648U,1431655766, 1073741824, 858993460, 715827883, 613566757,
103 536870912, 477218589, 429496730, 390451573, 357913942, 330382100, 306783379, 286331154,
104 268435456, 252645136, 238609295, 226050911, 214748365, 204522253, 195225787, 186737709,
105 178956971, 171798692, 165191050, 159072863, 153391690, 148102321, 143165577, 138547333,
106 134217728, 130150525, 126322568, 122713352, 119304648, 116080198, 113025456, 110127367,
107 107374183, 104755300, 102261127, 99882961, 97612894, 95443718, 93368855, 91382283,
108 89478486, 87652394, 85899346, 84215046, 82595525, 81037119, 79536432, 78090315,
109 76695845, 75350304, 74051161, 72796056, 71582789, 70409300, 69273667, 68174085,
110 67108864, 66076420, 65075263, 64103990, 63161284, 62245903, 61356676, 60492498,
111 59652324, 58835169, 58040099, 57266231, 56512728, 55778797, 55063684, 54366675,
112 53687092, 53024288, 52377650, 51746594, 51130564, 50529028, 49941481, 49367441,
113 48806447, 48258060, 47721859, 47197443, 46684428, 46182445, 45691142, 45210183,
114 44739243, 44278014, 43826197, 43383509, 42949673, 42524429, 42107523, 41698712,
115 41297763, 40904451, 40518560, 40139882, 39768216, 39403370, 39045158, 38693400,
116 38347923, 38008561, 37675152, 37347542, 37025581, 36709123, 36398028, 36092163,
117 35791395, 35495598, 35204650, 34918434, 34636834, 34359739, 34087043, 33818641,
118 33554432, 33294321, 33038210, 32786010, 32537632, 32292988, 32051995, 31814573,
119 31580642, 31350127, 31122952, 30899046, 30678338, 30460761, 30246249, 30034737,
120 29826162, 29620465, 29417585, 29217465, 29020050, 28825284, 28633116, 28443493,
121 28256364, 28071682, 27889399, 27709467, 27531842, 27356480, 27183338, 27012373,
122 26843546, 26676816, 26512144, 26349493, 26188825, 26030105, 25873297, 25718368,
123 25565282, 25414008, 25264514, 25116768, 24970741, 24826401, 24683721, 24542671,
124 24403224, 24265352, 24129030, 23994231, 23860930, 23729102, 23598722, 23469767,
125 23342214, 23216040, 23091223, 22967740, 22845571, 22724695, 22605092, 22486740,
126 22369622, 22253717, 22139007, 22025474, 21913099, 21801865, 21691755, 21582751,
127 21474837, 21367997, 21262215, 21157475, 21053762, 20951060, 20849356, 20748635,
128 20648882, 20550083, 20452226, 20355296, 20259280, 20164166, 20069941, 19976593,
129 19884108, 19792477, 19701685, 19611723, 19522579, 19434242, 19346700, 19259944,
130 19173962, 19088744, 19004281, 18920561, 18837576, 18755316, 18673771, 18592933,
131 18512791, 18433337, 18354562, 18276457, 18199014, 18122225, 18046082, 17970575,
132 17895698, 17821442, 17747799, 17674763, 17602325, 17530479, 17459217, 17388532,
133 17318417, 17248865, 17179870, 17111424, 17043522, 16976156, 16909321, 16843010,
134 16777216
135};
136
137/* Input permutation for the simple_idct_mmx */
138static const uint8_t simple_mmx_permutation[64]={
139 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
140 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
141 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
142 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
143 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
144 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
145 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
146 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
147};
148
149static const uint8_t idct_sse2_row_perm[8] = {0, 4, 1, 5, 2, 6, 3, 7};
150
151void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){
152 int i;
153 int end;
154
155 st->scantable= src_scantable;
156
157 for(i=0; i<64; i++){
158 int j;
159 j = src_scantable[i];
160 st->permutated[i] = permutation[j];
161#if ARCH_PPC
162 st->inverse[j] = i;
163#endif
164 }
165
166 end=-1;
167 for(i=0; i<64; i++){
168 int j;
169 j = st->permutated[i];
170 if(j>end) end=j;
171 st->raster_end[i]= end;
172 }
173}
174
175static int pix_sum_c(uint8_t * pix, int line_size)
176{
177 int s, i, j;
178
179 s = 0;
180 for (i = 0; i < 16; i++) {
181 for (j = 0; j < 16; j += 8) {
182 s += pix[0];
183 s += pix[1];
184 s += pix[2];
185 s += pix[3];
186 s += pix[4];
187 s += pix[5];
188 s += pix[6];
189 s += pix[7];
190 pix += 8;
191 }
192 pix += line_size - 16;
193 }
194 return s;
195}
196
197static int pix_norm1_c(uint8_t * pix, int line_size)
198{
199 int s, i, j;
200 uint32_t *sq = ff_squareTbl + 256;
201
202 s = 0;
203 for (i = 0; i < 16; i++) {
204 for (j = 0; j < 16; j += 8) {
205#if 0
206 s += sq[pix[0]];
207 s += sq[pix[1]];
208 s += sq[pix[2]];
209 s += sq[pix[3]];
210 s += sq[pix[4]];
211 s += sq[pix[5]];
212 s += sq[pix[6]];
213 s += sq[pix[7]];
214#else
215#if LONG_MAX > 2147483647
216 register uint64_t x=*(uint64_t*)pix;
217 s += sq[x&0xff];
218 s += sq[(x>>8)&0xff];
219 s += sq[(x>>16)&0xff];
220 s += sq[(x>>24)&0xff];
221 s += sq[(x>>32)&0xff];
222 s += sq[(x>>40)&0xff];
223 s += sq[(x>>48)&0xff];
224 s += sq[(x>>56)&0xff];
225#else
226 register uint32_t x=*(uint32_t*)pix;
227 s += sq[x&0xff];
228 s += sq[(x>>8)&0xff];
229 s += sq[(x>>16)&0xff];
230 s += sq[(x>>24)&0xff];
231 x=*(uint32_t*)(pix+4);
232 s += sq[x&0xff];
233 s += sq[(x>>8)&0xff];
234 s += sq[(x>>16)&0xff];
235 s += sq[(x>>24)&0xff];
236#endif
237#endif
238 pix += 8;
239 }
240 pix += line_size - 16;
241 }
242 return s;
243}
244
245static void bswap_buf(uint32_t *dst, const uint32_t *src, int w){
246 int i;
247
248 for(i=0; i+8<=w; i+=8){
249 dst[i+0]= bswap_32(src[i+0]);
250 dst[i+1]= bswap_32(src[i+1]);
251 dst[i+2]= bswap_32(src[i+2]);
252 dst[i+3]= bswap_32(src[i+3]);
253 dst[i+4]= bswap_32(src[i+4]);
254 dst[i+5]= bswap_32(src[i+5]);
255 dst[i+6]= bswap_32(src[i+6]);
256 dst[i+7]= bswap_32(src[i+7]);
257 }
258 for(;i<w; i++){
259 dst[i+0]= bswap_32(src[i+0]);
260 }
261}
262
263static int sse4_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
264{
265 int s, i;
266 uint32_t *sq = ff_squareTbl + 256;
267
268 s = 0;
269 for (i = 0; i < h; i++) {
270 s += sq[pix1[0] - pix2[0]];
271 s += sq[pix1[1] - pix2[1]];
272 s += sq[pix1[2] - pix2[2]];
273 s += sq[pix1[3] - pix2[3]];
274 pix1 += line_size;
275 pix2 += line_size;
276 }
277 return s;
278}
279
280static int sse8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
281{
282 int s, i;
283 uint32_t *sq = ff_squareTbl + 256;
284
285 s = 0;
286 for (i = 0; i < h; i++) {
287 s += sq[pix1[0] - pix2[0]];
288 s += sq[pix1[1] - pix2[1]];
289 s += sq[pix1[2] - pix2[2]];
290 s += sq[pix1[3] - pix2[3]];
291 s += sq[pix1[4] - pix2[4]];
292 s += sq[pix1[5] - pix2[5]];
293 s += sq[pix1[6] - pix2[6]];
294 s += sq[pix1[7] - pix2[7]];
295 pix1 += line_size;
296 pix2 += line_size;
297 }
298 return s;
299}
300
301static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
302{
303 int s, i;
304 uint32_t *sq = ff_squareTbl + 256;
305
306 s = 0;
307 for (i = 0; i < h; i++) {
308 s += sq[pix1[ 0] - pix2[ 0]];
309 s += sq[pix1[ 1] - pix2[ 1]];
310 s += sq[pix1[ 2] - pix2[ 2]];
311 s += sq[pix1[ 3] - pix2[ 3]];
312 s += sq[pix1[ 4] - pix2[ 4]];
313 s += sq[pix1[ 5] - pix2[ 5]];
314 s += sq[pix1[ 6] - pix2[ 6]];
315 s += sq[pix1[ 7] - pix2[ 7]];
316 s += sq[pix1[ 8] - pix2[ 8]];
317 s += sq[pix1[ 9] - pix2[ 9]];
318 s += sq[pix1[10] - pix2[10]];
319 s += sq[pix1[11] - pix2[11]];
320 s += sq[pix1[12] - pix2[12]];
321 s += sq[pix1[13] - pix2[13]];
322 s += sq[pix1[14] - pix2[14]];
323 s += sq[pix1[15] - pix2[15]];
324
325 pix1 += line_size;
326 pix2 += line_size;
327 }
328 return s;
329}
330
331/* draw the edges of width 'w' of an image of size width, height */
332//FIXME check that this is ok for mpeg4 interlaced
333static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w)
334{
335 uint8_t *ptr, *last_line;
336 int i;
337
338 last_line = buf + (height - 1) * wrap;
339 for(i=0;i<w;i++) {
340 /* top and bottom */
341 memcpy(buf - (i + 1) * wrap, buf, width);
342 memcpy(last_line + (i + 1) * wrap, last_line, width);
343 }
344 /* left and right */
345 ptr = buf;
346 for(i=0;i<height;i++) {
347 memset(ptr - w, ptr[0], w);
348 memset(ptr + width, ptr[width-1], w);
349 ptr += wrap;
350 }
351 /* corners */
352 for(i=0;i<w;i++) {
353 memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */
354 memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */
355 memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */
356 memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */
357 }
358}
359
360/**
361 * Copies a rectangular area of samples to a temporary buffer and replicates the boarder samples.
362 * @param buf destination buffer
363 * @param src source buffer
364 * @param linesize number of bytes between 2 vertically adjacent samples in both the source and destination buffers
365 * @param block_w width of block
366 * @param block_h height of block
367 * @param src_x x coordinate of the top left sample of the block in the source buffer
368 * @param src_y y coordinate of the top left sample of the block in the source buffer
369 * @param w width of the source buffer
370 * @param h height of the source buffer
371 */
372void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, int block_h,
373 int src_x, int src_y, int w, int h){
374 int x, y;
375 int start_y, start_x, end_y, end_x;
376
377 if(src_y>= h){
378 src+= (h-1-src_y)*linesize;
379 src_y=h-1;
380 }else if(src_y<=-block_h){
381 src+= (1-block_h-src_y)*linesize;
382 src_y=1-block_h;
383 }
384 if(src_x>= w){
385 src+= (w-1-src_x);
386 src_x=w-1;
387 }else if(src_x<=-block_w){
388 src+= (1-block_w-src_x);
389 src_x=1-block_w;
390 }
391
392 start_y= FFMAX(0, -src_y);
393 start_x= FFMAX(0, -src_x);
394 end_y= FFMIN(block_h, h-src_y);
395 end_x= FFMIN(block_w, w-src_x);
396
397 // copy existing part
398 for(y=start_y; y<end_y; y++){
399 for(x=start_x; x<end_x; x++){
400 buf[x + y*linesize]= src[x + y*linesize];
401 }
402 }
403
404 //top
405 for(y=0; y<start_y; y++){
406 for(x=start_x; x<end_x; x++){
407 buf[x + y*linesize]= buf[x + start_y*linesize];
408 }
409 }
410
411 //bottom
412 for(y=end_y; y<block_h; y++){
413 for(x=start_x; x<end_x; x++){
414 buf[x + y*linesize]= buf[x + (end_y-1)*linesize];
415 }
416 }
417
418 for(y=0; y<block_h; y++){
419 //left
420 for(x=0; x<start_x; x++){
421 buf[x + y*linesize]= buf[start_x + y*linesize];
422 }
423
424 //right
425 for(x=end_x; x<block_w; x++){
426 buf[x + y*linesize]= buf[end_x - 1 + y*linesize];
427 }
428 }
429}
430
431static void get_pixels_c(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
432{
433 int i;
434
435 /* read the pixels */
436 for(i=0;i<8;i++) {
437 block[0] = pixels[0];
438 block[1] = pixels[1];
439 block[2] = pixels[2];
440 block[3] = pixels[3];
441 block[4] = pixels[4];
442 block[5] = pixels[5];
443 block[6] = pixels[6];
444 block[7] = pixels[7];
445 pixels += line_size;
446 block += 8;
447 }
448}
449
450static void diff_pixels_c(DCTELEM *restrict block, const uint8_t *s1,
451 const uint8_t *s2, int stride){
452 int i;
453
454 /* read the pixels */
455 for(i=0;i<8;i++) {
456 block[0] = s1[0] - s2[0];
457 block[1] = s1[1] - s2[1];
458 block[2] = s1[2] - s2[2];
459 block[3] = s1[3] - s2[3];
460 block[4] = s1[4] - s2[4];
461 block[5] = s1[5] - s2[5];
462 block[6] = s1[6] - s2[6];
463 block[7] = s1[7] - s2[7];
464 s1 += stride;
465 s2 += stride;
466 block += 8;
467 }
468}
469
470
471static void put_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
472 int line_size)
473{
474 int i;
475 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
476
477 /* read the pixels */
478 for(i=0;i<8;i++) {
479 pixels[0] = cm[block[0]];
480 pixels[1] = cm[block[1]];
481 pixels[2] = cm[block[2]];
482 pixels[3] = cm[block[3]];
483 pixels[4] = cm[block[4]];
484 pixels[5] = cm[block[5]];
485 pixels[6] = cm[block[6]];
486 pixels[7] = cm[block[7]];
487
488 pixels += line_size;
489 block += 8;
490 }
491}
492
493static void put_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
494 int line_size)
495{
496 int i;
497 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
498
499 /* read the pixels */
500 for(i=0;i<4;i++) {
501 pixels[0] = cm[block[0]];
502 pixels[1] = cm[block[1]];
503 pixels[2] = cm[block[2]];
504 pixels[3] = cm[block[3]];
505
506 pixels += line_size;
507 block += 8;
508 }
509}
510
511static void put_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
512 int line_size)
513{
514 int i;
515 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
516
517 /* read the pixels */
518 for(i=0;i<2;i++) {
519 pixels[0] = cm[block[0]];
520 pixels[1] = cm[block[1]];
521
522 pixels += line_size;
523 block += 8;
524 }
525}
526
527static void put_signed_pixels_clamped_c(const DCTELEM *block,
528 uint8_t *restrict pixels,
529 int line_size)
530{
531 int i, j;
532
533 for (i = 0; i < 8; i++) {
534 for (j = 0; j < 8; j++) {
535 if (*block < -128)
536 *pixels = 0;
537 else if (*block > 127)
538 *pixels = 255;
539 else
540 *pixels = (uint8_t)(*block + 128);
541 block++;
542 pixels++;
543 }
544 pixels += (line_size - 8);
545 }
546}
547
548static void put_pixels_nonclamped_c(const DCTELEM *block, uint8_t *restrict pixels,
549 int line_size)
550{
551 int i;
552
553 /* read the pixels */
554 for(i=0;i<8;i++) {
555 pixels[0] = block[0];
556 pixels[1] = block[1];
557 pixels[2] = block[2];
558 pixels[3] = block[3];
559 pixels[4] = block[4];
560 pixels[5] = block[5];
561 pixels[6] = block[6];
562 pixels[7] = block[7];
563
564 pixels += line_size;
565 block += 8;
566 }
567}
568
569static void add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
570 int line_size)
571{
572 int i;
573 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
574
575 /* read the pixels */
576 for(i=0;i<8;i++) {
577 pixels[0] = cm[pixels[0] + block[0]];
578 pixels[1] = cm[pixels[1] + block[1]];
579 pixels[2] = cm[pixels[2] + block[2]];
580 pixels[3] = cm[pixels[3] + block[3]];
581 pixels[4] = cm[pixels[4] + block[4]];
582 pixels[5] = cm[pixels[5] + block[5]];
583 pixels[6] = cm[pixels[6] + block[6]];
584 pixels[7] = cm[pixels[7] + block[7]];
585 pixels += line_size;
586 block += 8;
587 }
588}
589
590static void add_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
591 int line_size)
592{
593 int i;
594 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
595
596 /* read the pixels */
597 for(i=0;i<4;i++) {
598 pixels[0] = cm[pixels[0] + block[0]];
599 pixels[1] = cm[pixels[1] + block[1]];
600 pixels[2] = cm[pixels[2] + block[2]];
601 pixels[3] = cm[pixels[3] + block[3]];
602 pixels += line_size;
603 block += 8;
604 }
605}
606
607static void add_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
608 int line_size)
609{
610 int i;
611 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
612
613 /* read the pixels */
614 for(i=0;i<2;i++) {
615 pixels[0] = cm[pixels[0] + block[0]];
616 pixels[1] = cm[pixels[1] + block[1]];
617 pixels += line_size;
618 block += 8;
619 }
620}
621
622static void add_pixels8_c(uint8_t *restrict pixels, DCTELEM *block, int line_size)
623{
624 int i;
625 for(i=0;i<8;i++) {
626 pixels[0] += block[0];
627 pixels[1] += block[1];
628 pixels[2] += block[2];
629 pixels[3] += block[3];
630 pixels[4] += block[4];
631 pixels[5] += block[5];
632 pixels[6] += block[6];
633 pixels[7] += block[7];
634 pixels += line_size;
635 block += 8;
636 }
637}
638
639static void add_pixels4_c(uint8_t *restrict pixels, DCTELEM *block, int line_size)
640{
641 int i;
642 for(i=0;i<4;i++) {
643 pixels[0] += block[0];
644 pixels[1] += block[1];
645 pixels[2] += block[2];
646 pixels[3] += block[3];
647 pixels += line_size;
648 block += 4;
649 }
650}
651
652static int sum_abs_dctelem_c(DCTELEM *block)
653{
654 int sum=0, i;
655 for(i=0; i<64; i++)
656 sum+= FFABS(block[i]);
657 return sum;
658}
659
660static void fill_block16_c(uint8_t *block, uint8_t value, int line_size, int h)
661{
662 int i;
663
664 for (i = 0; i < h; i++) {
665 memset(block, value, 16);
666 block += line_size;
667 }
668}
669
670static void fill_block8_c(uint8_t *block, uint8_t value, int line_size, int h)
671{
672 int i;
673
674 for (i = 0; i < h; i++) {
675 memset(block, value, 8);
676 block += line_size;
677 }
678}
679
680static void scale_block_c(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize)
681{
682 int i, j;
683 uint16_t *dst1 = (uint16_t *) dst;
684 uint16_t *dst2 = (uint16_t *)(dst + linesize);
685
686 for (j = 0; j < 8; j++) {
687 for (i = 0; i < 8; i++) {
688 dst1[i] = dst2[i] = src[i] * 0x0101;
689 }
690 src += 8;
691 dst1 += linesize;
692 dst2 += linesize;
693 }
694}
695
696#if 0
697
698#define PIXOP2(OPNAME, OP) \
699static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
700{\
701 int i;\
702 for(i=0; i<h; i++){\
703 OP(*((uint64_t*)block), AV_RN64(pixels));\
704 pixels+=line_size;\
705 block +=line_size;\
706 }\
707}\
708\
709static void OPNAME ## _no_rnd_pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
710{\
711 int i;\
712 for(i=0; i<h; i++){\
713 const uint64_t a= AV_RN64(pixels );\
714 const uint64_t b= AV_RN64(pixels+1);\
715 OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
716 pixels+=line_size;\
717 block +=line_size;\
718 }\
719}\
720\
721static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
722{\
723 int i;\
724 for(i=0; i<h; i++){\
725 const uint64_t a= AV_RN64(pixels );\
726 const uint64_t b= AV_RN64(pixels+1);\
727 OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
728 pixels+=line_size;\
729 block +=line_size;\
730 }\
731}\
732\
733static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
734{\
735 int i;\
736 for(i=0; i<h; i++){\
737 const uint64_t a= AV_RN64(pixels );\
738 const uint64_t b= AV_RN64(pixels+line_size);\
739 OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
740 pixels+=line_size;\
741 block +=line_size;\
742 }\
743}\
744\
745static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
746{\
747 int i;\
748 for(i=0; i<h; i++){\
749 const uint64_t a= AV_RN64(pixels );\
750 const uint64_t b= AV_RN64(pixels+line_size);\
751 OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
752 pixels+=line_size;\
753 block +=line_size;\
754 }\
755}\
756\
757static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
758{\
759 int i;\
760 const uint64_t a= AV_RN64(pixels );\
761 const uint64_t b= AV_RN64(pixels+1);\
762 uint64_t l0= (a&0x0303030303030303ULL)\
763 + (b&0x0303030303030303ULL)\
764 + 0x0202020202020202ULL;\
765 uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
766 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
767 uint64_t l1,h1;\
768\
769 pixels+=line_size;\
770 for(i=0; i<h; i+=2){\
771 uint64_t a= AV_RN64(pixels );\
772 uint64_t b= AV_RN64(pixels+1);\
773 l1= (a&0x0303030303030303ULL)\
774 + (b&0x0303030303030303ULL);\
775 h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
776 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
777 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
778 pixels+=line_size;\
779 block +=line_size;\
780 a= AV_RN64(pixels );\
781 b= AV_RN64(pixels+1);\
782 l0= (a&0x0303030303030303ULL)\
783 + (b&0x0303030303030303ULL)\
784 + 0x0202020202020202ULL;\
785 h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
786 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
787 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
788 pixels+=line_size;\
789 block +=line_size;\
790 }\
791}\
792\
793static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
794{\
795 int i;\
796 const uint64_t a= AV_RN64(pixels );\
797 const uint64_t b= AV_RN64(pixels+1);\
798 uint64_t l0= (a&0x0303030303030303ULL)\
799 + (b&0x0303030303030303ULL)\
800 + 0x0101010101010101ULL;\
801 uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
802 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
803 uint64_t l1,h1;\
804\
805 pixels+=line_size;\
806 for(i=0; i<h; i+=2){\
807 uint64_t a= AV_RN64(pixels );\
808 uint64_t b= AV_RN64(pixels+1);\
809 l1= (a&0x0303030303030303ULL)\
810 + (b&0x0303030303030303ULL);\
811 h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
812 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
813 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
814 pixels+=line_size;\
815 block +=line_size;\
816 a= AV_RN64(pixels );\
817 b= AV_RN64(pixels+1);\
818 l0= (a&0x0303030303030303ULL)\
819 + (b&0x0303030303030303ULL)\
820 + 0x0101010101010101ULL;\
821 h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
822 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
823 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
824 pixels+=line_size;\
825 block +=line_size;\
826 }\
827}\
828\
829CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8)\
830CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8)\
831CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8)\
832CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8)\
833CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8)\
834CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8)\
835CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8)
836
837#define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) )
838#else // 64 bit variant
839
840#define PIXOP2(OPNAME, OP) \
841static void OPNAME ## _pixels2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
842 int i;\
843 for(i=0; i<h; i++){\
844 OP(*((uint16_t*)(block )), AV_RN16(pixels ));\
845 pixels+=line_size;\
846 block +=line_size;\
847 }\
848}\
849static void OPNAME ## _pixels4_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
850 int i;\
851 for(i=0; i<h; i++){\
852 OP(*((uint32_t*)(block )), AV_RN32(pixels ));\
853 pixels+=line_size;\
854 block +=line_size;\
855 }\
856}\
857static void OPNAME ## _pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
858 int i;\
859 for(i=0; i<h; i++){\
860 OP(*((uint32_t*)(block )), AV_RN32(pixels ));\
861 OP(*((uint32_t*)(block+4)), AV_RN32(pixels+4));\
862 pixels+=line_size;\
863 block +=line_size;\
864 }\
865}\
866static inline void OPNAME ## _no_rnd_pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
867 OPNAME ## _pixels8_c(block, pixels, line_size, h);\
868}\
869\
870static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
871 int src_stride1, int src_stride2, int h){\
872 int i;\
873 for(i=0; i<h; i++){\
874 uint32_t a,b;\
875 a= AV_RN32(&src1[i*src_stride1 ]);\
876 b= AV_RN32(&src2[i*src_stride2 ]);\
877 OP(*((uint32_t*)&dst[i*dst_stride ]), no_rnd_avg32(a, b));\
878 a= AV_RN32(&src1[i*src_stride1+4]);\
879 b= AV_RN32(&src2[i*src_stride2+4]);\
880 OP(*((uint32_t*)&dst[i*dst_stride+4]), no_rnd_avg32(a, b));\
881 }\
882}\
883\
884static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
885 int src_stride1, int src_stride2, int h){\
886 int i;\
887 for(i=0; i<h; i++){\
888 uint32_t a,b;\
889 a= AV_RN32(&src1[i*src_stride1 ]);\
890 b= AV_RN32(&src2[i*src_stride2 ]);\
891 OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
892 a= AV_RN32(&src1[i*src_stride1+4]);\
893 b= AV_RN32(&src2[i*src_stride2+4]);\
894 OP(*((uint32_t*)&dst[i*dst_stride+4]), rnd_avg32(a, b));\
895 }\
896}\
897\
898static inline void OPNAME ## _pixels4_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
899 int src_stride1, int src_stride2, int h){\
900 int i;\
901 for(i=0; i<h; i++){\
902 uint32_t a,b;\
903 a= AV_RN32(&src1[i*src_stride1 ]);\
904 b= AV_RN32(&src2[i*src_stride2 ]);\
905 OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
906 }\
907}\
908\
909static inline void OPNAME ## _pixels2_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
910 int src_stride1, int src_stride2, int h){\
911 int i;\
912 for(i=0; i<h; i++){\
913 uint32_t a,b;\
914 a= AV_RN16(&src1[i*src_stride1 ]);\
915 b= AV_RN16(&src2[i*src_stride2 ]);\
916 OP(*((uint16_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
917 }\
918}\
919\
920static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
921 int src_stride1, int src_stride2, int h){\
922 OPNAME ## _pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
923 OPNAME ## _pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
924}\
925\
926static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
927 int src_stride1, int src_stride2, int h){\
928 OPNAME ## _no_rnd_pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
929 OPNAME ## _no_rnd_pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
930}\
931\
932static inline void OPNAME ## _no_rnd_pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
933 OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
934}\
935\
936static inline void OPNAME ## _pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
937 OPNAME ## _pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
938}\
939\
940static inline void OPNAME ## _no_rnd_pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
941 OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
942}\
943\
944static inline void OPNAME ## _pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
945 OPNAME ## _pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
946}\
947\
948static inline void OPNAME ## _pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
949 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
950 int i;\
951 for(i=0; i<h; i++){\
952 uint32_t a, b, c, d, l0, l1, h0, h1;\
953 a= AV_RN32(&src1[i*src_stride1]);\
954 b= AV_RN32(&src2[i*src_stride2]);\
955 c= AV_RN32(&src3[i*src_stride3]);\
956 d= AV_RN32(&src4[i*src_stride4]);\
957 l0= (a&0x03030303UL)\
958 + (b&0x03030303UL)\
959 + 0x02020202UL;\
960 h0= ((a&0xFCFCFCFCUL)>>2)\
961 + ((b&0xFCFCFCFCUL)>>2);\
962 l1= (c&0x03030303UL)\
963 + (d&0x03030303UL);\
964 h1= ((c&0xFCFCFCFCUL)>>2)\
965 + ((d&0xFCFCFCFCUL)>>2);\
966 OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
967 a= AV_RN32(&src1[i*src_stride1+4]);\
968 b= AV_RN32(&src2[i*src_stride2+4]);\
969 c= AV_RN32(&src3[i*src_stride3+4]);\
970 d= AV_RN32(&src4[i*src_stride4+4]);\
971 l0= (a&0x03030303UL)\
972 + (b&0x03030303UL)\
973 + 0x02020202UL;\
974 h0= ((a&0xFCFCFCFCUL)>>2)\
975 + ((b&0xFCFCFCFCUL)>>2);\
976 l1= (c&0x03030303UL)\
977 + (d&0x03030303UL);\
978 h1= ((c&0xFCFCFCFCUL)>>2)\
979 + ((d&0xFCFCFCFCUL)>>2);\
980 OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
981 }\
982}\
983\
984static inline void OPNAME ## _pixels4_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
985 OPNAME ## _pixels4_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
986}\
987\
988static inline void OPNAME ## _pixels4_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
989 OPNAME ## _pixels4_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
990}\
991\
992static inline void OPNAME ## _pixels2_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
993 OPNAME ## _pixels2_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
994}\
995\
996static inline void OPNAME ## _pixels2_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
997 OPNAME ## _pixels2_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
998}\
999\
1000static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
1001 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
1002 int i;\
1003 for(i=0; i<h; i++){\
1004 uint32_t a, b, c, d, l0, l1, h0, h1;\
1005 a= AV_RN32(&src1[i*src_stride1]);\
1006 b= AV_RN32(&src2[i*src_stride2]);\
1007 c= AV_RN32(&src3[i*src_stride3]);\
1008 d= AV_RN32(&src4[i*src_stride4]);\
1009 l0= (a&0x03030303UL)\
1010 + (b&0x03030303UL)\
1011 + 0x01010101UL;\
1012 h0= ((a&0xFCFCFCFCUL)>>2)\
1013 + ((b&0xFCFCFCFCUL)>>2);\
1014 l1= (c&0x03030303UL)\
1015 + (d&0x03030303UL);\
1016 h1= ((c&0xFCFCFCFCUL)>>2)\
1017 + ((d&0xFCFCFCFCUL)>>2);\
1018 OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1019 a= AV_RN32(&src1[i*src_stride1+4]);\
1020 b= AV_RN32(&src2[i*src_stride2+4]);\
1021 c= AV_RN32(&src3[i*src_stride3+4]);\
1022 d= AV_RN32(&src4[i*src_stride4+4]);\
1023 l0= (a&0x03030303UL)\
1024 + (b&0x03030303UL)\
1025 + 0x01010101UL;\
1026 h0= ((a&0xFCFCFCFCUL)>>2)\
1027 + ((b&0xFCFCFCFCUL)>>2);\
1028 l1= (c&0x03030303UL)\
1029 + (d&0x03030303UL);\
1030 h1= ((c&0xFCFCFCFCUL)>>2)\
1031 + ((d&0xFCFCFCFCUL)>>2);\
1032 OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1033 }\
1034}\
1035static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
1036 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
1037 OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
1038 OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
1039}\
1040static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
1041 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
1042 OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
1043 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);\
1044}\
1045\
1046static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
1047{\
1048 int i, a0, b0, a1, b1;\
1049 a0= pixels[0];\
1050 b0= pixels[1] + 2;\
1051 a0 += b0;\
1052 b0 += pixels[2];\
1053\
1054 pixels+=line_size;\
1055 for(i=0; i<h; i+=2){\
1056 a1= pixels[0];\
1057 b1= pixels[1];\
1058 a1 += b1;\
1059 b1 += pixels[2];\
1060\
1061 block[0]= (a1+a0)>>2; /* FIXME non put */\
1062 block[1]= (b1+b0)>>2;\
1063\
1064 pixels+=line_size;\
1065 block +=line_size;\
1066\
1067 a0= pixels[0];\
1068 b0= pixels[1] + 2;\
1069 a0 += b0;\
1070 b0 += pixels[2];\
1071\
1072 block[0]= (a1+a0)>>2;\
1073 block[1]= (b1+b0)>>2;\
1074 pixels+=line_size;\
1075 block +=line_size;\
1076 }\
1077}\
1078\
1079static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
1080{\
1081 int i;\
1082 const uint32_t a= AV_RN32(pixels );\
1083 const uint32_t b= AV_RN32(pixels+1);\
1084 uint32_t l0= (a&0x03030303UL)\
1085 + (b&0x03030303UL)\
1086 + 0x02020202UL;\
1087 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
1088 + ((b&0xFCFCFCFCUL)>>2);\
1089 uint32_t l1,h1;\
1090\
1091 pixels+=line_size;\
1092 for(i=0; i<h; i+=2){\
1093 uint32_t a= AV_RN32(pixels );\
1094 uint32_t b= AV_RN32(pixels+1);\
1095 l1= (a&0x03030303UL)\
1096 + (b&0x03030303UL);\
1097 h1= ((a&0xFCFCFCFCUL)>>2)\
1098 + ((b&0xFCFCFCFCUL)>>2);\
1099 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1100 pixels+=line_size;\
1101 block +=line_size;\
1102 a= AV_RN32(pixels );\
1103 b= AV_RN32(pixels+1);\
1104 l0= (a&0x03030303UL)\
1105 + (b&0x03030303UL)\
1106 + 0x02020202UL;\
1107 h0= ((a&0xFCFCFCFCUL)>>2)\
1108 + ((b&0xFCFCFCFCUL)>>2);\
1109 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1110 pixels+=line_size;\
1111 block +=line_size;\
1112 }\
1113}\
1114\
1115static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
1116{\
1117 int j;\
1118 for(j=0; j<2; j++){\
1119 int i;\
1120 const uint32_t a= AV_RN32(pixels );\
1121 const uint32_t b= AV_RN32(pixels+1);\
1122 uint32_t l0= (a&0x03030303UL)\
1123 + (b&0x03030303UL)\
1124 + 0x02020202UL;\
1125 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
1126 + ((b&0xFCFCFCFCUL)>>2);\
1127 uint32_t l1,h1;\
1128\
1129 pixels+=line_size;\
1130 for(i=0; i<h; i+=2){\
1131 uint32_t a= AV_RN32(pixels );\
1132 uint32_t b= AV_RN32(pixels+1);\
1133 l1= (a&0x03030303UL)\
1134 + (b&0x03030303UL);\
1135 h1= ((a&0xFCFCFCFCUL)>>2)\
1136 + ((b&0xFCFCFCFCUL)>>2);\
1137 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1138 pixels+=line_size;\
1139 block +=line_size;\
1140 a= AV_RN32(pixels );\
1141 b= AV_RN32(pixels+1);\
1142 l0= (a&0x03030303UL)\
1143 + (b&0x03030303UL)\
1144 + 0x02020202UL;\
1145 h0= ((a&0xFCFCFCFCUL)>>2)\
1146 + ((b&0xFCFCFCFCUL)>>2);\
1147 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1148 pixels+=line_size;\
1149 block +=line_size;\
1150 }\
1151 pixels+=4-line_size*(h+1);\
1152 block +=4-line_size*h;\
1153 }\
1154}\
1155\
1156static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
1157{\
1158 int j;\
1159 for(j=0; j<2; j++){\
1160 int i;\
1161 const uint32_t a= AV_RN32(pixels );\
1162 const uint32_t b= AV_RN32(pixels+1);\
1163 uint32_t l0= (a&0x03030303UL)\
1164 + (b&0x03030303UL)\
1165 + 0x01010101UL;\
1166 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
1167 + ((b&0xFCFCFCFCUL)>>2);\
1168 uint32_t l1,h1;\
1169\
1170 pixels+=line_size;\
1171 for(i=0; i<h; i+=2){\
1172 uint32_t a= AV_RN32(pixels );\
1173 uint32_t b= AV_RN32(pixels+1);\
1174 l1= (a&0x03030303UL)\
1175 + (b&0x03030303UL);\
1176 h1= ((a&0xFCFCFCFCUL)>>2)\
1177 + ((b&0xFCFCFCFCUL)>>2);\
1178 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1179 pixels+=line_size;\
1180 block +=line_size;\
1181 a= AV_RN32(pixels );\
1182 b= AV_RN32(pixels+1);\
1183 l0= (a&0x03030303UL)\
1184 + (b&0x03030303UL)\
1185 + 0x01010101UL;\
1186 h0= ((a&0xFCFCFCFCUL)>>2)\
1187 + ((b&0xFCFCFCFCUL)>>2);\
1188 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
1189 pixels+=line_size;\
1190 block +=line_size;\
1191 }\
1192 pixels+=4-line_size*(h+1);\
1193 block +=4-line_size*h;\
1194 }\
1195}\
1196\
1197CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\
1198CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels8_x2_c , 8)\
1199CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels8_y2_c , 8)\
1200CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels8_xy2_c, 8)\
1201CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_c , OPNAME ## _pixels8_c , 8)\
1202CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels8_x2_c , 8)\
1203CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels8_y2_c , 8)\
1204CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels8_xy2_c, 8)\
1205
1206#define op_avg(a, b) a = rnd_avg32(a, b)
1207#endif
1208#define op_put(a, b) a = b
1209
1210PIXOP2(avg, op_avg)
1211PIXOP2(put, op_put)
1212#undef op_avg
1213#undef op_put
1214
1215#define avg2(a,b) ((a+b+1)>>1)
1216#define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
1217
1218static void put_no_rnd_pixels16_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
1219 put_no_rnd_pixels16_l2(dst, a, b, stride, stride, stride, h);
1220}
1221
1222static void put_no_rnd_pixels8_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
1223 put_no_rnd_pixels8_l2(dst, a, b, stride, stride, stride, h);
1224}
1225
1226static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
1227{
1228 const int A=(16-x16)*(16-y16);
1229 const int B=( x16)*(16-y16);
1230 const int C=(16-x16)*( y16);
1231 const int D=( x16)*( y16);
1232 int i;
1233
1234 for(i=0; i<h; i++)
1235 {
1236 dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
1237 dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
1238 dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
1239 dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
1240 dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
1241 dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
1242 dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
1243 dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
1244 dst+= stride;
1245 src+= stride;
1246 }
1247}
1248
1249void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
1250 int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
1251{
1252 int y, vx, vy;
1253 const int s= 1<<shift;
1254
1255 width--;
1256 height--;
1257
1258 for(y=0; y<h; y++){
1259 int x;
1260
1261 vx= ox;
1262 vy= oy;
1263 for(x=0; x<8; x++){ //XXX FIXME optimize
1264 int src_x, src_y, frac_x, frac_y, index;
1265
1266 src_x= vx>>16;
1267 src_y= vy>>16;
1268 frac_x= src_x&(s-1);
1269 frac_y= src_y&(s-1);
1270 src_x>>=shift;
1271 src_y>>=shift;
1272
1273 if((unsigned)src_x < width){
1274 if((unsigned)src_y < height){
1275 index= src_x + src_y*stride;
1276 dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
1277 + src[index +1]* frac_x )*(s-frac_y)
1278 + ( src[index+stride ]*(s-frac_x)
1279 + src[index+stride+1]* frac_x )* frac_y
1280 + r)>>(shift*2);
1281 }else{
1282 index= src_x + av_clip(src_y, 0, height)*stride;
1283 dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
1284 + src[index +1]* frac_x )*s
1285 + r)>>(shift*2);
1286 }
1287 }else{
1288 if((unsigned)src_y < height){
1289 index= av_clip(src_x, 0, width) + src_y*stride;
1290 dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
1291 + src[index+stride ]* frac_y )*s
1292 + r)>>(shift*2);
1293 }else{
1294 index= av_clip(src_x, 0, width) + av_clip(src_y, 0, height)*stride;
1295 dst[y*stride + x]= src[index ];
1296 }
1297 }
1298
1299 vx+= dxx;
1300 vy+= dyx;
1301 }
1302 ox += dxy;
1303 oy += dyy;
1304 }
1305}
1306
1307static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1308 switch(width){
1309 case 2: put_pixels2_c (dst, src, stride, height); break;
1310 case 4: put_pixels4_c (dst, src, stride, height); break;
1311 case 8: put_pixels8_c (dst, src, stride, height); break;
1312 case 16:put_pixels16_c(dst, src, stride, height); break;
1313 }
1314}
1315
1316static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1317 int i,j;
1318 for (i=0; i < height; i++) {
1319 for (j=0; j < width; j++) {
1320 dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11;
1321 }
1322 src += stride;
1323 dst += stride;
1324 }
1325}
1326
1327static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1328 int i,j;
1329 for (i=0; i < height; i++) {
1330 for (j=0; j < width; j++) {
1331 dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11;
1332 }
1333 src += stride;
1334 dst += stride;
1335 }
1336}
1337
1338static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1339 int i,j;
1340 for (i=0; i < height; i++) {
1341 for (j=0; j < width; j++) {
1342 dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11;
1343 }
1344 src += stride;
1345 dst += stride;
1346 }
1347}
1348
1349static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1350 int i,j;
1351 for (i=0; i < height; i++) {
1352 for (j=0; j < width; j++) {
1353 dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15;
1354 }
1355 src += stride;
1356 dst += stride;
1357 }
1358}
1359
1360static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1361 int i,j;
1362 for (i=0; i < height; i++) {
1363 for (j=0; j < width; j++) {
1364 dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
1365 }
1366 src += stride;
1367 dst += stride;
1368 }
1369}
1370
1371static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1372 int i,j;
1373 for (i=0; i < height; i++) {
1374 for (j=0; j < width; j++) {
1375 dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11;
1376 }
1377 src += stride;
1378 dst += stride;
1379 }
1380}
1381
1382static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1383 int i,j;
1384 for (i=0; i < height; i++) {
1385 for (j=0; j < width; j++) {
1386 dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
1387 }
1388 src += stride;
1389 dst += stride;
1390 }
1391}
1392
1393static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1394 int i,j;
1395 for (i=0; i < height; i++) {
1396 for (j=0; j < width; j++) {
1397 dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15;
1398 }
1399 src += stride;
1400 dst += stride;
1401 }
1402}
1403
1404static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1405 switch(width){
1406 case 2: avg_pixels2_c (dst, src, stride, height); break;
1407 case 4: avg_pixels4_c (dst, src, stride, height); break;
1408 case 8: avg_pixels8_c (dst, src, stride, height); break;
1409 case 16:avg_pixels16_c(dst, src, stride, height); break;
1410 }
1411}
1412
1413static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1414 int i,j;
1415 for (i=0; i < height; i++) {
1416 for (j=0; j < width; j++) {
1417 dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1;
1418 }
1419 src += stride;
1420 dst += stride;
1421 }
1422}
1423
1424static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1425 int i,j;
1426 for (i=0; i < height; i++) {
1427 for (j=0; j < width; j++) {
1428 dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1;
1429 }
1430 src += stride;
1431 dst += stride;
1432 }
1433}
1434
1435static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1436 int i,j;
1437 for (i=0; i < height; i++) {
1438 for (j=0; j < width; j++) {
1439 dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1;
1440 }
1441 src += stride;
1442 dst += stride;
1443 }
1444}
1445
1446static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1447 int i,j;
1448 for (i=0; i < height; i++) {
1449 for (j=0; j < width; j++) {
1450 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;
1451 }
1452 src += stride;
1453 dst += stride;
1454 }
1455}
1456
1457static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1458 int i,j;
1459 for (i=0; i < height; i++) {
1460 for (j=0; j < width; j++) {
1461 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;
1462 }
1463 src += stride;
1464 dst += stride;
1465 }
1466}
1467
1468static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1469 int i,j;
1470 for (i=0; i < height; i++) {
1471 for (j=0; j < width; j++) {
1472 dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1;
1473 }
1474 src += stride;
1475 dst += stride;
1476 }
1477}
1478
1479static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1480 int i,j;
1481 for (i=0; i < height; i++) {
1482 for (j=0; j < width; j++) {
1483 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;
1484 }
1485 src += stride;
1486 dst += stride;
1487 }
1488}
1489
1490static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
1491 int i,j;
1492 for (i=0; i < height; i++) {
1493 for (j=0; j < width; j++) {
1494 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;
1495 }
1496 src += stride;
1497 dst += stride;
1498 }
1499}
1500#if 0
1501#define TPEL_WIDTH(width)\
1502static void put_tpel_pixels ## width ## _mc00_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1503 void put_tpel_pixels_mc00_c(dst, src, stride, width, height);}\
1504static void put_tpel_pixels ## width ## _mc10_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1505 void put_tpel_pixels_mc10_c(dst, src, stride, width, height);}\
1506static void put_tpel_pixels ## width ## _mc20_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1507 void put_tpel_pixels_mc20_c(dst, src, stride, width, height);}\
1508static void put_tpel_pixels ## width ## _mc01_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1509 void put_tpel_pixels_mc01_c(dst, src, stride, width, height);}\
1510static void put_tpel_pixels ## width ## _mc11_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1511 void put_tpel_pixels_mc11_c(dst, src, stride, width, height);}\
1512static void put_tpel_pixels ## width ## _mc21_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1513 void put_tpel_pixels_mc21_c(dst, src, stride, width, height);}\
1514static void put_tpel_pixels ## width ## _mc02_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1515 void put_tpel_pixels_mc02_c(dst, src, stride, width, height);}\
1516static void put_tpel_pixels ## width ## _mc12_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1517 void put_tpel_pixels_mc12_c(dst, src, stride, width, height);}\
1518static void put_tpel_pixels ## width ## _mc22_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
1519 void put_tpel_pixels_mc22_c(dst, src, stride, width, height);}
1520#endif
1521
1522#define H264_CHROMA_MC(OPNAME, OP)\
1523static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
1524 const int A=(8-x)*(8-y);\
1525 const int B=( x)*(8-y);\
1526 const int C=(8-x)*( y);\
1527 const int D=( x)*( y);\
1528 int i;\
1529 \
1530 assert(x<8 && y<8 && x>=0 && y>=0);\
1531\
1532 if(D){\
1533 for(i=0; i<h; i++){\
1534 OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
1535 OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
1536 dst+= stride;\
1537 src+= stride;\
1538 }\
1539 }else{\
1540 const int E= B+C;\
1541 const int step= C ? stride : 1;\
1542 for(i=0; i<h; i++){\
1543 OP(dst[0], (A*src[0] + E*src[step+0]));\
1544 OP(dst[1], (A*src[1] + E*src[step+1]));\
1545 dst+= stride;\
1546 src+= stride;\
1547 }\
1548 }\
1549}\
1550\
1551static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
1552 const int A=(8-x)*(8-y);\
1553 const int B=( x)*(8-y);\
1554 const int C=(8-x)*( y);\
1555 const int D=( x)*( y);\
1556 int i;\
1557 \
1558 assert(x<8 && y<8 && x>=0 && y>=0);\
1559\
1560 if(D){\
1561 for(i=0; i<h; i++){\
1562 OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
1563 OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
1564 OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
1565 OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
1566 dst+= stride;\
1567 src+= stride;\
1568 }\
1569 }else{\
1570 const int E= B+C;\
1571 const int step= C ? stride : 1;\
1572 for(i=0; i<h; i++){\
1573 OP(dst[0], (A*src[0] + E*src[step+0]));\
1574 OP(dst[1], (A*src[1] + E*src[step+1]));\
1575 OP(dst[2], (A*src[2] + E*src[step+2]));\
1576 OP(dst[3], (A*src[3] + E*src[step+3]));\
1577 dst+= stride;\
1578 src+= stride;\
1579 }\
1580 }\
1581}\
1582\
1583static void OPNAME ## h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
1584 const int A=(8-x)*(8-y);\
1585 const int B=( x)*(8-y);\
1586 const int C=(8-x)*( y);\
1587 const int D=( x)*( y);\
1588 int i;\
1589 \
1590 assert(x<8 && y<8 && x>=0 && y>=0);\
1591\
1592 if(D){\
1593 for(i=0; i<h; i++){\
1594 OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
1595 OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
1596 OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
1597 OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
1598 OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
1599 OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
1600 OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
1601 OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
1602 dst+= stride;\
1603 src+= stride;\
1604 }\
1605 }else{\
1606 const int E= B+C;\
1607 const int step= C ? stride : 1;\
1608 for(i=0; i<h; i++){\
1609 OP(dst[0], (A*src[0] + E*src[step+0]));\
1610 OP(dst[1], (A*src[1] + E*src[step+1]));\
1611 OP(dst[2], (A*src[2] + E*src[step+2]));\
1612 OP(dst[3], (A*src[3] + E*src[step+3]));\
1613 OP(dst[4], (A*src[4] + E*src[step+4]));\
1614 OP(dst[5], (A*src[5] + E*src[step+5]));\
1615 OP(dst[6], (A*src[6] + E*src[step+6]));\
1616 OP(dst[7], (A*src[7] + E*src[step+7]));\
1617 dst+= stride;\
1618 src+= stride;\
1619 }\
1620 }\
1621}
1622
1623#define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
1624#define op_put(a, b) a = (((b) + 32)>>6)
1625
1626H264_CHROMA_MC(put_ , op_put)
1627H264_CHROMA_MC(avg_ , op_avg)
1628#undef op_avg
1629#undef op_put
1630
1631static 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){
1632 const int A=(8-x)*(8-y);
1633 const int B=( x)*(8-y);
1634 const int C=(8-x)*( y);
1635 const int D=( x)*( y);
1636 int i;
1637
1638 assert(x<8 && y<8 && x>=0 && y>=0);
1639
1640 for(i=0; i<h; i++)
1641 {
1642 dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
1643 dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
1644 dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
1645 dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
1646 dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6;
1647 dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6;
1648 dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6;
1649 dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6;
1650 dst+= stride;
1651 src+= stride;
1652 }
1653}
1654
1655static 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){
1656 const int A=(8-x)*(8-y);
1657 const int B=( x)*(8-y);
1658 const int C=(8-x)*( y);
1659 const int D=( x)*( y);
1660 int i;
1661
1662 assert(x<8 && y<8 && x>=0 && y>=0);
1663
1664 for(i=0; i<h; i++)
1665 {
1666 dst[0] = avg2(dst[0], ((A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6));
1667 dst[1] = avg2(dst[1], ((A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6));
1668 dst[2] = avg2(dst[2], ((A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6));
1669 dst[3] = avg2(dst[3], ((A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6));
1670 dst[4] = avg2(dst[4], ((A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6));
1671 dst[5] = avg2(dst[5], ((A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6));
1672 dst[6] = avg2(dst[6], ((A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6));
1673 dst[7] = avg2(dst[7], ((A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6));
1674 dst+= stride;
1675 src+= stride;
1676 }
1677}
1678
1679#define QPEL_MC(r, OPNAME, RND, OP) \
1680static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1681 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
1682 int i;\
1683 for(i=0; i<h; i++)\
1684 {\
1685 OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
1686 OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
1687 OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
1688 OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
1689 OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
1690 OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
1691 OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
1692 OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
1693 dst+=dstStride;\
1694 src+=srcStride;\
1695 }\
1696}\
1697\
1698static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1699 const int w=8;\
1700 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
1701 int i;\
1702 for(i=0; i<w; i++)\
1703 {\
1704 const int src0= src[0*srcStride];\
1705 const int src1= src[1*srcStride];\
1706 const int src2= src[2*srcStride];\
1707 const int src3= src[3*srcStride];\
1708 const int src4= src[4*srcStride];\
1709 const int src5= src[5*srcStride];\
1710 const int src6= src[6*srcStride];\
1711 const int src7= src[7*srcStride];\
1712 const int src8= src[8*srcStride];\
1713 OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
1714 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
1715 OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
1716 OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
1717 OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
1718 OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
1719 OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
1720 OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
1721 dst++;\
1722 src++;\
1723 }\
1724}\
1725\
1726static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1727 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
1728 int i;\
1729 \
1730 for(i=0; i<h; i++)\
1731 {\
1732 OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
1733 OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
1734 OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
1735 OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
1736 OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
1737 OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
1738 OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
1739 OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
1740 OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
1741 OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
1742 OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
1743 OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
1744 OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
1745 OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
1746 OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
1747 OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
1748 dst+=dstStride;\
1749 src+=srcStride;\
1750 }\
1751}\
1752\
1753static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1754 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
1755 int i;\
1756 const int w=16;\
1757 for(i=0; i<w; i++)\
1758 {\
1759 const int src0= src[0*srcStride];\
1760 const int src1= src[1*srcStride];\
1761 const int src2= src[2*srcStride];\
1762 const int src3= src[3*srcStride];\
1763 const int src4= src[4*srcStride];\
1764 const int src5= src[5*srcStride];\
1765 const int src6= src[6*srcStride];\
1766 const int src7= src[7*srcStride];\
1767 const int src8= src[8*srcStride];\
1768 const int src9= src[9*srcStride];\
1769 const int src10= src[10*srcStride];\
1770 const int src11= src[11*srcStride];\
1771 const int src12= src[12*srcStride];\
1772 const int src13= src[13*srcStride];\
1773 const int src14= src[14*srcStride];\
1774 const int src15= src[15*srcStride];\
1775 const int src16= src[16*srcStride];\
1776 OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
1777 OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
1778 OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
1779 OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
1780 OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
1781 OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
1782 OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
1783 OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
1784 OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
1785 OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
1786 OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
1787 OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
1788 OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
1789 OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
1790 OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
1791 OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
1792 dst++;\
1793 src++;\
1794 }\
1795}\
1796\
1797static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
1798 OPNAME ## pixels8_c(dst, src, stride, 8);\
1799}\
1800\
1801static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
1802 uint8_t half[64];\
1803 put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
1804 OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
1805}\
1806\
1807static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
1808 OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
1809}\
1810\
1811static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
1812 uint8_t half[64];\
1813 put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
1814 OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
1815}\
1816\
1817static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
1818 uint8_t full[16*9];\
1819 uint8_t half[64];\
1820 copy_block9(full, src, 16, stride, 9);\
1821 put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
1822 OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
1823}\
1824\
1825static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
1826 uint8_t full[16*9];\
1827 copy_block9(full, src, 16, stride, 9);\
1828 OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
1829}\
1830\
1831static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
1832 uint8_t full[16*9];\
1833 uint8_t half[64];\
1834 copy_block9(full, src, 16, stride, 9);\
1835 put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
1836 OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
1837}\
1838void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
1839 uint8_t full[16*9];\
1840 uint8_t halfH[72];\
1841 uint8_t halfV[64];\
1842 uint8_t halfHV[64];\
1843 copy_block9(full, src, 16, stride, 9);\
1844 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1845 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
1846 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1847 OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
1848}\
1849static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
1850 uint8_t full[16*9];\
1851 uint8_t halfH[72];\
1852 uint8_t halfHV[64];\
1853 copy_block9(full, src, 16, stride, 9);\
1854 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1855 put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
1856 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1857 OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
1858}\
1859void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
1860 uint8_t full[16*9];\
1861 uint8_t halfH[72];\
1862 uint8_t halfV[64];\
1863 uint8_t halfHV[64];\
1864 copy_block9(full, src, 16, stride, 9);\
1865 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1866 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
1867 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1868 OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
1869}\
1870static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
1871 uint8_t full[16*9];\
1872 uint8_t halfH[72];\
1873 uint8_t halfHV[64];\
1874 copy_block9(full, src, 16, stride, 9);\
1875 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1876 put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
1877 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1878 OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
1879}\
1880void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
1881 uint8_t full[16*9];\
1882 uint8_t halfH[72];\
1883 uint8_t halfV[64];\
1884 uint8_t halfHV[64];\
1885 copy_block9(full, src, 16, stride, 9);\
1886 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1887 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
1888 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1889 OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
1890}\
1891static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
1892 uint8_t full[16*9];\
1893 uint8_t halfH[72];\
1894 uint8_t halfHV[64];\
1895 copy_block9(full, src, 16, stride, 9);\
1896 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1897 put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
1898 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1899 OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
1900}\
1901void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
1902 uint8_t full[16*9];\
1903 uint8_t halfH[72];\
1904 uint8_t halfV[64];\
1905 uint8_t halfHV[64];\
1906 copy_block9(full, src, 16, stride, 9);\
1907 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
1908 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
1909 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1910 OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
1911}\
1912static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
1913 uint8_t full[16*9];\
1914 uint8_t halfH[72];\
1915 uint8_t halfHV[64];\
1916 copy_block9(full, src, 16, stride, 9);\
1917 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1918 put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
1919 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1920 OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
1921}\
1922static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
1923 uint8_t halfH[72];\
1924 uint8_t halfHV[64];\
1925 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
1926 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1927 OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
1928}\
1929static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
1930 uint8_t halfH[72];\
1931 uint8_t halfHV[64];\
1932 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
1933 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1934 OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
1935}\
1936void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
1937 uint8_t full[16*9];\
1938 uint8_t halfH[72];\
1939 uint8_t halfV[64];\
1940 uint8_t halfHV[64];\
1941 copy_block9(full, src, 16, stride, 9);\
1942 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1943 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
1944 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1945 OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
1946}\
1947static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
1948 uint8_t full[16*9];\
1949 uint8_t halfH[72];\
1950 copy_block9(full, src, 16, stride, 9);\
1951 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1952 put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
1953 OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
1954}\
1955void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
1956 uint8_t full[16*9];\
1957 uint8_t halfH[72];\
1958 uint8_t halfV[64];\
1959 uint8_t halfHV[64];\
1960 copy_block9(full, src, 16, stride, 9);\
1961 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1962 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
1963 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
1964 OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
1965}\
1966static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
1967 uint8_t full[16*9];\
1968 uint8_t halfH[72];\
1969 copy_block9(full, src, 16, stride, 9);\
1970 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1971 put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
1972 OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
1973}\
1974static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
1975 uint8_t halfH[72];\
1976 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
1977 OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
1978}\
1979static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
1980 OPNAME ## pixels16_c(dst, src, stride, 16);\
1981}\
1982\
1983static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
1984 uint8_t half[256];\
1985 put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
1986 OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
1987}\
1988\
1989static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
1990 OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
1991}\
1992\
1993static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
1994 uint8_t half[256];\
1995 put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
1996 OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
1997}\
1998\
1999static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
2000 uint8_t full[24*17];\
2001 uint8_t half[256];\
2002 copy_block17(full, src, 24, stride, 17);\
2003 put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
2004 OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
2005}\
2006\
2007static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
2008 uint8_t full[24*17];\
2009 copy_block17(full, src, 24, stride, 17);\
2010 OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
2011}\
2012\
2013static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
2014 uint8_t full[24*17];\
2015 uint8_t half[256];\
2016 copy_block17(full, src, 24, stride, 17);\
2017 put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
2018 OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
2019}\
2020void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
2021 uint8_t full[24*17];\
2022 uint8_t halfH[272];\
2023 uint8_t halfV[256];\
2024 uint8_t halfHV[256];\
2025 copy_block17(full, src, 24, stride, 17);\
2026 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2027 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
2028 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2029 OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
2030}\
2031static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
2032 uint8_t full[24*17];\
2033 uint8_t halfH[272];\
2034 uint8_t halfHV[256];\
2035 copy_block17(full, src, 24, stride, 17);\
2036 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2037 put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
2038 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2039 OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
2040}\
2041void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
2042 uint8_t full[24*17];\
2043 uint8_t halfH[272];\
2044 uint8_t halfV[256];\
2045 uint8_t halfHV[256];\
2046 copy_block17(full, src, 24, stride, 17);\
2047 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2048 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
2049 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2050 OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
2051}\
2052static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
2053 uint8_t full[24*17];\
2054 uint8_t halfH[272];\
2055 uint8_t halfHV[256];\
2056 copy_block17(full, src, 24, stride, 17);\
2057 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2058 put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
2059 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2060 OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
2061}\
2062void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
2063 uint8_t full[24*17];\
2064 uint8_t halfH[272];\
2065 uint8_t halfV[256];\
2066 uint8_t halfHV[256];\
2067 copy_block17(full, src, 24, stride, 17);\
2068 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2069 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
2070 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2071 OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
2072}\
2073static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
2074 uint8_t full[24*17];\
2075 uint8_t halfH[272];\
2076 uint8_t halfHV[256];\
2077 copy_block17(full, src, 24, stride, 17);\
2078 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2079 put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
2080 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2081 OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
2082}\
2083void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
2084 uint8_t full[24*17];\
2085 uint8_t halfH[272];\
2086 uint8_t halfV[256];\
2087 uint8_t halfHV[256];\
2088 copy_block17(full, src, 24, stride, 17);\
2089 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
2090 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
2091 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2092 OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
2093}\
2094static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
2095 uint8_t full[24*17];\
2096 uint8_t halfH[272];\
2097 uint8_t halfHV[256];\
2098 copy_block17(full, src, 24, stride, 17);\
2099 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2100 put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
2101 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2102 OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
2103}\
2104static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
2105 uint8_t halfH[272];\
2106 uint8_t halfHV[256];\
2107 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
2108 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2109 OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
2110}\
2111static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
2112 uint8_t halfH[272];\
2113 uint8_t halfHV[256];\
2114 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
2115 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2116 OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
2117}\
2118void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
2119 uint8_t full[24*17];\
2120 uint8_t halfH[272];\
2121 uint8_t halfV[256];\
2122 uint8_t halfHV[256];\
2123 copy_block17(full, src, 24, stride, 17);\
2124 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2125 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
2126 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2127 OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
2128}\
2129static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
2130 uint8_t full[24*17];\
2131 uint8_t halfH[272];\
2132 copy_block17(full, src, 24, stride, 17);\
2133 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2134 put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
2135 OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
2136}\
2137void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
2138 uint8_t full[24*17];\
2139 uint8_t halfH[272];\
2140 uint8_t halfV[256];\
2141 uint8_t halfHV[256];\
2142 copy_block17(full, src, 24, stride, 17);\
2143 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2144 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
2145 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
2146 OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
2147}\
2148static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
2149 uint8_t full[24*17];\
2150 uint8_t halfH[272];\
2151 copy_block17(full, src, 24, stride, 17);\
2152 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
2153 put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
2154 OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
2155}\
2156static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
2157 uint8_t halfH[272];\
2158 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
2159 OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
2160}
2161
2162#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
2163#define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
2164#define op_put(a, b) a = cm[((b) + 16)>>5]
2165#define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
2166
2167QPEL_MC(0, put_ , _ , op_put)
2168QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
2169QPEL_MC(0, avg_ , _ , op_avg)
2170//QPEL_MC(1, avg_no_rnd , _ , op_avg)
2171#undef op_avg
2172#undef op_avg_no_rnd
2173#undef op_put
2174#undef op_put_no_rnd
2175
2176#if 1
2177#define H264_LOWPASS(OPNAME, OP, OP2) \
2178static av_unused void OPNAME ## h264_qpel2_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2179 const int h=2;\
2180 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2181 int i;\
2182 for(i=0; i<h; i++)\
2183 {\
2184 OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
2185 OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
2186 dst+=dstStride;\
2187 src+=srcStride;\
2188 }\
2189}\
2190\
2191static av_unused void OPNAME ## h264_qpel2_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2192 const int w=2;\
2193 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2194 int i;\
2195 for(i=0; i<w; i++)\
2196 {\
2197 const int srcB= src[-2*srcStride];\
2198 const int srcA= src[-1*srcStride];\
2199 const int src0= src[0 *srcStride];\
2200 const int src1= src[1 *srcStride];\
2201 const int src2= src[2 *srcStride];\
2202 const int src3= src[3 *srcStride];\
2203 const int src4= src[4 *srcStride];\
2204 OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
2205 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
2206 dst++;\
2207 src++;\
2208 }\
2209}\
2210\
2211static av_unused void OPNAME ## h264_qpel2_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
2212 const int h=2;\
2213 const int w=2;\
2214 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2215 int i;\
2216 src -= 2*srcStride;\
2217 for(i=0; i<h+5; i++)\
2218 {\
2219 tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
2220 tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
2221 tmp+=tmpStride;\
2222 src+=srcStride;\
2223 }\
2224 tmp -= tmpStride*(h+5-2);\
2225 for(i=0; i<w; i++)\
2226 {\
2227 const int tmpB= tmp[-2*tmpStride];\
2228 const int tmpA= tmp[-1*tmpStride];\
2229 const int tmp0= tmp[0 *tmpStride];\
2230 const int tmp1= tmp[1 *tmpStride];\
2231 const int tmp2= tmp[2 *tmpStride];\
2232 const int tmp3= tmp[3 *tmpStride];\
2233 const int tmp4= tmp[4 *tmpStride];\
2234 OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
2235 OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
2236 dst++;\
2237 tmp++;\
2238 }\
2239}\
2240static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2241 const int h=4;\
2242 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2243 int i;\
2244 for(i=0; i<h; i++)\
2245 {\
2246 OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
2247 OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
2248 OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
2249 OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
2250 dst+=dstStride;\
2251 src+=srcStride;\
2252 }\
2253}\
2254\
2255static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2256 const int w=4;\
2257 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2258 int i;\
2259 for(i=0; i<w; i++)\
2260 {\
2261 const int srcB= src[-2*srcStride];\
2262 const int srcA= src[-1*srcStride];\
2263 const int src0= src[0 *srcStride];\
2264 const int src1= src[1 *srcStride];\
2265 const int src2= src[2 *srcStride];\
2266 const int src3= src[3 *srcStride];\
2267 const int src4= src[4 *srcStride];\
2268 const int src5= src[5 *srcStride];\
2269 const int src6= src[6 *srcStride];\
2270 OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
2271 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
2272 OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
2273 OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
2274 dst++;\
2275 src++;\
2276 }\
2277}\
2278\
2279static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
2280 const int h=4;\
2281 const int w=4;\
2282 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2283 int i;\
2284 src -= 2*srcStride;\
2285 for(i=0; i<h+5; i++)\
2286 {\
2287 tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
2288 tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
2289 tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\
2290 tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\
2291 tmp+=tmpStride;\
2292 src+=srcStride;\
2293 }\
2294 tmp -= tmpStride*(h+5-2);\
2295 for(i=0; i<w; i++)\
2296 {\
2297 const int tmpB= tmp[-2*tmpStride];\
2298 const int tmpA= tmp[-1*tmpStride];\
2299 const int tmp0= tmp[0 *tmpStride];\
2300 const int tmp1= tmp[1 *tmpStride];\
2301 const int tmp2= tmp[2 *tmpStride];\
2302 const int tmp3= tmp[3 *tmpStride];\
2303 const int tmp4= tmp[4 *tmpStride];\
2304 const int tmp5= tmp[5 *tmpStride];\
2305 const int tmp6= tmp[6 *tmpStride];\
2306 OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
2307 OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
2308 OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
2309 OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
2310 dst++;\
2311 tmp++;\
2312 }\
2313}\
2314\
2315static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2316 const int h=8;\
2317 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2318 int i;\
2319 for(i=0; i<h; i++)\
2320 {\
2321 OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
2322 OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
2323 OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
2324 OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
2325 OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
2326 OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
2327 OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
2328 OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
2329 dst+=dstStride;\
2330 src+=srcStride;\
2331 }\
2332}\
2333\
2334static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2335 const int w=8;\
2336 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2337 int i;\
2338 for(i=0; i<w; i++)\
2339 {\
2340 const int srcB= src[-2*srcStride];\
2341 const int srcA= src[-1*srcStride];\
2342 const int src0= src[0 *srcStride];\
2343 const int src1= src[1 *srcStride];\
2344 const int src2= src[2 *srcStride];\
2345 const int src3= src[3 *srcStride];\
2346 const int src4= src[4 *srcStride];\
2347 const int src5= src[5 *srcStride];\
2348 const int src6= src[6 *srcStride];\
2349 const int src7= src[7 *srcStride];\
2350 const int src8= src[8 *srcStride];\
2351 const int src9= src[9 *srcStride];\
2352 const int src10=src[10*srcStride];\
2353 OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
2354 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
2355 OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
2356 OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
2357 OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
2358 OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
2359 OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
2360 OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
2361 dst++;\
2362 src++;\
2363 }\
2364}\
2365\
2366static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
2367 const int h=8;\
2368 const int w=8;\
2369 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
2370 int i;\
2371 src -= 2*srcStride;\
2372 for(i=0; i<h+5; i++)\
2373 {\
2374 tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\
2375 tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\
2376 tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\
2377 tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\
2378 tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\
2379 tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\
2380 tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\
2381 tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\
2382 tmp+=tmpStride;\
2383 src+=srcStride;\
2384 }\
2385 tmp -= tmpStride*(h+5-2);\
2386 for(i=0; i<w; i++)\
2387 {\
2388 const int tmpB= tmp[-2*tmpStride];\
2389 const int tmpA= tmp[-1*tmpStride];\
2390 const int tmp0= tmp[0 *tmpStride];\
2391 const int tmp1= tmp[1 *tmpStride];\
2392 const int tmp2= tmp[2 *tmpStride];\
2393 const int tmp3= tmp[3 *tmpStride];\
2394 const int tmp4= tmp[4 *tmpStride];\
2395 const int tmp5= tmp[5 *tmpStride];\
2396 const int tmp6= tmp[6 *tmpStride];\
2397 const int tmp7= tmp[7 *tmpStride];\
2398 const int tmp8= tmp[8 *tmpStride];\
2399 const int tmp9= tmp[9 *tmpStride];\
2400 const int tmp10=tmp[10*tmpStride];\
2401 OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
2402 OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
2403 OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
2404 OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
2405 OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
2406 OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
2407 OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
2408 OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
2409 dst++;\
2410 tmp++;\
2411 }\
2412}\
2413\
2414static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2415 OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
2416 OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
2417 src += 8*srcStride;\
2418 dst += 8*dstStride;\
2419 OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
2420 OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
2421}\
2422\
2423static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2424 OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
2425 OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
2426 src += 8*srcStride;\
2427 dst += 8*dstStride;\
2428 OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
2429 OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
2430}\
2431\
2432static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
2433 OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
2434 OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
2435 src += 8*srcStride;\
2436 dst += 8*dstStride;\
2437 OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
2438 OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
2439}\
2440
2441#define H264_MC(OPNAME, SIZE) \
2442static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
2443 OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
2444}\
2445\
2446static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
2447 uint8_t half[SIZE*SIZE];\
2448 put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
2449 OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\
2450}\
2451\
2452static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
2453 OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
2454}\
2455\
2456static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
2457 uint8_t half[SIZE*SIZE];\
2458 put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
2459 OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\
2460}\
2461\
2462static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
2463 uint8_t full[SIZE*(SIZE+5)];\
2464 uint8_t * const full_mid= full + SIZE*2;\
2465 uint8_t half[SIZE*SIZE];\
2466 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
2467 put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
2468 OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
2469}\
2470\
2471static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
2472 uint8_t full[SIZE*(SIZE+5)];\
2473 uint8_t * const full_mid= full + SIZE*2;\
2474 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
2475 OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
2476}\
2477\
2478static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
2479 uint8_t full[SIZE*(SIZE+5)];\
2480 uint8_t * const full_mid= full + SIZE*2;\
2481 uint8_t half[SIZE*SIZE];\
2482 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
2483 put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
2484 OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
2485}\
2486\
2487static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
2488 uint8_t full[SIZE*(SIZE+5)];\
2489 uint8_t * const full_mid= full + SIZE*2;\
2490 uint8_t halfH[SIZE*SIZE];\
2491 uint8_t halfV[SIZE*SIZE];\
2492 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
2493 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
2494 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
2495 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
2496}\
2497\
2498static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
2499 uint8_t full[SIZE*(SIZE+5)];\
2500 uint8_t * const full_mid= full + SIZE*2;\
2501 uint8_t halfH[SIZE*SIZE];\
2502 uint8_t halfV[SIZE*SIZE];\
2503 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
2504 copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
2505 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
2506 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
2507}\
2508\
2509static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
2510 uint8_t full[SIZE*(SIZE+5)];\
2511 uint8_t * const full_mid= full + SIZE*2;\
2512 uint8_t halfH[SIZE*SIZE];\
2513 uint8_t halfV[SIZE*SIZE];\
2514 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
2515 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
2516 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
2517 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
2518}\
2519\
2520static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
2521 uint8_t full[SIZE*(SIZE+5)];\
2522 uint8_t * const full_mid= full + SIZE*2;\
2523 uint8_t halfH[SIZE*SIZE];\
2524 uint8_t halfV[SIZE*SIZE];\
2525 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
2526 copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
2527 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
2528 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
2529}\
2530\
2531static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
2532 int16_t tmp[SIZE*(SIZE+5)];\
2533 OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
2534}\
2535\
2536static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
2537 int16_t tmp[SIZE*(SIZE+5)];\
2538 uint8_t halfH[SIZE*SIZE];\
2539 uint8_t halfHV[SIZE*SIZE];\
2540 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
2541 put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
2542 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
2543}\
2544\
2545static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
2546 int16_t tmp[SIZE*(SIZE+5)];\
2547 uint8_t halfH[SIZE*SIZE];\
2548 uint8_t halfHV[SIZE*SIZE];\
2549 put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
2550 put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
2551 OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
2552}\
2553\
2554static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
2555 uint8_t full[SIZE*(SIZE+5)];\
2556 uint8_t * const full_mid= full + SIZE*2;\
2557 int16_t tmp[SIZE*(SIZE+5)];\
2558 uint8_t halfV[SIZE*SIZE];\
2559 uint8_t halfHV[SIZE*SIZE];\
2560 copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
2561 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
2562 put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
2563 OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
2564}\
2565\
2566static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
2567 uint8_t full[SIZE*(SIZE+5)];\
2568 uint8_t * const full_mid= full + SIZE*2;\
2569 int16_t tmp[SIZE*(SIZE+5)];\
2570 uint8_t halfV[SIZE*SIZE];\
2571 uint8_t halfHV[SIZE*SIZE];\
2572 copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
2573 put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
2574 put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
2575 OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
2576}\
2577
2578#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
2579//#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
2580#define op_put(a, b) a = cm[((b) + 16)>>5]
2581#define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1)
2582#define op2_put(a, b) a = cm[((b) + 512)>>10]
2583
2584H264_LOWPASS(put_ , op_put, op2_put)
2585H264_LOWPASS(avg_ , op_avg, op2_avg)
2586H264_MC(put_, 2)
2587H264_MC(put_, 4)
2588H264_MC(put_, 8)
2589H264_MC(put_, 16)
2590H264_MC(avg_, 4)
2591H264_MC(avg_, 8)
2592H264_MC(avg_, 16)
2593
2594#undef op_avg
2595#undef op_put
2596#undef op2_avg
2597#undef op2_put
2598#endif
2599
2600static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
2601 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
2602 int i;
2603
2604 for(i=0; i<h; i++){
2605 dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
2606 dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
2607 dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
2608 dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
2609 dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
2610 dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
2611 dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
2612 dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
2613 dst+=dstStride;
2614 src+=srcStride;
2615 }
2616}
2617
2618#if CONFIG_CAVS_DECODER
2619/* AVS specific */
2620void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
2621 put_pixels8_c(dst, src, stride, 8);
2622}
2623void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
2624 avg_pixels8_c(dst, src, stride, 8);
2625}
2626void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
2627 put_pixels16_c(dst, src, stride, 16);
2628}
2629void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
2630 avg_pixels16_c(dst, src, stride, 16);
2631}
2632#endif /* CONFIG_CAVS_DECODER */
2633
2634#if CONFIG_VC1_DECODER
2635/* VC-1 specific */
2636void ff_put_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
2637 put_pixels8_c(dst, src, stride, 8);
2638}
2639void ff_avg_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
2640 avg_pixels8_c(dst, src, stride, 8);
2641}
2642#endif /* CONFIG_VC1_DECODER */
2643
2644#if CONFIG_RV40_DECODER
2645static void put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
2646 put_pixels16_xy2_c(dst, src, stride, 16);
2647}
2648static void avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
2649 avg_pixels16_xy2_c(dst, src, stride, 16);
2650}
2651static void put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
2652 put_pixels8_xy2_c(dst, src, stride, 8);
2653}
2654static void avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
2655 avg_pixels8_xy2_c(dst, src, stride, 8);
2656}
2657#endif /* CONFIG_RV40_DECODER */
2658
2659static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
2660 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
2661 int i;
2662
2663 for(i=0; i<w; i++){
2664 const int src_1= src[ -srcStride];
2665 const int src0 = src[0 ];
2666 const int src1 = src[ srcStride];
2667 const int src2 = src[2*srcStride];
2668 const int src3 = src[3*srcStride];
2669 const int src4 = src[4*srcStride];
2670 const int src5 = src[5*srcStride];
2671 const int src6 = src[6*srcStride];
2672 const int src7 = src[7*srcStride];
2673 const int src8 = src[8*srcStride];
2674 const int src9 = src[9*srcStride];
2675 dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
2676 dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
2677 dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
2678 dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
2679 dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
2680 dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
2681 dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
2682 dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
2683 src++;
2684 dst++;
2685 }
2686}
2687
2688static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
2689 put_pixels8_c(dst, src, stride, 8);
2690}
2691
2692static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
2693 uint8_t half[64];
2694 wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
2695 put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
2696}
2697
2698static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
2699 wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
2700}
2701
2702static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
2703 uint8_t half[64];
2704 wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
2705 put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
2706}
2707
2708static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
2709 wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
2710}
2711
2712static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
2713 uint8_t halfH[88];
2714 uint8_t halfV[64];
2715 uint8_t halfHV[64];
2716 wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
2717 wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
2718 wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
2719 put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
2720}
2721static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
2722 uint8_t halfH[88];
2723 uint8_t halfV[64];
2724 uint8_t halfHV[64];
2725 wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
2726 wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
2727 wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
2728 put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
2729}
2730static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
2731 uint8_t halfH[88];
2732 wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
2733 wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
2734}
2735
2736static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
2737 if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
2738 int x;
2739 const int strength= ff_h263_loop_filter_strength[qscale];
2740
2741 for(x=0; x<8; x++){
2742 int d1, d2, ad1;
2743 int p0= src[x-2*stride];
2744 int p1= src[x-1*stride];
2745 int p2= src[x+0*stride];
2746 int p3= src[x+1*stride];
2747 int d = (p0 - p3 + 4*(p2 - p1)) / 8;
2748
2749 if (d<-2*strength) d1= 0;
2750 else if(d<- strength) d1=-2*strength - d;
2751 else if(d< strength) d1= d;
2752 else if(d< 2*strength) d1= 2*strength - d;
2753 else d1= 0;
2754
2755 p1 += d1;
2756 p2 -= d1;
2757 if(p1&256) p1= ~(p1>>31);
2758 if(p2&256) p2= ~(p2>>31);
2759
2760 src[x-1*stride] = p1;
2761 src[x+0*stride] = p2;
2762
2763 ad1= FFABS(d1)>>1;
2764
2765 d2= av_clip((p0-p3)/4, -ad1, ad1);
2766
2767 src[x-2*stride] = p0 - d2;
2768 src[x+ stride] = p3 + d2;
2769 }
2770 }
2771}
2772
2773static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
2774 if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
2775 int y;
2776 const int strength= ff_h263_loop_filter_strength[qscale];
2777
2778 for(y=0; y<8; y++){
2779 int d1, d2, ad1;
2780 int p0= src[y*stride-2];
2781 int p1= src[y*stride-1];
2782 int p2= src[y*stride+0];
2783 int p3= src[y*stride+1];
2784 int d = (p0 - p3 + 4*(p2 - p1)) / 8;
2785
2786 if (d<-2*strength) d1= 0;
2787 else if(d<- strength) d1=-2*strength - d;
2788 else if(d< strength) d1= d;
2789 else if(d< 2*strength) d1= 2*strength - d;
2790 else d1= 0;
2791
2792 p1 += d1;
2793 p2 -= d1;
2794 if(p1&256) p1= ~(p1>>31);
2795 if(p2&256) p2= ~(p2>>31);
2796
2797 src[y*stride-1] = p1;
2798 src[y*stride+0] = p2;
2799
2800 ad1= FFABS(d1)>>1;
2801
2802 d2= av_clip((p0-p3)/4, -ad1, ad1);
2803
2804 src[y*stride-2] = p0 - d2;
2805 src[y*stride+1] = p3 + d2;
2806 }
2807 }
2808}
2809
2810static void h261_loop_filter_c(uint8_t *src, int stride){
2811 int x,y,xy,yz;
2812 int temp[64];
2813
2814 for(x=0; x<8; x++){
2815 temp[x ] = 4*src[x ];
2816 temp[x + 7*8] = 4*src[x + 7*stride];
2817 }
2818 for(y=1; y<7; y++){
2819 for(x=0; x<8; x++){
2820 xy = y * stride + x;
2821 yz = y * 8 + x;
2822 temp[yz] = src[xy - stride] + 2*src[xy] + src[xy + stride];
2823 }
2824 }
2825
2826 for(y=0; y<8; y++){
2827 src[ y*stride] = (temp[ y*8] + 2)>>2;
2828 src[7+y*stride] = (temp[7+y*8] + 2)>>2;
2829 for(x=1; x<7; x++){
2830 xy = y * stride + x;
2831 yz = y * 8 + x;
2832 src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4;
2833 }
2834 }
2835}
2836
2837static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
2838{
2839 int s, i;
2840
2841 s = 0;
2842 for(i=0;i<h;i++) {
2843 s += abs(pix1[0] - pix2[0]);
2844 s += abs(pix1[1] - pix2[1]);
2845 s += abs(pix1[2] - pix2[2]);
2846 s += abs(pix1[3] - pix2[3]);
2847 s += abs(pix1[4] - pix2[4]);
2848 s += abs(pix1[5] - pix2[5]);
2849 s += abs(pix1[6] - pix2[6]);
2850 s += abs(pix1[7] - pix2[7]);
2851 s += abs(pix1[8] - pix2[8]);
2852 s += abs(pix1[9] - pix2[9]);
2853 s += abs(pix1[10] - pix2[10]);
2854 s += abs(pix1[11] - pix2[11]);
2855 s += abs(pix1[12] - pix2[12]);
2856 s += abs(pix1[13] - pix2[13]);
2857 s += abs(pix1[14] - pix2[14]);
2858 s += abs(pix1[15] - pix2[15]);
2859 pix1 += line_size;
2860 pix2 += line_size;
2861 }
2862 return s;
2863}
2864
2865static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
2866{
2867 int s, i;
2868
2869 s = 0;
2870 for(i=0;i<h;i++) {
2871 s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
2872 s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
2873 s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
2874 s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
2875 s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
2876 s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
2877 s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
2878 s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
2879 s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
2880 s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
2881 s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
2882 s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
2883 s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
2884 s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
2885 s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
2886 s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
2887 pix1 += line_size;
2888 pix2 += line_size;
2889 }
2890 return s;
2891}
2892
2893static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
2894{
2895 int s, i;
2896 uint8_t *pix3 = pix2 + line_size;
2897
2898 s = 0;
2899 for(i=0;i<h;i++) {
2900 s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
2901 s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
2902 s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
2903 s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
2904 s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
2905 s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
2906 s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
2907 s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
2908 s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
2909 s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
2910 s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
2911 s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
2912 s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
2913 s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
2914 s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
2915 s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
2916 pix1 += line_size;
2917 pix2 += line_size;
2918 pix3 += line_size;
2919 }
2920 return s;
2921}
2922
2923static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
2924{
2925 int s, i;
2926 uint8_t *pix3 = pix2 + line_size;
2927
2928 s = 0;
2929 for(i=0;i<h;i++) {
2930 s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
2931 s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
2932 s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
2933 s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
2934 s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
2935 s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
2936 s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
2937 s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
2938 s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
2939 s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
2940 s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
2941 s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
2942 s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
2943 s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
2944 s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
2945 s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
2946 pix1 += line_size;
2947 pix2 += line_size;
2948 pix3 += line_size;
2949 }
2950 return s;
2951}
2952
2953static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
2954{
2955 int s, i;
2956
2957 s = 0;
2958 for(i=0;i<h;i++) {
2959 s += abs(pix1[0] - pix2[0]);
2960 s += abs(pix1[1] - pix2[1]);
2961 s += abs(pix1[2] - pix2[2]);
2962 s += abs(pix1[3] - pix2[3]);
2963 s += abs(pix1[4] - pix2[4]);
2964 s += abs(pix1[5] - pix2[5]);
2965 s += abs(pix1[6] - pix2[6]);
2966 s += abs(pix1[7] - pix2[7]);
2967 pix1 += line_size;
2968 pix2 += line_size;
2969 }
2970 return s;
2971}
2972
2973static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
2974{
2975 int s, i;
2976
2977 s = 0;
2978 for(i=0;i<h;i++) {
2979 s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
2980 s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
2981 s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
2982 s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
2983 s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
2984 s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
2985 s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
2986 s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
2987 pix1 += line_size;
2988 pix2 += line_size;
2989 }
2990 return s;
2991}
2992
2993static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
2994{
2995 int s, i;
2996 uint8_t *pix3 = pix2 + line_size;
2997
2998 s = 0;
2999 for(i=0;i<h;i++) {
3000 s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
3001 s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
3002 s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
3003 s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
3004 s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
3005 s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
3006 s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
3007 s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
3008 pix1 += line_size;
3009 pix2 += line_size;
3010 pix3 += line_size;
3011 }
3012 return s;
3013}
3014
3015static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
3016{
3017 int s, i;
3018 uint8_t *pix3 = pix2 + line_size;
3019
3020 s = 0;
3021 for(i=0;i<h;i++) {
3022 s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
3023 s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
3024 s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
3025 s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
3026 s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
3027 s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
3028 s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
3029 s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
3030 pix1 += line_size;
3031 pix2 += line_size;
3032 pix3 += line_size;
3033 }
3034 return s;
3035}
3036
3037static int nsse16_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
3038 MpegEncContext *c = v;
3039 int score1=0;
3040 int score2=0;
3041 int x,y;
3042
3043 for(y=0; y<h; y++){
3044 for(x=0; x<16; x++){
3045 score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
3046 }
3047 if(y+1<h){
3048 for(x=0; x<15; x++){
3049 score2+= FFABS( s1[x ] - s1[x +stride]
3050 - s1[x+1] + s1[x+1+stride])
3051 -FFABS( s2[x ] - s2[x +stride]
3052 - s2[x+1] + s2[x+1+stride]);
3053 }
3054 }
3055 s1+= stride;
3056 s2+= stride;
3057 }
3058
3059 if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
3060 else return score1 + FFABS(score2)*8;
3061}
3062
3063static int nsse8_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
3064 MpegEncContext *c = v;
3065 int score1=0;
3066 int score2=0;
3067 int x,y;
3068
3069 for(y=0; y<h; y++){
3070 for(x=0; x<8; x++){
3071 score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
3072 }
3073 if(y+1<h){
3074 for(x=0; x<7; x++){
3075 score2+= FFABS( s1[x ] - s1[x +stride]
3076 - s1[x+1] + s1[x+1+stride])
3077 -FFABS( s2[x ] - s2[x +stride]
3078 - s2[x+1] + s2[x+1+stride]);
3079 }
3080 }
3081 s1+= stride;
3082 s2+= stride;
3083 }
3084
3085 if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
3086 else return score1 + FFABS(score2)*8;
3087}
3088
3089static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
3090 int i;
3091 unsigned int sum=0;
3092
3093 for(i=0; i<8*8; i++){
3094 int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
3095 int w= weight[i];
3096 b>>= RECON_SHIFT;
3097 assert(-512<b && b<512);
3098
3099 sum += (w*b)*(w*b)>>4;
3100 }
3101 return sum>>2;
3102}
3103
3104static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
3105 int i;
3106
3107 for(i=0; i<8*8; i++){
3108 rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
3109 }
3110}
3111
3112/**
3113 * permutes an 8x8 block.
3114 * @param block the block which will be permuted according to the given permutation vector
3115 * @param permutation the permutation vector
3116 * @param last the last non zero coefficient in scantable order, used to speed the permutation up
3117 * @param scantable the used scantable, this is only used to speed the permutation up, the block is not
3118 * (inverse) permutated to scantable order!
3119 */
3120void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
3121{
3122 int i;
3123 DCTELEM temp[64];
3124
3125 if(last<=0) return;
3126 //if(permutation[1]==1) return; //FIXME it is ok but not clean and might fail for some permutations
3127
3128 for(i=0; i<=last; i++){
3129 const int j= scantable[i];
3130 temp[j]= block[j];
3131 block[j]=0;
3132 }
3133
3134 for(i=0; i<=last; i++){
3135 const int j= scantable[i];
3136 const int perm_j= permutation[j];
3137 block[perm_j]= temp[j];
3138 }
3139}
3140
3141static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
3142 return 0;
3143}
3144
3145void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
3146 int i;
3147
3148 memset(cmp, 0, sizeof(void*)*6);
3149
3150 for(i=0; i<6; i++){
3151 switch(type&0xFF){
3152 case FF_CMP_SAD:
3153 cmp[i]= c->sad[i];
3154 break;
3155 case FF_CMP_SATD:
3156 cmp[i]= c->hadamard8_diff[i];
3157 break;
3158 case FF_CMP_SSE:
3159 cmp[i]= c->sse[i];
3160 break;
3161 case FF_CMP_DCT:
3162 cmp[i]= c->dct_sad[i];
3163 break;
3164 case FF_CMP_DCT264:
3165 cmp[i]= c->dct264_sad[i];
3166 break;
3167 case FF_CMP_DCTMAX:
3168 cmp[i]= c->dct_max[i];
3169 break;
3170 case FF_CMP_PSNR:
3171 cmp[i]= c->quant_psnr[i];
3172 break;
3173 case FF_CMP_BIT:
3174 cmp[i]= c->bit[i];
3175 break;
3176 case FF_CMP_RD:
3177 cmp[i]= c->rd[i];
3178 break;
3179 case FF_CMP_VSAD:
3180 cmp[i]= c->vsad[i];
3181 break;
3182 case FF_CMP_VSSE:
3183 cmp[i]= c->vsse[i];
3184 break;
3185 case FF_CMP_ZERO:
3186 cmp[i]= zero_cmp;
3187 break;
3188 case FF_CMP_NSSE:
3189 cmp[i]= c->nsse[i];
3190 break;
3191#if CONFIG_DWT
3192 case FF_CMP_W53:
3193 cmp[i]= c->w53[i];
3194 break;
3195 case FF_CMP_W97:
3196 cmp[i]= c->w97[i];
3197 break;
3198#endif
3199 default:
3200 av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
3201 }
3202 }
3203}
3204
3205static void clear_block_c(DCTELEM *block)
3206{
3207 memset(block, 0, sizeof(DCTELEM)*64);
3208}
3209
3210/**
3211 * memset(blocks, 0, sizeof(DCTELEM)*6*64)
3212 */
3213static void clear_blocks_c(DCTELEM *blocks)
3214{
3215 memset(blocks, 0, sizeof(DCTELEM)*6*64);
3216}
3217
3218static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
3219 long i;
3220 for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
3221 long a = *(long*)(src+i);
3222 long b = *(long*)(dst+i);
3223 *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
3224 }
3225 for(; i<w; i++)
3226 dst[i+0] += src[i+0];
3227}
3228
3229static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
3230 long i;
3231 for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
3232 long a = *(long*)(src1+i);
3233 long b = *(long*)(src2+i);
3234 *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
3235 }
3236 for(; i<w; i++)
3237 dst[i] = src1[i]+src2[i];
3238}
3239
3240static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
3241 long i;
3242#if !HAVE_FAST_UNALIGNED
3243 if((long)src2 & (sizeof(long)-1)){
3244 for(i=0; i+7<w; i+=8){
3245 dst[i+0] = src1[i+0]-src2[i+0];
3246 dst[i+1] = src1[i+1]-src2[i+1];
3247 dst[i+2] = src1[i+2]-src2[i+2];
3248 dst[i+3] = src1[i+3]-src2[i+3];
3249 dst[i+4] = src1[i+4]-src2[i+4];
3250 dst[i+5] = src1[i+5]-src2[i+5];
3251 dst[i+6] = src1[i+6]-src2[i+6];
3252 dst[i+7] = src1[i+7]-src2[i+7];
3253 }
3254 }else
3255#endif
3256 for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
3257 long a = *(long*)(src1+i);
3258 long b = *(long*)(src2+i);
3259 *(long*)(dst+i) = ((a|pb_80) - (b&pb_7f)) ^ ((a^b^pb_80)&pb_80);
3260 }
3261 for(; i<w; i++)
3262 dst[i+0] = src1[i+0]-src2[i+0];
3263}
3264
3265static void add_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const uint8_t *diff, int w, int *left, int *left_top){
3266 int i;
3267 uint8_t l, lt;
3268
3269 l= *left;
3270 lt= *left_top;
3271
3272 for(i=0; i<w; i++){
3273 l= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF) + diff[i];
3274 lt= src1[i];
3275 dst[i]= l;
3276 }
3277
3278 *left= l;
3279 *left_top= lt;
3280}
3281
3282static void sub_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top){
3283 int i;
3284 uint8_t l, lt;
3285
3286 l= *left;
3287 lt= *left_top;
3288
3289 for(i=0; i<w; i++){
3290 const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
3291 lt= src1[i];
3292 l= src2[i];
3293 dst[i]= l - pred;
3294 }
3295
3296 *left= l;
3297 *left_top= lt;
3298}
3299
3300static int add_hfyu_left_prediction_c(uint8_t *dst, const uint8_t *src, int w, int acc){
3301 int i;
3302
3303 for(i=0; i<w-1; i++){
3304 acc+= src[i];
3305 dst[i]= acc;
3306 i++;
3307 acc+= src[i];
3308 dst[i]= acc;
3309 }
3310
3311 for(; i<w; i++){
3312 acc+= src[i];
3313 dst[i]= acc;
3314 }
3315
3316 return acc;
3317}
3318
3319#if HAVE_BIGENDIAN
3320#define B 3
3321#define G 2
3322#define R 1
3323#define A 0
3324#else
3325#define B 0
3326#define G 1
3327#define R 2
3328#define A 3
3329#endif
3330static void add_hfyu_left_prediction_bgr32_c(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha){
3331 int i;
3332 int r,g,b,a;
3333 r= *red;
3334 g= *green;
3335 b= *blue;
3336 a= *alpha;
3337
3338 for(i=0; i<w; i++){
3339 b+= src[4*i+B];
3340 g+= src[4*i+G];
3341 r+= src[4*i+R];
3342 a+= src[4*i+A];
3343
3344 dst[4*i+B]= b;
3345 dst[4*i+G]= g;
3346 dst[4*i+R]= r;
3347 dst[4*i+A]= a;
3348 }
3349
3350 *red= r;
3351 *green= g;
3352 *blue= b;
3353 *alpha= a;
3354}
3355#undef B
3356#undef G
3357#undef R
3358#undef A
3359
3360#define BUTTERFLY2(o1,o2,i1,i2) \
3361o1= (i1)+(i2);\
3362o2= (i1)-(i2);
3363
3364#define BUTTERFLY1(x,y) \
3365{\
3366 int a,b;\
3367 a= x;\
3368 b= y;\
3369 x= a+b;\
3370 y= a-b;\
3371}
3372
3373#define BUTTERFLYA(x,y) (FFABS((x)+(y)) + FFABS((x)-(y)))
3374
3375static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
3376 int i;
3377 int temp[64];
3378 int sum=0;
3379
3380 assert(h==8);
3381
3382 for(i=0; i<8; i++){
3383 //FIXME try pointer walks
3384 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]);
3385 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]);
3386 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]);
3387 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]);
3388
3389 BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
3390 BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
3391 BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
3392 BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
3393
3394 BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
3395 BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
3396 BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
3397 BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
3398 }
3399
3400 for(i=0; i<8; i++){
3401 BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
3402 BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
3403 BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
3404 BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
3405
3406 BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
3407 BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
3408 BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
3409 BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
3410
3411 sum +=
3412 BUTTERFLYA(temp[8*0+i], temp[8*4+i])
3413 +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
3414 +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
3415 +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
3416 }
3417#if 0
3418static int maxi=0;
3419if(sum>maxi){
3420 maxi=sum;
3421 printf("MAX:%d\n", maxi);
3422}
3423#endif
3424 return sum;
3425}
3426
3427static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
3428 int i;
3429 int temp[64];
3430 int sum=0;
3431
3432 assert(h==8);
3433
3434 for(i=0; i<8; i++){
3435 //FIXME try pointer walks
3436 BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
3437 BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
3438 BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
3439 BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]);
3440
3441 BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
3442 BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
3443 BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
3444 BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
3445
3446 BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
3447 BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
3448 BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
3449 BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
3450 }
3451
3452 for(i=0; i<8; i++){
3453 BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
3454 BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
3455 BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
3456 BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
3457
3458 BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
3459 BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
3460 BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
3461 BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
3462
3463 sum +=
3464 BUTTERFLYA(temp[8*0+i], temp[8*4+i])
3465 +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
3466 +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
3467 +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
3468 }
3469
3470 sum -= FFABS(temp[8*0] + temp[8*4]); // -mean
3471
3472 return sum;
3473}
3474
3475static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
3476 MpegEncContext * const s= (MpegEncContext *)c;
3477 LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
3478
3479 assert(h==8);
3480
3481 s->dsp.diff_pixels(temp, src1, src2, stride);
3482 s->dsp.fdct(temp);
3483 return s->dsp.sum_abs_dctelem(temp);
3484}
3485
3486#if CONFIG_GPL
3487#define DCT8_1D {\
3488 const int s07 = SRC(0) + SRC(7);\
3489 const int s16 = SRC(1) + SRC(6);\
3490 const int s25 = SRC(2) + SRC(5);\
3491 const int s34 = SRC(3) + SRC(4);\
3492 const int a0 = s07 + s34;\
3493 const int a1 = s16 + s25;\
3494 const int a2 = s07 - s34;\
3495 const int a3 = s16 - s25;\
3496 const int d07 = SRC(0) - SRC(7);\
3497 const int d16 = SRC(1) - SRC(6);\
3498 const int d25 = SRC(2) - SRC(5);\
3499 const int d34 = SRC(3) - SRC(4);\
3500 const int a4 = d16 + d25 + (d07 + (d07>>1));\
3501 const int a5 = d07 - d34 - (d25 + (d25>>1));\
3502 const int a6 = d07 + d34 - (d16 + (d16>>1));\
3503 const int a7 = d16 - d25 + (d34 + (d34>>1));\
3504 DST(0, a0 + a1 ) ;\
3505 DST(1, a4 + (a7>>2)) ;\
3506 DST(2, a2 + (a3>>1)) ;\
3507 DST(3, a5 + (a6>>2)) ;\
3508 DST(4, a0 - a1 ) ;\
3509 DST(5, a6 - (a5>>2)) ;\
3510 DST(6, (a2>>1) - a3 ) ;\
3511 DST(7, (a4>>2) - a7 ) ;\
3512}
3513
3514static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
3515 MpegEncContext * const s= (MpegEncContext *)c;
3516 DCTELEM dct[8][8];
3517 int i;
3518 int sum=0;
3519
3520 s->dsp.diff_pixels(dct[0], src1, src2, stride);
3521
3522#define SRC(x) dct[i][x]
3523#define DST(x,v) dct[i][x]= v
3524 for( i = 0; i < 8; i++ )
3525 DCT8_1D
3526#undef SRC
3527#undef DST
3528
3529#define SRC(x) dct[x][i]
3530#define DST(x,v) sum += FFABS(v)
3531 for( i = 0; i < 8; i++ )
3532 DCT8_1D
3533#undef SRC
3534#undef DST
3535 return sum;
3536}
3537#endif
3538
3539static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
3540 MpegEncContext * const s= (MpegEncContext *)c;
3541 LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
3542 int sum=0, i;
3543
3544 assert(h==8);
3545
3546 s->dsp.diff_pixels(temp, src1, src2, stride);
3547 s->dsp.fdct(temp);
3548
3549 for(i=0; i<64; i++)
3550 sum= FFMAX(sum, FFABS(temp[i]));
3551
3552 return sum;
3553}
3554
3555static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
3556 MpegEncContext * const s= (MpegEncContext *)c;
3557 LOCAL_ALIGNED_16(DCTELEM, temp, [64*2]);
3558 DCTELEM * const bak = temp+64;
3559 int sum=0, i;
3560
3561 assert(h==8);
3562 s->mb_intra=0;
3563
3564 s->dsp.diff_pixels(temp, src1, src2, stride);
3565
3566 memcpy(bak, temp, 64*sizeof(DCTELEM));
3567
3568 s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
3569 s->dct_unquantize_inter(s, temp, 0, s->qscale);
3570 ff_simple_idct(temp); //FIXME
3571
3572 for(i=0; i<64; i++)
3573 sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
3574
3575 return sum;
3576}
3577
3578static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
3579 MpegEncContext * const s= (MpegEncContext *)c;
3580 const uint8_t *scantable= s->intra_scantable.permutated;
3581 LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
3582 LOCAL_ALIGNED_16(uint8_t, lsrc1, [64]);
3583 LOCAL_ALIGNED_16(uint8_t, lsrc2, [64]);
3584 int i, last, run, bits, level, distortion, start_i;
3585 const int esc_length= s->ac_esc_length;
3586 uint8_t * length;
3587 uint8_t * last_length;
3588
3589 assert(h==8);
3590
3591 copy_block8(lsrc1, src1, 8, stride, 8);
3592 copy_block8(lsrc2, src2, 8, stride, 8);
3593
3594 s->dsp.diff_pixels(temp, lsrc1, lsrc2, 8);
3595
3596 s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
3597
3598 bits=0;
3599
3600 if (s->mb_intra) {
3601 start_i = 1;
3602 length = s->intra_ac_vlc_length;
3603 last_length= s->intra_ac_vlc_last_length;
3604 bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
3605 } else {
3606 start_i = 0;
3607 length = s->inter_ac_vlc_length;
3608 last_length= s->inter_ac_vlc_last_length;
3609 }
3610
3611 if(last>=start_i){
3612 run=0;
3613 for(i=start_i; i<last; i++){
3614 int j= scantable[i];
3615 level= temp[j];
3616
3617 if(level){
3618 level+=64;
3619 if((level&(~127)) == 0){
3620 bits+= length[UNI_AC_ENC_INDEX(run, level)];
3621 }else
3622 bits+= esc_length;
3623 run=0;
3624 }else
3625 run++;
3626 }
3627 i= scantable[last];
3628
3629 level= temp[i] + 64;
3630
3631 assert(level - 64);
3632
3633 if((level&(~127)) == 0){
3634 bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
3635 }else
3636 bits+= esc_length;
3637
3638 }
3639
3640 if(last>=0){
3641 if(s->mb_intra)
3642 s->dct_unquantize_intra(s, temp, 0, s->qscale);
3643 else
3644 s->dct_unquantize_inter(s, temp, 0, s->qscale);
3645 }
3646
3647 s->dsp.idct_add(lsrc2, 8, temp);
3648
3649 distortion= s->dsp.sse[1](NULL, lsrc2, lsrc1, 8, 8);
3650
3651 return distortion + ((bits*s->qscale*s->qscale*109 + 64)>>7);
3652}
3653
3654static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
3655 MpegEncContext * const s= (MpegEncContext *)c;
3656 const uint8_t *scantable= s->intra_scantable.permutated;
3657 LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
3658 int i, last, run, bits, level, start_i;
3659 const int esc_length= s->ac_esc_length;
3660 uint8_t * length;
3661 uint8_t * last_length;
3662
3663 assert(h==8);
3664
3665 s->dsp.diff_pixels(temp, src1, src2, stride);
3666
3667 s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
3668
3669 bits=0;
3670
3671 if (s->mb_intra) {
3672 start_i = 1;
3673 length = s->intra_ac_vlc_length;
3674 last_length= s->intra_ac_vlc_last_length;
3675 bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
3676 } else {
3677 start_i = 0;
3678 length = s->inter_ac_vlc_length;
3679 last_length= s->inter_ac_vlc_last_length;
3680 }
3681
3682 if(last>=start_i){
3683 run=0;
3684 for(i=start_i; i<last; i++){
3685 int j= scantable[i];
3686 level= temp[j];
3687
3688 if(level){
3689 level+=64;
3690 if((level&(~127)) == 0){
3691 bits+= length[UNI_AC_ENC_INDEX(run, level)];
3692 }else
3693 bits+= esc_length;
3694 run=0;
3695 }else
3696 run++;
3697 }
3698 i= scantable[last];
3699
3700 level= temp[i] + 64;
3701
3702 assert(level - 64);
3703
3704 if((level&(~127)) == 0){
3705 bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
3706 }else
3707 bits+= esc_length;
3708 }
3709
3710 return bits;
3711}
3712
3713#define VSAD_INTRA(size) \
3714static int vsad_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
3715 int score=0; \
3716 int x,y; \
3717 \
3718 for(y=1; y<h; y++){ \
3719 for(x=0; x<size; x+=4){ \
3720 score+= FFABS(s[x ] - s[x +stride]) + FFABS(s[x+1] - s[x+1+stride]) \
3721 +FFABS(s[x+2] - s[x+2+stride]) + FFABS(s[x+3] - s[x+3+stride]); \
3722 } \
3723 s+= stride; \
3724 } \
3725 \
3726 return score; \
3727}
3728VSAD_INTRA(8)
3729VSAD_INTRA(16)
3730
3731static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
3732 int score=0;
3733 int x,y;
3734
3735 for(y=1; y<h; y++){
3736 for(x=0; x<16; x++){
3737 score+= FFABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
3738 }
3739 s1+= stride;
3740 s2+= stride;
3741 }
3742
3743 return score;
3744}
3745
3746#define SQ(a) ((a)*(a))
3747#define VSSE_INTRA(size) \
3748static int vsse_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
3749 int score=0; \
3750 int x,y; \
3751 \
3752 for(y=1; y<h; y++){ \
3753 for(x=0; x<size; x+=4){ \
3754 score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride]) \
3755 +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]); \
3756 } \
3757 s+= stride; \
3758 } \
3759 \
3760 return score; \
3761}
3762VSSE_INTRA(8)
3763VSSE_INTRA(16)
3764
3765static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
3766 int score=0;
3767 int x,y;
3768
3769 for(y=1; y<h; y++){
3770 for(x=0; x<16; x++){
3771 score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
3772 }
3773 s1+= stride;
3774 s2+= stride;
3775 }
3776
3777 return score;
3778}
3779
3780static int ssd_int8_vs_int16_c(const int8_t *pix1, const int16_t *pix2,
3781 int size){
3782 int score=0;
3783 int i;
3784 for(i=0; i<size; i++)
3785 score += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]);
3786 return score;
3787}
3788
3789WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
3790WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
3791WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
3792#if CONFIG_GPL
3793WRAPPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
3794#endif
3795WRAPPER8_16_SQ(dct_max8x8_c, dct_max16_c)
3796WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
3797WRAPPER8_16_SQ(rd8x8_c, rd16_c)
3798WRAPPER8_16_SQ(bit8x8_c, bit16_c)
3799
3800static void vector_fmul_c(float *dst, const float *src, int len){
3801 int i;
3802 for(i=0; i<len; i++)
3803 dst[i] *= src[i];
3804}
3805
3806static void vector_fmul_reverse_c(float *dst, const float *src0, const float *src1, int len){
3807 int i;
3808 src1 += len-1;
3809 for(i=0; i<len; i++)
3810 dst[i] = src0[i] * src1[-i];
3811}
3812
3813static void vector_fmul_add_c(float *dst, const float *src0, const float *src1, const float *src2, int len){
3814 int i;
3815 for(i=0; i<len; i++)
3816 dst[i] = src0[i] * src1[i] + src2[i];
3817}
3818
3819void ff_vector_fmul_window_c(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len){
3820 int i,j;
3821 dst += len;
3822 win += len;
3823 src0+= len;
3824 for(i=-len, j=len-1; i<0; i++, j--) {
3825 float s0 = src0[i];
3826 float s1 = src1[j];
3827 float wi = win[i];
3828 float wj = win[j];
3829 dst[i] = s0*wj - s1*wi + add_bias;
3830 dst[j] = s0*wi + s1*wj + add_bias;
3831 }
3832}
3833
3834static void vector_fmul_scalar_c(float *dst, const float *src, float mul,
3835 int len)
3836{
3837 int i;
3838 for (i = 0; i < len; i++)
3839 dst[i] = src[i] * mul;
3840}
3841
3842static void vector_fmul_sv_scalar_2_c(float *dst, const float *src,
3843 const float **sv, float mul, int len)
3844{
3845 int i;
3846 for (i = 0; i < len; i += 2, sv++) {
3847 dst[i ] = src[i ] * sv[0][0] * mul;
3848 dst[i+1] = src[i+1] * sv[0][1] * mul;
3849 }
3850}
3851
3852static void vector_fmul_sv_scalar_4_c(float *dst, const float *src,
3853 const float **sv, float mul, int len)
3854{
3855 int i;
3856 for (i = 0; i < len; i += 4, sv++) {
3857 dst[i ] = src[i ] * sv[0][0] * mul;
3858 dst[i+1] = src[i+1] * sv[0][1] * mul;
3859 dst[i+2] = src[i+2] * sv[0][2] * mul;
3860 dst[i+3] = src[i+3] * sv[0][3] * mul;
3861 }
3862}
3863
3864static void sv_fmul_scalar_2_c(float *dst, const float **sv, float mul,
3865 int len)
3866{
3867 int i;
3868 for (i = 0; i < len; i += 2, sv++) {
3869 dst[i ] = sv[0][0] * mul;
3870 dst[i+1] = sv[0][1] * mul;
3871 }
3872}
3873
3874static void sv_fmul_scalar_4_c(float *dst, const float **sv, float mul,
3875 int len)
3876{
3877 int i;
3878 for (i = 0; i < len; i += 4, sv++) {
3879 dst[i ] = sv[0][0] * mul;
3880 dst[i+1] = sv[0][1] * mul;
3881 dst[i+2] = sv[0][2] * mul;
3882 dst[i+3] = sv[0][3] * mul;
3883 }
3884}
3885
3886static void butterflies_float_c(float *restrict v1, float *restrict v2,
3887 int len)
3888{
3889 int i;
3890 for (i = 0; i < len; i++) {
3891 float t = v1[i] - v2[i];
3892 v1[i] += v2[i];
3893 v2[i] = t;
3894 }
3895}
3896
3897static float scalarproduct_float_c(const float *v1, const float *v2, int len)
3898{
3899 float p = 0.0;
3900 int i;
3901
3902 for (i = 0; i < len; i++)
3903 p += v1[i] * v2[i];
3904
3905 return p;
3906}
3907
3908static void int32_to_float_fmul_scalar_c(float *dst, const int *src, float mul, int len){
3909 int i;
3910 for(i=0; i<len; i++)
3911 dst[i] = src[i] * mul;
3912}
3913
3914static inline uint32_t clipf_c_one(uint32_t a, uint32_t mini,
3915 uint32_t maxi, uint32_t maxisign)
3916{
3917
3918 if(a > mini) return mini;
3919 else if((a^(1<<31)) > maxisign) return maxi;
3920 else return a;
3921}
3922
3923static void vector_clipf_c_opposite_sign(float *dst, const float *src, float *min, float *max, int len){
3924 int i;
3925 uint32_t mini = *(uint32_t*)min;
3926 uint32_t maxi = *(uint32_t*)max;
3927 uint32_t maxisign = maxi ^ (1<<31);
3928 uint32_t *dsti = (uint32_t*)dst;
3929 const uint32_t *srci = (const uint32_t*)src;
3930 for(i=0; i<len; i+=8) {
3931 dsti[i + 0] = clipf_c_one(srci[i + 0], mini, maxi, maxisign);
3932 dsti[i + 1] = clipf_c_one(srci[i + 1], mini, maxi, maxisign);
3933 dsti[i + 2] = clipf_c_one(srci[i + 2], mini, maxi, maxisign);
3934 dsti[i + 3] = clipf_c_one(srci[i + 3], mini, maxi, maxisign);
3935 dsti[i + 4] = clipf_c_one(srci[i + 4], mini, maxi, maxisign);
3936 dsti[i + 5] = clipf_c_one(srci[i + 5], mini, maxi, maxisign);
3937 dsti[i + 6] = clipf_c_one(srci[i + 6], mini, maxi, maxisign);
3938 dsti[i + 7] = clipf_c_one(srci[i + 7], mini, maxi, maxisign);
3939 }
3940}
3941static void vector_clipf_c(float *dst, const float *src, float min, float max, int len){
3942 int i;
3943 if(min < 0 && max > 0) {
3944 vector_clipf_c_opposite_sign(dst, src, &min, &max, len);
3945 } else {
3946 for(i=0; i < len; i+=8) {
3947 dst[i ] = av_clipf(src[i ], min, max);
3948 dst[i + 1] = av_clipf(src[i + 1], min, max);
3949 dst[i + 2] = av_clipf(src[i + 2], min, max);
3950 dst[i + 3] = av_clipf(src[i + 3], min, max);
3951 dst[i + 4] = av_clipf(src[i + 4], min, max);
3952 dst[i + 5] = av_clipf(src[i + 5], min, max);
3953 dst[i + 6] = av_clipf(src[i + 6], min, max);
3954 dst[i + 7] = av_clipf(src[i + 7], min, max);
3955 }
3956 }
3957}
3958
3959static av_always_inline int float_to_int16_one(const float *src){
3960 int_fast32_t tmp = *(const int32_t*)src;
3961 if(tmp & 0xf0000){
3962 tmp = (0x43c0ffff - tmp)>>31;
3963 // is this faster on some gcc/cpu combinations?
3964// if(tmp > 0x43c0ffff) tmp = 0xFFFF;
3965// else tmp = 0;
3966 }
3967 return tmp - 0x8000;
3968}
3969
3970void ff_float_to_int16_c(int16_t *dst, const float *src, long len){
3971 int i;
3972 for(i=0; i<len; i++)
3973 dst[i] = float_to_int16_one(src+i);
3974}
3975
3976void ff_float_to_int16_interleave_c(int16_t *dst, const float **src, long len, int channels){
3977 int i,j,c;
3978 if(channels==2){
3979 for(i=0; i<len; i++){
3980 dst[2*i] = float_to_int16_one(src[0]+i);
3981 dst[2*i+1] = float_to_int16_one(src[1]+i);
3982 }
3983 }else{
3984 for(c=0; c<channels; c++)
3985 for(i=0, j=c; i<len; i++, j+=channels)
3986 dst[j] = float_to_int16_one(src[c]+i);
3987 }
3988}
3989
3990static int32_t scalarproduct_int16_c(int16_t * v1, int16_t * v2, int order, int shift)
3991{
3992 int res = 0;
3993
3994 while (order--)
3995 res += (*v1++ * *v2++) >> shift;
3996
3997 return res;
3998}
3999
4000static int32_t scalarproduct_and_madd_int16_c(int16_t *v1, int16_t *v2, int16_t *v3, int order, int mul)
4001{
4002 int res = 0;
4003 while (order--) {
4004 res += *v1 * *v2++;
4005 *v1++ += mul * *v3++;
4006 }
4007 return res;
4008}
4009
4010#define W0 2048
4011#define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
4012#define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
4013#define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
4014#define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
4015#define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
4016#define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
4017#define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
4018
4019static void wmv2_idct_row(short * b)
4020{
4021 int s1,s2;
4022 int a0,a1,a2,a3,a4,a5,a6,a7;
4023 /*step 1*/
4024 a1 = W1*b[1]+W7*b[7];
4025 a7 = W7*b[1]-W1*b[7];
4026 a5 = W5*b[5]+W3*b[3];
4027 a3 = W3*b[5]-W5*b[3];
4028 a2 = W2*b[2]+W6*b[6];
4029 a6 = W6*b[2]-W2*b[6];
4030 a0 = W0*b[0]+W0*b[4];
4031 a4 = W0*b[0]-W0*b[4];
4032 /*step 2*/
4033 s1 = (181*(a1-a5+a7-a3)+128)>>8;//1,3,5,7,
4034 s2 = (181*(a1-a5-a7+a3)+128)>>8;
4035 /*step 3*/
4036 b[0] = (a0+a2+a1+a5 + (1<<7))>>8;
4037 b[1] = (a4+a6 +s1 + (1<<7))>>8;
4038 b[2] = (a4-a6 +s2 + (1<<7))>>8;
4039 b[3] = (a0-a2+a7+a3 + (1<<7))>>8;
4040 b[4] = (a0-a2-a7-a3 + (1<<7))>>8;
4041 b[5] = (a4-a6 -s2 + (1<<7))>>8;
4042 b[6] = (a4+a6 -s1 + (1<<7))>>8;
4043 b[7] = (a0+a2-a1-a5 + (1<<7))>>8;
4044}
4045static void wmv2_idct_col(short * b)
4046{
4047 int s1,s2;
4048 int a0,a1,a2,a3,a4,a5,a6,a7;
4049 /*step 1, with extended precision*/
4050 a1 = (W1*b[8*1]+W7*b[8*7] + 4)>>3;
4051 a7 = (W7*b[8*1]-W1*b[8*7] + 4)>>3;
4052 a5 = (W5*b[8*5]+W3*b[8*3] + 4)>>3;
4053 a3 = (W3*b[8*5]-W5*b[8*3] + 4)>>3;
4054 a2 = (W2*b[8*2]+W6*b[8*6] + 4)>>3;
4055 a6 = (W6*b[8*2]-W2*b[8*6] + 4)>>3;
4056 a0 = (W0*b[8*0]+W0*b[8*4] )>>3;
4057 a4 = (W0*b[8*0]-W0*b[8*4] )>>3;
4058 /*step 2*/
4059 s1 = (181*(a1-a5+a7-a3)+128)>>8;
4060 s2 = (181*(a1-a5-a7+a3)+128)>>8;
4061 /*step 3*/
4062 b[8*0] = (a0+a2+a1+a5 + (1<<13))>>14;
4063 b[8*1] = (a4+a6 +s1 + (1<<13))>>14;
4064 b[8*2] = (a4-a6 +s2 + (1<<13))>>14;
4065 b[8*3] = (a0-a2+a7+a3 + (1<<13))>>14;
4066
4067 b[8*4] = (a0-a2-a7-a3 + (1<<13))>>14;
4068 b[8*5] = (a4-a6 -s2 + (1<<13))>>14;
4069 b[8*6] = (a4+a6 -s1 + (1<<13))>>14;
4070 b[8*7] = (a0+a2-a1-a5 + (1<<13))>>14;
4071}
4072void ff_wmv2_idct_c(short * block){
4073 int i;
4074
4075 for(i=0;i<64;i+=8){
4076 wmv2_idct_row(block+i);
4077 }
4078 for(i=0;i<8;i++){
4079 wmv2_idct_col(block+i);
4080 }
4081}
4082/* XXX: those functions should be suppressed ASAP when all IDCTs are
4083 converted */
4084static void ff_wmv2_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block)
4085{
4086 ff_wmv2_idct_c(block);
4087 put_pixels_clamped_c(block, dest, line_size);
4088}
4089static void ff_wmv2_idct_add_c(uint8_t *dest, int line_size, DCTELEM *block)
4090{
4091 ff_wmv2_idct_c(block);
4092 add_pixels_clamped_c(block, dest, line_size);
4093}
4094static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
4095{
4096 j_rev_dct (block);
4097 put_pixels_clamped_c(block, dest, line_size);
4098}
4099static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
4100{
4101 j_rev_dct (block);
4102 add_pixels_clamped_c(block, dest, line_size);
4103}
4104
4105static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block)
4106{
4107 j_rev_dct4 (block);
4108 put_pixels_clamped4_c(block, dest, line_size);
4109}
4110static void ff_jref_idct4_add(uint8_t *dest, int line_size, DCTELEM *block)
4111{
4112 j_rev_dct4 (block);
4113 add_pixels_clamped4_c(block, dest, line_size);
4114}
4115
4116static void ff_jref_idct2_put(uint8_t *dest, int line_size, DCTELEM *block)
4117{
4118 j_rev_dct2 (block);
4119 put_pixels_clamped2_c(block, dest, line_size);
4120}
4121static void ff_jref_idct2_add(uint8_t *dest, int line_size, DCTELEM *block)
4122{
4123 j_rev_dct2 (block);
4124 add_pixels_clamped2_c(block, dest, line_size);
4125}
4126
4127static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block)
4128{
4129 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
4130
4131 dest[0] = cm[(block[0] + 4)>>3];
4132}
4133static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block)
4134{
4135 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
4136
4137 dest[0] = cm[dest[0] + ((block[0] + 4)>>3)];
4138}
4139
4140static void just_return(void *mem av_unused, int stride av_unused, int h av_unused) { return; }
4141
4142/* init static data */
4143av_cold void dsputil_static_init(void)
4144{
4145 int i;
4146
4147 for(i=0;i<256;i++) ff_cropTbl[i + MAX_NEG_CROP] = i;
4148 for(i=0;i<MAX_NEG_CROP;i++) {
4149 ff_cropTbl[i] = 0;
4150 ff_cropTbl[i + MAX_NEG_CROP + 256] = 255;
4151 }
4152
4153 for(i=0;i<512;i++) {
4154 ff_squareTbl[i] = (i - 256) * (i - 256);
4155 }
4156
4157 for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
4158}
4159
4160int ff_check_alignment(void){
4161 static int did_fail=0;
4162 DECLARE_ALIGNED(16, int, aligned);
4163
4164 if((intptr_t)&aligned & 15){
4165 if(!did_fail){
4166#if HAVE_MMX || HAVE_ALTIVEC
4167 av_log(NULL, AV_LOG_ERROR,
4168 "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
4169 "and may be very slow or crash. This is not a bug in libavcodec,\n"
4170 "but in the compiler. You may try recompiling using gcc >= 4.2.\n"
4171 "Do not report crashes to FFmpeg developers.\n");
4172#endif
4173 did_fail=1;
4174 }
4175 return -1;
4176 }
4177 return 0;
4178}
4179
4180av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
4181{
4182 int i;
4183
4184 ff_check_alignment();
4185
4186#if CONFIG_ENCODERS
4187 if(avctx->dct_algo==FF_DCT_FASTINT) {
4188 c->fdct = fdct_ifast;
4189 c->fdct248 = fdct_ifast248;
4190 }
4191 else if(avctx->dct_algo==FF_DCT_FAAN) {
4192 c->fdct = ff_faandct;
4193 c->fdct248 = ff_faandct248;
4194 }
4195 else {
4196 c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
4197 c->fdct248 = ff_fdct248_islow;
4198 }
4199#endif //CONFIG_ENCODERS
4200
4201 if(avctx->lowres==1){
4202 if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO || !CONFIG_H264_DECODER){
4203 c->idct_put= ff_jref_idct4_put;
4204 c->idct_add= ff_jref_idct4_add;
4205 }else{
4206 c->idct_put= ff_h264_lowres_idct_put_c;
4207 c->idct_add= ff_h264_lowres_idct_add_c;
4208 }
4209 c->idct = j_rev_dct4;
4210 c->idct_permutation_type= FF_NO_IDCT_PERM;
4211 }else if(avctx->lowres==2){
4212 c->idct_put= ff_jref_idct2_put;
4213 c->idct_add= ff_jref_idct2_add;
4214 c->idct = j_rev_dct2;
4215 c->idct_permutation_type= FF_NO_IDCT_PERM;
4216 }else if(avctx->lowres==3){
4217 c->idct_put= ff_jref_idct1_put;
4218 c->idct_add= ff_jref_idct1_add;
4219 c->idct = j_rev_dct1;
4220 c->idct_permutation_type= FF_NO_IDCT_PERM;
4221 }else{
4222 if(avctx->idct_algo==FF_IDCT_INT){
4223 c->idct_put= ff_jref_idct_put;
4224 c->idct_add= ff_jref_idct_add;
4225 c->idct = j_rev_dct;
4226 c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
4227 }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER ) &&
4228 avctx->idct_algo==FF_IDCT_VP3){
4229 c->idct_put= ff_vp3_idct_put_c;
4230 c->idct_add= ff_vp3_idct_add_c;
4231 c->idct = ff_vp3_idct_c;
4232 c->idct_permutation_type= FF_NO_IDCT_PERM;
4233 }else if(avctx->idct_algo==FF_IDCT_WMV2){
4234 c->idct_put= ff_wmv2_idct_put_c;
4235 c->idct_add= ff_wmv2_idct_add_c;
4236 c->idct = ff_wmv2_idct_c;
4237 c->idct_permutation_type= FF_NO_IDCT_PERM;
4238 }else if(avctx->idct_algo==FF_IDCT_FAAN){
4239 c->idct_put= ff_faanidct_put;
4240 c->idct_add= ff_faanidct_add;
4241 c->idct = ff_faanidct;
4242 c->idct_permutation_type= FF_NO_IDCT_PERM;
4243 }else if(CONFIG_EATGQ_DECODER && avctx->idct_algo==FF_IDCT_EA) {
4244 c->idct_put= ff_ea_idct_put_c;
4245 c->idct_permutation_type= FF_NO_IDCT_PERM;
4246 }else if(CONFIG_BINK_DECODER && avctx->idct_algo==FF_IDCT_BINK) {
4247 c->idct = ff_bink_idct_c;
4248 c->idct_add = ff_bink_idct_add_c;
4249 c->idct_put = ff_bink_idct_put_c;
4250 c->idct_permutation_type = FF_NO_IDCT_PERM;
4251 }else{ //accurate/default
4252 c->idct_put= ff_simple_idct_put;
4253 c->idct_add= ff_simple_idct_add;
4254 c->idct = ff_simple_idct;
4255 c->idct_permutation_type= FF_NO_IDCT_PERM;
4256 }
4257 }
4258
4259 c->get_pixels = get_pixels_c;
4260 c->diff_pixels = diff_pixels_c;
4261 c->put_pixels_clamped = put_pixels_clamped_c;
4262 c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
4263 c->put_pixels_nonclamped = put_pixels_nonclamped_c;
4264 c->add_pixels_clamped = add_pixels_clamped_c;
4265 c->add_pixels8 = add_pixels8_c;
4266 c->add_pixels4 = add_pixels4_c;
4267 c->sum_abs_dctelem = sum_abs_dctelem_c;
4268 c->gmc1 = gmc1_c;
4269 c->gmc = ff_gmc_c;
4270 c->clear_block = clear_block_c;
4271 c->clear_blocks = clear_blocks_c;
4272 c->pix_sum = pix_sum_c;
4273 c->pix_norm1 = pix_norm1_c;
4274
4275 c->fill_block_tab[0] = fill_block16_c;
4276 c->fill_block_tab[1] = fill_block8_c;
4277 c->scale_block = scale_block_c;
4278
4279 /* TODO [0] 16 [1] 8 */
4280 c->pix_abs[0][0] = pix_abs16_c;
4281 c->pix_abs[0][1] = pix_abs16_x2_c;
4282 c->pix_abs[0][2] = pix_abs16_y2_c;
4283 c->pix_abs[0][3] = pix_abs16_xy2_c;
4284 c->pix_abs[1][0] = pix_abs8_c;
4285 c->pix_abs[1][1] = pix_abs8_x2_c;
4286 c->pix_abs[1][2] = pix_abs8_y2_c;
4287 c->pix_abs[1][3] = pix_abs8_xy2_c;
4288
4289#define dspfunc(PFX, IDX, NUM) \
4290 c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \
4291 c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \
4292 c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \
4293 c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
4294
4295 dspfunc(put, 0, 16);
4296 dspfunc(put_no_rnd, 0, 16);
4297 dspfunc(put, 1, 8);
4298 dspfunc(put_no_rnd, 1, 8);
4299 dspfunc(put, 2, 4);
4300 dspfunc(put, 3, 2);
4301
4302 dspfunc(avg, 0, 16);
4303 dspfunc(avg_no_rnd, 0, 16);
4304 dspfunc(avg, 1, 8);
4305 dspfunc(avg_no_rnd, 1, 8);
4306 dspfunc(avg, 2, 4);
4307 dspfunc(avg, 3, 2);
4308#undef dspfunc
4309
4310 c->put_no_rnd_pixels_l2[0]= put_no_rnd_pixels16_l2_c;
4311 c->put_no_rnd_pixels_l2[1]= put_no_rnd_pixels8_l2_c;
4312
4313 c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
4314 c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
4315 c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
4316 c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
4317 c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
4318 c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
4319 c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
4320 c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
4321 c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
4322
4323 c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
4324 c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
4325 c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
4326 c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
4327 c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
4328 c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
4329 c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
4330 c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
4331 c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
4332
4333#define dspfunc(PFX, IDX, NUM) \
4334 c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
4335 c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
4336 c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
4337 c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
4338 c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
4339 c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
4340 c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
4341 c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
4342 c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
4343 c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
4344 c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
4345 c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
4346 c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
4347 c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
4348 c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
4349 c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
4350
4351 dspfunc(put_qpel, 0, 16);
4352 dspfunc(put_no_rnd_qpel, 0, 16);
4353
4354 dspfunc(avg_qpel, 0, 16);
4355 /* dspfunc(avg_no_rnd_qpel, 0, 16); */
4356
4357 dspfunc(put_qpel, 1, 8);
4358 dspfunc(put_no_rnd_qpel, 1, 8);
4359
4360 dspfunc(avg_qpel, 1, 8);
4361 /* dspfunc(avg_no_rnd_qpel, 1, 8); */
4362
4363 dspfunc(put_h264_qpel, 0, 16);
4364 dspfunc(put_h264_qpel, 1, 8);
4365 dspfunc(put_h264_qpel, 2, 4);
4366 dspfunc(put_h264_qpel, 3, 2);
4367 dspfunc(avg_h264_qpel, 0, 16);
4368 dspfunc(avg_h264_qpel, 1, 8);
4369 dspfunc(avg_h264_qpel, 2, 4);
4370
4371#undef dspfunc
4372 c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
4373 c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
4374 c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
4375 c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
4376 c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
4377 c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
4378 c->put_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c;
4379 c->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c;
4380
4381 c->draw_edges = draw_edges_c;
4382
4383#if CONFIG_CAVS_DECODER
4384 ff_cavsdsp_init(c,avctx);
4385#endif
4386
4387#if CONFIG_MLP_DECODER || CONFIG_TRUEHD_DECODER
4388 ff_mlp_init(c, avctx);
4389#endif
4390#if CONFIG_VC1_DECODER
4391 ff_vc1dsp_init(c,avctx);
4392#endif
4393#if CONFIG_WMV2_DECODER || CONFIG_VC1_DECODER
4394 ff_intrax8dsp_init(c,avctx);
4395#endif
4396#if CONFIG_RV30_DECODER
4397 ff_rv30dsp_init(c,avctx);
4398#endif
4399#if CONFIG_RV40_DECODER
4400 ff_rv40dsp_init(c,avctx);
4401 c->put_rv40_qpel_pixels_tab[0][15] = put_rv40_qpel16_mc33_c;
4402 c->avg_rv40_qpel_pixels_tab[0][15] = avg_rv40_qpel16_mc33_c;
4403 c->put_rv40_qpel_pixels_tab[1][15] = put_rv40_qpel8_mc33_c;
4404 c->avg_rv40_qpel_pixels_tab[1][15] = avg_rv40_qpel8_mc33_c;
4405#endif
4406
4407 c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
4408 c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
4409 c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
4410 c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
4411 c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
4412 c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
4413 c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
4414 c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
4415
4416#define SET_CMP_FUNC(name) \
4417 c->name[0]= name ## 16_c;\
4418 c->name[1]= name ## 8x8_c;
4419
4420 SET_CMP_FUNC(hadamard8_diff)
4421 c->hadamard8_diff[4]= hadamard8_intra16_c;
4422 c->hadamard8_diff[5]= hadamard8_intra8x8_c;
4423 SET_CMP_FUNC(dct_sad)
4424 SET_CMP_FUNC(dct_max)
4425#if CONFIG_GPL
4426 SET_CMP_FUNC(dct264_sad)
4427#endif
4428 c->sad[0]= pix_abs16_c;
4429 c->sad[1]= pix_abs8_c;
4430 c->sse[0]= sse16_c;
4431 c->sse[1]= sse8_c;
4432 c->sse[2]= sse4_c;
4433 SET_CMP_FUNC(quant_psnr)
4434 SET_CMP_FUNC(rd)
4435 SET_CMP_FUNC(bit)
4436 c->vsad[0]= vsad16_c;
4437 c->vsad[4]= vsad_intra16_c;
4438 c->vsad[5]= vsad_intra8_c;
4439 c->vsse[0]= vsse16_c;
4440 c->vsse[4]= vsse_intra16_c;
4441 c->vsse[5]= vsse_intra8_c;
4442 c->nsse[0]= nsse16_c;
4443 c->nsse[1]= nsse8_c;
4444#if CONFIG_DWT
4445 ff_dsputil_init_dwt(c);
4446#endif
4447
4448 c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
4449
4450 c->add_bytes= add_bytes_c;
4451 c->add_bytes_l2= add_bytes_l2_c;
4452 c->diff_bytes= diff_bytes_c;
4453 c->add_hfyu_median_prediction= add_hfyu_median_prediction_c;
4454 c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
4455 c->add_hfyu_left_prediction = add_hfyu_left_prediction_c;
4456 c->add_hfyu_left_prediction_bgr32 = add_hfyu_left_prediction_bgr32_c;
4457 c->bswap_buf= bswap_buf;
4458#if CONFIG_PNG_DECODER
4459 c->add_png_paeth_prediction= ff_add_png_paeth_prediction;
4460#endif
4461
4462 if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
4463 c->h263_h_loop_filter= h263_h_loop_filter_c;
4464 c->h263_v_loop_filter= h263_v_loop_filter_c;
4465 }
4466
4467 if (CONFIG_VP3_DECODER) {
4468 c->vp3_h_loop_filter= ff_vp3_h_loop_filter_c;
4469 c->vp3_v_loop_filter= ff_vp3_v_loop_filter_c;
4470 }
4471 if (CONFIG_VP6_DECODER) {
4472 c->vp6_filter_diag4= ff_vp6_filter_diag4_c;
4473 }
4474
4475 c->h261_loop_filter= h261_loop_filter_c;
4476
4477 c->try_8x8basis= try_8x8basis_c;
4478 c->add_8x8basis= add_8x8basis_c;
4479
4480#if CONFIG_VORBIS_DECODER
4481 c->vorbis_inverse_coupling = vorbis_inverse_coupling;
4482#endif
4483#if CONFIG_AC3_DECODER
4484 c->ac3_downmix = ff_ac3_downmix_c;
4485#endif
4486#if CONFIG_LPC
4487 c->lpc_compute_autocorr = ff_lpc_compute_autocorr;
4488#endif
4489 c->vector_fmul = vector_fmul_c;
4490 c->vector_fmul_reverse = vector_fmul_reverse_c;
4491 c->vector_fmul_add = vector_fmul_add_c;
4492 c->vector_fmul_window = ff_vector_fmul_window_c;
4493 c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_c;
4494 c->vector_clipf = vector_clipf_c;
4495 c->float_to_int16 = ff_float_to_int16_c;
4496 c->float_to_int16_interleave = ff_float_to_int16_interleave_c;
4497 c->scalarproduct_int16 = scalarproduct_int16_c;
4498 c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_c;
4499 c->scalarproduct_float = scalarproduct_float_c;
4500 c->butterflies_float = butterflies_float_c;
4501 c->vector_fmul_scalar = vector_fmul_scalar_c;
4502
4503 c->vector_fmul_sv_scalar[0] = vector_fmul_sv_scalar_2_c;
4504 c->vector_fmul_sv_scalar[1] = vector_fmul_sv_scalar_4_c;
4505
4506 c->sv_fmul_scalar[0] = sv_fmul_scalar_2_c;
4507 c->sv_fmul_scalar[1] = sv_fmul_scalar_4_c;
4508
4509 c->shrink[0]= ff_img_copy_plane;
4510 c->shrink[1]= ff_shrink22;
4511 c->shrink[2]= ff_shrink44;
4512 c->shrink[3]= ff_shrink88;
4513
4514 c->prefetch= just_return;
4515
4516 memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab));
4517 memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab));
4518
4519 if (HAVE_MMX) dsputil_init_mmx (c, avctx);
4520 if (ARCH_ARM) dsputil_init_arm (c, avctx);
4521 if (CONFIG_MLIB) dsputil_init_mlib (c, avctx);
4522 if (HAVE_VIS) dsputil_init_vis (c, avctx);
4523 if (ARCH_ALPHA) dsputil_init_alpha (c, avctx);
4524 if (ARCH_PPC) dsputil_init_ppc (c, avctx);
4525 if (HAVE_MMI) dsputil_init_mmi (c, avctx);
4526 if (ARCH_SH4) dsputil_init_sh4 (c, avctx);
4527 if (ARCH_BFIN) dsputil_init_bfin (c, avctx);
4528
4529 for(i=0; i<64; i++){
4530 if(!c->put_2tap_qpel_pixels_tab[0][i])
4531 c->put_2tap_qpel_pixels_tab[0][i]= c->put_h264_qpel_pixels_tab[0][i];
4532 if(!c->avg_2tap_qpel_pixels_tab[0][i])
4533 c->avg_2tap_qpel_pixels_tab[0][i]= c->avg_h264_qpel_pixels_tab[0][i];
4534 }
4535
4536 switch(c->idct_permutation_type){
4537 case FF_NO_IDCT_PERM:
4538 for(i=0; i<64; i++)
4539 c->idct_permutation[i]= i;
4540 break;
4541 case FF_LIBMPEG2_IDCT_PERM:
4542 for(i=0; i<64; i++)
4543 c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
4544 break;
4545 case FF_SIMPLE_IDCT_PERM:
4546 for(i=0; i<64; i++)
4547 c->idct_permutation[i]= simple_mmx_permutation[i];
4548 break;
4549 case FF_TRANSPOSE_IDCT_PERM:
4550 for(i=0; i<64; i++)
4551 c->idct_permutation[i]= ((i&7)<<3) | (i>>3);
4552 break;
4553 case FF_PARTTRANS_IDCT_PERM:
4554 for(i=0; i<64; i++)
4555 c->idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);
4556 break;
4557 case FF_SSE2_IDCT_PERM:
4558 for(i=0; i<64; i++)
4559 c->idct_permutation[i]= (i&0x38) | idct_sse2_row_perm[i&7];
4560 break;
4561 default:
4562 av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
4563 }
4564}
4565
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..7275d98e9f
--- /dev/null
+++ b/apps/codecs/libwmapro/fft.c
@@ -0,0 +1,368 @@
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 <stdlib.h>
30#include <string.h>
31#include "libavutil/mathematics.h"
32#include "fft.h"
33
34/* cos(2*pi*x/n) for 0<=x<=n/4, followed by its reverse */
35#if !CONFIG_HARDCODED_TABLES
36COSTABLE(16);
37COSTABLE(32);
38COSTABLE(64);
39COSTABLE(128);
40COSTABLE(256);
41COSTABLE(512);
42COSTABLE(1024);
43COSTABLE(2048);
44COSTABLE(4096);
45COSTABLE(8192);
46COSTABLE(16384);
47COSTABLE(32768);
48COSTABLE(65536);
49#endif
50COSTABLE_CONST FFTSample * const ff_cos_tabs[] = {
51 NULL, NULL, NULL, NULL,
52 ff_cos_16, ff_cos_32, ff_cos_64, ff_cos_128, ff_cos_256, ff_cos_512, ff_cos_1024,
53 ff_cos_2048, ff_cos_4096, ff_cos_8192, ff_cos_16384, ff_cos_32768, ff_cos_65536,
54};
55
56static int split_radix_permutation(int i, int n, int inverse)
57{
58 int m;
59 if(n <= 2) return i&1;
60 m = n >> 1;
61 if(!(i&m)) return split_radix_permutation(i, m, inverse)*2;
62 m >>= 1;
63 if(inverse == !(i&m)) return split_radix_permutation(i, m, inverse)*4 + 1;
64 else return split_radix_permutation(i, m, inverse)*4 - 1;
65}
66
67av_cold void ff_init_ff_cos_tabs(int index)
68{
69#if !CONFIG_HARDCODED_TABLES
70 int i;
71 int m = 1<<index;
72 double freq = 2*M_PI/m;
73 FFTSample *tab = ff_cos_tabs[index];
74 for(i=0; i<=m/4; i++)
75 tab[i] = cos(i*freq);
76 for(i=1; i<m/4; i++)
77 tab[m/2-i] = tab[i];
78#endif
79}
80
81av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse)
82{
83 int i, j, m, n;
84 float alpha, c1, s1, s2;
85 int av_unused has_vectors;
86
87 if (nbits < 2 || nbits > 16)
88 goto fail;
89 s->nbits = nbits;
90 n = 1 << nbits;
91
92 s->tmp_buf = NULL;
93 s->exptab = av_malloc((n / 2) * sizeof(FFTComplex));
94 if (!s->exptab)
95 goto fail;
96 s->revtab = av_malloc(n * sizeof(uint16_t));
97 if (!s->revtab)
98 goto fail;
99 s->inverse = inverse;
100
101 s2 = inverse ? 1.0 : -1.0;
102
103 s->fft_permute = ff_fft_permute_c;
104 s->fft_calc = ff_fft_calc_c;
105#if CONFIG_MDCT
106 s->imdct_calc = ff_imdct_calc_c;
107 s->imdct_half = ff_imdct_half_c;
108 s->mdct_calc = ff_mdct_calc_c;
109#endif
110 s->exptab1 = NULL;
111 s->split_radix = 1;
112
113 if (ARCH_ARM) ff_fft_init_arm(s);
114 if (HAVE_ALTIVEC) ff_fft_init_altivec(s);
115 if (HAVE_MMX) ff_fft_init_mmx(s);
116
117 if (s->split_radix) {
118 for(j=4; j<=nbits; j++) {
119 ff_init_ff_cos_tabs(j);
120 }
121 for(i=0; i<n; i++)
122 s->revtab[-split_radix_permutation(i, n, s->inverse) & (n-1)] = i;
123 s->tmp_buf = av_malloc(n * sizeof(FFTComplex));
124 } else {
125 int np, nblocks, np2, l;
126 FFTComplex *q;
127
128 for(i=0; i<(n/2); i++) {
129 alpha = 2 * M_PI * (float)i / (float)n;
130 c1 = cos(alpha);
131 s1 = sin(alpha) * s2;
132 s->exptab[i].re = c1;
133 s->exptab[i].im = s1;
134 }
135
136 np = 1 << nbits;
137 nblocks = np >> 3;
138 np2 = np >> 1;
139 s->exptab1 = av_malloc(np * 2 * sizeof(FFTComplex));
140 if (!s->exptab1)
141 goto fail;
142 q = s->exptab1;
143 do {
144 for(l = 0; l < np2; l += 2 * nblocks) {
145 *q++ = s->exptab[l];
146 *q++ = s->exptab[l + nblocks];
147
148 q->re = -s->exptab[l].im;
149 q->im = s->exptab[l].re;
150 q++;
151 q->re = -s->exptab[l + nblocks].im;
152 q->im = s->exptab[l + nblocks].re;
153 q++;
154 }
155 nblocks = nblocks >> 1;
156 } while (nblocks != 0);
157 av_freep(&s->exptab);
158
159 /* compute bit reverse table */
160 for(i=0;i<n;i++) {
161 m=0;
162 for(j=0;j<nbits;j++) {
163 m |= ((i >> j) & 1) << (nbits-j-1);
164 }
165 s->revtab[i]=m;
166 }
167 }
168
169 return 0;
170 fail:
171 av_freep(&s->revtab);
172 av_freep(&s->exptab);
173 av_freep(&s->exptab1);
174 av_freep(&s->tmp_buf);
175 return -1;
176}
177
178void ff_fft_permute_c(FFTContext *s, FFTComplex *z)
179{
180 int j, k, np;
181 FFTComplex tmp;
182 const uint16_t *revtab = s->revtab;
183 np = 1 << s->nbits;
184
185 if (s->tmp_buf) {
186 /* TODO: handle split-radix permute in a more optimal way, probably in-place */
187 for(j=0;j<np;j++) s->tmp_buf[revtab[j]] = z[j];
188 memcpy(z, s->tmp_buf, np * sizeof(FFTComplex));
189 return;
190 }
191
192 /* reverse */
193 for(j=0;j<np;j++) {
194 k = revtab[j];
195 if (k < j) {
196 tmp = z[k];
197 z[k] = z[j];
198 z[j] = tmp;
199 }
200 }
201}
202
203av_cold void ff_fft_end(FFTContext *s)
204{
205 av_freep(&s->revtab);
206 av_freep(&s->exptab);
207 av_freep(&s->exptab1);
208 av_freep(&s->tmp_buf);
209}
210
211#define sqrthalf (float)M_SQRT1_2
212
213#define BF(x,y,a,b) {\
214 x = a - b;\
215 y = a + b;\
216}
217
218#define BUTTERFLIES(a0,a1,a2,a3) {\
219 BF(t3, t5, t5, t1);\
220 BF(a2.re, a0.re, a0.re, t5);\
221 BF(a3.im, a1.im, a1.im, t3);\
222 BF(t4, t6, t2, t6);\
223 BF(a3.re, a1.re, a1.re, t4);\
224 BF(a2.im, a0.im, a0.im, t6);\
225}
226
227// force loading all the inputs before storing any.
228// this is slightly slower for small data, but avoids store->load aliasing
229// for addresses separated by large powers of 2.
230#define BUTTERFLIES_BIG(a0,a1,a2,a3) {\
231 FFTSample r0=a0.re, i0=a0.im, r1=a1.re, i1=a1.im;\
232 BF(t3, t5, t5, t1);\
233 BF(a2.re, a0.re, r0, t5);\
234 BF(a3.im, a1.im, i1, t3);\
235 BF(t4, t6, t2, t6);\
236 BF(a3.re, a1.re, r1, t4);\
237 BF(a2.im, a0.im, i0, t6);\
238}
239
240#define TRANSFORM(a0,a1,a2,a3,wre,wim) {\
241 t1 = a2.re * wre + a2.im * wim;\
242 t2 = a2.im * wre - a2.re * wim;\
243 t5 = a3.re * wre - a3.im * wim;\
244 t6 = a3.im * wre + a3.re * wim;\
245 BUTTERFLIES(a0,a1,a2,a3)\
246}
247
248#define TRANSFORM_ZERO(a0,a1,a2,a3) {\
249 t1 = a2.re;\
250 t2 = a2.im;\
251 t5 = a3.re;\
252 t6 = a3.im;\
253 BUTTERFLIES(a0,a1,a2,a3)\
254}
255
256/* z[0...8n-1], w[1...2n-1] */
257#define PASS(name)\
258static void name(FFTComplex *z, const FFTSample *wre, unsigned int n)\
259{\
260 FFTSample t1, t2, t3, t4, t5, t6;\
261 int o1 = 2*n;\
262 int o2 = 4*n;\
263 int o3 = 6*n;\
264 const FFTSample *wim = wre+o1;\
265 n--;\
266\
267 TRANSFORM_ZERO(z[0],z[o1],z[o2],z[o3]);\
268 TRANSFORM(z[1],z[o1+1],z[o2+1],z[o3+1],wre[1],wim[-1]);\
269 do {\
270 z += 2;\
271 wre += 2;\
272 wim -= 2;\
273 TRANSFORM(z[0],z[o1],z[o2],z[o3],wre[0],wim[0]);\
274 TRANSFORM(z[1],z[o1+1],z[o2+1],z[o3+1],wre[1],wim[-1]);\
275 } while(--n);\
276}
277
278PASS(pass)
279#undef BUTTERFLIES
280#define BUTTERFLIES BUTTERFLIES_BIG
281PASS(pass_big)
282
283#define DECL_FFT(n,n2,n4)\
284static void fft##n(FFTComplex *z)\
285{\
286 fft##n2(z);\
287 fft##n4(z+n4*2);\
288 fft##n4(z+n4*3);\
289 pass(z,ff_cos_##n,n4/2);\
290}
291
292static void fft4(FFTComplex *z)
293{
294 FFTSample t1, t2, t3, t4, t5, t6, t7, t8;
295
296 BF(t3, t1, z[0].re, z[1].re);
297 BF(t8, t6, z[3].re, z[2].re);
298 BF(z[2].re, z[0].re, t1, t6);
299 BF(t4, t2, z[0].im, z[1].im);
300 BF(t7, t5, z[2].im, z[3].im);
301 BF(z[3].im, z[1].im, t4, t8);
302 BF(z[3].re, z[1].re, t3, t7);
303 BF(z[2].im, z[0].im, t2, t5);
304}
305
306static void fft8(FFTComplex *z)
307{
308 FFTSample t1, t2, t3, t4, t5, t6, t7, t8;
309
310 fft4(z);
311
312 BF(t1, z[5].re, z[4].re, -z[5].re);
313 BF(t2, z[5].im, z[4].im, -z[5].im);
314 BF(t3, z[7].re, z[6].re, -z[7].re);
315 BF(t4, z[7].im, z[6].im, -z[7].im);
316 BF(t8, t1, t3, t1);
317 BF(t7, t2, t2, t4);
318 BF(z[4].re, z[0].re, z[0].re, t1);
319 BF(z[4].im, z[0].im, z[0].im, t2);
320 BF(z[6].re, z[2].re, z[2].re, t7);
321 BF(z[6].im, z[2].im, z[2].im, t8);
322
323 TRANSFORM(z[1],z[3],z[5],z[7],sqrthalf,sqrthalf);
324}
325
326#if !CONFIG_SMALL
327static void fft16(FFTComplex *z)
328{
329 FFTSample t1, t2, t3, t4, t5, t6;
330
331 fft8(z);
332 fft4(z+8);
333 fft4(z+12);
334
335 TRANSFORM_ZERO(z[0],z[4],z[8],z[12]);
336 TRANSFORM(z[2],z[6],z[10],z[14],sqrthalf,sqrthalf);
337 TRANSFORM(z[1],z[5],z[9],z[13],ff_cos_16[1],ff_cos_16[3]);
338 TRANSFORM(z[3],z[7],z[11],z[15],ff_cos_16[3],ff_cos_16[1]);
339}
340#else
341DECL_FFT(16,8,4)
342#endif
343DECL_FFT(32,16,8)
344DECL_FFT(64,32,16)
345DECL_FFT(128,64,32)
346DECL_FFT(256,128,64)
347DECL_FFT(512,256,128)
348#if !CONFIG_SMALL
349#define pass pass_big
350#endif
351DECL_FFT(1024,512,256)
352DECL_FFT(2048,1024,512)
353DECL_FFT(4096,2048,1024)
354DECL_FFT(8192,4096,2048)
355DECL_FFT(16384,8192,4096)
356DECL_FFT(32768,16384,8192)
357DECL_FFT(65536,32768,16384)
358
359static void (* const fft_dispatch[])(FFTComplex*) = {
360 fft4, fft8, fft16, fft32, fft64, fft128, fft256, fft512, fft1024,
361 fft2048, fft4096, fft8192, fft16384, fft32768, fft65536,
362};
363
364void ff_fft_calc_c(FFTContext *s, FFTComplex *z)
365{
366 fft_dispatch[s->nbits-2](z);
367}
368
diff --git a/apps/codecs/libwmapro/fft.h b/apps/codecs/libwmapro/fft.h
new file mode 100644
index 0000000000..1f5b2e86da
--- /dev/null
+++ b/apps/codecs/libwmapro/fft.h
@@ -0,0 +1,240 @@
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/* FFT computation */
31
32struct FFTContext {
33 int nbits;
34 int inverse;
35 uint16_t *revtab;
36 FFTComplex *exptab;
37 FFTComplex *exptab1; /* only used by SSE code */
38 FFTComplex *tmp_buf;
39 int mdct_size; /* size of MDCT (i.e. number of input data * 2) */
40 int mdct_bits; /* n = 2^nbits */
41 /* pre/post rotation tables */
42 FFTSample *tcos;
43 FFTSample *tsin;
44 void (*fft_permute)(struct FFTContext *s, FFTComplex *z);
45 void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
46 void (*imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input);
47 void (*imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input);
48 void (*mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input);
49 int split_radix;
50 int permutation;
51#define FF_MDCT_PERM_NONE 0
52#define FF_MDCT_PERM_INTERLEAVE 1
53};
54
55#if CONFIG_HARDCODED_TABLES
56#define COSTABLE_CONST const
57#define SINTABLE_CONST const
58#define SINETABLE_CONST const
59#else
60#define COSTABLE_CONST
61#define SINTABLE_CONST
62#define SINETABLE_CONST
63#endif
64
65#define COSTABLE(size) \
66 COSTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_cos_##size)[size/2]
67#define SINTABLE(size) \
68 SINTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_sin_##size)[size/2]
69#define SINETABLE(size) \
70 SINETABLE_CONST DECLARE_ALIGNED(16, float, ff_sine_##size)[size]
71extern COSTABLE(16);
72extern COSTABLE(32);
73extern COSTABLE(64);
74extern COSTABLE(128);
75extern COSTABLE(256);
76extern COSTABLE(512);
77extern COSTABLE(1024);
78extern COSTABLE(2048);
79extern COSTABLE(4096);
80extern COSTABLE(8192);
81extern COSTABLE(16384);
82extern COSTABLE(32768);
83extern COSTABLE(65536);
84extern COSTABLE_CONST FFTSample* const ff_cos_tabs[17];
85
86/**
87 * Initializes the cosine table in ff_cos_tabs[index]
88 * \param index index in ff_cos_tabs array of the table to initialize
89 */
90void ff_init_ff_cos_tabs(int index);
91
92extern SINTABLE(16);
93extern SINTABLE(32);
94extern SINTABLE(64);
95extern SINTABLE(128);
96extern SINTABLE(256);
97extern SINTABLE(512);
98extern SINTABLE(1024);
99extern SINTABLE(2048);
100extern SINTABLE(4096);
101extern SINTABLE(8192);
102extern SINTABLE(16384);
103extern SINTABLE(32768);
104extern SINTABLE(65536);
105
106/**
107 * Sets up a complex FFT.
108 * @param nbits log2 of the length of the input array
109 * @param inverse if 0 perform the forward transform, if 1 perform the inverse
110 */
111int ff_fft_init(FFTContext *s, int nbits, int inverse);
112void ff_fft_permute_c(FFTContext *s, FFTComplex *z);
113void ff_fft_calc_c(FFTContext *s, FFTComplex *z);
114
115void ff_fft_init_altivec(FFTContext *s);
116void ff_fft_init_mmx(FFTContext *s);
117void ff_fft_init_arm(FFTContext *s);
118
119/**
120 * Do the permutation needed BEFORE calling ff_fft_calc().
121 */
122static inline void ff_fft_permute(FFTContext *s, FFTComplex *z)
123{
124 s->fft_permute(s, z);
125}
126/**
127 * Do a complex FFT with the parameters defined in ff_fft_init(). The
128 * input data must be permuted before. No 1.0/sqrt(n) normalization is done.
129 */
130static inline void ff_fft_calc(FFTContext *s, FFTComplex *z)
131{
132 s->fft_calc(s, z);
133}
134void ff_fft_end(FFTContext *s);
135
136/* MDCT computation */
137
138static inline void ff_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
139{
140 s->imdct_calc(s, output, input);
141}
142static inline void ff_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input)
143{
144 s->imdct_half(s, output, input);
145}
146
147static inline void ff_mdct_calc(FFTContext *s, FFTSample *output,
148 const FFTSample *input)
149{
150 s->mdct_calc(s, output, input);
151}
152
153/**
154 * Generate a Kaiser-Bessel Derived Window.
155 * @param window pointer to half window
156 * @param alpha determines window shape
157 * @param n size of half window
158 */
159void ff_kbd_window_init(float *window, float alpha, int n);
160
161/**
162 * Generate a sine window.
163 * @param window pointer to half window
164 * @param n size of half window
165 */
166void ff_sine_window_init(float *window, int n);
167
168/**
169 * initialize the specified entry of ff_sine_windows
170 */
171void ff_init_ff_sine_windows(int index);
172extern SINETABLE( 32);
173extern SINETABLE( 64);
174extern SINETABLE( 128);
175extern SINETABLE( 256);
176extern SINETABLE( 512);
177extern SINETABLE(1024);
178extern SINETABLE(2048);
179extern SINETABLE(4096);
180extern SINETABLE_CONST float * const ff_sine_windows[13];
181
182int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale);
183void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input);
184void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input);
185void ff_mdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input);
186void ff_mdct_end(FFTContext *s);
187
188/* Real Discrete Fourier Transform */
189
190struct RDFTContext {
191 int nbits;
192 int inverse;
193 int sign_convention;
194
195 /* pre/post rotation tables */
196 const FFTSample *tcos;
197 SINTABLE_CONST FFTSample *tsin;
198 FFTContext fft;
199 void (*rdft_calc)(struct RDFTContext *s, FFTSample *z);
200};
201
202/**
203 * Sets up a real FFT.
204 * @param nbits log2 of the length of the input array
205 * @param trans the type of transform
206 */
207int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans);
208void ff_rdft_end(RDFTContext *s);
209
210void ff_rdft_init_arm(RDFTContext *s);
211
212static av_always_inline void ff_rdft_calc(RDFTContext *s, FFTSample *data)
213{
214 s->rdft_calc(s, data);
215}
216
217/* Discrete Cosine Transform */
218
219struct DCTContext {
220 int nbits;
221 int inverse;
222 RDFTContext rdft;
223 const float *costab;
224 FFTSample *csc2;
225 void (*dct_calc)(struct DCTContext *s, FFTSample *data);
226};
227
228/**
229 * Sets up DCT.
230 * @param nbits size of the input array:
231 * (1 << nbits) for DCT-II, DCT-III and DST-I
232 * (1 << nbits) + 1 for DCT-I
233 *
234 * @note the first element of the input of DST-I is ignored
235 */
236int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType type);
237void ff_dct_calc(DCTContext *s, FFTSample *data);
238void ff_dct_end (DCTContext *s);
239
240#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..c325778d67
--- /dev/null
+++ b/apps/codecs/libwmapro/get_bits.h
@@ -0,0 +1,691 @@
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
437/**
438 * reads 0-32 bits as a signed integer.
439 */
440static inline int get_sbits_long(GetBitContext *s, int n) {
441 return sign_extend(get_bits_long(s, n), n);
442}
443
444/**
445 * shows 0-32 bits.
446 */
447static inline unsigned int show_bits_long(GetBitContext *s, int n){
448 if(n<=MIN_CACHE_BITS) return show_bits(s, n);
449 else{
450 GetBitContext gb= *s;
451 return get_bits_long(&gb, n);
452 }
453}
454
455static inline int check_marker(GetBitContext *s, const char *msg)
456{
457 int bit= get_bits1(s);
458 if(!bit)
459 av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg);
460
461 return bit;
462}
463
464/**
465 * init GetBitContext.
466 * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits
467 * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
468 * @param bit_size the size of the buffer in bits
469 *
470 * While GetBitContext stores the buffer size, for performance reasons you are
471 * responsible for checking for the buffer end yourself (take advantage of the padding)!
472 */
473static inline void init_get_bits(GetBitContext *s,
474 const uint8_t *buffer, int bit_size)
475{
476 int buffer_size= (bit_size+7)>>3;
477 if(buffer_size < 0 || bit_size < 0) {
478 buffer_size = bit_size = 0;
479 buffer = NULL;
480 }
481
482 s->buffer= buffer;
483 s->size_in_bits= bit_size;
484 s->buffer_end= buffer + buffer_size;
485#ifdef ALT_BITSTREAM_READER
486 s->index=0;
487#elif defined LIBMPEG2_BITSTREAM_READER
488 s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));
489 s->bit_count = 16 + 8*((intptr_t)buffer&1);
490 skip_bits_long(s, 0);
491#elif defined A32_BITSTREAM_READER
492 s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));
493 s->bit_count = 32 + 8*((intptr_t)buffer&3);
494 skip_bits_long(s, 0);
495#endif
496}
497
498static inline void align_get_bits(GetBitContext *s)
499{
500 int n= (-get_bits_count(s)) & 7;
501 if(n) skip_bits(s, n);
502}
503
504#define init_vlc(vlc, nb_bits, nb_codes,\
505 bits, bits_wrap, bits_size,\
506 codes, codes_wrap, codes_size,\
507 flags)\
508 init_vlc_sparse(vlc, nb_bits, nb_codes,\
509 bits, bits_wrap, bits_size,\
510 codes, codes_wrap, codes_size,\
511 NULL, 0, 0, flags)
512
513int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
514 const void *bits, int bits_wrap, int bits_size,
515 const void *codes, int codes_wrap, int codes_size,
516 const void *symbols, int symbols_wrap, int symbols_size,
517 int flags);
518#define INIT_VLC_LE 2
519#define INIT_VLC_USE_NEW_STATIC 4
520void free_vlc(VLC *vlc);
521
522#define INIT_VLC_STATIC(vlc, bits, a,b,c,d,e,f,g, static_size)\
523{\
524 static VLC_TYPE table[static_size][2];\
525 (vlc)->table= table;\
526 (vlc)->table_allocated= static_size;\
527 init_vlc(vlc, bits, a,b,c,d,e,f,g, INIT_VLC_USE_NEW_STATIC);\
528}
529
530
531/**
532 *
533 * If the vlc code is invalid and max_depth=1, then no bits will be removed.
534 * If the vlc code is invalid and max_depth>1, then the number of bits removed
535 * is undefined.
536 */
537#define GET_VLC(code, name, gb, table, bits, max_depth)\
538{\
539 int n, nb_bits;\
540 unsigned int index;\
541\
542 index= SHOW_UBITS(name, gb, bits);\
543 code = table[index][0];\
544 n = table[index][1];\
545\
546 if(max_depth > 1 && n < 0){\
547 LAST_SKIP_BITS(name, gb, bits)\
548 UPDATE_CACHE(name, gb)\
549\
550 nb_bits = -n;\
551\
552 index= SHOW_UBITS(name, gb, nb_bits) + code;\
553 code = table[index][0];\
554 n = table[index][1];\
555 if(max_depth > 2 && n < 0){\
556 LAST_SKIP_BITS(name, gb, nb_bits)\
557 UPDATE_CACHE(name, gb)\
558\
559 nb_bits = -n;\
560\
561 index= SHOW_UBITS(name, gb, nb_bits) + code;\
562 code = table[index][0];\
563 n = table[index][1];\
564 }\
565 }\
566 SKIP_BITS(name, gb, n)\
567}
568
569#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\
570{\
571 int n, nb_bits;\
572 unsigned int index;\
573\
574 index= SHOW_UBITS(name, gb, bits);\
575 level = table[index].level;\
576 n = table[index].len;\
577\
578 if(max_depth > 1 && n < 0){\
579 SKIP_BITS(name, gb, bits)\
580 if(need_update){\
581 UPDATE_CACHE(name, gb)\
582 }\
583\
584 nb_bits = -n;\
585\
586 index= SHOW_UBITS(name, gb, nb_bits) + level;\
587 level = table[index].level;\
588 n = table[index].len;\
589 }\
590 run= table[index].run;\
591 SKIP_BITS(name, gb, n)\
592}
593
594
595/**
596 * parses a vlc code, faster then get_vlc()
597 * @param bits is the number of bits which will be read at once, must be
598 * identical to nb_bits in init_vlc()
599 * @param max_depth is the number of times bits bits must be read to completely
600 * read the longest vlc code
601 * = (max_vlc_length + bits - 1) / bits
602 */
603static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
604 int bits, int max_depth)
605{
606 int code;
607
608 OPEN_READER(re, s)
609 UPDATE_CACHE(re, s)
610
611 GET_VLC(code, re, s, table, bits, max_depth)
612
613 CLOSE_READER(re, s)
614 return code;
615}
616
617//#define TRACE
618
619#ifdef TRACE
620static inline void print_bin(int bits, int n){
621 int i;
622
623 for(i=n-1; i>=0; i--){
624 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1);
625 }
626 for(i=n; i<24; i++)
627 av_log(NULL, AV_LOG_DEBUG, " ");
628}
629
630static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
631 int r= get_bits(s, n);
632
633 print_bin(r, n);
634 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);
635 return r;
636}
637static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){
638 int show= show_bits(s, 24);
639 int pos= get_bits_count(s);
640 int r= get_vlc2(s, table, bits, max_depth);
641 int len= get_bits_count(s) - pos;
642 int bits2= show>>(24-len);
643
644 print_bin(bits2, len);
645
646 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
647 return r;
648}
649static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
650 int show= show_bits(s, n);
651 int r= get_xbits(s, n);
652
653 print_bin(show, n);
654 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);
655 return r;
656}
657
658#define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
659#define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
660#define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
661#define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
662#define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
663
664#define tprintf(p, ...) av_log(p, AV_LOG_DEBUG, __VA_ARGS__)
665
666#else //TRACE
667#define tprintf(p, ...) {}
668#endif
669
670static inline int decode012(GetBitContext *gb){
671 int n;
672 n = get_bits1(gb);
673 if (n == 0)
674 return 0;
675 else
676 return get_bits1(gb) + 1;
677}
678
679static inline int decode210(GetBitContext *gb){
680 if (get_bits1(gb))
681 return 0;
682 else
683 return 2 - get_bits1(gb);
684}
685
686static inline int get_bits_left(GetBitContext *gb)
687{
688 return gb->size_in_bits - get_bits_count(gb);
689}
690
691#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..7ce019c12a
--- /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 */
33int 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 */
43AVHWAccel *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..1523de6753
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/avutil.h
@@ -0,0 +1,89 @@
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_GLUE(a, b) a ## b
34#define AV_JOIN(a, b) AV_GLUE(a, b)
35
36#define AV_PRAGMA(s) _Pragma(#s)
37
38#define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c)
39#define AV_VERSION_DOT(a, b, c) a ##.## b ##.## c
40#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
41
42#define LIBAVUTIL_VERSION_MAJOR 50
43#define LIBAVUTIL_VERSION_MINOR 14
44#define LIBAVUTIL_VERSION_MICRO 0
45
46#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
47 LIBAVUTIL_VERSION_MINOR, \
48 LIBAVUTIL_VERSION_MICRO)
49#define LIBAVUTIL_VERSION AV_VERSION(LIBAVUTIL_VERSION_MAJOR, \
50 LIBAVUTIL_VERSION_MINOR, \
51 LIBAVUTIL_VERSION_MICRO)
52#define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT
53
54#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION)
55
56/**
57 * Returns the LIBAVUTIL_VERSION_INT constant.
58 */
59unsigned avutil_version(void);
60
61/**
62 * Returns the libavutil build-time configuration.
63 */
64const char *avutil_configuration(void);
65
66/**
67 * Returns the libavutil license.
68 */
69const char *avutil_license(void);
70
71enum AVMediaType {
72 AVMEDIA_TYPE_UNKNOWN = -1,
73 AVMEDIA_TYPE_VIDEO,
74 AVMEDIA_TYPE_AUDIO,
75 AVMEDIA_TYPE_DATA,
76 AVMEDIA_TYPE_SUBTITLE,
77 AVMEDIA_TYPE_ATTACHMENT,
78 AVMEDIA_TYPE_NB
79};
80
81#include "common.h"
82#include "error.h"
83#include "mathematics.h"
84#include "rational.h"
85#include "intfloat_readwrite.h"
86#include "log.h"
87#include "pixfmt.h"
88
89#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..74c7af3026
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/bswap.h
@@ -0,0 +1,101 @@
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 "config.h"
31#include "attributes.h"
32
33#if ARCH_ARM
34# include "arm/bswap.h"
35#elif ARCH_AVR32
36# include "avr32/bswap.h"
37#elif ARCH_BFIN
38# include "bfin/bswap.h"
39#elif ARCH_SH4
40# include "sh4/bswap.h"
41#elif ARCH_X86
42# include "x86/bswap.h"
43#endif
44
45#ifndef bswap_16
46static av_always_inline av_const uint16_t bswap_16(uint16_t x)
47{
48 x= (x>>8) | (x<<8);
49 return x;
50}
51#endif
52
53#ifndef bswap_32
54static av_always_inline av_const uint32_t bswap_32(uint32_t x)
55{
56 x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
57 x= (x>>16) | (x<<16);
58 return x;
59}
60#endif
61
62#ifndef bswap_64
63static inline uint64_t av_const bswap_64(uint64_t x)
64{
65#if 0
66 x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
67 x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
68 return (x>>32) | (x<<32);
69#else
70 union {
71 uint64_t ll;
72 uint32_t l[2];
73 } w, r;
74 w.ll = x;
75 r.l[0] = bswap_32 (w.l[1]);
76 r.l[1] = bswap_32 (w.l[0]);
77 return r.ll;
78#endif
79}
80#endif
81
82// be2me ... big-endian to machine-endian
83// le2me ... little-endian to machine-endian
84
85#if HAVE_BIGENDIAN
86#define be2me_16(x) (x)
87#define be2me_32(x) (x)
88#define be2me_64(x) (x)
89#define le2me_16(x) bswap_16(x)
90#define le2me_32(x) bswap_32(x)
91#define le2me_64(x) bswap_64(x)
92#else
93#define be2me_16(x) bswap_16(x)
94#define be2me_32(x) bswap_32(x)
95#define be2me_64(x) bswap_64(x)
96#define le2me_16(x) (x)
97#define le2me_32(x) (x)
98#define le2me_64(x) (x)
99#endif
100
101#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..fae0b5b09b
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/common.h
@@ -0,0 +1,297 @@
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
39//rounded division & shift
40#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
41/* assume b>0 */
42#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
43#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
44#define FFSIGN(a) ((a) > 0 ? 1 : -1)
45
46#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
47#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
48#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
49#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
50
51#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
52#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
53#define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))
54
55/* misc math functions */
56extern const uint8_t ff_log2_tab[256];
57
58extern const uint8_t av_reverse[256];
59
60static inline av_const int av_log2_c(unsigned int v)
61{
62 int n = 0;
63 if (v & 0xffff0000) {
64 v >>= 16;
65 n += 16;
66 }
67 if (v & 0xff00) {
68 v >>= 8;
69 n += 8;
70 }
71 n += ff_log2_tab[v];
72
73 return n;
74}
75
76static inline av_const int av_log2_16bit_c(unsigned int v)
77{
78 int n = 0;
79 if (v & 0xff00) {
80 v >>= 8;
81 n += 8;
82 }
83 n += ff_log2_tab[v];
84
85 return n;
86}
87
88#ifdef HAVE_AV_CONFIG_H
89# include "config.h"
90# include "intmath.h"
91#endif
92
93#ifndef av_log2
94# define av_log2 av_log2_c
95#endif
96#ifndef av_log2_16bit
97# define av_log2_16bit av_log2_16bit_c
98#endif
99
100/**
101 * Clips a signed integer value into the amin-amax range.
102 * @param a value to clip
103 * @param amin minimum value of the clip range
104 * @param amax maximum value of the clip range
105 * @return clipped value
106 */
107static inline av_const int av_clip(int a, int amin, int amax)
108{
109 if (a < amin) return amin;
110 else if (a > amax) return amax;
111 else return a;
112}
113
114/**
115 * Clips a signed integer value into the 0-255 range.
116 * @param a value to clip
117 * @return clipped value
118 */
119static inline av_const uint8_t av_clip_uint8(int a)
120{
121 if (a&(~255)) return (-a)>>31;
122 else return a;
123}
124
125/**
126 * Clips a signed integer value into the 0-65535 range.
127 * @param a value to clip
128 * @return clipped value
129 */
130static inline av_const uint16_t av_clip_uint16(int a)
131{
132 if (a&(~65535)) return (-a)>>31;
133 else return a;
134}
135
136/**
137 * Clips a signed integer value into the -32768,32767 range.
138 * @param a value to clip
139 * @return clipped value
140 */
141static inline av_const int16_t av_clip_int16(int a)
142{
143 if ((a+32768) & ~65535) return (a>>31) ^ 32767;
144 else return a;
145}
146
147/**
148 * Clips a float value into the amin-amax range.
149 * @param a value to clip
150 * @param amin minimum value of the clip range
151 * @param amax maximum value of the clip range
152 * @return clipped value
153 */
154static inline av_const float av_clipf(float a, float amin, float amax)
155{
156 if (a < amin) return amin;
157 else if (a > amax) return amax;
158 else return a;
159}
160
161/** Computes ceil(log2(x)).
162 * @param x value used to compute ceil(log2(x))
163 * @return computed ceiling of log2(x)
164 */
165static inline av_const int av_ceil_log2(int x)
166{
167 return av_log2((x - 1) << 1);
168}
169
170#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
171#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
172
173/*!
174 * \def GET_UTF8(val, GET_BYTE, ERROR)
175 * Converts a UTF-8 character (up to 4 bytes long) to its 32-bit UCS-4 encoded form
176 * \param val is the output and should be of type uint32_t. It holds the converted
177 * UCS-4 character and should be a left value.
178 * \param GET_BYTE gets UTF-8 encoded bytes from any proper source. It can be
179 * a function or a statement whose return value or evaluated value is of type
180 * uint8_t. It will be executed up to 4 times for values in the valid UTF-8 range,
181 * and up to 7 times in the general case.
182 * \param ERROR action that should be taken when an invalid UTF-8 byte is returned
183 * from GET_BYTE. It should be a statement that jumps out of the macro,
184 * like exit(), goto, return, break, or continue.
185 */
186#define GET_UTF8(val, GET_BYTE, ERROR)\
187 val= GET_BYTE;\
188 {\
189 int ones= 7 - av_log2(val ^ 255);\
190 if(ones==1)\
191 ERROR\
192 val&= 127>>ones;\
193 while(--ones > 0){\
194 int tmp= GET_BYTE - 128;\
195 if(tmp>>6)\
196 ERROR\
197 val= (val<<6) + tmp;\
198 }\
199 }
200
201/*!
202 * \def GET_UTF16(val, GET_16BIT, ERROR)
203 * Converts a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form
204 * \param val is the output and should be of type uint32_t. It holds the converted
205 * UCS-4 character and should be a left value.
206 * \param GET_16BIT gets two bytes of UTF-16 encoded data converted to native endianness.
207 * It can be a function or a statement whose return value or evaluated value is of type
208 * uint16_t. It will be executed up to 2 times.
209 * \param ERROR action that should be taken when an invalid UTF-16 surrogate is
210 * returned from GET_BYTE. It should be a statement that jumps out of the macro,
211 * like exit(), goto, return, break, or continue.
212 */
213#define GET_UTF16(val, GET_16BIT, ERROR)\
214 val = GET_16BIT;\
215 {\
216 unsigned int hi = val - 0xD800;\
217 if (hi < 0x800) {\
218 val = GET_16BIT - 0xDC00;\
219 if (val > 0x3FFU || hi > 0x3FFU)\
220 ERROR\
221 val += (hi<<10) + 0x10000;\
222 }\
223 }\
224
225/*!
226 * \def PUT_UTF8(val, tmp, PUT_BYTE)
227 * Converts a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long).
228 * \param val is an input-only argument and should be of type uint32_t. It holds
229 * a UCS-4 encoded Unicode character that is to be converted to UTF-8. If
230 * val is given as a function it is executed only once.
231 * \param tmp is a temporary variable and should be of type uint8_t. It
232 * represents an intermediate value during conversion that is to be
233 * output by PUT_BYTE.
234 * \param PUT_BYTE writes the converted UTF-8 bytes to any proper destination.
235 * It could be a function or a statement, and uses tmp as the input byte.
236 * For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be
237 * executed up to 4 times for values in the valid UTF-8 range and up to
238 * 7 times in the general case, depending on the length of the converted
239 * Unicode character.
240 */
241#define PUT_UTF8(val, tmp, PUT_BYTE)\
242 {\
243 int bytes, shift;\
244 uint32_t in = val;\
245 if (in < 0x80) {\
246 tmp = in;\
247 PUT_BYTE\
248 } else {\
249 bytes = (av_log2(in) + 4) / 5;\
250 shift = (bytes - 1) * 6;\
251 tmp = (256 - (256 >> bytes)) | (in >> shift);\
252 PUT_BYTE\
253 while (shift >= 6) {\
254 shift -= 6;\
255 tmp = 0x80 | ((in >> shift) & 0x3f);\
256 PUT_BYTE\
257 }\
258 }\
259 }
260
261/*!
262 * \def PUT_UTF16(val, tmp, PUT_16BIT)
263 * Converts a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes).
264 * \param val is an input-only argument and should be of type uint32_t. It holds
265 * a UCS-4 encoded Unicode character that is to be converted to UTF-16. If
266 * val is given as a function it is executed only once.
267 * \param tmp is a temporary variable and should be of type uint16_t. It
268 * represents an intermediate value during conversion that is to be
269 * output by PUT_16BIT.
270 * \param PUT_16BIT writes the converted UTF-16 data to any proper destination
271 * in desired endianness. It could be a function or a statement, and uses tmp
272 * as the input byte. For example, PUT_BYTE could be "*output++ = tmp;"
273 * PUT_BYTE will be executed 1 or 2 times depending on input character.
274 */
275#define PUT_UTF16(val, tmp, PUT_16BIT)\
276 {\
277 uint32_t in = val;\
278 if (in < 0x10000) {\
279 tmp = in;\
280 PUT_16BIT\
281 } else {\
282 tmp = 0xD800 | ((in - 0x10000) >> 10);\
283 PUT_16BIT\
284 tmp = 0xDC00 | ((in - 0x10000) & 0x3FF);\
285 PUT_16BIT\
286 }\
287 }\
288
289
290
291#include "mem.h"
292
293#ifdef HAVE_AV_CONFIG_H
294# include "internal.h"
295#endif /* HAVE_AV_CONFIG_H */
296
297#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..b47db3d8c6
--- /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..c8026f0872
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/intreadwrite.h
@@ -0,0 +1,516 @@
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 "config.h"
24#include "bswap.h"
25#include "common.h"
26
27typedef union {
28 uint64_t u64;
29 uint32_t u32[2];
30 uint16_t u16[4];
31 uint8_t u8 [8];
32 double f64;
33 float f32[2];
34} av_alias av_alias64;
35
36typedef union {
37 uint32_t u32;
38 uint16_t u16[2];
39 uint8_t u8 [4];
40 float f32;
41} av_alias av_alias32;
42
43typedef union {
44 uint16_t u16;
45 uint8_t u8 [2];
46} av_alias av_alias16;
47
48/*
49 * Arch-specific headers can provide any combination of
50 * AV_[RW][BLN](16|24|32|64) and AV_(COPY|SWAP|ZERO)(64|128) macros.
51 * Preprocessor symbols must be defined, even if these are implemented
52 * as inline functions.
53 */
54
55#if ARCH_ARM
56# include "arm/intreadwrite.h"
57#elif ARCH_AVR32
58# include "avr32/intreadwrite.h"
59#elif ARCH_MIPS
60# include "mips/intreadwrite.h"
61#elif ARCH_PPC
62# include "ppc/intreadwrite.h"
63#elif ARCH_TOMI
64# include "tomi/intreadwrite.h"
65#elif ARCH_X86
66# include "x86/intreadwrite.h"
67#endif
68
69/*
70 * Map AV_RNXX <-> AV_R[BL]XX for all variants provided by per-arch headers.
71 */
72
73#if HAVE_BIGENDIAN
74
75# if defined(AV_RN16) && !defined(AV_RB16)
76# define AV_RB16(p) AV_RN16(p)
77# elif !defined(AV_RN16) && defined(AV_RB16)
78# define AV_RN16(p) AV_RB16(p)
79# endif
80
81# if defined(AV_WN16) && !defined(AV_WB16)
82# define AV_WB16(p, v) AV_WN16(p, v)
83# elif !defined(AV_WN16) && defined(AV_WB16)
84# define AV_WN16(p, v) AV_WB16(p, v)
85# endif
86
87# if defined(AV_RN24) && !defined(AV_RB24)
88# define AV_RB24(p) AV_RN24(p)
89# elif !defined(AV_RN24) && defined(AV_RB24)
90# define AV_RN24(p) AV_RB24(p)
91# endif
92
93# if defined(AV_WN24) && !defined(AV_WB24)
94# define AV_WB24(p, v) AV_WN24(p, v)
95# elif !defined(AV_WN24) && defined(AV_WB24)
96# define AV_WN24(p, v) AV_WB24(p, v)
97# endif
98
99# if defined(AV_RN32) && !defined(AV_RB32)
100# define AV_RB32(p) AV_RN32(p)
101# elif !defined(AV_RN32) && defined(AV_RB32)
102# define AV_RN32(p) AV_RB32(p)
103# endif
104
105# if defined(AV_WN32) && !defined(AV_WB32)
106# define AV_WB32(p, v) AV_WN32(p, v)
107# elif !defined(AV_WN32) && defined(AV_WB32)
108# define AV_WN32(p, v) AV_WB32(p, v)
109# endif
110
111# if defined(AV_RN64) && !defined(AV_RB64)
112# define AV_RB64(p) AV_RN64(p)
113# elif !defined(AV_RN64) && defined(AV_RB64)
114# define AV_RN64(p) AV_RB64(p)
115# endif
116
117# if defined(AV_WN64) && !defined(AV_WB64)
118# define AV_WB64(p, v) AV_WN64(p, v)
119# elif !defined(AV_WN64) && defined(AV_WB64)
120# define AV_WN64(p, v) AV_WB64(p, v)
121# endif
122
123#else /* HAVE_BIGENDIAN */
124
125# if defined(AV_RN16) && !defined(AV_RL16)
126# define AV_RL16(p) AV_RN16(p)
127# elif !defined(AV_RN16) && defined(AV_RL16)
128# define AV_RN16(p) AV_RL16(p)
129# endif
130
131# if defined(AV_WN16) && !defined(AV_WL16)
132# define AV_WL16(p, v) AV_WN16(p, v)
133# elif !defined(AV_WN16) && defined(AV_WL16)
134# define AV_WN16(p, v) AV_WL16(p, v)
135# endif
136
137# if defined(AV_RN24) && !defined(AV_RL24)
138# define AV_RL24(p) AV_RN24(p)
139# elif !defined(AV_RN24) && defined(AV_RL24)
140# define AV_RN24(p) AV_RL24(p)
141# endif
142
143# if defined(AV_WN24) && !defined(AV_WL24)
144# define AV_WL24(p, v) AV_WN24(p, v)
145# elif !defined(AV_WN24) && defined(AV_WL24)
146# define AV_WN24(p, v) AV_WL24(p, v)
147# endif
148
149# if defined(AV_RN32) && !defined(AV_RL32)
150# define AV_RL32(p) AV_RN32(p)
151# elif !defined(AV_RN32) && defined(AV_RL32)
152# define AV_RN32(p) AV_RL32(p)
153# endif
154
155# if defined(AV_WN32) && !defined(AV_WL32)
156# define AV_WL32(p, v) AV_WN32(p, v)
157# elif !defined(AV_WN32) && defined(AV_WL32)
158# define AV_WN32(p, v) AV_WL32(p, v)
159# endif
160
161# if defined(AV_RN64) && !defined(AV_RL64)
162# define AV_RL64(p) AV_RN64(p)
163# elif !defined(AV_RN64) && defined(AV_RL64)
164# define AV_RN64(p) AV_RL64(p)
165# endif
166
167# if defined(AV_WN64) && !defined(AV_WL64)
168# define AV_WL64(p, v) AV_WN64(p, v)
169# elif !defined(AV_WN64) && defined(AV_WL64)
170# define AV_WN64(p, v) AV_WL64(p, v)
171# endif
172
173#endif /* !HAVE_BIGENDIAN */
174
175/*
176 * Define AV_[RW]N helper macros to simplify definitions not provided
177 * by per-arch headers.
178 */
179
180#if HAVE_ATTRIBUTE_PACKED
181
182union unaligned_64 { uint64_t l; } __attribute__((packed)) av_alias;
183union unaligned_32 { uint32_t l; } __attribute__((packed)) av_alias;
184union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
185
186# define AV_RN(s, p) (((const union unaligned_##s *) (p))->l)
187# define AV_WN(s, p, v) ((((union unaligned_##s *) (p))->l) = (v))
188
189#elif defined(__DECC)
190
191# define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
192# define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v))
193
194#elif HAVE_FAST_UNALIGNED
195
196# define AV_RN(s, p) (((const av_alias##s*)(p))->u##s)
197# define AV_WN(s, p, v) (((av_alias##s*)(p))->u##s = (v))
198
199#else
200
201#ifndef AV_RB16
202# define AV_RB16(x) \
203 ((((const uint8_t*)(x))[0] << 8) | \
204 ((const uint8_t*)(x))[1])
205#endif
206#ifndef AV_WB16
207# define AV_WB16(p, d) do { \
208 ((uint8_t*)(p))[1] = (d); \
209 ((uint8_t*)(p))[0] = (d)>>8; \
210 } while(0)
211#endif
212
213#ifndef AV_RL16
214# define AV_RL16(x) \
215 ((((const uint8_t*)(x))[1] << 8) | \
216 ((const uint8_t*)(x))[0])
217#endif
218#ifndef AV_WL16
219# define AV_WL16(p, d) do { \
220 ((uint8_t*)(p))[0] = (d); \
221 ((uint8_t*)(p))[1] = (d)>>8; \
222 } while(0)
223#endif
224
225#ifndef AV_RB32
226# define AV_RB32(x) \
227 ((((const uint8_t*)(x))[0] << 24) | \
228 (((const uint8_t*)(x))[1] << 16) | \
229 (((const uint8_t*)(x))[2] << 8) | \
230 ((const uint8_t*)(x))[3])
231#endif
232#ifndef AV_WB32
233# define AV_WB32(p, d) do { \
234 ((uint8_t*)(p))[3] = (d); \
235 ((uint8_t*)(p))[2] = (d)>>8; \
236 ((uint8_t*)(p))[1] = (d)>>16; \
237 ((uint8_t*)(p))[0] = (d)>>24; \
238 } while(0)
239#endif
240
241#ifndef AV_RL32
242# define AV_RL32(x) \
243 ((((const uint8_t*)(x))[3] << 24) | \
244 (((const uint8_t*)(x))[2] << 16) | \
245 (((const uint8_t*)(x))[1] << 8) | \
246 ((const uint8_t*)(x))[0])
247#endif
248#ifndef AV_WL32
249# define AV_WL32(p, d) do { \
250 ((uint8_t*)(p))[0] = (d); \
251 ((uint8_t*)(p))[1] = (d)>>8; \
252 ((uint8_t*)(p))[2] = (d)>>16; \
253 ((uint8_t*)(p))[3] = (d)>>24; \
254 } while(0)
255#endif
256
257#ifndef AV_RB64
258# define AV_RB64(x) \
259 (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
260 ((uint64_t)((const uint8_t*)(x))[1] << 48) | \
261 ((uint64_t)((const uint8_t*)(x))[2] << 40) | \
262 ((uint64_t)((const uint8_t*)(x))[3] << 32) | \
263 ((uint64_t)((const uint8_t*)(x))[4] << 24) | \
264 ((uint64_t)((const uint8_t*)(x))[5] << 16) | \
265 ((uint64_t)((const uint8_t*)(x))[6] << 8) | \
266 (uint64_t)((const uint8_t*)(x))[7])
267#endif
268#ifndef AV_WB64
269# define AV_WB64(p, d) do { \
270 ((uint8_t*)(p))[7] = (d); \
271 ((uint8_t*)(p))[6] = (d)>>8; \
272 ((uint8_t*)(p))[5] = (d)>>16; \
273 ((uint8_t*)(p))[4] = (d)>>24; \
274 ((uint8_t*)(p))[3] = (d)>>32; \
275 ((uint8_t*)(p))[2] = (d)>>40; \
276 ((uint8_t*)(p))[1] = (d)>>48; \
277 ((uint8_t*)(p))[0] = (d)>>56; \
278 } while(0)
279#endif
280
281#ifndef AV_RL64
282# define AV_RL64(x) \
283 (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
284 ((uint64_t)((const uint8_t*)(x))[6] << 48) | \
285 ((uint64_t)((const uint8_t*)(x))[5] << 40) | \
286 ((uint64_t)((const uint8_t*)(x))[4] << 32) | \
287 ((uint64_t)((const uint8_t*)(x))[3] << 24) | \
288 ((uint64_t)((const uint8_t*)(x))[2] << 16) | \
289 ((uint64_t)((const uint8_t*)(x))[1] << 8) | \
290 (uint64_t)((const uint8_t*)(x))[0])
291#endif
292#ifndef AV_WL64
293# define AV_WL64(p, d) do { \
294 ((uint8_t*)(p))[0] = (d); \
295 ((uint8_t*)(p))[1] = (d)>>8; \
296 ((uint8_t*)(p))[2] = (d)>>16; \
297 ((uint8_t*)(p))[3] = (d)>>24; \
298 ((uint8_t*)(p))[4] = (d)>>32; \
299 ((uint8_t*)(p))[5] = (d)>>40; \
300 ((uint8_t*)(p))[6] = (d)>>48; \
301 ((uint8_t*)(p))[7] = (d)>>56; \
302 } while(0)
303#endif
304
305#if HAVE_BIGENDIAN
306# define AV_RN(s, p) AV_RB##s(p)
307# define AV_WN(s, p, v) AV_WB##s(p, v)
308#else
309# define AV_RN(s, p) AV_RL##s(p)
310# define AV_WN(s, p, v) AV_WL##s(p, v)
311#endif
312
313#endif /* HAVE_FAST_UNALIGNED */
314
315#ifndef AV_RN16
316# define AV_RN16(p) AV_RN(16, p)
317#endif
318
319#ifndef AV_RN32
320# define AV_RN32(p) AV_RN(32, p)
321#endif
322
323#ifndef AV_RN64
324# define AV_RN64(p) AV_RN(64, p)
325#endif
326
327#ifndef AV_WN16
328# define AV_WN16(p, v) AV_WN(16, p, v)
329#endif
330
331#ifndef AV_WN32
332# define AV_WN32(p, v) AV_WN(32, p, v)
333#endif
334
335#ifndef AV_WN64
336# define AV_WN64(p, v) AV_WN(64, p, v)
337#endif
338
339#if HAVE_BIGENDIAN
340# define AV_RB(s, p) AV_RN##s(p)
341# define AV_WB(s, p, v) AV_WN##s(p, v)
342# define AV_RL(s, p) bswap_##s(AV_RN##s(p))
343# define AV_WL(s, p, v) AV_WN##s(p, bswap_##s(v))
344#else
345# define AV_RB(s, p) bswap_##s(AV_RN##s(p))
346# define AV_WB(s, p, v) AV_WN##s(p, bswap_##s(v))
347# define AV_RL(s, p) AV_RN##s(p)
348# define AV_WL(s, p, v) AV_WN##s(p, v)
349#endif
350
351#define AV_RB8(x) (((const uint8_t*)(x))[0])
352#define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0)
353
354#define AV_RL8(x) AV_RB8(x)
355#define AV_WL8(p, d) AV_WB8(p, d)
356
357#ifndef AV_RB16
358# define AV_RB16(p) AV_RB(16, p)
359#endif
360#ifndef AV_WB16
361# define AV_WB16(p, v) AV_WB(16, p, v)
362#endif
363
364#ifndef AV_RL16
365# define AV_RL16(p) AV_RL(16, p)
366#endif
367#ifndef AV_WL16
368# define AV_WL16(p, v) AV_WL(16, p, v)
369#endif
370
371#ifndef AV_RB32
372# define AV_RB32(p) AV_RB(32, p)
373#endif
374#ifndef AV_WB32
375# define AV_WB32(p, v) AV_WB(32, p, v)
376#endif
377
378#ifndef AV_RL32
379# define AV_RL32(p) AV_RL(32, p)
380#endif
381#ifndef AV_WL32
382# define AV_WL32(p, v) AV_WL(32, p, v)
383#endif
384
385#ifndef AV_RB64
386# define AV_RB64(p) AV_RB(64, p)
387#endif
388#ifndef AV_WB64
389# define AV_WB64(p, v) AV_WB(64, p, v)
390#endif
391
392#ifndef AV_RL64
393# define AV_RL64(p) AV_RL(64, p)
394#endif
395#ifndef AV_WL64
396# define AV_WL64(p, v) AV_WL(64, p, v)
397#endif
398
399#ifndef AV_RB24
400# define AV_RB24(x) \
401 ((((const uint8_t*)(x))[0] << 16) | \
402 (((const uint8_t*)(x))[1] << 8) | \
403 ((const uint8_t*)(x))[2])
404#endif
405#ifndef AV_WB24
406# define AV_WB24(p, d) do { \
407 ((uint8_t*)(p))[2] = (d); \
408 ((uint8_t*)(p))[1] = (d)>>8; \
409 ((uint8_t*)(p))[0] = (d)>>16; \
410 } while(0)
411#endif
412
413#ifndef AV_RL24
414# define AV_RL24(x) \
415 ((((const uint8_t*)(x))[2] << 16) | \
416 (((const uint8_t*)(x))[1] << 8) | \
417 ((const uint8_t*)(x))[0])
418#endif
419#ifndef AV_WL24
420# define AV_WL24(p, d) do { \
421 ((uint8_t*)(p))[0] = (d); \
422 ((uint8_t*)(p))[1] = (d)>>8; \
423 ((uint8_t*)(p))[2] = (d)>>16; \
424 } while(0)
425#endif
426
427/*
428 * The AV_[RW]NA macros access naturally aligned data
429 * in a type-safe way.
430 */
431
432#define AV_RNA(s, p) (((const av_alias##s*)(p))->u##s)
433#define AV_WNA(s, p, v) (((av_alias##s*)(p))->u##s = (v))
434
435#ifndef AV_RN16A
436# define AV_RN16A(p) AV_RNA(16, p)
437#endif
438
439#ifndef AV_RN32A
440# define AV_RN32A(p) AV_RNA(32, p)
441#endif
442
443#ifndef AV_RN64A
444# define AV_RN64A(p) AV_RNA(64, p)
445#endif
446
447#ifndef AV_WN16A
448# define AV_WN16A(p, v) AV_WNA(16, p, v)
449#endif
450
451#ifndef AV_WN32A
452# define AV_WN32A(p, v) AV_WNA(32, p, v)
453#endif
454
455#ifndef AV_WN64A
456# define AV_WN64A(p, v) AV_WNA(64, p, v)
457#endif
458
459/* Parameters for AV_COPY*, AV_SWAP*, AV_ZERO* must be
460 * naturally aligned. They may be implemented using MMX,
461 * so emms_c() must be called before using any float code
462 * afterwards.
463 */
464
465#define AV_COPY(n, d, s) \
466 (((av_alias##n*)(d))->u##n = ((const av_alias##n*)(s))->u##n)
467
468#ifndef AV_COPY16
469# define AV_COPY16(d, s) AV_COPY(16, d, s)
470#endif
471
472#ifndef AV_COPY32
473# define AV_COPY32(d, s) AV_COPY(32, d, s)
474#endif
475
476#ifndef AV_COPY64
477# define AV_COPY64(d, s) AV_COPY(64, d, s)
478#endif
479
480#ifndef AV_COPY128
481# define AV_COPY128(d, s) \
482 do { \
483 AV_COPY64(d, s); \
484 AV_COPY64((char*)(d)+8, (char*)(s)+8); \
485 } while(0)
486#endif
487
488#define AV_SWAP(n, a, b) FFSWAP(av_alias##n, *(av_alias##n*)(a), *(av_alias##n*)(b))
489
490#ifndef AV_SWAP64
491# define AV_SWAP64(a, b) AV_SWAP(64, a, b)
492#endif
493
494#define AV_ZERO(n, d) (((av_alias##n*)(d))->u##n = 0)
495
496#ifndef AV_ZERO16
497# define AV_ZERO16(d) AV_ZERO(16, d)
498#endif
499
500#ifndef AV_ZERO32
501# define AV_ZERO32(d) AV_ZERO(32, d)
502#endif
503
504#ifndef AV_ZERO64
505# define AV_ZERO64(d) AV_ZERO(64, d)
506#endif
507
508#ifndef AV_ZERO128
509# define AV_ZERO128(d) \
510 do { \
511 AV_ZERO64(d); \
512 AV_ZERO64((char*)(d)+8); \
513 } while(0)
514#endif
515
516#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..166e724b07
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/log.c
@@ -0,0 +1,92 @@
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
30#if LIBAVUTIL_VERSION_MAJOR > 50
31static
32#endif
33int av_log_level = AV_LOG_INFO;
34
35void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
36{
37 static int print_prefix=1;
38 static int count;
39 static char line[1024], prev[1024];
40 AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
41 if(level>av_log_level)
42 return;
43#undef fprintf
44 if(print_prefix && avc) {
45 snprintf(line, sizeof(line), "[%s @ %p]", avc->item_name(ptr), ptr);
46 }else
47 line[0]=0;
48
49 vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);
50
51 print_prefix= line[strlen(line)-1] == '\n';
52 if(print_prefix && !strcmp(line, prev)){
53 count++;
54 return;
55 }
56 if(count>0){
57 fprintf(stderr, " Last message repeated %d times\n", count);
58 count=0;
59 }
60 fputs(line, stderr);
61 strcpy(prev, line);
62}
63
64static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
65
66void av_log(void* avcl, int level, const char *fmt, ...)
67{
68 va_list vl;
69 va_start(vl, fmt);
70 av_vlog(avcl, level, fmt, vl);
71 va_end(vl);
72}
73
74void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
75{
76 av_log_callback(avcl, level, fmt, vl);
77}
78
79int av_log_get_level(void)
80{
81 return av_log_level;
82}
83
84void av_log_set_level(int level)
85{
86 av_log_level = level;
87}
88
89void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
90{
91 av_log_callback = callback;
92}
diff --git a/apps/codecs/libwmapro/libavutil/log.h b/apps/codecs/libwmapro/libavutil/log.h
new file mode 100644
index 0000000000..b0a1493607
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/log.h
@@ -0,0 +1,115 @@
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 {
33 /**
34 * The name of the class; usually it is the same name as the
35 * context structure type to which the AVClass is associated.
36 */
37 const char* class_name;
38
39 /**
40 * A pointer to a function which returns the name of a context
41 * instance ctx associated with the class.
42 */
43 const char* (*item_name)(void* ctx);
44
45 /**
46 * a pointer to the first option specified in the class if any or NULL
47 *
48 * @see av_set_default_options()
49 */
50 const struct AVOption *option;
51} AVClass;
52
53/* av_log API */
54
55#define AV_LOG_QUIET -8
56
57/**
58 * Something went really wrong and we will crash now.
59 */
60#define AV_LOG_PANIC 0
61
62/**
63 * Something went wrong and recovery is not possible.
64 * For example, no header was found for a format which depends
65 * on headers or an illegal combination of parameters is used.
66 */
67#define AV_LOG_FATAL 8
68
69/**
70 * Something went wrong and cannot losslessly be recovered.
71 * However, not all future data is affected.
72 */
73#define AV_LOG_ERROR 16
74
75/**
76 * Something somehow does not look correct. This may or may not
77 * lead to problems. An example would be the use of '-vstrict -2'.
78 */
79#define AV_LOG_WARNING 24
80
81#define AV_LOG_INFO 32
82#define AV_LOG_VERBOSE 40
83
84/**
85 * Stuff which is only useful for libav* developers.
86 */
87#define AV_LOG_DEBUG 48
88
89/**
90 * Sends the specified message to the log if the level is less than or equal
91 * to the current av_log_level. By default, all logging messages are sent to
92 * stderr. This behavior can be altered by setting a different av_vlog callback
93 * function.
94 *
95 * @param avcl A pointer to an arbitrary struct of which the first field is a
96 * pointer to an AVClass struct.
97 * @param level The importance level of the message, lower values signifying
98 * higher importance.
99 * @param fmt The format string (printf-compatible) that specifies how
100 * subsequent arguments are converted to output.
101 * @see av_vlog
102 */
103#ifdef __GNUC__
104void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
105#else
106void av_log(void*, int level, const char *fmt, ...);
107#endif
108
109void av_vlog(void*, int level, const char *fmt, va_list);
110int av_log_get_level(void);
111void av_log_set_level(int);
112void av_log_set_callback(void (*)(void*, int, const char*, va_list));
113void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl);
114
115#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..81d47c1bf1
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/mathematics.c
@@ -0,0 +1,174 @@
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
133int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
134 int64_t b= bq.num * (int64_t)cq.den;
135 int64_t c= cq.num * (int64_t)bq.den;
136 return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
137}
138
139int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){
140 int64_t a= tb_a.num * (int64_t)tb_b.den;
141 int64_t b= tb_b.num * (int64_t)tb_a.den;
142 if (av_rescale_rnd(ts_a, a, b, AV_ROUND_DOWN) < ts_b) return -1;
143 if (av_rescale_rnd(ts_b, b, a, AV_ROUND_DOWN) < ts_a) return 1;
144 return 0;
145}
146
147#ifdef TEST
148#include "integer.h"
149#undef printf
150int main(void){
151 int64_t a,b,c,d,e;
152
153 for(a=7; a<(1LL<<62); a+=a/3+1){
154 for(b=3; b<(1LL<<62); b+=b/4+1){
155 for(c=9; c<(1LL<<62); c+=(c*2)/5+3){
156 int64_t r= c/2;
157 AVInteger ai;
158 ai= av_mul_i(av_int2i(a), av_int2i(b));
159 ai= av_add_i(ai, av_int2i(r));
160
161 d= av_i2int(av_div_i(ai, av_int2i(c)));
162
163 e= av_rescale(a,b,c);
164
165 if((double)a * (double)b / (double)c > (1LL<<63))
166 continue;
167
168 if(d!=e) printf("%"PRId64"*%"PRId64"/%"PRId64"= %"PRId64"=%"PRId64"\n", a, b, c, d, e);
169 }
170 }
171 }
172 return 0;
173}
174#endif
diff --git a/apps/codecs/libwmapro/libavutil/mathematics.h b/apps/codecs/libwmapro/libavutil/mathematics.h
new file mode 100644
index 0000000000..e198aef8cb
--- /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 */
87int64_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 */
95int 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..4d776d4450
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/mem.c
@@ -0,0 +1,176 @@
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 "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 "avutil.h"
37#include "mem.h"
38
39/* here we can use OS-dependent allocation functions */
40#undef free
41#undef malloc
42#undef realloc
43
44#ifdef MALLOC_PREFIX
45
46#define malloc AV_JOIN(MALLOC_PREFIX, malloc)
47#define memalign AV_JOIN(MALLOC_PREFIX, memalign)
48#define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign)
49#define realloc AV_JOIN(MALLOC_PREFIX, realloc)
50#define free AV_JOIN(MALLOC_PREFIX, free)
51
52void *malloc(size_t size);
53void *memalign(size_t align, size_t size);
54int posix_memalign(void **ptr, size_t align, size_t size);
55void *realloc(void *ptr, size_t size);
56void free(void *ptr);
57
58#endif /* MALLOC_PREFIX */
59
60/* You can redefine av_malloc and av_free in your project to use your
61 memory allocator. You do not need to suppress this file because the
62 linker will do it automatically. */
63
64void *av_malloc(unsigned int size)
65{
66 void *ptr = NULL;
67#if CONFIG_MEMALIGN_HACK
68 long diff;
69#endif
70
71 /* let's disallow possible ambiguous cases */
72 if(size > (INT_MAX-16) )
73 return NULL;
74
75#if CONFIG_MEMALIGN_HACK
76 ptr = malloc(size+16);
77 if(!ptr)
78 return ptr;
79 diff= ((-(long)ptr - 1)&15) + 1;
80 ptr = (char*)ptr + diff;
81 ((char*)ptr)[-1]= diff;
82#elif HAVE_POSIX_MEMALIGN
83 if (posix_memalign(&ptr,16,size))
84 ptr = NULL;
85#elif HAVE_MEMALIGN
86 ptr = memalign(16,size);
87 /* Why 64?
88 Indeed, we should align it:
89 on 4 for 386
90 on 16 for 486
91 on 32 for 586, PPro - K6-III
92 on 64 for K7 (maybe for P3 too).
93 Because L1 and L2 caches are aligned on those values.
94 But I don't want to code such logic here!
95 */
96 /* Why 16?
97 Because some CPUs need alignment, for example SSE2 on P4, & most RISC CPUs
98 it will just trigger an exception and the unaligned load will be done in the
99 exception handler or it will just segfault (SSE2 on P4).
100 Why not larger? Because I did not see a difference in benchmarks ...
101 */
102 /* benchmarks with P3
103 memalign(64)+1 3071,3051,3032
104 memalign(64)+2 3051,3032,3041
105 memalign(64)+4 2911,2896,2915
106 memalign(64)+8 2545,2554,2550
107 memalign(64)+16 2543,2572,2563
108 memalign(64)+32 2546,2545,2571
109 memalign(64)+64 2570,2533,2558
110
111 BTW, malloc seems to do 8-byte alignment by default here.
112 */
113#else
114 ptr = malloc(size);
115#endif
116 return ptr;
117}
118
119void *av_realloc(void *ptr, unsigned int size)
120{
121#if CONFIG_MEMALIGN_HACK
122 int diff;
123#endif
124
125 /* let's disallow possible ambiguous cases */
126 if(size > (INT_MAX-16) )
127 return NULL;
128
129#if CONFIG_MEMALIGN_HACK
130 //FIXME this isn't aligned correctly, though it probably isn't needed
131 if(!ptr) return av_malloc(size);
132 diff= ((char*)ptr)[-1];
133 return (char*)realloc((char*)ptr - diff, size + diff) + diff;
134#else
135 return realloc(ptr, size);
136#endif
137}
138
139void av_free(void *ptr)
140{
141 /* XXX: this test should not be needed on most libcs */
142 if (ptr)
143#if CONFIG_MEMALIGN_HACK
144 free((char*)ptr - ((char*)ptr)[-1]);
145#else
146 free(ptr);
147#endif
148}
149
150void av_freep(void *arg)
151{
152 void **ptr= (void**)arg;
153 av_free(*ptr);
154 *ptr = NULL;
155}
156
157void *av_mallocz(unsigned int size)
158{
159 void *ptr = av_malloc(size);
160 if (ptr)
161 memset(ptr, 0, size);
162 return ptr;
163}
164
165char *av_strdup(const char *s)
166{
167 char *ptr= NULL;
168 if(s){
169 int len = strlen(s) + 1;
170 ptr = av_malloc(len);
171 if (ptr)
172 memcpy(ptr, s, len);
173 }
174 return ptr;
175}
176
diff --git a/apps/codecs/libwmapro/libavutil/mem.h b/apps/codecs/libwmapro/libavutil/mem.h
new file mode 100644
index 0000000000..fffbb872ae
--- /dev/null
+++ b/apps/codecs/libwmapro/libavutil/mem.h
@@ -0,0 +1,125 @@
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 "attributes.h"
30
31#if defined(__ICC) || defined(__SUNPRO_C)
32 #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
33 #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
34#elif defined(__TI_COMPILER_VERSION__)
35 #define DECLARE_ALIGNED(n,t,v) \
36 AV_PRAGMA(DATA_ALIGN(v,n)) \
37 t __attribute__((aligned(n))) v
38 #define DECLARE_ASM_CONST(n,t,v) \
39 AV_PRAGMA(DATA_ALIGN(v,n)) \
40 static const t __attribute__((aligned(n))) v
41#elif defined(__GNUC__)
42 #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
43 #define DECLARE_ASM_CONST(n,t,v) static const t attribute_used __attribute__ ((aligned (n))) v
44#elif defined(_MSC_VER)
45 #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
46 #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
47#else
48 #define DECLARE_ALIGNED(n,t,v) t v
49 #define DECLARE_ASM_CONST(n,t,v) static const t v
50#endif
51
52#if AV_GCC_VERSION_AT_LEAST(3,1)
53 #define av_malloc_attrib __attribute__((__malloc__))
54#else
55 #define av_malloc_attrib
56#endif
57
58#if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,3)
59 #define av_alloc_size(n) __attribute__((alloc_size(n)))
60#else
61 #define av_alloc_size(n)
62#endif
63
64/**
65 * Allocates a block of size bytes with alignment suitable for all
66 * memory accesses (including vectors if available on the CPU).
67 * @param size Size in bytes for the memory block to be allocated.
68 * @return Pointer to the allocated block, NULL if the block cannot
69 * be allocated.
70 * @see av_mallocz()
71 */
72void *av_malloc(unsigned int size) av_malloc_attrib av_alloc_size(1);
73
74/**
75 * Allocates or reallocates a block of memory.
76 * If ptr is NULL and size > 0, allocates a new block. If
77 * size is zero, frees the memory block pointed to by ptr.
78 * @param size Size in bytes for the memory block to be allocated or
79 * reallocated.
80 * @param ptr Pointer to a memory block already allocated with
81 * av_malloc(z)() or av_realloc() or NULL.
82 * @return Pointer to a newly reallocated block or NULL if the block
83 * cannot be reallocated or the function is used to free the memory block.
84 * @see av_fast_realloc()
85 */
86void *av_realloc(void *ptr, unsigned int size) av_alloc_size(2);
87
88/**
89 * Frees a memory block which has been allocated with av_malloc(z)() or
90 * av_realloc().
91 * @param ptr Pointer to the memory block which should be freed.
92 * @note ptr = NULL is explicitly allowed.
93 * @note It is recommended that you use av_freep() instead.
94 * @see av_freep()
95 */
96void av_free(void *ptr);
97
98/**
99 * Allocates a block of size bytes with alignment suitable for all
100 * memory accesses (including vectors if available on the CPU) and
101 * zeroes all the bytes of the block.
102 * @param size Size in bytes for the memory block to be allocated.
103 * @return Pointer to the allocated block, NULL if it cannot be allocated.
104 * @see av_malloc()
105 */
106void *av_mallocz(unsigned int size) av_malloc_attrib av_alloc_size(1);
107
108/**
109 * Duplicates the string s.
110 * @param s string to be duplicated
111 * @return Pointer to a newly allocated string containing a
112 * copy of s or NULL if the string cannot be allocated.
113 */
114char *av_strdup(const char *s) av_malloc_attrib;
115
116/**
117 * Frees a memory block which has been allocated with av_malloc(z)() or
118 * av_realloc() and set the pointer pointing to it to NULL.
119 * @param ptr Pointer to the pointer to the memory block which should
120 * be freed.
121 * @see av_free()
122 */
123void av_freep(void *ptr);
124
125#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..1722c3b4d0
--- /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..65780459aa
--- /dev/null
+++ b/apps/codecs/libwmapro/wma.c
@@ -0,0 +1,523 @@
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
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
69/**
70 *@brief Get the samples per frame for this stream.
71 *@param sample_rate output sample_rate
72 *@param version wma version
73 *@param decode_flags codec compression features
74 *@return log2 of the number of output samples per frame
75 */
76int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version,
77 unsigned int decode_flags)
78{
79
80 int frame_len_bits;
81
82 if (sample_rate <= 16000) {
83 frame_len_bits = 9;
84 } else if (sample_rate <= 22050 ||
85 (sample_rate <= 32000 && version == 1)) {
86 frame_len_bits = 10;
87 } else if (sample_rate <= 48000) {
88 frame_len_bits = 11;
89 } else if (sample_rate <= 96000) {
90 frame_len_bits = 12;
91 } else {
92 frame_len_bits = 13;
93 }
94
95 if (version == 3) {
96 int tmp = decode_flags & 0x6;
97 if (tmp == 0x2) {
98 ++frame_len_bits;
99 } else if (tmp == 0x4) {
100 --frame_len_bits;
101 } else if (tmp == 0x6) {
102 frame_len_bits -= 2;
103 }
104 }
105
106 return frame_len_bits;
107}
108
109int ff_wma_init(AVCodecContext *avctx, int flags2)
110{
111 WMACodecContext *s = avctx->priv_data;
112 int i;
113 float bps1, high_freq;
114 volatile float bps;
115 int sample_rate1;
116 int coef_vlc_table;
117
118 if ( avctx->sample_rate <= 0 || avctx->sample_rate > 50000
119 || avctx->channels <= 0 || avctx->channels > 8
120 || avctx->bit_rate <= 0)
121 return -1;
122
123 s->sample_rate = avctx->sample_rate;
124 s->nb_channels = avctx->channels;
125 s->bit_rate = avctx->bit_rate;
126 s->block_align = avctx->block_align;
127
128 dsputil_init(&s->dsp, avctx);
129
130 if (avctx->codec->id == CODEC_ID_WMAV1) {
131 s->version = 1;
132 } else {
133 s->version = 2;
134 }
135
136 /* compute MDCT block size */
137 s->frame_len_bits = ff_wma_get_frame_len_bits(s->sample_rate, s->version, 0);
138
139 s->frame_len = 1 << s->frame_len_bits;
140 if (s->use_variable_block_len) {
141 int nb_max, nb;
142 nb = ((flags2 >> 3) & 3) + 1;
143 if ((s->bit_rate / s->nb_channels) >= 32000)
144 nb += 2;
145 nb_max = s->frame_len_bits - BLOCK_MIN_BITS;
146 if (nb > nb_max)
147 nb = nb_max;
148 s->nb_block_sizes = nb + 1;
149 } else {
150 s->nb_block_sizes = 1;
151 }
152
153 /* init rate dependent parameters */
154 s->use_noise_coding = 1;
155 high_freq = s->sample_rate * 0.5;
156
157 /* if version 2, then the rates are normalized */
158 sample_rate1 = s->sample_rate;
159 if (s->version == 2) {
160 if (sample_rate1 >= 44100) {
161 sample_rate1 = 44100;
162 } else if (sample_rate1 >= 22050) {
163 sample_rate1 = 22050;
164 } else if (sample_rate1 >= 16000) {
165 sample_rate1 = 16000;
166 } else if (sample_rate1 >= 11025) {
167 sample_rate1 = 11025;
168 } else if (sample_rate1 >= 8000) {
169 sample_rate1 = 8000;
170 }
171 }
172
173 bps = (float)s->bit_rate / (float)(s->nb_channels * s->sample_rate);
174 s->byte_offset_bits = av_log2((int)(bps * s->frame_len / 8.0 + 0.5)) + 2;
175
176 /* compute high frequency value and choose if noise coding should
177 be activated */
178 bps1 = bps;
179 if (s->nb_channels == 2)
180 bps1 = bps * 1.6;
181 if (sample_rate1 == 44100) {
182 if (bps1 >= 0.61) {
183 s->use_noise_coding = 0;
184 } else {
185 high_freq = high_freq * 0.4;
186 }
187 } else if (sample_rate1 == 22050) {
188 if (bps1 >= 1.16) {
189 s->use_noise_coding = 0;
190 } else if (bps1 >= 0.72) {
191 high_freq = high_freq * 0.7;
192 } else {
193 high_freq = high_freq * 0.6;
194 }
195 } else if (sample_rate1 == 16000) {
196 if (bps > 0.5) {
197 high_freq = high_freq * 0.5;
198 } else {
199 high_freq = high_freq * 0.3;
200 }
201 } else if (sample_rate1 == 11025) {
202 high_freq = high_freq * 0.7;
203 } else if (sample_rate1 == 8000) {
204 if (bps <= 0.625) {
205 high_freq = high_freq * 0.5;
206 } else if (bps > 0.75) {
207 s->use_noise_coding = 0;
208 } else {
209 high_freq = high_freq * 0.65;
210 }
211 } else {
212 if (bps >= 0.8) {
213 high_freq = high_freq * 0.75;
214 } else if (bps >= 0.6) {
215 high_freq = high_freq * 0.6;
216 } else {
217 high_freq = high_freq * 0.5;
218 }
219 }
220 dprintf(s->avctx, "flags2=0x%x\n", flags2);
221 dprintf(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n",
222 s->version, s->nb_channels, s->sample_rate, s->bit_rate,
223 s->block_align);
224 dprintf(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
225 bps, bps1, high_freq, s->byte_offset_bits);
226 dprintf(s->avctx, "use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n",
227 s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes);
228
229 /* compute the scale factor band sizes for each MDCT block size */
230 {
231 int a, b, pos, lpos, k, block_len, i, j, n;
232 const uint8_t *table;
233
234 if (s->version == 1) {
235 s->coefs_start = 3;
236 } else {
237 s->coefs_start = 0;
238 }
239 for (k = 0; k < s->nb_block_sizes; k++) {
240 block_len = s->frame_len >> k;
241
242 if (s->version == 1) {
243 lpos = 0;
244 for (i = 0; i < 25; i++) {
245 a = ff_wma_critical_freqs[i];
246 b = s->sample_rate;
247 pos = ((block_len * 2 * a) + (b >> 1)) / b;
248 if (pos > block_len)
249 pos = block_len;
250 s->exponent_bands[0][i] = pos - lpos;
251 if (pos >= block_len) {
252 i++;
253 break;
254 }
255 lpos = pos;
256 }
257 s->exponent_sizes[0] = i;
258 } else {
259 /* hardcoded tables */
260 table = NULL;
261 a = s->frame_len_bits - BLOCK_MIN_BITS - k;
262 if (a < 3) {
263 if (s->sample_rate >= 44100) {
264 table = exponent_band_44100[a];
265 } else if (s->sample_rate >= 32000) {
266 table = exponent_band_32000[a];
267 } else if (s->sample_rate >= 22050) {
268 table = exponent_band_22050[a];
269 }
270 }
271 if (table) {
272 n = *table++;
273 for (i = 0; i < n; i++)
274 s->exponent_bands[k][i] = table[i];
275 s->exponent_sizes[k] = n;
276 } else {
277 j = 0;
278 lpos = 0;
279 for (i = 0; i < 25; i++) {
280 a = ff_wma_critical_freqs[i];
281 b = s->sample_rate;
282 pos = ((block_len * 2 * a) + (b << 1)) / (4 * b);
283 pos <<= 2;
284 if (pos > block_len)
285 pos = block_len;
286 if (pos > lpos)
287 s->exponent_bands[k][j++] = pos - lpos;
288 if (pos >= block_len)
289 break;
290 lpos = pos;
291 }
292 s->exponent_sizes[k] = j;
293 }
294 }
295
296 /* max number of coefs */
297 s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k;
298 /* high freq computation */
299 s->high_band_start[k] = (int)((block_len * 2 * high_freq) /
300 s->sample_rate + 0.5);
301 n = s->exponent_sizes[k];
302 j = 0;
303 pos = 0;
304 for (i = 0; i < n; i++) {
305 int start, end;
306 start = pos;
307 pos += s->exponent_bands[k][i];
308 end = pos;
309 if (start < s->high_band_start[k])
310 start = s->high_band_start[k];
311 if (end > s->coefs_end[k])
312 end = s->coefs_end[k];
313 if (end > start)
314 s->exponent_high_bands[k][j++] = end - start;
315 }
316 s->exponent_high_sizes[k] = j;
317#if 0
318 tprintf(s->avctx, "%5d: coefs_end=%d high_band_start=%d nb_high_bands=%d: ",
319 s->frame_len >> k,
320 s->coefs_end[k],
321 s->high_band_start[k],
322 s->exponent_high_sizes[k]);
323 for (j = 0; j < s->exponent_high_sizes[k]; j++)
324 tprintf(s->avctx, " %d", s->exponent_high_bands[k][j]);
325 tprintf(s->avctx, "\n");
326#endif
327 }
328 }
329
330#ifdef TRACE
331 {
332 int i, j;
333 for (i = 0; i < s->nb_block_sizes; i++) {
334 tprintf(s->avctx, "%5d: n=%2d:",
335 s->frame_len >> i,
336 s->exponent_sizes[i]);
337 for (j = 0; j < s->exponent_sizes[i]; j++)
338 tprintf(s->avctx, " %d", s->exponent_bands[i][j]);
339 tprintf(s->avctx, "\n");
340 }
341 }
342#endif
343
344 /* init MDCT windows : simple sinus window */
345 for (i = 0; i < s->nb_block_sizes; i++) {
346 ff_init_ff_sine_windows(s->frame_len_bits - i);
347 s->windows[i] = ff_sine_windows[s->frame_len_bits - i];
348 }
349
350 s->reset_block_lengths = 1;
351
352 if (s->use_noise_coding) {
353
354 /* init the noise generator */
355 if (s->use_exp_vlc) {
356 s->noise_mult = 0.02;
357 } else {
358 s->noise_mult = 0.04;
359 }
360
361#ifdef TRACE
362 for (i = 0; i < NOISE_TAB_SIZE; i++)
363 s->noise_table[i] = 1.0 * s->noise_mult;
364#else
365 {
366 unsigned int seed;
367 float norm;
368 seed = 1;
369 norm = (1.0 / (float)(1LL << 31)) * sqrt(3) * s->noise_mult;
370 for (i = 0; i < NOISE_TAB_SIZE; i++) {
371 seed = seed * 314159 + 1;
372 s->noise_table[i] = (float)((int)seed) * norm;
373 }
374 }
375#endif
376 }
377
378 /* choose the VLC tables for the coefficients */
379 coef_vlc_table = 2;
380 if (s->sample_rate >= 32000) {
381 if (bps1 < 0.72) {
382 coef_vlc_table = 0;
383 } else if (bps1 < 1.16) {
384 coef_vlc_table = 1;
385 }
386 }
387 s->coef_vlcs[0]= &coef_vlcs[coef_vlc_table * 2 ];
388 s->coef_vlcs[1]= &coef_vlcs[coef_vlc_table * 2 + 1];
389 init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0], &s->int_table[0],
390 s->coef_vlcs[0]);
391 init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1], &s->int_table[1],
392 s->coef_vlcs[1]);
393
394 return 0;
395}
396
397int ff_wma_total_gain_to_bits(int total_gain)
398{
399 if (total_gain < 15) return 13;
400 else if (total_gain < 32) return 12;
401 else if (total_gain < 40) return 11;
402 else if (total_gain < 45) return 10;
403 else return 9;
404}
405
406int ff_wma_end(AVCodecContext *avctx)
407{
408 WMACodecContext *s = avctx->priv_data;
409 int i;
410
411 for (i = 0; i < s->nb_block_sizes; i++)
412 ff_mdct_end(&s->mdct_ctx[i]);
413
414 if (s->use_exp_vlc) {
415 free_vlc(&s->exp_vlc);
416 }
417 if (s->use_noise_coding) {
418 free_vlc(&s->hgain_vlc);
419 }
420 for (i = 0; i < 2; i++) {
421 free_vlc(&s->coef_vlc[i]);
422 av_free(s->run_table[i]);
423 av_free(s->level_table[i]);
424 av_free(s->int_table[i]);
425 }
426
427 return 0;
428}
429
430/**
431 * Decode an uncompressed coefficient.
432 * @param s codec context
433 * @return the decoded coefficient
434 */
435unsigned int ff_wma_get_large_val(GetBitContext* gb)
436{
437 /** consumes up to 34 bits */
438 int n_bits = 8;
439 /** decode length */
440 if (get_bits1(gb)) {
441 n_bits += 8;
442 if (get_bits1(gb)) {
443 n_bits += 8;
444 if (get_bits1(gb)) {
445 n_bits += 7;
446 }
447 }
448 }
449 return get_bits_long(gb, n_bits);
450}
451
452/**
453 * Decode run level compressed coefficients.
454 * @param avctx codec context
455 * @param gb bitstream reader context
456 * @param vlc vlc table for get_vlc2
457 * @param level_table level codes
458 * @param run_table run codes
459 * @param version 0 for wma1,2 1 for wmapro
460 * @param ptr output buffer
461 * @param offset offset in the output buffer
462 * @param num_coefs number of input coefficents
463 * @param block_len input buffer length (2^n)
464 * @param frame_len_bits number of bits for escaped run codes
465 * @param coef_nb_bits number of bits for escaped level codes
466 * @return 0 on success, -1 otherwise
467 */
468int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
469 VLC *vlc,
470 const float *level_table, const uint16_t *run_table,
471 int version, WMACoef *ptr, int offset,
472 int num_coefs, int block_len, int frame_len_bits,
473 int coef_nb_bits)
474{
475 int code, level, sign;
476 const uint32_t *ilvl = (const uint32_t*)level_table;
477 uint32_t *iptr = (uint32_t*)ptr;
478 const unsigned int coef_mask = block_len - 1;
479 for (; offset < num_coefs; offset++) {
480 code = get_vlc2(gb, vlc->table, VLCBITS, VLCMAX);
481 if (code > 1) {
482 /** normal code */
483 offset += run_table[code];
484 sign = get_bits1(gb) - 1;
485 iptr[offset & coef_mask] = ilvl[code] ^ sign<<31;
486 } else if (code == 1) {
487 /** EOB */
488 break;
489 } else {
490 /** escape */
491 if (!version) {
492 level = get_bits(gb, coef_nb_bits);
493 /** NOTE: this is rather suboptimal. reading
494 block_len_bits would be better */
495 offset += get_bits(gb, frame_len_bits);
496 } else {
497 level = ff_wma_get_large_val(gb);
498 /** escape decode */
499 if (get_bits1(gb)) {
500 if (get_bits1(gb)) {
501 if (get_bits1(gb)) {
502 av_log(avctx,AV_LOG_ERROR,
503 "broken escape sequence\n");
504 return -1;
505 } else
506 offset += get_bits(gb, frame_len_bits) + 4;
507 } else
508 offset += get_bits(gb, 2) + 1;
509 }
510 }
511 sign = get_bits1(gb) - 1;
512 ptr[offset & coef_mask] = (level^sign) - sign;
513 }
514 }
515 /** NOTE: EOB can be omitted */
516 if (offset > num_coefs) {
517 av_log(avctx, AV_LOG_ERROR, "overflow in spectral RLE, ignoring\n");
518 return -1;
519 }
520
521 return 0;
522}
523
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..82f1b3623b
--- /dev/null
+++ b/apps/codecs/libwmapro/wmaprodec.c
@@ -0,0 +1,1578 @@
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/** current decoder limitations */
98#define WMAPRO_MAX_CHANNELS 8 ///< max number of handled channels
99#define MAX_SUBFRAMES 32 ///< max number of subframes per channel
100#define MAX_BANDS 29 ///< max number of scale factor bands
101#define MAX_FRAMESIZE 32768 ///< maximum compressed frame size
102
103#define WMAPRO_BLOCK_MAX_BITS 12 ///< log2 of max block size
104#define WMAPRO_BLOCK_MAX_SIZE (1 << WMAPRO_BLOCK_MAX_BITS) ///< maximum block size
105#define WMAPRO_BLOCK_SIZES (WMAPRO_BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1) ///< possible block sizes
106
107
108#define VLCBITS 9
109#define SCALEVLCBITS 8
110#define VEC4MAXDEPTH ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS)
111#define VEC2MAXDEPTH ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS)
112#define VEC1MAXDEPTH ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS)
113#define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)
114#define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS)
115
116static VLC sf_vlc; ///< scale factor DPCM vlc
117static VLC sf_rl_vlc; ///< scale factor run length vlc
118static VLC vec4_vlc; ///< 4 coefficients per symbol
119static VLC vec2_vlc; ///< 2 coefficients per symbol
120static VLC vec1_vlc; ///< 1 coefficient per symbol
121static VLC coef_vlc[2]; ///< coefficient run length vlc codes
122static float sin64[33]; ///< sinus table for decorrelation
123
124/**
125 * @brief frame specific decoder context for a single channel
126 */
127typedef struct {
128 int16_t prev_block_len; ///< length of the previous block
129 uint8_t transmit_coefs;
130 uint8_t num_subframes;
131 uint16_t subframe_len[MAX_SUBFRAMES]; ///< subframe length in samples
132 uint16_t subframe_offset[MAX_SUBFRAMES]; ///< subframe positions in the current frame
133 uint8_t cur_subframe; ///< current subframe number
134 uint16_t decoded_samples; ///< number of already processed samples
135 uint8_t grouped; ///< channel is part of a group
136 int quant_step; ///< quantization step for the current subframe
137 int8_t reuse_sf; ///< share scale factors between subframes
138 int8_t scale_factor_step; ///< scaling step for the current subframe
139 int max_scale_factor; ///< maximum scale factor for the current subframe
140 int saved_scale_factors[2][MAX_BANDS]; ///< resampled and (previously) transmitted scale factor values
141 int8_t scale_factor_idx; ///< index for the transmitted scale factor values (used for resampling)
142 int* scale_factors; ///< pointer to the scale factor values used for decoding
143 uint8_t table_idx; ///< index in sf_offsets for the scale factor reference block
144 float* coeffs; ///< pointer to the subframe decode buffer
145 DECLARE_ALIGNED(16, float, out)[WMAPRO_BLOCK_MAX_SIZE + WMAPRO_BLOCK_MAX_SIZE / 2]; ///< output buffer
146} WMAProChannelCtx;
147
148/**
149 * @brief channel group for channel transformations
150 */
151typedef struct {
152 uint8_t num_channels; ///< number of channels in the group
153 int8_t transform; ///< transform on / off
154 int8_t transform_band[MAX_BANDS]; ///< controls if the transform is enabled for a certain band
155 float decorrelation_matrix[WMAPRO_MAX_CHANNELS*WMAPRO_MAX_CHANNELS];
156 float* channel_data[WMAPRO_MAX_CHANNELS]; ///< transformation coefficients
157} WMAProChannelGrp;
158
159/**
160 * @brief main decoder context
161 */
162typedef struct WMAProDecodeCtx {
163 /* generic decoder variables */
164 AVCodecContext* avctx; ///< codec context for av_log
165 DSPContext dsp; ///< accelerated DSP functions
166 uint8_t frame_data[MAX_FRAMESIZE +
167 FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data
168 PutBitContext pb; ///< context for filling the frame_data buffer
169 FFTContext mdct_ctx[WMAPRO_BLOCK_SIZES]; ///< MDCT context per block size
170 DECLARE_ALIGNED(16, float, tmp)[WMAPRO_BLOCK_MAX_SIZE]; ///< IMDCT output buffer
171 float* windows[WMAPRO_BLOCK_SIZES]; ///< windows for the different block sizes
172
173 /* frame size dependent frame information (set during initialization) */
174 uint32_t decode_flags; ///< used compression features
175 uint8_t len_prefix; ///< frame is prefixed with its length
176 uint8_t dynamic_range_compression; ///< frame contains DRC data
177 uint8_t bits_per_sample; ///< integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1.0])
178 uint16_t samples_per_frame; ///< number of samples to output
179 uint16_t log2_frame_size;
180 int8_t num_channels; ///< number of channels in the stream (same as AVCodecContext.num_channels)
181 int8_t lfe_channel; ///< lfe channel index
182 uint8_t max_num_subframes;
183 uint8_t subframe_len_bits; ///< number of bits used for the subframe length
184 uint8_t max_subframe_len_bit; ///< flag indicating that the subframe is of maximum size when the first subframe length bit is 1
185 uint16_t min_samples_per_subframe;
186 int8_t num_sfb[WMAPRO_BLOCK_SIZES]; ///< scale factor bands per block size
187 int16_t sfb_offsets[WMAPRO_BLOCK_SIZES][MAX_BANDS]; ///< scale factor band offsets (multiples of 4)
188 int8_t sf_offsets[WMAPRO_BLOCK_SIZES][WMAPRO_BLOCK_SIZES][MAX_BANDS]; ///< scale factor resample matrix
189 int16_t subwoofer_cutoffs[WMAPRO_BLOCK_SIZES]; ///< subwoofer cutoff values
190
191 /* packet decode state */
192 GetBitContext pgb; ///< bitstream reader context for the packet
193 uint8_t packet_offset; ///< frame offset in the packet
194 uint8_t packet_sequence_number; ///< current packet number
195 int num_saved_bits; ///< saved number of bits
196 int frame_offset; ///< frame offset in the bit reservoir
197 int subframe_offset; ///< subframe offset in the bit reservoir
198 uint8_t packet_loss; ///< set in case of bitstream error
199 uint8_t packet_done; ///< set when a packet is fully decoded
200
201 /* frame decode state */
202 uint32_t frame_num; ///< current frame number (not used for decoding)
203 GetBitContext gb; ///< bitstream reader context
204 int buf_bit_size; ///< buffer size in bits
205 float* samples; ///< current samplebuffer pointer
206 float* samples_end; ///< maximum samplebuffer pointer
207 uint8_t drc_gain; ///< gain for the DRC tool
208 int8_t skip_frame; ///< skip output step
209 int8_t parsed_all_subframes; ///< all subframes decoded?
210
211 /* subframe/block decode state */
212 int16_t subframe_len; ///< current subframe length
213 int8_t channels_for_cur_subframe; ///< number of channels that contain the subframe
214 int8_t channel_indexes_for_cur_subframe[WMAPRO_MAX_CHANNELS];
215 int8_t num_bands; ///< number of scale factor bands
216 int16_t* cur_sfb_offsets; ///< sfb offsets for the current block
217 uint8_t table_idx; ///< index for the num_sfb, sfb_offsets, sf_offsets and subwoofer_cutoffs tables
218 int8_t esc_len; ///< length of escaped coefficients
219
220 uint8_t num_chgroups; ///< number of channel groups
221 WMAProChannelGrp chgroup[WMAPRO_MAX_CHANNELS]; ///< channel group information
222
223 WMAProChannelCtx channel[WMAPRO_MAX_CHANNELS]; ///< per channel data
224} WMAProDecodeCtx;
225
226
227/**
228 *@brief helper function to print the most important members of the context
229 *@param s context
230 */
231static void av_cold dump_context(WMAProDecodeCtx *s)
232{
233#define PRINT(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b);
234#define PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %x\n", a, b);
235
236 PRINT("ed sample bit depth", s->bits_per_sample);
237 PRINT_HEX("ed decode flags", s->decode_flags);
238 PRINT("samples per frame", s->samples_per_frame);
239 PRINT("log2 frame size", s->log2_frame_size);
240 PRINT("max num subframes", s->max_num_subframes);
241 PRINT("len prefix", s->len_prefix);
242 PRINT("num channels", s->num_channels);
243}
244
245/**
246 *@brief Uninitialize the decoder and free all resources.
247 *@param avctx codec context
248 *@return 0 on success, < 0 otherwise
249 */
250static av_cold int decode_end(AVCodecContext *avctx)
251{
252 WMAProDecodeCtx *s = avctx->priv_data;
253 int i;
254
255 for (i = 0; i < WMAPRO_BLOCK_SIZES; i++)
256 ff_mdct_end(&s->mdct_ctx[i]);
257
258 return 0;
259}
260
261/**
262 *@brief Initialize the decoder.
263 *@param avctx codec context
264 *@return 0 on success, -1 otherwise
265 */
266static av_cold int decode_init(AVCodecContext *avctx)
267{
268 WMAProDecodeCtx *s = avctx->priv_data;
269 uint8_t *edata_ptr = avctx->extradata;
270 unsigned int channel_mask;
271 int i;
272 int log2_max_num_subframes;
273 int num_possible_block_sizes;
274
275 s->avctx = avctx;
276 dsputil_init(&s->dsp, avctx);
277 init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
278
279 avctx->sample_fmt = SAMPLE_FMT_FLT;
280
281 if (avctx->extradata_size >= 18) {
282 s->decode_flags = AV_RL16(edata_ptr+14);
283 channel_mask = AV_RL32(edata_ptr+2);
284 s->bits_per_sample = AV_RL16(edata_ptr);
285 /** dump the extradata */
286 for (i = 0; i < avctx->extradata_size; i++)
287 dprintf(avctx, "[%x] ", avctx->extradata[i]);
288 dprintf(avctx, "\n");
289
290 } else {
291 av_log_ask_for_sample(avctx, "Unknown extradata size\n");
292 return AVERROR_INVALIDDATA;
293 }
294
295 /** generic init */
296 s->log2_frame_size = av_log2(avctx->block_align) + 4;
297
298 /** frame info */
299 s->skip_frame = 1; /** skip first frame */
300 s->packet_loss = 1;
301 s->len_prefix = (s->decode_flags & 0x40);
302
303 if (!s->len_prefix) {
304 av_log_ask_for_sample(avctx, "no length prefix\n");
305 return AVERROR_INVALIDDATA;
306 }
307
308 /** get frame len */
309 s->samples_per_frame = 1 << ff_wma_get_frame_len_bits(avctx->sample_rate,
310 3, s->decode_flags);
311
312 /** init previous block len */
313 for (i = 0; i < avctx->channels; i++)
314 s->channel[i].prev_block_len = s->samples_per_frame;
315
316 /** subframe info */
317 log2_max_num_subframes = ((s->decode_flags & 0x38) >> 3);
318 s->max_num_subframes = 1 << log2_max_num_subframes;
319 if (s->max_num_subframes == 16)
320 s->max_subframe_len_bit = 1;
321 s->subframe_len_bits = av_log2(log2_max_num_subframes) + 1;
322
323 num_possible_block_sizes = log2_max_num_subframes + 1;
324 s->min_samples_per_subframe = s->samples_per_frame / s->max_num_subframes;
325 s->dynamic_range_compression = (s->decode_flags & 0x80);
326
327 if (s->max_num_subframes > MAX_SUBFRAMES) {
328 av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %i\n",
329 s->max_num_subframes);
330 return AVERROR_INVALIDDATA;
331 }
332
333 s->num_channels = avctx->channels;
334
335 /** extract lfe channel position */
336 s->lfe_channel = -1;
337
338 if (channel_mask & 8) {
339 unsigned int mask;
340 for (mask = 1; mask < 16; mask <<= 1) {
341 if (channel_mask & mask)
342 ++s->lfe_channel;
343 }
344 }
345
346 if (s->num_channels < 0) {
347 av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n", s->num_channels);
348 return AVERROR_INVALIDDATA;
349 } else if (s->num_channels > WMAPRO_MAX_CHANNELS) {
350 av_log_ask_for_sample(avctx, "unsupported number of channels\n");
351 return AVERROR_PATCHWELCOME;
352 }
353
354 INIT_VLC_STATIC(&sf_vlc, SCALEVLCBITS, HUFF_SCALE_SIZE,
355 scale_huffbits, 1, 1,
356 scale_huffcodes, 2, 2, 616);
357
358 INIT_VLC_STATIC(&sf_rl_vlc, VLCBITS, HUFF_SCALE_RL_SIZE,
359 scale_rl_huffbits, 1, 1,
360 scale_rl_huffcodes, 4, 4, 1406);
361
362 INIT_VLC_STATIC(&coef_vlc[0], VLCBITS, HUFF_COEF0_SIZE,
363 coef0_huffbits, 1, 1,
364 coef0_huffcodes, 4, 4, 2108);
365
366 INIT_VLC_STATIC(&coef_vlc[1], VLCBITS, HUFF_COEF1_SIZE,
367 coef1_huffbits, 1, 1,
368 coef1_huffcodes, 4, 4, 3912);
369
370 INIT_VLC_STATIC(&vec4_vlc, VLCBITS, HUFF_VEC4_SIZE,
371 vec4_huffbits, 1, 1,
372 vec4_huffcodes, 2, 2, 604);
373
374 INIT_VLC_STATIC(&vec2_vlc, VLCBITS, HUFF_VEC2_SIZE,
375 vec2_huffbits, 1, 1,
376 vec2_huffcodes, 2, 2, 562);
377
378 INIT_VLC_STATIC(&vec1_vlc, VLCBITS, HUFF_VEC1_SIZE,
379 vec1_huffbits, 1, 1,
380 vec1_huffcodes, 2, 2, 562);
381
382 /** calculate number of scale factor bands and their offsets
383 for every possible block size */
384 for (i = 0; i < num_possible_block_sizes; i++) {
385 int subframe_len = s->samples_per_frame >> i;
386 int x;
387 int band = 1;
388
389 s->sfb_offsets[i][0] = 0;
390
391 for (x = 0; x < MAX_BANDS-1 && s->sfb_offsets[i][band - 1] < subframe_len; x++) {
392 int offset = (subframe_len * 2 * critical_freq[x])
393 / s->avctx->sample_rate + 2;
394 offset &= ~3;
395 if (offset > s->sfb_offsets[i][band - 1])
396 s->sfb_offsets[i][band++] = offset;
397 }
398 s->sfb_offsets[i][band - 1] = subframe_len;
399 s->num_sfb[i] = band - 1;
400 }
401
402
403 /** Scale factors can be shared between blocks of different size
404 as every block has a different scale factor band layout.
405 The matrix sf_offsets is needed to find the correct scale factor.
406 */
407
408 for (i = 0; i < num_possible_block_sizes; i++) {
409 int b;
410 for (b = 0; b < s->num_sfb[i]; b++) {
411 int x;
412 int offset = ((s->sfb_offsets[i][b]
413 + s->sfb_offsets[i][b + 1] - 1) << i) >> 1;
414 for (x = 0; x < num_possible_block_sizes; x++) {
415 int v = 0;
416 while (s->sfb_offsets[x][v + 1] << x < offset)
417 ++v;
418 s->sf_offsets[i][x][b] = v;
419 }
420 }
421 }
422
423 /** init MDCT, FIXME: only init needed sizes */
424 for (i = 0; i < WMAPRO_BLOCK_SIZES; i++)
425 ff_mdct_init(&s->mdct_ctx[i], BLOCK_MIN_BITS+1+i, 1,
426 1.0 / (1 << (BLOCK_MIN_BITS + i - 1))
427 / (1 << (s->bits_per_sample - 1)));
428
429 /** init MDCT windows: simple sinus window */
430 for (i = 0; i < WMAPRO_BLOCK_SIZES; i++) {
431 const int win_idx = WMAPRO_BLOCK_MAX_BITS - i;
432 ff_init_ff_sine_windows(win_idx);
433 s->windows[WMAPRO_BLOCK_SIZES - i - 1] = ff_sine_windows[win_idx];
434 }
435
436 /** calculate subwoofer cutoff values */
437 for (i = 0; i < num_possible_block_sizes; i++) {
438 int block_size = s->samples_per_frame >> i;
439 int cutoff = (440*block_size + 3 * (s->avctx->sample_rate >> 1) - 1)
440 / s->avctx->sample_rate;
441 s->subwoofer_cutoffs[i] = av_clip(cutoff, 4, block_size);
442 }
443
444 /** calculate sine values for the decorrelation matrix */
445 for (i = 0; i < 33; i++)
446 sin64[i] = sin(i*M_PI / 64.0);
447
448 if (avctx->debug & FF_DEBUG_BITSTREAM)
449 dump_context(s);
450
451 avctx->channel_layout = channel_mask;
452 return 0;
453}
454
455/**
456 *@brief Decode the subframe length.
457 *@param s context
458 *@param offset sample offset in the frame
459 *@return decoded subframe length on success, < 0 in case of an error
460 */
461static int decode_subframe_length(WMAProDecodeCtx *s, int offset)
462{
463 int frame_len_shift = 0;
464 int subframe_len;
465
466 /** no need to read from the bitstream when only one length is possible */
467 if (offset == s->samples_per_frame - s->min_samples_per_subframe)
468 return s->min_samples_per_subframe;
469
470 /** 1 bit indicates if the subframe is of maximum length */
471 if (s->max_subframe_len_bit) {
472 if (get_bits1(&s->gb))
473 frame_len_shift = 1 + get_bits(&s->gb, s->subframe_len_bits-1);
474 } else
475 frame_len_shift = get_bits(&s->gb, s->subframe_len_bits);
476
477 subframe_len = s->samples_per_frame >> frame_len_shift;
478
479 /** sanity check the length */
480 if (subframe_len < s->min_samples_per_subframe ||
481 subframe_len > s->samples_per_frame) {
482 av_log(s->avctx, AV_LOG_ERROR, "broken frame: subframe_len %i\n",
483 subframe_len);
484 return AVERROR_INVALIDDATA;
485 }
486 return subframe_len;
487}
488
489/**
490 *@brief Decode how the data in the frame is split into subframes.
491 * Every WMA frame contains the encoded data for a fixed number of
492 * samples per channel. The data for every channel might be split
493 * into several subframes. This function will reconstruct the list of
494 * subframes for every channel.
495 *
496 * If the subframes are not evenly split, the algorithm estimates the
497 * channels with the lowest number of total samples.
498 * Afterwards, for each of these channels a bit is read from the
499 * bitstream that indicates if the channel contains a subframe with the
500 * next subframe size that is going to be read from the bitstream or not.
501 * If a channel contains such a subframe, the subframe size gets added to
502 * the channel's subframe list.
503 * The algorithm repeats these steps until the frame is properly divided
504 * between the individual channels.
505 *
506 *@param s context
507 *@return 0 on success, < 0 in case of an error
508 */
509static int decode_tilehdr(WMAProDecodeCtx *s)
510{
511 uint16_t num_samples[WMAPRO_MAX_CHANNELS]; /** sum of samples for all currently known subframes of a channel */
512 uint8_t contains_subframe[WMAPRO_MAX_CHANNELS]; /** flag indicating if a channel contains the current subframe */
513 int channels_for_cur_subframe = s->num_channels; /** number of channels that contain the current subframe */
514 int fixed_channel_layout = 0; /** flag indicating that all channels use the same subframe offsets and sizes */
515 int min_channel_len = 0; /** smallest sum of samples (channels with this length will be processed first) */
516 int c;
517
518 /* Should never consume more than 3073 bits (256 iterations for the
519 * while loop when always the minimum amount of 128 samples is substracted
520 * from missing samples in the 8 channel case).
521 * 1 + BLOCK_MAX_SIZE * MAX_CHANNELS / BLOCK_MIN_SIZE * (MAX_CHANNELS + 4)
522 */
523
524 /** reset tiling information */
525 for (c = 0; c < s->num_channels; c++)
526 s->channel[c].num_subframes = 0;
527
528 memset(num_samples, 0, sizeof(num_samples));
529
530 if (s->max_num_subframes == 1 || get_bits1(&s->gb))
531 fixed_channel_layout = 1;
532
533 /** loop until the frame data is split between the subframes */
534 do {
535 int subframe_len;
536
537 /** check which channels contain the subframe */
538 for (c = 0; c < s->num_channels; c++) {
539 if (num_samples[c] == min_channel_len) {
540 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
541 (min_channel_len == s->samples_per_frame - s->min_samples_per_subframe))
542 contains_subframe[c] = 1;
543 else
544 contains_subframe[c] = get_bits1(&s->gb);
545 } else
546 contains_subframe[c] = 0;
547 }
548
549 /** get subframe length, subframe_len == 0 is not allowed */
550 if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0)
551 return AVERROR_INVALIDDATA;
552
553 /** add subframes to the individual channels and find new min_channel_len */
554 min_channel_len += subframe_len;
555 for (c = 0; c < s->num_channels; c++) {
556 WMAProChannelCtx* chan = &s->channel[c];
557
558 if (contains_subframe[c]) {
559 if (chan->num_subframes >= MAX_SUBFRAMES) {
560 av_log(s->avctx, AV_LOG_ERROR,
561 "broken frame: num subframes > 31\n");
562 return AVERROR_INVALIDDATA;
563 }
564 chan->subframe_len[chan->num_subframes] = subframe_len;
565 num_samples[c] += subframe_len;
566 ++chan->num_subframes;
567 if (num_samples[c] > s->samples_per_frame) {
568 av_log(s->avctx, AV_LOG_ERROR, "broken frame: "
569 "channel len > samples_per_frame\n");
570 return AVERROR_INVALIDDATA;
571 }
572 } else if (num_samples[c] <= min_channel_len) {
573 if (num_samples[c] < min_channel_len) {
574 channels_for_cur_subframe = 0;
575 min_channel_len = num_samples[c];
576 }
577 ++channels_for_cur_subframe;
578 }
579 }
580 } while (min_channel_len < s->samples_per_frame);
581
582 for (c = 0; c < s->num_channels; c++) {
583 int i;
584 int offset = 0;
585 for (i = 0; i < s->channel[c].num_subframes; i++) {
586 dprintf(s->avctx, "frame[%i] channel[%i] subframe[%i]"
587 " len %i\n", s->frame_num, c, i,
588 s->channel[c].subframe_len[i]);
589 s->channel[c].subframe_offset[i] = offset;
590 offset += s->channel[c].subframe_len[i];
591 }
592 }
593
594 return 0;
595}
596
597/**
598 *@brief Calculate a decorrelation matrix from the bitstream parameters.
599 *@param s codec context
600 *@param chgroup channel group for which the matrix needs to be calculated
601 */
602static void decode_decorrelation_matrix(WMAProDecodeCtx *s,
603 WMAProChannelGrp *chgroup)
604{
605 int i;
606 int offset = 0;
607 int8_t rotation_offset[WMAPRO_MAX_CHANNELS * WMAPRO_MAX_CHANNELS];
608 memset(chgroup->decorrelation_matrix, 0, s->num_channels *
609 s->num_channels * sizeof(*chgroup->decorrelation_matrix));
610
611 for (i = 0; i < chgroup->num_channels * (chgroup->num_channels - 1) >> 1; i++)
612 rotation_offset[i] = get_bits(&s->gb, 6);
613
614 for (i = 0; i < chgroup->num_channels; i++)
615 chgroup->decorrelation_matrix[chgroup->num_channels * i + i] =
616 get_bits1(&s->gb) ? 1.0 : -1.0;
617
618 for (i = 1; i < chgroup->num_channels; i++) {
619 int x;
620 for (x = 0; x < i; x++) {
621 int y;
622 for (y = 0; y < i + 1; y++) {
623 float v1 = chgroup->decorrelation_matrix[x * chgroup->num_channels + y];
624 float v2 = chgroup->decorrelation_matrix[i * chgroup->num_channels + y];
625 int n = rotation_offset[offset + x];
626 float sinv;
627 float cosv;
628
629 if (n < 32) {
630 sinv = sin64[n];
631 cosv = sin64[32 - n];
632 } else {
633 sinv = sin64[64 - n];
634 cosv = -sin64[n - 32];
635 }
636
637 chgroup->decorrelation_matrix[y + x * chgroup->num_channels] =
638 (v1 * sinv) - (v2 * cosv);
639 chgroup->decorrelation_matrix[y + i * chgroup->num_channels] =
640 (v1 * cosv) + (v2 * sinv);
641 }
642 }
643 offset += i;
644 }
645}
646
647/**
648 *@brief Decode channel transformation parameters
649 *@param s codec context
650 *@return 0 in case of success, < 0 in case of bitstream errors
651 */
652static int decode_channel_transform(WMAProDecodeCtx* s)
653{
654 int i;
655 /* should never consume more than 1921 bits for the 8 channel case
656 * 1 + MAX_CHANNELS * (MAX_CHANNELS + 2 + 3 * MAX_CHANNELS * MAX_CHANNELS
657 * + MAX_CHANNELS + MAX_BANDS + 1)
658 */
659
660 /** in the one channel case channel transforms are pointless */
661 s->num_chgroups = 0;
662 if (s->num_channels > 1) {
663 int remaining_channels = s->channels_for_cur_subframe;
664
665 if (get_bits1(&s->gb)) {
666 av_log_ask_for_sample(s->avctx,
667 "unsupported channel transform bit\n");
668 return AVERROR_INVALIDDATA;
669 }
670
671 for (s->num_chgroups = 0; remaining_channels &&
672 s->num_chgroups < s->channels_for_cur_subframe; s->num_chgroups++) {
673 WMAProChannelGrp* chgroup = &s->chgroup[s->num_chgroups];
674 float** channel_data = chgroup->channel_data;
675 chgroup->num_channels = 0;
676 chgroup->transform = 0;
677
678 /** decode channel mask */
679 if (remaining_channels > 2) {
680 for (i = 0; i < s->channels_for_cur_subframe; i++) {
681 int channel_idx = s->channel_indexes_for_cur_subframe[i];
682 if (!s->channel[channel_idx].grouped
683 && get_bits1(&s->gb)) {
684 ++chgroup->num_channels;
685 s->channel[channel_idx].grouped = 1;
686 *channel_data++ = s->channel[channel_idx].coeffs;
687 }
688 }
689 } else {
690 chgroup->num_channels = remaining_channels;
691 for (i = 0; i < s->channels_for_cur_subframe; i++) {
692 int channel_idx = s->channel_indexes_for_cur_subframe[i];
693 if (!s->channel[channel_idx].grouped)
694 *channel_data++ = s->channel[channel_idx].coeffs;
695 s->channel[channel_idx].grouped = 1;
696 }
697 }
698
699 /** decode transform type */
700 if (chgroup->num_channels == 2) {
701 if (get_bits1(&s->gb)) {
702 if (get_bits1(&s->gb)) {
703 av_log_ask_for_sample(s->avctx,
704 "unsupported channel transform type\n");
705 }
706 } else {
707 chgroup->transform = 1;
708 if (s->num_channels == 2) {
709 chgroup->decorrelation_matrix[0] = 1.0;
710 chgroup->decorrelation_matrix[1] = -1.0;
711 chgroup->decorrelation_matrix[2] = 1.0;
712 chgroup->decorrelation_matrix[3] = 1.0;
713 } else {
714 /** cos(pi/4) */
715 chgroup->decorrelation_matrix[0] = 0.70703125;
716 chgroup->decorrelation_matrix[1] = -0.70703125;
717 chgroup->decorrelation_matrix[2] = 0.70703125;
718 chgroup->decorrelation_matrix[3] = 0.70703125;
719 }
720 }
721 } else if (chgroup->num_channels > 2) {
722 if (get_bits1(&s->gb)) {
723 chgroup->transform = 1;
724 if (get_bits1(&s->gb)) {
725 decode_decorrelation_matrix(s, chgroup);
726 } else {
727 /** FIXME: more than 6 coupled channels not supported */
728 if (chgroup->num_channels > 6) {
729 av_log_ask_for_sample(s->avctx,
730 "coupled channels > 6\n");
731 } else {
732 memcpy(chgroup->decorrelation_matrix,
733 default_decorrelation[chgroup->num_channels],
734 chgroup->num_channels * chgroup->num_channels *
735 sizeof(*chgroup->decorrelation_matrix));
736 }
737 }
738 }
739 }
740
741 /** decode transform on / off */
742 if (chgroup->transform) {
743 if (!get_bits1(&s->gb)) {
744 int i;
745 /** transform can be enabled for individual bands */
746 for (i = 0; i < s->num_bands; i++) {
747 chgroup->transform_band[i] = get_bits1(&s->gb);
748 }
749 } else {
750 memset(chgroup->transform_band, 1, s->num_bands);
751 }
752 }
753 remaining_channels -= chgroup->num_channels;
754 }
755 }
756 return 0;
757}
758
759/**
760 *@brief Extract the coefficients from the bitstream.
761 *@param s codec context
762 *@param c current channel number
763 *@return 0 on success, < 0 in case of bitstream errors
764 */
765static int decode_coeffs(WMAProDecodeCtx *s, int c)
766{
767 /* Integers 0..15 as single-precision floats. The table saves a
768 costly int to float conversion, and storing the values as
769 integers allows fast sign-flipping. */
770 static const int fval_tab[16] = {
771 0x00000000, 0x3f800000, 0x40000000, 0x40400000,
772 0x40800000, 0x40a00000, 0x40c00000, 0x40e00000,
773 0x41000000, 0x41100000, 0x41200000, 0x41300000,
774 0x41400000, 0x41500000, 0x41600000, 0x41700000,
775 };
776 int vlctable;
777 VLC* vlc;
778 WMAProChannelCtx* ci = &s->channel[c];
779 int rl_mode = 0;
780 int cur_coeff = 0;
781 int num_zeros = 0;
782 const uint16_t* run;
783 const float* level;
784
785 dprintf(s->avctx, "decode coefficients for channel %i\n", c);
786
787 vlctable = get_bits1(&s->gb);
788 vlc = &coef_vlc[vlctable];
789
790 if (vlctable) {
791 run = coef1_run;
792 level = coef1_level;
793 } else {
794 run = coef0_run;
795 level = coef0_level;
796 }
797
798 /** decode vector coefficients (consumes up to 167 bits per iteration for
799 4 vector coded large values) */
800 while (!rl_mode && cur_coeff + 3 < s->subframe_len) {
801 int vals[4];
802 int i;
803 unsigned int idx;
804
805 idx = get_vlc2(&s->gb, vec4_vlc.table, VLCBITS, VEC4MAXDEPTH);
806
807 if (idx == HUFF_VEC4_SIZE - 1) {
808 for (i = 0; i < 4; i += 2) {
809 idx = get_vlc2(&s->gb, vec2_vlc.table, VLCBITS, VEC2MAXDEPTH);
810 if (idx == HUFF_VEC2_SIZE - 1) {
811 int v0, v1;
812 v0 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);
813 if (v0 == HUFF_VEC1_SIZE - 1)
814 v0 += ff_wma_get_large_val(&s->gb);
815 v1 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);
816 if (v1 == HUFF_VEC1_SIZE - 1)
817 v1 += ff_wma_get_large_val(&s->gb);
818 ((float*)vals)[i ] = v0;
819 ((float*)vals)[i+1] = v1;
820 } else {
821 vals[i] = fval_tab[symbol_to_vec2[idx] >> 4 ];
822 vals[i+1] = fval_tab[symbol_to_vec2[idx] & 0xF];
823 }
824 }
825 } else {
826 vals[0] = fval_tab[ symbol_to_vec4[idx] >> 12 ];
827 vals[1] = fval_tab[(symbol_to_vec4[idx] >> 8) & 0xF];
828 vals[2] = fval_tab[(symbol_to_vec4[idx] >> 4) & 0xF];
829 vals[3] = fval_tab[ symbol_to_vec4[idx] & 0xF];
830 }
831
832 /** decode sign */
833 for (i = 0; i < 4; i++) {
834 if (vals[i]) {
835 int sign = get_bits1(&s->gb) - 1;
836 *(uint32_t*)&ci->coeffs[cur_coeff] = vals[i] ^ sign<<31;
837 num_zeros = 0;
838 } else {
839 ci->coeffs[cur_coeff] = 0;
840 /** switch to run level mode when subframe_len / 128 zeros
841 were found in a row */
842 rl_mode |= (++num_zeros > s->subframe_len >> 8);
843 }
844 ++cur_coeff;
845 }
846 }
847
848 /** decode run level coded coefficients */
849 if (rl_mode) {
850 memset(&ci->coeffs[cur_coeff], 0,
851 sizeof(*ci->coeffs) * (s->subframe_len - cur_coeff));
852 if (ff_wma_run_level_decode(s->avctx, &s->gb, vlc,
853 level, run, 1, ci->coeffs,
854 cur_coeff, s->subframe_len,
855 s->subframe_len, s->esc_len, 0))
856 return AVERROR_INVALIDDATA;
857 }
858
859 return 0;
860}
861
862/**
863 *@brief Extract scale factors from the bitstream.
864 *@param s codec context
865 *@return 0 on success, < 0 in case of bitstream errors
866 */
867static int decode_scale_factors(WMAProDecodeCtx* s)
868{
869 int i;
870
871 /** should never consume more than 5344 bits
872 * MAX_CHANNELS * (1 + MAX_BANDS * 23)
873 */
874
875 for (i = 0; i < s->channels_for_cur_subframe; i++) {
876 int c = s->channel_indexes_for_cur_subframe[i];
877 int* sf;
878 int* sf_end;
879 s->channel[c].scale_factors = s->channel[c].saved_scale_factors[!s->channel[c].scale_factor_idx];
880 sf_end = s->channel[c].scale_factors + s->num_bands;
881
882 /** resample scale factors for the new block size
883 * as the scale factors might need to be resampled several times
884 * before some new values are transmitted, a backup of the last
885 * transmitted scale factors is kept in saved_scale_factors
886 */
887 if (s->channel[c].reuse_sf) {
888 const int8_t* sf_offsets = s->sf_offsets[s->table_idx][s->channel[c].table_idx];
889 int b;
890 for (b = 0; b < s->num_bands; b++)
891 s->channel[c].scale_factors[b] =
892 s->channel[c].saved_scale_factors[s->channel[c].scale_factor_idx][*sf_offsets++];
893 }
894
895 if (!s->channel[c].cur_subframe || get_bits1(&s->gb)) {
896
897 if (!s->channel[c].reuse_sf) {
898 int val;
899 /** decode DPCM coded scale factors */
900 s->channel[c].scale_factor_step = get_bits(&s->gb, 2) + 1;
901 val = 45 / s->channel[c].scale_factor_step;
902 for (sf = s->channel[c].scale_factors; sf < sf_end; sf++) {
903 val += get_vlc2(&s->gb, sf_vlc.table, SCALEVLCBITS, SCALEMAXDEPTH) - 60;
904 *sf = val;
905 }
906 } else {
907 int i;
908 /** run level decode differences to the resampled factors */
909 for (i = 0; i < s->num_bands; i++) {
910 int idx;
911 int skip;
912 int val;
913 int sign;
914
915 idx = get_vlc2(&s->gb, sf_rl_vlc.table, VLCBITS, SCALERLMAXDEPTH);
916
917 if (!idx) {
918 uint32_t code = get_bits(&s->gb, 14);
919 val = code >> 6;
920 sign = (code & 1) - 1;
921 skip = (code & 0x3f) >> 1;
922 } else if (idx == 1) {
923 break;
924 } else {
925 skip = scale_rl_run[idx];
926 val = scale_rl_level[idx];
927 sign = get_bits1(&s->gb)-1;
928 }
929
930 i += skip;
931 if (i >= s->num_bands) {
932 av_log(s->avctx, AV_LOG_ERROR,
933 "invalid scale factor coding\n");
934 return AVERROR_INVALIDDATA;
935 }
936 s->channel[c].scale_factors[i] += (val ^ sign) - sign;
937 }
938 }
939 /** swap buffers */
940 s->channel[c].scale_factor_idx = !s->channel[c].scale_factor_idx;
941 s->channel[c].table_idx = s->table_idx;
942 s->channel[c].reuse_sf = 1;
943 }
944
945 /** calculate new scale factor maximum */
946 s->channel[c].max_scale_factor = s->channel[c].scale_factors[0];
947 for (sf = s->channel[c].scale_factors + 1; sf < sf_end; sf++) {
948 s->channel[c].max_scale_factor =
949 FFMAX(s->channel[c].max_scale_factor, *sf);
950 }
951
952 }
953 return 0;
954}
955
956/**
957 *@brief Reconstruct the individual channel data.
958 *@param s codec context
959 */
960static void inverse_channel_transform(WMAProDecodeCtx *s)
961{
962 int i;
963
964 for (i = 0; i < s->num_chgroups; i++) {
965 if (s->chgroup[i].transform) {
966 float data[WMAPRO_MAX_CHANNELS];
967 const int num_channels = s->chgroup[i].num_channels;
968 float** ch_data = s->chgroup[i].channel_data;
969 float** ch_end = ch_data + num_channels;
970 const int8_t* tb = s->chgroup[i].transform_band;
971 int16_t* sfb;
972
973 /** multichannel decorrelation */
974 for (sfb = s->cur_sfb_offsets;
975 sfb < s->cur_sfb_offsets + s->num_bands; sfb++) {
976 int y;
977 if (*tb++ == 1) {
978 /** multiply values with the decorrelation_matrix */
979 for (y = sfb[0]; y < FFMIN(sfb[1], s->subframe_len); y++) {
980 const float* mat = s->chgroup[i].decorrelation_matrix;
981 const float* data_end = data + num_channels;
982 float* data_ptr = data;
983 float** ch;
984
985 for (ch = ch_data; ch < ch_end; ch++)
986 *data_ptr++ = (*ch)[y];
987
988 for (ch = ch_data; ch < ch_end; ch++) {
989 float sum = 0;
990 data_ptr = data;
991 while (data_ptr < data_end)
992 sum += *data_ptr++ * *mat++;
993
994 (*ch)[y] = sum;
995 }
996 }
997 } else if (s->num_channels == 2) {
998 int len = FFMIN(sfb[1], s->subframe_len) - sfb[0];
999 s->dsp.vector_fmul_scalar(ch_data[0] + sfb[0],
1000 ch_data[0] + sfb[0],
1001 181.0 / 128, len);
1002 s->dsp.vector_fmul_scalar(ch_data[1] + sfb[0],
1003 ch_data[1] + sfb[0],
1004 181.0 / 128, len);
1005 }
1006 }
1007 }
1008 }
1009}
1010
1011/**
1012 *@brief Apply sine window and reconstruct the output buffer.
1013 *@param s codec context
1014 */
1015static void wmapro_window(WMAProDecodeCtx *s)
1016{
1017 int i;
1018 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1019 int c = s->channel_indexes_for_cur_subframe[i];
1020 float* window;
1021 int winlen = s->channel[c].prev_block_len;
1022 float* start = s->channel[c].coeffs - (winlen >> 1);
1023
1024 if (s->subframe_len < winlen) {
1025 start += (winlen - s->subframe_len) >> 1;
1026 winlen = s->subframe_len;
1027 }
1028
1029 window = s->windows[av_log2(winlen) - BLOCK_MIN_BITS];
1030
1031 winlen >>= 1;
1032
1033 s->dsp.vector_fmul_window(start, start, start + winlen,
1034 window, 0, winlen);
1035
1036 s->channel[c].prev_block_len = s->subframe_len;
1037 }
1038}
1039
1040/**
1041 *@brief Decode a single subframe (block).
1042 *@param s codec context
1043 *@return 0 on success, < 0 when decoding failed
1044 */
1045static int decode_subframe(WMAProDecodeCtx *s)
1046{
1047 int offset = s->samples_per_frame;
1048 int subframe_len = s->samples_per_frame;
1049 int i;
1050 int total_samples = s->samples_per_frame * s->num_channels;
1051 int transmit_coeffs = 0;
1052 int cur_subwoofer_cutoff;
1053
1054 s->subframe_offset = get_bits_count(&s->gb);
1055
1056 /** reset channel context and find the next block offset and size
1057 == the next block of the channel with the smallest number of
1058 decoded samples
1059 */
1060 for (i = 0; i < s->num_channels; i++) {
1061 s->channel[i].grouped = 0;
1062 if (offset > s->channel[i].decoded_samples) {
1063 offset = s->channel[i].decoded_samples;
1064 subframe_len =
1065 s->channel[i].subframe_len[s->channel[i].cur_subframe];
1066 }
1067 }
1068
1069 dprintf(s->avctx,
1070 "processing subframe with offset %i len %i\n", offset, subframe_len);
1071
1072 /** get a list of all channels that contain the estimated block */
1073 s->channels_for_cur_subframe = 0;
1074 for (i = 0; i < s->num_channels; i++) {
1075 const int cur_subframe = s->channel[i].cur_subframe;
1076 /** substract already processed samples */
1077 total_samples -= s->channel[i].decoded_samples;
1078
1079 /** and count if there are multiple subframes that match our profile */
1080 if (offset == s->channel[i].decoded_samples &&
1081 subframe_len == s->channel[i].subframe_len[cur_subframe]) {
1082 total_samples -= s->channel[i].subframe_len[cur_subframe];
1083 s->channel[i].decoded_samples +=
1084 s->channel[i].subframe_len[cur_subframe];
1085 s->channel_indexes_for_cur_subframe[s->channels_for_cur_subframe] = i;
1086 ++s->channels_for_cur_subframe;
1087 }
1088 }
1089
1090 /** check if the frame will be complete after processing the
1091 estimated block */
1092 if (!total_samples)
1093 s->parsed_all_subframes = 1;
1094
1095
1096 dprintf(s->avctx, "subframe is part of %i channels\n",
1097 s->channels_for_cur_subframe);
1098
1099 /** calculate number of scale factor bands and their offsets */
1100 s->table_idx = av_log2(s->samples_per_frame/subframe_len);
1101 s->num_bands = s->num_sfb[s->table_idx];
1102 s->cur_sfb_offsets = s->sfb_offsets[s->table_idx];
1103 cur_subwoofer_cutoff = s->subwoofer_cutoffs[s->table_idx];
1104
1105 /** configure the decoder for the current subframe */
1106 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1107 int c = s->channel_indexes_for_cur_subframe[i];
1108
1109 s->channel[c].coeffs = &s->channel[c].out[(s->samples_per_frame >> 1)
1110 + offset];
1111 }
1112
1113 s->subframe_len = subframe_len;
1114 s->esc_len = av_log2(s->subframe_len - 1) + 1;
1115
1116 /** skip extended header if any */
1117 if (get_bits1(&s->gb)) {
1118 int num_fill_bits;
1119 if (!(num_fill_bits = get_bits(&s->gb, 2))) {
1120 int len = get_bits(&s->gb, 4);
1121 num_fill_bits = get_bits(&s->gb, len) + 1;
1122 }
1123
1124 if (num_fill_bits >= 0) {
1125 if (get_bits_count(&s->gb) + num_fill_bits > s->num_saved_bits) {
1126 av_log(s->avctx, AV_LOG_ERROR, "invalid number of fill bits\n");
1127 return AVERROR_INVALIDDATA;
1128 }
1129
1130 skip_bits_long(&s->gb, num_fill_bits);
1131 }
1132 }
1133
1134 /** no idea for what the following bit is used */
1135 if (get_bits1(&s->gb)) {
1136 av_log_ask_for_sample(s->avctx, "reserved bit set\n");
1137 return AVERROR_INVALIDDATA;
1138 }
1139
1140
1141 if (decode_channel_transform(s) < 0)
1142 return AVERROR_INVALIDDATA;
1143
1144
1145 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1146 int c = s->channel_indexes_for_cur_subframe[i];
1147 if ((s->channel[c].transmit_coefs = get_bits1(&s->gb)))
1148 transmit_coeffs = 1;
1149 }
1150
1151 if (transmit_coeffs) {
1152 int step;
1153 int quant_step = 90 * s->bits_per_sample >> 4;
1154 if ((get_bits1(&s->gb))) {
1155 /** FIXME: might change run level mode decision */
1156 av_log_ask_for_sample(s->avctx, "unsupported quant step coding\n");
1157 return AVERROR_INVALIDDATA;
1158 }
1159 /** decode quantization step */
1160 step = get_sbits(&s->gb, 6);
1161 quant_step += step;
1162 if (step == -32 || step == 31) {
1163 const int sign = (step == 31) - 1;
1164 int quant = 0;
1165 while (get_bits_count(&s->gb) + 5 < s->num_saved_bits &&
1166 (step = get_bits(&s->gb, 5)) == 31) {
1167 quant += 31;
1168 }
1169 quant_step += ((quant + step) ^ sign) - sign;
1170 }
1171 if (quant_step < 0) {
1172 av_log(s->avctx, AV_LOG_DEBUG, "negative quant step\n");
1173 }
1174
1175 /** decode quantization step modifiers for every channel */
1176
1177 if (s->channels_for_cur_subframe == 1) {
1178 s->channel[s->channel_indexes_for_cur_subframe[0]].quant_step = quant_step;
1179 } else {
1180 int modifier_len = get_bits(&s->gb, 3);
1181 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1182 int c = s->channel_indexes_for_cur_subframe[i];
1183 s->channel[c].quant_step = quant_step;
1184 if (get_bits1(&s->gb)) {
1185 if (modifier_len) {
1186 s->channel[c].quant_step += get_bits(&s->gb, modifier_len) + 1;
1187 } else
1188 ++s->channel[c].quant_step;
1189 }
1190 }
1191 }
1192
1193 /** decode scale factors */
1194 if (decode_scale_factors(s) < 0)
1195 return AVERROR_INVALIDDATA;
1196 }
1197
1198 dprintf(s->avctx, "BITSTREAM: subframe header length was %i\n",
1199 get_bits_count(&s->gb) - s->subframe_offset);
1200
1201 /** parse coefficients */
1202 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1203 int c = s->channel_indexes_for_cur_subframe[i];
1204 if (s->channel[c].transmit_coefs &&
1205 get_bits_count(&s->gb) < s->num_saved_bits) {
1206 decode_coeffs(s, c);
1207 } else
1208 memset(s->channel[c].coeffs, 0,
1209 sizeof(*s->channel[c].coeffs) * subframe_len);
1210 }
1211
1212 dprintf(s->avctx, "BITSTREAM: subframe length was %i\n",
1213 get_bits_count(&s->gb) - s->subframe_offset);
1214
1215 if (transmit_coeffs) {
1216 /** reconstruct the per channel data */
1217 inverse_channel_transform(s);
1218 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1219 int c = s->channel_indexes_for_cur_subframe[i];
1220 const int* sf = s->channel[c].scale_factors;
1221 int b;
1222
1223 if (c == s->lfe_channel)
1224 memset(&s->tmp[cur_subwoofer_cutoff], 0, sizeof(*s->tmp) *
1225 (subframe_len - cur_subwoofer_cutoff));
1226
1227 /** inverse quantization and rescaling */
1228 for (b = 0; b < s->num_bands; b++) {
1229 const int end = FFMIN(s->cur_sfb_offsets[b+1], s->subframe_len);
1230 const int exp = s->channel[c].quant_step -
1231 (s->channel[c].max_scale_factor - *sf++) *
1232 s->channel[c].scale_factor_step;
1233 const float quant = pow(10.0, exp / 20.0);
1234 int start = s->cur_sfb_offsets[b];
1235 s->dsp.vector_fmul_scalar(s->tmp + start,
1236 s->channel[c].coeffs + start,
1237 quant, end - start);
1238 }
1239
1240 /** apply imdct (ff_imdct_half == DCTIV with reverse) */
1241 ff_imdct_half(&s->mdct_ctx[av_log2(subframe_len) - BLOCK_MIN_BITS],
1242 s->channel[c].coeffs, s->tmp);
1243 }
1244 }
1245
1246 /** window and overlapp-add */
1247 wmapro_window(s);
1248
1249 /** handled one subframe */
1250 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1251 int c = s->channel_indexes_for_cur_subframe[i];
1252 if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) {
1253 av_log(s->avctx, AV_LOG_ERROR, "broken subframe\n");
1254 return AVERROR_INVALIDDATA;
1255 }
1256 ++s->channel[c].cur_subframe;
1257 }
1258
1259 return 0;
1260}
1261
1262/**
1263 *@brief Decode one WMA frame.
1264 *@param s codec context
1265 *@return 0 if the trailer bit indicates that this is the last frame,
1266 * 1 if there are additional frames
1267 */
1268static int decode_frame(WMAProDecodeCtx *s)
1269{
1270 GetBitContext* gb = &s->gb;
1271 int more_frames = 0;
1272 int len = 0;
1273 int i;
1274
1275 /** check for potential output buffer overflow */
1276 if (s->num_channels * s->samples_per_frame > s->samples_end - s->samples) {
1277 /** return an error if no frame could be decoded at all */
1278 av_log(s->avctx, AV_LOG_ERROR,
1279 "not enough space for the output samples\n");
1280 s->packet_loss = 1;
1281 return 0;
1282 }
1283
1284 /** get frame length */
1285 if (s->len_prefix)
1286 len = get_bits(gb, s->log2_frame_size);
1287
1288 dprintf(s->avctx, "decoding frame with length %x\n", len);
1289
1290 /** decode tile information */
1291 if (decode_tilehdr(s)) {
1292 s->packet_loss = 1;
1293 return 0;
1294 }
1295
1296 /** read postproc transform */
1297 if (s->num_channels > 1 && get_bits1(gb)) {
1298 av_log_ask_for_sample(s->avctx, "Unsupported postproc transform found\n");
1299 s->packet_loss = 1;
1300 return 0;
1301 }
1302
1303 /** read drc info */
1304 if (s->dynamic_range_compression) {
1305 s->drc_gain = get_bits(gb, 8);
1306 dprintf(s->avctx, "drc_gain %i\n", s->drc_gain);
1307 }
1308
1309 /** no idea what these are for, might be the number of samples
1310 that need to be skipped at the beginning or end of a stream */
1311 if (get_bits1(gb)) {
1312 int skip;
1313
1314 /** usually true for the first frame */
1315 if (get_bits1(gb)) {
1316 skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
1317 dprintf(s->avctx, "start skip: %i\n", skip);
1318 }
1319
1320 /** sometimes true for the last frame */
1321 if (get_bits1(gb)) {
1322 skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
1323 dprintf(s->avctx, "end skip: %i\n", skip);
1324 }
1325
1326 }
1327
1328 dprintf(s->avctx, "BITSTREAM: frame header length was %i\n",
1329 get_bits_count(gb) - s->frame_offset);
1330
1331 /** reset subframe states */
1332 s->parsed_all_subframes = 0;
1333 for (i = 0; i < s->num_channels; i++) {
1334 s->channel[i].decoded_samples = 0;
1335 s->channel[i].cur_subframe = 0;
1336 s->channel[i].reuse_sf = 0;
1337 }
1338
1339 /** decode all subframes */
1340 while (!s->parsed_all_subframes) {
1341 if (decode_subframe(s) < 0) {
1342 s->packet_loss = 1;
1343 return 0;
1344 }
1345 }
1346
1347 /** interleave samples and write them to the output buffer */
1348 for (i = 0; i < s->num_channels; i++) {
1349 float* ptr = s->samples + i;
1350 int incr = s->num_channels;
1351 float* iptr = s->channel[i].out;
1352 float* iend = iptr + s->samples_per_frame;
1353
1354 while (iptr < iend) {
1355 *ptr = av_clipf(*iptr++, -1.0, 32767.0 / 32768.0);
1356 ptr += incr;
1357 }
1358
1359 /** reuse second half of the IMDCT output for the next frame */
1360 memcpy(&s->channel[i].out[0],
1361 &s->channel[i].out[s->samples_per_frame],
1362 s->samples_per_frame * sizeof(*s->channel[i].out) >> 1);
1363 }
1364
1365 if (s->skip_frame) {
1366 s->skip_frame = 0;
1367 } else
1368 s->samples += s->num_channels * s->samples_per_frame;
1369
1370 if (len != (get_bits_count(gb) - s->frame_offset) + 2) {
1371 /** FIXME: not sure if this is always an error */
1372 av_log(s->avctx, AV_LOG_ERROR, "frame[%i] would have to skip %i bits\n",
1373 s->frame_num, len - (get_bits_count(gb) - s->frame_offset) - 1);
1374 s->packet_loss = 1;
1375 return 0;
1376 }
1377
1378 /** skip the rest of the frame data */
1379 skip_bits_long(gb, len - (get_bits_count(gb) - s->frame_offset) - 1);
1380
1381 /** decode trailer bit */
1382 more_frames = get_bits1(gb);
1383
1384 ++s->frame_num;
1385 return more_frames;
1386}
1387
1388/**
1389 *@brief Calculate remaining input buffer length.
1390 *@param s codec context
1391 *@param gb bitstream reader context
1392 *@return remaining size in bits
1393 */
1394static int remaining_bits(WMAProDecodeCtx *s, GetBitContext *gb)
1395{
1396 return s->buf_bit_size - get_bits_count(gb);
1397}
1398
1399/**
1400 *@brief Fill the bit reservoir with a (partial) frame.
1401 *@param s codec context
1402 *@param gb bitstream reader context
1403 *@param len length of the partial frame
1404 *@param append decides wether to reset the buffer or not
1405 */
1406static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len,
1407 int append)
1408{
1409 int buflen;
1410
1411 /** when the frame data does not need to be concatenated, the input buffer
1412 is resetted and additional bits from the previous frame are copyed
1413 and skipped later so that a fast byte copy is possible */
1414
1415 if (!append) {
1416 s->frame_offset = get_bits_count(gb) & 7;
1417 s->num_saved_bits = s->frame_offset;
1418 init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
1419 }
1420
1421 buflen = (s->num_saved_bits + len + 8) >> 3;
1422
1423 if (len <= 0 || buflen > MAX_FRAMESIZE) {
1424 av_log_ask_for_sample(s->avctx, "input buffer too small\n");
1425 s->packet_loss = 1;
1426 return;
1427 }
1428
1429 s->num_saved_bits += len;
1430 if (!append) {
1431 ff_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3),
1432 s->num_saved_bits);
1433 } else {
1434 int align = 8 - (get_bits_count(gb) & 7);
1435 align = FFMIN(align, len);
1436 put_bits(&s->pb, align, get_bits(gb, align));
1437 len -= align;
1438 ff_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), len);
1439 }
1440 skip_bits_long(gb, len);
1441
1442 {
1443 PutBitContext tmp = s->pb;
1444 flush_put_bits(&tmp);
1445 }
1446
1447 init_get_bits(&s->gb, s->frame_data, s->num_saved_bits);
1448 skip_bits(&s->gb, s->frame_offset);
1449}
1450
1451/**
1452 *@brief Decode a single WMA packet.
1453 *@param avctx codec context
1454 *@param data the output buffer
1455 *@param data_size number of bytes that were written to the output buffer
1456 *@param avpkt input packet
1457 *@return number of bytes that were read from the input buffer
1458 */
1459static int decode_packet(AVCodecContext *avctx,
1460 void *data, int *data_size, AVPacket* avpkt)
1461{
1462 WMAProDecodeCtx *s = avctx->priv_data;
1463 GetBitContext* gb = &s->pgb;
1464 const uint8_t* buf = avpkt->data;
1465 int buf_size = avpkt->size;
1466 int num_bits_prev_frame;
1467 int packet_sequence_number;
1468
1469 s->samples = data;
1470 s->samples_end = (float*)((int8_t*)data + *data_size);
1471 *data_size = 0;
1472
1473 if (s->packet_done || s->packet_loss) {
1474 s->packet_done = 0;
1475 s->buf_bit_size = buf_size << 3;
1476
1477 /** sanity check for the buffer length */
1478 if (buf_size < avctx->block_align)
1479 return 0;
1480
1481 buf_size = avctx->block_align;
1482
1483 /** parse packet header */
1484 init_get_bits(gb, buf, s->buf_bit_size);
1485 packet_sequence_number = get_bits(gb, 4);
1486 skip_bits(gb, 2);
1487
1488 /** get number of bits that need to be added to the previous frame */
1489 num_bits_prev_frame = get_bits(gb, s->log2_frame_size);
1490 dprintf(avctx, "packet[%d]: nbpf %x\n", avctx->frame_number,
1491 num_bits_prev_frame);
1492
1493 /** check for packet loss */
1494 if (!s->packet_loss &&
1495 ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1496 s->packet_loss = 1;
1497 av_log(avctx, AV_LOG_ERROR, "Packet loss detected! seq %x vs %x\n",
1498 s->packet_sequence_number, packet_sequence_number);
1499 }
1500 s->packet_sequence_number = packet_sequence_number;
1501
1502 if (num_bits_prev_frame > 0) {
1503 /** append the previous frame data to the remaining data from the
1504 previous packet to create a full frame */
1505 save_bits(s, gb, num_bits_prev_frame, 1);
1506 dprintf(avctx, "accumulated %x bits of frame data\n",
1507 s->num_saved_bits - s->frame_offset);
1508
1509 /** decode the cross packet frame if it is valid */
1510 if (!s->packet_loss)
1511 decode_frame(s);
1512 } else if (s->num_saved_bits - s->frame_offset) {
1513 dprintf(avctx, "ignoring %x previously saved bits\n",
1514 s->num_saved_bits - s->frame_offset);
1515 }
1516
1517 s->packet_loss = 0;
1518
1519 } else {
1520 int frame_size;
1521 s->buf_bit_size = avpkt->size << 3;
1522 init_get_bits(gb, avpkt->data, s->buf_bit_size);
1523 skip_bits(gb, s->packet_offset);
1524 if (remaining_bits(s, gb) > s->log2_frame_size &&
1525 (frame_size = show_bits(gb, s->log2_frame_size)) &&
1526 frame_size <= remaining_bits(s, gb)) {
1527 save_bits(s, gb, frame_size, 0);
1528 s->packet_done = !decode_frame(s);
1529 } else
1530 s->packet_done = 1;
1531 }
1532
1533 if (s->packet_done && !s->packet_loss &&
1534 remaining_bits(s, gb) > 0) {
1535 /** save the rest of the data so that it can be decoded
1536 with the next packet */
1537 save_bits(s, gb, remaining_bits(s, gb), 0);
1538 }
1539
1540 *data_size = (int8_t *)s->samples - (int8_t *)data;
1541 s->packet_offset = get_bits_count(gb) & 7;
1542
1543 return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3;
1544}
1545
1546/**
1547 *@brief Clear decoder buffers (for seeking).
1548 *@param avctx codec context
1549 */
1550static void flush(AVCodecContext *avctx)
1551{
1552 WMAProDecodeCtx *s = avctx->priv_data;
1553 int i;
1554 /** reset output buffer as a part of it is used during the windowing of a
1555 new frame */
1556 for (i = 0; i < s->num_channels; i++)
1557 memset(s->channel[i].out, 0, s->samples_per_frame *
1558 sizeof(*s->channel[i].out));
1559 s->packet_loss = 1;
1560}
1561
1562
1563/**
1564 *@brief wmapro decoder
1565 */
1566AVCodec wmapro_decoder = {
1567 "wmapro",
1568 AVMEDIA_TYPE_AUDIO,
1569 CODEC_ID_WMAPRO,
1570 sizeof(WMAProDecodeCtx),
1571 decode_init,
1572 NULL,
1573 decode_end,
1574 decode_packet,
1575 .capabilities = CODEC_CAP_SUBFRAMES,
1576 .flush= flush,
1577 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 9 Professional"),
1578};