fix image buffer leak on keyframes, add more error condition checks
[libav.git] / libavcodec / avcodec.h
CommitLineData
a96b68b7
FB
1#ifndef AVCODEC_H
2#define AVCODEC_H
3
36df8805
MN
4/**
5 * @file avcodec.h
d33c949c 6 * external api header.
36df8805
MN
7 */
8
9
02d697aa
ZK
10#ifdef __cplusplus
11extern "C" {
12#endif
13
de6d9b64
FB
14#include "common.h"
15
4b1f4f23
J
16#define LIBAVCODEC_VERSION_INT 0x000406
17#define LIBAVCODEC_VERSION "0.4.6"
0469baf1
FB
18#define LIBAVCODEC_BUILD 4666
19#define LIBAVCODEC_BUILD_STR "4666"
4b1f4f23 20
ce2749d2
AB
21#define LIBAVCODEC_IDENT "FFmpeg" LIBAVCODEC_VERSION "b" LIBAVCODEC_BUILD_STR
22
de6d9b64
FB
23enum CodecID {
24 CODEC_ID_NONE,
25 CODEC_ID_MPEG1VIDEO,
26 CODEC_ID_H263,
27 CODEC_ID_RV10,
28 CODEC_ID_MP2,
9d36bdc9 29 CODEC_ID_MP3LAME,
81e0d0b4 30 CODEC_ID_VORBIS,
de6d9b64
FB
31 CODEC_ID_AC3,
32 CODEC_ID_MJPEG,
b135d9fb 33 CODEC_ID_MJPEGB,
bf89e6b1 34 CODEC_ID_MPEG4,
de6d9b64 35 CODEC_ID_RAWVIDEO,
84afee34
MN
36 CODEC_ID_MSMPEG4V1,
37 CODEC_ID_MSMPEG4V2,
38 CODEC_ID_MSMPEG4V3,
e1a9dbff 39 CODEC_ID_WMV1,
b50eef3a 40 CODEC_ID_WMV2,
de6d9b64
FB
41 CODEC_ID_H263P,
42 CODEC_ID_H263I,
be8ffec9 43 CODEC_ID_SVQ1,
8b82a956 44 CODEC_ID_SVQ3,
020fcc94
FB
45 CODEC_ID_DVVIDEO,
46 CODEC_ID_DVAUDIO,
bc8d1857
FB
47 CODEC_ID_WMAV1,
48 CODEC_ID_WMAV2,
3f95e843
FR
49 CODEC_ID_MACE3,
50 CODEC_ID_MACE6,
11f18faf 51 CODEC_ID_HUFFYUV,
f70f7c6d 52 CODEC_ID_CYUV,
0da71265 53 CODEC_ID_H264,
deabd4fd 54 CODEC_ID_INDEO3,
d86053a4 55 CODEC_ID_VP3,
a96b68b7
FB
56
57 /* various pcm "codecs" */
58 CODEC_ID_PCM_S16LE,
59 CODEC_ID_PCM_S16BE,
60 CODEC_ID_PCM_U16LE,
61 CODEC_ID_PCM_U16BE,
62 CODEC_ID_PCM_S8,
63 CODEC_ID_PCM_U8,
64 CODEC_ID_PCM_MULAW,
65 CODEC_ID_PCM_ALAW,
0147f198
FR
66
67 /* various adpcm codecs */
68 CODEC_ID_ADPCM_IMA_QT,
69 CODEC_ID_ADPCM_IMA_WAV,
70 CODEC_ID_ADPCM_MS,
de6d9b64
FB
71};
72
73enum CodecType {
4a663d80 74 CODEC_TYPE_UNKNOWN = -1,
de6d9b64
FB
75 CODEC_TYPE_VIDEO,
76 CODEC_TYPE_AUDIO,
77};
78
64863965
MN
79/**
80 * Pixel format.
81 */
de6d9b64
FB
82enum PixelFormat {
83 PIX_FMT_YUV420P,
84 PIX_FMT_YUV422,
64863965
MN
85 PIX_FMT_RGB24, ///< 3 bytes, R is first
86 PIX_FMT_BGR24, ///< 3 bytes, B is first
d9fea0b5
FB
87 PIX_FMT_YUV422P,
88 PIX_FMT_YUV444P,
64863965 89 PIX_FMT_RGBA32, ///< always stored in cpu endianness
e9feea59 90 PIX_FMT_YUV410P,
a32072d0 91 PIX_FMT_YUV411P,
64863965
MN
92 PIX_FMT_RGB565, ///< always stored in cpu endianness
93 PIX_FMT_RGB555, ///< always stored in cpu endianness, most significant bit to 1
dab64ebc 94 PIX_FMT_GRAY8,
64863965
MN
95 PIX_FMT_MONOWHITE, ///< 0 is white
96 PIX_FMT_MONOBLACK, ///< 0 is black
97 PIX_FMT_PAL8, ///< 8 bit with RGBA palette
fab21997
FB
98 PIX_FMT_YUVJ420P, ///< YUV full scale (jpeg)
99 PIX_FMT_YUVJ422P, ///< YUV full scale (jpeg)
100 PIX_FMT_YUVJ444P, ///< YUV full scale (jpeg)
dab64ebc 101 PIX_FMT_NB,
de6d9b64
FB
102};
103
a96b68b7
FB
104/* currently unused, may be used if 24/32 bits samples ever supported */
105enum SampleFormat {
64863965 106 SAMPLE_FMT_S16 = 0, ///< signed 16 bits
a96b68b7
FB
107};
108
de6d9b64 109/* in bytes */
bc8d1857 110#define AVCODEC_MAX_AUDIO_FRAME_SIZE 131072
de6d9b64 111
d7425f59
MN
112/**
113 * Required number of zero bytes at the end of the input bitstream for decoding.
114 * to avoid overreading (and possibly segfaulting)
115 */
116#define FF_INPUT_BUFFER_PADDING_SIZE 8
117
e4986da9
J
118/* motion estimation type, EPZS by default */
119enum Motion_Est_ID {
101bea5f 120 ME_ZERO = 1,
e4986da9
J
121 ME_FULL,
122 ME_LOG,
123 ME_PHODS,
124 ME_EPZS,
125 ME_X1
126};
127
ce980a95
MN
128typedef struct RcOverride{
129 int start_frame;
130 int end_frame;
131 int qscale; // if this is 0 then quality_factor will be used instead
132 float quality_factor;
133} RcOverride;
134
101bea5f
J
135/* only for ME compatiblity with old apps */
136extern int motion_estimation_method;
137
e4986da9 138/* ME algos sorted by quality */
bc6caae2
J
139static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG,
140 ME_X1, ME_EPZS, ME_FULL };
de6d9b64 141
28db7fce 142
4e00e76b 143#define FF_MAX_B_FRAMES 8
9dbcbd92 144
a949d72e
MN
145/* encoding support
146 these flags can be passed in AVCodecContext.flags before initing
147 Note: note not everything is supported yet
148*/
de6d9b64 149
64863965
MN
150#define CODEC_FLAG_HQ 0x0001 ///< brute force MB-type decission mode (slow)
151#define CODEC_FLAG_QSCALE 0x0002 ///< use fixed qscale
152#define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed
153#define CODEC_FLAG_QPEL 0x0010 ///< use qpel MC
154#define CODEC_FLAG_GMC 0x0020 ///< use GMC
155#define CODEC_FLAG_PART 0x0080 ///< use data partitioning
9dbcbd92
MN
156/* parent program gurantees that the input for b-frame containing streams is not written to
157 for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */
8b4c7dbc 158#define CODEC_FLAG_INPUT_PRESERVED 0x0100
64863965
MN
159#define CODEC_FLAG_PASS1 0x0200 ///< use internal 2pass ratecontrol in first pass mode
160#define CODEC_FLAG_PASS2 0x0400 ///< use internal 2pass ratecontrol in second pass mode
161#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< use external huffman table (for mjpeg)
162#define CODEC_FLAG_GRAY 0x2000 ///< only decode/encode grayscale
163#define CODEC_FLAG_EMU_EDGE 0x4000///< dont draw edges
164#define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding
165#define CODEC_FLAG_TRUNCATED 0x00010000 /** input bitstream might be truncated at a random location instead
d7425f59 166 of only at frame boundaries */
64863965
MN
167#define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< normalize adaptive quantization
168#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< use interlaced dct
169#define CODEC_FLAG_LOW_DELAY 0x00080000 ///< force low delay / will fail on b frames
170#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< use alternate scan
171#define CODEC_FLAG_TRELLIS_QUANT 0x00200000 ///< use trellis quantization
172#define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< place global headers in extradata instead of every keyframe
173#define CODEC_FLAG_BITEXACT 0x00800000 ///< use only bitexact stuff (except (i)dct)
21e59552 174/* Fx : Flag for h263+ extra options */
64863965
MN
175#define CODEC_FLAG_H263P_AIC 0x01000000 ///< Advanced intra coding
176#define CODEC_FLAG_H263P_UMV 0x02000000 ///< Unlimited motion vector
21e59552
MN
177/* For advanced prediction mode, we reuse the 4MV flag */
178/* Unsupported options :
179 * Syntax Arithmetic coding (SAC)
180 * Deblocking filter internal loop
181 * Slice structured
182 * Reference Picture Selection
183 * Independant Segment Decoding
184 * Alternative Inter * VLC
185 * Modified Quantization */
186/* /Fx */
bf89e6b1
FB
187/* codec capabilities */
188
64863965 189#define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< decoder can use draw_horiz_band callback
6814a25c
MN
190/**
191 * Codec uses get_buffer() for allocating buffers.
192 * direct rendering method 1
193 */
194#define CODEC_CAP_DR1 0x0002
917e06c8
FB
195/* if 'parse_only' field is true, then avcodec_parse_frame() can be
196 used */
197#define CODEC_CAP_PARSE_ONLY 0x0004
d7425f59 198#define CODEC_CAP_TRUNCATED 0x0008
bf89e6b1 199
492cd3a9 200#define FF_COMMON_FRAME \
b536d0aa
MN
201 /**\
202 * pointer to the picture planes.\
203 * this might be different from the first allocated byte\
204 * - encoding: \
205 * - decoding: \
206 */\
1e491e29
MN
207 uint8_t *data[4];\
208 int linesize[4];\
209 /**\
32db2b1d 210 * pointer to the first allocated byte of the picture. can be used in get_buffer/release_buffer\
1e491e29 211 * this isnt used by lavc unless the default get/release_buffer() is used\
64863965
MN
212 * - encoding: \
213 * - decoding: \
1e491e29
MN
214 */\
215 uint8_t *base[4];\
216 /**\
217 * 1 -> keyframe, 0-> not\
64863965
MN
218 * - encoding: set by lavc\
219 * - decoding: set by lavc\
1e491e29
MN
220 */\
221 int key_frame;\
222\
223 /**\
0da71265 224 * picture type of the frame, see ?_TYPE below.\
64863965
MN
225 * - encoding: set by lavc for coded_picture (and set by user for input)\
226 * - decoding: set by lavc\
1e491e29
MN
227 */\
228 int pict_type;\
229\
230 /**\
231 * presentation timestamp in micro seconds (time when frame should be shown to user)\
232 * if 0 then the frame_rate will be used as reference\
64863965
MN
233 * - encoding: MUST be set by user\
234 * - decoding: set by lavc\
1e491e29 235 */\
be6784dc 236 int64_t pts;\
1e491e29
MN
237\
238 /**\
239 * picture number in bitstream order.\
64863965
MN
240 * - encoding: set by\
241 * - decoding: set by lavc\
1e491e29
MN
242 */\
243 int coded_picture_number;\
244 /**\
1e491e29 245 * picture number in display order.\
64863965
MN
246 * - encoding: set by\
247 * - decoding: set by lavc\
1e491e29
MN
248 */\
249 int display_picture_number;\
250\
251 /**\
252 * quality (between 1 (good) and 31 (bad)) \
64863965
MN
253 * - encoding: set by lavc for coded_picture (and set by user for input)\
254 * - decoding: set by lavc\
1e491e29
MN
255 */\
256 float quality; \
257\
258 /**\
259 * buffer age (1->was last buffer and dint change, 2->..., ...).\
260 * set to something large if the buffer has not been used yet \
64863965
MN
261 * - encoding: unused\
262 * - decoding: MUST be set by get_buffer()\
1e491e29
MN
263 */\
264 int age;\
265\
266 /**\
267 * is this picture used as reference\
64863965
MN
268 * - encoding: unused\
269 * - decoding: set by lavc (before get_buffer() call))\
1e491e29
MN
270 */\
271 int reference;\
272\
273 /**\
274 * QP table\
64863965
MN
275 * - encoding: unused\
276 * - decoding: set by lavc\
1e491e29
MN
277 */\
278 int8_t *qscale_table;\
279 /**\
280 * QP store stride\
64863965
MN
281 * - encoding: unused\
282 * - decoding: set by lavc\
1e491e29
MN
283 */\
284 int qstride;\
285\
286 /**\
287 * mbskip_table[mb]>=1 if MB didnt change\
288 * stride= mb_width = (width+15)>>4\
64863965
MN
289 * - encoding: unused\
290 * - decoding: set by lavc\
1e491e29
MN
291 */\
292 uint8_t *mbskip_table;\
293\
294 /**\
295 * for some private data of the user\
64863965
MN
296 * - encoding: unused\
297 * - decoding: set by user\
1e491e29
MN
298 */\
299 void *opaque;\
140cb663
MN
300\
301 /**\
302 * error\
64863965
MN
303 * - encoding: set by lavc if flags&CODEC_FLAG_PSNR\
304 * - decoding: unused\
140cb663
MN
305 */\
306 uint64_t error[4];\
4e00e76b
MN
307\
308 /**\
309 * type of the buffer (to keep track of who has to dealloc data[*])\
64863965
MN
310 * - encoding: set by the one who allocs it\
311 * - decoding: set by the one who allocs it\
4e00e76b
MN
312 * Note: user allocated (direct rendering) & internal buffers can not coexist currently\
313 */\
314 int type;\
2ec23b6d
MN
315 \
316 /**\
317 * when decoding, this signal how much the picture must be delayed.\
318 * extra_delay = repeat_pict / (2*fps)\
64863965
MN
319 * - encoding: unused\
320 * - decoding: set by lavc\
2ec23b6d 321 */\
0426af31
MN
322 int repeat_pict;\
323 \
324 /**\
325 * \
326 */\
327 int qscale_type;\
2ec23b6d 328
0426af31
MN
329#define FF_QSCALE_TYPE_MPEG1 0
330#define FF_QSCALE_TYPE_MPEG2 1
4e00e76b
MN
331
332#define FF_BUFFER_TYPE_INTERNAL 1
b536d0aa
MN
333#define FF_BUFFER_TYPE_USER 2 ///< Direct rendering buffers
334#define FF_BUFFER_TYPE_SHARED 4 ///< buffer from somewher else, dont dealloc
4e00e76b 335
1e491e29 336
140cb663
MN
337#define FF_I_TYPE 1 // Intra
338#define FF_P_TYPE 2 // Predicted
339#define FF_B_TYPE 3 // Bi-dir predicted
340#define FF_S_TYPE 4 // S(GMC)-VOP MPEG4
0da71265
MN
341#define FF_SI_TYPE 5
342#define FF_SP_TYPE 6
1e491e29 343
0da71265
MN
344/**
345 * Audio Video Frame.
346 */
492cd3a9
MN
347typedef struct AVFrame {
348 FF_COMMON_FRAME
349} AVFrame;
1e491e29 350
14bea432 351#define DEFAULT_FRAME_RATE_BASE 1001000
d33c949c
MN
352
353/**
354 * main external api structure.
355 */
de6d9b64 356typedef struct AVCodecContext {
b71901e6 357 /**
64863965
MN
358 * the average bitrate.
359 * - encoding: set by user. unused for constant quantizer encoding
360 * - decoding: set by lavc. 0 or some bitrate if this info is available in the stream
b71901e6 361 */
de6d9b64 362 int bit_rate;
b71901e6
MN
363
364 /**
64863965 365 * number of bits the bitstream is allowed to diverge from the reference.
b71901e6 366 * the reference can be CBR (for CBR pass1) or VBR (for pass2)
64863965
MN
367 * - encoding: set by user. unused for constant quantizer encoding
368 * - decoding: unused
b71901e6
MN
369 */
370 int bit_rate_tolerance;
371
372 /**
64863965
MN
373 * CODEC_FLAG_*.
374 * - encoding: set by user.
375 * - decoding: set by user.
b71901e6 376 */
de6d9b64 377 int flags;
b71901e6
MN
378
379 /**
380 * some codecs needs additionnal format info. It is stored here
64863965
MN
381 * - encoding: set by user.
382 * - decoding: set by lavc. (FIXME is this ok?)
b71901e6
MN
383 */
384 int sub_id;
385
386 /**
64863965
MN
387 * motion estimation algorithm used for video coding.
388 * - encoding: MUST be set by user.
389 * - decoding: unused
b71901e6
MN
390 */
391 int me_method;
392
393 /**
64863965 394 * some codecs need / can use extra-data like huffman tables.
b71901e6
MN
395 * mjpeg: huffman tables
396 * rv10: additional flags
b704e742 397 * mpeg4: global headers (they can be in the bitstream or here)
64863965
MN
398 * - encoding: set/allocated/freed by lavc.
399 * - decoding: set/allocated/freed by user.
b71901e6 400 */
e84c31dc
A
401 void *extradata;
402 int extradata_size;
403
de6d9b64 404 /* video only */
b71901e6 405 /**
14bea432 406 * frames per sec multiplied by frame_rate_base.
b71901e6 407 * for variable fps this is the precission, so if the timestamps
14bea432 408 * can be specified in msec precssion then this is 1000*frame_rate_base
64863965
MN
409 * - encoding: MUST be set by user
410 * - decoding: set by lavc. 0 or the frame_rate if available
b71901e6
MN
411 */
412 int frame_rate;
14bea432
MN
413
414 /**
64863965
MN
415 * width / height.
416 * - encoding: MUST be set by user.
417 * - decoding: set by user, some codecs might override / change it during playback
b71901e6 418 */
de6d9b64 419 int width, height;
b71901e6 420
2efe097a
MN
421#define FF_ASPECT_SQUARE 1
422#define FF_ASPECT_4_3_625 2
423#define FF_ASPECT_4_3_525 3
424#define FF_ASPECT_16_9_625 4
425#define FF_ASPECT_16_9_525 5
e769f053 426#define FF_ASPECT_EXTENDED 15
b71901e6
MN
427
428 /**
64863965
MN
429 * the number of pictures in a group of pitures, or 0 for intra_only.
430 * - encoding: set by user.
431 * - decoding: unused
b71901e6
MN
432 */
433 int gop_size;
434
435 /**
64863965
MN
436 * pixel format, see PIX_FMT_xxx.
437 * - encoding: unused
438 * - decoding: set by lavc.
b71901e6
MN
439 */
440 enum PixelFormat pix_fmt;
bdfcbbed
MK
441
442 /**
443 * Frame rate emulation. If not zero lower layer (i.e. format handler)
444 * has to read frames at native frame rate.
445 * - encoding: set by user.
446 * - decoding: unused.
447 */
448 int rate_emu;
449
b71901e6
MN
450 /**
451 * if non NULL, 'draw_horiz_band' is called by the libavcodec
452 * decoder to draw an horizontal band. It improve cache usage. Not
453 * all codecs can do that. You must check the codec capabilities
454 * before
64863965
MN
455 * - encoding: unused
456 * - decoding: set by user.
b71901e6 457 */
bf89e6b1 458 void (*draw_horiz_band)(struct AVCodecContext *s,
0c1a9eda 459 uint8_t **src_ptr, int linesize,
bf89e6b1
FB
460 int y, int width, int height);
461
de6d9b64 462 /* audio only */
64863965 463 int sample_rate; ///< samples per sec
de6d9b64 464 int channels;
64863965 465 int sample_fmt; ///< sample format, currenly unused
de6d9b64
FB
466
467 /* the following data should not be initialized */
64863965
MN
468 int frame_size; ///< in samples, initialized when calling 'init'
469 int frame_number; ///< audio or video frame number
470 int real_pict_num; ///< returns the real picture number of previous encoded frame
1e491e29 471
b71901e6 472 /**
b71901e6 473 * number of frames the decoded output will be delayed relative to
64863965
MN
474 * the encoded input.
475 * - encoding: set by lavc.
476 * - decoding: unused
b71901e6
MN
477 */
478 int delay;
1ff662cc 479
64863965
MN
480 /* - encoding parameters */
481 float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
482 float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
b71901e6
MN
483
484 /**
64863965
MN
485 * minimum quantizer.
486 * - encoding: set by user.
487 * - decoding: unused
b71901e6
MN
488 */
489 int qmin;
490
491 /**
64863965
MN
492 * maximum quantizer.
493 * - encoding: set by user.
494 * - decoding: unused
b71901e6
MN
495 */
496 int qmax;
497
498 /**
64863965
MN
499 * maximum quantizer difference etween frames.
500 * - encoding: set by user.
501 * - decoding: unused
b71901e6
MN
502 */
503 int max_qdiff;
504
505 /**
64863965 506 * maximum number of b frames between non b frames.
b71901e6 507 * note: the output will be delayed by max_b_frames+1 relative to the input
64863965
MN
508 * - encoding: set by user.
509 * - decoding: unused
b71901e6
MN
510 */
511 int max_b_frames;
512
513 /**
64863965
MN
514 * qscale factor between ip and b frames.
515 * - encoding: set by user.
516 * - decoding: unused
b71901e6
MN
517 */
518 float b_quant_factor;
519
520 /** obsolete FIXME remove */
521 int rc_strategy;
8b4c7dbc 522 int b_frame_strategy;
9dbcbd92 523
b71901e6 524 /**
64863965
MN
525 * hurry up amount.
526 * - encoding: unused
527 * - decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header
b71901e6
MN
528 */
529 int hurry_up;
2417652e 530
de6d9b64 531 struct AVCodec *codec;
b71901e6 532
de6d9b64
FB
533 void *priv_data;
534
644d98a4 535 /* The following data is for RTP friendly coding */
1f6b6e50 536 /* By now only H.263/H.263+/MPEG4 coder honours this */
644d98a4
J
537 int rtp_mode; /* 1 for activate RTP friendly-mode */
538 /* highers numbers represent more error-prone */
539 /* enviroments, by now just "1" exist */
540
541 int rtp_payload_size; /* The size of the RTP payload, the coder will */
542 /* do it's best to deliver a chunk with size */
543 /* below rtp_payload_size, the chunk will start */
544 /* with a start code on some codecs like H.263 */
545 /* This doesn't take account of any particular */
546 /* headers inside the transmited RTP payload */
81401c1f
J
547
548
549 /* The RTP callcack: This function is called */
550 /* every time the encoder as a packet to send */
551 /* Depends on the encoder if the data starts */
552 /* with a Start Code (it should) H.263 does */
553 void (*rtp_callback)(void *data, int size, int packet_number);
554
098eefe1
MN
555 /* statistics, used for 2-pass encoding */
556 int mv_bits;
557 int header_bits;
558 int i_tex_bits;
559 int p_tex_bits;
560 int i_count;
561 int p_count;
562 int skip_count;
b71901e6
MN
563 int misc_bits;
564
565 /**
64863965
MN
566 * number of bits used for the previously encoded frame.
567 * - encoding: set by lavc
7004ffb3 568 * - decoding: unused
b71901e6 569 */
098eefe1 570 int frame_bits;
7004ffb3 571
b71901e6 572 /**
64863965
MN
573 * private data of the user, can be used to carry app specific stuff.
574 * - encoding: set by user
575 * - decoding: set by user
b71901e6
MN
576 */
577 void *opaque;
578
de6d9b64 579 char codec_name[32];
4a663d80
PG
580 enum CodecType codec_type; /* see CODEC_TYPE_xxx */
581 enum CodecID codec_id; /* see CODEC_ID_xxx */
7004ffb3
MN
582
583 /**
584 * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
585 * this is used to workaround some encoder bugs
586 * - encoding: unused
587 * - decoding: set by user, will be converted to upper case by lavc during init
588 */
589 unsigned int codec_tag;
92ba5ffb 590
b71901e6 591 /**
64863965
MN
592 * workaround bugs in encoders which sometimes cannot be detected automatically.
593 * - encoding: unused
594 * - decoding: set by user
b71901e6
MN
595 */
596 int workaround_bugs;
64863965 597#define FF_BUG_AUTODETECT 1 ///< autodetection
4d2858de
MN
598#define FF_BUG_OLD_MSMPEG4 2
599#define FF_BUG_XVID_ILACE 4
600#define FF_BUG_UMP4 8
601#define FF_BUG_NO_PADDING 16
602#define FF_BUG_AC_VLC 32
03e93d35 603#define FF_BUG_QPEL_CHROMA 64
db794953 604#define FF_BUG_STD_QPEL 128
36df8805 605#define FF_BUG_QPEL_CHROMA2 256
c40c3482 606#define FF_BUG_DIRECT_BLOCKSIZE 512
1c6dcb0f 607#define FF_BUG_EDGE 1024
4d2858de
MN
608//#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100%
609
b71901e6 610 /**
64863965
MN
611 * luma single coeff elimination threshold.
612 * - encoding: set by user
613 * - decoding: unused
b71901e6 614 */
1f6b6e50 615 int luma_elim_threshold;
b71901e6
MN
616
617 /**
64863965
MN
618 * chroma single coeff elimination threshold.
619 * - encoding: set by user
620 * - decoding: unused
b71901e6 621 */
1f6b6e50 622 int chroma_elim_threshold;
b71901e6
MN
623
624 /**
64863965
MN
625 * strictly follow the std (MPEG4, ...).
626 * - encoding: set by user
627 * - decoding: unused
b71901e6
MN
628 */
629 int strict_std_compliance;
630
631 /**
64863965 632 * qscale offset between ip and b frames.
b3a391e8
MN
633 * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
634 * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
64863965
MN
635 * - encoding: set by user.
636 * - decoding: unused
b71901e6
MN
637 */
638 float b_quant_offset;
639
640 /**
ce3bcaed 641 * error resilience higher values will detect more errors but may missdetect
64863965
MN
642 * some more or less valid parts as errors.
643 * - encoding: unused
644 * - decoding: set by user
b71901e6 645 */
1f6b6e50 646 int error_resilience;
ce3bcaed
MN
647#define FF_ER_CAREFULL 1
648#define FF_ER_COMPLIANT 2
649#define FF_ER_AGGRESSIVE 3
650#define FF_ER_VERY_AGGRESSIVE 4
ae72cda6 651
6b72ac63 652 /**
1e491e29
MN
653 * called at the beginning of each frame to get a buffer for it.
654 * if pic.reference is set then the frame will be read later by lavc
64863965
MN
655 * - encoding: unused
656 * - decoding: set by lavc, user can override
b71901e6 657 */
492cd3a9 658 int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
b71901e6
MN
659
660 /**
1e491e29
MN
661 * called to release buffers which where allocated with get_buffer.
662 * a released buffer can be reused in get_buffer()
663 * pic.data[*] must be set to NULL
64863965
MN
664 * - encoding: unused
665 * - decoding: set by lavc, user can override
b71901e6 666 */
492cd3a9 667 void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
0fd90455 668
b71901e6 669 /**
64863965
MN
670 * is 1 if the decoded stream contains b frames, 0 otherwise.
671 * - encoding: unused
672 * - decoding: set by lavc
b71901e6
MN
673 */
674 int has_b_frames;
b71901e6 675
64863965 676 int block_align; ///< used by some WAV based audio codecs
ce980a95 677
64863965 678 int parse_only; /* - decoding only: if true, only parsing is done
917e06c8
FB
679 (function avcodec_parse_frame()). The frame
680 data is returned. Only MPEG codecs support this now. */
ce980a95 681
b71901e6 682 /**
64863965
MN
683 * 0-> h263 quant 1-> mpeg quant.
684 * - encoding: set by user.
685 * - decoding: unused
b71901e6
MN
686 */
687 int mpeg_quant;
ce980a95 688
b71901e6 689 /**
64863965
MN
690 * pass1 encoding statistics output buffer.
691 * - encoding: set by lavc
692 * - decoding: unused
b71901e6 693 */
64863965 694 char *stats_out;
b71901e6
MN
695
696 /**
697 * pass2 encoding statistics input buffer.
698 * concatenated stuff from stats_out of pass1 should be placed here
64863965
MN
699 * - encoding: allocated/set/freed by user
700 * - decoding: unused
b71901e6
MN
701 */
702 char *stats_in;
703
704 /**
64863965 705 * ratecontrol qmin qmax limiting method.
b71901e6 706 * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax
64863965
MN
707 * - encoding: set by user.
708 * - decoding: unused
b71901e6 709 */
ce980a95 710 float rc_qsquish;
b71901e6 711
ce980a95
MN
712 float rc_qmod_amp;
713 int rc_qmod_freq;
b71901e6
MN
714
715 /**
64863965
MN
716 * ratecontrol override, see RcOverride.
717 * - encoding: allocated/set/freed by user.
718 * - decoding: unused
b71901e6 719 */
ce980a95
MN
720 RcOverride *rc_override;
721 int rc_override_count;
b71901e6
MN
722
723 /**
64863965
MN
724 * rate control equation.
725 * - encoding: set by user
726 * - decoding: unused
b71901e6 727 */
ce980a95 728 char *rc_eq;
b71901e6
MN
729
730 /**
64863965
MN
731 * maximum bitrate.
732 * - encoding: set by user.
733 * - decoding: unused
b71901e6 734 */
ce980a95 735 int rc_max_rate;
b71901e6
MN
736
737 /**
64863965
MN
738 * minimum bitrate.
739 * - encoding: set by user.
740 * - decoding: unused
b71901e6 741 */
ce980a95 742 int rc_min_rate;
b71901e6
MN
743
744 /**
64863965
MN
745 * decoder bitstream buffer size.
746 * - encoding: set by user.
747 * - decoding: unused
b71901e6 748 */
ce980a95
MN
749 int rc_buffer_size;
750 float rc_buffer_aggressivity;
b71901e6
MN
751
752 /**
64863965
MN
753 * qscale factor between p and i frames.
754 * - encoding: set by user.
755 * - decoding: unused
b71901e6
MN
756 */
757 float i_quant_factor;
758
759 /**
64863965 760 * qscale offset between p and i frames.
b3a391e8
MN
761 * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
762 * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
64863965
MN
763 * - encoding: set by user.
764 * - decoding: unused
b71901e6
MN
765 */
766 float i_quant_offset;
767
768 /**
64863965
MN
769 * initial complexity for pass1 ratecontrol.
770 * - encoding: set by user.
771 * - decoding: unused
b71901e6 772 */
ce980a95 773 float rc_initial_cplx;
917e06c8 774
b71901e6 775 /**
64863965
MN
776 * dct algorithm, see FF_DCT_* below.
777 * - encoding: set by user
778 * - decoding: unused
b71901e6 779 */
28db7fce 780 int dct_algo;
c7e07931 781#define FF_DCT_AUTO 0
28db7fce 782#define FF_DCT_FASTINT 1
c7e07931
MO
783#define FF_DCT_INT 2
784#define FF_DCT_MMX 3
785#define FF_DCT_MLIB 4
05c4072b 786#define FF_DCT_ALTIVEC 5
c5d309f2
MN
787
788 /**
64863965
MN
789 * luminance masking (0-> disabled).
790 * - encoding: set by user
791 * - decoding: unused
c5d309f2
MN
792 */
793 float lumi_masking;
794
795 /**
64863965
MN
796 * temporary complexity masking (0-> disabled).
797 * - encoding: set by user
798 * - decoding: unused
c5d309f2
MN
799 */
800 float temporal_cplx_masking;
801
802 /**
64863965
MN
803 * spatial complexity masking (0-> disabled).
804 * - encoding: set by user
805 * - decoding: unused
c5d309f2
MN
806 */
807 float spatial_cplx_masking;
808
809 /**
64863965
MN
810 * p block masking (0-> disabled).
811 * - encoding: set by user
812 * - decoding: unused
c5d309f2
MN
813 */
814 float p_masking;
15415af4 815
5e746b99 816 /**
64863965
MN
817 * darkness masking (0-> disabled).
818 * - encoding: set by user
819 * - decoding: unused
5e746b99
MN
820 */
821 float dark_masking;
0c2dd16e 822
3a694b04
NK
823
824 /* for binary compatibility */
825 int unused;
826
0c2dd16e 827 /**
64863965
MN
828 * idct algorithm, see FF_IDCT_* below.
829 * - encoding: set by user
830 * - decoding: set by user
2ad1516a
MN
831 */
832 int idct_algo;
833#define FF_IDCT_AUTO 0
834#define FF_IDCT_INT 1
835#define FF_IDCT_SIMPLE 2
836#define FF_IDCT_SIMPLEMMX 3
837#define FF_IDCT_LIBMPEG2MMX 4
838#define FF_IDCT_PS2 5
839#define FF_IDCT_MLIB 6
840#define FF_IDCT_ARM 7
05c4072b 841#define FF_IDCT_ALTIVEC 8
2ad1516a 842
144f0625 843 /**
64863965
MN
844 * slice count.
845 * - encoding: set by lavc
846 * - decoding: set by user (or 0)
144f0625
MN
847 */
848 int slice_count;
849 /**
64863965
MN
850 * slice offsets in the frame in bytes.
851 * - encoding: set/allocated by lavc
852 * - decoding: set/allocated by user (or NULL)
144f0625
MN
853 */
854 int *slice_offset;
855
4d2858de 856 /**
64863965
MN
857 * error concealment flags.
858 * - encoding: unused
859 * - decoding: set by user
4d2858de
MN
860 */
861 int error_concealment;
862#define FF_EC_GUESS_MVS 1
863#define FF_EC_DEBLOCK 2
864
6b72ac63 865 /**
bec89a84 866 * dsp_mask could be add used to disable unwanted CPU features
8350df97 867 * CPU features (i.e. MMX, SSE. ...)
bec89a84
ZK
868 *
869 * with FORCE flag you may instead enable given CPU features
870 * (Dangerous: usable in case of misdetection, improper usage however will
871 * result into program crash)
872 */
873 unsigned dsp_mask;
874#define FF_MM_FORCE 0x80000000 /* force usage of selected flags (OR) */
875 /* lower 16 bits - CPU features */
876#ifdef HAVE_MMX
877#define FF_MM_MMX 0x0001 /* standard MMX */
878#define FF_MM_3DNOW 0x0004 /* AMD 3DNOW */
879#define FF_MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
880#define FF_MM_SSE 0x0008 /* SSE functions */
881#define FF_MM_SSE2 0x0010 /* PIV SSE2 functions */
882#endif /* HAVE_MMX */
11f18faf
MN
883
884 /**
64863965
MN
885 * bits per sample/pixel from the demuxer (needed for huffyuv).
886 * - encoding: set by lavc
887 * - decoding: set by user
11f18faf
MN
888 */
889 int bits_per_sample;
890
891 /**
64863965
MN
892 * prediction method (needed for huffyuv).
893 * - encoding: set by user
894 * - decoding: unused
11f18faf
MN
895 */
896 int prediction_method;
897#define FF_PRED_LEFT 0
898#define FF_PRED_PLANE 1
899#define FF_PRED_MEDIAN 2
5d3cea3a
MN
900
901 /**
64863965
MN
902 * aspect ratio (0 if unknown).
903 * - encoding: set by user.
904 * - decoding: set by lavc.
5d3cea3a
MN
905 */
906 float aspect_ratio;
1e491e29
MN
907
908 /**
64863965
MN
909 * the picture in the bitstream.
910 * - encoding: set by lavc
911 * - decoding: set by lavc
1e491e29 912 */
492cd3a9 913 AVFrame *coded_frame;
c8c437bc
MN
914
915 /**
64863965
MN
916 * debug.
917 * - encoding: set by user.
918 * - decoding: set by user.
c8c437bc
MN
919 */
920 int debug;
921#define FF_DEBUG_PICT_INFO 1
922#define FF_DEBUG_RC 2
923#define FF_DEBUG_BITSTREAM 4
924#define FF_DEBUG_MB_TYPE 8
925#define FF_DEBUG_QP 16
926#define FF_DEBUG_MV 32
41773b73
MN
927#define FF_DEBUG_VIS_MV 0x00000040
928#define FF_DEBUG_SKIP 0x00000080
929#define FF_DEBUG_STARTCODE 0x00000100
930#define FF_DEBUG_PTS 0x00000200
46b4feec 931#define FF_DEBUG_ER 0x00000400
0da71265 932#define FF_DEBUG_MMCO 0x00000800
140cb663
MN
933
934 /**
64863965
MN
935 * error.
936 * - encoding: set by lavc if flags&CODEC_FLAG_PSNR
937 * - decoding: unused
140cb663
MN
938 */
939 uint64_t error[4];
17a70fde
MN
940
941 /**
64863965
MN
942 * minimum MB quantizer.
943 * - encoding: set by user.
944 * - decoding: unused
17a70fde
MN
945 */
946 int mb_qmin;
947
948 /**
64863965
MN
949 * maximum MB quantizer.
950 * - encoding: set by user.
951 * - decoding: unused
17a70fde
MN
952 */
953 int mb_qmax;
1457ab52
MN
954
955 /**
64863965
MN
956 * motion estimation compare function.
957 * - encoding: set by user.
958 * - decoding: unused
1457ab52
MN
959 */
960 int me_cmp;
961 /**
64863965
MN
962 * subpixel motion estimation compare function.
963 * - encoding: set by user.
964 * - decoding: unused
1457ab52
MN
965 */
966 int me_sub_cmp;
967 /**
64863965
MN
968 * macroblock compare function (not supported yet).
969 * - encoding: set by user.
970 * - decoding: unused
1457ab52
MN
971 */
972 int mb_cmp;
973#define FF_CMP_SAD 0
974#define FF_CMP_SSE 1
975#define FF_CMP_SATD 2
976#define FF_CMP_DCT 3
977#define FF_CMP_PSNR 4
978#define FF_CMP_BIT 5
979#define FF_CMP_RD 6
980#define FF_CMP_ZERO 7
981#define FF_CMP_CHROMA 256
982
983 /**
64863965
MN
984 * ME diamond size & shape.
985 * - encoding: set by user.
986 * - decoding: unused
1457ab52
MN
987 */
988 int dia_size;
b07a5980
MN
989
990 /**
64863965
MN
991 * amount of previous MV predictors (2a+1 x 2a+1 square).
992 * - encoding: set by user.
993 * - decoding: unused
b07a5980
MN
994 */
995 int last_predictor_count;
70ac76c0 996
f5fb6b34 997 /**
64863965
MN
998 * pre pass for motion estimation.
999 * - encoding: set by user.
1000 * - decoding: unused
f5fb6b34
MN
1001 */
1002 int pre_me;
b07a5980 1003
70ac76c0 1004 /**
64863965
MN
1005 * motion estimation pre pass compare function.
1006 * - encoding: set by user.
1007 * - decoding: unused
70ac76c0
MN
1008 */
1009 int me_pre_cmp;
826f429a 1010
70ac76c0 1011 /**
64863965
MN
1012 * ME pre pass diamond size & shape.
1013 * - encoding: set by user.
1014 * - decoding: unused
70ac76c0
MN
1015 */
1016 int pre_dia_size;
1017
826f429a 1018 /**
64863965
MN
1019 * subpel ME quality.
1020 * - encoding: set by user.
1021 * - decoding: unused
826f429a
MN
1022 */
1023 int me_subpel_quality;
1024
a33c7159 1025 /**
64863965 1026 * callback to negotiate the pixelFormat.
a33c7159
MN
1027 * @param fmt is the list of formats which are supported by the codec,
1028 * its terminated by -1 as 0 is a valid format, the formats are ordered by quality
1029 * the first is allways the native one
1030 * @return the choosen format
64863965
MN
1031 * - encoding: unused
1032 * - decoding: set by user, if not set then the native format will always be choosen
a33c7159
MN
1033 */
1034 enum PixelFormat (*get_format)(struct AVCodecContext *s, enum PixelFormat * fmt);
e2f9490e
FB
1035
1036 /**
1037 * DTG active format information (additionnal aspect ratio
1038 * information only used in DVB MPEG2 transport streams). 0 if
1039 * not set.
1040 *
64863965
MN
1041 * - encoding: unused.
1042 * - decoding: set by decoder
e2f9490e
FB
1043 */
1044 int dtg_active_format;
1045#define FF_DTG_AFD_SAME 8
1046#define FF_DTG_AFD_4_3 9
1047#define FF_DTG_AFD_16_9 10
1048#define FF_DTG_AFD_14_9 11
1049#define FF_DTG_AFD_4_3_SP_14_9 13
1050#define FF_DTG_AFD_16_9_SP_14_9 14
1051#define FF_DTG_AFD_SP_4_3 15
1052
ebbcdc9a
MN
1053 /**
1054 * Maximum motion estimation search range in subpel units.
1055 * if 0 then no limit
1056 *
64863965
MN
1057 * - encoding: set by user.
1058 * - decoding: unused.
ebbcdc9a 1059 */
59e0ac8e 1060 int me_range;
ebbcdc9a 1061
65f7062d
MN
1062 /**
1063 * frame_rate_base.
1064 * for variable fps this is 1
1065 * - encoding: set by user.
1066 * - decoding: set by lavc.
1067 * @todo move this after frame_rate
1068 */
65f7062d 1069
1984f635
MN
1070 int frame_rate_base;
1071 /**
1072 * intra quantizer bias.
1073 * - encoding: set by user.
1074 * - decoding: unused
1075 */
1076 int intra_quant_bias;
1077#define FF_DEFAULT_QUANT_BIAS 999999
1078
1079 /**
1080 * inter quantizer bias.
1081 * - encoding: set by user.
1082 * - decoding: unused
1083 */
1084 int inter_quant_bias;
5cd62665
ZK
1085
1086 /**
1087 * color table ID.
1088 * - encoding: unused.
1089 * - decoding: which clrtable should be used for 8bit RGB images
1090 * table have to be stored somewhere FIXME
1091 */
1092 int color_table_id;
1984f635 1093
d90cf87b
MN
1094 /**
1095 * internal_buffer count.
1096 * Dont touch, used by lavc default_get_buffer()
1097 */
1098 int internal_buffer_count;
1099
1100 /**
1101 * internal_buffers.
1102 * Dont touch, used by lavc default_get_buffer()
1103 */
1104 void *internal_buffer;
de6d9b64
FB
1105} AVCodecContext;
1106
97d96aaa 1107
64863965
MN
1108/**
1109 * AVOption.
1110 */
97d96aaa
ZK
1111typedef struct AVOption {
1112 /** options' name */
1113 const char *name; /* if name is NULL, it indicates a link to next */
bec89a84
ZK
1114 /** short English text help or const struct AVOption* subpointer */
1115 const char *help; // const struct AVOption* sub;
97d96aaa
ZK
1116 /** offset to context structure where the parsed value should be stored */
1117 int offset;
1118 /** options' type */
1119 int type;
64863965
MN
1120#define FF_OPT_TYPE_BOOL 1 ///< boolean - true,1,on (or simply presence)
1121#define FF_OPT_TYPE_DOUBLE 2 ///< double
1122#define FF_OPT_TYPE_INT 3 ///< integer
1123#define FF_OPT_TYPE_STRING 4 ///< string (finished with \0)
1124#define FF_OPT_TYPE_MASK 0x1f ///< mask for types - upper bits are various flags
97d96aaa
ZK
1125//#define FF_OPT_TYPE_EXPERT 0x20 // flag for expert option
1126#define FF_OPT_TYPE_FLAG (FF_OPT_TYPE_BOOL | 0x40)
1127#define FF_OPT_TYPE_RCOVERRIDE (FF_OPT_TYPE_STRING | 0x80)
1128 /** min value (min == max -> no limits) */
1129 double min;
1130 /** maximum value for double/int */
1131 double max;
1132 /** default boo [0,1]l/double/int value */
1133 double defval;
1134 /**
1135 * default string value (with optional semicolon delimited extra option-list
1136 * i.e. option1;option2;option3
1137 * defval might select other then first argument as default
1138 */
1139 const char *defstr;
97d96aaa
ZK
1140#define FF_OPT_MAX_DEPTH 10
1141} AVOption;
1142
64863965 1143/**
bec89a84
ZK
1144 * Parse option(s) and sets fields in passed structure
1145 * @param strct structure where the parsed results will be written
1146 * @param list list with AVOptions
1147 * @param opts string with options for parsing
1148 */
1149int avoption_parse(void* strct, const AVOption* list, const char* opts);
1150
1151
1152/**
64863965
MN
1153 * AVCodec.
1154 */
de6d9b64 1155typedef struct AVCodec {
18f77016 1156 const char *name;
5d234974 1157 enum CodecType type;
de6d9b64
FB
1158 int id;
1159 int priv_data_size;
1160 int (*init)(AVCodecContext *);
0c1a9eda 1161 int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
de6d9b64 1162 int (*close)(AVCodecContext *);
0fd90455 1163 int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
0c1a9eda 1164 uint8_t *buf, int buf_size);
bf89e6b1 1165 int capabilities;
97d96aaa 1166 const AVOption *options;
de6d9b64
FB
1167 struct AVCodec *next;
1168} AVCodec;
1169
97d96aaa 1170/**
d7425f59
MN
1171 * four components are given, that's all.
1172 * the last component is alpha
1173 */
de6d9b64 1174typedef struct AVPicture {
0c1a9eda 1175 uint8_t *data[4];
d7425f59 1176 int linesize[4];
de6d9b64
FB
1177} AVPicture;
1178
1179extern AVCodec ac3_encoder;
1180extern AVCodec mp2_encoder;
9d36bdc9 1181extern AVCodec mp3lame_encoder;
81e0d0b4 1182extern AVCodec oggvorbis_encoder;
de6d9b64
FB
1183extern AVCodec mpeg1video_encoder;
1184extern AVCodec h263_encoder;
1185extern AVCodec h263p_encoder;
1186extern AVCodec rv10_encoder;
1187extern AVCodec mjpeg_encoder;
bf89e6b1 1188extern AVCodec mpeg4_encoder;
84afee34
MN
1189extern AVCodec msmpeg4v1_encoder;
1190extern AVCodec msmpeg4v2_encoder;
1191extern AVCodec msmpeg4v3_encoder;
0151a6f5
MN
1192extern AVCodec wmv1_encoder;
1193extern AVCodec wmv2_encoder;
11f18faf 1194extern AVCodec huffyuv_encoder;
0da71265 1195extern AVCodec h264_encoder;
de6d9b64
FB
1196
1197extern AVCodec h263_decoder;
bf89e6b1 1198extern AVCodec mpeg4_decoder;
84afee34
MN
1199extern AVCodec msmpeg4v1_decoder;
1200extern AVCodec msmpeg4v2_decoder;
1201extern AVCodec msmpeg4v3_decoder;
e1a9dbff 1202extern AVCodec wmv1_decoder;
0151a6f5 1203extern AVCodec wmv2_decoder;
de6d9b64
FB
1204extern AVCodec mpeg_decoder;
1205extern AVCodec h263i_decoder;
1206extern AVCodec rv10_decoder;
be8ffec9 1207extern AVCodec svq1_decoder;
8b82a956 1208extern AVCodec svq3_decoder;
020fcc94
FB
1209extern AVCodec dvvideo_decoder;
1210extern AVCodec dvaudio_decoder;
bc8d1857
FB
1211extern AVCodec wmav1_decoder;
1212extern AVCodec wmav2_decoder;
4e66ab3b 1213extern AVCodec mjpeg_decoder;
b135d9fb 1214extern AVCodec mjpegb_decoder;
4b1f4f23 1215extern AVCodec mp2_decoder;
a96b68b7 1216extern AVCodec mp3_decoder;
3f95e843
FR
1217extern AVCodec mace3_decoder;
1218extern AVCodec mace6_decoder;
11f18faf 1219extern AVCodec huffyuv_decoder;
3aca208a 1220extern AVCodec oggvorbis_decoder;
f70f7c6d 1221extern AVCodec cyuv_decoder;
0da71265 1222extern AVCodec h264_decoder;
deabd4fd 1223extern AVCodec indeo3_decoder;
d86053a4 1224extern AVCodec vp3_decoder;
de6d9b64 1225
a96b68b7
FB
1226/* pcm codecs */
1227#define PCM_CODEC(id, name) \
1228extern AVCodec name ## _decoder; \
f11d3f23 1229extern AVCodec name ## _encoder
a96b68b7
FB
1230
1231PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
1232PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
1233PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
1234PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
1235PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
1236PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
1237PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
1238PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
1239
0147f198
FR
1240/* adpcm codecs */
1241
1242PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
1243PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
1244PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
1245
a96b68b7
FB
1246#undef PCM_CODEC
1247
1248/* dummy raw video codec */
63167088
RS
1249extern AVCodec rawvideo_encoder;
1250extern AVCodec rawvideo_decoder;
de6d9b64
FB
1251
1252/* the following codecs use external GPL libs */
de6d9b64
FB
1253extern AVCodec ac3_decoder;
1254
1255/* resample.c */
1256
1257struct ReSampleContext;
1258
1259typedef struct ReSampleContext ReSampleContext;
1260
1261ReSampleContext *audio_resample_init(int output_channels, int input_channels,
1262 int output_rate, int input_rate);
1263int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
1264void audio_resample_close(ReSampleContext *s);
1265
1266/* YUV420 format is assumed ! */
1267
1268struct ImgReSampleContext;
1269
1270typedef struct ImgReSampleContext ImgReSampleContext;
1271
1272ImgReSampleContext *img_resample_init(int output_width, int output_height,
1273 int input_width, int input_height);
ab6d194a
MN
1274
1275ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
1276 int iwidth, int iheight,
1277 int topBand, int bottomBand,
1278 int leftBand, int rightBand);
1279
de6d9b64
FB
1280void img_resample(ImgReSampleContext *s,
1281 AVPicture *output, AVPicture *input);
1282
1283void img_resample_close(ImgReSampleContext *s);
1284
0c1a9eda 1285int avpicture_fill(AVPicture *picture, uint8_t *ptr,
2d1a4094 1286 int pix_fmt, int width, int height);
63167088
RS
1287int avpicture_layout(AVPicture* src, int pix_fmt, int width, int height,
1288 unsigned char *dest, int dest_size);
219b06c6 1289int avpicture_get_size(int pix_fmt, int width, int height);
dab64ebc
FB
1290void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
1291const char *avcodec_get_pix_fmt_name(int pix_fmt);
63167088 1292enum PixelFormat avcodec_get_pix_fmt(const char* name);
219b06c6 1293
fab21997
FB
1294#define FF_LOSS_RESOLUTION 0x0001 /* loss due to resolution change */
1295#define FF_LOSS_DEPTH 0x0002 /* loss due to color depth change */
1296#define FF_LOSS_COLORSPACE 0x0004 /* loss due to color space conversion */
1297#define FF_LOSS_ALPHA 0x0008 /* loss of alpha bits */
1298#define FF_LOSS_COLORQUANT 0x0010 /* loss due to color quantization */
1299#define FF_LOSS_CHROMA 0x0020 /* loss of chroma (e.g. rgb to gray conversion) */
1300
1301int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
1302 int has_alpha);
1303int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
1304 int has_alpha, int *loss_ptr);
1305
0469baf1
FB
1306#define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */
1307#define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */
1308int img_get_alpha_info(AVPicture *src, int pix_fmt, int width, int height);
1309
219b06c6
FB
1310/* convert among pixel formats */
1311int img_convert(AVPicture *dst, int dst_pix_fmt,
1312 AVPicture *src, int pix_fmt,
1313 int width, int height);
1314
1315/* deinterlace a picture */
1316int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
de6d9b64
FB
1317 int pix_fmt, int width, int height);
1318
1319/* external high level API */
1320
1321extern AVCodec *first_avcodec;
1322
156e5023 1323/* returns LIBAVCODEC_VERSION_INT constant */
51a49663 1324unsigned avcodec_version(void);
8bceb6af 1325/* returns LIBAVCODEC_BUILD constant */
51a49663 1326unsigned avcodec_build(void);
de6d9b64
FB
1327void avcodec_init(void);
1328
1329void register_avcodec(AVCodec *format);
1330AVCodec *avcodec_find_encoder(enum CodecID id);
98f3b098 1331AVCodec *avcodec_find_encoder_by_name(const char *name);
de6d9b64
FB
1332AVCodec *avcodec_find_decoder(enum CodecID id);
1333AVCodec *avcodec_find_decoder_by_name(const char *name);
1334void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
1335
1e491e29 1336void avcodec_get_context_defaults(AVCodecContext *s);
7ffbb60e 1337AVCodecContext *avcodec_alloc_context(void);
492cd3a9 1338AVFrame *avcodec_alloc_frame(void);
1e491e29 1339
492cd3a9
MN
1340int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
1341void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
d90cf87b 1342void avcodec_default_free_buffers(AVCodecContext *s);
1e491e29 1343
de6d9b64 1344int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
0c1a9eda 1345int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
de6d9b64 1346 int *frame_size_ptr,
0c1a9eda 1347 uint8_t *buf, int buf_size);
492cd3a9 1348int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
de6d9b64 1349 int *got_picture_ptr,
0c1a9eda
ZK
1350 uint8_t *buf, int buf_size);
1351int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata,
917e06c8 1352 int *data_size_ptr,
0c1a9eda
ZK
1353 uint8_t *buf, int buf_size);
1354int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
de6d9b64 1355 const short *samples);
0c1a9eda 1356int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
492cd3a9 1357 const AVFrame *pict);
de6d9b64
FB
1358
1359int avcodec_close(AVCodecContext *avctx);
1360
1361void avcodec_register_all(void);
a96b68b7 1362
1c2a8c7f
MN
1363void avcodec_flush_buffers(AVCodecContext *avctx);
1364
14bea432
MN
1365/* misc usefull functions */
1366/**
1367 * reduce a fraction.
1368 * this is usefull for framerate calculations
1369 * @param max the maximum allowed for dst_nom & dst_den
1370 * @return 1 if exact, 0 otherwise
1371 */
1372int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max);
1373
1374/**
1375 * rescale a 64bit integer.
1376 * a simple a*b/c isnt possible as it can overflow
1377 */
1378int64_t av_rescale(int64_t a, int b, int c);
628d601b 1379
628d601b 1380
e8f14793
ZK
1381/**
1382 * Interface for 0.5.0 version
1383 *
1384 * do not even think about it's usage for this moment
1385 */
1386
1387typedef struct {
64863965 1388 /// compressed size used from given memory buffer
e8f14793
ZK
1389 int size;
1390 /// I/P/B frame type
1391 int frame_type;
1392} avc_enc_result_t;
1393
1394/**
1395 * Commands
1396 * order can't be changed - once it was defined
1397 */
1398typedef enum {
1399 // general commands
1400 AVC_OPEN_BY_NAME = 0xACA000,
1401 AVC_OPEN_BY_CODEC_ID,
1402 AVC_OPEN_BY_FOURCC,
1403 AVC_CLOSE,
1404
1405 AVC_FLUSH,
1406 // pin - struct { uint8_t* src, uint_t src_size }
1407 // pout - struct { AVPicture* img, consumed_bytes,
1408 AVC_DECODE,
1409 // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size }
1410 // pout - uint_t used_from_dest_size
1411 AVC_ENCODE,
1412
1413 // query/get video commands
1414 AVC_GET_VERSION = 0xACB000,
1415 AVC_GET_WIDTH,
1416 AVC_GET_HEIGHT,
1417 AVC_GET_DELAY,
1418 AVC_GET_QUANT_TABLE,
1419 // ...
1420
1421 // query/get audio commands
1422 AVC_GET_FRAME_SIZE = 0xABC000,
1423
1424 // maybe define some simple structure which
1425 // might be passed to the user - but they can't
1426 // contain any codec specific parts and these
1427 // calls are usualy necessary only few times
1428
1429 // set video commands
1430 AVC_SET_WIDTH = 0xACD000,
1431 AVC_SET_HEIGHT,
1432
1433 // set video encoding commands
1434 AVC_SET_FRAME_RATE = 0xACD800,
1435 AVC_SET_QUALITY,
1436 AVC_SET_HURRY_UP,
1437
1438 // set audio commands
1439 AVC_SET_SAMPLE_RATE = 0xACE000,
1440 AVC_SET_CHANNELS,
1441
1442} avc_cmd_t;
1443
1444/**
1445 * \param handle allocated private structure by libavcodec
1446 * for initialization pass NULL - will be returned pout
1447 * user is supposed to know nothing about its structure
1448 * \param cmd type of operation to be performed
1449 * \param pint input parameter
1450 * \param pout output parameter
1451 *
1452 * \returns command status - eventually for query command it might return
1453 * integer resulting value
1454 */
1455int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout);
1456
544eb99c 1457/* memory */
18f77016
ZK
1458void *av_malloc(unsigned int size);
1459void *av_mallocz(unsigned int size);
8e1e6f31 1460void *av_realloc(void *ptr, unsigned int size);
544eb99c 1461void av_free(void *ptr);
8e1e6f31 1462char *av_strdup(const char *s);
544eb99c
FB
1463void __av_freep(void **ptr);
1464#define av_freep(p) __av_freep((void **)(p))
97d96aaa 1465void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
855ea723
ZK
1466/* for static data only */
1467/* call av_free_static to release all staticaly allocated tables */
628d601b 1468void av_free_static(void);
855ea723
ZK
1469void *__av_mallocz_static(void** location, unsigned int size);
1470#define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s)
544eb99c 1471
02d697aa
ZK
1472#ifdef __cplusplus
1473}
1474#endif
1475
a96b68b7 1476#endif /* AVCODEC_H */