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