summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2009-05-09 01:04:20 +0000
committerDave Chapman <dave@dchapman.com>2009-05-09 01:04:20 +0000
commit69db01e72f2de91d35703919bfc9d0700df83e85 (patch)
tree18a8d01dc3df13c5dc51b813d7ce70e6bec79704
parent681a774472eded71f7a82fbfa4c3591f3f98d209 (diff)
downloadrockbox-69db01e72f2de91d35703919bfc9d0700df83e85.tar.gz
rockbox-69db01e72f2de91d35703919bfc9d0700df83e85.zip
Initial commit of the minimal set of ffmpeg (r18079) files required for Cook (realaudio) decoding. These are the unmodified versions from ffmpeg, committed as a base for future changes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20882 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/libcook/avcodec.h3432
-rw-r--r--apps/codecs/libcook/bitstream.c320
-rw-r--r--apps/codecs/libcook/bitstream.h955
-rw-r--r--apps/codecs/libcook/bytestream.h71
-rw-r--r--apps/codecs/libcook/cook.c1213
-rw-r--r--apps/codecs/libcook/cookdata.h563
-rw-r--r--apps/codecs/libcook/dsputil.h898
-rw-r--r--apps/codecs/libcook/fft.c374
-rw-r--r--apps/codecs/libcook/libavutil/avutil.h63
-rw-r--r--apps/codecs/libcook/libavutil/bswap.h99
-rw-r--r--apps/codecs/libcook/libavutil/common.h286
-rw-r--r--apps/codecs/libcook/libavutil/internal.h328
-rw-r--r--apps/codecs/libcook/libavutil/intreadwrite.h192
-rw-r--r--apps/codecs/libcook/libavutil/lfg.c64
-rw-r--r--apps/codecs/libcook/libavutil/lfg.h54
-rw-r--r--apps/codecs/libcook/libavutil/log.c89
-rw-r--r--apps/codecs/libcook/libavutil/log.h116
-rw-r--r--apps/codecs/libcook/libavutil/md5.c182
-rw-r--r--apps/codecs/libcook/libavutil/md5.h36
-rw-r--r--apps/codecs/libcook/libavutil/mem.c159
-rw-r--r--apps/codecs/libcook/libavutil/mem.h104
-rw-r--r--apps/codecs/libcook/mdct.c229
22 files changed, 9827 insertions, 0 deletions
diff --git a/apps/codecs/libcook/avcodec.h b/apps/codecs/libcook/avcodec.h
new file mode 100644
index 0000000000..a520340162
--- /dev/null
+++ b/apps/codecs/libcook/avcodec.h
@@ -0,0 +1,3432 @@
1/*
2 * copyright (c) 2001 Fabrice Bellard
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef AVCODEC_AVCODEC_H
22#define AVCODEC_AVCODEC_H
23
24/**
25 * @file libavcodec/avcodec.h
26 * external API header
27 */
28
29#include <errno.h>
30#include "libavutil/avutil.h"
31
32#define LIBAVCODEC_VERSION_MAJOR 52
33#define LIBAVCODEC_VERSION_MINOR 22
34#define LIBAVCODEC_VERSION_MICRO 0
35
36#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
37 LIBAVCODEC_VERSION_MINOR, \
38 LIBAVCODEC_VERSION_MICRO)
39#define LIBAVCODEC_VERSION AV_VERSION(LIBAVCODEC_VERSION_MAJOR, \
40 LIBAVCODEC_VERSION_MINOR, \
41 LIBAVCODEC_VERSION_MICRO)
42#define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT
43
44#define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
45
46#define AV_NOPTS_VALUE INT64_C(0x8000000000000000)
47#define AV_TIME_BASE 1000000
48#define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE}
49
50/**
51 * Identifies the syntax and semantics of the bitstream.
52 * The principle is roughly:
53 * Two decoders with the same ID can decode the same streams.
54 * Two encoders with the same ID can encode compatible streams.
55 * There may be slight deviations from the principle due to implementation
56 * details.
57 *
58 * If you add a codec ID to this list, add it so that
59 * 1. no value of a existing codec ID changes (that would break ABI),
60 * 2. it is as close as possible to similar codecs.
61 */
62enum CodecID {
63 CODEC_ID_NONE,
64
65 /* video codecs */
66 CODEC_ID_MPEG1VIDEO,
67 CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding
68 CODEC_ID_MPEG2VIDEO_XVMC,
69 CODEC_ID_H261,
70 CODEC_ID_H263,
71 CODEC_ID_RV10,
72 CODEC_ID_RV20,
73 CODEC_ID_MJPEG,
74 CODEC_ID_MJPEGB,
75 CODEC_ID_LJPEG,
76 CODEC_ID_SP5X,
77 CODEC_ID_JPEGLS,
78 CODEC_ID_MPEG4,
79 CODEC_ID_RAWVIDEO,
80 CODEC_ID_MSMPEG4V1,
81 CODEC_ID_MSMPEG4V2,
82 CODEC_ID_MSMPEG4V3,
83 CODEC_ID_WMV1,
84 CODEC_ID_WMV2,
85 CODEC_ID_H263P,
86 CODEC_ID_H263I,
87 CODEC_ID_FLV1,
88 CODEC_ID_SVQ1,
89 CODEC_ID_SVQ3,
90 CODEC_ID_DVVIDEO,
91 CODEC_ID_HUFFYUV,
92 CODEC_ID_CYUV,
93 CODEC_ID_H264,
94 CODEC_ID_INDEO3,
95 CODEC_ID_VP3,
96 CODEC_ID_THEORA,
97 CODEC_ID_ASV1,
98 CODEC_ID_ASV2,
99 CODEC_ID_FFV1,
100 CODEC_ID_4XM,
101 CODEC_ID_VCR1,
102 CODEC_ID_CLJR,
103 CODEC_ID_MDEC,
104 CODEC_ID_ROQ,
105 CODEC_ID_INTERPLAY_VIDEO,
106 CODEC_ID_XAN_WC3,
107 CODEC_ID_XAN_WC4,
108 CODEC_ID_RPZA,
109 CODEC_ID_CINEPAK,
110 CODEC_ID_WS_VQA,
111 CODEC_ID_MSRLE,
112 CODEC_ID_MSVIDEO1,
113 CODEC_ID_IDCIN,
114 CODEC_ID_8BPS,
115 CODEC_ID_SMC,
116 CODEC_ID_FLIC,
117 CODEC_ID_TRUEMOTION1,
118 CODEC_ID_VMDVIDEO,
119 CODEC_ID_MSZH,
120 CODEC_ID_ZLIB,
121 CODEC_ID_QTRLE,
122 CODEC_ID_SNOW,
123 CODEC_ID_TSCC,
124 CODEC_ID_ULTI,
125 CODEC_ID_QDRAW,
126 CODEC_ID_VIXL,
127 CODEC_ID_QPEG,
128 CODEC_ID_XVID,
129 CODEC_ID_PNG,
130 CODEC_ID_PPM,
131 CODEC_ID_PBM,
132 CODEC_ID_PGM,
133 CODEC_ID_PGMYUV,
134 CODEC_ID_PAM,
135 CODEC_ID_FFVHUFF,
136 CODEC_ID_RV30,
137 CODEC_ID_RV40,
138 CODEC_ID_VC1,
139 CODEC_ID_WMV3,
140 CODEC_ID_LOCO,
141 CODEC_ID_WNV1,
142 CODEC_ID_AASC,
143 CODEC_ID_INDEO2,
144 CODEC_ID_FRAPS,
145 CODEC_ID_TRUEMOTION2,
146 CODEC_ID_BMP,
147 CODEC_ID_CSCD,
148 CODEC_ID_MMVIDEO,
149 CODEC_ID_ZMBV,
150 CODEC_ID_AVS,
151 CODEC_ID_SMACKVIDEO,
152 CODEC_ID_NUV,
153 CODEC_ID_KMVC,
154 CODEC_ID_FLASHSV,
155 CODEC_ID_CAVS,
156 CODEC_ID_JPEG2000,
157 CODEC_ID_VMNC,
158 CODEC_ID_VP5,
159 CODEC_ID_VP6,
160 CODEC_ID_VP6F,
161 CODEC_ID_TARGA,
162 CODEC_ID_DSICINVIDEO,
163 CODEC_ID_TIERTEXSEQVIDEO,
164 CODEC_ID_TIFF,
165 CODEC_ID_GIF,
166 CODEC_ID_FFH264,
167 CODEC_ID_DXA,
168 CODEC_ID_DNXHD,
169 CODEC_ID_THP,
170 CODEC_ID_SGI,
171 CODEC_ID_C93,
172 CODEC_ID_BETHSOFTVID,
173 CODEC_ID_PTX,
174 CODEC_ID_TXD,
175 CODEC_ID_VP6A,
176 CODEC_ID_AMV,
177 CODEC_ID_VB,
178 CODEC_ID_PCX,
179 CODEC_ID_SUNRAST,
180 CODEC_ID_INDEO4,
181 CODEC_ID_INDEO5,
182 CODEC_ID_MIMIC,
183 CODEC_ID_RL2,
184 CODEC_ID_8SVX_EXP,
185 CODEC_ID_8SVX_FIB,
186 CODEC_ID_ESCAPE124,
187 CODEC_ID_DIRAC,
188 CODEC_ID_BFI,
189 CODEC_ID_CMV,
190 CODEC_ID_MOTIONPIXELS,
191 CODEC_ID_TGV,
192 CODEC_ID_TGQ,
193 CODEC_ID_TQI,
194
195 /* various PCM "codecs" */
196 CODEC_ID_PCM_S16LE= 0x10000,
197 CODEC_ID_PCM_S16BE,
198 CODEC_ID_PCM_U16LE,
199 CODEC_ID_PCM_U16BE,
200 CODEC_ID_PCM_S8,
201 CODEC_ID_PCM_U8,
202 CODEC_ID_PCM_MULAW,
203 CODEC_ID_PCM_ALAW,
204 CODEC_ID_PCM_S32LE,
205 CODEC_ID_PCM_S32BE,
206 CODEC_ID_PCM_U32LE,
207 CODEC_ID_PCM_U32BE,
208 CODEC_ID_PCM_S24LE,
209 CODEC_ID_PCM_S24BE,
210 CODEC_ID_PCM_U24LE,
211 CODEC_ID_PCM_U24BE,
212 CODEC_ID_PCM_S24DAUD,
213 CODEC_ID_PCM_ZORK,
214 CODEC_ID_PCM_S16LE_PLANAR,
215 CODEC_ID_PCM_DVD,
216 CODEC_ID_PCM_F32BE,
217 CODEC_ID_PCM_F32LE,
218 CODEC_ID_PCM_F64BE,
219 CODEC_ID_PCM_F64LE,
220
221 /* various ADPCM codecs */
222 CODEC_ID_ADPCM_IMA_QT= 0x11000,
223 CODEC_ID_ADPCM_IMA_WAV,
224 CODEC_ID_ADPCM_IMA_DK3,
225 CODEC_ID_ADPCM_IMA_DK4,
226 CODEC_ID_ADPCM_IMA_WS,
227 CODEC_ID_ADPCM_IMA_SMJPEG,
228 CODEC_ID_ADPCM_MS,
229 CODEC_ID_ADPCM_4XM,
230 CODEC_ID_ADPCM_XA,
231 CODEC_ID_ADPCM_ADX,
232 CODEC_ID_ADPCM_EA,
233 CODEC_ID_ADPCM_G726,
234 CODEC_ID_ADPCM_CT,
235 CODEC_ID_ADPCM_SWF,
236 CODEC_ID_ADPCM_YAMAHA,
237 CODEC_ID_ADPCM_SBPRO_4,
238 CODEC_ID_ADPCM_SBPRO_3,
239 CODEC_ID_ADPCM_SBPRO_2,
240 CODEC_ID_ADPCM_THP,
241 CODEC_ID_ADPCM_IMA_AMV,
242 CODEC_ID_ADPCM_EA_R1,
243 CODEC_ID_ADPCM_EA_R3,
244 CODEC_ID_ADPCM_EA_R2,
245 CODEC_ID_ADPCM_IMA_EA_SEAD,
246 CODEC_ID_ADPCM_IMA_EA_EACS,
247 CODEC_ID_ADPCM_EA_XAS,
248 CODEC_ID_ADPCM_EA_MAXIS_XA,
249 CODEC_ID_ADPCM_IMA_ISS,
250
251 /* AMR */
252 CODEC_ID_AMR_NB= 0x12000,
253 CODEC_ID_AMR_WB,
254
255 /* RealAudio codecs*/
256 CODEC_ID_RA_144= 0x13000,
257 CODEC_ID_RA_288,
258
259 /* various DPCM codecs */
260 CODEC_ID_ROQ_DPCM= 0x14000,
261 CODEC_ID_INTERPLAY_DPCM,
262 CODEC_ID_XAN_DPCM,
263 CODEC_ID_SOL_DPCM,
264
265 /* audio codecs */
266 CODEC_ID_MP2= 0x15000,
267 CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
268 CODEC_ID_AAC,
269 CODEC_ID_AC3,
270 CODEC_ID_DTS,
271 CODEC_ID_VORBIS,
272 CODEC_ID_DVAUDIO,
273 CODEC_ID_WMAV1,
274 CODEC_ID_WMAV2,
275 CODEC_ID_MACE3,
276 CODEC_ID_MACE6,
277 CODEC_ID_VMDAUDIO,
278 CODEC_ID_SONIC,
279 CODEC_ID_SONIC_LS,
280 CODEC_ID_FLAC,
281 CODEC_ID_MP3ADU,
282 CODEC_ID_MP3ON4,
283 CODEC_ID_SHORTEN,
284 CODEC_ID_ALAC,
285 CODEC_ID_WESTWOOD_SND1,
286 CODEC_ID_GSM, ///< as in Berlin toast format
287 CODEC_ID_QDM2,
288 CODEC_ID_COOK,
289 CODEC_ID_TRUESPEECH,
290 CODEC_ID_TTA,
291 CODEC_ID_SMACKAUDIO,
292 CODEC_ID_QCELP,
293 CODEC_ID_WAVPACK,
294 CODEC_ID_DSICINAUDIO,
295 CODEC_ID_IMC,
296 CODEC_ID_MUSEPACK7,
297 CODEC_ID_MLP,
298 CODEC_ID_GSM_MS, /* as found in WAV */
299 CODEC_ID_ATRAC3,
300 CODEC_ID_VOXWARE,
301 CODEC_ID_APE,
302 CODEC_ID_NELLYMOSER,
303 CODEC_ID_MUSEPACK8,
304 CODEC_ID_SPEEX,
305 CODEC_ID_WMAVOICE,
306 CODEC_ID_WMAPRO,
307 CODEC_ID_WMALOSSLESS,
308 CODEC_ID_ATRAC3P,
309 CODEC_ID_EAC3,
310 CODEC_ID_SIPR,
311 CODEC_ID_MP1,
312 CODEC_ID_TWINVQ,
313 CODEC_ID_TRUEHD,
314
315 /* subtitle codecs */
316 CODEC_ID_DVD_SUBTITLE= 0x17000,
317 CODEC_ID_DVB_SUBTITLE,
318 CODEC_ID_TEXT, ///< raw UTF-8 text
319 CODEC_ID_XSUB,
320 CODEC_ID_SSA,
321 CODEC_ID_MOV_TEXT,
322
323 /* other specific kind of codecs (generally used for attachments) */
324 CODEC_ID_TTF= 0x18000,
325
326 CODEC_ID_PROBE= 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it
327
328 CODEC_ID_MPEG2TS= 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
329 * stream (only used by libavformat) */
330};
331
332enum CodecType {
333 CODEC_TYPE_UNKNOWN = -1,
334 CODEC_TYPE_VIDEO,
335 CODEC_TYPE_AUDIO,
336 CODEC_TYPE_DATA,
337 CODEC_TYPE_SUBTITLE,
338 CODEC_TYPE_ATTACHMENT,
339 CODEC_TYPE_NB
340};
341
342/**
343 * all in native-endian format
344 */
345enum SampleFormat {
346 SAMPLE_FMT_NONE = -1,
347 SAMPLE_FMT_U8, ///< unsigned 8 bits
348 SAMPLE_FMT_S16, ///< signed 16 bits
349 SAMPLE_FMT_S32, ///< signed 32 bits
350 SAMPLE_FMT_FLT, ///< float
351 SAMPLE_FMT_DBL, ///< double
352 SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if dynamically linking to libavcodec
353};
354
355/* Audio channel masks */
356#define CH_FRONT_LEFT 0x00000001
357#define CH_FRONT_RIGHT 0x00000002
358#define CH_FRONT_CENTER 0x00000004
359#define CH_LOW_FREQUENCY 0x00000008
360#define CH_BACK_LEFT 0x00000010
361#define CH_BACK_RIGHT 0x00000020
362#define CH_FRONT_LEFT_OF_CENTER 0x00000040
363#define CH_FRONT_RIGHT_OF_CENTER 0x00000080
364#define CH_BACK_CENTER 0x00000100
365#define CH_SIDE_LEFT 0x00000200
366#define CH_SIDE_RIGHT 0x00000400
367#define CH_TOP_CENTER 0x00000800
368#define CH_TOP_FRONT_LEFT 0x00001000
369#define CH_TOP_FRONT_CENTER 0x00002000
370#define CH_TOP_FRONT_RIGHT 0x00004000
371#define CH_TOP_BACK_LEFT 0x00008000
372#define CH_TOP_BACK_CENTER 0x00010000
373#define CH_TOP_BACK_RIGHT 0x00020000
374#define CH_STEREO_LEFT 0x20000000 ///< Stereo downmix.
375#define CH_STEREO_RIGHT 0x40000000 ///< See CH_STEREO_LEFT.
376
377/* Audio channel convenience macros */
378#define CH_LAYOUT_MONO (CH_FRONT_CENTER)
379#define CH_LAYOUT_STEREO (CH_FRONT_LEFT|CH_FRONT_RIGHT)
380#define CH_LAYOUT_SURROUND (CH_LAYOUT_STEREO|CH_FRONT_CENTER)
381#define CH_LAYOUT_QUAD (CH_LAYOUT_STEREO|CH_BACK_LEFT|CH_BACK_RIGHT)
382#define CH_LAYOUT_5POINT0 (CH_LAYOUT_SURROUND|CH_SIDE_LEFT|CH_SIDE_RIGHT)
383#define CH_LAYOUT_5POINT1 (CH_LAYOUT_5POINT0|CH_LOW_FREQUENCY)
384#define CH_LAYOUT_7POINT1 (CH_LAYOUT_5POINT1|CH_BACK_LEFT|CH_BACK_RIGHT)
385#define CH_LAYOUT_7POINT1_WIDE (CH_LAYOUT_SURROUND|CH_LOW_FREQUENCY|\
386 CH_BACK_LEFT|CH_BACK_RIGHT|\
387 CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER)
388#define CH_LAYOUT_STEREO_DOWNMIX (CH_STEREO_LEFT|CH_STEREO_RIGHT)
389
390/* in bytes */
391#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
392
393/**
394 * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
395 * This is mainly needed because some optimized bitstream readers read
396 * 32 or 64 bit at once and could read over the end.<br>
397 * Note: If the first 23 bits of the additional bytes are not 0, then damaged
398 * MPEG bitstreams could cause overread and segfault.
399 */
400#define FF_INPUT_BUFFER_PADDING_SIZE 8
401
402/**
403 * minimum encoding buffer size
404 * Used to avoid some checks during header writing.
405 */
406#define FF_MIN_BUFFER_SIZE 16384
407
408
409/**
410 * motion estimation type.
411 */
412enum Motion_Est_ID {
413 ME_ZERO = 1, ///< no search, that is use 0,0 vector whenever one is needed
414 ME_FULL,
415 ME_LOG,
416 ME_PHODS,
417 ME_EPZS, ///< enhanced predictive zonal search
418 ME_X1, ///< reserved for experiments
419 ME_HEX, ///< hexagon based search
420 ME_UMH, ///< uneven multi-hexagon search
421 ME_ITER, ///< iterative search
422 ME_TESA, ///< transformed exhaustive search algorithm
423};
424
425enum AVDiscard{
426 /* We leave some space between them for extensions (drop some
427 * keyframes for intra-only or drop just some bidir frames). */
428 AVDISCARD_NONE =-16, ///< discard nothing
429 AVDISCARD_DEFAULT= 0, ///< discard useless packets like 0 size packets in avi
430 AVDISCARD_NONREF = 8, ///< discard all non reference
431 AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
432 AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
433 AVDISCARD_ALL = 48, ///< discard all
434};
435
436typedef struct RcOverride{
437 int start_frame;
438 int end_frame;
439 int qscale; // If this is 0 then quality_factor will be used instead.
440 float quality_factor;
441} RcOverride;
442
443#define FF_MAX_B_FRAMES 16
444
445/* encoding support
446 These flags can be passed in AVCodecContext.flags before initialization.
447 Note: Not everything is supported yet.
448*/
449
450#define CODEC_FLAG_QSCALE 0x0002 ///< Use fixed qscale.
451#define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / advanced prediction for H.263.
452#define CODEC_FLAG_QPEL 0x0010 ///< Use qpel MC.
453#define CODEC_FLAG_GMC 0x0020 ///< Use GMC.
454#define CODEC_FLAG_MV0 0x0040 ///< Always try a MB with MV=<0,0>.
455#define CODEC_FLAG_PART 0x0080 ///< Use data partitioning.
456/**
457 * The parent program guarantees that the input for B-frames containing
458 * streams is not written to for at least s->max_b_frames+1 frames, if
459 * this is not set the input will be copied.
460 */
461#define CODEC_FLAG_INPUT_PRESERVED 0x0100
462#define CODEC_FLAG_PASS1 0x0200 ///< Use internal 2pass ratecontrol in first pass mode.
463#define CODEC_FLAG_PASS2 0x0400 ///< Use internal 2pass ratecontrol in second pass mode.
464#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< Use external Huffman table (for MJPEG).
465#define CODEC_FLAG_GRAY 0x2000 ///< Only decode/encode grayscale.
466#define CODEC_FLAG_EMU_EDGE 0x4000 ///< Don't draw edges.
467#define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding.
468#define CODEC_FLAG_TRUNCATED 0x00010000 /** Input bitstream might be truncated at a random
469 location instead of only at frame boundaries. */
470#define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< Normalize adaptive quantization.
471#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT.
472#define CODEC_FLAG_LOW_DELAY 0x00080000 ///< Force low delay.
473#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< Use alternate scan.
474#define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< Place global headers in extradata instead of every keyframe.
475#define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT).
476/* Fx : Flag for h263+ extra options */
477#define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
478#define CODEC_FLAG_H263P_UMV 0x02000000 ///< unlimited motion vector
479#define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp.
480#define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon.
481#define CODEC_FLAG_H263P_AIV 0x00000008 ///< H.263 alternative inter VLC
482#define CODEC_FLAG_OBMC 0x00000001 ///< OBMC
483#define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter
484#define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000
485#define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
486#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< Will reserve space for SVCD scan offset user data.
487#define CODEC_FLAG_CLOSED_GOP 0x80000000
488#define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks.
489#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size.
490#define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding.
491#define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata.
492#define CODEC_FLAG2_BPYRAMID 0x00000010 ///< H.264 allow B-frames to be used as references.
493#define CODEC_FLAG2_WPRED 0x00000020 ///< H.264 weighted biprediction for B-frames
494#define CODEC_FLAG2_MIXED_REFS 0x00000040 ///< H.264 one reference per partition, as opposed to one reference per macroblock
495#define CODEC_FLAG2_8X8DCT 0x00000080 ///< H.264 high profile 8x8 transform
496#define CODEC_FLAG2_FASTPSKIP 0x00000100 ///< H.264 fast pskip
497#define CODEC_FLAG2_AUD 0x00000200 ///< H.264 access unit delimiters
498#define CODEC_FLAG2_BRDO 0x00000400 ///< B-frame rate-distortion optimization
499#define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< Use MPEG-2 intra VLC table.
500#define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC).
501#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format.
502#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping
503#define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
504#define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer.
505#define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible
506
507/* Unsupported options :
508 * Syntax Arithmetic coding (SAC)
509 * Reference Picture Selection
510 * Independent Segment Decoding */
511/* /Fx */
512/* codec capabilities */
513
514#define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback.
515/**
516 * Codec uses get_buffer() for allocating buffers.
517 * direct rendering method 1
518 */
519#define CODEC_CAP_DR1 0x0002
520/* If 'parse_only' field is true, then avcodec_parse_frame() can be used. */
521#define CODEC_CAP_PARSE_ONLY 0x0004
522#define CODEC_CAP_TRUNCATED 0x0008
523/* Codec can export data for HW decoding (XvMC). */
524#define CODEC_CAP_HWACCEL 0x0010
525/**
526 * Codec has a nonzero delay and needs to be fed with NULL at the end to get the delayed data.
527 * If this is not set, the codec is guaranteed to never be fed with NULL data.
528 */
529#define CODEC_CAP_DELAY 0x0020
530/**
531 * Codec can be fed a final frame with a smaller size.
532 * This can be used to prevent truncation of the last audio samples.
533 */
534#define CODEC_CAP_SMALL_LAST_FRAME 0x0040
535/**
536 * Codec can export data for HW decoding (VDPAU).
537 */
538#define CODEC_CAP_HWACCEL_VDPAU 0x0080
539
540//The following defines may change, don't expect compatibility if you use them.
541#define MB_TYPE_INTRA4x4 0x0001
542#define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific
543#define MB_TYPE_INTRA_PCM 0x0004 //FIXME H.264-specific
544#define MB_TYPE_16x16 0x0008
545#define MB_TYPE_16x8 0x0010
546#define MB_TYPE_8x16 0x0020
547#define MB_TYPE_8x8 0x0040
548#define MB_TYPE_INTERLACED 0x0080
549#define MB_TYPE_DIRECT2 0x0100 //FIXME
550#define MB_TYPE_ACPRED 0x0200
551#define MB_TYPE_GMC 0x0400
552#define MB_TYPE_SKIP 0x0800
553#define MB_TYPE_P0L0 0x1000
554#define MB_TYPE_P1L0 0x2000
555#define MB_TYPE_P0L1 0x4000
556#define MB_TYPE_P1L1 0x8000
557#define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
558#define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
559#define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
560#define MB_TYPE_QUANT 0x00010000
561#define MB_TYPE_CBP 0x00020000
562//Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...)
563
564/**
565 * Pan Scan area.
566 * This specifies the area which should be displayed.
567 * Note there may be multiple such areas for one frame.
568 */
569typedef struct AVPanScan{
570 /**
571 * id
572 * - encoding: Set by user.
573 * - decoding: Set by libavcodec.
574 */
575 int id;
576
577 /**
578 * width and height in 1/16 pel
579 * - encoding: Set by user.
580 * - decoding: Set by libavcodec.
581 */
582 int width;
583 int height;
584
585 /**
586 * position of the top left corner in 1/16 pel for up to 3 fields/frames
587 * - encoding: Set by user.
588 * - decoding: Set by libavcodec.
589 */
590 int16_t position[3][2];
591}AVPanScan;
592
593#define FF_COMMON_FRAME \
594 /**\
595 * pointer to the picture planes.\
596 * This might be different from the first allocated byte\
597 * - encoding: \
598 * - decoding: \
599 */\
600 uint8_t *data[4];\
601 int linesize[4];\
602 /**\
603 * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.\
604 * This isn't used by libavcodec unless the default get/release_buffer() is used.\
605 * - encoding: \
606 * - decoding: \
607 */\
608 uint8_t *base[4];\
609 /**\
610 * 1 -> keyframe, 0-> not\
611 * - encoding: Set by libavcodec.\
612 * - decoding: Set by libavcodec.\
613 */\
614 int key_frame;\
615\
616 /**\
617 * Picture type of the frame, see ?_TYPE below.\
618 * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\
619 * - decoding: Set by libavcodec.\
620 */\
621 int pict_type;\
622\
623 /**\
624 * presentation timestamp in time_base units (time when frame should be shown to user)\
625 * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.\
626 * - encoding: MUST be set by user.\
627 * - decoding: Set by libavcodec.\
628 */\
629 int64_t pts;\
630\
631 /**\
632 * picture number in bitstream order\
633 * - encoding: set by\
634 * - decoding: Set by libavcodec.\
635 */\
636 int coded_picture_number;\
637 /**\
638 * picture number in display order\
639 * - encoding: set by\
640 * - decoding: Set by libavcodec.\
641 */\
642 int display_picture_number;\
643\
644 /**\
645 * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \
646 * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\
647 * - decoding: Set by libavcodec.\
648 */\
649 int quality; \
650\
651 /**\
652 * buffer age (1->was last buffer and dint change, 2->..., ...).\
653 * Set to INT_MAX if the buffer has not been used yet.\
654 * - encoding: unused\
655 * - decoding: MUST be set by get_buffer().\
656 */\
657 int age;\
658\
659 /**\
660 * is this picture used as reference\
661 * The values for this are the same as the MpegEncContext.picture_structure\
662 * variable, that is 1->top field, 2->bottom field, 3->frame/both fields.\
663 * Set to 4 for delayed, non-reference frames.\
664 * - encoding: unused\
665 * - decoding: Set by libavcodec. (before get_buffer() call)).\
666 */\
667 int reference;\
668\
669 /**\
670 * QP table\
671 * - encoding: unused\
672 * - decoding: Set by libavcodec.\
673 */\
674 int8_t *qscale_table;\
675 /**\
676 * QP store stride\
677 * - encoding: unused\
678 * - decoding: Set by libavcodec.\
679 */\
680 int qstride;\
681\
682 /**\
683 * mbskip_table[mb]>=1 if MB didn't change\
684 * stride= mb_width = (width+15)>>4\
685 * - encoding: unused\
686 * - decoding: Set by libavcodec.\
687 */\
688 uint8_t *mbskip_table;\
689\
690 /**\
691 * motion vector table\
692 * @code\
693 * example:\
694 * int mv_sample_log2= 4 - motion_subsample_log2;\
695 * int mb_width= (width+15)>>4;\
696 * int mv_stride= (mb_width << mv_sample_log2) + 1;\
697 * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];\
698 * @endcode\
699 * - encoding: Set by user.\
700 * - decoding: Set by libavcodec.\
701 */\
702 int16_t (*motion_val[2])[2];\
703\
704 /**\
705 * macroblock type table\
706 * mb_type_base + mb_width + 2\
707 * - encoding: Set by user.\
708 * - decoding: Set by libavcodec.\
709 */\
710 uint32_t *mb_type;\
711\
712 /**\
713 * log2 of the size of the block which a single vector in motion_val represents: \
714 * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)\
715 * - encoding: unused\
716 * - decoding: Set by libavcodec.\
717 */\
718 uint8_t motion_subsample_log2;\
719\
720 /**\
721 * for some private data of the user\
722 * - encoding: unused\
723 * - decoding: Set by user.\
724 */\
725 void *opaque;\
726\
727 /**\
728 * error\
729 * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.\
730 * - decoding: unused\
731 */\
732 uint64_t error[4];\
733\
734 /**\
735 * type of the buffer (to keep track of who has to deallocate data[*])\
736 * - encoding: Set by the one who allocates it.\
737 * - decoding: Set by the one who allocates it.\
738 * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.\
739 */\
740 int type;\
741 \
742 /**\
743 * When decoding, this signals how much the picture must be delayed.\
744 * extra_delay = repeat_pict / (2*fps)\
745 * - encoding: unused\
746 * - decoding: Set by libavcodec.\
747 */\
748 int repeat_pict;\
749 \
750 /**\
751 * \
752 */\
753 int qscale_type;\
754 \
755 /**\
756 * The content of the picture is interlaced.\
757 * - encoding: Set by user.\
758 * - decoding: Set by libavcodec. (default 0)\
759 */\
760 int interlaced_frame;\
761 \
762 /**\
763 * If the content is interlaced, is top field displayed first.\
764 * - encoding: Set by user.\
765 * - decoding: Set by libavcodec.\
766 */\
767 int top_field_first;\
768 \
769 /**\
770 * Pan scan.\
771 * - encoding: Set by user.\
772 * - decoding: Set by libavcodec.\
773 */\
774 AVPanScan *pan_scan;\
775 \
776 /**\
777 * Tell user application that palette has changed from previous frame.\
778 * - encoding: ??? (no palette-enabled encoder yet)\
779 * - decoding: Set by libavcodec. (default 0).\
780 */\
781 int palette_has_changed;\
782 \
783 /**\
784 * codec suggestion on buffer type if != 0\
785 * - encoding: unused\
786 * - decoding: Set by libavcodec. (before get_buffer() call)).\
787 */\
788 int buffer_hints;\
789\
790 /**\
791 * DCT coefficients\
792 * - encoding: unused\
793 * - decoding: Set by libavcodec.\
794 */\
795 short *dct_coeff;\
796\
797 /**\
798 * motion referece frame index\
799 * - encoding: Set by user.\
800 * - decoding: Set by libavcodec.\
801 */\
802 int8_t *ref_index[2];\
803\
804 /**\
805 * reordered opaque 64bit number (generally a PTS) from AVCodecContext.reordered_opaque\
806 * output in AVFrame.reordered_opaque\
807 * - encoding: unused\
808 * - decoding: Read by user.\
809 */\
810 int64_t reordered_opaque;\
811\
812 /**\
813 * hardware accelerator private data (FFmpeg allocated)\
814 * - encoding: unused\
815 * - decoding: Set by libavcodec\
816 */\
817 void *hwaccel_picture_private;\
818
819
820#define FF_QSCALE_TYPE_MPEG1 0
821#define FF_QSCALE_TYPE_MPEG2 1
822#define FF_QSCALE_TYPE_H264 2
823
824#define FF_BUFFER_TYPE_INTERNAL 1
825#define FF_BUFFER_TYPE_USER 2 ///< direct rendering buffers (image is (de)allocated by user)
826#define FF_BUFFER_TYPE_SHARED 4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared.
827#define FF_BUFFER_TYPE_COPY 8 ///< Just a (modified) copy of some other buffer, don't deallocate anything.
828
829
830#define FF_I_TYPE 1 ///< Intra
831#define FF_P_TYPE 2 ///< Predicted
832#define FF_B_TYPE 3 ///< Bi-dir predicted
833#define FF_S_TYPE 4 ///< S(GMC)-VOP MPEG4
834#define FF_SI_TYPE 5 ///< Switching Intra
835#define FF_SP_TYPE 6 ///< Switching Predicted
836#define FF_BI_TYPE 7
837
838#define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore).
839#define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer.
840#define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content.
841#define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update).
842
843/**
844 * Audio Video Frame.
845 * New fields can be added to the end of FF_COMMON_FRAME with minor version
846 * bumps.
847 * Removal, reordering and changes to existing fields require a major
848 * version bump. No fields should be added into AVFrame before or after
849 * FF_COMMON_FRAME!
850 * sizeof(AVFrame) must not be used outside libav*.
851 */
852typedef struct AVFrame {
853 FF_COMMON_FRAME
854} AVFrame;
855
856/**
857 * main external API structure.
858 * New fields can be added to the end with minor version bumps.
859 * Removal, reordering and changes to existing fields require a major
860 * version bump.
861 * sizeof(AVCodecContext) must not be used outside libav*.
862 */
863typedef struct AVCodecContext {
864 /**
865 * information on struct for av_log
866 * - set by avcodec_alloc_context
867 */
868 const AVClass *av_class;
869 /**
870 * the average bitrate
871 * - encoding: Set by user; unused for constant quantizer encoding.
872 * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream.
873 */
874 int bit_rate;
875
876 /**
877 * number of bits the bitstream is allowed to diverge from the reference.
878 * the reference can be CBR (for CBR pass1) or VBR (for pass2)
879 * - encoding: Set by user; unused for constant quantizer encoding.
880 * - decoding: unused
881 */
882 int bit_rate_tolerance;
883
884 /**
885 * CODEC_FLAG_*.
886 * - encoding: Set by user.
887 * - decoding: Set by user.
888 */
889 int flags;
890
891 /**
892 * Some codecs need additional format info. It is stored here.
893 * If any muxer uses this then ALL demuxers/parsers AND encoders for the
894 * specific codec MUST set it correctly otherwise stream copy breaks.
895 * In general use of this field by muxers is not recommanded.
896 * - encoding: Set by libavcodec.
897 * - decoding: Set by libavcodec. (FIXME: Is this OK?)
898 */
899 int sub_id;
900
901 /**
902 * Motion estimation algorithm used for video coding.
903 * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
904 * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific]
905 * - encoding: MUST be set by user.
906 * - decoding: unused
907 */
908 int me_method;
909
910 /**
911 * some codecs need / can use extradata like Huffman tables.
912 * mjpeg: Huffman tables
913 * rv10: additional flags
914 * mpeg4: global headers (they can be in the bitstream or here)
915 * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
916 * than extradata_size to avoid prolems if it is read with the bitstream reader.
917 * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
918 * - encoding: Set/allocated/freed by libavcodec.
919 * - decoding: Set/allocated/freed by user.
920 */
921 uint8_t *extradata;
922 int extradata_size;
923
924 /**
925 * This is the fundamental unit of time (in seconds) in terms
926 * of which frame timestamps are represented. For fixed-fps content,
927 * timebase should be 1/framerate and timestamp increments should be
928 * identically 1.
929 * - encoding: MUST be set by user.
930 * - decoding: Set by libavcodec.
931 */
932 AVRational time_base;
933
934 /* video only */
935 /**
936 * picture width / height.
937 * - encoding: MUST be set by user.
938 * - decoding: Set by libavcodec.
939 * Note: For compatibility it is possible to set this instead of
940 * coded_width/height before decoding.
941 */
942 int width, height;
943
944#define FF_ASPECT_EXTENDED 15
945
946 /**
947 * the number of pictures in a group of pictures, or 0 for intra_only
948 * - encoding: Set by user.
949 * - decoding: unused
950 */
951 int gop_size;
952
953 /**
954 * Pixel format, see PIX_FMT_xxx.
955 * - encoding: Set by user.
956 * - decoding: Set by libavcodec.
957 */
958 enum PixelFormat pix_fmt;
959
960 /**
961 * Frame rate emulation. If not zero, the lower layer (i.e. format handler)
962 * has to read frames at native frame rate.
963 * - encoding: Set by user.
964 * - decoding: unused
965 */
966 int rate_emu;
967
968 /**
969 * If non NULL, 'draw_horiz_band' is called by the libavcodec
970 * decoder to draw a horizontal band. It improves cache usage. Not
971 * all codecs can do that. You must check the codec capabilities
972 * beforehand.
973 * The function is also used by hardware acceleration APIs.
974 * It is called at least once during frame decoding to pass
975 * the data needed for hardware render.
976 * In that mode instead of pixel data, AVFrame points to
977 * a structure specific to the acceleration API. The application
978 * reads the structure and can change some fields to indicate progress
979 * or mark state.
980 * - encoding: unused
981 * - decoding: Set by user.
982 * @param height the height of the slice
983 * @param y the y position of the slice
984 * @param type 1->top field, 2->bottom field, 3->frame
985 * @param offset offset into the AVFrame.data from which the slice should be read
986 */
987 void (*draw_horiz_band)(struct AVCodecContext *s,
988 const AVFrame *src, int offset[4],
989 int y, int type, int height);
990
991 /* audio only */
992 int sample_rate; ///< samples per second
993 int channels; ///< number of audio channels
994
995 /**
996 * audio sample format
997 * - encoding: Set by user.
998 * - decoding: Set by libavcodec.
999 */
1000 enum SampleFormat sample_fmt; ///< sample format, currently unused
1001
1002 /* The following data should not be initialized. */
1003 /**
1004 * Samples per packet, initialized when calling 'init'.
1005 */
1006 int frame_size;
1007 int frame_number; ///< audio or video frame number
1008 int real_pict_num; ///< Returns the real picture number of previous encoded frame.
1009
1010 /**
1011 * Number of frames the decoded output will be delayed relative to
1012 * the encoded input.
1013 * - encoding: Set by libavcodec.
1014 * - decoding: unused
1015 */
1016 int delay;
1017
1018 /* - encoding parameters */
1019 float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
1020 float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
1021
1022 /**
1023 * minimum quantizer
1024 * - encoding: Set by user.
1025 * - decoding: unused
1026 */
1027 int qmin;
1028
1029 /**
1030 * maximum quantizer
1031 * - encoding: Set by user.
1032 * - decoding: unused
1033 */
1034 int qmax;
1035
1036 /**
1037 * maximum quantizer difference between frames
1038 * - encoding: Set by user.
1039 * - decoding: unused
1040 */
1041 int max_qdiff;
1042
1043 /**
1044 * maximum number of B-frames between non-B-frames
1045 * Note: The output will be delayed by max_b_frames+1 relative to the input.
1046 * - encoding: Set by user.
1047 * - decoding: unused
1048 */
1049 int max_b_frames;
1050
1051 /**
1052 * qscale factor between IP and B-frames
1053 * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
1054 * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
1055 * - encoding: Set by user.
1056 * - decoding: unused
1057 */
1058 float b_quant_factor;
1059
1060 /** obsolete FIXME remove */
1061 int rc_strategy;
1062#define FF_RC_STRATEGY_XVID 1
1063
1064 int b_frame_strategy;
1065
1066 /**
1067 * hurry up amount
1068 * - encoding: unused
1069 * - decoding: Set by user. 1-> Skip B-frames, 2-> Skip IDCT/dequant too, 5-> Skip everything except header
1070 * @deprecated Deprecated in favor of skip_idct and skip_frame.
1071 */
1072 int hurry_up;
1073
1074 struct AVCodec *codec;
1075
1076 void *priv_data;
1077
1078 int rtp_payload_size; /* The size of the RTP payload: the coder will */
1079 /* do its best to deliver a chunk with size */
1080 /* below rtp_payload_size, the chunk will start */
1081 /* with a start code on some codecs like H.263. */
1082 /* This doesn't take account of any particular */
1083 /* headers inside the transmitted RTP payload. */
1084
1085
1086 /* The RTP callback: This function is called */
1087 /* every time the encoder has a packet to send. */
1088 /* It depends on the encoder if the data starts */
1089 /* with a Start Code (it should). H.263 does. */
1090 /* mb_nb contains the number of macroblocks */
1091 /* encoded in the RTP payload. */
1092 void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
1093
1094 /* statistics, used for 2-pass encoding */
1095 int mv_bits;
1096 int header_bits;
1097 int i_tex_bits;
1098 int p_tex_bits;
1099 int i_count;
1100 int p_count;
1101 int skip_count;
1102 int misc_bits;
1103
1104 /**
1105 * number of bits used for the previously encoded frame
1106 * - encoding: Set by libavcodec.
1107 * - decoding: unused
1108 */
1109 int frame_bits;
1110
1111 /**
1112 * Private data of the user, can be used to carry app specific stuff.
1113 * - encoding: Set by user.
1114 * - decoding: Set by user.
1115 */
1116 void *opaque;
1117
1118 char codec_name[32];
1119 enum CodecType codec_type; /* see CODEC_TYPE_xxx */
1120 enum CodecID codec_id; /* see CODEC_ID_xxx */
1121
1122 /**
1123 * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
1124 * This is used to work around some encoder bugs.
1125 * A demuxer should set this to what is stored in the field used to identify the codec.
1126 * If there are multiple such fields in a container then the demuxer should choose the one
1127 * which maximizes the information about the used codec.
1128 * If the codec tag field in a container is larger then 32 bits then the demuxer should
1129 * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
1130 * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
1131 * first.
1132 * - encoding: Set by user, if not then the default based on codec_id will be used.
1133 * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
1134 */
1135 unsigned int codec_tag;
1136
1137 /**
1138 * Work around bugs in encoders which sometimes cannot be detected automatically.
1139 * - encoding: Set by user
1140 * - decoding: Set by user
1141 */
1142 int workaround_bugs;
1143#define FF_BUG_AUTODETECT 1 ///< autodetection
1144#define FF_BUG_OLD_MSMPEG4 2
1145#define FF_BUG_XVID_ILACE 4
1146#define FF_BUG_UMP4 8
1147#define FF_BUG_NO_PADDING 16
1148#define FF_BUG_AMV 32
1149#define FF_BUG_AC_VLC 0 ///< Will be removed, libavcodec can now handle these non-compliant files by default.
1150#define FF_BUG_QPEL_CHROMA 64
1151#define FF_BUG_STD_QPEL 128
1152#define FF_BUG_QPEL_CHROMA2 256
1153#define FF_BUG_DIRECT_BLOCKSIZE 512
1154#define FF_BUG_EDGE 1024
1155#define FF_BUG_HPEL_CHROMA 2048
1156#define FF_BUG_DC_CLIP 4096
1157#define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders.
1158//#define FF_BUG_FAKE_SCALABILITY 16 //Autodetection should work 100%.
1159
1160 /**
1161 * luma single coefficient elimination threshold
1162 * - encoding: Set by user.
1163 * - decoding: unused
1164 */
1165 int luma_elim_threshold;
1166
1167 /**
1168 * chroma single coeff elimination threshold
1169 * - encoding: Set by user.
1170 * - decoding: unused
1171 */
1172 int chroma_elim_threshold;
1173
1174 /**
1175 * strictly follow the standard (MPEG4, ...).
1176 * - encoding: Set by user.
1177 * - decoding: Set by user.
1178 * Setting this to STRICT or higher means the encoder and decoder will
1179 * generally do stupid things. While setting it to inofficial or lower
1180 * will mean the encoder might use things that are not supported by all
1181 * spec compliant decoders. Decoders make no difference between normal,
1182 * inofficial and experimental, that is they always try to decode things
1183 * when they can unless they are explicitly asked to behave stupid
1184 * (=strictly conform to the specs)
1185 */
1186 int strict_std_compliance;
1187#define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to a older more strict version of the spec or reference software.
1188#define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences.
1189#define FF_COMPLIANCE_NORMAL 0
1190#define FF_COMPLIANCE_INOFFICIAL -1 ///< Allow inofficial extensions.
1191#define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
1192
1193 /**
1194 * qscale offset between IP and B-frames
1195 * - encoding: Set by user.
1196 * - decoding: unused
1197 */
1198 float b_quant_offset;
1199
1200 /**
1201 * Error recognization; higher values will detect more errors but may
1202 * misdetect some more or less valid parts as errors.
1203 * - encoding: unused
1204 * - decoding: Set by user.
1205 */
1206 int error_recognition;
1207#define FF_ER_CAREFUL 1
1208#define FF_ER_COMPLIANT 2
1209#define FF_ER_AGGRESSIVE 3
1210#define FF_ER_VERY_AGGRESSIVE 4
1211
1212 /**
1213 * Called at the beginning of each frame to get a buffer for it.
1214 * If pic.reference is set then the frame will be read later by libavcodec.
1215 * avcodec_align_dimensions() should be used to find the required width and
1216 * height, as they normally need to be rounded up to the next multiple of 16.
1217 * - encoding: unused
1218 * - decoding: Set by libavcodec., user can override.
1219 */
1220 int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
1221
1222 /**
1223 * Called to release buffers which were allocated with get_buffer.
1224 * A released buffer can be reused in get_buffer().
1225 * pic.data[*] must be set to NULL.
1226 * - encoding: unused
1227 * - decoding: Set by libavcodec., user can override.
1228 */
1229 void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
1230
1231 /**
1232 * Size of the frame reordering buffer in the decoder.
1233 * For MPEG-2 it is 1 IPB or 0 low delay IP.
1234 * - encoding: Set by libavcodec.
1235 * - decoding: Set by libavcodec.
1236 */
1237 int has_b_frames;
1238
1239 /**
1240 * number of bytes per packet if constant and known or 0
1241 * Used by some WAV based audio codecs.
1242 */
1243 int block_align;
1244
1245 int parse_only; /* - decoding only: If true, only parsing is done
1246 (function avcodec_parse_frame()). The frame
1247 data is returned. Only MPEG codecs support this now. */
1248
1249 /**
1250 * 0-> h263 quant 1-> mpeg quant
1251 * - encoding: Set by user.
1252 * - decoding: unused
1253 */
1254 int mpeg_quant;
1255
1256 /**
1257 * pass1 encoding statistics output buffer
1258 * - encoding: Set by libavcodec.
1259 * - decoding: unused
1260 */
1261 char *stats_out;
1262
1263 /**
1264 * pass2 encoding statistics input buffer
1265 * Concatenated stuff from stats_out of pass1 should be placed here.
1266 * - encoding: Allocated/set/freed by user.
1267 * - decoding: unused
1268 */
1269 char *stats_in;
1270
1271 /**
1272 * ratecontrol qmin qmax limiting method
1273 * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax.
1274 * - encoding: Set by user.
1275 * - decoding: unused
1276 */
1277 float rc_qsquish;
1278
1279 float rc_qmod_amp;
1280 int rc_qmod_freq;
1281
1282 /**
1283 * ratecontrol override, see RcOverride
1284 * - encoding: Allocated/set/freed by user.
1285 * - decoding: unused
1286 */
1287 RcOverride *rc_override;
1288 int rc_override_count;
1289
1290 /**
1291 * rate control equation
1292 * - encoding: Set by user
1293 * - decoding: unused
1294 */
1295 const char *rc_eq;
1296
1297 /**
1298 * maximum bitrate
1299 * - encoding: Set by user.
1300 * - decoding: unused
1301 */
1302 int rc_max_rate;
1303
1304 /**
1305 * minimum bitrate
1306 * - encoding: Set by user.
1307 * - decoding: unused
1308 */
1309 int rc_min_rate;
1310
1311 /**
1312 * decoder bitstream buffer size
1313 * - encoding: Set by user.
1314 * - decoding: unused
1315 */
1316 int rc_buffer_size;
1317 float rc_buffer_aggressivity;
1318
1319 /**
1320 * qscale factor between P and I-frames
1321 * If > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset).
1322 * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
1323 * - encoding: Set by user.
1324 * - decoding: unused
1325 */
1326 float i_quant_factor;
1327
1328 /**
1329 * qscale offset between P and I-frames
1330 * - encoding: Set by user.
1331 * - decoding: unused
1332 */
1333 float i_quant_offset;
1334
1335 /**
1336 * initial complexity for pass1 ratecontrol
1337 * - encoding: Set by user.
1338 * - decoding: unused
1339 */
1340 float rc_initial_cplx;
1341
1342 /**
1343 * DCT algorithm, see FF_DCT_* below
1344 * - encoding: Set by user.
1345 * - decoding: unused
1346 */
1347 int dct_algo;
1348#define FF_DCT_AUTO 0
1349#define FF_DCT_FASTINT 1
1350#define FF_DCT_INT 2
1351#define FF_DCT_MMX 3
1352#define FF_DCT_MLIB 4
1353#define FF_DCT_ALTIVEC 5
1354#define FF_DCT_FAAN 6
1355
1356 /**
1357 * luminance masking (0-> disabled)
1358 * - encoding: Set by user.
1359 * - decoding: unused
1360 */
1361 float lumi_masking;
1362
1363 /**
1364 * temporary complexity masking (0-> disabled)
1365 * - encoding: Set by user.
1366 * - decoding: unused
1367 */
1368 float temporal_cplx_masking;
1369
1370 /**
1371 * spatial complexity masking (0-> disabled)
1372 * - encoding: Set by user.
1373 * - decoding: unused
1374 */
1375 float spatial_cplx_masking;
1376
1377 /**
1378 * p block masking (0-> disabled)
1379 * - encoding: Set by user.
1380 * - decoding: unused
1381 */
1382 float p_masking;
1383
1384 /**
1385 * darkness masking (0-> disabled)
1386 * - encoding: Set by user.
1387 * - decoding: unused
1388 */
1389 float dark_masking;
1390
1391 /**
1392 * IDCT algorithm, see FF_IDCT_* below.
1393 * - encoding: Set by user.
1394 * - decoding: Set by user.
1395 */
1396 int idct_algo;
1397#define FF_IDCT_AUTO 0
1398#define FF_IDCT_INT 1
1399#define FF_IDCT_SIMPLE 2
1400#define FF_IDCT_SIMPLEMMX 3
1401#define FF_IDCT_LIBMPEG2MMX 4
1402#define FF_IDCT_PS2 5
1403#define FF_IDCT_MLIB 6
1404#define FF_IDCT_ARM 7
1405#define FF_IDCT_ALTIVEC 8
1406#define FF_IDCT_SH4 9
1407#define FF_IDCT_SIMPLEARM 10
1408#define FF_IDCT_H264 11
1409#define FF_IDCT_VP3 12
1410#define FF_IDCT_IPP 13
1411#define FF_IDCT_XVIDMMX 14
1412#define FF_IDCT_CAVS 15
1413#define FF_IDCT_SIMPLEARMV5TE 16
1414#define FF_IDCT_SIMPLEARMV6 17
1415#define FF_IDCT_SIMPLEVIS 18
1416#define FF_IDCT_WMV2 19
1417#define FF_IDCT_FAAN 20
1418#define FF_IDCT_EA 21
1419#define FF_IDCT_SIMPLENEON 22
1420#define FF_IDCT_SIMPLEALPHA 23
1421
1422 /**
1423 * slice count
1424 * - encoding: Set by libavcodec.
1425 * - decoding: Set by user (or 0).
1426 */
1427 int slice_count;
1428 /**
1429 * slice offsets in the frame in bytes
1430 * - encoding: Set/allocated by libavcodec.
1431 * - decoding: Set/allocated by user (or NULL).
1432 */
1433 int *slice_offset;
1434
1435 /**
1436 * error concealment flags
1437 * - encoding: unused
1438 * - decoding: Set by user.
1439 */
1440 int error_concealment;
1441#define FF_EC_GUESS_MVS 1
1442#define FF_EC_DEBLOCK 2
1443
1444 /**
1445 * dsp_mask could be add used to disable unwanted CPU features
1446 * CPU features (i.e. MMX, SSE. ...)
1447 *
1448 * With the FORCE flag you may instead enable given CPU features.
1449 * (Dangerous: Usable in case of misdetection, improper usage however will
1450 * result into program crash.)
1451 */
1452 unsigned dsp_mask;
1453#define FF_MM_FORCE 0x80000000 /* Force usage of selected flags (OR) */
1454 /* lower 16 bits - CPU features */
1455#define FF_MM_MMX 0x0001 ///< standard MMX
1456#define FF_MM_3DNOW 0x0004 ///< AMD 3DNOW
1457#define FF_MM_MMXEXT 0x0002 ///< SSE integer functions or AMD MMX ext
1458#define FF_MM_SSE 0x0008 ///< SSE functions
1459#define FF_MM_SSE2 0x0010 ///< PIV SSE2 functions
1460#define FF_MM_3DNOWEXT 0x0020 ///< AMD 3DNowExt
1461#define FF_MM_SSE3 0x0040 ///< Prescott SSE3 functions
1462#define FF_MM_SSSE3 0x0080 ///< Conroe SSSE3 functions
1463#define FF_MM_IWMMXT 0x0100 ///< XScale IWMMXT
1464#define FF_MM_ALTIVEC 0x0001 ///< standard AltiVec
1465
1466 /**
1467 * bits per sample/pixel from the demuxer (needed for huffyuv).
1468 * - encoding: Set by libavcodec.
1469 * - decoding: Set by user.
1470 */
1471 int bits_per_coded_sample;
1472
1473 /**
1474 * prediction method (needed for huffyuv)
1475 * - encoding: Set by user.
1476 * - decoding: unused
1477 */
1478 int prediction_method;
1479#define FF_PRED_LEFT 0
1480#define FF_PRED_PLANE 1
1481#define FF_PRED_MEDIAN 2
1482
1483 /**
1484 * sample aspect ratio (0 if unknown)
1485 * That is the width of a pixel divided by the height of the pixel.
1486 * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
1487 * - encoding: Set by user.
1488 * - decoding: Set by libavcodec.
1489 */
1490 AVRational sample_aspect_ratio;
1491
1492 /**
1493 * the picture in the bitstream
1494 * - encoding: Set by libavcodec.
1495 * - decoding: Set by libavcodec.
1496 */
1497 AVFrame *coded_frame;
1498
1499 /**
1500 * debug
1501 * - encoding: Set by user.
1502 * - decoding: Set by user.
1503 */
1504 int debug;
1505#define FF_DEBUG_PICT_INFO 1
1506#define FF_DEBUG_RC 2
1507#define FF_DEBUG_BITSTREAM 4
1508#define FF_DEBUG_MB_TYPE 8
1509#define FF_DEBUG_QP 16
1510#define FF_DEBUG_MV 32
1511#define FF_DEBUG_DCT_COEFF 0x00000040
1512#define FF_DEBUG_SKIP 0x00000080
1513#define FF_DEBUG_STARTCODE 0x00000100
1514#define FF_DEBUG_PTS 0x00000200
1515#define FF_DEBUG_ER 0x00000400
1516#define FF_DEBUG_MMCO 0x00000800
1517#define FF_DEBUG_BUGS 0x00001000
1518#define FF_DEBUG_VIS_QP 0x00002000
1519#define FF_DEBUG_VIS_MB_TYPE 0x00004000
1520#define FF_DEBUG_BUFFERS 0x00008000
1521
1522 /**
1523 * debug
1524 * - encoding: Set by user.
1525 * - decoding: Set by user.
1526 */
1527 int debug_mv;
1528#define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames
1529#define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames
1530#define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
1531
1532 /**
1533 * error
1534 * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR.
1535 * - decoding: unused
1536 */
1537 uint64_t error[4];
1538
1539 /**
1540 * minimum MB quantizer
1541 * - encoding: unused
1542 * - decoding: unused
1543 */
1544 int mb_qmin;
1545
1546 /**
1547 * maximum MB quantizer
1548 * - encoding: unused
1549 * - decoding: unused
1550 */
1551 int mb_qmax;
1552
1553 /**
1554 * motion estimation comparison function
1555 * - encoding: Set by user.
1556 * - decoding: unused
1557 */
1558 int me_cmp;
1559 /**
1560 * subpixel motion estimation comparison function
1561 * - encoding: Set by user.
1562 * - decoding: unused
1563 */
1564 int me_sub_cmp;
1565 /**
1566 * macroblock comparison function (not supported yet)
1567 * - encoding: Set by user.
1568 * - decoding: unused
1569 */
1570 int mb_cmp;
1571 /**
1572 * interlaced DCT comparison function
1573 * - encoding: Set by user.
1574 * - decoding: unused
1575 */
1576 int ildct_cmp;
1577#define FF_CMP_SAD 0
1578#define FF_CMP_SSE 1
1579#define FF_CMP_SATD 2
1580#define FF_CMP_DCT 3
1581#define FF_CMP_PSNR 4
1582#define FF_CMP_BIT 5
1583#define FF_CMP_RD 6
1584#define FF_CMP_ZERO 7
1585#define FF_CMP_VSAD 8
1586#define FF_CMP_VSSE 9
1587#define FF_CMP_NSSE 10
1588#define FF_CMP_W53 11
1589#define FF_CMP_W97 12
1590#define FF_CMP_DCTMAX 13
1591#define FF_CMP_DCT264 14
1592#define FF_CMP_CHROMA 256
1593
1594 /**
1595 * ME diamond size & shape
1596 * - encoding: Set by user.
1597 * - decoding: unused
1598 */
1599 int dia_size;
1600
1601 /**
1602 * amount of previous MV predictors (2a+1 x 2a+1 square)
1603 * - encoding: Set by user.
1604 * - decoding: unused
1605 */
1606 int last_predictor_count;
1607
1608 /**
1609 * prepass for motion estimation
1610 * - encoding: Set by user.
1611 * - decoding: unused
1612 */
1613 int pre_me;
1614
1615 /**
1616 * motion estimation prepass comparison function
1617 * - encoding: Set by user.
1618 * - decoding: unused
1619 */
1620 int me_pre_cmp;
1621
1622 /**
1623 * ME prepass diamond size & shape
1624 * - encoding: Set by user.
1625 * - decoding: unused
1626 */
1627 int pre_dia_size;
1628
1629 /**
1630 * subpel ME quality
1631 * - encoding: Set by user.
1632 * - decoding: unused
1633 */
1634 int me_subpel_quality;
1635
1636 /**
1637 * callback to negotiate the pixelFormat
1638 * @param fmt is the list of formats which are supported by the codec,
1639 * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
1640 * The first is always the native one.
1641 * @return the chosen format
1642 * - encoding: unused
1643 * - decoding: Set by user, if not set the native format will be chosen.
1644 */
1645 enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt);
1646
1647 /**
1648 * DTG active format information (additional aspect ratio
1649 * information only used in DVB MPEG-2 transport streams)
1650 * 0 if not set.
1651 *
1652 * - encoding: unused
1653 * - decoding: Set by decoder.
1654 */
1655 int dtg_active_format;
1656#define FF_DTG_AFD_SAME 8
1657#define FF_DTG_AFD_4_3 9
1658#define FF_DTG_AFD_16_9 10
1659#define FF_DTG_AFD_14_9 11
1660#define FF_DTG_AFD_4_3_SP_14_9 13
1661#define FF_DTG_AFD_16_9_SP_14_9 14
1662#define FF_DTG_AFD_SP_4_3 15
1663
1664 /**
1665 * maximum motion estimation search range in subpel units
1666 * If 0 then no limit.
1667 *
1668 * - encoding: Set by user.
1669 * - decoding: unused
1670 */
1671 int me_range;
1672
1673 /**
1674 * intra quantizer bias
1675 * - encoding: Set by user.
1676 * - decoding: unused
1677 */
1678 int intra_quant_bias;
1679#define FF_DEFAULT_QUANT_BIAS 999999
1680
1681 /**
1682 * inter quantizer bias
1683 * - encoding: Set by user.
1684 * - decoding: unused
1685 */
1686 int inter_quant_bias;
1687
1688 /**
1689 * color table ID
1690 * - encoding: unused
1691 * - decoding: Which clrtable should be used for 8bit RGB images.
1692 * Tables have to be stored somewhere. FIXME
1693 */
1694 int color_table_id;
1695
1696 /**
1697 * internal_buffer count
1698 * Don't touch, used by libavcodec default_get_buffer().
1699 */
1700 int internal_buffer_count;
1701
1702 /**
1703 * internal_buffers
1704 * Don't touch, used by libavcodec default_get_buffer().
1705 */
1706 void *internal_buffer;
1707
1708#define FF_LAMBDA_SHIFT 7
1709#define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT)
1710#define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
1711#define FF_LAMBDA_MAX (256*128-1)
1712
1713#define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove
1714 /**
1715 * Global quality for codecs which cannot change it per frame.
1716 * This should be proportional to MPEG-1/2/4 qscale.
1717 * - encoding: Set by user.
1718 * - decoding: unused
1719 */
1720 int global_quality;
1721
1722#define FF_CODER_TYPE_VLC 0
1723#define FF_CODER_TYPE_AC 1
1724#define FF_CODER_TYPE_RAW 2
1725#define FF_CODER_TYPE_RLE 3
1726#define FF_CODER_TYPE_DEFLATE 4
1727 /**
1728 * coder type
1729 * - encoding: Set by user.
1730 * - decoding: unused
1731 */
1732 int coder_type;
1733
1734 /**
1735 * context model
1736 * - encoding: Set by user.
1737 * - decoding: unused
1738 */
1739 int context_model;
1740#if 0
1741 /**
1742 *
1743 * - encoding: unused
1744 * - decoding: Set by user.
1745 */
1746 uint8_t * (*realloc)(struct AVCodecContext *s, uint8_t *buf, int buf_size);
1747#endif
1748
1749 /**
1750 * slice flags
1751 * - encoding: unused
1752 * - decoding: Set by user.
1753 */
1754 int slice_flags;
1755#define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
1756#define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
1757#define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
1758
1759 /**
1760 * XVideo Motion Acceleration
1761 * - encoding: forbidden
1762 * - decoding: set by decoder
1763 */
1764 int xvmc_acceleration;
1765
1766 /**
1767 * macroblock decision mode
1768 * - encoding: Set by user.
1769 * - decoding: unused
1770 */
1771 int mb_decision;
1772#define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
1773#define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
1774#define FF_MB_DECISION_RD 2 ///< rate distortion
1775
1776 /**
1777 * custom intra quantization matrix
1778 * - encoding: Set by user, can be NULL.
1779 * - decoding: Set by libavcodec.
1780 */
1781 uint16_t *intra_matrix;
1782
1783 /**
1784 * custom inter quantization matrix
1785 * - encoding: Set by user, can be NULL.
1786 * - decoding: Set by libavcodec.
1787 */
1788 uint16_t *inter_matrix;
1789
1790 /**
1791 * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
1792 * This is used to work around some encoder bugs.
1793 * - encoding: unused
1794 * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
1795 */
1796 unsigned int stream_codec_tag;
1797
1798 /**
1799 * scene change detection threshold
1800 * 0 is default, larger means fewer detected scene changes.
1801 * - encoding: Set by user.
1802 * - decoding: unused
1803 */
1804 int scenechange_threshold;
1805
1806 /**
1807 * minimum Lagrange multipler
1808 * - encoding: Set by user.
1809 * - decoding: unused
1810 */
1811 int lmin;
1812
1813 /**
1814 * maximum Lagrange multipler
1815 * - encoding: Set by user.
1816 * - decoding: unused
1817 */
1818 int lmax;
1819
1820 /**
1821 * palette control structure
1822 * - encoding: ??? (no palette-enabled encoder yet)
1823 * - decoding: Set by user.
1824 */
1825 struct AVPaletteControl *palctrl;
1826
1827 /**
1828 * noise reduction strength
1829 * - encoding: Set by user.
1830 * - decoding: unused
1831 */
1832 int noise_reduction;
1833
1834 /**
1835 * Called at the beginning of a frame to get cr buffer for it.
1836 * Buffer type (size, hints) must be the same. libavcodec won't check it.
1837 * libavcodec will pass previous buffer in pic, function should return
1838 * same buffer or new buffer with old frame "painted" into it.
1839 * If pic.data[0] == NULL must behave like get_buffer().
1840 * - encoding: unused
1841 * - decoding: Set by libavcodec., user can override
1842 */
1843 int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
1844
1845 /**
1846 * Number of bits which should be loaded into the rc buffer before decoding starts.
1847 * - encoding: Set by user.
1848 * - decoding: unused
1849 */
1850 int rc_initial_buffer_occupancy;
1851
1852 /**
1853 *
1854 * - encoding: Set by user.
1855 * - decoding: unused
1856 */
1857 int inter_threshold;
1858
1859 /**
1860 * CODEC_FLAG2_*
1861 * - encoding: Set by user.
1862 * - decoding: Set by user.
1863 */
1864 int flags2;
1865
1866 /**
1867 * Simulates errors in the bitstream to test error concealment.
1868 * - encoding: Set by user.
1869 * - decoding: unused
1870 */
1871 int error_rate;
1872
1873 /**
1874 * MP3 antialias algorithm, see FF_AA_* below.
1875 * - encoding: unused
1876 * - decoding: Set by user.
1877 */
1878 int antialias_algo;
1879#define FF_AA_AUTO 0
1880#define FF_AA_FASTINT 1 //not implemented yet
1881#define FF_AA_INT 2
1882#define FF_AA_FLOAT 3
1883 /**
1884 * quantizer noise shaping
1885 * - encoding: Set by user.
1886 * - decoding: unused
1887 */
1888 int quantizer_noise_shaping;
1889
1890 /**
1891 * thread count
1892 * is used to decide how many independent tasks should be passed to execute()
1893 * - encoding: Set by user.
1894 * - decoding: Set by user.
1895 */
1896 int thread_count;
1897
1898 /**
1899 * The codec may call this to execute several independent things.
1900 * It will return only after finishing all tasks.
1901 * The user may replace this with some multithreaded implementation,
1902 * the default implementation will execute the parts serially.
1903 * @param count the number of things to execute
1904 * - encoding: Set by libavcodec, user can override.
1905 * - decoding: Set by libavcodec, user can override.
1906 */
1907 int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
1908
1909 /**
1910 * thread opaque
1911 * Can be used by execute() to store some per AVCodecContext stuff.
1912 * - encoding: set by execute()
1913 * - decoding: set by execute()
1914 */
1915 void *thread_opaque;
1916
1917 /**
1918 * Motion estimation threshold below which no motion estimation is
1919 * performed, but instead the user specified motion vectors are used.
1920 *
1921 * - encoding: Set by user.
1922 * - decoding: unused
1923 */
1924 int me_threshold;
1925
1926 /**
1927 * Macroblock threshold below which the user specified macroblock types will be used.
1928 * - encoding: Set by user.
1929 * - decoding: unused
1930 */
1931 int mb_threshold;
1932
1933 /**
1934 * precision of the intra DC coefficient - 8
1935 * - encoding: Set by user.
1936 * - decoding: unused
1937 */
1938 int intra_dc_precision;
1939
1940 /**
1941 * noise vs. sse weight for the nsse comparsion function
1942 * - encoding: Set by user.
1943 * - decoding: unused
1944 */
1945 int nsse_weight;
1946
1947 /**
1948 * Number of macroblock rows at the top which are skipped.
1949 * - encoding: unused
1950 * - decoding: Set by user.
1951 */
1952 int skip_top;
1953
1954 /**
1955 * Number of macroblock rows at the bottom which are skipped.
1956 * - encoding: unused
1957 * - decoding: Set by user.
1958 */
1959 int skip_bottom;
1960
1961 /**
1962 * profile
1963 * - encoding: Set by user.
1964 * - decoding: Set by libavcodec.
1965 */
1966 int profile;
1967#define FF_PROFILE_UNKNOWN -99
1968#define FF_PROFILE_AAC_MAIN 0
1969#define FF_PROFILE_AAC_LOW 1
1970#define FF_PROFILE_AAC_SSR 2
1971#define FF_PROFILE_AAC_LTP 3
1972
1973 /**
1974 * level
1975 * - encoding: Set by user.
1976 * - decoding: Set by libavcodec.
1977 */
1978 int level;
1979#define FF_LEVEL_UNKNOWN -99
1980
1981 /**
1982 * low resolution decoding, 1-> 1/2 size, 2->1/4 size
1983 * - encoding: unused
1984 * - decoding: Set by user.
1985 */
1986 int lowres;
1987
1988 /**
1989 * Bitstream width / height, may be different from width/height if lowres
1990 * or other things are used.
1991 * - encoding: unused
1992 * - decoding: Set by user before init if known. Codec should override / dynamically change if needed.
1993 */
1994 int coded_width, coded_height;
1995
1996 /**
1997 * frame skip threshold
1998 * - encoding: Set by user.
1999 * - decoding: unused
2000 */
2001 int frame_skip_threshold;
2002
2003 /**
2004 * frame skip factor
2005 * - encoding: Set by user.
2006 * - decoding: unused
2007 */
2008 int frame_skip_factor;
2009
2010 /**
2011 * frame skip exponent
2012 * - encoding: Set by user.
2013 * - decoding: unused
2014 */
2015 int frame_skip_exp;
2016
2017 /**
2018 * frame skip comparison function
2019 * - encoding: Set by user.
2020 * - decoding: unused
2021 */
2022 int frame_skip_cmp;
2023
2024 /**
2025 * Border processing masking, raises the quantizer for mbs on the borders
2026 * of the picture.
2027 * - encoding: Set by user.
2028 * - decoding: unused
2029 */
2030 float border_masking;
2031
2032 /**
2033 * minimum MB lagrange multipler
2034 * - encoding: Set by user.
2035 * - decoding: unused
2036 */
2037 int mb_lmin;
2038
2039 /**
2040 * maximum MB lagrange multipler
2041 * - encoding: Set by user.
2042 * - decoding: unused
2043 */
2044 int mb_lmax;
2045
2046 /**
2047 *
2048 * - encoding: Set by user.
2049 * - decoding: unused
2050 */
2051 int me_penalty_compensation;
2052
2053 /**
2054 *
2055 * - encoding: unused
2056 * - decoding: Set by user.
2057 */
2058 enum AVDiscard skip_loop_filter;
2059
2060 /**
2061 *
2062 * - encoding: unused
2063 * - decoding: Set by user.
2064 */
2065 enum AVDiscard skip_idct;
2066
2067 /**
2068 *
2069 * - encoding: unused
2070 * - decoding: Set by user.
2071 */
2072 enum AVDiscard skip_frame;
2073
2074 /**
2075 *
2076 * - encoding: Set by user.
2077 * - decoding: unused
2078 */
2079 int bidir_refine;
2080
2081 /**
2082 *
2083 * - encoding: Set by user.
2084 * - decoding: unused
2085 */
2086 int brd_scale;
2087
2088 /**
2089 * constant rate factor - quality-based VBR - values ~correspond to qps
2090 * - encoding: Set by user.
2091 * - decoding: unused
2092 */
2093 float crf;
2094
2095 /**
2096 * constant quantization parameter rate control method
2097 * - encoding: Set by user.
2098 * - decoding: unused
2099 */
2100 int cqp;
2101
2102 /**
2103 * minimum GOP size
2104 * - encoding: Set by user.
2105 * - decoding: unused
2106 */
2107 int keyint_min;
2108
2109 /**
2110 * number of reference frames
2111 * - encoding: Set by user.
2112 * - decoding: Set by lavc.
2113 */
2114 int refs;
2115
2116 /**
2117 * chroma qp offset from luma
2118 * - encoding: Set by user.
2119 * - decoding: unused
2120 */
2121 int chromaoffset;
2122
2123 /**
2124 * Influences how often B-frames are used.
2125 * - encoding: Set by user.
2126 * - decoding: unused
2127 */
2128 int bframebias;
2129
2130 /**
2131 * trellis RD quantization
2132 * - encoding: Set by user.
2133 * - decoding: unused
2134 */
2135 int trellis;
2136
2137 /**
2138 * Reduce fluctuations in qp (before curve compression).
2139 * - encoding: Set by user.
2140 * - decoding: unused
2141 */
2142 float complexityblur;
2143
2144 /**
2145 * in-loop deblocking filter alphac0 parameter
2146 * alpha is in the range -6...6
2147 * - encoding: Set by user.
2148 * - decoding: unused
2149 */
2150 int deblockalpha;
2151
2152 /**
2153 * in-loop deblocking filter beta parameter
2154 * beta is in the range -6...6
2155 * - encoding: Set by user.
2156 * - decoding: unused
2157 */
2158 int deblockbeta;
2159
2160 /**
2161 * macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4
2162 * - encoding: Set by user.
2163 * - decoding: unused
2164 */
2165 int partitions;
2166#define X264_PART_I4X4 0x001 /* Analyze i4x4 */
2167#define X264_PART_I8X8 0x002 /* Analyze i8x8 (requires 8x8 transform) */
2168#define X264_PART_P8X8 0x010 /* Analyze p16x8, p8x16 and p8x8 */
2169#define X264_PART_P4X4 0x020 /* Analyze p8x4, p4x8, p4x4 */
2170#define X264_PART_B8X8 0x100 /* Analyze b16x8, b8x16 and b8x8 */
2171
2172 /**
2173 * direct MV prediction mode - 0 (none), 1 (spatial), 2 (temporal), 3 (auto)
2174 * - encoding: Set by user.
2175 * - decoding: unused
2176 */
2177 int directpred;
2178
2179 /**
2180 * Audio cutoff bandwidth (0 means "automatic")
2181 * - encoding: Set by user.
2182 * - decoding: unused
2183 */
2184 int cutoff;
2185
2186 /**
2187 * Multiplied by qscale for each frame and added to scene_change_score.
2188 * - encoding: Set by user.
2189 * - decoding: unused
2190 */
2191 int scenechange_factor;
2192
2193 /**
2194 *
2195 * Note: Value depends upon the compare function used for fullpel ME.
2196 * - encoding: Set by user.
2197 * - decoding: unused
2198 */
2199 int mv0_threshold;
2200
2201 /**
2202 * Adjusts sensitivity of b_frame_strategy 1.
2203 * - encoding: Set by user.
2204 * - decoding: unused
2205 */
2206 int b_sensitivity;
2207
2208 /**
2209 * - encoding: Set by user.
2210 * - decoding: unused
2211 */
2212 int compression_level;
2213#define FF_COMPRESSION_DEFAULT -1
2214
2215 /**
2216 * Sets whether to use LPC mode - used by FLAC encoder.
2217 * - encoding: Set by user.
2218 * - decoding: unused
2219 */
2220 int use_lpc;
2221
2222 /**
2223 * LPC coefficient precision - used by FLAC encoder
2224 * - encoding: Set by user.
2225 * - decoding: unused
2226 */
2227 int lpc_coeff_precision;
2228
2229 /**
2230 * - encoding: Set by user.
2231 * - decoding: unused
2232 */
2233 int min_prediction_order;
2234
2235 /**
2236 * - encoding: Set by user.
2237 * - decoding: unused
2238 */
2239 int max_prediction_order;
2240
2241 /**
2242 * search method for selecting prediction order
2243 * - encoding: Set by user.
2244 * - decoding: unused
2245 */
2246 int prediction_order_method;
2247
2248 /**
2249 * - encoding: Set by user.
2250 * - decoding: unused
2251 */
2252 int min_partition_order;
2253
2254 /**
2255 * - encoding: Set by user.
2256 * - decoding: unused
2257 */
2258 int max_partition_order;
2259
2260 /**
2261 * GOP timecode frame start number, in non drop frame format
2262 * - encoding: Set by user.
2263 * - decoding: unused
2264 */
2265 int64_t timecode_frame_start;
2266
2267#if LIBAVCODEC_VERSION_MAJOR < 53
2268 /**
2269 * Decoder should decode to this many channels if it can (0 for default)
2270 * - encoding: unused
2271 * - decoding: Set by user.
2272 * @deprecated Deprecated in favor of request_channel_layout.
2273 */
2274 int request_channels;
2275#endif
2276
2277 /**
2278 * Percentage of dynamic range compression to be applied by the decoder.
2279 * The default value is 1.0, corresponding to full compression.
2280 * - encoding: unused
2281 * - decoding: Set by user.
2282 */
2283 float drc_scale;
2284
2285 /**
2286 * opaque 64bit number (generally a PTS) that will be reordered and
2287 * output in AVFrame.reordered_opaque
2288 * - encoding: unused
2289 * - decoding: Set by user.
2290 */
2291 int64_t reordered_opaque;
2292
2293 /**
2294 * Bits per sample/pixel of internal libavcodec pixel/sample format.
2295 * This field is applicable only when sample_fmt is SAMPLE_FMT_S32.
2296 * - encoding: set by user.
2297 * - decoding: set by libavcodec.
2298 */
2299 int bits_per_raw_sample;
2300
2301 /**
2302 * Audio channel layout.
2303 * - encoding: set by user.
2304 * - decoding: set by libavcodec.
2305 */
2306 int64_t channel_layout;
2307
2308 /**
2309 * Request decoder to use this channel layout if it can (0 for default)
2310 * - encoding: unused
2311 * - decoding: Set by user.
2312 */
2313 int64_t request_channel_layout;
2314
2315 /**
2316 * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
2317 * - encoding: Set by user.
2318 * - decoding: unused.
2319 */
2320 float rc_max_available_vbv_use;
2321
2322 /**
2323 * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
2324 * - encoding: Set by user.
2325 * - decoding: unused.
2326 */
2327 float rc_min_vbv_overflow_use;
2328
2329 /**
2330 * Hardware accelerator in use
2331 * - encoding: unused.
2332 * - decoding: Set by libavcodec
2333 */
2334 struct AVHWAccel *hwaccel;
2335
2336 /**
2337 * For some codecs, the time base is closer to the field rate than the frame rate.
2338 * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
2339 * if no telecine is used ...
2340 *
2341 * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
2342 */
2343 int ticks_per_frame;
2344
2345 /**
2346 * Hardware accelerator context.
2347 * For some hardware accelerators, a global context needs to be
2348 * provided by the user. In that case, this holds display-dependent
2349 * data FFmpeg cannot instantiate itself. Please refer to the
2350 * FFmpeg HW accelerator documentation to know how to fill this
2351 * is. e.g. for VA API, this is a struct vaapi_context.
2352 * - encoding: unused
2353 * - decoding: Set by user
2354 */
2355 void *hwaccel_context;
2356} AVCodecContext;
2357
2358/**
2359 * AVCodec.
2360 */
2361typedef struct AVCodec {
2362 /**
2363 * Name of the codec implementation.
2364 * The name is globally unique among encoders and among decoders (but an
2365 * encoder and a decoder can share the same name).
2366 * This is the primary way to find a codec from the user perspective.
2367 */
2368 const char *name;
2369 enum CodecType type;
2370 enum CodecID id;
2371 int priv_data_size;
2372 int (*init)(AVCodecContext *);
2373 int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
2374 int (*close)(AVCodecContext *);
2375 int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
2376 const uint8_t *buf, int buf_size);
2377 /**
2378 * Codec capabilities.
2379 * see CODEC_CAP_*
2380 */
2381 int capabilities;
2382 struct AVCodec *next;
2383 /**
2384 * Flush buffers.
2385 * Will be called when seeking
2386 */
2387 void (*flush)(AVCodecContext *);
2388 const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
2389 const enum PixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
2390 /**
2391 * Descriptive name for the codec, meant to be more human readable than \p name.
2392 * You \e should use the NULL_IF_CONFIG_SMALL() macro to define it.
2393 */
2394 const char *long_name;
2395 const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
2396 const enum SampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
2397 const int64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
2398} AVCodec;
2399
2400/**
2401 * AVHWAccel.
2402 */
2403typedef struct AVHWAccel {
2404 /**
2405 * Name of the hardware accelerated codec.
2406 * The name is globally unique among encoders and among decoders (but an
2407 * encoder and a decoder can share the same name).
2408 */
2409 const char *name;
2410
2411 /**
2412 * Type of codec implemented by the hardware accelerator.
2413 *
2414 * See CODEC_TYPE_xxx
2415 */
2416 enum CodecType type;
2417
2418 /**
2419 * Codec implemented by the hardware accelerator.
2420 *
2421 * See CODEC_ID_xxx
2422 */
2423 enum CodecID id;
2424
2425 /**
2426 * Supported pixel format.
2427 *
2428 * Only hardware accelerated formats are supported here.
2429 */
2430 enum PixelFormat pix_fmt;
2431
2432 /**
2433 * Hardware accelerated codec capabilities.
2434 * see FF_HWACCEL_CODEC_CAP_*
2435 */
2436 int capabilities;
2437
2438 struct AVHWAccel *next;
2439
2440 /**
2441 * Called at the beginning of each frame or field picture.
2442 *
2443 * Meaningful frame information (codec specific) is guaranteed to
2444 * be parsed at this point. This function is mandatory.
2445 *
2446 * Note that \p buf can be NULL along with \p buf_size set to 0.
2447 * Otherwise, this means the whole frame is available at this point.
2448 *
2449 * @param avctx the codec context
2450 * @param buf the frame data buffer base
2451 * @param buf_size the size of the frame in bytes
2452 * @return zero if successful, a negative value otherwise
2453 */
2454 int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
2455
2456 /**
2457 * Callback for each slice.
2458 *
2459 * Meaningful slice information (codec specific) is guaranteed to
2460 * be parsed at this point. This function is mandatory.
2461 *
2462 * @param avctx the codec context
2463 * @param buf the slice data buffer base
2464 * @param buf_size the size of the slice in bytes
2465 * @return zero if successful, a negative value otherwise
2466 */
2467 int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
2468
2469 /**
2470 * Called at the end of each frame or field picture.
2471 *
2472 * The whole picture is parsed at this point and can now be sent
2473 * to the hardware accelerator. This function is mandatory.
2474 *
2475 * @param avctx the codec context
2476 * @return zero if successful, a negative value otherwise
2477 */
2478 int (*end_frame)(AVCodecContext *avctx);
2479
2480 /**
2481 * Size of HW accelerator private data.
2482 *
2483 * Private data is allocated with av_mallocz() before
2484 * AVCodecContext.get_buffer() and deallocated after
2485 * AVCodecContext.release_buffer().
2486 */
2487 int priv_data_size;
2488} AVHWAccel;
2489
2490/**
2491 * four components are given, that's all.
2492 * the last component is alpha
2493 */
2494typedef struct AVPicture {
2495 uint8_t *data[4];
2496 int linesize[4]; ///< number of bytes per line
2497} AVPicture;
2498
2499/**
2500 * AVPaletteControl
2501 * This structure defines a method for communicating palette changes
2502 * between and demuxer and a decoder.
2503 *
2504 * @deprecated Use AVPacket to send palette changes instead.
2505 * This is totally broken.
2506 */
2507#define AVPALETTE_SIZE 1024
2508#define AVPALETTE_COUNT 256
2509typedef struct AVPaletteControl {
2510
2511 /* Demuxer sets this to 1 to indicate the palette has changed;
2512 * decoder resets to 0. */
2513 int palette_changed;
2514
2515 /* 4-byte ARGB palette entries, stored in native byte order; note that
2516 * the individual palette components should be on a 8-bit scale; if
2517 * the palette data comes from an IBM VGA native format, the component
2518 * data is probably 6 bits in size and needs to be scaled. */
2519 unsigned int palette[AVPALETTE_COUNT];
2520
2521} AVPaletteControl attribute_deprecated;
2522
2523enum AVSubtitleType {
2524 SUBTITLE_NONE,
2525
2526 SUBTITLE_BITMAP, ///< A bitmap, pict will be set
2527
2528 /**
2529 * Plain text, the text field must be set by the decoder and is
2530 * authoritative. ass and pict fields may contain approximations.
2531 */
2532 SUBTITLE_TEXT,
2533
2534 /**
2535 * Formatted text, the ass field must be set by the decoder and is
2536 * authoritative. pict and text fields may contain approximations.
2537 */
2538 SUBTITLE_ASS,
2539};
2540
2541typedef struct AVSubtitleRect {
2542 int x; ///< top left corner of pict, undefined when pict is not set
2543 int y; ///< top left corner of pict, undefined when pict is not set
2544 int w; ///< width of pict, undefined when pict is not set
2545 int h; ///< height of pict, undefined when pict is not set
2546 int nb_colors; ///< number of colors in pict, undefined when pict is not set
2547
2548 /**
2549 * data+linesize for the bitmap of this subtitle.
2550 * can be set for text/ass as well once they where rendered
2551 */
2552 AVPicture pict;
2553 enum AVSubtitleType type;
2554
2555 char *text; ///< 0 terminated plain UTF-8 text
2556
2557 /**
2558 * 0 terminated ASS/SSA compatible event line.
2559 * The pressentation of this is unaffected by the other values in this
2560 * struct.
2561 */
2562 char *ass;
2563} AVSubtitleRect;
2564
2565typedef struct AVSubtitle {
2566 uint16_t format; /* 0 = graphics */
2567 uint32_t start_display_time; /* relative to packet pts, in ms */
2568 uint32_t end_display_time; /* relative to packet pts, in ms */
2569 unsigned num_rects;
2570 AVSubtitleRect **rects;
2571} AVSubtitle;
2572
2573
2574/* resample.c */
2575
2576struct ReSampleContext;
2577struct AVResampleContext;
2578
2579typedef struct ReSampleContext ReSampleContext;
2580
2581#if LIBAVCODEC_VERSION_MAJOR < 53
2582/**
2583 * @deprecated Use av_audio_resample_init() instead.
2584 */
2585attribute_deprecated ReSampleContext *audio_resample_init(int output_channels, int input_channels,
2586 int output_rate, int input_rate);
2587#endif
2588/**
2589 * Initializes audio resampling context
2590 *
2591 * @param output_channels number of output channels
2592 * @param input_channels number of input channels
2593 * @param output_rate output sample rate
2594 * @param input_rate input sample rate
2595 * @param sample_fmt_out requested output sample format
2596 * @param sample_fmt_in input sample format
2597 * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq
2598 * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
2599 * @param linear If 1 then the used FIR filter will be linearly interpolated
2600 between the 2 closest, if 0 the closest will be used
2601 * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
2602 * @return allocated ReSampleContext, NULL if error occured
2603 */
2604ReSampleContext *av_audio_resample_init(int output_channels, int input_channels,
2605 int output_rate, int input_rate,
2606 enum SampleFormat sample_fmt_out,
2607 enum SampleFormat sample_fmt_in,
2608 int filter_length, int log2_phase_count,
2609 int linear, double cutoff);
2610
2611int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
2612void audio_resample_close(ReSampleContext *s);
2613
2614
2615/**
2616 * Initializes an audio resampler.
2617 * Note, if either rate is not an integer then simply scale both rates up so they are.
2618 * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq
2619 * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
2620 * @param linear If 1 then the used FIR filter will be linearly interpolated
2621 between the 2 closest, if 0 the closest will be used
2622 * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
2623 */
2624struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff);
2625
2626/**
2627 * resamples.
2628 * @param src an array of unconsumed samples
2629 * @param consumed the number of samples of src which have been consumed are returned here
2630 * @param src_size the number of unconsumed samples available
2631 * @param dst_size the amount of space in samples available in dst
2632 * @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.
2633 * @return the number of samples written in dst or -1 if an error occurred
2634 */
2635int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
2636
2637
2638/**
2639 * Compensates samplerate/timestamp drift. The compensation is done by changing
2640 * the resampler parameters, so no audible clicks or similar distortions occur
2641 * @param compensation_distance distance in output samples over which the compensation should be performed
2642 * @param sample_delta number of output samples which should be output less
2643 *
2644 * example: av_resample_compensate(c, 10, 500)
2645 * here instead of 510 samples only 500 samples would be output
2646 *
2647 * note, due to rounding the actual compensation might be slightly different,
2648 * especially if the compensation_distance is large and the in_rate used during init is small
2649 */
2650void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
2651void av_resample_close(struct AVResampleContext *c);
2652
2653/**
2654 * Allocate memory for a picture. Call avpicture_free to free it.
2655 *
2656 * @param picture the picture to be filled in
2657 * @param pix_fmt the format of the picture
2658 * @param width the width of the picture
2659 * @param height the height of the picture
2660 * @return zero if successful, a negative value if not
2661 */
2662int avpicture_alloc(AVPicture *picture, int pix_fmt, int width, int height);
2663
2664/**
2665 * Free a picture previously allocated by avpicture_alloc().
2666 *
2667 * @param picture the AVPicture to be freed
2668 */
2669void avpicture_free(AVPicture *picture);
2670
2671/**
2672 * Fill in the AVPicture fields.
2673 * The fields of the given AVPicture are filled in by using the 'ptr' address
2674 * which points to the image data buffer. Depending on the specified picture
2675 * format, one or multiple image data pointers and line sizes will be set.
2676 * If a planar format is specified, several pointers will be set pointing to
2677 * the different picture planes and the line sizes of the different planes
2678 * will be stored in the lines_sizes array.
2679 *
2680 * @param picture AVPicture whose fields are to be filled in
2681 * @param ptr Buffer which will contain or contains the actual image data
2682 * @param pix_fmt The format in which the picture data is stored.
2683 * @param width the width of the image in pixels
2684 * @param height the height of the image in pixels
2685 * @return size of the image data in bytes
2686 */
2687int avpicture_fill(AVPicture *picture, uint8_t *ptr,
2688 int pix_fmt, int width, int height);
2689int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
2690 unsigned char *dest, int dest_size);
2691
2692/**
2693 * Calculate the size in bytes that a picture of the given width and height
2694 * would occupy if stored in the given picture format.
2695 *
2696 * @param pix_fmt the given picture format
2697 * @param width the width of the image
2698 * @param height the height of the image
2699 * @return Image data size in bytes
2700 */
2701int avpicture_get_size(int pix_fmt, int width, int height);
2702void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
2703const char *avcodec_get_pix_fmt_name(int pix_fmt);
2704void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
2705enum PixelFormat avcodec_get_pix_fmt(const char* name);
2706unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat p);
2707
2708#define FF_LOSS_RESOLUTION 0x0001 /**< loss due to resolution change */
2709#define FF_LOSS_DEPTH 0x0002 /**< loss due to color depth change */
2710#define FF_LOSS_COLORSPACE 0x0004 /**< loss due to color space conversion */
2711#define FF_LOSS_ALPHA 0x0008 /**< loss of alpha bits */
2712#define FF_LOSS_COLORQUANT 0x0010 /**< loss due to color quantization */
2713#define FF_LOSS_CHROMA 0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */
2714
2715/**
2716 * Computes what kind of losses will occur when converting from one specific
2717 * pixel format to another.
2718 * When converting from one pixel format to another, information loss may occur.
2719 * For example, when converting from RGB24 to GRAY, the color information will
2720 * be lost. Similarly, other losses occur when converting from some formats to
2721 * other formats. These losses can involve loss of chroma, but also loss of
2722 * resolution, loss of color depth, loss due to the color space conversion, loss
2723 * of the alpha bits or loss due to color quantization.
2724 * avcodec_get_fix_fmt_loss() informs you about the various types of losses
2725 * which will occur when converting from one pixel format to another.
2726 *
2727 * @param[in] dst_pix_fmt destination pixel format
2728 * @param[in] src_pix_fmt source pixel format
2729 * @param[in] has_alpha Whether the source pixel format alpha channel is used.
2730 * @return Combination of flags informing you what kind of losses will occur.
2731 */
2732int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
2733 int has_alpha);
2734
2735/**
2736 * Finds the best pixel format to convert to given a certain source pixel
2737 * format. When converting from one pixel format to another, information loss
2738 * may occur. For example, when converting from RGB24 to GRAY, the color
2739 * information will be lost. Similarly, other losses occur when converting from
2740 * some formats to other formats. avcodec_find_best_pix_fmt() searches which of
2741 * the given pixel formats should be used to suffer the least amount of loss.
2742 * The pixel formats from which it chooses one, are determined by the
2743 * \p pix_fmt_mask parameter.
2744 *
2745 * @code
2746 * src_pix_fmt = PIX_FMT_YUV420P;
2747 * pix_fmt_mask = (1 << PIX_FMT_YUV422P) || (1 << PIX_FMT_RGB24);
2748 * dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss);
2749 * @endcode
2750 *
2751 * @param[in] pix_fmt_mask bitmask determining which pixel format to choose from
2752 * @param[in] src_pix_fmt source pixel format
2753 * @param[in] has_alpha Whether the source pixel format alpha channel is used.
2754 * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
2755 * @return The best pixel format to convert to or -1 if none was found.
2756 */
2757int avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, int src_pix_fmt,
2758 int has_alpha, int *loss_ptr);
2759
2760
2761/**
2762 * Print in buf the string corresponding to the pixel format with
2763 * number pix_fmt, or an header if pix_fmt is negative.
2764 *
2765 * @param[in] buf the buffer where to write the string
2766 * @param[in] buf_size the size of buf
2767 * @param[in] pix_fmt the number of the pixel format to print the corresponding info string, or
2768 * a negative value to print the corresponding header.
2769 * Meaningful values for obtaining a pixel format info vary from 0 to PIX_FMT_NB -1.
2770 */
2771void avcodec_pix_fmt_string (char *buf, int buf_size, int pix_fmt);
2772
2773#define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */
2774#define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */
2775
2776/**
2777 * Tell if an image really has transparent alpha values.
2778 * @return ored mask of FF_ALPHA_xxx constants
2779 */
2780int img_get_alpha_info(const AVPicture *src,
2781 int pix_fmt, int width, int height);
2782
2783/* deinterlace a picture */
2784/* deinterlace - if not supported return -1 */
2785int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
2786 int pix_fmt, int width, int height);
2787
2788/* external high level API */
2789
2790/**
2791 * If c is NULL, returns the first registered codec,
2792 * if c is non-NULL, returns the next registered codec after c,
2793 * or NULL if c is the last one.
2794 */
2795AVCodec *av_codec_next(AVCodec *c);
2796
2797/**
2798 * Returns the LIBAVCODEC_VERSION_INT constant.
2799 */
2800unsigned avcodec_version(void);
2801
2802/**
2803 * Initializes libavcodec.
2804 *
2805 * @warning This function \e must be called before any other libavcodec
2806 * function.
2807 */
2808void avcodec_init(void);
2809
2810#if LIBAVCODEC_VERSION_MAJOR < 53
2811/**
2812 * @deprecated Deprecated in favor of avcodec_register().
2813 */
2814attribute_deprecated void register_avcodec(AVCodec *codec);
2815#endif
2816
2817/**
2818 * Register the codec \p codec and initialize libavcodec.
2819 *
2820 * @see avcodec_init()
2821 */
2822void avcodec_register(AVCodec *codec);
2823
2824/**
2825 * Finds a registered encoder with a matching codec ID.
2826 *
2827 * @param id CodecID of the requested encoder
2828 * @return An encoder if one was found, NULL otherwise.
2829 */
2830AVCodec *avcodec_find_encoder(enum CodecID id);
2831
2832/**
2833 * Finds a registered encoder with the specified name.
2834 *
2835 * @param name name of the requested encoder
2836 * @return An encoder if one was found, NULL otherwise.
2837 */
2838AVCodec *avcodec_find_encoder_by_name(const char *name);
2839
2840/**
2841 * Finds a registered decoder with a matching codec ID.
2842 *
2843 * @param id CodecID of the requested decoder
2844 * @return A decoder if one was found, NULL otherwise.
2845 */
2846AVCodec *avcodec_find_decoder(enum CodecID id);
2847
2848/**
2849 * Finds a registered decoder with the specified name.
2850 *
2851 * @param name name of the requested decoder
2852 * @return A decoder if one was found, NULL otherwise.
2853 */
2854AVCodec *avcodec_find_decoder_by_name(const char *name);
2855void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
2856
2857/**
2858 * Sets the fields of the given AVCodecContext to default values.
2859 *
2860 * @param s The AVCodecContext of which the fields should be set to default values.
2861 */
2862void avcodec_get_context_defaults(AVCodecContext *s);
2863
2864/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
2865 * we WILL change its arguments and name a few times! */
2866void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType);
2867
2868/**
2869 * Allocates an AVCodecContext and sets its fields to default values. The
2870 * resulting struct can be deallocated by simply calling av_free().
2871 *
2872 * @return An AVCodecContext filled with default values or NULL on failure.
2873 * @see avcodec_get_context_defaults
2874 */
2875AVCodecContext *avcodec_alloc_context(void);
2876
2877/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
2878 * we WILL change its arguments and name a few times! */
2879AVCodecContext *avcodec_alloc_context2(enum CodecType);
2880
2881/**
2882 * Sets the fields of the given AVFrame to default values.
2883 *
2884 * @param pic The AVFrame of which the fields should be set to default values.
2885 */
2886void avcodec_get_frame_defaults(AVFrame *pic);
2887
2888/**
2889 * Allocates an AVFrame and sets its fields to default values. The resulting
2890 * struct can be deallocated by simply calling av_free().
2891 *
2892 * @return An AVFrame filled with default values or NULL on failure.
2893 * @see avcodec_get_frame_defaults
2894 */
2895AVFrame *avcodec_alloc_frame(void);
2896
2897int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
2898void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
2899int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
2900void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
2901
2902/**
2903 * Checks if the given dimension of a picture is valid, meaning that all
2904 * bytes of the picture can be addressed with a signed int.
2905 *
2906 * @param[in] w Width of the picture.
2907 * @param[in] h Height of the picture.
2908 * @return Zero if valid, a negative value if invalid.
2909 */
2910int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h);
2911enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt);
2912
2913int avcodec_thread_init(AVCodecContext *s, int thread_count);
2914void avcodec_thread_free(AVCodecContext *s);
2915int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
2916int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
2917//FIXME func typedef
2918
2919/**
2920 * Initializes the AVCodecContext to use the given AVCodec. Prior to using this
2921 * function the context has to be allocated.
2922 *
2923 * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
2924 * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
2925 * retrieving a codec.
2926 *
2927 * @warning This function is not thread safe!
2928 *
2929 * @code
2930 * avcodec_register_all();
2931 * codec = avcodec_find_decoder(CODEC_ID_H264);
2932 * if (!codec)
2933 * exit(1);
2934 *
2935 * context = avcodec_alloc_context();
2936 *
2937 * if (avcodec_open(context, codec) < 0)
2938 * exit(1);
2939 * @endcode
2940 *
2941 * @param avctx The context which will be set up to use the given codec.
2942 * @param codec The codec to use within the context.
2943 * @return zero on success, a negative value on error
2944 * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder
2945 */
2946int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
2947
2948/**
2949 * Decodes an audio frame from \p buf into \p samples.
2950 * The avcodec_decode_audio2() function decodes an audio frame from the input
2951 * buffer \p buf of size \p buf_size. To decode it, it makes use of the
2952 * audio codec which was coupled with \p avctx using avcodec_open(). The
2953 * resulting decoded frame is stored in output buffer \p samples. If no frame
2954 * could be decompressed, \p frame_size_ptr is zero. Otherwise, it is the
2955 * decompressed frame size in \e bytes.
2956 *
2957 * @warning You \e must set \p frame_size_ptr to the allocated size of the
2958 * output buffer before calling avcodec_decode_audio2().
2959 *
2960 * @warning The input buffer must be \c FF_INPUT_BUFFER_PADDING_SIZE larger than
2961 * the actual read bytes because some optimized bitstream readers read 32 or 64
2962 * bits at once and could read over the end.
2963 *
2964 * @warning The end of the input buffer \p buf should be set to 0 to ensure that
2965 * no overreading happens for damaged MPEG streams.
2966 *
2967 * @note You might have to align the input buffer \p buf and output buffer \p
2968 * samples. The alignment requirements depend on the CPU: On some CPUs it isn't
2969 * necessary at all, on others it won't work at all if not aligned and on others
2970 * it will work but it will have an impact on performance. In practice, the
2971 * bitstream should have 4 byte alignment at minimum and all sample data should
2972 * be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If
2973 * the linesize is not a multiple of 16 then there's no sense in aligning the
2974 * start of the buffer to 16.
2975 *
2976 * @param avctx the codec context
2977 * @param[out] samples the output buffer
2978 * @param[in,out] frame_size_ptr the output buffer size in bytes
2979 * @param[in] buf the input buffer
2980 * @param[in] buf_size the input buffer size in bytes
2981 * @return On error a negative value is returned, otherwise the number of bytes
2982 * used or zero if no frame could be decompressed.
2983 */
2984int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
2985 int *frame_size_ptr,
2986 const uint8_t *buf, int buf_size);
2987
2988/**
2989 * Decodes a video frame from \p buf into \p picture.
2990 * The avcodec_decode_video() function decodes a video frame from the input
2991 * buffer \p buf of size \p buf_size. To decode it, it makes use of the
2992 * video codec which was coupled with \p avctx using avcodec_open(). The
2993 * resulting decoded frame is stored in \p picture.
2994 *
2995 * @warning The input buffer must be \c FF_INPUT_BUFFER_PADDING_SIZE larger than
2996 * the actual read bytes because some optimized bitstream readers read 32 or 64
2997 * bits at once and could read over the end.
2998 *
2999 * @warning The end of the input buffer \p buf should be set to 0 to ensure that
3000 * no overreading happens for damaged MPEG streams.
3001 *
3002 * @note You might have to align the input buffer \p buf and output buffer \p
3003 * samples. The alignment requirements depend on the CPU: on some CPUs it isn't
3004 * necessary at all, on others it won't work at all if not aligned and on others
3005 * it will work but it will have an impact on performance. In practice, the
3006 * bitstream should have 4 byte alignment at minimum and all sample data should
3007 * be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If
3008 * the linesize is not a multiple of 16 then there's no sense in aligning the
3009 * start of the buffer to 16.
3010 *
3011 * @note Some codecs have a delay between input and output, these need to be
3012 * feeded with buf=NULL, buf_size=0 at the end to return the remaining frames.
3013 *
3014 * @param avctx the codec context
3015 * @param[out] picture The AVFrame in which the decoded video frame will be stored.
3016 * @param[in] buf the input buffer
3017 * @param[in] buf_size the size of the input buffer in bytes
3018 * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
3019 * @return On error a negative value is returned, otherwise the number of bytes
3020 * used or zero if no frame could be decompressed.
3021 */
3022int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
3023 int *got_picture_ptr,
3024 const uint8_t *buf, int buf_size);
3025
3026/* Decode a subtitle message. Return -1 if error, otherwise return the
3027 * number of bytes used. If no subtitle could be decompressed,
3028 * got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */
3029int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
3030 int *got_sub_ptr,
3031 const uint8_t *buf, int buf_size);
3032int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata,
3033 int *data_size_ptr,
3034 uint8_t *buf, int buf_size);
3035
3036/**
3037 * Encodes an audio frame from \p samples into \p buf.
3038 * The avcodec_encode_audio() function encodes an audio frame from the input
3039 * buffer \p samples. To encode it, it makes use of the audio codec which was
3040 * coupled with \p avctx using avcodec_open(). The resulting encoded frame is
3041 * stored in output buffer \p buf.
3042 *
3043 * @note The output buffer should be at least \c FF_MIN_BUFFER_SIZE bytes large.
3044 *
3045 * @param avctx the codec context
3046 * @param[out] buf the output buffer
3047 * @param[in] buf_size the output buffer size
3048 * @param[in] samples the input buffer containing the samples
3049 * The number of samples read from this buffer is frame_size*channels,
3050 * both of which are defined in \p avctx.
3051 * For PCM audio the number of samples read from \p samples is equal to
3052 * \p buf_size * input_sample_size / output_sample_size.
3053 * @return On error a negative value is returned, on success zero or the number
3054 * of bytes used to encode the data read from the input buffer.
3055 */
3056int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
3057 const short *samples);
3058
3059/**
3060 * Encodes a video frame from \p pict into \p buf.
3061 * The avcodec_encode_video() function encodes a video frame from the input
3062 * \p pict. To encode it, it makes use of the video codec which was coupled with
3063 * \p avctx using avcodec_open(). The resulting encoded bytes representing the
3064 * frame are stored in the output buffer \p buf. The input picture should be
3065 * stored using a specific format, namely \c avctx.pix_fmt.
3066 *
3067 * @param avctx the codec context
3068 * @param[out] buf the output buffer for the bitstream of encoded frame
3069 * @param[in] buf_size the size of the output buffer in bytes
3070 * @param[in] pict the input picture to encode
3071 * @return On error a negative value is returned, on success zero or the number
3072 * of bytes used from the output buffer.
3073 */
3074int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
3075 const AVFrame *pict);
3076int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
3077 const AVSubtitle *sub);
3078
3079int avcodec_close(AVCodecContext *avctx);
3080
3081/**
3082 * Register all the codecs, parsers and bitstream filters which were enabled at
3083 * configuration time. If you do not call this function you can select exactly
3084 * which formats you want to support, by using the individual registration
3085 * functions.
3086 *
3087 * @see avcodec_register
3088 * @see av_register_codec_parser
3089 * @see av_register_bitstream_filter
3090 */
3091void avcodec_register_all(void);
3092
3093/**
3094 * Flush buffers, should be called when seeking or when switching to a different stream.
3095 */
3096void avcodec_flush_buffers(AVCodecContext *avctx);
3097
3098void avcodec_default_free_buffers(AVCodecContext *s);
3099
3100/* misc useful functions */
3101
3102/**
3103 * Returns a single letter to describe the given picture type \p pict_type.
3104 *
3105 * @param[in] pict_type the picture type
3106 * @return A single character representing the picture type.
3107 */
3108char av_get_pict_type_char(int pict_type);
3109
3110/**
3111 * Returns codec bits per sample.
3112 *
3113 * @param[in] codec_id the codec
3114 * @return Number of bits per sample or zero if unknown for the given codec.
3115 */
3116int av_get_bits_per_sample(enum CodecID codec_id);
3117
3118/**
3119 * Returns sample format bits per sample.
3120 *
3121 * @param[in] sample_fmt the sample format
3122 * @return Number of bits per sample or zero if unknown for the given sample format.
3123 */
3124int av_get_bits_per_sample_format(enum SampleFormat sample_fmt);
3125
3126/* frame parsing */
3127typedef struct AVCodecParserContext {
3128 void *priv_data;
3129 struct AVCodecParser *parser;
3130 int64_t frame_offset; /* offset of the current frame */
3131 int64_t cur_offset; /* current offset
3132 (incremented by each av_parser_parse()) */
3133 int64_t next_frame_offset; /* offset of the next frame */
3134 /* video info */
3135 int pict_type; /* XXX: Put it back in AVCodecContext. */
3136 /**
3137 * This field is used for proper frame duration computation in lavf.
3138 * It signals, how much longer the frame duration of the current frame
3139 * is compared to normal frame duration.
3140 *
3141 * frame_duration = (1 + repeat_pict) * time_base
3142 *
3143 * It is used by codecs like H.264 to display telecined material.
3144 */
3145 int repeat_pict; /* XXX: Put it back in AVCodecContext. */
3146 int64_t pts; /* pts of the current frame */
3147 int64_t dts; /* dts of the current frame */
3148
3149 /* private data */
3150 int64_t last_pts;
3151 int64_t last_dts;
3152 int fetch_timestamp;
3153
3154#define AV_PARSER_PTS_NB 4
3155 int cur_frame_start_index;
3156 int64_t cur_frame_offset[AV_PARSER_PTS_NB];
3157 int64_t cur_frame_pts[AV_PARSER_PTS_NB];
3158 int64_t cur_frame_dts[AV_PARSER_PTS_NB];
3159
3160 int flags;
3161#define PARSER_FLAG_COMPLETE_FRAMES 0x0001
3162
3163 int64_t offset; ///< byte offset from starting packet start
3164 int64_t cur_frame_end[AV_PARSER_PTS_NB];
3165
3166 /*!
3167 * Set by parser to 1 for key frames and 0 for non-key frames.
3168 * It is initialized to -1, so if the parser doesn't set this flag,
3169 * old-style fallback using FF_I_TYPE picture type as key frames
3170 * will be used.
3171 */
3172 int key_frame;
3173
3174 /**
3175 * Time difference in stream time base units from the pts of this
3176 * packet to the point at which the output from the decoder has converged
3177 * independent from the availability of previous frames. That is, the
3178 * frames are virtually identical no matter if decoding started from
3179 * the very first frame or from this keyframe.
3180 * Is AV_NOPTS_VALUE if unknown.
3181 * This field is not the display duration of the current frame.
3182 *
3183 * The purpose of this field is to allow seeking in streams that have no
3184 * keyframes in the conventional sense. It corresponds to the
3185 * recovery point SEI in H.264 and match_time_delta in NUT. It is also
3186 * essential for some types of subtitle streams to ensure that all
3187 * subtitles are correctly displayed after seeking.
3188 */
3189 int64_t convergence_duration;
3190
3191 // Timestamp generation support:
3192 /**
3193 * Synchronization point for start of timestamp generation.
3194 *
3195 * Set to >0 for sync point, 0 for no sync point and <0 for undefined
3196 * (default).
3197 *
3198 * For example, this corresponds to presence of H.264 buffering period
3199 * SEI message.
3200 */
3201 int dts_sync_point;
3202
3203 /**
3204 * Offset of the current timestamp against last timestamp sync point in
3205 * units of AVCodecContext.time_base.
3206 *
3207 * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
3208 * contain a valid timestamp offset.
3209 *
3210 * Note that the timestamp of sync point has usually a nonzero
3211 * dts_ref_dts_delta, which refers to the previous sync point. Offset of
3212 * the next frame after timestamp sync point will be usually 1.
3213 *
3214 * For example, this corresponds to H.264 cpb_removal_delay.
3215 */
3216 int dts_ref_dts_delta;
3217
3218 /**
3219 * Presentation delay of current frame in units of AVCodecContext.time_base.
3220 *
3221 * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
3222 * contain valid non-negative timestamp delta (presentation time of a frame
3223 * must not lie in the past).
3224 *
3225 * This delay represents the difference between decoding and presentation
3226 * time of the frame.
3227 *
3228 * For example, this corresponds to H.264 dpb_output_delay.
3229 */
3230 int pts_dts_delta;
3231
3232 /**
3233 * Position of the packet in file.
3234 *
3235 * Analogous to cur_frame_pts/dts
3236 */
3237 int64_t cur_frame_pos[AV_PARSER_PTS_NB];
3238
3239 /**
3240 * Byte position of currently parsed frame in stream.
3241 */
3242 int64_t pos;
3243
3244 /**
3245 * Previous frame byte position.
3246 */
3247 int64_t last_pos;
3248} AVCodecParserContext;
3249
3250typedef struct AVCodecParser {
3251 int codec_ids[5]; /* several codec IDs are permitted */
3252 int priv_data_size;
3253 int (*parser_init)(AVCodecParserContext *s);
3254 int (*parser_parse)(AVCodecParserContext *s,
3255 AVCodecContext *avctx,
3256 const uint8_t **poutbuf, int *poutbuf_size,
3257 const uint8_t *buf, int buf_size);
3258 void (*parser_close)(AVCodecParserContext *s);
3259 int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
3260 struct AVCodecParser *next;
3261} AVCodecParser;
3262
3263AVCodecParser *av_parser_next(AVCodecParser *c);
3264
3265void av_register_codec_parser(AVCodecParser *parser);
3266AVCodecParserContext *av_parser_init(int codec_id);
3267
3268attribute_deprecated
3269int av_parser_parse(AVCodecParserContext *s,
3270 AVCodecContext *avctx,
3271 uint8_t **poutbuf, int *poutbuf_size,
3272 const uint8_t *buf, int buf_size,
3273 int64_t pts, int64_t dts);
3274
3275/**
3276 * Parse a packet.
3277 *
3278 * @param s parser context.
3279 * @param avctx codec context.
3280 * @param poutbuf set to pointer to parsed buffer or NULL if not yet finished.
3281 * @param poutbuf_size set to size of parsed buffer or zero if not yet finished.
3282 * @param buf input buffer.
3283 * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output).
3284 * @param pts input presentation timestamp.
3285 * @param dts input decoding timestamp.
3286 * @param pos input byte position in stream.
3287 * @return the number of bytes of the input bitstream used.
3288 *
3289 * Example:
3290 * @code
3291 * while(in_len){
3292 * len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
3293 * in_data, in_len,
3294 * pts, dts, pos);
3295 * in_data += len;
3296 * in_len -= len;
3297 *
3298 * if(size)
3299 * decode_frame(data, size);
3300 * }
3301 * @endcode
3302 */
3303int av_parser_parse2(AVCodecParserContext *s,
3304 AVCodecContext *avctx,
3305 uint8_t **poutbuf, int *poutbuf_size,
3306 const uint8_t *buf, int buf_size,
3307 int64_t pts, int64_t dts,
3308 int64_t pos);
3309
3310int av_parser_change(AVCodecParserContext *s,
3311 AVCodecContext *avctx,
3312 uint8_t **poutbuf, int *poutbuf_size,
3313 const uint8_t *buf, int buf_size, int keyframe);
3314void av_parser_close(AVCodecParserContext *s);
3315
3316
3317typedef struct AVBitStreamFilterContext {
3318 void *priv_data;
3319 struct AVBitStreamFilter *filter;
3320 AVCodecParserContext *parser;
3321 struct AVBitStreamFilterContext *next;
3322} AVBitStreamFilterContext;
3323
3324
3325typedef struct AVBitStreamFilter {
3326 const char *name;
3327 int priv_data_size;
3328 int (*filter)(AVBitStreamFilterContext *bsfc,
3329 AVCodecContext *avctx, const char *args,
3330 uint8_t **poutbuf, int *poutbuf_size,
3331 const uint8_t *buf, int buf_size, int keyframe);
3332 void (*close)(AVBitStreamFilterContext *bsfc);
3333 struct AVBitStreamFilter *next;
3334} AVBitStreamFilter;
3335
3336void av_register_bitstream_filter(AVBitStreamFilter *bsf);
3337AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
3338int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
3339 AVCodecContext *avctx, const char *args,
3340 uint8_t **poutbuf, int *poutbuf_size,
3341 const uint8_t *buf, int buf_size, int keyframe);
3342void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);
3343
3344AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f);
3345
3346/* memory */
3347
3348/**
3349 * Reallocates the given block if it is not large enough, otherwise it
3350 * does nothing.
3351 *
3352 * @see av_realloc
3353 */
3354void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
3355
3356/**
3357 * Copy image 'src' to 'dst'.
3358 */
3359void av_picture_copy(AVPicture *dst, const AVPicture *src,
3360 int pix_fmt, int width, int height);
3361
3362/**
3363 * Crop image top and left side.
3364 */
3365int av_picture_crop(AVPicture *dst, const AVPicture *src,
3366 int pix_fmt, int top_band, int left_band);
3367
3368/**
3369 * Pad image.
3370 */
3371int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, int pix_fmt,
3372 int padtop, int padbottom, int padleft, int padright, int *color);
3373
3374unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
3375
3376/**
3377 * Parses \p str and put in \p width_ptr and \p height_ptr the detected values.
3378 *
3379 * @return 0 in case of a successful parsing, a negative value otherwise
3380 * @param[in] str the string to parse: it has to be a string in the format
3381 * <width>x<height> or a valid video frame size abbreviation.
3382 * @param[in,out] width_ptr pointer to the variable which will contain the detected
3383 * frame width value
3384 * @param[in,out] height_ptr pointer to the variable which will contain the detected
3385 * frame height value
3386 */
3387int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str);
3388
3389/**
3390 * Parses \p str and put in \p frame_rate the detected values.
3391 *
3392 * @return 0 in case of a successful parsing, a negative value otherwise
3393 * @param[in] str the string to parse: it has to be a string in the format
3394 * <frame_rate_num>/<frame_rate_den>, a float number or a valid video rate abbreviation
3395 * @param[in,out] frame_rate pointer to the AVRational which will contain the detected
3396 * frame rate
3397 */
3398int av_parse_video_frame_rate(AVRational *frame_rate, const char *str);
3399
3400/* error handling */
3401#if EINVAL > 0
3402#define AVERROR(e) (-(e)) /**< Returns a negative error code from a POSIX error code, to return from library functions. */
3403#define AVUNERROR(e) (-(e)) /**< Returns a POSIX error code from a library function error return value. */
3404#else
3405/* Some platforms have E* and errno already negated. */
3406#define AVERROR(e) (e)
3407#define AVUNERROR(e) (e)
3408#endif
3409#define AVERROR_UNKNOWN AVERROR(EINVAL) /**< unknown error */
3410#define AVERROR_IO AVERROR(EIO) /**< I/O error */
3411#define AVERROR_NUMEXPECTED AVERROR(EDOM) /**< Number syntax expected in filename. */
3412#define AVERROR_INVALIDDATA AVERROR(EINVAL) /**< invalid data found */
3413#define AVERROR_NOMEM AVERROR(ENOMEM) /**< not enough memory */
3414#define AVERROR_NOFMT AVERROR(EILSEQ) /**< unknown format */
3415#define AVERROR_NOTSUPP AVERROR(ENOSYS) /**< Operation not supported. */
3416#define AVERROR_NOENT AVERROR(ENOENT) /**< No such file or directory. */
3417#define AVERROR_EOF AVERROR(EPIPE) /**< End of file. */
3418#define AVERROR_PATCHWELCOME -MKTAG('P','A','W','E') /**< Not yet implemented in FFmpeg. Patches welcome. */
3419
3420/**
3421 * Registers the hardware accelerator \p hwaccel.
3422 */
3423void av_register_hwaccel(AVHWAccel *hwaccel);
3424
3425/**
3426 * If hwaccel is NULL, returns the first registered hardware accelerator,
3427 * if hwaccel is non-NULL, returns the next registered hardware accelerator
3428 * after hwaccel, or NULL if hwaccel is the last one.
3429 */
3430AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel);
3431
3432#endif /* AVCODEC_AVCODEC_H */
diff --git a/apps/codecs/libcook/bitstream.c b/apps/codecs/libcook/bitstream.c
new file mode 100644
index 0000000000..6781fe6cb0
--- /dev/null
+++ b/apps/codecs/libcook/bitstream.c
@@ -0,0 +1,320 @@
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 *
6 * alternative bitstream reader & writer 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/bitstream.c
27 * bitstream api.
28 */
29
30#include "avcodec.h"
31#include "bitstream.h"
32
33const uint8_t ff_log2_run[32]={
34 0, 0, 0, 0, 1, 1, 1, 1,
35 2, 2, 2, 2, 3, 3, 3, 3,
36 4, 4, 5, 5, 6, 6, 7, 7,
37 8, 9,10,11,12,13,14,15
38};
39
40/**
41 * Same as av_mallocz_static(), but does a realloc.
42 *
43 * @param[in] ptr The block of memory to reallocate.
44 * @param[in] size The requested size.
45 * @return Block of memory of requested size.
46 * @deprecated. Code which uses ff_realloc_static is broken/misdesigned
47 * and should correctly use static arrays
48 */
49attribute_deprecated av_alloc_size(2)
50static void *ff_realloc_static(void *ptr, unsigned int size);
51
52static void *ff_realloc_static(void *ptr, unsigned int size)
53{
54 return av_realloc(ptr, size);
55}
56
57void align_put_bits(PutBitContext *s)
58{
59#ifdef ALT_BITSTREAM_WRITER
60 put_bits(s,( - s->index) & 7,0);
61#else
62 put_bits(s,s->bit_left & 7,0);
63#endif
64}
65
66void ff_put_string(PutBitContext * pbc, const char *s, int put_zero)
67{
68 while(*s){
69 put_bits(pbc, 8, *s);
70 s++;
71 }
72 if(put_zero)
73 put_bits(pbc, 8, 0);
74}
75
76void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
77{
78 const uint16_t *srcw= (const uint16_t*)src;
79 int words= length>>4;
80 int bits= length&15;
81 int i;
82
83 if(length==0) return;
84
85 if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){
86 for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(&srcw[i]));
87 }else{
88 for(i=0; put_bits_count(pb)&31; i++)
89 put_bits(pb, 8, src[i]);
90 flush_put_bits(pb);
91 memcpy(pbBufPtr(pb), src+i, 2*words-i);
92 skip_put_bytes(pb, 2*words-i);
93 }
94
95 put_bits(pb, bits, AV_RB16(&srcw[words])>>(16-bits));
96}
97
98/* VLC decoding */
99
100//#define DEBUG_VLC
101
102#define GET_DATA(v, table, i, wrap, size) \
103{\
104 const uint8_t *ptr = (const uint8_t *)table + i * wrap;\
105 switch(size) {\
106 case 1:\
107 v = *(const uint8_t *)ptr;\
108 break;\
109 case 2:\
110 v = *(const uint16_t *)ptr;\
111 break;\
112 default:\
113 v = *(const uint32_t *)ptr;\
114 break;\
115 }\
116}
117
118
119static int alloc_table(VLC *vlc, int size, int use_static)
120{
121 int index;
122 index = vlc->table_size;
123 vlc->table_size += size;
124 if (vlc->table_size > vlc->table_allocated) {
125 if(use_static>1)
126 abort(); //cant do anything, init_vlc() is used with too little memory
127 vlc->table_allocated += (1 << vlc->bits);
128 if(use_static)
129 vlc->table = ff_realloc_static(vlc->table,
130 sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
131 else
132 vlc->table = av_realloc(vlc->table,
133 sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
134 if (!vlc->table)
135 return -1;
136 }
137 return index;
138}
139
140static int build_table(VLC *vlc, int table_nb_bits,
141 int nb_codes,
142 const void *bits, int bits_wrap, int bits_size,
143 const void *codes, int codes_wrap, int codes_size,
144 const void *symbols, int symbols_wrap, int symbols_size,
145 uint32_t code_prefix, int n_prefix, int flags)
146{
147 int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2, symbol;
148 uint32_t code;
149 VLC_TYPE (*table)[2];
150
151 table_size = 1 << table_nb_bits;
152 table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC));
153#ifdef DEBUG_VLC
154 av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d code_prefix=%x n=%d\n",
155 table_index, table_size, code_prefix, n_prefix);
156#endif
157 if (table_index < 0)
158 return -1;
159 table = &vlc->table[table_index];
160
161 for(i=0;i<table_size;i++) {
162 table[i][1] = 0; //bits
163 table[i][0] = -1; //codes
164 }
165
166 /* first pass: map codes and compute auxillary table sizes */
167 for(i=0;i<nb_codes;i++) {
168 GET_DATA(n, bits, i, bits_wrap, bits_size);
169 GET_DATA(code, codes, i, codes_wrap, codes_size);
170 /* we accept tables with holes */
171 if (n <= 0)
172 continue;
173 if (!symbols)
174 symbol = i;
175 else
176 GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size);
177#if defined(DEBUG_VLC) && 0
178 av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code);
179#endif
180 /* if code matches the prefix, it is in the table */
181 n -= n_prefix;
182 if(flags & INIT_VLC_LE)
183 code_prefix2= code & (n_prefix>=32 ? 0xffffffff : (1 << n_prefix)-1);
184 else
185 code_prefix2= code >> n;
186 if (n > 0 && code_prefix2 == code_prefix) {
187 if (n <= table_nb_bits) {
188 /* no need to add another table */
189 j = (code << (table_nb_bits - n)) & (table_size - 1);
190 nb = 1 << (table_nb_bits - n);
191 for(k=0;k<nb;k++) {
192 if(flags & INIT_VLC_LE)
193 j = (code >> n_prefix) + (k<<n);
194#ifdef DEBUG_VLC
195 av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n",
196 j, i, n);
197#endif
198 if (table[j][1] /*bits*/ != 0) {
199 av_log(NULL, AV_LOG_ERROR, "incorrect codes\n");
200 return -1;
201 }
202 table[j][1] = n; //bits
203 table[j][0] = symbol;
204 j++;
205 }
206 } else {
207 n -= table_nb_bits;
208 j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1);
209#ifdef DEBUG_VLC
210 av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n",
211 j, n);
212#endif
213 /* compute table size */
214 n1 = -table[j][1]; //bits
215 if (n > n1)
216 n1 = n;
217 table[j][1] = -n1; //bits
218 }
219 }
220 }
221
222 /* second pass : fill auxillary tables recursively */
223 for(i=0;i<table_size;i++) {
224 n = table[i][1]; //bits
225 if (n < 0) {
226 n = -n;
227 if (n > table_nb_bits) {
228 n = table_nb_bits;
229 table[i][1] = -n; //bits
230 }
231 index = build_table(vlc, n, nb_codes,
232 bits, bits_wrap, bits_size,
233 codes, codes_wrap, codes_size,
234 symbols, symbols_wrap, symbols_size,
235 (flags & INIT_VLC_LE) ? (code_prefix | (i << n_prefix)) : ((code_prefix << table_nb_bits) | i),
236 n_prefix + table_nb_bits, flags);
237 if (index < 0)
238 return -1;
239 /* note: realloc has been done, so reload tables */
240 table = &vlc->table[table_index];
241 table[i][0] = index; //code
242 }
243 }
244 return table_index;
245}
246
247
248/* Build VLC decoding tables suitable for use with get_vlc().
249
250 'nb_bits' set thee decoding table size (2^nb_bits) entries. The
251 bigger it is, the faster is the decoding. But it should not be too
252 big to save memory and L1 cache. '9' is a good compromise.
253
254 'nb_codes' : number of vlcs codes
255
256 'bits' : table which gives the size (in bits) of each vlc code.
257
258 'codes' : table which gives the bit pattern of of each vlc code.
259
260 'symbols' : table which gives the values to be returned from get_vlc().
261
262 'xxx_wrap' : give the number of bytes between each entry of the
263 'bits' or 'codes' tables.
264
265 'xxx_size' : gives the number of bytes of each entry of the 'bits'
266 or 'codes' tables.
267
268 'wrap' and 'size' allows to use any memory configuration and types
269 (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables.
270
271 'use_static' should be set to 1 for tables, which should be freed
272 with av_free_static(), 0 if free_vlc() will be used.
273*/
274int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
275 const void *bits, int bits_wrap, int bits_size,
276 const void *codes, int codes_wrap, int codes_size,
277 const void *symbols, int symbols_wrap, int symbols_size,
278 int flags)
279{
280 vlc->bits = nb_bits;
281 if(flags & INIT_VLC_USE_NEW_STATIC){
282 if(vlc->table_size && vlc->table_size == vlc->table_allocated){
283 return 0;
284 }else if(vlc->table_size){
285 abort(); // fatal error, we are called on a partially initialized table
286 }
287 }else if(!(flags & INIT_VLC_USE_STATIC)) {
288 vlc->table = NULL;
289 vlc->table_allocated = 0;
290 vlc->table_size = 0;
291 } else {
292 /* Static tables are initially always NULL, return
293 if vlc->table != NULL to avoid double allocation */
294 if(vlc->table)
295 return 0;
296 }
297
298#ifdef DEBUG_VLC
299 av_log(NULL,AV_LOG_DEBUG,"build table nb_codes=%d\n", nb_codes);
300#endif
301
302 if (build_table(vlc, nb_bits, nb_codes,
303 bits, bits_wrap, bits_size,
304 codes, codes_wrap, codes_size,
305 symbols, symbols_wrap, symbols_size,
306 0, 0, flags) < 0) {
307 av_freep(&vlc->table);
308 return -1;
309 }
310 if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size != vlc->table_allocated)
311 av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated);
312 return 0;
313}
314
315
316void free_vlc(VLC *vlc)
317{
318 av_freep(&vlc->table);
319}
320
diff --git a/apps/codecs/libcook/bitstream.h b/apps/codecs/libcook/bitstream.h
new file mode 100644
index 0000000000..3670285904
--- /dev/null
+++ b/apps/codecs/libcook/bitstream.h
@@ -0,0 +1,955 @@
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/bitstream.h
23 * bitstream api header.
24 */
25
26#ifndef AVCODEC_BITSTREAM_H
27#define AVCODEC_BITSTREAM_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//#define ALT_BITSTREAM_WRITER
43//#define ALIGNED_BITSTREAM_WRITER
44#if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
45# if ARCH_ARM
46# define A32_BITSTREAM_READER
47# else
48# define ALT_BITSTREAM_READER
49//#define LIBMPEG2_BITSTREAM_READER
50//#define A32_BITSTREAM_READER
51# endif
52#endif
53
54extern const uint8_t ff_reverse[256];
55
56#if ARCH_X86
57// avoid +32 for shift optimization (gcc should do that ...)
58static inline int32_t NEG_SSR32( int32_t a, int8_t s){
59 __asm__ ("sarl %1, %0\n\t"
60 : "+r" (a)
61 : "ic" ((uint8_t)(-s))
62 );
63 return a;
64}
65static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
66 __asm__ ("shrl %1, %0\n\t"
67 : "+r" (a)
68 : "ic" ((uint8_t)(-s))
69 );
70 return a;
71}
72#else
73# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
74# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
75#endif
76
77/* bit output */
78
79/* buf and buf_end must be present and used by every alternative writer. */
80typedef struct PutBitContext {
81#ifdef ALT_BITSTREAM_WRITER
82 uint8_t *buf, *buf_end;
83 int index;
84#else
85 uint32_t bit_buf;
86 int bit_left;
87 uint8_t *buf, *buf_ptr, *buf_end;
88#endif
89 int size_in_bits;
90} PutBitContext;
91
92static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
93{
94 if(buffer_size < 0) {
95 buffer_size = 0;
96 buffer = NULL;
97 }
98
99 s->size_in_bits= 8*buffer_size;
100 s->buf = buffer;
101 s->buf_end = s->buf + buffer_size;
102#ifdef ALT_BITSTREAM_WRITER
103 s->index=0;
104 ((uint32_t*)(s->buf))[0]=0;
105// memset(buffer, 0, buffer_size);
106#else
107 s->buf_ptr = s->buf;
108 s->bit_left=32;
109 s->bit_buf=0;
110#endif
111}
112
113/* return the number of bits output */
114static inline int put_bits_count(PutBitContext *s)
115{
116#ifdef ALT_BITSTREAM_WRITER
117 return s->index;
118#else
119 return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left;
120#endif
121}
122
123/* pad the end of the output stream with zeros */
124static inline void flush_put_bits(PutBitContext *s)
125{
126#ifdef ALT_BITSTREAM_WRITER
127 align_put_bits(s);
128#else
129#ifndef BITSTREAM_WRITER_LE
130 s->bit_buf<<= s->bit_left;
131#endif
132 while (s->bit_left < 32) {
133 /* XXX: should test end of buffer */
134#ifdef BITSTREAM_WRITER_LE
135 *s->buf_ptr++=s->bit_buf;
136 s->bit_buf>>=8;
137#else
138 *s->buf_ptr++=s->bit_buf >> 24;
139 s->bit_buf<<=8;
140#endif
141 s->bit_left+=8;
142 }
143 s->bit_left=32;
144 s->bit_buf=0;
145#endif
146}
147
148void align_put_bits(PutBitContext *s);
149void ff_put_string(PutBitContext * pbc, const char *s, int put_zero);
150void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length);
151
152/* bit input */
153/* buffer, buffer_end and size_in_bits must be present and used by every reader */
154typedef struct GetBitContext {
155 const uint8_t *buffer, *buffer_end;
156#ifdef ALT_BITSTREAM_READER
157 int index;
158#elif defined LIBMPEG2_BITSTREAM_READER
159 uint8_t *buffer_ptr;
160 uint32_t cache;
161 int bit_count;
162#elif defined A32_BITSTREAM_READER
163 uint32_t *buffer_ptr;
164 uint32_t cache0;
165 uint32_t cache1;
166 int bit_count;
167#endif
168 int size_in_bits;
169} GetBitContext;
170
171#define VLC_TYPE int16_t
172
173typedef struct VLC {
174 int bits;
175 VLC_TYPE (*table)[2]; ///< code, bits
176 int table_size, table_allocated;
177} VLC;
178
179typedef struct RL_VLC_ELEM {
180 int16_t level;
181 int8_t len;
182 uint8_t run;
183} RL_VLC_ELEM;
184
185#ifndef ALT_BITSTREAM_WRITER
186static inline void put_bits(PutBitContext *s, int n, unsigned int value)
187{
188 unsigned int bit_buf;
189 int bit_left;
190
191 // printf("put_bits=%d %x\n", n, value);
192 assert(n == 32 || value < (1U << n));
193
194 bit_buf = s->bit_buf;
195 bit_left = s->bit_left;
196
197 // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
198 /* XXX: optimize */
199#ifdef BITSTREAM_WRITER_LE
200 bit_buf |= value << (32 - bit_left);
201 if (n >= bit_left) {
202#if !HAVE_FAST_UNALIGNED
203 if (3 & (intptr_t) s->buf_ptr) {
204 AV_WL32(s->buf_ptr, bit_buf);
205 } else
206#endif
207 *(uint32_t *)s->buf_ptr = le2me_32(bit_buf);
208 s->buf_ptr+=4;
209 bit_buf = (bit_left==32)?0:value >> bit_left;
210 bit_left+=32;
211 }
212 bit_left-=n;
213#else
214 if (n < bit_left) {
215 bit_buf = (bit_buf<<n) | value;
216 bit_left-=n;
217 } else {
218 bit_buf<<=bit_left;
219 bit_buf |= value >> (n - bit_left);
220#if !HAVE_FAST_UNALIGNED
221 if (3 & (intptr_t) s->buf_ptr) {
222 AV_WB32(s->buf_ptr, bit_buf);
223 } else
224#endif
225 *(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
226 //printf("bitbuf = %08x\n", bit_buf);
227 s->buf_ptr+=4;
228 bit_left+=32 - n;
229 bit_buf = value;
230 }
231#endif
232
233 s->bit_buf = bit_buf;
234 s->bit_left = bit_left;
235}
236#endif
237
238
239#ifdef ALT_BITSTREAM_WRITER
240static inline void put_bits(PutBitContext *s, int n, unsigned int value)
241{
242# ifdef ALIGNED_BITSTREAM_WRITER
243# if ARCH_X86
244 __asm__ volatile(
245 "movl %0, %%ecx \n\t"
246 "xorl %%eax, %%eax \n\t"
247 "shrdl %%cl, %1, %%eax \n\t"
248 "shrl %%cl, %1 \n\t"
249 "movl %0, %%ecx \n\t"
250 "shrl $3, %%ecx \n\t"
251 "andl $0xFFFFFFFC, %%ecx \n\t"
252 "bswapl %1 \n\t"
253 "orl %1, (%2, %%ecx) \n\t"
254 "bswapl %%eax \n\t"
255 "addl %3, %0 \n\t"
256 "movl %%eax, 4(%2, %%ecx) \n\t"
257 : "=&r" (s->index), "=&r" (value)
258 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n))
259 : "%eax", "%ecx"
260 );
261# else
262 int index= s->index;
263 uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5);
264
265 value<<= 32-n;
266
267 ptr[0] |= be2me_32(value>>(index&31));
268 ptr[1] = be2me_32(value<<(32-(index&31)));
269//if(n>24) printf("%d %d\n", n, value);
270 index+= n;
271 s->index= index;
272# endif
273# else //ALIGNED_BITSTREAM_WRITER
274# if ARCH_X86
275 __asm__ volatile(
276 "movl $7, %%ecx \n\t"
277 "andl %0, %%ecx \n\t"
278 "addl %3, %%ecx \n\t"
279 "negl %%ecx \n\t"
280 "shll %%cl, %1 \n\t"
281 "bswapl %1 \n\t"
282 "movl %0, %%ecx \n\t"
283 "shrl $3, %%ecx \n\t"
284 "orl %1, (%%ecx, %2) \n\t"
285 "addl %3, %0 \n\t"
286 "movl $0, 4(%%ecx, %2) \n\t"
287 : "=&r" (s->index), "=&r" (value)
288 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value)
289 : "%ecx"
290 );
291# else
292 int index= s->index;
293 uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
294
295 ptr[0] |= be2me_32(value<<(32-n-(index&7) ));
296 ptr[1] = 0;
297//if(n>24) printf("%d %d\n", n, value);
298 index+= n;
299 s->index= index;
300# endif
301# endif //!ALIGNED_BITSTREAM_WRITER
302}
303#endif
304
305static inline void put_sbits(PutBitContext *pb, int bits, int32_t val)
306{
307 assert(bits >= 0 && bits <= 31);
308
309 put_bits(pb, bits, val & ((1<<bits)-1));
310}
311
312
313static inline uint8_t* pbBufPtr(PutBitContext *s)
314{
315#ifdef ALT_BITSTREAM_WRITER
316 return s->buf + (s->index>>3);
317#else
318 return s->buf_ptr;
319#endif
320}
321
322/**
323 *
324 * PutBitContext must be flushed & aligned to a byte boundary before calling this.
325 */
326static inline void skip_put_bytes(PutBitContext *s, int n){
327 assert((put_bits_count(s)&7)==0);
328#ifdef ALT_BITSTREAM_WRITER
329 FIXME may need some cleaning of the buffer
330 s->index += n<<3;
331#else
332 assert(s->bit_left==32);
333 s->buf_ptr += n;
334#endif
335}
336
337/**
338 * Skips the given number of bits.
339 * Must only be used if the actual values in the bitstream do not matter.
340 */
341static inline void skip_put_bits(PutBitContext *s, int n){
342#ifdef ALT_BITSTREAM_WRITER
343 s->index += n;
344#else
345 s->bit_left -= n;
346 s->buf_ptr-= s->bit_left>>5;
347 s->bit_left &= 31;
348#endif
349}
350
351/**
352 * Changes the end of the buffer.
353 */
354static inline void set_put_bits_buffer_size(PutBitContext *s, int size){
355 s->buf_end= s->buf + size;
356}
357
358/* Bitstream reader API docs:
359name
360 arbitrary name which is used as prefix for the internal variables
361
362gb
363 getbitcontext
364
365OPEN_READER(name, gb)
366 loads gb into local variables
367
368CLOSE_READER(name, gb)
369 stores local vars in gb
370
371UPDATE_CACHE(name, gb)
372 refills the internal cache from the bitstream
373 after this call at least MIN_CACHE_BITS will be available,
374
375GET_CACHE(name, gb)
376 will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit)
377
378SHOW_UBITS(name, gb, num)
379 will return the next num bits
380
381SHOW_SBITS(name, gb, num)
382 will return the next num bits and do sign extension
383
384SKIP_BITS(name, gb, num)
385 will skip over the next num bits
386 note, this is equivalent to SKIP_CACHE; SKIP_COUNTER
387
388SKIP_CACHE(name, gb, num)
389 will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER)
390
391SKIP_COUNTER(name, gb, num)
392 will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS)
393
394LAST_SKIP_CACHE(name, gb, num)
395 will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing
396
397LAST_SKIP_BITS(name, gb, num)
398 is equivalent to SKIP_LAST_CACHE; SKIP_COUNTER
399
400for examples see get_bits, show_bits, skip_bits, get_vlc
401*/
402
403#ifdef ALT_BITSTREAM_READER
404# define MIN_CACHE_BITS 25
405
406# define OPEN_READER(name, gb)\
407 int name##_index= (gb)->index;\
408 int name##_cache= 0;\
409
410# define CLOSE_READER(name, gb)\
411 (gb)->index= name##_index;\
412
413# ifdef ALT_BITSTREAM_READER_LE
414# define UPDATE_CACHE(name, gb)\
415 name##_cache= AV_RL32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\
416
417# define SKIP_CACHE(name, gb, num)\
418 name##_cache >>= (num);
419# else
420# define UPDATE_CACHE(name, gb)\
421 name##_cache= AV_RB32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
422
423# define SKIP_CACHE(name, gb, num)\
424 name##_cache <<= (num);
425# endif
426
427// FIXME name?
428# define SKIP_COUNTER(name, gb, num)\
429 name##_index += (num);\
430
431# define SKIP_BITS(name, gb, num)\
432 {\
433 SKIP_CACHE(name, gb, num)\
434 SKIP_COUNTER(name, gb, num)\
435 }\
436
437# define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
438# define LAST_SKIP_CACHE(name, gb, num) ;
439
440# ifdef ALT_BITSTREAM_READER_LE
441# define SHOW_UBITS(name, gb, num)\
442 ((name##_cache) & (NEG_USR32(0xffffffff,num)))
443
444# define SHOW_SBITS(name, gb, num)\
445 NEG_SSR32((name##_cache)<<(32-(num)), num)
446# else
447# define SHOW_UBITS(name, gb, num)\
448 NEG_USR32(name##_cache, num)
449
450# define SHOW_SBITS(name, gb, num)\
451 NEG_SSR32(name##_cache, num)
452# endif
453
454# define GET_CACHE(name, gb)\
455 ((uint32_t)name##_cache)
456
457static inline int get_bits_count(GetBitContext *s){
458 return s->index;
459}
460
461static inline void skip_bits_long(GetBitContext *s, int n){
462 s->index += n;
463}
464
465#elif defined LIBMPEG2_BITSTREAM_READER
466//libmpeg2 like reader
467
468# define MIN_CACHE_BITS 17
469
470# define OPEN_READER(name, gb)\
471 int name##_bit_count=(gb)->bit_count;\
472 int name##_cache= (gb)->cache;\
473 uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\
474
475# define CLOSE_READER(name, gb)\
476 (gb)->bit_count= name##_bit_count;\
477 (gb)->cache= name##_cache;\
478 (gb)->buffer_ptr= name##_buffer_ptr;\
479
480# define UPDATE_CACHE(name, gb)\
481 if(name##_bit_count >= 0){\
482 name##_cache+= AV_RB16(name##_buffer_ptr) << name##_bit_count; \
483 name##_buffer_ptr+=2;\
484 name##_bit_count-= 16;\
485 }\
486
487# define SKIP_CACHE(name, gb, num)\
488 name##_cache <<= (num);\
489
490# define SKIP_COUNTER(name, gb, num)\
491 name##_bit_count += (num);\
492
493# define SKIP_BITS(name, gb, num)\
494 {\
495 SKIP_CACHE(name, gb, num)\
496 SKIP_COUNTER(name, gb, num)\
497 }\
498
499# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
500# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
501
502# define SHOW_UBITS(name, gb, num)\
503 NEG_USR32(name##_cache, num)
504
505# define SHOW_SBITS(name, gb, num)\
506 NEG_SSR32(name##_cache, num)
507
508# define GET_CACHE(name, gb)\
509 ((uint32_t)name##_cache)
510
511static inline int get_bits_count(GetBitContext *s){
512 return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count;
513}
514
515static inline void skip_bits_long(GetBitContext *s, int n){
516 OPEN_READER(re, s)
517 re_bit_count += n;
518 re_buffer_ptr += 2*(re_bit_count>>4);
519 re_bit_count &= 15;
520 re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count);
521 UPDATE_CACHE(re, s)
522 CLOSE_READER(re, s)
523}
524
525#elif defined A32_BITSTREAM_READER
526
527# define MIN_CACHE_BITS 32
528
529# define OPEN_READER(name, gb)\
530 int name##_bit_count=(gb)->bit_count;\
531 uint32_t name##_cache0= (gb)->cache0;\
532 uint32_t name##_cache1= (gb)->cache1;\
533 uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\
534
535# define CLOSE_READER(name, gb)\
536 (gb)->bit_count= name##_bit_count;\
537 (gb)->cache0= name##_cache0;\
538 (gb)->cache1= name##_cache1;\
539 (gb)->buffer_ptr= name##_buffer_ptr;\
540
541# define UPDATE_CACHE(name, gb)\
542 if(name##_bit_count > 0){\
543 const uint32_t next= be2me_32( *name##_buffer_ptr );\
544 name##_cache0 |= NEG_USR32(next,name##_bit_count);\
545 name##_cache1 |= next<<name##_bit_count;\
546 name##_buffer_ptr++;\
547 name##_bit_count-= 32;\
548 }\
549
550#if ARCH_X86
551# define SKIP_CACHE(name, gb, num)\
552 __asm__(\
553 "shldl %2, %1, %0 \n\t"\
554 "shll %2, %1 \n\t"\
555 : "+r" (name##_cache0), "+r" (name##_cache1)\
556 : "Ic" ((uint8_t)(num))\
557 );
558#else
559# define SKIP_CACHE(name, gb, num)\
560 name##_cache0 <<= (num);\
561 name##_cache0 |= NEG_USR32(name##_cache1,num);\
562 name##_cache1 <<= (num);
563#endif
564
565# define SKIP_COUNTER(name, gb, num)\
566 name##_bit_count += (num);\
567
568# define SKIP_BITS(name, gb, num)\
569 {\
570 SKIP_CACHE(name, gb, num)\
571 SKIP_COUNTER(name, gb, num)\
572 }\
573
574# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
575# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
576
577# define SHOW_UBITS(name, gb, num)\
578 NEG_USR32(name##_cache0, num)
579
580# define SHOW_SBITS(name, gb, num)\
581 NEG_SSR32(name##_cache0, num)
582
583# define GET_CACHE(name, gb)\
584 (name##_cache0)
585
586static inline int get_bits_count(GetBitContext *s){
587 return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count;
588}
589
590static inline void skip_bits_long(GetBitContext *s, int n){
591 OPEN_READER(re, s)
592 re_bit_count += n;
593 re_buffer_ptr += re_bit_count>>5;
594 re_bit_count &= 31;
595 re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count;
596 re_cache1 = 0;
597 UPDATE_CACHE(re, s)
598 CLOSE_READER(re, s)
599}
600
601#endif
602
603/**
604 * read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
605 * if MSB not set it is negative
606 * @param n length in bits
607 * @author BERO
608 */
609static inline int get_xbits(GetBitContext *s, int n){
610 register int sign;
611 register int32_t cache;
612 OPEN_READER(re, s)
613 UPDATE_CACHE(re, s)
614 cache = GET_CACHE(re,s);
615 sign=(~cache)>>31;
616 LAST_SKIP_BITS(re, s, n)
617 CLOSE_READER(re, s)
618 return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
619}
620
621static inline int get_sbits(GetBitContext *s, int n){
622 register int tmp;
623 OPEN_READER(re, s)
624 UPDATE_CACHE(re, s)
625 tmp= SHOW_SBITS(re, s, n);
626 LAST_SKIP_BITS(re, s, n)
627 CLOSE_READER(re, s)
628 return tmp;
629}
630
631/**
632 * reads 1-17 bits.
633 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
634 */
635static inline unsigned int get_bits(GetBitContext *s, int n){
636 register int tmp;
637 OPEN_READER(re, s)
638 UPDATE_CACHE(re, s)
639 tmp= SHOW_UBITS(re, s, n);
640 LAST_SKIP_BITS(re, s, n)
641 CLOSE_READER(re, s)
642 return tmp;
643}
644
645/**
646 * shows 1-17 bits.
647 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
648 */
649static inline unsigned int show_bits(GetBitContext *s, int n){
650 register int tmp;
651 OPEN_READER(re, s)
652 UPDATE_CACHE(re, s)
653 tmp= SHOW_UBITS(re, s, n);
654// CLOSE_READER(re, s)
655 return tmp;
656}
657
658static inline void skip_bits(GetBitContext *s, int n){
659 //Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
660 OPEN_READER(re, s)
661 UPDATE_CACHE(re, s)
662 LAST_SKIP_BITS(re, s, n)
663 CLOSE_READER(re, s)
664}
665
666static inline unsigned int get_bits1(GetBitContext *s){
667#ifdef ALT_BITSTREAM_READER
668 int index= s->index;
669 uint8_t result= s->buffer[ index>>3 ];
670#ifdef ALT_BITSTREAM_READER_LE
671 result>>= (index&0x07);
672 result&= 1;
673#else
674 result<<= (index&0x07);
675 result>>= 8 - 1;
676#endif
677 index++;
678 s->index= index;
679
680 return result;
681#else
682 return get_bits(s, 1);
683#endif
684}
685
686static inline unsigned int show_bits1(GetBitContext *s){
687 return show_bits(s, 1);
688}
689
690static inline void skip_bits1(GetBitContext *s){
691 skip_bits(s, 1);
692}
693
694/**
695 * reads 0-32 bits.
696 */
697static inline unsigned int get_bits_long(GetBitContext *s, int n){
698 if(n<=17) return get_bits(s, n);
699 else{
700#ifdef ALT_BITSTREAM_READER_LE
701 int ret= get_bits(s, 16);
702 return ret | (get_bits(s, n-16) << 16);
703#else
704 int ret= get_bits(s, 16) << (n-16);
705 return ret | get_bits(s, n-16);
706#endif
707 }
708}
709
710/**
711 * reads 0-32 bits as a signed integer.
712 */
713static inline int get_sbits_long(GetBitContext *s, int n) {
714 return sign_extend(get_bits_long(s, n), n);
715}
716
717/**
718 * shows 0-32 bits.
719 */
720static inline unsigned int show_bits_long(GetBitContext *s, int n){
721 if(n<=17) return show_bits(s, n);
722 else{
723 GetBitContext gb= *s;
724 return get_bits_long(&gb, n);
725 }
726}
727
728static inline int check_marker(GetBitContext *s, const char *msg)
729{
730 int bit= get_bits1(s);
731 if(!bit)
732 av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg);
733
734 return bit;
735}
736
737/**
738 * init GetBitContext.
739 * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits
740 * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
741 * @param bit_size the size of the buffer in bits
742 */
743static inline void init_get_bits(GetBitContext *s,
744 const uint8_t *buffer, int bit_size)
745{
746 int buffer_size= (bit_size+7)>>3;
747 if(buffer_size < 0 || bit_size < 0) {
748 buffer_size = bit_size = 0;
749 buffer = NULL;
750 }
751
752 s->buffer= buffer;
753 s->size_in_bits= bit_size;
754 s->buffer_end= buffer + buffer_size;
755#ifdef ALT_BITSTREAM_READER
756 s->index=0;
757#elif defined LIBMPEG2_BITSTREAM_READER
758 s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));
759 s->bit_count = 16 + 8*((intptr_t)buffer&1);
760 skip_bits_long(s, 0);
761#elif defined A32_BITSTREAM_READER
762 s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));
763 s->bit_count = 32 + 8*((intptr_t)buffer&3);
764 skip_bits_long(s, 0);
765#endif
766}
767
768static inline void align_get_bits(GetBitContext *s)
769{
770 int n= (-get_bits_count(s)) & 7;
771 if(n) skip_bits(s, n);
772}
773
774#define init_vlc(vlc, nb_bits, nb_codes,\
775 bits, bits_wrap, bits_size,\
776 codes, codes_wrap, codes_size,\
777 flags)\
778 init_vlc_sparse(vlc, nb_bits, nb_codes,\
779 bits, bits_wrap, bits_size,\
780 codes, codes_wrap, codes_size,\
781 NULL, 0, 0, flags)
782
783int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
784 const void *bits, int bits_wrap, int bits_size,
785 const void *codes, int codes_wrap, int codes_size,
786 const void *symbols, int symbols_wrap, int symbols_size,
787 int flags);
788#define INIT_VLC_USE_STATIC 1 ///< VERY strongly deprecated and forbidden
789#define INIT_VLC_LE 2
790#define INIT_VLC_USE_NEW_STATIC 4
791void free_vlc(VLC *vlc);
792
793#define INIT_VLC_STATIC(vlc, bits, a,b,c,d,e,f,g, static_size)\
794{\
795 static VLC_TYPE table[static_size][2];\
796 (vlc)->table= table;\
797 (vlc)->table_allocated= static_size;\
798 init_vlc(vlc, bits, a,b,c,d,e,f,g, INIT_VLC_USE_NEW_STATIC);\
799}
800
801
802/**
803 *
804 * if the vlc code is invalid and max_depth=1 than no bits will be removed
805 * if the vlc code is invalid and max_depth>1 than the number of bits removed
806 * is undefined
807 */
808#define GET_VLC(code, name, gb, table, bits, max_depth)\
809{\
810 int n, index, nb_bits;\
811\
812 index= SHOW_UBITS(name, gb, bits);\
813 code = table[index][0];\
814 n = table[index][1];\
815\
816 if(max_depth > 1 && n < 0){\
817 LAST_SKIP_BITS(name, gb, bits)\
818 UPDATE_CACHE(name, gb)\
819\
820 nb_bits = -n;\
821\
822 index= SHOW_UBITS(name, gb, nb_bits) + code;\
823 code = table[index][0];\
824 n = table[index][1];\
825 if(max_depth > 2 && n < 0){\
826 LAST_SKIP_BITS(name, gb, nb_bits)\
827 UPDATE_CACHE(name, gb)\
828\
829 nb_bits = -n;\
830\
831 index= SHOW_UBITS(name, gb, nb_bits) + code;\
832 code = table[index][0];\
833 n = table[index][1];\
834 }\
835 }\
836 SKIP_BITS(name, gb, n)\
837}
838
839#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\
840{\
841 int n, index, nb_bits;\
842\
843 index= SHOW_UBITS(name, gb, bits);\
844 level = table[index].level;\
845 n = table[index].len;\
846\
847 if(max_depth > 1 && n < 0){\
848 SKIP_BITS(name, gb, bits)\
849 if(need_update){\
850 UPDATE_CACHE(name, gb)\
851 }\
852\
853 nb_bits = -n;\
854\
855 index= SHOW_UBITS(name, gb, nb_bits) + level;\
856 level = table[index].level;\
857 n = table[index].len;\
858 }\
859 run= table[index].run;\
860 SKIP_BITS(name, gb, n)\
861}
862
863
864/**
865 * parses a vlc code, faster then get_vlc()
866 * @param bits is the number of bits which will be read at once, must be
867 * identical to nb_bits in init_vlc()
868 * @param max_depth is the number of times bits bits must be read to completely
869 * read the longest vlc code
870 * = (max_vlc_length + bits - 1) / bits
871 */
872static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
873 int bits, int max_depth)
874{
875 int code;
876
877 OPEN_READER(re, s)
878 UPDATE_CACHE(re, s)
879
880 GET_VLC(code, re, s, table, bits, max_depth)
881
882 CLOSE_READER(re, s)
883 return code;
884}
885
886//#define TRACE
887
888#ifdef TRACE
889static inline void print_bin(int bits, int n){
890 int i;
891
892 for(i=n-1; i>=0; i--){
893 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1);
894 }
895 for(i=n; i<24; i++)
896 av_log(NULL, AV_LOG_DEBUG, " ");
897}
898
899static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
900 int r= get_bits(s, n);
901
902 print_bin(r, n);
903 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);
904 return r;
905}
906static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){
907 int show= show_bits(s, 24);
908 int pos= get_bits_count(s);
909 int r= get_vlc2(s, table, bits, max_depth);
910 int len= get_bits_count(s) - pos;
911 int bits2= show>>(24-len);
912
913 print_bin(bits2, len);
914
915 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
916 return r;
917}
918static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
919 int show= show_bits(s, n);
920 int r= get_xbits(s, n);
921
922 print_bin(show, n);
923 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);
924 return r;
925}
926
927#define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
928#define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
929#define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
930#define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
931#define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
932
933#define tprintf(p, ...) av_log(p, AV_LOG_DEBUG, __VA_ARGS__)
934
935#else //TRACE
936#define tprintf(p, ...) {}
937#endif
938
939static inline int decode012(GetBitContext *gb){
940 int n;
941 n = get_bits1(gb);
942 if (n == 0)
943 return 0;
944 else
945 return get_bits1(gb) + 1;
946}
947
948static inline int decode210(GetBitContext *gb){
949 if (get_bits1(gb))
950 return 0;
951 else
952 return 2 - get_bits1(gb);
953}
954
955#endif /* AVCODEC_BITSTREAM_H */
diff --git a/apps/codecs/libcook/bytestream.h b/apps/codecs/libcook/bytestream.h
new file mode 100644
index 0000000000..b56f6ce743
--- /dev/null
+++ b/apps/codecs/libcook/bytestream.h
@@ -0,0 +1,71 @@
1/*
2 * Bytestream functions
3 * copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
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_BYTESTREAM_H
23#define AVCODEC_BYTESTREAM_H
24
25#include <string.h>
26#include "libavutil/common.h"
27#include "libavutil/intreadwrite.h"
28
29#define DEF_T(type, name, bytes, read, write) \
30static av_always_inline type bytestream_get_ ## name(const uint8_t **b){\
31 (*b) += bytes;\
32 return read(*b - bytes);\
33}\
34static av_always_inline void bytestream_put_ ##name(uint8_t **b, const type value){\
35 write(*b, value);\
36 (*b) += bytes;\
37}
38
39#define DEF(name, bytes, read, write) \
40 DEF_T(unsigned int, name, bytes, read, write)
41#define DEF64(name, bytes, read, write) \
42 DEF_T(uint64_t, name, bytes, read, write)
43
44DEF64(le64, 8, AV_RL64, AV_WL64)
45DEF (le32, 4, AV_RL32, AV_WL32)
46DEF (le24, 3, AV_RL24, AV_WL24)
47DEF (le16, 2, AV_RL16, AV_WL16)
48DEF64(be64, 8, AV_RB64, AV_WB64)
49DEF (be32, 4, AV_RB32, AV_WB32)
50DEF (be24, 3, AV_RB24, AV_WB24)
51DEF (be16, 2, AV_RB16, AV_WB16)
52DEF (byte, 1, AV_RB8 , AV_WB8 )
53
54#undef DEF
55#undef DEF64
56#undef DEF_T
57
58static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
59{
60 memcpy(dst, *b, size);
61 (*b) += size;
62 return size;
63}
64
65static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
66{
67 memcpy(*b, src, size);
68 (*b) += size;
69}
70
71#endif /* AVCODEC_BYTESTREAM_H */
diff --git a/apps/codecs/libcook/cook.c b/apps/codecs/libcook/cook.c
new file mode 100644
index 0000000000..cee69fe14a
--- /dev/null
+++ b/apps/codecs/libcook/cook.c
@@ -0,0 +1,1213 @@
1/*
2 * COOK compatible decoder
3 * Copyright (c) 2003 Sascha Sommer
4 * Copyright (c) 2005 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/cook.c
25 * Cook compatible decoder. Bastardization of the G.722.1 standard.
26 * This decoder handles RealNetworks, RealAudio G2 data.
27 * Cook is identified by the codec name cook in RM files.
28 *
29 * To use this decoder, a calling application must supply the extradata
30 * bytes provided from the RM container; 8+ bytes for mono streams and
31 * 16+ for stereo streams (maybe more).
32 *
33 * Codec technicalities (all this assume a buffer length of 1024):
34 * Cook works with several different techniques to achieve its compression.
35 * In the timedomain the buffer is divided into 8 pieces and quantized. If
36 * two neighboring pieces have different quantization index a smooth
37 * quantization curve is used to get a smooth overlap between the different
38 * pieces.
39 * To get to the transformdomain Cook uses a modulated lapped transform.
40 * The transform domain has 50 subbands with 20 elements each. This
41 * means only a maximum of 50*20=1000 coefficients are used out of the 1024
42 * available.
43 */
44
45#include <math.h>
46#include <stddef.h>
47#include <stdio.h>
48
49#include "libavutil/lfg.h"
50#include "libavutil/random_seed.h"
51#include "avcodec.h"
52#include "bitstream.h"
53#include "dsputil.h"
54#include "bytestream.h"
55
56#include "cookdata.h"
57
58/* the different Cook versions */
59#define MONO 0x1000001
60#define STEREO 0x1000002
61#define JOINT_STEREO 0x1000003
62#define MC_COOK 0x2000000 //multichannel Cook, not supported
63
64#define SUBBAND_SIZE 20
65#define MAX_SUBPACKETS 5
66//#define COOKDEBUG
67
68typedef struct {
69 int *now;
70 int *previous;
71} cook_gains;
72
73typedef struct cook {
74 /*
75 * The following 5 functions provide the lowlevel arithmetic on
76 * the internal audio buffers.
77 */
78 void (* scalar_dequant)(struct cook *q, int index, int quant_index,
79 int* subband_coef_index, int* subband_coef_sign,
80 float* mlt_p);
81
82 void (* decouple) (struct cook *q,
83 int subband,
84 float f1, float f2,
85 float *decode_buffer,
86 float *mlt_buffer1, float *mlt_buffer2);
87
88 void (* imlt_window) (struct cook *q, float *buffer1,
89 cook_gains *gains_ptr, float *previous_buffer);
90
91 void (* interpolate) (struct cook *q, float* buffer,
92 int gain_index, int gain_index_next);
93
94 void (* saturate_output) (struct cook *q, int chan, int16_t *out);
95
96 AVCodecContext* avctx;
97 GetBitContext gb;
98 /* stream data */
99 int nb_channels;
100 int joint_stereo;
101 int bit_rate;
102 int sample_rate;
103 int samples_per_channel;
104 int samples_per_frame;
105 int subbands;
106 int log2_numvector_size;
107 int numvector_size; //1 << log2_numvector_size;
108 int js_subband_start;
109 int total_subbands;
110 int num_vectors;
111 int bits_per_subpacket;
112 int cookversion;
113 /* states */
114 AVLFG random_state;
115
116 /* transform data */
117 MDCTContext mdct_ctx;
118 float* mlt_window;
119
120 /* gain buffers */
121 cook_gains gains1;
122 cook_gains gains2;
123 int gain_1[9];
124 int gain_2[9];
125 int gain_3[9];
126 int gain_4[9];
127
128 /* VLC data */
129 int js_vlc_bits;
130 VLC envelope_quant_index[13];
131 VLC sqvh[7]; //scalar quantization
132 VLC ccpl; //channel coupling
133
134 /* generatable tables and related variables */
135 int gain_size_factor;
136 float gain_table[23];
137
138 /* data buffers */
139
140 uint8_t* decoded_bytes_buffer;
141 DECLARE_ALIGNED_16(float,mono_mdct_output[2048]);
142 float mono_previous_buffer1[1024];
143 float mono_previous_buffer2[1024];
144 float decode_buffer_1[1024];
145 float decode_buffer_2[1024];
146 float decode_buffer_0[1060]; /* static allocation for joint decode */
147
148 const float *cplscales[5];
149} COOKContext;
150
151static float pow2tab[127];
152static float rootpow2tab[127];
153
154/* debug functions */
155
156#ifdef COOKDEBUG
157static void dump_float_table(float* table, int size, int delimiter) {
158 int i=0;
159 av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
160 for (i=0 ; i<size ; i++) {
161 av_log(NULL, AV_LOG_ERROR, "%5.1f, ", table[i]);
162 if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
163 }
164}
165
166static void dump_int_table(int* table, int size, int delimiter) {
167 int i=0;
168 av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
169 for (i=0 ; i<size ; i++) {
170 av_log(NULL, AV_LOG_ERROR, "%d, ", table[i]);
171 if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
172 }
173}
174
175static void dump_short_table(short* table, int size, int delimiter) {
176 int i=0;
177 av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
178 for (i=0 ; i<size ; i++) {
179 av_log(NULL, AV_LOG_ERROR, "%d, ", table[i]);
180 if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
181 }
182}
183
184#endif
185
186/*************** init functions ***************/
187
188/* table generator */
189static av_cold void init_pow2table(void){
190 int i;
191 for (i=-63 ; i<64 ; i++){
192 pow2tab[63+i]= pow(2, i);
193 rootpow2tab[63+i]=sqrt(pow(2, i));
194 }
195}
196
197/* table generator */
198static av_cold void init_gain_table(COOKContext *q) {
199 int i;
200 q->gain_size_factor = q->samples_per_channel/8;
201 for (i=0 ; i<23 ; i++) {
202 q->gain_table[i] = pow(pow2tab[i+52] ,
203 (1.0/(double)q->gain_size_factor));
204 }
205}
206
207
208static av_cold int init_cook_vlc_tables(COOKContext *q) {
209 int i, result;
210
211 result = 0;
212 for (i=0 ; i<13 ; i++) {
213 result |= init_vlc (&q->envelope_quant_index[i], 9, 24,
214 envelope_quant_index_huffbits[i], 1, 1,
215 envelope_quant_index_huffcodes[i], 2, 2, 0);
216 }
217 av_log(q->avctx,AV_LOG_DEBUG,"sqvh VLC init\n");
218 for (i=0 ; i<7 ; i++) {
219 result |= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
220 cvh_huffbits[i], 1, 1,
221 cvh_huffcodes[i], 2, 2, 0);
222 }
223
224 if (q->nb_channels==2 && q->joint_stereo==1){
225 result |= init_vlc (&q->ccpl, 6, (1<<q->js_vlc_bits)-1,
226 ccpl_huffbits[q->js_vlc_bits-2], 1, 1,
227 ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, 0);
228 av_log(q->avctx,AV_LOG_DEBUG,"Joint-stereo VLC used.\n");
229 }
230
231 av_log(q->avctx,AV_LOG_DEBUG,"VLC tables initialized.\n");
232 return result;
233}
234
235static av_cold int init_cook_mlt(COOKContext *q) {
236 int j;
237 int mlt_size = q->samples_per_channel;
238
239 if ((q->mlt_window = av_malloc(sizeof(float)*mlt_size)) == 0)
240 return -1;
241
242 /* Initialize the MLT window: simple sine window. */
243 ff_sine_window_init(q->mlt_window, mlt_size);
244 for(j=0 ; j<mlt_size ; j++)
245 q->mlt_window[j] *= sqrt(2.0 / q->samples_per_channel);
246
247 /* Initialize the MDCT. */
248 if (ff_mdct_init(&q->mdct_ctx, av_log2(mlt_size)+1, 1)) {
249 av_free(q->mlt_window);
250 return -1;
251 }
252 av_log(q->avctx,AV_LOG_DEBUG,"MDCT initialized, order = %d.\n",
253 av_log2(mlt_size)+1);
254
255 return 0;
256}
257
258static const float *maybe_reformat_buffer32 (COOKContext *q, const float *ptr, int n)
259{
260 if (1)
261 return ptr;
262}
263
264static av_cold void init_cplscales_table (COOKContext *q) {
265 int i;
266 for (i=0;i<5;i++)
267 q->cplscales[i] = maybe_reformat_buffer32 (q, cplscales[i], (1<<(i+2))-1);
268}
269
270/*************** init functions end ***********/
271
272/**
273 * Cook indata decoding, every 32 bits are XORed with 0x37c511f2.
274 * Why? No idea, some checksum/error detection method maybe.
275 *
276 * Out buffer size: extra bytes are needed to cope with
277 * padding/misalignment.
278 * Subpackets passed to the decoder can contain two, consecutive
279 * half-subpackets, of identical but arbitrary size.
280 * 1234 1234 1234 1234 extraA extraB
281 * Case 1: AAAA BBBB 0 0
282 * Case 2: AAAA ABBB BB-- 3 3
283 * Case 3: AAAA AABB BBBB 2 2
284 * Case 4: AAAA AAAB BBBB BB-- 1 5
285 *
286 * Nice way to waste CPU cycles.
287 *
288 * @param inbuffer pointer to byte array of indata
289 * @param out pointer to byte array of outdata
290 * @param bytes number of bytes
291 */
292#define DECODE_BYTES_PAD1(bytes) (3 - ((bytes)+3) % 4)
293#define DECODE_BYTES_PAD2(bytes) ((bytes) % 4 + DECODE_BYTES_PAD1(2 * (bytes)))
294
295static inline int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){
296 int i, off;
297 uint32_t c;
298 const uint32_t* buf;
299 uint32_t* obuf = (uint32_t*) out;
300 /* FIXME: 64 bit platforms would be able to do 64 bits at a time.
301 * I'm too lazy though, should be something like
302 * for(i=0 ; i<bitamount/64 ; i++)
303 * (int64_t)out[i] = 0x37c511f237c511f2^be2me_64(int64_t)in[i]);
304 * Buffer alignment needs to be checked. */
305
306 off = (intptr_t)inbuffer & 3;
307 buf = (const uint32_t*) (inbuffer - off);
308 c = be2me_32((0x37c511f2 >> (off*8)) | (0x37c511f2 << (32-(off*8))));
309 bytes += 3 + off;
310 for (i = 0; i < bytes/4; i++)
311 obuf[i] = c ^ buf[i];
312
313 return off;
314}
315
316/**
317 * Cook uninit
318 */
319
320static av_cold int cook_decode_close(AVCodecContext *avctx)
321{
322 int i;
323 COOKContext *q = avctx->priv_data;
324 av_log(avctx,AV_LOG_DEBUG, "Deallocating memory.\n");
325
326 /* Free allocated memory buffers. */
327 av_free(q->mlt_window);
328 av_free(q->decoded_bytes_buffer);
329
330 /* Free the transform. */
331 ff_mdct_end(&q->mdct_ctx);
332
333 /* Free the VLC tables. */
334 for (i=0 ; i<13 ; i++) {
335 free_vlc(&q->envelope_quant_index[i]);
336 }
337 for (i=0 ; i<7 ; i++) {
338 free_vlc(&q->sqvh[i]);
339 }
340 if(q->nb_channels==2 && q->joint_stereo==1 ){
341 free_vlc(&q->ccpl);
342 }
343
344 av_log(avctx,AV_LOG_DEBUG,"Memory deallocated.\n");
345
346 return 0;
347}
348
349/**
350 * Fill the gain array for the timedomain quantization.
351 *
352 * @param q pointer to the COOKContext
353 * @param gaininfo[9] array of gain indexes
354 */
355
356static void decode_gain_info(GetBitContext *gb, int *gaininfo)
357{
358 int i, n;
359
360 while (get_bits1(gb)) {}
361 n = get_bits_count(gb) - 1; //amount of elements*2 to update
362
363 i = 0;
364 while (n--) {
365 int index = get_bits(gb, 3);
366 int gain = get_bits1(gb) ? get_bits(gb, 4) - 7 : -1;
367
368 while (i <= index) gaininfo[i++] = gain;
369 }
370 while (i <= 8) gaininfo[i++] = 0;
371}
372
373/**
374 * Create the quant index table needed for the envelope.
375 *
376 * @param q pointer to the COOKContext
377 * @param quant_index_table pointer to the array
378 */
379
380static void decode_envelope(COOKContext *q, int* quant_index_table) {
381 int i,j, vlc_index;
382
383 quant_index_table[0]= get_bits(&q->gb,6) - 6; //This is used later in categorize
384
385 for (i=1 ; i < q->total_subbands ; i++){
386 vlc_index=i;
387 if (i >= q->js_subband_start * 2) {
388 vlc_index-=q->js_subband_start;
389 } else {
390 vlc_index/=2;
391 if(vlc_index < 1) vlc_index = 1;
392 }
393 if (vlc_index>13) vlc_index = 13; //the VLC tables >13 are identical to No. 13
394
395 j = get_vlc2(&q->gb, q->envelope_quant_index[vlc_index-1].table,
396 q->envelope_quant_index[vlc_index-1].bits,2);
397 quant_index_table[i] = quant_index_table[i-1] + j - 12; //differential encoding
398 }
399}
400
401/**
402 * Calculate the category and category_index vector.
403 *
404 * @param q pointer to the COOKContext
405 * @param quant_index_table pointer to the array
406 * @param category pointer to the category array
407 * @param category_index pointer to the category_index array
408 */
409
410static void categorize(COOKContext *q, int* quant_index_table,
411 int* category, int* category_index){
412 int exp_idx, bias, tmpbias1, tmpbias2, bits_left, num_bits, index, v, i, j;
413 int exp_index2[102];
414 int exp_index1[102];
415
416 int tmp_categorize_array[128*2];
417 int tmp_categorize_array1_idx=q->numvector_size;
418 int tmp_categorize_array2_idx=q->numvector_size;
419
420 bits_left = q->bits_per_subpacket - get_bits_count(&q->gb);
421
422 if(bits_left > q->samples_per_channel) {
423 bits_left = q->samples_per_channel +
424 ((bits_left - q->samples_per_channel)*5)/8;
425 //av_log(q->avctx, AV_LOG_ERROR, "bits_left = %d\n",bits_left);
426 }
427
428 memset(&exp_index1,0,102*sizeof(int));
429 memset(&exp_index2,0,102*sizeof(int));
430 memset(&tmp_categorize_array,0,128*2*sizeof(int));
431
432 bias=-32;
433
434 /* Estimate bias. */
435 for (i=32 ; i>0 ; i=i/2){
436 num_bits = 0;
437 index = 0;
438 for (j=q->total_subbands ; j>0 ; j--){
439 exp_idx = av_clip((i - quant_index_table[index] + bias) / 2, 0, 7);
440 index++;
441 num_bits+=expbits_tab[exp_idx];
442 }
443 if(num_bits >= bits_left - 32){
444 bias+=i;
445 }
446 }
447
448 /* Calculate total number of bits. */
449 num_bits=0;
450 for (i=0 ; i<q->total_subbands ; i++) {
451 exp_idx = av_clip((bias - quant_index_table[i]) / 2, 0, 7);
452 num_bits += expbits_tab[exp_idx];
453 exp_index1[i] = exp_idx;
454 exp_index2[i] = exp_idx;
455 }
456 tmpbias1 = tmpbias2 = num_bits;
457
458 for (j = 1 ; j < q->numvector_size ; j++) {
459 if (tmpbias1 + tmpbias2 > 2*bits_left) { /* ---> */
460 int max = -999999;
461 index=-1;
462 for (i=0 ; i<q->total_subbands ; i++){
463 if (exp_index1[i] < 7) {
464 v = (-2*exp_index1[i]) - quant_index_table[i] + bias;
465 if ( v >= max) {
466 max = v;
467 index = i;
468 }
469 }
470 }
471 if(index==-1)break;
472 tmp_categorize_array[tmp_categorize_array1_idx++] = index;
473 tmpbias1 -= expbits_tab[exp_index1[index]] -
474 expbits_tab[exp_index1[index]+1];
475 ++exp_index1[index];
476 } else { /* <--- */
477 int min = 999999;
478 index=-1;
479 for (i=0 ; i<q->total_subbands ; i++){
480 if(exp_index2[i] > 0){
481 v = (-2*exp_index2[i])-quant_index_table[i]+bias;
482 if ( v < min) {
483 min = v;
484 index = i;
485 }
486 }
487 }
488 if(index == -1)break;
489 tmp_categorize_array[--tmp_categorize_array2_idx] = index;
490 tmpbias2 -= expbits_tab[exp_index2[index]] -
491 expbits_tab[exp_index2[index]-1];
492 --exp_index2[index];
493 }
494 }
495
496 for(i=0 ; i<q->total_subbands ; i++)
497 category[i] = exp_index2[i];
498
499 for(i=0 ; i<q->numvector_size-1 ; i++)
500 category_index[i] = tmp_categorize_array[tmp_categorize_array2_idx++];
501
502}
503
504
505/**
506 * Expand the category vector.
507 *
508 * @param q pointer to the COOKContext
509 * @param category pointer to the category array
510 * @param category_index pointer to the category_index array
511 */
512
513static inline void expand_category(COOKContext *q, int* category,
514 int* category_index){
515 int i;
516 for(i=0 ; i<q->num_vectors ; i++){
517 ++category[category_index[i]];
518 }
519}
520
521/**
522 * The real requantization of the mltcoefs
523 *
524 * @param q pointer to the COOKContext
525 * @param index index
526 * @param quant_index quantisation index
527 * @param subband_coef_index array of indexes to quant_centroid_tab
528 * @param subband_coef_sign signs of coefficients
529 * @param mlt_p pointer into the mlt buffer
530 */
531
532static void scalar_dequant_float(COOKContext *q, int index, int quant_index,
533 int* subband_coef_index, int* subband_coef_sign,
534 float* mlt_p){
535 int i;
536 float f1;
537
538 for(i=0 ; i<SUBBAND_SIZE ; i++) {
539 if (subband_coef_index[i]) {
540 f1 = quant_centroid_tab[index][subband_coef_index[i]];
541 if (subband_coef_sign[i]) f1 = -f1;
542 } else {
543 /* noise coding if subband_coef_index[i] == 0 */
544 f1 = dither_tab[index];
545 if (av_lfg_get(&q->random_state) < 0x80000000) f1 = -f1;
546 }
547 mlt_p[i] = f1 * rootpow2tab[quant_index+63];
548 }
549}
550/**
551 * Unpack the subband_coef_index and subband_coef_sign vectors.
552 *
553 * @param q pointer to the COOKContext
554 * @param category pointer to the category array
555 * @param subband_coef_index array of indexes to quant_centroid_tab
556 * @param subband_coef_sign signs of coefficients
557 */
558
559static int unpack_SQVH(COOKContext *q, int category, int* subband_coef_index,
560 int* subband_coef_sign) {
561 int i,j;
562 int vlc, vd ,tmp, result;
563
564 vd = vd_tab[category];
565 result = 0;
566 for(i=0 ; i<vpr_tab[category] ; i++){
567 vlc = get_vlc2(&q->gb, q->sqvh[category].table, q->sqvh[category].bits, 3);
568 if (q->bits_per_subpacket < get_bits_count(&q->gb)){
569 vlc = 0;
570 result = 1;
571 }
572 for(j=vd-1 ; j>=0 ; j--){
573 tmp = (vlc * invradix_tab[category])/0x100000;
574 subband_coef_index[vd*i+j] = vlc - tmp * (kmax_tab[category]+1);
575 vlc = tmp;
576 }
577 for(j=0 ; j<vd ; j++){
578 if (subband_coef_index[i*vd + j]) {
579 if(get_bits_count(&q->gb) < q->bits_per_subpacket){
580 subband_coef_sign[i*vd+j] = get_bits1(&q->gb);
581 } else {
582 result=1;
583 subband_coef_sign[i*vd+j]=0;
584 }
585 } else {
586 subband_coef_sign[i*vd+j]=0;
587 }
588 }
589 }
590 return result;
591}
592
593
594/**
595 * Fill the mlt_buffer with mlt coefficients.
596 *
597 * @param q pointer to the COOKContext
598 * @param category pointer to the category array
599 * @param quant_index_table pointer to the array
600 * @param mlt_buffer pointer to mlt coefficients
601 */
602
603
604static void decode_vectors(COOKContext* q, int* category,
605 int *quant_index_table, float* mlt_buffer){
606 /* A zero in this table means that the subband coefficient is
607 random noise coded. */
608 int subband_coef_index[SUBBAND_SIZE];
609 /* A zero in this table means that the subband coefficient is a
610 positive multiplicator. */
611 int subband_coef_sign[SUBBAND_SIZE];
612 int band, j;
613 int index=0;
614
615 for(band=0 ; band<q->total_subbands ; band++){
616 index = category[band];
617 if(category[band] < 7){
618 if(unpack_SQVH(q, category[band], subband_coef_index, subband_coef_sign)){
619 index=7;
620 for(j=0 ; j<q->total_subbands ; j++) category[band+j]=7;
621 }
622 }
623 if(index>=7) {
624 memset(subband_coef_index, 0, sizeof(subband_coef_index));
625 memset(subband_coef_sign, 0, sizeof(subband_coef_sign));
626 }
627 q->scalar_dequant(q, index, quant_index_table[band],
628 subband_coef_index, subband_coef_sign,
629 &mlt_buffer[band * SUBBAND_SIZE]);
630 }
631
632 if(q->total_subbands*SUBBAND_SIZE >= q->samples_per_channel){
633 return;
634 } /* FIXME: should this be removed, or moved into loop above? */
635}
636
637
638/**
639 * function for decoding mono data
640 *
641 * @param q pointer to the COOKContext
642 * @param mlt_buffer pointer to mlt coefficients
643 */
644
645static void mono_decode(COOKContext *q, float* mlt_buffer) {
646
647 int category_index[128];
648 int quant_index_table[102];
649 int category[128];
650
651 memset(&category, 0, 128*sizeof(int));
652 memset(&category_index, 0, 128*sizeof(int));
653
654 decode_envelope(q, quant_index_table);
655 q->num_vectors = get_bits(&q->gb,q->log2_numvector_size);
656 categorize(q, quant_index_table, category, category_index);
657 expand_category(q, category, category_index);
658 decode_vectors(q, category, quant_index_table, mlt_buffer);
659}
660
661
662/**
663 * the actual requantization of the timedomain samples
664 *
665 * @param q pointer to the COOKContext
666 * @param buffer pointer to the timedomain buffer
667 * @param gain_index index for the block multiplier
668 * @param gain_index_next index for the next block multiplier
669 */
670
671static void interpolate_float(COOKContext *q, float* buffer,
672 int gain_index, int gain_index_next){
673 int i;
674 float fc1, fc2;
675 fc1 = pow2tab[gain_index+63];
676
677 if(gain_index == gain_index_next){ //static gain
678 for(i=0 ; i<q->gain_size_factor ; i++){
679 buffer[i]*=fc1;
680 }
681 return;
682 } else { //smooth gain
683 fc2 = q->gain_table[11 + (gain_index_next-gain_index)];
684 for(i=0 ; i<q->gain_size_factor ; i++){
685 buffer[i]*=fc1;
686 fc1*=fc2;
687 }
688 return;
689 }
690}
691
692/**
693 * Apply transform window, overlap buffers.
694 *
695 * @param q pointer to the COOKContext
696 * @param inbuffer pointer to the mltcoefficients
697 * @param gains_ptr current and previous gains
698 * @param previous_buffer pointer to the previous buffer to be used for overlapping
699 */
700
701static void imlt_window_float (COOKContext *q, float *buffer1,
702 cook_gains *gains_ptr, float *previous_buffer)
703{
704 const float fc = pow2tab[gains_ptr->previous[0] + 63];
705 int i;
706 /* The weird thing here, is that the two halves of the time domain
707 * buffer are swapped. Also, the newest data, that we save away for
708 * next frame, has the wrong sign. Hence the subtraction below.
709 * Almost sounds like a complex conjugate/reverse data/FFT effect.
710 */
711
712 /* Apply window and overlap */
713 for(i = 0; i < q->samples_per_channel; i++){
714 buffer1[i] = buffer1[i] * fc * q->mlt_window[i] -
715 previous_buffer[i] * q->mlt_window[q->samples_per_channel - 1 - i];
716 }
717}
718
719/**
720 * The modulated lapped transform, this takes transform coefficients
721 * and transforms them into timedomain samples.
722 * Apply transform window, overlap buffers, apply gain profile
723 * and buffer management.
724 *
725 * @param q pointer to the COOKContext
726 * @param inbuffer pointer to the mltcoefficients
727 * @param gains_ptr current and previous gains
728 * @param previous_buffer pointer to the previous buffer to be used for overlapping
729 */
730
731static void imlt_gain(COOKContext *q, float *inbuffer,
732 cook_gains *gains_ptr, float* previous_buffer)
733{
734 float *buffer0 = q->mono_mdct_output;
735 float *buffer1 = q->mono_mdct_output + q->samples_per_channel;
736 int i;
737
738 /* Inverse modified discrete cosine transform */
739 ff_imdct_calc(&q->mdct_ctx, q->mono_mdct_output, inbuffer);
740
741 q->imlt_window (q, buffer1, gains_ptr, previous_buffer);
742
743 /* Apply gain profile */
744 for (i = 0; i < 8; i++) {
745 if (gains_ptr->now[i] || gains_ptr->now[i + 1])
746 q->interpolate(q, &buffer1[q->gain_size_factor * i],
747 gains_ptr->now[i], gains_ptr->now[i + 1]);
748 }
749
750 /* Save away the current to be previous block. */
751 memcpy(previous_buffer, buffer0, sizeof(float)*q->samples_per_channel);
752}
753
754
755/**
756 * function for getting the jointstereo coupling information
757 *
758 * @param q pointer to the COOKContext
759 * @param decouple_tab decoupling array
760 *
761 */
762
763static void decouple_info(COOKContext *q, int* decouple_tab){
764 int length, i;
765
766 if(get_bits1(&q->gb)) {
767 if(cplband[q->js_subband_start] > cplband[q->subbands-1]) return;
768
769 length = cplband[q->subbands-1] - cplband[q->js_subband_start] + 1;
770 for (i=0 ; i<length ; i++) {
771 decouple_tab[cplband[q->js_subband_start] + i] = get_vlc2(&q->gb, q->ccpl.table, q->ccpl.bits, 2);
772 }
773 return;
774 }
775
776 if(cplband[q->js_subband_start] > cplband[q->subbands-1]) return;
777
778 length = cplband[q->subbands-1] - cplband[q->js_subband_start] + 1;
779 for (i=0 ; i<length ; i++) {
780 decouple_tab[cplband[q->js_subband_start] + i] = get_bits(&q->gb, q->js_vlc_bits);
781 }
782 return;
783}
784
785/*
786 * function decouples a pair of signals from a single signal via multiplication.
787 *
788 * @param q pointer to the COOKContext
789 * @param subband index of the current subband
790 * @param f1 multiplier for channel 1 extraction
791 * @param f2 multiplier for channel 2 extraction
792 * @param decode_buffer input buffer
793 * @param mlt_buffer1 pointer to left channel mlt coefficients
794 * @param mlt_buffer2 pointer to right channel mlt coefficients
795 */
796static void decouple_float (COOKContext *q,
797 int subband,
798 float f1, float f2,
799 float *decode_buffer,
800 float *mlt_buffer1, float *mlt_buffer2)
801{
802 int j, tmp_idx;
803 for (j=0 ; j<SUBBAND_SIZE ; j++) {
804 tmp_idx = ((q->js_subband_start + subband)*SUBBAND_SIZE)+j;
805 mlt_buffer1[SUBBAND_SIZE*subband + j] = f1 * decode_buffer[tmp_idx];
806 mlt_buffer2[SUBBAND_SIZE*subband + j] = f2 * decode_buffer[tmp_idx];
807 }
808}
809
810/**
811 * function for decoding joint stereo data
812 *
813 * @param q pointer to the COOKContext
814 * @param mlt_buffer1 pointer to left channel mlt coefficients
815 * @param mlt_buffer2 pointer to right channel mlt coefficients
816 */
817
818static void joint_decode(COOKContext *q, float* mlt_buffer1,
819 float* mlt_buffer2) {
820 int i,j;
821 int decouple_tab[SUBBAND_SIZE];
822 float *decode_buffer = q->decode_buffer_0;
823 int idx, cpl_tmp;
824 float f1,f2;
825 const float* cplscale;
826
827 memset(decouple_tab, 0, sizeof(decouple_tab));
828 memset(decode_buffer, 0, sizeof(decode_buffer));
829
830 /* Make sure the buffers are zeroed out. */
831 memset(mlt_buffer1,0, 1024*sizeof(float));
832 memset(mlt_buffer2,0, 1024*sizeof(float));
833 decouple_info(q, decouple_tab);
834 mono_decode(q, decode_buffer);
835
836 /* The two channels are stored interleaved in decode_buffer. */
837 for (i=0 ; i<q->js_subband_start ; i++) {
838 for (j=0 ; j<SUBBAND_SIZE ; j++) {
839 mlt_buffer1[i*20+j] = decode_buffer[i*40+j];
840 mlt_buffer2[i*20+j] = decode_buffer[i*40+20+j];
841 }
842 }
843
844 /* When we reach js_subband_start (the higher frequencies)
845 the coefficients are stored in a coupling scheme. */
846 idx = (1 << q->js_vlc_bits) - 1;
847 for (i=q->js_subband_start ; i<q->subbands ; i++) {
848 cpl_tmp = cplband[i];
849 idx -=decouple_tab[cpl_tmp];
850 cplscale = q->cplscales[q->js_vlc_bits-2]; //choose decoupler table
851 f1 = cplscale[decouple_tab[cpl_tmp]];
852 f2 = cplscale[idx-1];
853 q->decouple (q, i, f1, f2, decode_buffer, mlt_buffer1, mlt_buffer2);
854 idx = (1 << q->js_vlc_bits) - 1;
855 }
856}
857
858/**
859 * First part of subpacket decoding:
860 * decode raw stream bytes and read gain info.
861 *
862 * @param q pointer to the COOKContext
863 * @param inbuffer pointer to raw stream data
864 * @param gain_ptr array of current/prev gain pointers
865 */
866
867static inline void
868decode_bytes_and_gain(COOKContext *q, const uint8_t *inbuffer,
869 cook_gains *gains_ptr)
870{
871 int offset;
872
873 offset = decode_bytes(inbuffer, q->decoded_bytes_buffer,
874 q->bits_per_subpacket/8);
875 init_get_bits(&q->gb, q->decoded_bytes_buffer + offset,
876 q->bits_per_subpacket);
877 decode_gain_info(&q->gb, gains_ptr->now);
878
879 /* Swap current and previous gains */
880 FFSWAP(int *, gains_ptr->now, gains_ptr->previous);
881}
882
883 /**
884 * Saturate the output signal to signed 16bit integers.
885 *
886 * @param q pointer to the COOKContext
887 * @param chan channel to saturate
888 * @param out pointer to the output vector
889 */
890static void
891saturate_output_float (COOKContext *q, int chan, int16_t *out)
892{
893 int j;
894 float *output = q->mono_mdct_output + q->samples_per_channel;
895 /* Clip and convert floats to 16 bits.
896 */
897 for (j = 0; j < q->samples_per_channel; j++) {
898 out[chan + q->nb_channels * j] =
899 av_clip_int16(lrintf(output[j]));
900 }
901}
902
903/**
904 * Final part of subpacket decoding:
905 * Apply modulated lapped transform, gain compensation,
906 * clip and convert to integer.
907 *
908 * @param q pointer to the COOKContext
909 * @param decode_buffer pointer to the mlt coefficients
910 * @param gain_ptr array of current/prev gain pointers
911 * @param previous_buffer pointer to the previous buffer to be used for overlapping
912 * @param out pointer to the output buffer
913 * @param chan 0: left or single channel, 1: right channel
914 */
915
916static inline void
917mlt_compensate_output(COOKContext *q, float *decode_buffer,
918 cook_gains *gains, float *previous_buffer,
919 int16_t *out, int chan)
920{
921 imlt_gain(q, decode_buffer, gains, previous_buffer);
922 q->saturate_output (q, chan, out);
923}
924
925
926/**
927 * Cook subpacket decoding. This function returns one decoded subpacket,
928 * usually 1024 samples per channel.
929 *
930 * @param q pointer to the COOKContext
931 * @param inbuffer pointer to the inbuffer
932 * @param sub_packet_size subpacket size
933 * @param outbuffer pointer to the outbuffer
934 */
935
936
937static int decode_subpacket(COOKContext *q, const uint8_t *inbuffer,
938 int sub_packet_size, int16_t *outbuffer) {
939 /* packet dump */
940// for (i=0 ; i<sub_packet_size ; i++) {
941// av_log(q->avctx, AV_LOG_ERROR, "%02x", inbuffer[i]);
942// }
943// av_log(q->avctx, AV_LOG_ERROR, "\n");
944
945 decode_bytes_and_gain(q, inbuffer, &q->gains1);
946
947 if (q->joint_stereo) {
948 joint_decode(q, q->decode_buffer_1, q->decode_buffer_2);
949 } else {
950 mono_decode(q, q->decode_buffer_1);
951
952 if (q->nb_channels == 2) {
953 decode_bytes_and_gain(q, inbuffer + sub_packet_size/2, &q->gains2);
954 mono_decode(q, q->decode_buffer_2);
955 }
956 }
957
958 mlt_compensate_output(q, q->decode_buffer_1, &q->gains1,
959 q->mono_previous_buffer1, outbuffer, 0);
960
961 if (q->nb_channels == 2) {
962 if (q->joint_stereo) {
963 mlt_compensate_output(q, q->decode_buffer_2, &q->gains1,
964 q->mono_previous_buffer2, outbuffer, 1);
965 } else {
966 mlt_compensate_output(q, q->decode_buffer_2, &q->gains2,
967 q->mono_previous_buffer2, outbuffer, 1);
968 }
969 }
970 return q->samples_per_frame * sizeof(int16_t);
971}
972
973
974/**
975 * Cook frame decoding
976 *
977 * @param avctx pointer to the AVCodecContext
978 */
979
980static int cook_decode_frame(AVCodecContext *avctx,
981 void *data, int *data_size,
982 const uint8_t *buf, int buf_size) {
983 COOKContext *q = avctx->priv_data;
984
985 if (buf_size < avctx->block_align)
986 return buf_size;
987
988 *data_size = decode_subpacket(q, buf, avctx->block_align, data);
989
990 /* Discard the first two frames: no valid audio. */
991 if (avctx->frame_number < 2) *data_size = 0;
992
993 return avctx->block_align;
994}
995
996#ifdef COOKDEBUG
997static void dump_cook_context(COOKContext *q)
998{
999 //int i=0;
1000#define PRINT(a,b) av_log(q->avctx,AV_LOG_ERROR," %s = %d\n", a, b);
1001 av_log(q->avctx,AV_LOG_ERROR,"COOKextradata\n");
1002 av_log(q->avctx,AV_LOG_ERROR,"cookversion=%x\n",q->cookversion);
1003 if (q->cookversion > STEREO) {
1004 PRINT("js_subband_start",q->js_subband_start);
1005 PRINT("js_vlc_bits",q->js_vlc_bits);
1006 }
1007 av_log(q->avctx,AV_LOG_ERROR,"COOKContext\n");
1008 PRINT("nb_channels",q->nb_channels);
1009 PRINT("bit_rate",q->bit_rate);
1010 PRINT("sample_rate",q->sample_rate);
1011 PRINT("samples_per_channel",q->samples_per_channel);
1012 PRINT("samples_per_frame",q->samples_per_frame);
1013 PRINT("subbands",q->subbands);
1014 PRINT("random_state",q->random_state);
1015 PRINT("js_subband_start",q->js_subband_start);
1016 PRINT("log2_numvector_size",q->log2_numvector_size);
1017 PRINT("numvector_size",q->numvector_size);
1018 PRINT("total_subbands",q->total_subbands);
1019}
1020#endif
1021
1022static av_cold int cook_count_channels(unsigned int mask){
1023 int i;
1024 int channels = 0;
1025 for(i = 0;i<32;i++){
1026 if(mask & (1<<i))
1027 ++channels;
1028 }
1029 return channels;
1030}
1031
1032/**
1033 * Cook initialization
1034 *
1035 * @param avctx pointer to the AVCodecContext
1036 */
1037
1038static av_cold int cook_decode_init(AVCodecContext *avctx)
1039{
1040 COOKContext *q = avctx->priv_data;
1041 const uint8_t *edata_ptr = avctx->extradata;
1042 q->avctx = avctx;
1043
1044 /* Take care of the codec specific extradata. */
1045 if (avctx->extradata_size <= 0) {
1046 av_log(avctx,AV_LOG_ERROR,"Necessary extradata missing!\n");
1047 return -1;
1048 } else {
1049 /* 8 for mono, 16 for stereo, ? for multichannel
1050 Swap to right endianness so we don't need to care later on. */
1051 av_log(avctx,AV_LOG_DEBUG,"codecdata_length=%d\n",avctx->extradata_size);
1052 if (avctx->extradata_size >= 8){
1053 q->cookversion = bytestream_get_be32(&edata_ptr);
1054 q->samples_per_frame = bytestream_get_be16(&edata_ptr);
1055 q->subbands = bytestream_get_be16(&edata_ptr);
1056 }
1057 if (avctx->extradata_size >= 16){
1058 bytestream_get_be32(&edata_ptr); //Unknown unused
1059 q->js_subband_start = bytestream_get_be16(&edata_ptr);
1060 q->js_vlc_bits = bytestream_get_be16(&edata_ptr);
1061 }
1062 }
1063
1064 /* Take data from the AVCodecContext (RM container). */
1065 q->sample_rate = avctx->sample_rate;
1066 q->nb_channels = avctx->channels;
1067 q->bit_rate = avctx->bit_rate;
1068
1069 /* Initialize RNG. */
1070 av_lfg_init(&q->random_state, ff_random_get_seed());
1071
1072 /* Initialize extradata related variables. */
1073 q->samples_per_channel = q->samples_per_frame / q->nb_channels;
1074 q->bits_per_subpacket = avctx->block_align * 8;
1075
1076 /* Initialize default data states. */
1077 q->log2_numvector_size = 5;
1078 q->total_subbands = q->subbands;
1079
1080 /* Initialize version-dependent variables */
1081 av_log(avctx,AV_LOG_DEBUG,"q->cookversion=%x\n",q->cookversion);
1082 q->joint_stereo = 0;
1083 switch (q->cookversion) {
1084 case MONO:
1085 if (q->nb_channels != 1) {
1086 av_log(avctx,AV_LOG_ERROR,"Container channels != 1, report sample!\n");
1087 return -1;
1088 }
1089 av_log(avctx,AV_LOG_DEBUG,"MONO\n");
1090 break;
1091 case STEREO:
1092 if (q->nb_channels != 1) {
1093 q->bits_per_subpacket = q->bits_per_subpacket/2;
1094 }
1095 av_log(avctx,AV_LOG_DEBUG,"STEREO\n");
1096 break;
1097 case JOINT_STEREO:
1098 if (q->nb_channels != 2) {
1099 av_log(avctx,AV_LOG_ERROR,"Container channels != 2, report sample!\n");
1100 return -1;
1101 }
1102 av_log(avctx,AV_LOG_DEBUG,"JOINT_STEREO\n");
1103 if (avctx->extradata_size >= 16){
1104 q->total_subbands = q->subbands + q->js_subband_start;
1105 q->joint_stereo = 1;
1106 }
1107 if (q->samples_per_channel > 256) {
1108 q->log2_numvector_size = 6;
1109 }
1110 if (q->samples_per_channel > 512) {
1111 q->log2_numvector_size = 7;
1112 }
1113 break;
1114 case MC_COOK:
1115 av_log(avctx,AV_LOG_ERROR,"MC_COOK not supported!\n");
1116 return -1;
1117 break;
1118 default:
1119 av_log(avctx,AV_LOG_ERROR,"Unknown Cook version, report sample!\n");
1120 return -1;
1121 break;
1122 }
1123
1124 /* Initialize variable relations */
1125 q->numvector_size = (1 << q->log2_numvector_size);
1126
1127 /* Generate tables */
1128 init_pow2table();
1129 init_gain_table(q);
1130 init_cplscales_table(q);
1131
1132 if (init_cook_vlc_tables(q) != 0)
1133 return -1;
1134
1135
1136 if(avctx->block_align >= UINT_MAX/2)
1137 return -1;
1138
1139 /* Pad the databuffer with:
1140 DECODE_BYTES_PAD1 or DECODE_BYTES_PAD2 for decode_bytes(),
1141 FF_INPUT_BUFFER_PADDING_SIZE, for the bitstreamreader. */
1142 if (q->nb_channels==2 && q->joint_stereo==0) {
1143 q->decoded_bytes_buffer =
1144 av_mallocz(avctx->block_align/2
1145 + DECODE_BYTES_PAD2(avctx->block_align/2)
1146 + FF_INPUT_BUFFER_PADDING_SIZE);
1147 } else {
1148 q->decoded_bytes_buffer =
1149 av_mallocz(avctx->block_align
1150 + DECODE_BYTES_PAD1(avctx->block_align)
1151 + FF_INPUT_BUFFER_PADDING_SIZE);
1152 }
1153 if (q->decoded_bytes_buffer == NULL)
1154 return -1;
1155
1156 q->gains1.now = q->gain_1;
1157 q->gains1.previous = q->gain_2;
1158 q->gains2.now = q->gain_3;
1159 q->gains2.previous = q->gain_4;
1160
1161 /* Initialize transform. */
1162 if ( init_cook_mlt(q) != 0 )
1163 return -1;
1164
1165 /* Initialize COOK signal arithmetic handling */
1166 if (1) {
1167 q->scalar_dequant = scalar_dequant_float;
1168 q->decouple = decouple_float;
1169 q->imlt_window = imlt_window_float;
1170 q->interpolate = interpolate_float;
1171 q->saturate_output = saturate_output_float;
1172 }
1173
1174 /* Try to catch some obviously faulty streams, othervise it might be exploitable */
1175 if (q->total_subbands > 53) {
1176 av_log(avctx,AV_LOG_ERROR,"total_subbands > 53, report sample!\n");
1177 return -1;
1178 }
1179 if (q->subbands > 50) {
1180 av_log(avctx,AV_LOG_ERROR,"subbands > 50, report sample!\n");
1181 return -1;
1182 }
1183 if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512) || (q->samples_per_channel == 1024)) {
1184 } else {
1185 av_log(avctx,AV_LOG_ERROR,"unknown amount of samples_per_channel = %d, report sample!\n",q->samples_per_channel);
1186 return -1;
1187 }
1188 if ((q->js_vlc_bits > 6) || (q->js_vlc_bits < 0)) {
1189 av_log(avctx,AV_LOG_ERROR,"q->js_vlc_bits = %d, only >= 0 and <= 6 allowed!\n",q->js_vlc_bits);
1190 return -1;
1191 }
1192
1193 avctx->sample_fmt = SAMPLE_FMT_S16;
1194 avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
1195
1196#ifdef COOKDEBUG
1197 dump_cook_context(q);
1198#endif
1199 return 0;
1200}
1201
1202
1203AVCodec cook_decoder =
1204{
1205 .name = "cook",
1206 .type = CODEC_TYPE_AUDIO,
1207 .id = CODEC_ID_COOK,
1208 .priv_data_size = sizeof(COOKContext),
1209 .init = cook_decode_init,
1210 .close = cook_decode_close,
1211 .decode = cook_decode_frame,
1212 .long_name = NULL_IF_CONFIG_SMALL("COOK"),
1213};
diff --git a/apps/codecs/libcook/cookdata.h b/apps/codecs/libcook/cookdata.h
new file mode 100644
index 0000000000..e2e81fbab6
--- /dev/null
+++ b/apps/codecs/libcook/cookdata.h
@@ -0,0 +1,563 @@
1/*
2 * COOK compatible decoder data
3 * Copyright (c) 2003 Sascha Sommer
4 * Copyright (c) 2005 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/cookdata.h
25 * Cook AKA RealAudio G2 compatible decoderdata
26 */
27
28#ifndef AVCODEC_COOKDATA_H
29#define AVCODEC_COOKDATA_H
30
31#include <stdint.h>
32
33/* various data tables */
34
35static const int expbits_tab[8] = {
36 52,47,43,37,29,22,16,0,
37};
38
39static const float dither_tab[8] = {
40 0.0, 0.0, 0.0, 0.0, 0.0, 0.176777, 0.25, 0.707107,
41};
42
43static const float quant_centroid_tab[7][14] = {
44 { 0.000, 0.392, 0.761, 1.120, 1.477, 1.832, 2.183, 2.541, 2.893, 3.245, 3.598, 3.942, 4.288, 4.724 },
45 { 0.000, 0.544, 1.060, 1.563, 2.068, 2.571, 3.072, 3.562, 4.070, 4.620, 0.000, 0.000, 0.000, 0.000 },
46 { 0.000, 0.746, 1.464, 2.180, 2.882, 3.584, 4.316, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 },
47 { 0.000, 1.006, 2.000, 2.993, 3.985, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 },
48 { 0.000, 1.321, 2.703, 3.983, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 },
49 { 0.000, 1.657, 3.491, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 },
50 { 0.000, 1.964, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 }
51};
52
53static const int invradix_tab[7] = {
54 74899, 104858, 149797, 209716, 262144, 349526, 524288,
55};
56
57static const int kmax_tab[7] = {
58 13, 9, 6, 4, 3, 2, 1,
59};
60
61static const int vd_tab[7] = {
62 2, 2, 2, 4, 4, 5, 5,
63};
64
65static const int vpr_tab[7] = {
66 10, 10, 10, 5, 5, 4, 4,
67};
68
69
70
71/* VLC data */
72
73static const int vhsize_tab[7] = {
74 191, 97, 48, 607, 246, 230, 32,
75};
76
77static const int vhvlcsize_tab[7] = {
78 8, 7, 7, 10, 9, 9, 6,
79};
80
81static const uint8_t envelope_quant_index_huffbits[13][24] = {
82 { 4, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 4, 5, 7, 8, 9, 11, 11, 12, 12, 12, 12 },
83 { 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 7, 9, 11, 12, 13, 15, 15, 15, 16, 16 },
84 { 12, 10, 8, 6, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 4, 4, 5, 5, 7, 9, 11, 13, 14, 14 },
85 { 13, 10, 9, 9, 7, 7, 5, 5, 4, 3, 3, 3, 3, 3, 4, 4, 4, 5, 7, 9, 11, 13, 13, 13 },
86 { 12, 13, 10, 8, 6, 6, 5, 5, 4, 4, 3, 3, 3, 3, 3, 4, 5, 5, 6, 7, 9, 11, 14, 14 },
87 { 12, 11, 9, 8, 8, 7, 5, 4, 4, 3, 3, 3, 3, 3, 4, 4, 5, 5, 7, 8, 10, 13, 14, 14 },
88 { 15, 16, 15, 12, 10, 8, 6, 5, 4, 3, 3, 3, 2, 3, 4, 5, 5, 7, 9, 11, 13, 16, 16, 16 },
89 { 14, 14, 11, 10, 9, 7, 7, 5, 5, 4, 3, 3, 2, 3, 3, 4, 5, 7, 9, 9, 12, 14, 15, 15 },
90 { 9, 9, 9, 8, 7, 6, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 13 },
91 { 14, 12, 10, 8, 6, 6, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 6, 8, 8, 9, 11, 14, 14, 14 },
92 { 13, 10, 9, 8, 6, 6, 5, 4, 4, 4, 3, 3, 2, 3, 4, 5, 6, 8, 9, 9, 11, 12, 14, 14 },
93 { 16, 13, 12, 11, 9, 6, 5, 5, 4, 4, 4, 3, 2, 3, 3, 4, 5, 7, 8, 10, 14, 16, 16, 16 },
94 { 13, 14, 14, 14, 10, 8, 7, 7, 5, 4, 3, 3, 2, 3, 3, 4, 5, 5, 7, 9, 11, 14, 14, 14 },
95};
96
97static const uint16_t envelope_quant_index_huffcodes[13][24] = {
98 {0x0006, 0x003e, 0x001c, 0x001d, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x0000, 0x0001,
99 0x0002, 0x000d, 0x001e, 0x007e, 0x00fe, 0x01fe, 0x07fc, 0x07fd, 0x0ffc, 0x0ffd, 0x0ffe, 0x0fff},
100 {0x03fe, 0x00fe, 0x003e, 0x001c, 0x001d, 0x000c, 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005,
101 0x000d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x0ffe, 0x1ffe, 0x7ffc, 0x7ffd, 0x7ffe, 0xfffe, 0xffff},
102 {0x0ffe, 0x03fe, 0x00fe, 0x003e, 0x001c, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x0000,
103 0x0001, 0x0002, 0x000c, 0x000d, 0x001d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x1ffe, 0x3ffe, 0x3fff},
104 {0x1ffc, 0x03fe, 0x01fc, 0x01fd, 0x007c, 0x007d, 0x001c, 0x001d, 0x000a, 0x0000, 0x0001, 0x0002,
105 0x0003, 0x0004, 0x000b, 0x000c, 0x000d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x1ffd, 0x1ffe, 0x1fff},
106 {0x0ffe, 0x1ffe, 0x03fe, 0x00fe, 0x003c, 0x003d, 0x001a, 0x001b, 0x000a, 0x000b, 0x0000, 0x0001,
107 0x0002, 0x0003, 0x0004, 0x000c, 0x001c, 0x001d, 0x003e, 0x007e, 0x01fe, 0x07fe, 0x3ffe, 0x3fff},
108 {0x0ffe, 0x07fe, 0x01fe, 0x00fc, 0x00fd, 0x007c, 0x001c, 0x000a, 0x000b, 0x0000, 0x0001, 0x0002,
109 0x0003, 0x0004, 0x000c, 0x000d, 0x001d, 0x001e, 0x007d, 0x00fe, 0x03fe, 0x1ffe, 0x3ffe, 0x3fff},
110 {0x7ffc, 0xfffc, 0x7ffd, 0x0ffe, 0x03fe, 0x00fe, 0x003e, 0x001c, 0x000c, 0x0002, 0x0003, 0x0004,
111 0x0000, 0x0005, 0x000d, 0x001d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x1ffe, 0xfffd, 0xfffe, 0xffff},
112 {0x3ffc, 0x3ffd, 0x07fe, 0x03fe, 0x01fc, 0x007c, 0x007d, 0x001c, 0x001d, 0x000c, 0x0002, 0x0003,
113 0x0000, 0x0004, 0x0005, 0x000d, 0x001e, 0x007e, 0x01fd, 0x01fe, 0x0ffe, 0x3ffe, 0x7ffe, 0x7fff},
114 {0x01fc, 0x01fd, 0x01fe, 0x00fc, 0x007c, 0x003c, 0x001c, 0x000c, 0x0000, 0x0001, 0x0002, 0x0003,
115 0x0004, 0x0005, 0x000d, 0x001d, 0x003d, 0x007d, 0x00fd, 0x03fe, 0x07fe, 0x0ffe, 0x1ffe, 0x1fff},
116 {0x3ffc, 0x0ffe, 0x03fe, 0x00fc, 0x003c, 0x003d, 0x001c, 0x000c, 0x0000, 0x0001, 0x0002, 0x0003,
117 0x0004, 0x0005, 0x000d, 0x001d, 0x003e, 0x00fd, 0x00fe, 0x01fe, 0x07fe, 0x3ffd, 0x3ffe, 0x3fff},
118 {0x1ffe, 0x03fe, 0x01fc, 0x00fc, 0x003c, 0x003d, 0x001c, 0x000a, 0x000b, 0x000c, 0x0002, 0x0003,
119 0x0000, 0x0004, 0x000d, 0x001d, 0x003e, 0x00fd, 0x01fd, 0x01fe, 0x07fe, 0x0ffe, 0x3ffe, 0x3fff},
120 {0xfffc, 0x1ffe, 0x0ffe, 0x07fe, 0x01fe, 0x003e, 0x001c, 0x001d, 0x000a, 0x000b, 0x000c, 0x0002,
121 0x0000, 0x0003, 0x0004, 0x000d, 0x001e, 0x007e, 0x00fe, 0x03fe, 0x3ffe, 0xfffd, 0xfffe, 0xffff},
122 {0x1ffc, 0x3ffa, 0x3ffb, 0x3ffc, 0x03fe, 0x00fe, 0x007c, 0x007d, 0x001c, 0x000c, 0x0002, 0x0003,
123 0x0000, 0x0004, 0x0005, 0x000d, 0x001d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x3ffd, 0x3ffe, 0x3fff},
124};
125
126
127static const uint8_t cvh_huffbits0[191] = {
128 1, 4, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10,
129 11, 11, 4, 5, 6, 7, 7, 8, 8, 9, 9, 9,
130 9, 10, 11, 11, 5, 6, 7, 8, 8, 9, 9, 9,
131 9, 10, 10, 10, 11, 12, 6, 7, 8, 9, 9, 9,
132 9, 10, 10, 10, 10, 11, 12, 13, 7, 7, 8, 9,
133 9, 9, 10, 10, 10, 10, 11, 11, 12, 13, 8, 8,
134 9, 9, 9, 10, 10, 10, 10, 11, 11, 12, 13, 14,
135 8, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 13,
136 13, 15, 8, 8, 9, 9, 10, 10, 11, 11, 11, 12,
137 12, 13, 14, 15, 9, 9, 9, 10, 10, 10, 11, 11,
138 12, 13, 12, 14, 15, 16, 9, 9, 10, 10, 10, 10,
139 11, 12, 12, 14, 14, 16, 16, 0, 9, 9, 10, 10,
140 11, 11, 12, 13, 13, 14, 14, 15, 0, 0, 10, 10,
141 10, 11, 11, 12, 12, 13, 15, 15, 16, 0, 0, 0,
142 11, 11, 11, 12, 13, 13, 13, 15, 16, 16, 0, 0,
143 0, 0, 11, 11, 12, 13, 13, 14, 15, 16, 16,
144};
145
146static const uint16_t cvh_huffcodes0[191] = {
147 0x0000,0x0008,0x002c,0x002d,0x0062,0x0063,0x00d4,0x00d5,0x00d6,0x01c6,0x01c7,0x03ca,
148 0x07d6,0x07d7,0x0009,0x0014,0x002e,0x0064,0x0065,0x00d7,0x00d8,0x01c8,0x01c9,0x01ca,
149 0x01cb,0x03cb,0x07d8,0x07d9,0x0015,0x002f,0x0066,0x00d9,0x00da,0x01cc,0x01cd,0x01ce,
150 0x01cf,0x03cc,0x03cd,0x03ce,0x07da,0x0fe4,0x0030,0x0067,0x00db,0x01d0,0x01d1,0x01d2,
151 0x01d3,0x03cf,0x03d0,0x03d1,0x03d2,0x07db,0x0fe5,0x1fea,0x0068,0x0069,0x00dc,0x01d4,
152 0x01d5,0x01d6,0x03d3,0x03d4,0x03d5,0x03d6,0x07dc,0x07dd,0x0fe6,0x1feb,0x00dd,0x00de,
153 0x01d7,0x01d8,0x01d9,0x03d7,0x03d8,0x03d9,0x03da,0x07de,0x07df,0x0fe7,0x1fec,0x3ff2,
154 0x00df,0x00e0,0x01da,0x01db,0x03db,0x03dc,0x07e0,0x07e1,0x07e2,0x0fe8,0x0fe9,0x1fed,
155 0x1fee,0x7ff4,0x00e1,0x00e2,0x01dc,0x01dd,0x03dd,0x03de,0x07e3,0x07e4,0x07e5,0x0fea,
156 0x0feb,0x1fef,0x3ff3,0x7ff5,0x01de,0x01df,0x01e0,0x03df,0x03e0,0x03e1,0x07e6,0x07e7,
157 0x0fec,0x1ff0,0x0fed,0x3ff4,0x7ff6,0xfff8,0x01e1,0x01e2,0x03e2,0x03e3,0x03e4,0x03e5,
158 0x07e8,0x0fee,0x0fef,0x3ff5,0x3ff6,0xfff9,0xfffa,0xfffa,0x01e3,0x01e4,0x03e6,0x03e7,
159 0x07e9,0x07ea,0x0ff0,0x1ff1,0x1ff2,0x3ff7,0x3ff8,0x7ff7,0x7ff7,0xfffa,0x03e8,0x03e9,
160 0x03ea,0x07eb,0x07ec,0x0ff1,0x0ff2,0x1ff3,0x7ff8,0x7ff9,0xfffb,0x3ff8,0x7ff7,0x7ff7,
161 0x07ed,0x07ee,0x07ef,0x0ff3,0x1ff4,0x1ff5,0x1ff6,0x7ffa,0xfffc,0xfffd,0xfffb,0xfffb,
162 0x3ff8,0x7ff7,0x07f0,0x07f1,0x0ff4,0x1ff7,0x1ff8,0x3ff9,0x7ffb,0xfffe,0xffff,
163};
164
165
166static const uint8_t cvh_huffbits1[97] = {
167 1, 4, 5, 6, 7, 8, 8, 9, 10, 10, 4, 5,
168 6, 7, 7, 8, 8, 9, 9, 11, 5, 5, 6, 7,
169 8, 8, 9, 9, 10, 11, 6, 6, 7, 8, 8, 9,
170 9, 10, 11, 12, 7, 7, 8, 8, 9, 9, 10, 11,
171 11, 13, 8, 8, 8, 9, 9, 10, 10, 11, 12, 14,
172 8, 8, 8, 9, 10, 11, 11, 12, 13, 15, 9, 9,
173 9, 10, 11, 12, 12, 14, 14, 0, 9, 9, 9, 10,
174 11, 12, 14, 16, 0, 0, 10, 10, 11, 12, 13, 14,
175 16,
176};
177
178
179static const uint16_t cvh_huffcodes1[97] = {
180 0x0000,0x0008,0x0014,0x0030,0x006a,0x00e2,0x00e3,0x01e4,0x03ec,0x03ed,0x0009,0x0015,
181 0x0031,0x006b,0x006c,0x00e4,0x00e5,0x01e5,0x01e6,0x07f0,0x0016,0x0017,0x0032,0x006d,
182 0x00e6,0x00e7,0x01e7,0x01e8,0x03ee,0x07f1,0x0033,0x0034,0x006e,0x00e8,0x00e9,0x01e9,
183 0x01ea,0x03ef,0x07f2,0x0ff6,0x006f,0x0070,0x00ea,0x00eb,0x01eb,0x01ec,0x03f0,0x07f3,
184 0x07f4,0x1ffa,0x00ec,0x00ed,0x00ee,0x01ed,0x01ee,0x03f1,0x03f2,0x07f5,0x0ff7,0x3ffa,
185 0x00ef,0x00f0,0x00f1,0x01ef,0x03f3,0x07f6,0x07f7,0x0ff8,0x1ffb,0x7ffe,0x01f0,0x01f1,
186 0x01f2,0x03f4,0x07f8,0x0ff9,0x0ffa,0x3ffb,0x3ffc,0x0000,0x01f3,0x01f4,0x01f5,0x03f5,
187 0x07f9,0x0ffb,0x3ffd,0xfffe,0x0000,0x0000,0x03f6,0x03f7,0x07fa,0x0ffc,0x1ffc,0x3ffe,
188 0xffff,
189};
190
191static const uint8_t cvh_huffbits2[48] = {
192 1, 4, 5, 7, 8, 9, 10, 3, 4, 5, 7, 8,
193 9, 10, 5, 5, 6, 7, 8, 10, 10, 7, 6, 7,
194 8, 9, 10, 12, 8, 8, 8, 9, 10, 12, 14, 8,
195 9, 9, 10, 11, 15, 16, 9, 10, 11, 12, 13, 16,
196};
197
198static const uint16_t cvh_huffcodes2[48] = {
199 0x0000,0x000a,0x0018,0x0074,0x00f2,0x01f4,0x03f6,0x0004,0x000b,0x0019,0x0075,0x00f3,
200 0x01f5,0x03f7,0x001a,0x001b,0x0038,0x0076,0x00f4,0x03f8,0x03f9,0x0077,0x0039,0x0078,
201 0x00f5,0x01f6,0x03fa,0x0ffc,0x00f6,0x00f7,0x00f8,0x01f7,0x03fb,0x0ffd,0x3ffe,0x00f9,
202 0x01f8,0x01f9,0x03fc,0x07fc,0x7ffe,0xfffe,0x01fa,0x03fd,0x07fd,0x0ffe,0x1ffe,0xffff,
203};
204
205static const uint8_t cvh_huffbits3[607] = {
206 2, 4, 6, 8, 10, 5, 5, 6, 8, 10, 7, 8,
207 8, 10, 12, 9, 9, 10, 12, 15, 10, 11, 13, 16,
208 16, 5, 6, 8, 10, 11, 5, 6, 8, 10, 12, 7,
209 7, 8, 10, 13, 9, 9, 10, 12, 15, 12, 11, 13,
210 16, 16, 7, 9, 10, 12, 15, 7, 8, 10, 12, 13,
211 9, 9, 11, 13, 16, 11, 11, 12, 14, 16, 12, 12,
212 14, 16, 0, 9, 11, 12, 16, 16, 9, 10, 13, 15,
213 16, 10, 11, 12, 16, 16, 13, 13, 16, 16, 16, 16,
214 16, 15, 16, 0, 11, 13, 16, 16, 15, 11, 13, 15,
215 16, 16, 13, 13, 16, 16, 0, 14, 16, 16, 16, 0,
216 16, 16, 0, 0, 0, 4, 6, 8, 10, 13, 6, 6,
217 8, 10, 13, 9, 8, 10, 12, 16, 10, 10, 11, 15,
218 16, 13, 12, 14, 16, 16, 5, 6, 8, 11, 13, 6,
219 6, 8, 10, 13, 8, 8, 9, 11, 14, 10, 10, 12,
220 12, 16, 13, 12, 13, 15, 16, 7, 8, 9, 12, 16,
221 7, 8, 10, 12, 14, 9, 9, 10, 13, 16, 11, 10,
222 12, 15, 16, 13, 13, 16, 16, 0, 9, 11, 13, 16,
223 16, 9, 10, 12, 15, 16, 10, 11, 13, 16, 16, 13,
224 12, 16, 16, 16, 16, 16, 16, 16, 0, 11, 13, 16,
225 16, 16, 11, 13, 16, 16, 16, 12, 13, 15, 16, 0,
226 16, 16, 16, 16, 0, 16, 16, 0, 0, 0, 6, 8,
227 11, 13, 16, 8, 8, 10, 12, 16, 11, 10, 11, 13,
228 16, 12, 13, 13, 15, 16, 16, 16, 14, 16, 0, 6,
229 8, 10, 13, 16, 8, 8, 10, 12, 16, 10, 10, 11,
230 13, 16, 13, 12, 13, 16, 16, 14, 14, 14, 16, 0,
231 8, 9, 11, 13, 16, 8, 9, 11, 16, 14, 10, 10,
232 12, 15, 16, 12, 12, 13, 16, 16, 15, 16, 16, 16,
233 0, 10, 12, 15, 16, 16, 10, 12, 12, 14, 16, 12,
234 12, 13, 16, 16, 14, 15, 16, 16, 0, 16, 16, 16,
235 0, 0, 12, 15, 15, 16, 0, 13, 13, 16, 16, 0,
236 14, 16, 16, 16, 0, 16, 16, 16, 0, 0, 0, 0,
237 0, 0, 0, 8, 10, 13, 15, 16, 10, 11, 13, 16,
238 16, 13, 13, 14, 16, 16, 16, 16, 16, 16, 16, 16,
239 16, 16, 16, 0, 8, 10, 11, 15, 16, 9, 10, 12,
240 16, 16, 12, 12, 15, 16, 16, 16, 14, 16, 16, 16,
241 16, 16, 16, 16, 0, 9, 11, 14, 16, 16, 10, 11,
242 13, 16, 16, 14, 13, 14, 16, 16, 16, 15, 15, 16,
243 0, 16, 16, 16, 0, 0, 11, 13, 16, 16, 16, 11,
244 13, 15, 16, 16, 13, 16, 16, 16, 0, 16, 16, 16,
245 16, 0, 16, 16, 0, 0, 0, 15, 16, 16, 16, 0,
246 14, 16, 16, 16, 0, 16, 16, 16, 0, 0, 16, 16,
247 0, 0, 0, 0, 0, 0, 0, 0, 9, 13, 16, 16,
248 16, 11, 13, 16, 16, 16, 14, 15, 16, 16, 0, 15,
249 16, 16, 16, 0, 16, 16, 0, 0, 0, 9, 13, 15,
250 15, 16, 12, 13, 14, 16, 16, 16, 15, 16, 16, 0,
251 16, 16, 16, 16, 0, 16, 16, 0, 0, 0, 11, 13,
252 15, 16, 0, 12, 14, 16, 16, 0, 16, 16, 16, 16,
253 0, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 16,
254 16, 16, 16, 0, 16, 16, 16, 16, 0, 16, 16, 16,
255 0, 0, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0,
256 16, 16, 0, 0, 0, 16, 16,
257};
258
259
260static const uint16_t cvh_huffcodes3[607] = {
261 0x0000,0x0004,0x0022,0x00c6,0x03b0,0x000c,0x000d,0x0023,0x00c7,0x03b1,0x005c,0x00c8,
262 0x00c9,0x03b2,0x0fa4,0x01c2,0x01c3,0x03b3,0x0fa5,0x7f72,0x03b4,0x07b2,0x1f9a,0xff24,
263 0xff25,0x000e,0x0024,0x00ca,0x03b5,0x07b3,0x000f,0x0025,0x00cb,0x03b6,0x0fa6,0x005d,
264 0x005e,0x00cc,0x03b7,0x1f9b,0x01c4,0x01c5,0x03b8,0x0fa7,0x7f73,0x0fa8,0x07b4,0x1f9c,
265 0xff26,0xff27,0x005f,0x01c6,0x03b9,0x0fa9,0x7f74,0x0060,0x00cd,0x03ba,0x0faa,0x1f9d,
266 0x01c7,0x01c8,0x07b5,0x1f9e,0xff28,0x07b6,0x07b7,0x0fab,0x3fa2,0xff29,0x0fac,0x0fad,
267 0x3fa3,0xff2a,0x3fa2,0x01c9,0x07b8,0x0fae,0xff2b,0xff2c,0x01ca,0x03bb,0x1f9f,0x7f75,
268 0xff2d,0x03bc,0x07b9,0x0faf,0xff2e,0xff2f,0x1fa0,0x1fa1,0xff30,0xff31,0xff32,0xff33,
269 0xff34,0x7f76,0xff35,0xff31,0x07ba,0x1fa2,0xff36,0xff37,0x7f77,0x07bb,0x1fa3,0x7f78,
270 0xff38,0xff39,0x1fa4,0x1fa5,0xff3a,0xff3b,0xff2e,0x3fa4,0xff3c,0xff3d,0xff3e,0xff31,
271 0xff3f,0xff40,0xff30,0xff31,0xff31,0x0005,0x0026,0x00ce,0x03bd,0x1fa6,0x0027,0x0028,
272 0x00cf,0x03be,0x1fa7,0x01cb,0x00d0,0x03bf,0x0fb0,0xff41,0x03c0,0x03c1,0x07bc,0x7f79,
273 0xff42,0x1fa8,0x0fb1,0x3fa5,0xff43,0xff44,0x0010,0x0029,0x00d1,0x07bd,0x1fa9,0x002a,
274 0x002b,0x00d2,0x03c2,0x1faa,0x00d3,0x00d4,0x01cc,0x07be,0x3fa6,0x03c3,0x03c4,0x0fb2,
275 0x0fb3,0xff45,0x1fab,0x0fb4,0x1fac,0x7f7a,0xff46,0x0061,0x00d5,0x01cd,0x0fb5,0xff47,
276 0x0062,0x00d6,0x03c5,0x0fb6,0x3fa7,0x01ce,0x01cf,0x03c6,0x1fad,0xff48,0x07bf,0x03c7,
277 0x0fb7,0x7f7b,0xff49,0x1fae,0x1faf,0xff4a,0xff4b,0x7f7b,0x01d0,0x07c0,0x1fb0,0xff4c,
278 0xff4d,0x01d1,0x03c8,0x0fb8,0x7f7c,0xff4e,0x03c9,0x07c1,0x1fb1,0xff4f,0xff50,0x1fb2,
279 0x0fb9,0xff51,0xff52,0xff53,0xff54,0xff55,0xff56,0xff57,0xff52,0x07c2,0x1fb3,0xff58,
280 0xff59,0xff5a,0x07c3,0x1fb4,0xff5b,0xff5c,0xff5d,0x0fba,0x1fb5,0x7f7d,0xff5e,0xff4f,
281 0xff5f,0xff60,0xff61,0xff62,0xff52,0xff63,0xff64,0xff51,0xff52,0xff52,0x002c,0x00d7,
282 0x07c4,0x1fb6,0xff65,0x00d8,0x00d9,0x03ca,0x0fbb,0xff66,0x07c5,0x03cb,0x07c6,0x1fb7,
283 0xff67,0x0fbc,0x1fb8,0x1fb9,0x7f7e,0xff68,0xff69,0xff6a,0x3fa8,0xff6b,0x7f7e,0x002d,
284 0x00da,0x03cc,0x1fba,0xff6c,0x00db,0x00dc,0x03cd,0x0fbd,0xff6d,0x03ce,0x03cf,0x07c7,
285 0x1fbb,0xff6e,0x1fbc,0x0fbe,0x1fbd,0xff6f,0xff70,0x3fa9,0x3faa,0x3fab,0xff71,0xff6f,
286 0x00dd,0x01d2,0x07c8,0x1fbe,0xff72,0x00de,0x01d3,0x07c9,0xff73,0x3fac,0x03d0,0x03d1,
287 0x0fbf,0x7f7f,0xff74,0x0fc0,0x0fc1,0x1fbf,0xff75,0xff76,0x7f80,0xff77,0xff78,0xff79,
288 0xff75,0x03d2,0x0fc2,0x7f81,0xff7a,0xff7b,0x03d3,0x0fc3,0x0fc4,0x3fad,0xff7c,0x0fc5,
289 0x0fc6,0x1fc0,0xff7d,0xff7e,0x3fae,0x7f82,0xff7f,0xff80,0xff80,0xff81,0xff82,0xff83,
290 0xff80,0xff80,0x0fc7,0x7f83,0x7f84,0xff84,0xff7a,0x1fc1,0x1fc2,0xff85,0xff86,0x3fad,
291 0x3faf,0xff87,0xff88,0xff89,0xff7d,0xff8a,0xff8b,0xff8c,0xff80,0xff80,0x3fae,0x7f82,
292 0xff7f,0xff80,0xff80,0x00df,0x03d4,0x1fc3,0x7f85,0xff8d,0x03d5,0x07ca,0x1fc4,0xff8e,
293 0xff8f,0x1fc5,0x1fc6,0x3fb0,0xff90,0xff91,0xff92,0xff93,0xff94,0xff95,0xff96,0xff97,
294 0xff98,0xff99,0xff9a,0xff95,0x00e0,0x03d6,0x07cb,0x7f86,0xff9b,0x01d4,0x03d7,0x0fc8,
295 0xff9c,0xff9d,0x0fc9,0x0fca,0x7f87,0xff9e,0xff9f,0xffa0,0x3fb1,0xffa1,0xffa2,0xffa3,
296 0xffa4,0xffa5,0xffa6,0xffa7,0xffa2,0x01d5,0x07cc,0x3fb2,0xffa8,0xffa9,0x03d8,0x07cd,
297 0x1fc7,0xffaa,0xffab,0x3fb3,0x1fc8,0x3fb4,0xffac,0xffad,0xffae,0x7f88,0x7f89,0xffaf,
298 0xffaf,0xffb0,0xffb1,0xffb2,0xffaf,0xffaf,0x07ce,0x1fc9,0xffb3,0xffb4,0xffb5,0x07cf,
299 0x1fca,0x7f8a,0xffb6,0xffb7,0x1fcb,0xffb8,0xffb9,0xffba,0xffba,0xffbb,0xffbc,0xffbd,
300 0xffbe,0xffbe,0xffbf,0xffc0,0xffbd,0xffbe,0xffbe,0x7f8b,0xffc1,0xffc2,0xffc3,0xffb4,
301 0x3fb5,0xffc4,0xffc5,0xffc6,0xffb6,0xffc7,0xffc8,0xffc9,0xffba,0xffba,0xffca,0xffcb,
302 0xffbd,0xffbe,0xffbe,0xffbb,0xffbc,0xffbd,0xffbe,0xffbe,0x01d6,0x1fcc,0xffcc,0xffcd,
303 0xffce,0x07d0,0x1fcd,0xffcf,0xffd0,0xffd1,0x3fb6,0x7f8c,0xffd2,0xffd3,0xff90,0x7f8d,
304 0xffd4,0xffd5,0xffd6,0xff95,0xffd7,0xffd8,0xff94,0xff95,0xff95,0x01d7,0x1fce,0x7f8e,
305 0x7f8f,0xffd9,0x0fcb,0x1fcf,0x3fb7,0xffda,0xffdb,0xffdc,0x7f90,0xffdd,0xffde,0xff9e,
306 0xffdf,0xffe0,0xffe1,0xffe2,0xffa2,0xffe3,0xffe4,0xffa1,0xffa2,0xffa2,0x07d1,0x1fd0,
307 0x7f91,0xffe5,0xffa8,0x0fcc,0x3fb8,0xffe6,0xffe7,0xffaa,0xffe8,0xffe9,0xffea,0xffeb,
308 0xffac,0xffec,0xffed,0xffee,0xffaf,0xffaf,0xffae,0x7f88,0x7f89,0xffaf,0xffaf,0xffef,
309 0xfff0,0xfff1,0xfff2,0xffb4,0xfff3,0xfff4,0xfff5,0xfff6,0xffb6,0xfff7,0xfff8,0xfff9,
310 0xffba,0xffba,0xfffa,0xfffb,0xffbd,0xffbe,0xffbe,0xffbb,0xffbc,0xffbd,0xffbe,0xffbe,
311 0xfffc,0xfffd,0xffb3,0xffb4,0xffb4,0xfffe,0xffff,
312};
313
314static const uint8_t cvh_huffbits4[246] = {
315 2, 4, 7, 10, 4, 5, 7, 10, 7, 8, 10, 14,
316 11, 11, 15, 15, 4, 5, 9, 12, 5, 5, 8, 12,
317 8, 7, 10, 15, 11, 11, 15, 15, 7, 9, 12, 15,
318 8, 8, 12, 15, 10, 10, 13, 15, 14, 14, 15, 0,
319 11, 13, 15, 15, 11, 13, 15, 15, 14, 15, 15, 0,
320 15, 15, 0, 0, 4, 5, 9, 13, 5, 6, 9, 13,
321 9, 9, 11, 15, 14, 13, 15, 15, 4, 6, 9, 12,
322 5, 6, 9, 13, 9, 8, 11, 15, 13, 12, 15, 15,
323 7, 9, 12, 15, 7, 8, 11, 15, 10, 10, 14, 15,
324 14, 15, 15, 0, 10, 12, 15, 15, 11, 13, 15, 15,
325 15, 15, 15, 0, 15, 15, 0, 0, 6, 9, 13, 14,
326 8, 9, 12, 15, 12, 12, 15, 15, 15, 15, 15, 0,
327 7, 9, 13, 15, 8, 9, 12, 15, 11, 12, 15, 15,
328 15, 15, 15, 0, 9, 11, 15, 15, 9, 11, 15, 15,
329 14, 14, 15, 0, 15, 15, 0, 0, 14, 15, 15, 0,
330 14, 15, 15, 0, 15, 15, 0, 0, 0, 0, 0, 0,
331 9, 12, 15, 15, 12, 13, 15, 15, 15, 15, 15, 0,
332 15, 15, 0, 0, 10, 12, 15, 15, 12, 14, 15, 15,
333 15, 15, 15, 0, 15, 15, 0, 0, 14, 15, 15, 0,
334 15, 15, 15, 0, 15, 15, 0, 0, 0, 0, 0, 0,
335 15, 15, 0, 0, 15, 15,
336};
337
338
339static const uint16_t cvh_huffcodes4[246] = {
340 0x0000,0x0004,0x006c,0x03e6,0x0005,0x0012,0x006d,0x03e7,0x006e,0x00e8,0x03e8,0x3fc4,
341 0x07e0,0x07e1,0x7fa4,0x7fa5,0x0006,0x0013,0x01e2,0x0fda,0x0014,0x0015,0x00e9,0x0fdb,
342 0x00ea,0x006f,0x03e9,0x7fa6,0x07e2,0x07e3,0x7fa7,0x7fa8,0x0070,0x01e3,0x0fdc,0x7fa9,
343 0x00eb,0x00ec,0x0fdd,0x7faa,0x03ea,0x03eb,0x1fd6,0x7fab,0x3fc5,0x3fc6,0x7fac,0x1fd6,
344 0x07e4,0x1fd7,0x7fad,0x7fae,0x07e5,0x1fd8,0x7faf,0x7fb0,0x3fc7,0x7fb1,0x7fb2,0x1fd6,
345 0x7fb3,0x7fb4,0x1fd6,0x1fd6,0x0007,0x0016,0x01e4,0x1fd9,0x0017,0x0032,0x01e5,0x1fda,
346 0x01e6,0x01e7,0x07e6,0x7fb5,0x3fc8,0x1fdb,0x7fb6,0x7fb7,0x0008,0x0033,0x01e8,0x0fde,
347 0x0018,0x0034,0x01e9,0x1fdc,0x01ea,0x00ed,0x07e7,0x7fb8,0x1fdd,0x0fdf,0x7fb9,0x7fba,
348 0x0071,0x01eb,0x0fe0,0x7fbb,0x0072,0x00ee,0x07e8,0x7fbc,0x03ec,0x03ed,0x3fc9,0x7fbd,
349 0x3fca,0x7fbe,0x7fbf,0x3fc9,0x03ee,0x0fe1,0x7fc0,0x7fc1,0x07e9,0x1fde,0x7fc2,0x7fc3,
350 0x7fc4,0x7fc5,0x7fc6,0x3fc9,0x7fc7,0x7fc8,0x3fc9,0x3fc9,0x0035,0x01ec,0x1fdf,0x3fcb,
351 0x00ef,0x01ed,0x0fe2,0x7fc9,0x0fe3,0x0fe4,0x7fca,0x7fcb,0x7fcc,0x7fcd,0x7fce,0x7fca,
352 0x0073,0x01ee,0x1fe0,0x7fcf,0x00f0,0x01ef,0x0fe5,0x7fd0,0x07ea,0x0fe6,0x7fd1,0x7fd2,
353 0x7fd3,0x7fd4,0x7fd5,0x7fd1,0x01f0,0x07eb,0x7fd6,0x7fd7,0x01f1,0x07ec,0x7fd8,0x7fd9,
354 0x3fcc,0x3fcd,0x7fda,0x7fda,0x7fdb,0x7fdc,0x7fda,0x7fda,0x3fce,0x7fdd,0x7fde,0x7fd6,
355 0x3fcf,0x7fdf,0x7fe0,0x7fd8,0x7fe1,0x7fe2,0x7fda,0x7fda,0x3fcc,0x3fcd,0x7fda,0x7fda,
356 0x01f2,0x0fe7,0x7fe3,0x7fe4,0x0fe8,0x1fe1,0x7fe5,0x7fe6,0x7fe7,0x7fe8,0x7fe9,0x7fca,
357 0x7fea,0x7feb,0x7fca,0x7fca,0x03ef,0x0fe9,0x7fec,0x7fed,0x0fea,0x3fd0,0x7fee,0x7fef,
358 0x7ff0,0x7ff1,0x7ff2,0x7fd1,0x7ff3,0x7ff4,0x7fd1,0x7fd1,0x3fd1,0x7ff5,0x7ff6,0x7fd6,
359 0x7ff7,0x7ff8,0x7ff9,0x7fd8,0x7ffa,0x7ffb,0x7fda,0x7fda,0x3fcc,0x3fcd,0x7fda,0x7fda,
360 0x7ffc,0x7ffd,0x7fd6,0x7fd6,0x7ffe,0x7fff,
361};
362
363
364static const uint8_t cvh_huffbits5[230] = {
365 2, 4, 8, 4, 5, 9, 9, 10, 14, 4, 6, 11,
366 5, 6, 12, 10, 11, 15, 9, 11, 15, 10, 13, 15,
367 14, 15, 0, 4, 6, 12, 6, 7, 12, 12, 12, 15,
368 5, 7, 13, 6, 7, 13, 12, 13, 15, 10, 12, 15,
369 11, 13, 15, 15, 15, 0, 8, 13, 15, 11, 12, 15,
370 15, 15, 0, 10, 13, 15, 12, 15, 15, 15, 15, 0,
371 15, 15, 0, 15, 15, 0, 0, 0, 0, 4, 5, 11,
372 5, 7, 12, 11, 12, 15, 6, 7, 13, 7, 8, 14,
373 12, 14, 15, 11, 13, 15, 12, 13, 15, 15, 15, 0,
374 5, 6, 13, 7, 8, 15, 12, 14, 15, 6, 8, 14,
375 7, 8, 15, 14, 15, 15, 12, 12, 15, 12, 13, 15,
376 15, 15, 0, 9, 13, 15, 12, 13, 15, 15, 15, 0,
377 11, 13, 15, 13, 13, 15, 15, 15, 0, 14, 15, 0,
378 15, 15, 0, 0, 0, 0, 8, 10, 15, 11, 12, 15,
379 15, 15, 0, 10, 12, 15, 12, 13, 15, 15, 15, 0,
380 14, 15, 0, 15, 15, 0, 0, 0, 0, 8, 12, 15,
381 12, 13, 15, 15, 15, 0, 11, 13, 15, 13, 15, 15,
382 15, 15, 0, 15, 15, 0, 15, 15, 0, 0, 0, 0,
383 14, 15, 0, 15, 15, 0, 0, 0, 0, 15, 15, 0,
384 15, 15,
385};
386
387
388
389static const uint16_t cvh_huffcodes5[230] = {
390 0x0000,0x0004,0x00f0,0x0005,0x0012,0x01f0,0x01f1,0x03e8,0x3fce,0x0006,0x0030,0x07de,
391 0x0013,0x0031,0x0fd2,0x03e9,0x07df,0x7fb0,0x01f2,0x07e0,0x7fb1,0x03ea,0x1fd2,0x7fb2,
392 0x3fcf,0x7fb3,0x0031,0x0007,0x0032,0x0fd3,0x0033,0x0070,0x0fd4,0x0fd5,0x0fd6,0x7fb4,
393 0x0014,0x0071,0x1fd3,0x0034,0x0072,0x1fd4,0x0fd7,0x1fd5,0x7fb5,0x03eb,0x0fd8,0x7fb6,
394 0x07e1,0x1fd6,0x7fb7,0x7fb8,0x7fb9,0x0072,0x00f1,0x1fd7,0x7fba,0x07e2,0x0fd9,0x7fbb,
395 0x7fbc,0x7fbd,0x0070,0x03ec,0x1fd8,0x7fbe,0x0fda,0x7fbf,0x7fc0,0x7fc1,0x7fc2,0x0072,
396 0x7fc3,0x7fc4,0x0071,0x7fc5,0x7fc6,0x0072,0x0034,0x0072,0x0072,0x0008,0x0015,0x07e3,
397 0x0016,0x0073,0x0fdb,0x07e4,0x0fdc,0x7fc7,0x0035,0x0074,0x1fd9,0x0075,0x00f2,0x3fd0,
398 0x0fdd,0x3fd1,0x7fc8,0x07e5,0x1fda,0x7fc9,0x0fde,0x1fdb,0x7fca,0x7fcb,0x7fcc,0x00f2,
399 0x0017,0x0036,0x1fdc,0x0076,0x00f3,0x7fcd,0x0fdf,0x3fd2,0x7fce,0x0037,0x00f4,0x3fd3,
400 0x0077,0x00f5,0x7fcf,0x3fd4,0x7fd0,0x7fd1,0x0fe0,0x0fe1,0x7fd2,0x0fe2,0x1fdd,0x7fd3,
401 0x7fd4,0x7fd5,0x00f5,0x01f3,0x1fde,0x7fd6,0x0fe3,0x1fdf,0x7fd7,0x7fd8,0x7fd9,0x00f3,
402 0x07e6,0x1fe0,0x7fda,0x1fe1,0x1fe2,0x7fdb,0x7fdc,0x7fdd,0x00f5,0x3fd5,0x7fde,0x00f4,
403 0x7fdf,0x7fe0,0x00f5,0x0077,0x00f5,0x00f5,0x00f6,0x03ed,0x7fe1,0x07e7,0x0fe4,0x7fe2,
404 0x7fe3,0x7fe4,0x0073,0x03ee,0x0fe5,0x7fe5,0x0fe6,0x1fe3,0x7fe6,0x7fe7,0x7fe8,0x00f2,
405 0x3fd6,0x7fe9,0x0074,0x7fea,0x7feb,0x00f2,0x0075,0x00f2,0x00f2,0x00f7,0x0fe7,0x7fec,
406 0x0fe8,0x1fe4,0x7fed,0x7fee,0x7fef,0x00f3,0x07e8,0x1fe5,0x7ff0,0x1fe6,0x7ff1,0x7ff2,
407 0x7ff3,0x7ff4,0x00f5,0x7ff5,0x7ff6,0x00f4,0x7ff7,0x7ff8,0x00f5,0x0077,0x00f5,0x00f5,
408 0x3fd7,0x7ff9,0x0036,0x7ffa,0x7ffb,0x00f3,0x0076,0x00f3,0x00f3,0x7ffc,0x7ffd,0x0000,
409 0x7ffe,0x7fff,
410};
411
412
413static const uint8_t cvh_huffbits6[32] = {
414 1, 4, 4, 6, 4, 6, 6, 8, 4, 6, 6, 8,
415 6, 9, 8, 10, 4, 6, 7, 8, 6, 9, 8, 11,
416 6, 9, 8, 10, 8, 10, 9, 11,
417};
418
419static const uint16_t cvh_huffcodes6[32] = {
420 0x0000,0x0008,0x0009,0x0034,0x000a,0x0035,0x0036,0x00f6,0x000b,0x0037,0x0038,0x00f7,
421 0x0039,0x01fa,0x00f8,0x03fc,0x000c,0x003a,0x007a,0x00f9,0x003b,0x01fb,0x00fa,0x07fe,
422 0x003c,0x01fc,0x00fb,0x03fd,0x00fc,0x03fe,0x01fd,0x07ff,
423};
424
425static const uint16_t* const cvh_huffcodes[7] = {
426 cvh_huffcodes0, cvh_huffcodes1, cvh_huffcodes2, cvh_huffcodes3,
427 cvh_huffcodes4, cvh_huffcodes5, cvh_huffcodes6,
428};
429
430static const uint8_t* const cvh_huffbits[7] = {
431 cvh_huffbits0, cvh_huffbits1, cvh_huffbits2, cvh_huffbits3,
432 cvh_huffbits4, cvh_huffbits5, cvh_huffbits6,
433};
434
435
436static const uint16_t ccpl_huffcodes2[3] = {
437 0x02,0x00,0x03,
438};
439
440static const uint16_t ccpl_huffcodes3[7] = {
441 0x3e,0x1e,0x02,0x00,0x06,0x0e,0x3f,
442};
443
444static const uint16_t ccpl_huffcodes4[15] = {
445 0xfc,0xfd,0x7c,0x3c,0x1c,0x0c,0x04,0x00,0x05,0x0d,0x1d,0x3d,
446 0x7d,0xfe,0xff,
447};
448
449static const uint16_t ccpl_huffcodes5[31] = {
450 0x03f8,0x03f9,0x03fa,0x03fb,0x01f8,0x01f9,0x00f8,0x00f9,0x0078,0x0079,0x0038,0x0039,
451 0x0018,0x0019,0x0004,0x0000,0x0005,0x001a,0x001b,0x003a,0x003b,0x007a,0x007b,0x00fa,
452 0x00fb,0x01fa,0x01fb,0x03fc,0x03fd,0x03fe,0x03ff,
453};
454
455static const uint16_t ccpl_huffcodes6[63] = {
456 0x0004,0x0005,0x0005,0x0006,0x0006,0x0007,0x0007,0x0007,0x0007,0x0008,0x0008,0x0008,
457 0x0008,0x0009,0x0009,0x0009,0x0009,0x000a,0x000a,0x000a,0x000a,0x000a,0x000b,0x000b,
458 0x000b,0x000b,0x000c,0x000d,0x000e,0x000e,0x0010,0x0000,0x000a,0x0018,0x0019,0x0036,
459 0x0037,0x0074,0x0075,0x0076,0x0077,0x00f4,0x00f5,0x00f6,0x00f7,0x01f5,0x01f6,0x01f7,
460 0x01f8,0x03f6,0x03f7,0x03f8,0x03f9,0x03fa,0x07fa,0x07fb,0x07fc,0x07fd,0x0ffd,0x1ffd,
461 0x3ffd,0x3ffe,0xffff,
462};
463
464static const uint8_t ccpl_huffbits2[3] = {
465 2,1,2,
466};
467
468static const uint8_t ccpl_huffbits3[7] = {
469 6,5,2,1,3,4,6,
470};
471
472static const uint8_t ccpl_huffbits4[15] = {
473 8,8,7,6,5,4,3,1,3,4,5,6,7,8,8,
474};
475
476static const uint8_t ccpl_huffbits5[31] = {
477 10,10,10,10,9,9,8,8,7,7,6,6,
478 5,5,3,1,3,5,5,6,6,7,7,8,
479 8,9,9,10,10,10,10,
480};
481
482static const uint8_t ccpl_huffbits6[63] = {
483 16,15,14,13,12,11,11,11,11,10,10,10,
484 10,9,9,9,9,9,8,8,8,8,7,7,
485 7,7,6,6,5,5,3,1,4,5,5,6,
486 6,7,7,7,7,8,8,8,8,9,9,9,
487 9,10,10,10,10,10,11,11,11,11,12,13,
488 14,14,16,
489};
490
491static const uint16_t* const ccpl_huffcodes[5] = {
492 ccpl_huffcodes2,ccpl_huffcodes3,
493 ccpl_huffcodes4,ccpl_huffcodes5,ccpl_huffcodes6
494};
495
496static const uint8_t* const ccpl_huffbits[5] = {
497 ccpl_huffbits2,ccpl_huffbits3,
498 ccpl_huffbits4,ccpl_huffbits5,ccpl_huffbits6
499};
500
501
502//Coupling tables
503
504static const int cplband[51] = {
505 0,1,2,3,4,5,6,7,8,9,
506 10,11,11,12,12,13,13,14,14,14,
507 15,15,15,15,16,16,16,16,16,17,
508 17,17,17,17,17,18,18,18,18,18,
509 18,18,19,19,19,19,19,19,19,19,
510 19,
511};
512
513static const float cplscale2[3] = {
5140.953020632266998,0.70710676908493,0.302905440330505,
515};
516
517static const float cplscale3[7] = {
5180.981279790401459,0.936997592449188,0.875934481620789,0.70710676908493,
5190.482430040836334,0.349335819482803,0.192587479948997,
520};
521
522static const float cplscale4[15] = {
5230.991486728191376,0.973249018192291,0.953020632266998,0.930133521556854,
5240.903453230857849,0.870746195316315,0.826180458068848,0.70710676908493,
5250.563405573368073,0.491732746362686,0.428686618804932,0.367221474647522,
5260.302905440330505,0.229752898216248,0.130207896232605,
527};
528
529static const float cplscale5[31] = {
5300.995926380157471,0.987517595291138,0.978726446628571,0.969505727291107,
5310.95979779958725,0.949531257152557,0.938616216182709,0.926936149597168,
5320.914336204528809,0.900602877140045,0.885426938533783,0.868331849575043,
5330.84851086139679,0.824381768703461,0.791833400726318,0.70710676908493,
5340.610737144947052,0.566034197807312,0.529177963733673,0.495983630418777,
5350.464778542518616,0.434642940759659,0.404955863952637,0.375219136476517,
5360.344963222742081,0.313672333955765,0.280692428350449,0.245068684220314,
5370.205169528722763,0.157508864998817,0.0901700109243393,
538};
539
540static const float cplscale6[63] = {
5410.998005926609039,0.993956744670868,0.989822506904602,0.985598564147949,
5420.981279790401459,0.976860702037811,0.972335040569305,0.967696130275726,
5430.962936460971832,0.958047747612000,0.953020632266998,0.947844684123993,
5440.942508161067963,0.936997592449188,0.931297719478607,0.925390899181366,
5450.919256627559662,0.912870943546295,0.906205296516418,0.899225592613220,
5460.891890347003937,0.884148240089417,0.875934481620789,0.867165684700012,
5470.857730865478516,0.847477376461029,0.836184680461884,0.823513329029083,
5480.808890223503113,0.791194140911102,0.767520070075989,0.707106769084930,
5490.641024887561798,0.611565053462982,0.587959706783295,0.567296981811523,
5500.548448026180267,0.530831515789032,0.514098942279816,0.498019754886627,
5510.482430040836334,0.467206478118896,0.452251672744751,0.437485188245773,
5520.422837972640991,0.408248275518417,0.393658757209778,0.379014074802399,
5530.364258885383606,0.349335819482803,0.334183186292648,0.318732559680939,
5540.302905440330505,0.286608695983887,0.269728302955627,0.252119421958923,
5550.233590632677078,0.213876649737358,0.192587479948997,0.169101938605309,
5560.142307326197624,0.109772264957428,0.0631198287010193,
557};
558
559static const float* const cplscales[5] = {
560 cplscale2, cplscale3, cplscale4, cplscale5, cplscale6,
561};
562
563#endif /* AVCODEC_COOKDATA_H */
diff --git a/apps/codecs/libcook/dsputil.h b/apps/codecs/libcook/dsputil.h
new file mode 100644
index 0000000000..e9c2bfc77e
--- /dev/null
+++ b/apps/codecs/libcook/dsputil.h
@@ -0,0 +1,898 @@
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;
40typedef int DWTELEM;
41typedef short IDWTELEM;
42
43void fdct_ifast (DCTELEM *data);
44void fdct_ifast248 (DCTELEM *data);
45void ff_jpeg_fdct_islow (DCTELEM *data);
46void ff_fdct248_islow (DCTELEM *data);
47
48void j_rev_dct (DCTELEM *data);
49void j_rev_dct4 (DCTELEM *data);
50void j_rev_dct2 (DCTELEM *data);
51void j_rev_dct1 (DCTELEM *data);
52void ff_wmv2_idct_c(DCTELEM *data);
53
54void ff_fdct_mmx(DCTELEM *block);
55void ff_fdct_mmx2(DCTELEM *block);
56void ff_fdct_sse2(DCTELEM *block);
57
58void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride);
59void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride);
60void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
61void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
62void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block);
63void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block);
64void ff_h264_idct_add16_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
65void ff_h264_idct_add16intra_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
66void ff_h264_idct8_add4_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
67void ff_h264_idct_add8_c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
68
69void ff_vector_fmul_add_add_c(float *dst, const float *src0, const float *src1,
70 const float *src2, int src3, int blocksize, int step);
71void ff_vector_fmul_window_c(float *dst, const float *src0, const float *src1,
72 const float *win, float add_bias, int len);
73void ff_float_to_int16_c(int16_t *dst, const float *src, long len);
74void ff_float_to_int16_interleave_c(int16_t *dst, const float **src, long len, int channels);
75
76/* encoding scans */
77extern const uint8_t ff_alternate_horizontal_scan[64];
78extern const uint8_t ff_alternate_vertical_scan[64];
79extern const uint8_t ff_zigzag_direct[64];
80extern const uint8_t ff_zigzag248_direct[64];
81
82/* pixel operations */
83#define MAX_NEG_CROP 1024
84
85/* temporary */
86extern uint32_t ff_squareTbl[512];
87extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP];
88
89/* VP3 DSP functions */
90void ff_vp3_idct_c(DCTELEM *block/* align 16*/);
91void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
92void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
93
94void ff_vp3_v_loop_filter_c(uint8_t *src, int stride, int *bounding_values);
95void ff_vp3_h_loop_filter_c(uint8_t *src, int stride, int *bounding_values);
96
97/* VP6 DSP functions */
98void ff_vp6_filter_diag4_c(uint8_t *dst, uint8_t *src, int stride,
99 const int16_t *h_weights, const int16_t *v_weights);
100
101/* 1/2^n downscaling functions from imgconvert.c */
102void ff_img_copy_plane(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
103void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
104void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
105void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
106
107void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
108 int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
109
110/* minimum alignment rules ;)
111If you notice errors in the align stuff, need more alignment for some ASM code
112for some CPU or need to use a function with less aligned data then send a mail
113to the ffmpeg-devel mailing list, ...
114
115!warning These alignments might not match reality, (missing attribute((align))
116stuff somewhere possible).
117I (Michael) did not check them, these are just the alignments which I think
118could be reached easily ...
119
120!future video codecs might need functions with less strict alignment
121*/
122
123/*
124void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
125void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
126void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
127void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
128void clear_blocks_c(DCTELEM *blocks);
129*/
130
131/* add and put pixel (decoding) */
132// blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
133//h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4
134typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
135typedef 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);
136typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
137typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y);
138typedef void (*h264_weight_func)(uint8_t *block, int stride, int log2_denom, int weight, int offset);
139typedef void (*h264_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset);
140
141#define DEF_OLD_QPEL(name)\
142void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
143void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
144void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
145
146DEF_OLD_QPEL(qpel16_mc11_old_c)
147DEF_OLD_QPEL(qpel16_mc31_old_c)
148DEF_OLD_QPEL(qpel16_mc12_old_c)
149DEF_OLD_QPEL(qpel16_mc32_old_c)
150DEF_OLD_QPEL(qpel16_mc13_old_c)
151DEF_OLD_QPEL(qpel16_mc33_old_c)
152DEF_OLD_QPEL(qpel8_mc11_old_c)
153DEF_OLD_QPEL(qpel8_mc31_old_c)
154DEF_OLD_QPEL(qpel8_mc12_old_c)
155DEF_OLD_QPEL(qpel8_mc32_old_c)
156DEF_OLD_QPEL(qpel8_mc13_old_c)
157DEF_OLD_QPEL(qpel8_mc33_old_c)
158
159#define CALL_2X_PIXELS(a, b, n)\
160static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
161 b(block , pixels , line_size, h);\
162 b(block+n, pixels+n, line_size, h);\
163}
164
165/* motion estimation */
166// h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2
167// although currently h<4 is not used as functions with width <8 are neither used nor implemented
168typedef 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))*/;
169
170
171// for snow slices
172typedef struct slice_buffer_s slice_buffer;
173
174/**
175 * Scantable.
176 */
177typedef struct ScanTable{
178 const uint8_t *scantable;
179 uint8_t permutated[64];
180 uint8_t raster_end[64];
181#if ARCH_PPC
182 /** Used by dct_quantize_altivec to find last-non-zero */
183 DECLARE_ALIGNED(16, uint8_t, inverse[64]);
184#endif
185} ScanTable;
186
187void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);
188
189void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize,
190 int block_w, int block_h,
191 int src_x, int src_y, int w, int h);
192
193/**
194 * DSPContext.
195 */
196typedef struct DSPContext {
197 /* pixel ops : interface with DCT */
198 void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
199 void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
200 void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
201 void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
202 void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
203 void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size);
204 void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size);
205 int (*sum_abs_dctelem)(DCTELEM *block/*align 16*/);
206 /**
207 * translational global motion compensation.
208 */
209 void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder);
210 /**
211 * global motion compensation.
212 */
213 void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy,
214 int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
215 void (*clear_block)(DCTELEM *block/*align 16*/);
216 void (*clear_blocks)(DCTELEM *blocks/*align 16*/);
217 int (*pix_sum)(uint8_t * pix, int line_size);
218 int (*pix_norm1)(uint8_t * pix, int line_size);
219// 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4
220
221 me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
222 me_cmp_func sse[6];
223 me_cmp_func hadamard8_diff[6];
224 me_cmp_func dct_sad[6];
225 me_cmp_func quant_psnr[6];
226 me_cmp_func bit[6];
227 me_cmp_func rd[6];
228 me_cmp_func vsad[6];
229 me_cmp_func vsse[6];
230 me_cmp_func nsse[6];
231 me_cmp_func w53[6];
232 me_cmp_func w97[6];
233 me_cmp_func dct_max[6];
234 me_cmp_func dct264_sad[6];
235
236 me_cmp_func me_pre_cmp[6];
237 me_cmp_func me_cmp[6];
238 me_cmp_func me_sub_cmp[6];
239 me_cmp_func mb_cmp[6];
240 me_cmp_func ildct_cmp[6]; //only width 16 used
241 me_cmp_func frame_skip_cmp[6]; //only width 8 used
242
243 int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2,
244 int size);
245
246 /**
247 * Halfpel motion compensation with rounding (a+b+1)>>1.
248 * this is an array[4][4] of motion compensation functions for 4
249 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
250 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
251 * @param block destination where the result is stored
252 * @param pixels source
253 * @param line_size number of bytes in a horizontal line of block
254 * @param h height
255 */
256 op_pixels_func put_pixels_tab[4][4];
257
258 /**
259 * Halfpel motion compensation with rounding (a+b+1)>>1.
260 * This is an array[4][4] of motion compensation functions for 4
261 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
262 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
263 * @param block destination into which the result is averaged (a+b+1)>>1
264 * @param pixels source
265 * @param line_size number of bytes in a horizontal line of block
266 * @param h height
267 */
268 op_pixels_func avg_pixels_tab[4][4];
269
270 /**
271 * Halfpel motion compensation with no rounding (a+b)>>1.
272 * this is an array[2][4] of motion compensation functions for 2
273 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
274 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
275 * @param block destination where the result is stored
276 * @param pixels source
277 * @param line_size number of bytes in a horizontal line of block
278 * @param h height
279 */
280 op_pixels_func put_no_rnd_pixels_tab[4][4];
281
282 /**
283 * Halfpel motion compensation with no rounding (a+b)>>1.
284 * this is an array[2][4] of motion compensation functions for 2
285 * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
286 * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
287 * @param block destination into which the result is averaged (a+b)>>1
288 * @param pixels source
289 * @param line_size number of bytes in a horizontal line of block
290 * @param h height
291 */
292 op_pixels_func avg_no_rnd_pixels_tab[4][4];
293
294 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);
295
296 /**
297 * Thirdpel motion compensation with rounding (a+b+1)>>1.
298 * this is an array[12] of motion compensation functions for the 9 thirdpe
299 * positions<br>
300 * *pixels_tab[ xthirdpel + 4*ythirdpel ]
301 * @param block destination where the result is stored
302 * @param pixels source
303 * @param line_size number of bytes in a horizontal line of block
304 * @param h height
305 */
306 tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
307 tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
308
309 qpel_mc_func put_qpel_pixels_tab[2][16];
310 qpel_mc_func avg_qpel_pixels_tab[2][16];
311 qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
312 qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
313 qpel_mc_func put_mspel_pixels_tab[8];
314
315 /**
316 * h264 Chroma MC
317 */
318 h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
319 /* This is really one func used in VC-1 decoding */
320 h264_chroma_mc_func put_no_rnd_h264_chroma_pixels_tab[3];
321 h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
322
323 qpel_mc_func put_h264_qpel_pixels_tab[4][16];
324 qpel_mc_func avg_h264_qpel_pixels_tab[4][16];
325
326 qpel_mc_func put_2tap_qpel_pixels_tab[4][16];
327 qpel_mc_func avg_2tap_qpel_pixels_tab[4][16];
328
329 h264_weight_func weight_h264_pixels_tab[10];
330 h264_biweight_func biweight_h264_pixels_tab[10];
331
332 /* AVS specific */
333 qpel_mc_func put_cavs_qpel_pixels_tab[2][16];
334 qpel_mc_func avg_cavs_qpel_pixels_tab[2][16];
335 void (*cavs_filter_lv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
336 void (*cavs_filter_lh)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
337 void (*cavs_filter_cv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
338 void (*cavs_filter_ch)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
339 void (*cavs_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
340
341 me_cmp_func pix_abs[2][4];
342
343 /* huffyuv specific */
344 void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
345 void (*add_bytes_l2)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 16*/, int w);
346 void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w);
347 /**
348 * subtract huffyuv's variant of median prediction
349 * note, this might read from src1[-1], src2[-1]
350 */
351 void (*sub_hfyu_median_prediction)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top);
352 void (*add_hfyu_median_prediction)(uint8_t *dst, uint8_t *top, uint8_t *diff, int w, int *left, int *left_top);
353 /* this might write to dst[w] */
354 void (*add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp);
355 void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
356
357 void (*h264_v_loop_filter_luma)(uint8_t *pix/*align 16*/, int stride, int alpha, int beta, int8_t *tc0);
358 void (*h264_h_loop_filter_luma)(uint8_t *pix/*align 4 */, int stride, int alpha, int beta, int8_t *tc0);
359 /* v/h_loop_filter_luma_intra: align 16 */
360 void (*h264_v_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta);
361 void (*h264_h_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta);
362 void (*h264_v_loop_filter_chroma)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta, int8_t *tc0);
363 void (*h264_h_loop_filter_chroma)(uint8_t *pix/*align 4*/, int stride, int alpha, int beta, int8_t *tc0);
364 void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta);
365 void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta);
366 // h264_loop_filter_strength: simd only. the C version is inlined in h264.c
367 void (*h264_loop_filter_strength)(int16_t bS[2][4][4], uint8_t nnz[40], int8_t ref[2][40], int16_t mv[2][40][2],
368 int bidir, int edges, int step, int mask_mv0, int mask_mv1, int field);
369
370 void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
371 void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
372
373 void (*h261_loop_filter)(uint8_t *src, int stride);
374
375 void (*x8_v_loop_filter)(uint8_t *src, int stride, int qscale);
376 void (*x8_h_loop_filter)(uint8_t *src, int stride, int qscale);
377
378 void (*vp3_v_loop_filter)(uint8_t *src, int stride, int *bounding_values);
379 void (*vp3_h_loop_filter)(uint8_t *src, int stride, int *bounding_values);
380
381 void (*vp6_filter_diag4)(uint8_t *dst, uint8_t *src, int stride,
382 const int16_t *h_weights,const int16_t *v_weights);
383
384 /* assume len is a multiple of 4, and arrays are 16-byte aligned */
385 void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize);
386 void (*ac3_downmix)(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len);
387 /* no alignment needed */
388 void (*flac_compute_autocorr)(const int32_t *data, int len, int lag, double *autoc);
389 /* assume len is a multiple of 8, and arrays are 16-byte aligned */
390 void (*vector_fmul)(float *dst, const float *src, int len);
391 void (*vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len);
392 /* assume len is a multiple of 8, and src arrays are 16-byte aligned */
393 void (*vector_fmul_add_add)(float *dst, const float *src0, const float *src1, const float *src2, int src3, int len, int step);
394 /* assume len is a multiple of 4, and arrays are 16-byte aligned */
395 void (*vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len);
396 /* assume len is a multiple of 8, and arrays are 16-byte aligned */
397 void (*int32_to_float_fmul_scalar)(float *dst, const int *src, float mul, int len);
398
399 /* C version: convert floats from the range [384.0,386.0] to ints in [-32768,32767]
400 * simd versions: convert floats from [-32768.0,32767.0] without rescaling and arrays are 16byte aligned */
401 void (*float_to_int16)(int16_t *dst, const float *src, long len);
402 void (*float_to_int16_interleave)(int16_t *dst, const float **src, long len, int channels);
403
404 /* (I)DCT */
405 void (*fdct)(DCTELEM *block/* align 16*/);
406 void (*fdct248)(DCTELEM *block/* align 16*/);
407
408 /* IDCT really*/
409 void (*idct)(DCTELEM *block/* align 16*/);
410
411 /**
412 * block -> idct -> clip to unsigned 8 bit -> dest.
413 * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
414 * @param line_size size in bytes of a horizontal line of dest
415 */
416 void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
417
418 /**
419 * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
420 * @param line_size size in bytes of a horizontal line of dest
421 */
422 void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
423
424 /**
425 * idct input permutation.
426 * several optimized IDCTs need a permutated input (relative to the normal order of the reference
427 * IDCT)
428 * this permutation must be performed before the idct_put/add, note, normally this can be merged
429 * with the zigzag/alternate scan<br>
430 * an example to avoid confusion:
431 * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...)
432 * - (x -> referece dct -> reference idct -> x)
433 * - (x -> referece dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x)
434 * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...)
435 */
436 uint8_t idct_permutation[64];
437 int idct_permutation_type;
438#define FF_NO_IDCT_PERM 1
439#define FF_LIBMPEG2_IDCT_PERM 2
440#define FF_SIMPLE_IDCT_PERM 3
441#define FF_TRANSPOSE_IDCT_PERM 4
442#define FF_PARTTRANS_IDCT_PERM 5
443#define FF_SSE2_IDCT_PERM 6
444
445 int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale);
446 void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
447#define BASIS_SHIFT 16
448#define RECON_SHIFT 6
449
450 void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w);
451#define EDGE_WIDTH 16
452
453 /* h264 functions */
454 /* NOTE!!! if you implement any of h264_idct8_add, h264_idct8_add4 then you must implement all of them
455 NOTE!!! if you implement any of h264_idct_add, h264_idct_add16, h264_idct_add16intra, h264_idct_add8 then you must implement all of them
456 The reason for above, is that no 2 out of one list may use a different permutation.
457 */
458 void (*h264_idct_add)(uint8_t *dst/*align 4*/, DCTELEM *block/*align 16*/, int stride);
459 void (*h264_idct8_add)(uint8_t *dst/*align 8*/, DCTELEM *block/*align 16*/, int stride);
460 void (*h264_idct_dc_add)(uint8_t *dst/*align 4*/, DCTELEM *block/*align 16*/, int stride);
461 void (*h264_idct8_dc_add)(uint8_t *dst/*align 8*/, DCTELEM *block/*align 16*/, int stride);
462 void (*h264_dct)(DCTELEM block[4][4]);
463 void (*h264_idct_add16)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]);
464 void (*h264_idct8_add4)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]);
465 void (*h264_idct_add8)(uint8_t **dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]);
466 void (*h264_idct_add16intra)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]);
467
468 /* snow wavelet */
469 void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width);
470 void (*horizontal_compose97i)(IDWTELEM *b, int width);
471 void (*inner_add_yblock)(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8);
472
473 void (*prefetch)(void *mem, int stride, int h);
474
475 void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
476
477 /* vc1 functions */
478 void (*vc1_inv_trans_8x8)(DCTELEM *b);
479 void (*vc1_inv_trans_8x4)(uint8_t *dest, int line_size, DCTELEM *block);
480 void (*vc1_inv_trans_4x8)(uint8_t *dest, int line_size, DCTELEM *block);
481 void (*vc1_inv_trans_4x4)(uint8_t *dest, int line_size, DCTELEM *block);
482 void (*vc1_v_overlap)(uint8_t* src, int stride);
483 void (*vc1_h_overlap)(uint8_t* src, int stride);
484 /* put 8x8 block with bicubic interpolation and quarterpel precision
485 * last argument is actually round value instead of height
486 */
487 op_pixels_func put_vc1_mspel_pixels_tab[16];
488
489 /* intrax8 functions */
490 void (*x8_spatial_compensation[12])(uint8_t *src , uint8_t *dst, int linesize);
491 void (*x8_setup_spatial_compensation)(uint8_t *src, uint8_t *dst, int linesize,
492 int * range, int * sum, int edges);
493
494 /* ape functions */
495 /**
496 * Add contents of the second vector to the first one.
497 * @param len length of vectors, should be multiple of 16
498 */
499 void (*add_int16)(int16_t *v1/*align 16*/, int16_t *v2, int len);
500 /**
501 * Add contents of the second vector to the first one.
502 * @param len length of vectors, should be multiple of 16
503 */
504 void (*sub_int16)(int16_t *v1/*align 16*/, int16_t *v2, int len);
505 /**
506 * Calculate scalar product of two vectors.
507 * @param len length of vectors, should be multiple of 16
508 * @param shift number of bits to discard from product
509 */
510 int32_t (*scalarproduct_int16)(int16_t *v1, int16_t *v2/*align 16*/, int len, int shift);
511
512 /* rv30 functions */
513 qpel_mc_func put_rv30_tpel_pixels_tab[4][16];
514 qpel_mc_func avg_rv30_tpel_pixels_tab[4][16];
515
516 /* rv40 functions */
517 qpel_mc_func put_rv40_qpel_pixels_tab[4][16];
518 qpel_mc_func avg_rv40_qpel_pixels_tab[4][16];
519 h264_chroma_mc_func put_rv40_chroma_pixels_tab[3];
520 h264_chroma_mc_func avg_rv40_chroma_pixels_tab[3];
521} DSPContext;
522
523void dsputil_static_init(void);
524void dsputil_init(DSPContext* p, AVCodecContext *avctx);
525
526int ff_check_alignment(void);
527
528/**
529 * permute block according to permuatation.
530 * @param last last non zero element in scantable order
531 */
532void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
533
534void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
535
536#define BYTE_VEC32(c) ((c)*0x01010101UL)
537
538static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
539{
540 return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
541}
542
543static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
544{
545 return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
546}
547
548static inline int get_penalty_factor(int lambda, int lambda2, int type){
549 switch(type&0xFF){
550 default:
551 case FF_CMP_SAD:
552 return lambda>>FF_LAMBDA_SHIFT;
553 case FF_CMP_DCT:
554 return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
555 case FF_CMP_W53:
556 return (4*lambda)>>(FF_LAMBDA_SHIFT);
557 case FF_CMP_W97:
558 return (2*lambda)>>(FF_LAMBDA_SHIFT);
559 case FF_CMP_SATD:
560 case FF_CMP_DCT264:
561 return (2*lambda)>>FF_LAMBDA_SHIFT;
562 case FF_CMP_RD:
563 case FF_CMP_PSNR:
564 case FF_CMP_SSE:
565 case FF_CMP_NSSE:
566 return lambda2>>FF_LAMBDA_SHIFT;
567 case FF_CMP_BIT:
568 return 1;
569 }
570}
571
572/**
573 * Empty mmx state.
574 * this must be called between any dsp function and float/double code.
575 * for example sin(); dsp->idct_put(); emms_c(); cos()
576 */
577#define emms_c()
578
579/* should be defined by architectures supporting
580 one or more MultiMedia extension */
581int mm_support(void);
582
583void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
584void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx);
585void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx);
586void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx);
587void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx);
588void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
589void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
590void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
591void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
592
593#define DECLARE_ALIGNED_16(t, v) DECLARE_ALIGNED(16, t, v)
594
595#if HAVE_MMX
596
597#undef emms_c
598
599extern int mm_flags;
600
601void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
602void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
603void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
604
605static inline void emms(void)
606{
607 __asm__ volatile ("emms;":::"memory");
608}
609
610
611#define emms_c() \
612{\
613 if (mm_flags & FF_MM_MMX)\
614 emms();\
615}
616
617void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx);
618
619#elif ARCH_ARM
620
621extern int mm_flags;
622
623#if HAVE_NEON
624# define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
625# define STRIDE_ALIGN 16
626#endif
627
628#elif ARCH_PPC
629
630extern int mm_flags;
631
632#define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
633#define STRIDE_ALIGN 16
634
635#elif HAVE_MMI
636
637#define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
638#define STRIDE_ALIGN 16
639
640#else
641
642#define mm_flags 0
643#define mm_support() 0
644
645#endif
646
647#ifndef DECLARE_ALIGNED_8
648# define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(8, t, v)
649#endif
650
651#ifndef STRIDE_ALIGN
652# define STRIDE_ALIGN 8
653#endif
654
655/* PSNR */
656void get_psnr(uint8_t *orig_image[3], uint8_t *coded_image[3],
657 int orig_linesize[3], int coded_linesize,
658 AVCodecContext *avctx);
659
660/* FFT computation */
661
662/* NOTE: soon integer code will be added, so you must use the
663 FFTSample type */
664typedef float FFTSample;
665
666struct MDCTContext;
667
668typedef struct FFTComplex {
669 FFTSample re, im;
670} FFTComplex;
671
672typedef struct FFTContext {
673 int nbits;
674 int inverse;
675 uint16_t *revtab;
676 FFTComplex *exptab;
677 FFTComplex *exptab1; /* only used by SSE code */
678 FFTComplex *tmp_buf;
679 void (*fft_permute)(struct FFTContext *s, FFTComplex *z);
680 void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
681 void (*imdct_calc)(struct MDCTContext *s, FFTSample *output, const FFTSample *input);
682 void (*imdct_half)(struct MDCTContext *s, FFTSample *output, const FFTSample *input);
683} FFTContext;
684
685extern FFTSample* ff_cos_tabs[13];
686
687/**
688 * Sets up a complex FFT.
689 * @param nbits log2 of the length of the input array
690 * @param inverse if 0 perform the forward transform, if 1 perform the inverse
691 */
692int ff_fft_init(FFTContext *s, int nbits, int inverse);
693void ff_fft_permute_c(FFTContext *s, FFTComplex *z);
694void ff_fft_permute_sse(FFTContext *s, FFTComplex *z);
695void ff_fft_calc_c(FFTContext *s, FFTComplex *z);
696void ff_fft_calc_sse(FFTContext *s, FFTComplex *z);
697void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z);
698void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z);
699void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z);
700
701/**
702 * Do the permutation needed BEFORE calling ff_fft_calc().
703 */
704static inline void ff_fft_permute(FFTContext *s, FFTComplex *z)
705{
706 s->fft_permute(s, z);
707}
708/**
709 * Do a complex FFT with the parameters defined in ff_fft_init(). The
710 * input data must be permuted before. No 1.0/sqrt(n) normalization is done.
711 */
712static inline void ff_fft_calc(FFTContext *s, FFTComplex *z)
713{
714 s->fft_calc(s, z);
715}
716void ff_fft_end(FFTContext *s);
717
718/* MDCT computation */
719
720typedef struct MDCTContext {
721 int n; /* size of MDCT (i.e. number of input data * 2) */
722 int nbits; /* n = 2^nbits */
723 /* pre/post rotation tables */
724 FFTSample *tcos;
725 FFTSample *tsin;
726 FFTContext fft;
727} MDCTContext;
728
729static inline void ff_imdct_calc(MDCTContext *s, FFTSample *output, const FFTSample *input)
730{
731 s->fft.imdct_calc(s, output, input);
732}
733static inline void ff_imdct_half(MDCTContext *s, FFTSample *output, const FFTSample *input)
734{
735 s->fft.imdct_half(s, output, input);
736}
737
738/**
739 * Generate a Kaiser-Bessel Derived Window.
740 * @param window pointer to half window
741 * @param alpha determines window shape
742 * @param n size of half window
743 */
744void ff_kbd_window_init(float *window, float alpha, int n);
745
746/**
747 * Generate a sine window.
748 * @param window pointer to half window
749 * @param n size of half window
750 */
751void ff_sine_window_init(float *window, int n);
752extern float ff_sine_128 [ 128];
753extern float ff_sine_256 [ 256];
754extern float ff_sine_512 [ 512];
755extern float ff_sine_1024[1024];
756extern float ff_sine_2048[2048];
757extern float ff_sine_4096[4096];
758extern float *ff_sine_windows[6];
759
760int ff_mdct_init(MDCTContext *s, int nbits, int inverse);
761void ff_imdct_calc_c(MDCTContext *s, FFTSample *output, const FFTSample *input);
762void ff_imdct_half_c(MDCTContext *s, FFTSample *output, const FFTSample *input);
763void ff_imdct_calc_3dn(MDCTContext *s, FFTSample *output, const FFTSample *input);
764void ff_imdct_half_3dn(MDCTContext *s, FFTSample *output, const FFTSample *input);
765void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output, const FFTSample *input);
766void ff_imdct_half_3dn2(MDCTContext *s, FFTSample *output, const FFTSample *input);
767void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output, const FFTSample *input);
768void ff_imdct_half_sse(MDCTContext *s, FFTSample *output, const FFTSample *input);
769void ff_mdct_calc(MDCTContext *s, FFTSample *out, const FFTSample *input);
770void ff_mdct_end(MDCTContext *s);
771
772/* Real Discrete Fourier Transform */
773
774enum RDFTransformType {
775 RDFT,
776 IRDFT,
777 RIDFT,
778 IRIDFT,
779};
780
781typedef struct {
782 int nbits;
783 int inverse;
784 int sign_convention;
785
786 /* pre/post rotation tables */
787 FFTSample *tcos;
788 FFTSample *tsin;
789 FFTContext fft;
790} RDFTContext;
791
792/**
793 * Sets up a real FFT.
794 * @param nbits log2 of the length of the input array
795 * @param trans the type of transform
796 */
797int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans);
798void ff_rdft_calc(RDFTContext *s, FFTSample *data);
799void ff_rdft_end(RDFTContext *s);
800
801#define WRAPPER8_16(name8, name16)\
802static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
803 return name8(s, dst , src , stride, h)\
804 +name8(s, dst+8 , src+8 , stride, h);\
805}
806
807#define WRAPPER8_16_SQ(name8, name16)\
808static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
809 int score=0;\
810 score +=name8(s, dst , src , stride, 8);\
811 score +=name8(s, dst+8 , src+8 , stride, 8);\
812 if(h==16){\
813 dst += 8*stride;\
814 src += 8*stride;\
815 score +=name8(s, dst , src , stride, 8);\
816 score +=name8(s, dst+8 , src+8 , stride, 8);\
817 }\
818 return score;\
819}
820
821
822static inline void copy_block2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
823{
824 int i;
825 for(i=0; i<h; i++)
826 {
827 AV_WN16(dst , AV_RN16(src ));
828 dst+=dstStride;
829 src+=srcStride;
830 }
831}
832
833static inline void copy_block4(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
834{
835 int i;
836 for(i=0; i<h; i++)
837 {
838 AV_WN32(dst , AV_RN32(src ));
839 dst+=dstStride;
840 src+=srcStride;
841 }
842}
843
844static inline void copy_block8(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
845{
846 int i;
847 for(i=0; i<h; i++)
848 {
849 AV_WN32(dst , AV_RN32(src ));
850 AV_WN32(dst+4 , AV_RN32(src+4 ));
851 dst+=dstStride;
852 src+=srcStride;
853 }
854}
855
856static inline void copy_block9(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
857{
858 int i;
859 for(i=0; i<h; i++)
860 {
861 AV_WN32(dst , AV_RN32(src ));
862 AV_WN32(dst+4 , AV_RN32(src+4 ));
863 dst[8]= src[8];
864 dst+=dstStride;
865 src+=srcStride;
866 }
867}
868
869static inline void copy_block16(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
870{
871 int i;
872 for(i=0; i<h; i++)
873 {
874 AV_WN32(dst , AV_RN32(src ));
875 AV_WN32(dst+4 , AV_RN32(src+4 ));
876 AV_WN32(dst+8 , AV_RN32(src+8 ));
877 AV_WN32(dst+12, AV_RN32(src+12));
878 dst+=dstStride;
879 src+=srcStride;
880 }
881}
882
883static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
884{
885 int i;
886 for(i=0; i<h; i++)
887 {
888 AV_WN32(dst , AV_RN32(src ));
889 AV_WN32(dst+4 , AV_RN32(src+4 ));
890 AV_WN32(dst+8 , AV_RN32(src+8 ));
891 AV_WN32(dst+12, AV_RN32(src+12));
892 dst[16]= src[16];
893 dst+=dstStride;
894 src+=srcStride;
895 }
896}
897
898#endif /* AVCODEC_DSPUTIL_H */
diff --git a/apps/codecs/libcook/fft.c b/apps/codecs/libcook/fft.c
new file mode 100644
index 0000000000..a3f1151472
--- /dev/null
+++ b/apps/codecs/libcook/fft.c
@@ -0,0 +1,374 @@
1/*
2 * FFT/IFFT transforms
3 * Copyright (c) 2008 Loren Merritt
4 * Copyright (c) 2002 Fabrice Bellard
5 * Partly based on libdjbfft by D. J. Bernstein
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24/**
25 * @file libavcodec/fft.c
26 * FFT/IFFT transforms.
27 */
28
29#include "dsputil.h"
30
31/* cos(2*pi*x/n) for 0<=x<=n/4, followed by its reverse */
32DECLARE_ALIGNED_16(FFTSample, ff_cos_16[8]);
33DECLARE_ALIGNED_16(FFTSample, ff_cos_32[16]);
34DECLARE_ALIGNED_16(FFTSample, ff_cos_64[32]);
35DECLARE_ALIGNED_16(FFTSample, ff_cos_128[64]);
36DECLARE_ALIGNED_16(FFTSample, ff_cos_256[128]);
37DECLARE_ALIGNED_16(FFTSample, ff_cos_512[256]);
38DECLARE_ALIGNED_16(FFTSample, ff_cos_1024[512]);
39DECLARE_ALIGNED_16(FFTSample, ff_cos_2048[1024]);
40DECLARE_ALIGNED_16(FFTSample, ff_cos_4096[2048]);
41DECLARE_ALIGNED_16(FFTSample, ff_cos_8192[4096]);
42DECLARE_ALIGNED_16(FFTSample, ff_cos_16384[8192]);
43DECLARE_ALIGNED_16(FFTSample, ff_cos_32768[16384]);
44DECLARE_ALIGNED_16(FFTSample, ff_cos_65536[32768]);
45FFTSample *ff_cos_tabs[] = {
46 ff_cos_16, ff_cos_32, ff_cos_64, ff_cos_128, ff_cos_256, ff_cos_512, ff_cos_1024,
47 ff_cos_2048, ff_cos_4096, ff_cos_8192, ff_cos_16384, ff_cos_32768, ff_cos_65536,
48};
49
50static int split_radix_permutation(int i, int n, int inverse)
51{
52 int m;
53 if(n <= 2) return i&1;
54 m = n >> 1;
55 if(!(i&m)) return split_radix_permutation(i, m, inverse)*2;
56 m >>= 1;
57 if(inverse == !(i&m)) return split_radix_permutation(i, m, inverse)*4 + 1;
58 else return split_radix_permutation(i, m, inverse)*4 - 1;
59}
60
61av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse)
62{
63 int i, j, m, n;
64 float alpha, c1, s1, s2;
65 int split_radix = 1;
66 int av_unused has_vectors;
67
68 if (nbits < 2 || nbits > 16)
69 goto fail;
70 s->nbits = nbits;
71 n = 1 << nbits;
72
73 s->tmp_buf = NULL;
74 s->exptab = av_malloc((n / 2) * sizeof(FFTComplex));
75 if (!s->exptab)
76 goto fail;
77 s->revtab = av_malloc(n * sizeof(uint16_t));
78 if (!s->revtab)
79 goto fail;
80 s->inverse = inverse;
81
82 s2 = inverse ? 1.0 : -1.0;
83
84 s->fft_permute = ff_fft_permute_c;
85 s->fft_calc = ff_fft_calc_c;
86 s->imdct_calc = ff_imdct_calc_c;
87 s->imdct_half = ff_imdct_half_c;
88 s->exptab1 = NULL;
89
90#if HAVE_MMX && HAVE_YASM
91 has_vectors = mm_support();
92 if (has_vectors & FF_MM_SSE && HAVE_SSE) {
93 /* SSE for P3/P4/K8 */
94 s->imdct_calc = ff_imdct_calc_sse;
95 s->imdct_half = ff_imdct_half_sse;
96 s->fft_permute = ff_fft_permute_sse;
97 s->fft_calc = ff_fft_calc_sse;
98 } else if (has_vectors & FF_MM_3DNOWEXT && HAVE_AMD3DNOWEXT) {
99 /* 3DNowEx for K7 */
100 s->imdct_calc = ff_imdct_calc_3dn2;
101 s->imdct_half = ff_imdct_half_3dn2;
102 s->fft_calc = ff_fft_calc_3dn2;
103 } else if (has_vectors & FF_MM_3DNOW && HAVE_AMD3DNOW) {
104 /* 3DNow! for K6-2/3 */
105 s->imdct_calc = ff_imdct_calc_3dn;
106 s->imdct_half = ff_imdct_half_3dn;
107 s->fft_calc = ff_fft_calc_3dn;
108 }
109#elif HAVE_ALTIVEC
110 has_vectors = mm_support();
111 if (has_vectors & FF_MM_ALTIVEC) {
112 s->fft_calc = ff_fft_calc_altivec;
113 split_radix = 0;
114 }
115#endif
116
117 if (split_radix) {
118 for(j=4; j<=nbits; j++) {
119 int m = 1<<j;
120 double freq = 2*M_PI/m;
121 FFTSample *tab = ff_cos_tabs[j-4];
122 for(i=0; i<=m/4; i++)
123 tab[i] = cos(i*freq);
124 for(i=1; i<m/4; i++)
125 tab[m/2-i] = tab[i];
126 }
127 for(i=0; i<n; i++)
128 s->revtab[-split_radix_permutation(i, n, s->inverse) & (n-1)] = i;
129 s->tmp_buf = av_malloc(n * sizeof(FFTComplex));
130 } else {
131 int np, nblocks, np2, l;
132 FFTComplex *q;
133
134 for(i=0; i<(n/2); i++) {
135 alpha = 2 * M_PI * (float)i / (float)n;
136 c1 = cos(alpha);
137 s1 = sin(alpha) * s2;
138 s->exptab[i].re = c1;
139 s->exptab[i].im = s1;
140 }
141
142 np = 1 << nbits;
143 nblocks = np >> 3;
144 np2 = np >> 1;
145 s->exptab1 = av_malloc(np * 2 * sizeof(FFTComplex));
146 if (!s->exptab1)
147 goto fail;
148 q = s->exptab1;
149 do {
150 for(l = 0; l < np2; l += 2 * nblocks) {
151 *q++ = s->exptab[l];
152 *q++ = s->exptab[l + nblocks];
153
154 q->re = -s->exptab[l].im;
155 q->im = s->exptab[l].re;
156 q++;
157 q->re = -s->exptab[l + nblocks].im;
158 q->im = s->exptab[l + nblocks].re;
159 q++;
160 }
161 nblocks = nblocks >> 1;
162 } while (nblocks != 0);
163 av_freep(&s->exptab);
164
165 /* compute bit reverse table */
166 for(i=0;i<n;i++) {
167 m=0;
168 for(j=0;j<nbits;j++) {
169 m |= ((i >> j) & 1) << (nbits-j-1);
170 }
171 s->revtab[i]=m;
172 }
173 }
174
175 return 0;
176 fail:
177 av_freep(&s->revtab);
178 av_freep(&s->exptab);
179 av_freep(&s->exptab1);
180 av_freep(&s->tmp_buf);
181 return -1;
182}
183
184void ff_fft_permute_c(FFTContext *s, FFTComplex *z)
185{
186 int j, k, np;
187 FFTComplex tmp;
188 const uint16_t *revtab = s->revtab;
189 np = 1 << s->nbits;
190
191 if (s->tmp_buf) {
192 /* TODO: handle split-radix permute in a more optimal way, probably in-place */
193 for(j=0;j<np;j++) s->tmp_buf[revtab[j]] = z[j];
194 memcpy(z, s->tmp_buf, np * sizeof(FFTComplex));
195 return;
196 }
197
198 /* reverse */
199 for(j=0;j<np;j++) {
200 k = revtab[j];
201 if (k < j) {
202 tmp = z[k];
203 z[k] = z[j];
204 z[j] = tmp;
205 }
206 }
207}
208
209av_cold void ff_fft_end(FFTContext *s)
210{
211 av_freep(&s->revtab);
212 av_freep(&s->exptab);
213 av_freep(&s->exptab1);
214 av_freep(&s->tmp_buf);
215}
216
217#define sqrthalf (float)M_SQRT1_2
218
219#define BF(x,y,a,b) {\
220 x = a - b;\
221 y = a + b;\
222}
223
224#define BUTTERFLIES(a0,a1,a2,a3) {\
225 BF(t3, t5, t5, t1);\
226 BF(a2.re, a0.re, a0.re, t5);\
227 BF(a3.im, a1.im, a1.im, t3);\
228 BF(t4, t6, t2, t6);\
229 BF(a3.re, a1.re, a1.re, t4);\
230 BF(a2.im, a0.im, a0.im, t6);\
231}
232
233// force loading all the inputs before storing any.
234// this is slightly slower for small data, but avoids store->load aliasing
235// for addresses separated by large powers of 2.
236#define BUTTERFLIES_BIG(a0,a1,a2,a3) {\
237 FFTSample r0=a0.re, i0=a0.im, r1=a1.re, i1=a1.im;\
238 BF(t3, t5, t5, t1);\
239 BF(a2.re, a0.re, r0, t5);\
240 BF(a3.im, a1.im, i1, t3);\
241 BF(t4, t6, t2, t6);\
242 BF(a3.re, a1.re, r1, t4);\
243 BF(a2.im, a0.im, i0, t6);\
244}
245
246#define TRANSFORM(a0,a1,a2,a3,wre,wim) {\
247 t1 = a2.re * wre + a2.im * wim;\
248 t2 = a2.im * wre - a2.re * wim;\
249 t5 = a3.re * wre - a3.im * wim;\
250 t6 = a3.im * wre + a3.re * wim;\
251 BUTTERFLIES(a0,a1,a2,a3)\
252}
253
254#define TRANSFORM_ZERO(a0,a1,a2,a3) {\
255 t1 = a2.re;\
256 t2 = a2.im;\
257 t5 = a3.re;\
258 t6 = a3.im;\
259 BUTTERFLIES(a0,a1,a2,a3)\
260}
261
262/* z[0...8n-1], w[1...2n-1] */
263#define PASS(name)\
264static void name(FFTComplex *z, const FFTSample *wre, unsigned int n)\
265{\
266 FFTSample t1, t2, t3, t4, t5, t6;\
267 int o1 = 2*n;\
268 int o2 = 4*n;\
269 int o3 = 6*n;\
270 const FFTSample *wim = wre+o1;\
271 n--;\
272\
273 TRANSFORM_ZERO(z[0],z[o1],z[o2],z[o3]);\
274 TRANSFORM(z[1],z[o1+1],z[o2+1],z[o3+1],wre[1],wim[-1]);\
275 do {\
276 z += 2;\
277 wre += 2;\
278 wim -= 2;\
279 TRANSFORM(z[0],z[o1],z[o2],z[o3],wre[0],wim[0]);\
280 TRANSFORM(z[1],z[o1+1],z[o2+1],z[o3+1],wre[1],wim[-1]);\
281 } while(--n);\
282}
283
284PASS(pass)
285#undef BUTTERFLIES
286#define BUTTERFLIES BUTTERFLIES_BIG
287PASS(pass_big)
288
289#define DECL_FFT(n,n2,n4)\
290static void fft##n(FFTComplex *z)\
291{\
292 fft##n2(z);\
293 fft##n4(z+n4*2);\
294 fft##n4(z+n4*3);\
295 pass(z,ff_cos_##n,n4/2);\
296}
297
298static void fft4(FFTComplex *z)
299{
300 FFTSample t1, t2, t3, t4, t5, t6, t7, t8;
301
302 BF(t3, t1, z[0].re, z[1].re);
303 BF(t8, t6, z[3].re, z[2].re);
304 BF(z[2].re, z[0].re, t1, t6);
305 BF(t4, t2, z[0].im, z[1].im);
306 BF(t7, t5, z[2].im, z[3].im);
307 BF(z[3].im, z[1].im, t4, t8);
308 BF(z[3].re, z[1].re, t3, t7);
309 BF(z[2].im, z[0].im, t2, t5);
310}
311
312static void fft8(FFTComplex *z)
313{
314 FFTSample t1, t2, t3, t4, t5, t6, t7, t8;
315
316 fft4(z);
317
318 BF(t1, z[5].re, z[4].re, -z[5].re);
319 BF(t2, z[5].im, z[4].im, -z[5].im);
320 BF(t3, z[7].re, z[6].re, -z[7].re);
321 BF(t4, z[7].im, z[6].im, -z[7].im);
322 BF(t8, t1, t3, t1);
323 BF(t7, t2, t2, t4);
324 BF(z[4].re, z[0].re, z[0].re, t1);
325 BF(z[4].im, z[0].im, z[0].im, t2);
326 BF(z[6].re, z[2].re, z[2].re, t7);
327 BF(z[6].im, z[2].im, z[2].im, t8);
328
329 TRANSFORM(z[1],z[3],z[5],z[7],sqrthalf,sqrthalf);
330}
331
332#if !CONFIG_SMALL
333static void fft16(FFTComplex *z)
334{
335 FFTSample t1, t2, t3, t4, t5, t6;
336
337 fft8(z);
338 fft4(z+8);
339 fft4(z+12);
340
341 TRANSFORM_ZERO(z[0],z[4],z[8],z[12]);
342 TRANSFORM(z[2],z[6],z[10],z[14],sqrthalf,sqrthalf);
343 TRANSFORM(z[1],z[5],z[9],z[13],ff_cos_16[1],ff_cos_16[3]);
344 TRANSFORM(z[3],z[7],z[11],z[15],ff_cos_16[3],ff_cos_16[1]);
345}
346#else
347DECL_FFT(16,8,4)
348#endif
349DECL_FFT(32,16,8)
350DECL_FFT(64,32,16)
351DECL_FFT(128,64,32)
352DECL_FFT(256,128,64)
353DECL_FFT(512,256,128)
354#if !CONFIG_SMALL
355#define pass pass_big
356#endif
357DECL_FFT(1024,512,256)
358DECL_FFT(2048,1024,512)
359DECL_FFT(4096,2048,1024)
360DECL_FFT(8192,4096,2048)
361DECL_FFT(16384,8192,4096)
362DECL_FFT(32768,16384,8192)
363DECL_FFT(65536,32768,16384)
364
365static void (*fft_dispatch[])(FFTComplex*) = {
366 fft4, fft8, fft16, fft32, fft64, fft128, fft256, fft512, fft1024,
367 fft2048, fft4096, fft8192, fft16384, fft32768, fft65536,
368};
369
370void ff_fft_calc_c(FFTContext *s, FFTComplex *z)
371{
372 fft_dispatch[s->nbits-2](z);
373}
374
diff --git a/apps/codecs/libcook/libavutil/avutil.h b/apps/codecs/libcook/libavutil/avutil.h
new file mode 100644
index 0000000000..c57e69f10c
--- /dev/null
+++ b/apps/codecs/libcook/libavutil/avutil.h
@@ -0,0 +1,63 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef AVUTIL_AVUTIL_H
22#define AVUTIL_AVUTIL_H
23
24/**
25 * @file libavutil/avutil.h
26 * external API header
27 */
28
29
30#define AV_STRINGIFY(s) AV_TOSTRING(s)
31#define AV_TOSTRING(s) #s
32
33#define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c)
34#define AV_VERSION_DOT(a, b, c) a ##.## b ##.## c
35#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
36
37#define LIBAVUTIL_VERSION_MAJOR 50
38#define LIBAVUTIL_VERSION_MINOR 0
39#define LIBAVUTIL_VERSION_MICRO 0
40
41#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
42 LIBAVUTIL_VERSION_MINOR, \
43 LIBAVUTIL_VERSION_MICRO)
44#define LIBAVUTIL_VERSION AV_VERSION(LIBAVUTIL_VERSION_MAJOR, \
45 LIBAVUTIL_VERSION_MINOR, \
46 LIBAVUTIL_VERSION_MICRO)
47#define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT
48
49#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION)
50
51/**
52 * Returns the LIBAVUTIL_VERSION_INT constant.
53 */
54unsigned avutil_version(void);
55
56#include "common.h"
57#include "mathematics.h"
58#include "rational.h"
59#include "intfloat_readwrite.h"
60#include "log.h"
61#include "pixfmt.h"
62
63#endif /* AVUTIL_AVUTIL_H */
diff --git a/apps/codecs/libcook/libavutil/bswap.h b/apps/codecs/libcook/libavutil/bswap.h
new file mode 100644
index 0000000000..cf68c43c72
--- /dev/null
+++ b/apps/codecs/libcook/libavutil/bswap.h
@@ -0,0 +1,99 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file libavutil/bswap.h
23 * byte swapping routines
24 */
25
26#ifndef AVUTIL_BSWAP_H
27#define AVUTIL_BSWAP_H
28
29#include <stdint.h>
30#include "config.h"
31#include "common.h"
32
33#if ARCH_ARM
34# include "arm/bswap.h"
35#elif ARCH_BFIN
36# include "bfin/bswap.h"
37#elif ARCH_SH4
38# include "sh4/bswap.h"
39#elif ARCH_X86
40# include "x86/bswap.h"
41#endif
42
43#ifndef bswap_16
44static av_always_inline av_const uint16_t bswap_16(uint16_t x)
45{
46 x= (x>>8) | (x<<8);
47 return x;
48}
49#endif
50
51#ifndef bswap_32
52static av_always_inline av_const uint32_t bswap_32(uint32_t x)
53{
54 x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
55 x= (x>>16) | (x<<16);
56 return x;
57}
58#endif
59
60#ifndef bswap_64
61static inline uint64_t av_const bswap_64(uint64_t x)
62{
63#if 0
64 x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
65 x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
66 return (x>>32) | (x<<32);
67#else
68 union {
69 uint64_t ll;
70 uint32_t l[2];
71 } w, r;
72 w.ll = x;
73 r.l[0] = bswap_32 (w.l[1]);
74 r.l[1] = bswap_32 (w.l[0]);
75 return r.ll;
76#endif
77}
78#endif
79
80// be2me ... big-endian to machine-endian
81// le2me ... little-endian to machine-endian
82
83#ifdef WORDS_BIGENDIAN
84#define be2me_16(x) (x)
85#define be2me_32(x) (x)
86#define be2me_64(x) (x)
87#define le2me_16(x) bswap_16(x)
88#define le2me_32(x) bswap_32(x)
89#define le2me_64(x) bswap_64(x)
90#else
91#define be2me_16(x) bswap_16(x)
92#define be2me_32(x) bswap_32(x)
93#define be2me_64(x) bswap_64(x)
94#define le2me_16(x) (x)
95#define le2me_32(x) (x)
96#define le2me_64(x) (x)
97#endif
98
99#endif /* AVUTIL_BSWAP_H */
diff --git a/apps/codecs/libcook/libavutil/common.h b/apps/codecs/libcook/libavutil/common.h
new file mode 100644
index 0000000000..15eaf9849d
--- /dev/null
+++ b/apps/codecs/libcook/libavutil/common.h
@@ -0,0 +1,286 @@
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
38#ifdef __GNUC__
39# define AV_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNUC_MINOR__ >= y)
40#else
41# define AV_GCC_VERSION_AT_LEAST(x,y) 0
42#endif
43
44#ifndef av_always_inline
45#if AV_GCC_VERSION_AT_LEAST(3,1)
46# define av_always_inline __attribute__((always_inline)) inline
47#else
48# define av_always_inline inline
49#endif
50#endif
51
52#ifndef av_noinline
53#if AV_GCC_VERSION_AT_LEAST(3,1)
54# define av_noinline __attribute__((noinline))
55#else
56# define av_noinline
57#endif
58#endif
59
60#ifndef av_pure
61#if AV_GCC_VERSION_AT_LEAST(3,1)
62# define av_pure __attribute__((pure))
63#else
64# define av_pure
65#endif
66#endif
67
68#ifndef av_const
69#if AV_GCC_VERSION_AT_LEAST(2,6)
70# define av_const __attribute__((const))
71#else
72# define av_const
73#endif
74#endif
75
76#ifndef av_cold
77#if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,3)
78# define av_cold __attribute__((cold))
79#else
80# define av_cold
81#endif
82#endif
83
84#ifndef av_flatten
85#if AV_GCC_VERSION_AT_LEAST(4,1)
86# define av_flatten __attribute__((flatten))
87#else
88# define av_flatten
89#endif
90#endif
91
92#ifndef attribute_deprecated
93#if AV_GCC_VERSION_AT_LEAST(3,1)
94# define attribute_deprecated __attribute__((deprecated))
95#else
96# define attribute_deprecated
97#endif
98#endif
99
100#ifndef av_unused
101#if defined(__GNUC__)
102# define av_unused __attribute__((unused))
103#else
104# define av_unused
105#endif
106#endif
107
108#ifndef av_uninit
109#if defined(__GNUC__) && !defined(__ICC)
110# define av_uninit(x) x=x
111#else
112# define av_uninit(x) x
113#endif
114#endif
115
116//rounded division & shift
117#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
118/* assume b>0 */
119#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
120#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
121#define FFSIGN(a) ((a) > 0 ? 1 : -1)
122
123#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
124#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
125#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
126#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
127
128#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
129#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
130
131/* misc math functions */
132extern const uint8_t ff_log2_tab[256];
133
134static inline av_const int av_log2(unsigned int v)
135{
136 int n = 0;
137 if (v & 0xffff0000) {
138 v >>= 16;
139 n += 16;
140 }
141 if (v & 0xff00) {
142 v >>= 8;
143 n += 8;
144 }
145 n += ff_log2_tab[v];
146
147 return n;
148}
149
150static inline av_const int av_log2_16bit(unsigned int v)
151{
152 int n = 0;
153 if (v & 0xff00) {
154 v >>= 8;
155 n += 8;
156 }
157 n += ff_log2_tab[v];
158
159 return n;
160}
161
162/**
163 * Clips a signed integer value into the amin-amax range.
164 * @param a value to clip
165 * @param amin minimum value of the clip range
166 * @param amax maximum value of the clip range
167 * @return clipped value
168 */
169static inline av_const int av_clip(int a, int amin, int amax)
170{
171 if (a < amin) return amin;
172 else if (a > amax) return amax;
173 else return a;
174}
175
176/**
177 * Clips a signed integer value into the 0-255 range.
178 * @param a value to clip
179 * @return clipped value
180 */
181static inline av_const uint8_t av_clip_uint8(int a)
182{
183 if (a&(~255)) return (-a)>>31;
184 else return a;
185}
186
187/**
188 * Clips a signed integer value into the -32768,32767 range.
189 * @param a value to clip
190 * @return clipped value
191 */
192static inline av_const int16_t av_clip_int16(int a)
193{
194 if ((a+32768) & ~65535) return (a>>31) ^ 32767;
195 else return a;
196}
197
198/**
199 * Clips a float value into the amin-amax range.
200 * @param a value to clip
201 * @param amin minimum value of the clip range
202 * @param amax maximum value of the clip range
203 * @return clipped value
204 */
205static inline av_const float av_clipf(float a, float amin, float amax)
206{
207 if (a < amin) return amin;
208 else if (a > amax) return amax;
209 else return a;
210}
211
212#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
213#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
214
215/*!
216 * \def GET_UTF8(val, GET_BYTE, ERROR)
217 * Converts a UTF-8 character (up to 4 bytes long) to its 32-bit UCS-4 encoded form
218 * \param val is the output and should be of type uint32_t. It holds the converted
219 * UCS-4 character and should be a left value.
220 * \param GET_BYTE gets UTF-8 encoded bytes from any proper source. It can be
221 * a function or a statement whose return value or evaluated value is of type
222 * uint8_t. It will be executed up to 4 times for values in the valid UTF-8 range,
223 * and up to 7 times in the general case.
224 * \param ERROR action that should be taken when an invalid UTF-8 byte is returned
225 * from GET_BYTE. It should be a statement that jumps out of the macro,
226 * like exit(), goto, return, break, or continue.
227 */
228#define GET_UTF8(val, GET_BYTE, ERROR)\
229 val= GET_BYTE;\
230 {\
231 int ones= 7 - av_log2(val ^ 255);\
232 if(ones==1)\
233 ERROR\
234 val&= 127>>ones;\
235 while(--ones > 0){\
236 int tmp= GET_BYTE - 128;\
237 if(tmp>>6)\
238 ERROR\
239 val= (val<<6) + tmp;\
240 }\
241 }
242
243/*!
244 * \def PUT_UTF8(val, tmp, PUT_BYTE)
245 * Converts a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long).
246 * \param val is an input-only argument and should be of type uint32_t. It holds
247 * a UCS-4 encoded Unicode character that is to be converted to UTF-8. If
248 * val is given as a function it is executed only once.
249 * \param tmp is a temporary variable and should be of type uint8_t. It
250 * represents an intermediate value during conversion that is to be
251 * output by PUT_BYTE.
252 * \param PUT_BYTE writes the converted UTF-8 bytes to any proper destination.
253 * It could be a function or a statement, and uses tmp as the input byte.
254 * For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be
255 * executed up to 4 times for values in the valid UTF-8 range and up to
256 * 7 times in the general case, depending on the length of the converted
257 * Unicode character.
258 */
259#define PUT_UTF8(val, tmp, PUT_BYTE)\
260 {\
261 int bytes, shift;\
262 uint32_t in = val;\
263 if (in < 0x80) {\
264 tmp = in;\
265 PUT_BYTE\
266 } else {\
267 bytes = (av_log2(in) + 4) / 5;\
268 shift = (bytes - 1) * 6;\
269 tmp = (256 - (256 >> bytes)) | (in >> shift);\
270 PUT_BYTE\
271 while (shift >= 6) {\
272 shift -= 6;\
273 tmp = 0x80 | ((in >> shift) & 0x3f);\
274 PUT_BYTE\
275 }\
276 }\
277 }
278
279#include "mem.h"
280
281#ifdef HAVE_AV_CONFIG_H
282# include "config.h"
283# include "internal.h"
284#endif /* HAVE_AV_CONFIG_H */
285
286#endif /* AVUTIL_COMMON_H */
diff --git a/apps/codecs/libcook/libavutil/internal.h b/apps/codecs/libcook/libavutil/internal.h
new file mode 100644
index 0000000000..4191aa8e52
--- /dev/null
+++ b/apps/codecs/libcook/libavutil/internal.h
@@ -0,0 +1,328 @@
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 "common.h"
39#include "mem.h"
40#include "timer.h"
41
42#ifndef attribute_align_arg
43#if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,2)
44# define attribute_align_arg __attribute__((force_align_arg_pointer))
45#else
46# define attribute_align_arg
47#endif
48#endif
49
50#ifndef attribute_used
51#if AV_GCC_VERSION_AT_LEAST(3,1)
52# define attribute_used __attribute__((used))
53#else
54# define attribute_used
55#endif
56#endif
57
58#ifndef INT16_MIN
59#define INT16_MIN (-0x7fff-1)
60#endif
61
62#ifndef INT16_MAX
63#define INT16_MAX 0x7fff
64#endif
65
66#ifndef INT32_MIN
67#define INT32_MIN (-0x7fffffff-1)
68#endif
69
70#ifndef INT32_MAX
71#define INT32_MAX 0x7fffffff
72#endif
73
74#ifndef UINT32_MAX
75#define UINT32_MAX 0xffffffff
76#endif
77
78#ifndef INT64_MIN
79#define INT64_MIN (-0x7fffffffffffffffLL-1)
80#endif
81
82#ifndef INT64_MAX
83#define INT64_MAX INT64_C(9223372036854775807)
84#endif
85
86#ifndef UINT64_MAX
87#define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
88#endif
89
90#ifndef INT_BIT
91# define INT_BIT (CHAR_BIT * sizeof(int))
92#endif
93
94#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
95# define PIC
96#endif
97
98#ifndef offsetof
99# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
100#endif
101
102// Use rip-relative addressing if compiling PIC code on x86-64.
103#if ARCH_X86_64 && defined(PIC)
104# define LOCAL_MANGLE(a) #a "(%%rip)"
105#else
106# define LOCAL_MANGLE(a) #a
107#endif
108
109#define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
110
111/* debug stuff */
112
113/* dprintf macros */
114#ifdef DEBUG
115# define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
116#else
117# define dprintf(pctx, ...)
118#endif
119
120#define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
121
122/* math */
123
124extern const uint32_t ff_inverse[256];
125
126#if ARCH_X86
127# define FASTDIV(a,b) \
128 ({\
129 int ret,dmy;\
130 __asm__ volatile(\
131 "mull %3"\
132 :"=d"(ret),"=a"(dmy)\
133 :"1"(a),"g"(ff_inverse[b])\
134 );\
135 ret;\
136 })
137#elif HAVE_ARMV6 && HAVE_INLINE_ASM
138static inline av_const int FASTDIV(int a, int b)
139{
140 int r, t;
141 __asm__ volatile("cmp %3, #2 \n\t"
142 "ldr %1, [%4, %3, lsl #2] \n\t"
143 "lsrle %0, %2, #1 \n\t"
144 "smmulgt %0, %1, %2 \n\t"
145 : "=&r"(r), "=&r"(t) : "r"(a), "r"(b), "r"(ff_inverse));
146 return r;
147}
148#elif ARCH_ARM && HAVE_INLINE_ASM
149static inline av_const int FASTDIV(int a, int b)
150{
151 int r, t;
152 __asm__ volatile ("umull %1, %0, %2, %3"
153 : "=&r"(r), "=&r"(t) : "r"(a), "r"(ff_inverse[b]));
154 return r;
155}
156#elif CONFIG_FASTDIV
157# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*ff_inverse[b])>>32))
158#else
159# define FASTDIV(a,b) ((a)/(b))
160#endif
161
162extern const uint8_t ff_sqrt_tab[256];
163
164static inline av_const unsigned int ff_sqrt(unsigned int a)
165{
166 unsigned int b;
167
168 if(a<255) return (ff_sqrt_tab[a+1]-1)>>4;
169 else if(a<(1<<12)) b= ff_sqrt_tab[a>>4 ]>>2;
170#if !CONFIG_SMALL
171 else if(a<(1<<14)) b= ff_sqrt_tab[a>>6 ]>>1;
172 else if(a<(1<<16)) b= ff_sqrt_tab[a>>8 ] ;
173#endif
174 else{
175 int s= av_log2_16bit(a>>16)>>1;
176 unsigned int c= a>>(s+2);
177 b= ff_sqrt_tab[c>>(s+8)];
178 b= FASTDIV(c,b) + (b<<s);
179 }
180
181 return b - (a<b*b);
182}
183
184#if ARCH_X86
185#define MASK_ABS(mask, level)\
186 __asm__ volatile(\
187 "cltd \n\t"\
188 "xorl %1, %0 \n\t"\
189 "subl %1, %0 \n\t"\
190 : "+a" (level), "=&d" (mask)\
191 );
192#else
193#define MASK_ABS(mask, level)\
194 mask= level>>31;\
195 level= (level^mask)-mask;
196#endif
197
198#if HAVE_CMOV
199#define COPY3_IF_LT(x,y,a,b,c,d)\
200__asm__ volatile (\
201 "cmpl %0, %3 \n\t"\
202 "cmovl %3, %0 \n\t"\
203 "cmovl %4, %1 \n\t"\
204 "cmovl %5, %2 \n\t"\
205 : "+&r" (x), "+&r" (a), "+r" (c)\
206 : "r" (y), "r" (b), "r" (d)\
207);
208#else
209#define COPY3_IF_LT(x,y,a,b,c,d)\
210if((y)<(x)){\
211 (x)=(y);\
212 (a)=(b);\
213 (c)=(d);\
214}
215#endif
216
217/* avoid usage of dangerous/inappropriate system functions */
218#undef malloc
219#define malloc please_use_av_malloc
220#undef free
221#define free please_use_av_free
222#undef realloc
223#define realloc please_use_av_realloc
224#undef time
225#define time time_is_forbidden_due_to_security_issues
226#undef rand
227#define rand rand_is_forbidden_due_to_state_trashing_use_av_random
228#undef srand
229#define srand srand_is_forbidden_due_to_state_trashing_use_av_random_init
230#undef random
231#define random random_is_forbidden_due_to_state_trashing_use_av_random
232#undef sprintf
233#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
234#undef strcat
235#define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
236#undef exit
237#define exit exit_is_forbidden
238#ifndef LIBAVFORMAT_BUILD
239#undef printf
240#define printf please_use_av_log_instead_of_printf
241#undef fprintf
242#define fprintf please_use_av_log_instead_of_fprintf
243#undef puts
244#define puts please_use_av_log_instead_of_puts
245#undef perror
246#define perror please_use_av_log_instead_of_perror
247#endif
248
249#define CHECKED_ALLOCZ(p, size)\
250{\
251 p= av_mallocz(size);\
252 if(p==NULL && (size)!=0){\
253 av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory.");\
254 goto fail;\
255 }\
256}
257
258#if defined(__ICC) || defined(__SUNPRO_C)
259 #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
260 #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
261#elif defined(__GNUC__)
262 #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
263 #define DECLARE_ASM_CONST(n,t,v) static const t v attribute_used __attribute__ ((aligned (n)))
264#elif defined(_MSC_VER)
265 #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
266 #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
267#elif HAVE_INLINE_ASM
268 #error The asm code needs alignment, but we do not know how to do it for this compiler.
269#else
270 #define DECLARE_ALIGNED(n,t,v) t v
271 #define DECLARE_ASM_CONST(n,t,v) static const t v
272#endif
273
274
275#if !HAVE_LLRINT
276static av_always_inline av_const long long llrint(double x)
277{
278 return rint(x);
279}
280#endif /* HAVE_LLRINT */
281
282#if !HAVE_LRINT
283static av_always_inline av_const long int lrint(double x)
284{
285 return rint(x);
286}
287#endif /* HAVE_LRINT */
288
289#if !HAVE_LRINTF
290static av_always_inline av_const long int lrintf(float x)
291{
292 return (int)(rint(x));
293}
294#endif /* HAVE_LRINTF */
295
296#if !HAVE_ROUND
297static av_always_inline av_const double round(double x)
298{
299 return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
300}
301#endif /* HAVE_ROUND */
302
303#if !HAVE_ROUNDF
304static av_always_inline av_const float roundf(float x)
305{
306 return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
307}
308#endif /* HAVE_ROUNDF */
309
310#if !HAVE_TRUNCF
311static av_always_inline av_const float truncf(float x)
312{
313 return (x > 0) ? floor(x) : ceil(x);
314}
315#endif /* HAVE_TRUNCF */
316
317/**
318 * Returns NULL if CONFIG_SMALL is true, otherwise the argument
319 * without modification. Used to disable the definition of strings
320 * (for example AVCodec long_names).
321 */
322#if CONFIG_SMALL
323# define NULL_IF_CONFIG_SMALL(x) NULL
324#else
325# define NULL_IF_CONFIG_SMALL(x) x
326#endif
327
328#endif /* AVUTIL_INTERNAL_H */
diff --git a/apps/codecs/libcook/libavutil/intreadwrite.h b/apps/codecs/libcook/libavutil/intreadwrite.h
new file mode 100644
index 0000000000..7c5909ea51
--- /dev/null
+++ b/apps/codecs/libcook/libavutil/intreadwrite.h
@@ -0,0 +1,192 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVUTIL_INTREADWRITE_H
20#define AVUTIL_INTREADWRITE_H
21
22#include <stdint.h>
23#include "config.h"
24#include "bswap.h"
25
26#ifdef __GNUC__
27
28struct unaligned_64 { uint64_t l; } __attribute__((packed));
29struct unaligned_32 { uint32_t l; } __attribute__((packed));
30struct unaligned_16 { uint16_t l; } __attribute__((packed));
31
32#define AV_RN16(a) (((const struct unaligned_16 *) (a))->l)
33#define AV_RN32(a) (((const struct unaligned_32 *) (a))->l)
34#define AV_RN64(a) (((const struct unaligned_64 *) (a))->l)
35
36#define AV_WN16(a, b) (((struct unaligned_16 *) (a))->l) = (b)
37#define AV_WN32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
38#define AV_WN64(a, b) (((struct unaligned_64 *) (a))->l) = (b)
39
40#elif defined(__DECC)
41
42#define AV_RN16(a) (*((const __unaligned uint16_t*)(a)))
43#define AV_RN32(a) (*((const __unaligned uint32_t*)(a)))
44#define AV_RN64(a) (*((const __unaligned uint64_t*)(a)))
45
46#define AV_WN16(a, b) *((__unaligned uint16_t*)(a)) = (b)
47#define AV_WN32(a, b) *((__unaligned uint32_t*)(a)) = (b)
48#define AV_WN64(a, b) *((__unaligned uint64_t*)(a)) = (b)
49
50#else
51
52#define AV_RN16(a) (*((const uint16_t*)(a)))
53#define AV_RN32(a) (*((const uint32_t*)(a)))
54#define AV_RN64(a) (*((const uint64_t*)(a)))
55
56#define AV_WN16(a, b) *((uint16_t*)(a)) = (b)
57#define AV_WN32(a, b) *((uint32_t*)(a)) = (b)
58#define AV_WN64(a, b) *((uint64_t*)(a)) = (b)
59
60#endif /* !__GNUC__ */
61
62/* endian macros */
63#define AV_RB8(x) (((const uint8_t*)(x))[0])
64#define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0)
65
66#define AV_RL8(x) AV_RB8(x)
67#define AV_WL8(p, d) AV_WB8(p, d)
68
69#if HAVE_FAST_UNALIGNED
70# ifdef WORDS_BIGENDIAN
71# define AV_RB16(x) AV_RN16(x)
72# define AV_WB16(p, d) AV_WN16(p, d)
73
74# define AV_RL16(x) bswap_16(AV_RN16(x))
75# define AV_WL16(p, d) AV_WN16(p, bswap_16(d))
76
77# define AV_RB32(x) AV_RN32(x)
78# define AV_WB32(p, d) AV_WN32(p, d)
79
80# define AV_RL32(x) bswap_32(AV_RN32(x))
81# define AV_WL32(p, d) AV_WN32(p, bswap_32(d))
82
83# define AV_RB64(x) AV_RN64(x)
84# define AV_WB64(p, d) AV_WN64(p, d)
85
86# define AV_RL64(x) bswap_64(AV_RN64(x))
87# define AV_WL64(p, d) AV_WN64(p, bswap_64(d))
88# else /* WORDS_BIGENDIAN */
89# define AV_RB16(x) bswap_16(AV_RN16(x))
90# define AV_WB16(p, d) AV_WN16(p, bswap_16(d))
91
92# define AV_RL16(x) AV_RN16(x)
93# define AV_WL16(p, d) AV_WN16(p, d)
94
95# define AV_RB32(x) bswap_32(AV_RN32(x))
96# define AV_WB32(p, d) AV_WN32(p, bswap_32(d))
97
98# define AV_RL32(x) AV_RN32(x)
99# define AV_WL32(p, d) AV_WN32(p, d)
100
101# define AV_RB64(x) bswap_64(AV_RN64(x))
102# define AV_WB64(p, d) AV_WN64(p, bswap_64(d))
103
104# define AV_RL64(x) AV_RN64(x)
105# define AV_WL64(p, d) AV_WN64(p, d)
106# endif
107#else /* HAVE_FAST_UNALIGNED */
108#define AV_RB16(x) ((((const uint8_t*)(x))[0] << 8) | ((const uint8_t*)(x))[1])
109#define AV_WB16(p, d) do { \
110 ((uint8_t*)(p))[1] = (d); \
111 ((uint8_t*)(p))[0] = (d)>>8; } while(0)
112
113#define AV_RL16(x) ((((const uint8_t*)(x))[1] << 8) | \
114 ((const uint8_t*)(x))[0])
115#define AV_WL16(p, d) do { \
116 ((uint8_t*)(p))[0] = (d); \
117 ((uint8_t*)(p))[1] = (d)>>8; } while(0)
118
119#define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \
120 (((const uint8_t*)(x))[1] << 16) | \
121 (((const uint8_t*)(x))[2] << 8) | \
122 ((const uint8_t*)(x))[3])
123#define AV_WB32(p, d) do { \
124 ((uint8_t*)(p))[3] = (d); \
125 ((uint8_t*)(p))[2] = (d)>>8; \
126 ((uint8_t*)(p))[1] = (d)>>16; \
127 ((uint8_t*)(p))[0] = (d)>>24; } while(0)
128
129#define AV_RL32(x) ((((const uint8_t*)(x))[3] << 24) | \
130 (((const uint8_t*)(x))[2] << 16) | \
131 (((const uint8_t*)(x))[1] << 8) | \
132 ((const uint8_t*)(x))[0])
133#define AV_WL32(p, d) do { \
134 ((uint8_t*)(p))[0] = (d); \
135 ((uint8_t*)(p))[1] = (d)>>8; \
136 ((uint8_t*)(p))[2] = (d)>>16; \
137 ((uint8_t*)(p))[3] = (d)>>24; } while(0)
138
139#define AV_RB64(x) (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
140 ((uint64_t)((const uint8_t*)(x))[1] << 48) | \
141 ((uint64_t)((const uint8_t*)(x))[2] << 40) | \
142 ((uint64_t)((const uint8_t*)(x))[3] << 32) | \
143 ((uint64_t)((const uint8_t*)(x))[4] << 24) | \
144 ((uint64_t)((const uint8_t*)(x))[5] << 16) | \
145 ((uint64_t)((const uint8_t*)(x))[6] << 8) | \
146 (uint64_t)((const uint8_t*)(x))[7])
147#define AV_WB64(p, d) do { \
148 ((uint8_t*)(p))[7] = (d); \
149 ((uint8_t*)(p))[6] = (d)>>8; \
150 ((uint8_t*)(p))[5] = (d)>>16; \
151 ((uint8_t*)(p))[4] = (d)>>24; \
152 ((uint8_t*)(p))[3] = (d)>>32; \
153 ((uint8_t*)(p))[2] = (d)>>40; \
154 ((uint8_t*)(p))[1] = (d)>>48; \
155 ((uint8_t*)(p))[0] = (d)>>56; } while(0)
156
157#define AV_RL64(x) (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
158 ((uint64_t)((const uint8_t*)(x))[6] << 48) | \
159 ((uint64_t)((const uint8_t*)(x))[5] << 40) | \
160 ((uint64_t)((const uint8_t*)(x))[4] << 32) | \
161 ((uint64_t)((const uint8_t*)(x))[3] << 24) | \
162 ((uint64_t)((const uint8_t*)(x))[2] << 16) | \
163 ((uint64_t)((const uint8_t*)(x))[1] << 8) | \
164 (uint64_t)((const uint8_t*)(x))[0])
165#define AV_WL64(p, d) do { \
166 ((uint8_t*)(p))[0] = (d); \
167 ((uint8_t*)(p))[1] = (d)>>8; \
168 ((uint8_t*)(p))[2] = (d)>>16; \
169 ((uint8_t*)(p))[3] = (d)>>24; \
170 ((uint8_t*)(p))[4] = (d)>>32; \
171 ((uint8_t*)(p))[5] = (d)>>40; \
172 ((uint8_t*)(p))[6] = (d)>>48; \
173 ((uint8_t*)(p))[7] = (d)>>56; } while(0)
174#endif /* HAVE_FAST_UNALIGNED */
175
176#define AV_RB24(x) ((((const uint8_t*)(x))[0] << 16) | \
177 (((const uint8_t*)(x))[1] << 8) | \
178 ((const uint8_t*)(x))[2])
179#define AV_WB24(p, d) do { \
180 ((uint8_t*)(p))[2] = (d); \
181 ((uint8_t*)(p))[1] = (d)>>8; \
182 ((uint8_t*)(p))[0] = (d)>>16; } while(0)
183
184#define AV_RL24(x) ((((const uint8_t*)(x))[2] << 16) | \
185 (((const uint8_t*)(x))[1] << 8) | \
186 ((const uint8_t*)(x))[0])
187#define AV_WL24(p, d) do { \
188 ((uint8_t*)(p))[0] = (d); \
189 ((uint8_t*)(p))[1] = (d)>>8; \
190 ((uint8_t*)(p))[2] = (d)>>16; } while(0)
191
192#endif /* AVUTIL_INTREADWRITE_H */
diff --git a/apps/codecs/libcook/libavutil/lfg.c b/apps/codecs/libcook/libavutil/lfg.c
new file mode 100644
index 0000000000..337ee9e41c
--- /dev/null
+++ b/apps/codecs/libcook/libavutil/lfg.c
@@ -0,0 +1,64 @@
1/*
2 * Lagged Fibonacci PRNG
3 * Copyright (c) 2008 Michael Niedermayer
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 <inttypes.h>
23#include "lfg.h"
24#include "md5.h"
25#include "intreadwrite.h"
26
27void av_cold av_lfg_init(AVLFG *c, unsigned int seed){
28 uint8_t tmp[16]={0};
29 int i;
30
31 for(i=8; i<64; i+=4){
32 AV_WL32(tmp, seed); tmp[4]=i;
33 av_md5_sum(tmp, tmp, 16);
34 c->state[i ]= AV_RL32(tmp);
35 c->state[i+1]= AV_RL32(tmp+4);
36 c->state[i+2]= AV_RL32(tmp+8);
37 c->state[i+3]= AV_RL32(tmp+12);
38 }
39 c->index=0;
40}
41
42#ifdef TEST
43#include "log.h"
44#include "common.h"
45
46int main(void)
47{
48 int x=0;
49 int i, j;
50 AVLFG state;
51
52 av_lfg_init(&state, 0xdeadbeef);
53 for (j = 0; j < 10000; j++) {
54 START_TIMER
55 for (i = 0; i < 624; i++) {
56// av_log(NULL,AV_LOG_ERROR, "%X\n", av_lfg_get(&state));
57 x+=av_lfg_get(&state);
58 }
59 STOP_TIMER("624 calls of av_random");
60 }
61 av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x);
62 return 0;
63}
64#endif
diff --git a/apps/codecs/libcook/libavutil/lfg.h b/apps/codecs/libcook/libavutil/lfg.h
new file mode 100644
index 0000000000..3250c18e79
--- /dev/null
+++ b/apps/codecs/libcook/libavutil/lfg.h
@@ -0,0 +1,54 @@
1/*
2 * Lagged Fibonacci PRNG
3 * Copyright (c) 2008 Michael Niedermayer
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 AVUTIL_LFG_H
23#define AVUTIL_LFG_H
24
25typedef struct {
26 unsigned int state[64];
27 int index;
28} AVLFG;
29
30void av_lfg_init(AVLFG *c, unsigned int seed);
31
32/**
33 * Gets the next random unsigned 32-bit number using an ALFG.
34 *
35 * Please also consider a simple LCG like state= state*1664525+1013904223,
36 * it may be good enough and faster for your specific use case.
37 */
38static inline unsigned int av_lfg_get(AVLFG *c){
39 c->state[c->index & 63] = c->state[(c->index-24) & 63] + c->state[(c->index-55) & 63];
40 return c->state[c->index++ & 63];
41}
42
43/**
44 * Gets the next random unsigned 32-bit number using a MLFG.
45 *
46 * Please also consider av_lfg_get() above, it is faster.
47 */
48static inline unsigned int av_mlfg_get(AVLFG *c){
49 unsigned int a= c->state[(c->index-55) & 63];
50 unsigned int b= c->state[(c->index-24) & 63];
51 return c->state[c->index++ & 63] = 2*a*b+a+b;
52}
53
54#endif /* AVUTIL_LFG_H */
diff --git a/apps/codecs/libcook/libavutil/log.c b/apps/codecs/libcook/libavutil/log.c
new file mode 100644
index 0000000000..4bb9652c2c
--- /dev/null
+++ b/apps/codecs/libcook/libavutil/log.c
@@ -0,0 +1,89 @@
1/*
2 * log functions
3 * Copyright (c) 2003 Michel Bardiaux
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
23 * @file libavutil/log.c
24 * logging functions
25 */
26
27#include "avutil.h"
28#include "log.h"
29
30int av_log_level = AV_LOG_INFO;
31
32void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
33{
34 static int print_prefix=1;
35 static int count;
36 static char line[1024], prev[1024];
37 AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
38 if(level>av_log_level)
39 return;
40#undef fprintf
41 if(print_prefix && avc) {
42 snprintf(line, sizeof(line), "[%s @ %p]", avc->item_name(ptr), ptr);
43 }else
44 line[0]=0;
45
46 vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);
47
48 print_prefix= line[strlen(line)-1] == '\n';
49 if(print_prefix && !strcmp(line, prev)){
50 count++;
51 return;
52 }
53 if(count>0){
54 fprintf(stderr, " Last message repeated %d times\n", count);
55 count=0;
56 }
57 fputs(line, stderr);
58 strcpy(prev, line);
59}
60
61static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
62
63void av_log(void* avcl, int level, const char *fmt, ...)
64{
65 va_list vl;
66 va_start(vl, fmt);
67 av_vlog(avcl, level, fmt, vl);
68 va_end(vl);
69}
70
71void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
72{
73 av_log_callback(avcl, level, fmt, vl);
74}
75
76int av_log_get_level(void)
77{
78 return av_log_level;
79}
80
81void av_log_set_level(int level)
82{
83 av_log_level = level;
84}
85
86void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
87{
88 av_log_callback = callback;
89}
diff --git a/apps/codecs/libcook/libavutil/log.h b/apps/codecs/libcook/libavutil/log.h
new file mode 100644
index 0000000000..1206a2fc38
--- /dev/null
+++ b/apps/codecs/libcook/libavutil/log.h
@@ -0,0 +1,116 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef AVUTIL_LOG_H
22#define AVUTIL_LOG_H
23
24#include <stdarg.h>
25#include "avutil.h"
26
27/**
28 * Describes the class of an AVClass context structure. That is an
29 * arbitrary struct of which the first field is a pointer to an
30 * AVClass struct (e.g. AVCodecContext, AVFormatContext etc.).
31 */
32typedef struct AVCLASS AVClass;
33struct AVCLASS {
34 /**
35 * The name of the class; usually it is the same name as the
36 * context structure type to which the AVClass is associated.
37 */
38 const char* class_name;
39
40 /**
41 * A pointer to a function which returns the name of a context
42 * instance \p ctx associated with the class.
43 */
44 const char* (*item_name)(void* ctx);
45
46 /**
47 * a pointer to the first option specified in the class if any or NULL
48 *
49 * @see av_set_default_options()
50 */
51 const struct AVOption *option;
52};
53
54/* av_log API */
55
56#define AV_LOG_QUIET -8
57
58/**
59 * Something went really wrong and we will crash now.
60 */
61#define AV_LOG_PANIC 0
62
63/**
64 * Something went wrong and recovery is not possible.
65 * For example, no header was found for a format which depends
66 * on headers or an illegal combination of parameters is used.
67 */
68#define AV_LOG_FATAL 8
69
70/**
71 * Something went wrong and cannot losslessly be recovered.
72 * However, not all future data is affected.
73 */
74#define AV_LOG_ERROR 16
75
76/**
77 * Something somehow does not look correct. This may or may not
78 * lead to problems. An example would be the use of '-vstrict -2'.
79 */
80#define AV_LOG_WARNING 24
81
82#define AV_LOG_INFO 32
83#define AV_LOG_VERBOSE 40
84
85/**
86 * Stuff which is only useful for libav* developers.
87 */
88#define AV_LOG_DEBUG 48
89
90/**
91 * Sends the specified message to the log if the level is less than or equal
92 * to the current av_log_level. By default, all logging messages are sent to
93 * stderr. This behavior can be altered by setting a different av_vlog callback
94 * function.
95 *
96 * @param avcl A pointer to an arbitrary struct of which the first field is a
97 * pointer to an AVClass struct.
98 * @param level The importance level of the message, lower values signifying
99 * higher importance.
100 * @param fmt The format string (printf-compatible) that specifies how
101 * subsequent arguments are converted to output.
102 * @see av_vlog
103 */
104#ifdef __GNUC__
105void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
106#else
107void av_log(void*, int level, const char *fmt, ...);
108#endif
109
110void av_vlog(void*, int level, const char *fmt, va_list);
111int av_log_get_level(void);
112void av_log_set_level(int);
113void av_log_set_callback(void (*)(void*, int, const char*, va_list));
114void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl);
115
116#endif /* AVUTIL_LOG_H */
diff --git a/apps/codecs/libcook/libavutil/md5.c b/apps/codecs/libcook/libavutil/md5.c
new file mode 100644
index 0000000000..26d1fb3874
--- /dev/null
+++ b/apps/codecs/libcook/libavutil/md5.c
@@ -0,0 +1,182 @@
1/*
2 * Copyright (C) 2006 Michael Niedermayer (michaelni@gmx.at)
3 * Copyright (C) 2003-2005 by Christopher R. Hertel (crh@ubiqx.mn.org)
4 *
5 * References:
6 * IETF RFC 1321: The MD5 Message-Digest Algorithm
7 * Ron Rivest. IETF, April, 1992
8 *
9 * based on http://ubiqx.org/libcifs/source/Auth/MD5.c
10 * from Christopher R. Hertel (crh@ubiqx.mn.org)
11 * Simplified, cleaned and IMO redundant comments removed by michael.
12 *
13 * If you use gcc, then version 4.1 or later and -fomit-frame-pointer is
14 * strongly recommended.
15 *
16 * This file is part of FFmpeg.
17 *
18 * FFmpeg is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU Lesser General Public
20 * License as published by the Free Software Foundation; either
21 * version 2.1 of the License, or (at your option) any later version.
22 *
23 * FFmpeg is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * Lesser General Public License for more details.
27 *
28 * You should have received a copy of the GNU Lesser General Public
29 * License along with FFmpeg; if not, write to the Free Software
30 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31 */
32
33#include <string.h>
34#include "bswap.h"
35#include "md5.h"
36
37typedef struct AVMD5{
38 uint64_t len;
39 uint8_t block[64];
40 uint32_t ABCD[4];
41} AVMD5;
42
43const int av_md5_size= sizeof(AVMD5);
44
45static const uint8_t S[4][4] = {
46 { 7, 12, 17, 22 }, /* round 1 */
47 { 5, 9, 14, 20 }, /* round 2 */
48 { 4, 11, 16, 23 }, /* round 3 */
49 { 6, 10, 15, 21 } /* round 4 */
50};
51
52static const uint32_t T[64] = { // T[i]= fabs(sin(i+1)<<32)
53 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, /* round 1 */
54 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
55 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
56 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
57
58 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, /* round 2 */
59 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
60 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
61 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
62
63 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, /* round 3 */
64 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
65 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
66 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
67
68 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, /* round 4 */
69 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
70 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
71 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
72};
73
74#define CORE(i, a, b, c, d) \
75 t = S[i>>4][i&3];\
76 a += T[i];\
77\
78 if(i<32){\
79 if(i<16) a += (d ^ (b&(c^d))) + X[ i &15 ];\
80 else a += (c ^ (d&(c^b))) + X[ (1+5*i)&15 ];\
81 }else{\
82 if(i<48) a += (b^c^d) + X[ (5+3*i)&15 ];\
83 else a += (c^(b|~d)) + X[ ( 7*i)&15 ];\
84 }\
85 a = b + (( a << t ) | ( a >> (32 - t) ));
86
87static void body(uint32_t ABCD[4], uint32_t X[16]){
88
89 int t;
90 int i av_unused;
91 unsigned int a= ABCD[3];
92 unsigned int b= ABCD[2];
93 unsigned int c= ABCD[1];
94 unsigned int d= ABCD[0];
95
96#ifdef WORDS_BIGENDIAN
97 for(i=0; i<16; i++)
98 X[i]= bswap_32(X[i]);
99#endif
100
101#if CONFIG_SMALL
102 for( i = 0; i < 64; i++ ){
103 CORE(i,a,b,c,d)
104 t=d; d=c; c=b; b=a; a=t;
105 }
106#else
107#define CORE2(i) CORE(i,a,b,c,d) CORE((i+1),d,a,b,c) CORE((i+2),c,d,a,b) CORE((i+3),b,c,d,a)
108#define CORE4(i) CORE2(i) CORE2((i+4)) CORE2((i+8)) CORE2((i+12))
109CORE4(0) CORE4(16) CORE4(32) CORE4(48)
110#endif
111
112 ABCD[0] += d;
113 ABCD[1] += c;
114 ABCD[2] += b;
115 ABCD[3] += a;
116}
117
118void av_md5_init(AVMD5 *ctx){
119 ctx->len = 0;
120
121 ctx->ABCD[0] = 0x10325476;
122 ctx->ABCD[1] = 0x98badcfe;
123 ctx->ABCD[2] = 0xefcdab89;
124 ctx->ABCD[3] = 0x67452301;
125}
126
127void av_md5_update(AVMD5 *ctx, const uint8_t *src, const int len){
128 int i, j;
129
130 j= ctx->len & 63;
131 ctx->len += len;
132
133 for( i = 0; i < len; i++ ){
134 ctx->block[j++] = src[i];
135 if( 64 == j ){
136 body(ctx->ABCD, (uint32_t*) ctx->block);
137 j = 0;
138 }
139 }
140}
141
142void av_md5_final(AVMD5 *ctx, uint8_t *dst){
143 int i;
144 uint64_t finalcount= le2me_64(ctx->len<<3);
145
146 av_md5_update(ctx, "\200", 1);
147 while((ctx->len & 63)!=56)
148 av_md5_update(ctx, "", 1);
149
150 av_md5_update(ctx, (uint8_t*)&finalcount, 8);
151
152 for(i=0; i<4; i++)
153 ((uint32_t*)dst)[i]= le2me_32(ctx->ABCD[3-i]);
154}
155
156void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len){
157 AVMD5 ctx[1];
158
159 av_md5_init(ctx);
160 av_md5_update(ctx, src, len);
161 av_md5_final(ctx, dst);
162}
163
164#ifdef TEST
165#include <stdio.h>
166#undef printf
167int main(void){
168 uint64_t md5val;
169 int i;
170 uint8_t in[1000];
171
172 for(i=0; i<1000; i++) in[i]= i*i;
173 av_md5_sum( (uint8_t*)&md5val, in, 1000); printf("%"PRId64"\n", md5val);
174 av_md5_sum( (uint8_t*)&md5val, in, 63); printf("%"PRId64"\n", md5val);
175 av_md5_sum( (uint8_t*)&md5val, in, 64); printf("%"PRId64"\n", md5val);
176 av_md5_sum( (uint8_t*)&md5val, in, 65); printf("%"PRId64"\n", md5val);
177 for(i=0; i<1000; i++) in[i]= i % 127;
178 av_md5_sum( (uint8_t*)&md5val, in, 999); printf("%"PRId64"\n", md5val);
179
180 return 0;
181}
182#endif
diff --git a/apps/codecs/libcook/libavutil/md5.h b/apps/codecs/libcook/libavutil/md5.h
new file mode 100644
index 0000000000..969202a807
--- /dev/null
+++ b/apps/codecs/libcook/libavutil/md5.h
@@ -0,0 +1,36 @@
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_MD5_H
22#define AVUTIL_MD5_H
23
24#include <stdint.h>
25
26extern const int av_md5_size;
27
28struct AVMD5;
29
30void av_md5_init(struct AVMD5 *ctx);
31void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, const int len);
32void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);
33void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len);
34
35#endif /* AVUTIL_MD5_H */
36
diff --git a/apps/codecs/libcook/libavutil/mem.c b/apps/codecs/libcook/libavutil/mem.c
new file mode 100644
index 0000000000..741450b53f
--- /dev/null
+++ b/apps/codecs/libcook/libavutil/mem.c
@@ -0,0 +1,159 @@
1/*
2 * default memory allocator for libavutil
3 * Copyright (c) 2002 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
23 * @file libavutil/mem.c
24 * default memory allocator for libavutil
25 */
26
27#include "config.h"
28
29#include <limits.h>
30#include <stdlib.h>
31#include <string.h>
32#if HAVE_MALLOC_H
33#include <malloc.h>
34#endif
35
36#include "mem.h"
37
38/* here we can use OS-dependent allocation functions */
39#undef free
40#undef malloc
41#undef realloc
42
43/* You can redefine av_malloc and av_free in your project to use your
44 memory allocator. You do not need to suppress this file because the
45 linker will do it automatically. */
46
47void *av_malloc(unsigned int size)
48{
49 void *ptr = NULL;
50#if CONFIG_MEMALIGN_HACK
51 long diff;
52#endif
53
54 /* let's disallow possible ambiguous cases */
55 if(size > (INT_MAX-16) )
56 return NULL;
57
58#if CONFIG_MEMALIGN_HACK
59 ptr = malloc(size+16);
60 if(!ptr)
61 return ptr;
62 diff= ((-(long)ptr - 1)&15) + 1;
63 ptr = (char*)ptr + diff;
64 ((char*)ptr)[-1]= diff;
65#elif HAVE_POSIX_MEMALIGN
66 if (posix_memalign(&ptr,16,size))
67 ptr = NULL;
68#elif HAVE_MEMALIGN
69 ptr = memalign(16,size);
70 /* Why 64?
71 Indeed, we should align it:
72 on 4 for 386
73 on 16 for 486
74 on 32 for 586, PPro - K6-III
75 on 64 for K7 (maybe for P3 too).
76 Because L1 and L2 caches are aligned on those values.
77 But I don't want to code such logic here!
78 */
79 /* Why 16?
80 Because some CPUs need alignment, for example SSE2 on P4, & most RISC CPUs
81 it will just trigger an exception and the unaligned load will be done in the
82 exception handler or it will just segfault (SSE2 on P4).
83 Why not larger? Because I did not see a difference in benchmarks ...
84 */
85 /* benchmarks with P3
86 memalign(64)+1 3071,3051,3032
87 memalign(64)+2 3051,3032,3041
88 memalign(64)+4 2911,2896,2915
89 memalign(64)+8 2545,2554,2550
90 memalign(64)+16 2543,2572,2563
91 memalign(64)+32 2546,2545,2571
92 memalign(64)+64 2570,2533,2558
93
94 BTW, malloc seems to do 8-byte alignment by default here.
95 */
96#else
97 ptr = malloc(size);
98#endif
99 return ptr;
100}
101
102void *av_realloc(void *ptr, unsigned int size)
103{
104#if CONFIG_MEMALIGN_HACK
105 int diff;
106#endif
107
108 /* let's disallow possible ambiguous cases */
109 if(size > (INT_MAX-16) )
110 return NULL;
111
112#if CONFIG_MEMALIGN_HACK
113 //FIXME this isn't aligned correctly, though it probably isn't needed
114 if(!ptr) return av_malloc(size);
115 diff= ((char*)ptr)[-1];
116 return (char*)realloc((char*)ptr - diff, size + diff) + diff;
117#else
118 return realloc(ptr, size);
119#endif
120}
121
122void av_free(void *ptr)
123{
124 /* XXX: this test should not be needed on most libcs */
125 if (ptr)
126#if CONFIG_MEMALIGN_HACK
127 free((char*)ptr - ((char*)ptr)[-1]);
128#else
129 free(ptr);
130#endif
131}
132
133void av_freep(void *arg)
134{
135 void **ptr= (void**)arg;
136 av_free(*ptr);
137 *ptr = NULL;
138}
139
140void *av_mallocz(unsigned int size)
141{
142 void *ptr = av_malloc(size);
143 if (ptr)
144 memset(ptr, 0, size);
145 return ptr;
146}
147
148char *av_strdup(const char *s)
149{
150 char *ptr= NULL;
151 if(s){
152 int len = strlen(s) + 1;
153 ptr = av_malloc(len);
154 if (ptr)
155 memcpy(ptr, s, len);
156 }
157 return ptr;
158}
159
diff --git a/apps/codecs/libcook/libavutil/mem.h b/apps/codecs/libcook/libavutil/mem.h
new file mode 100644
index 0000000000..e50553aefe
--- /dev/null
+++ b/apps/codecs/libcook/libavutil/mem.h
@@ -0,0 +1,104 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file libavutil/mem.h
23 * memory handling functions
24 */
25
26#ifndef AVUTIL_MEM_H
27#define AVUTIL_MEM_H
28
29#include "common.h"
30
31#if AV_GCC_VERSION_AT_LEAST(3,1)
32 #define av_malloc_attrib __attribute__((__malloc__))
33#else
34 #define av_malloc_attrib
35#endif
36
37#if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,3)
38 #define av_alloc_size(n) __attribute__((alloc_size(n)))
39#else
40 #define av_alloc_size(n)
41#endif
42
43/**
44 * Allocates a block of \p size bytes with alignment suitable for all
45 * memory accesses (including vectors if available on the CPU).
46 * @param size Size in bytes for the memory block to be allocated.
47 * @return Pointer to the allocated block, NULL if the block cannot
48 * be allocated.
49 * @see av_mallocz()
50 */
51void *av_malloc(unsigned int size) av_malloc_attrib av_alloc_size(1);
52
53/**
54 * Allocates or reallocates a block of memory.
55 * If \p ptr is NULL and \p size > 0, allocates a new block. If \p
56 * size is zero, frees the memory block pointed to by \p ptr.
57 * @param size Size in bytes for the memory block to be allocated or
58 * reallocated.
59 * @param ptr Pointer to a memory block already allocated with
60 * av_malloc(z)() or av_realloc() or NULL.
61 * @return Pointer to a newly reallocated block or NULL if the block
62 * cannot be reallocated or the function is used to free the memory block.
63 * @see av_fast_realloc()
64 */
65void *av_realloc(void *ptr, unsigned int size) av_alloc_size(2);
66
67/**
68 * Frees a memory block which has been allocated with av_malloc(z)() or
69 * av_realloc().
70 * @param ptr Pointer to the memory block which should be freed.
71 * @note ptr = NULL is explicitly allowed.
72 * @note It is recommended that you use av_freep() instead.
73 * @see av_freep()
74 */
75void av_free(void *ptr);
76
77/**
78 * Allocates a block of \p size bytes with alignment suitable for all
79 * memory accesses (including vectors if available on the CPU) and
80 * zeroes all the bytes of the block.
81 * @param size Size in bytes for the memory block to be allocated.
82 * @return Pointer to the allocated block, NULL if it cannot be allocated.
83 * @see av_malloc()
84 */
85void *av_mallocz(unsigned int size) av_malloc_attrib av_alloc_size(1);
86
87/**
88 * Duplicates the string \p s.
89 * @param s string to be duplicated
90 * @return Pointer to a newly allocated string containing a
91 * copy of \p s or NULL if the string cannot be allocated.
92 */
93char *av_strdup(const char *s) av_malloc_attrib;
94
95/**
96 * Frees a memory block which has been allocated with av_malloc(z)() or
97 * av_realloc() and set the pointer pointing to it to NULL.
98 * @param ptr Pointer to the pointer to the memory block which should
99 * be freed.
100 * @see av_free()
101 */
102void av_freep(void *ptr);
103
104#endif /* AVUTIL_MEM_H */
diff --git a/apps/codecs/libcook/mdct.c b/apps/codecs/libcook/mdct.c
new file mode 100644
index 0000000000..cb3388f6ff
--- /dev/null
+++ b/apps/codecs/libcook/mdct.c
@@ -0,0 +1,229 @@
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#include "dsputil.h"
22
23/**
24 * @file libavcodec/mdct.c
25 * MDCT/IMDCT transforms.
26 */
27
28// Generate a Kaiser-Bessel Derived Window.
29#define BESSEL_I0_ITER 50 // default: 50 iterations of Bessel I0 approximation
30av_cold void ff_kbd_window_init(float *window, float alpha, int n)
31{
32 int i, j;
33 double sum = 0.0, bessel, tmp;
34 double local_window[n];
35 double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n);
36
37 for (i = 0; i < n; i++) {
38 tmp = i * (n - i) * alpha2;
39 bessel = 1.0;
40 for (j = BESSEL_I0_ITER; j > 0; j--)
41 bessel = bessel * tmp / (j * j) + 1;
42 sum += bessel;
43 local_window[i] = sum;
44 }
45
46 sum++;
47 for (i = 0; i < n; i++)
48 window[i] = sqrt(local_window[i] / sum);
49}
50
51DECLARE_ALIGNED(16, float, ff_sine_128 [ 128]);
52DECLARE_ALIGNED(16, float, ff_sine_256 [ 256]);
53DECLARE_ALIGNED(16, float, ff_sine_512 [ 512]);
54DECLARE_ALIGNED(16, float, ff_sine_1024[1024]);
55DECLARE_ALIGNED(16, float, ff_sine_2048[2048]);
56DECLARE_ALIGNED(16, float, ff_sine_4096[4096]);
57float *ff_sine_windows[6] = {
58 ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096
59};
60
61// Generate a sine window.
62av_cold void ff_sine_window_init(float *window, int n) {
63 int i;
64 for(i = 0; i < n; i++)
65 window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n)));
66}
67
68/**
69 * init MDCT or IMDCT computation.
70 */
71av_cold int ff_mdct_init(MDCTContext *s, int nbits, int inverse)
72{
73 int n, n4, i;
74 double alpha;
75
76 memset(s, 0, sizeof(*s));
77 n = 1 << nbits;
78 s->nbits = nbits;
79 s->n = n;
80 n4 = n >> 2;
81 s->tcos = av_malloc(n4 * sizeof(FFTSample));
82 if (!s->tcos)
83 goto fail;
84 s->tsin = av_malloc(n4 * sizeof(FFTSample));
85 if (!s->tsin)
86 goto fail;
87
88 for(i=0;i<n4;i++) {
89 alpha = 2 * M_PI * (i + 1.0 / 8.0) / n;
90 s->tcos[i] = -cos(alpha);
91 s->tsin[i] = -sin(alpha);
92 }
93 if (ff_fft_init(&s->fft, s->nbits - 2, inverse) < 0)
94 goto fail;
95 return 0;
96 fail:
97 av_freep(&s->tcos);
98 av_freep(&s->tsin);
99 return -1;
100}
101
102/* complex multiplication: p = a * b */
103#define CMUL(pre, pim, are, aim, bre, bim) \
104{\
105 FFTSample _are = (are);\
106 FFTSample _aim = (aim);\
107 FFTSample _bre = (bre);\
108 FFTSample _bim = (bim);\
109 (pre) = _are * _bre - _aim * _bim;\
110 (pim) = _are * _bim + _aim * _bre;\
111}
112
113/**
114 * Compute the middle half of the inverse MDCT of size N = 2^nbits,
115 * thus excluding the parts that can be derived by symmetry
116 * @param output N/2 samples
117 * @param input N/2 samples
118 */
119void ff_imdct_half_c(MDCTContext *s, FFTSample *output, const FFTSample *input)
120{
121 int k, n8, n4, n2, n, j;
122 const uint16_t *revtab = s->fft.revtab;
123 const FFTSample *tcos = s->tcos;
124 const FFTSample *tsin = s->tsin;
125 const FFTSample *in1, *in2;
126 FFTComplex *z = (FFTComplex *)output;
127
128 n = 1 << s->nbits;
129 n2 = n >> 1;
130 n4 = n >> 2;
131 n8 = n >> 3;
132
133 /* pre rotation */
134 in1 = input;
135 in2 = input + n2 - 1;
136 for(k = 0; k < n4; k++) {
137 j=revtab[k];
138 CMUL(z[j].re, z[j].im, *in2, *in1, tcos[k], tsin[k]);
139 in1 += 2;
140 in2 -= 2;
141 }
142 ff_fft_calc(&s->fft, z);
143
144 /* post rotation + reordering */
145 output += n4;
146 for(k = 0; k < n8; k++) {
147 FFTSample r0, i0, r1, i1;
148 CMUL(r0, i1, z[n8-k-1].im, z[n8-k-1].re, tsin[n8-k-1], tcos[n8-k-1]);
149 CMUL(r1, i0, z[n8+k ].im, z[n8+k ].re, tsin[n8+k ], tcos[n8+k ]);
150 z[n8-k-1].re = r0;
151 z[n8-k-1].im = i0;
152 z[n8+k ].re = r1;
153 z[n8+k ].im = i1;
154 }
155}
156
157/**
158 * Compute inverse MDCT of size N = 2^nbits
159 * @param output N samples
160 * @param input N/2 samples
161 */
162void ff_imdct_calc_c(MDCTContext *s, FFTSample *output, const FFTSample *input)
163{
164 int k;
165 int n = 1 << s->nbits;
166 int n2 = n >> 1;
167 int n4 = n >> 2;
168
169 ff_imdct_half_c(s, output+n4, input);
170
171 for(k = 0; k < n4; k++) {
172 output[k] = -output[n2-k-1];
173 output[n-k-1] = output[n2+k];
174 }
175}
176
177/**
178 * Compute MDCT of size N = 2^nbits
179 * @param input N samples
180 * @param out N/2 samples
181 */
182void ff_mdct_calc(MDCTContext *s, FFTSample *out, const FFTSample *input)
183{
184 int i, j, n, n8, n4, n2, n3;
185 FFTSample re, im;
186 const uint16_t *revtab = s->fft.revtab;
187 const FFTSample *tcos = s->tcos;
188 const FFTSample *tsin = s->tsin;
189 FFTComplex *x = (FFTComplex *)out;
190
191 n = 1 << s->nbits;
192 n2 = n >> 1;
193 n4 = n >> 2;
194 n8 = n >> 3;
195 n3 = 3 * n4;
196
197 /* pre rotation */
198 for(i=0;i<n8;i++) {
199 re = -input[2*i+3*n4] - input[n3-1-2*i];
200 im = -input[n4+2*i] + input[n4-1-2*i];
201 j = revtab[i];
202 CMUL(x[j].re, x[j].im, re, im, -tcos[i], tsin[i]);
203
204 re = input[2*i] - input[n2-1-2*i];
205 im = -(input[n2+2*i] + input[n-1-2*i]);
206 j = revtab[n8 + i];
207 CMUL(x[j].re, x[j].im, re, im, -tcos[n8 + i], tsin[n8 + i]);
208 }
209
210 ff_fft_calc(&s->fft, x);
211
212 /* post rotation */
213 for(i=0;i<n8;i++) {
214 FFTSample r0, i0, r1, i1;
215 CMUL(i1, r0, x[n8-i-1].re, x[n8-i-1].im, -tsin[n8-i-1], -tcos[n8-i-1]);
216 CMUL(i0, r1, x[n8+i ].re, x[n8+i ].im, -tsin[n8+i ], -tcos[n8+i ]);
217 x[n8-i-1].re = r0;
218 x[n8-i-1].im = i0;
219 x[n8+i ].re = r1;
220 x[n8+i ].im = i1;
221 }
222}
223
224av_cold void ff_mdct_end(MDCTContext *s)
225{
226 av_freep(&s->tcos);
227 av_freep(&s->tsin);
228 ff_fft_end(&s->fft);
229}