mpeg4 header encoding bugfix
[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"
70ac76c0
MN
8#define LIBAVCODEC_BUILD 4651
9#define LIBAVCODEC_BUILD_STR "4651"
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
4d2858de
MN
523//#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100%
524
b71901e6
MN
525 /**
526 * encoding: set by user
527 * decoding: unused
528 */
1f6b6e50 529 int luma_elim_threshold;
b71901e6
MN
530
531 /**
532 * encoding: set by user
533 * decoding: unused
534 */
1f6b6e50 535 int chroma_elim_threshold;
b71901e6
MN
536
537 /**
538 * strictly follow the std (MPEG4, ...)
539 * encoding: set by user
540 * decoding: unused
541 */
542 int strict_std_compliance;
543
544 /**
545 * qscale offset between ip and b frames
b3a391e8
MN
546 * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
547 * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
b71901e6
MN
548 * encoding: set by user.
549 * decoding: unused
550 */
551 float b_quant_offset;
552
553 /**
ce3bcaed 554 * error resilience higher values will detect more errors but may missdetect
b71901e6
MN
555 * some more or less valid parts as errors
556 * encoding: unused
557 * decoding: set by user
558 */
1f6b6e50 559 int error_resilience;
ce3bcaed
MN
560#define FF_ER_CAREFULL 1
561#define FF_ER_COMPLIANT 2
562#define FF_ER_AGGRESSIVE 3
563#define FF_ER_VERY_AGGRESSIVE 4
ae72cda6 564
6b72ac63 565 /**
1e491e29
MN
566 * called at the beginning of each frame to get a buffer for it.
567 * if pic.reference is set then the frame will be read later by lavc
b71901e6 568 * encoding: unused
1e491e29 569 * decoding: set by lavc, user can override
b71901e6 570 */
492cd3a9 571 int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
b71901e6
MN
572
573 /**
1e491e29
MN
574 * called to release buffers which where allocated with get_buffer.
575 * a released buffer can be reused in get_buffer()
576 * pic.data[*] must be set to NULL
b71901e6 577 * encoding: unused
1e491e29 578 * decoding: set by lavc, user can override
b71901e6 579 */
492cd3a9 580 void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
0fd90455 581
b71901e6
MN
582 /**
583 * is 1 if the decoded stream contains b frames, 0 otherwise
584 * encoding: unused
585 * decoding: set by lavc
586 */
587 int has_b_frames;
b71901e6 588
bc8d1857 589 int block_align; /* used by some WAV based audio codecs */
ce980a95 590
917e06c8
FB
591 int parse_only; /* decoding only: if true, only parsing is done
592 (function avcodec_parse_frame()). The frame
593 data is returned. Only MPEG codecs support this now. */
ce980a95 594
b71901e6
MN
595 /**
596 * 0-> h263 quant 1-> mpeg quant
597 * encoding: set by user.
598 * decoding: unused
599 */
600 int mpeg_quant;
ce980a95 601
b71901e6
MN
602 /**
603 * pass1 encoding statistics output buffer
604 * encoding: set by lavc
605 * decoding: unused
606 */
ce980a95 607 char *stats_out; /* encoding statistics output buffer */
b71901e6
MN
608
609 /**
610 * pass2 encoding statistics input buffer.
611 * concatenated stuff from stats_out of pass1 should be placed here
612 * encoding: allocated/set/freed by user
613 * decoding: unused
614 */
615 char *stats_in;
616
617 /**
618 * ratecontrol qmin qmax limiting method
619 * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax
620 * encoding: set by user.
621 * decoding: unused
622 */
ce980a95 623 float rc_qsquish;
b71901e6 624
ce980a95
MN
625 float rc_qmod_amp;
626 int rc_qmod_freq;
b71901e6
MN
627
628 /**
629 * ratecontrol override, see RcOverride
630 * encoding: allocated/set/freed by user.
631 * decoding: unused
632 */
ce980a95
MN
633 RcOverride *rc_override;
634 int rc_override_count;
b71901e6
MN
635
636 /**
637 * rate control equation
638 * encoding: set by user
639 * decoding: unused
640 */
ce980a95 641 char *rc_eq;
b71901e6
MN
642
643 /**
644 * maximum bitrate
645 * encoding: set by user.
646 * decoding: unused
647 */
ce980a95 648 int rc_max_rate;
b71901e6
MN
649
650 /**
651 * minimum bitrate
652 * encoding: set by user.
653 * decoding: unused
654 */
ce980a95 655 int rc_min_rate;
b71901e6
MN
656
657 /**
658 * decoder bitstream buffer size
659 * encoding: set by user.
660 * decoding: unused
661 */
ce980a95
MN
662 int rc_buffer_size;
663 float rc_buffer_aggressivity;
b71901e6
MN
664
665 /**
666 * qscale factor between p and i frames
667 * encoding: set by user.
668 * decoding: unused
669 */
670 float i_quant_factor;
671
672 /**
673 * qscale offset between p and i frames
b3a391e8
MN
674 * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
675 * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
b71901e6
MN
676 * encoding: set by user.
677 * decoding: unused
678 */
679 float i_quant_offset;
680
681 /**
682 * initial complexity for pass1 ratecontrol
683 * encoding: set by user.
684 * decoding: unused
685 */
ce980a95 686 float rc_initial_cplx;
917e06c8 687
b71901e6 688 /**
b71901e6
MN
689 * dct algorithm, see FF_DCT_* below
690 * encoding: set by user
691 * decoding: unused
692 */
28db7fce 693 int dct_algo;
c7e07931 694#define FF_DCT_AUTO 0
28db7fce 695#define FF_DCT_FASTINT 1
c7e07931
MO
696#define FF_DCT_INT 2
697#define FF_DCT_MMX 3
698#define FF_DCT_MLIB 4
05c4072b 699#define FF_DCT_ALTIVEC 5
c5d309f2
MN
700
701 /**
702 * luminance masking (0-> disabled)
703 * encoding: set by user
704 * decoding: unused
705 */
706 float lumi_masking;
707
708 /**
709 * temporary complexity masking (0-> disabled)
710 * encoding: set by user
711 * decoding: unused
712 */
713 float temporal_cplx_masking;
714
715 /**
716 * spatial complexity masking (0-> disabled)
717 * encoding: set by user
718 * decoding: unused
719 */
720 float spatial_cplx_masking;
721
722 /**
723 * p block masking (0-> disabled)
724 * encoding: set by user
725 * decoding: unused
726 */
727 float p_masking;
15415af4 728
5e746b99
MN
729 /**
730 * darkness masking (0-> disabled)
731 * encoding: set by user
732 * decoding: unused
733 */
734 float dark_masking;
0c2dd16e
MN
735
736 /**
737 * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A')
738 * this is used to workaround some encoder bugs
739 * encoding: unused
202ef8b8 740 * decoding: set by user, will be converted to upper case by lavc during init
0c2dd16e
MN
741 */
742 int fourcc;
5e746b99 743
2ad1516a
MN
744 /**
745 * idct algorithm, see FF_IDCT_* below
746 * encoding: set by user
747 * decoding: set by user
748 */
749 int idct_algo;
750#define FF_IDCT_AUTO 0
751#define FF_IDCT_INT 1
752#define FF_IDCT_SIMPLE 2
753#define FF_IDCT_SIMPLEMMX 3
754#define FF_IDCT_LIBMPEG2MMX 4
755#define FF_IDCT_PS2 5
756#define FF_IDCT_MLIB 6
757#define FF_IDCT_ARM 7
05c4072b 758#define FF_IDCT_ALTIVEC 8
2ad1516a 759
144f0625
MN
760 /**
761 * slice count
762 * encoding: set by lavc
763 * decoding: set by user (or 0)
764 */
765 int slice_count;
766 /**
767 * slice offsets in the frame in bytes
768 * encoding: set/allocated by lavc
769 * decoding: set/allocated by user (or NULL)
770 */
771 int *slice_offset;
772
4d2858de
MN
773 /**
774 * error concealment flags
775 * encoding: unused
776 * decoding: set by user
777 */
778 int error_concealment;
779#define FF_EC_GUESS_MVS 1
780#define FF_EC_DEBLOCK 2
781
6b72ac63 782 /**
8350df97
ZK
783 * dsp_mask could be used to disable unwanted
784 * CPU features (i.e. MMX, SSE. ...)
785 */
786 unsigned dsp_mask;
11f18faf
MN
787
788 /**
789 * bits per sample/pixel from the demuxer (needed for huffyuv)
1e491e29 790 * encoding: set by lavc
11f18faf
MN
791 * decoding: set by user
792 */
793 int bits_per_sample;
794
795 /**
796 * prediction method (needed for huffyuv)
1e491e29 797 * encoding: set by user
11f18faf
MN
798 * decoding: unused
799 */
800 int prediction_method;
801#define FF_PRED_LEFT 0
802#define FF_PRED_PLANE 1
803#define FF_PRED_MEDIAN 2
5d3cea3a
MN
804
805 /**
806 * aspect ratio. (0 if unknown)
807 * encoding: set by user.
808 * decoding: set by lavc.
809 */
810 float aspect_ratio;
1e491e29
MN
811
812 /**
813 * the picture in the bitstream
814 * encoding: set by lavc
815 * decoding: set by lavc
816 */
492cd3a9 817 AVFrame *coded_frame;
c8c437bc
MN
818
819 /**
820 * debug
821 * encoding: set by user.
822 * decoding: set by user.
823 */
824 int debug;
825#define FF_DEBUG_PICT_INFO 1
826#define FF_DEBUG_RC 2
827#define FF_DEBUG_BITSTREAM 4
828#define FF_DEBUG_MB_TYPE 8
829#define FF_DEBUG_QP 16
830#define FF_DEBUG_MV 32
41773b73
MN
831#define FF_DEBUG_VIS_MV 0x00000040
832#define FF_DEBUG_SKIP 0x00000080
833#define FF_DEBUG_STARTCODE 0x00000100
834#define FF_DEBUG_PTS 0x00000200
140cb663
MN
835
836 /**
837 * error
838 * encoding: set by lavc if flags&CODEC_FLAG_PSNR
839 * decoding: unused
840 */
841 uint64_t error[4];
17a70fde
MN
842
843 /**
844 * minimum MB quantizer
845 * encoding: set by user.
846 * decoding: unused
847 */
848 int mb_qmin;
849
850 /**
851 * maximum MB quantizer
852 * encoding: set by user.
853 * decoding: unused
854 */
855 int mb_qmax;
1457ab52
MN
856
857 /**
858 * motion estimation compare function
859 * encoding: set by user.
860 * decoding: unused
861 */
862 int me_cmp;
863 /**
864 * subpixel motion estimation compare function
865 * encoding: set by user.
866 * decoding: unused
867 */
868 int me_sub_cmp;
869 /**
870 * macroblock compare function (not supported yet)
871 * encoding: set by user.
872 * decoding: unused
873 */
874 int mb_cmp;
875#define FF_CMP_SAD 0
876#define FF_CMP_SSE 1
877#define FF_CMP_SATD 2
878#define FF_CMP_DCT 3
879#define FF_CMP_PSNR 4
880#define FF_CMP_BIT 5
881#define FF_CMP_RD 6
882#define FF_CMP_ZERO 7
883#define FF_CMP_CHROMA 256
884
885 /**
b07a5980 886 * ME diamond size & shape
1457ab52
MN
887 * encoding: set by user.
888 * decoding: unused
889 */
890 int dia_size;
b07a5980
MN
891
892 /**
893 * amount of previous MV predictors (2a+1 x 2a+1 square)
894 * encoding: set by user.
895 * decoding: unused
896 */
897 int last_predictor_count;
70ac76c0 898
f5fb6b34
MN
899 /**
900 * pre pass for motion estimation
901 * encoding: set by user.
902 * decoding: unused
903 */
904 int pre_me;
b07a5980 905
70ac76c0
MN
906 /**
907 * motion estimation pre pass compare function
908 * encoding: set by user.
909 * decoding: unused
910 */
911 int me_pre_cmp;
912
913 /**
914 * ME pre pass diamond size & shape
915 * encoding: set by user.
916 * decoding: unused
917 */
918 int pre_dia_size;
919
de6d9b64
FB
920} AVCodecContext;
921
922typedef struct AVCodec {
18f77016 923 const char *name;
de6d9b64
FB
924 int type;
925 int id;
926 int priv_data_size;
927 int (*init)(AVCodecContext *);
928 int (*encode)(AVCodecContext *, UINT8 *buf, int buf_size, void *data);
929 int (*close)(AVCodecContext *);
0fd90455 930 int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
de6d9b64 931 UINT8 *buf, int buf_size);
bf89e6b1 932 int capabilities;
de6d9b64
FB
933 struct AVCodec *next;
934} AVCodec;
935
d7425f59
MN
936/**
937 * four components are given, that's all.
938 * the last component is alpha
939 */
de6d9b64 940typedef struct AVPicture {
d7425f59
MN
941 UINT8 *data[4];
942 int linesize[4];
de6d9b64
FB
943} AVPicture;
944
945extern AVCodec ac3_encoder;
946extern AVCodec mp2_encoder;
9d36bdc9 947extern AVCodec mp3lame_encoder;
81e0d0b4 948extern AVCodec oggvorbis_encoder;
de6d9b64
FB
949extern AVCodec mpeg1video_encoder;
950extern AVCodec h263_encoder;
951extern AVCodec h263p_encoder;
952extern AVCodec rv10_encoder;
953extern AVCodec mjpeg_encoder;
bf89e6b1 954extern AVCodec mpeg4_encoder;
84afee34
MN
955extern AVCodec msmpeg4v1_encoder;
956extern AVCodec msmpeg4v2_encoder;
957extern AVCodec msmpeg4v3_encoder;
0151a6f5
MN
958extern AVCodec wmv1_encoder;
959extern AVCodec wmv2_encoder;
11f18faf 960extern AVCodec huffyuv_encoder;
de6d9b64
FB
961
962extern AVCodec h263_decoder;
bf89e6b1 963extern AVCodec mpeg4_decoder;
84afee34
MN
964extern AVCodec msmpeg4v1_decoder;
965extern AVCodec msmpeg4v2_decoder;
966extern AVCodec msmpeg4v3_decoder;
e1a9dbff 967extern AVCodec wmv1_decoder;
0151a6f5 968extern AVCodec wmv2_decoder;
de6d9b64
FB
969extern AVCodec mpeg_decoder;
970extern AVCodec h263i_decoder;
971extern AVCodec rv10_decoder;
be8ffec9 972extern AVCodec svq1_decoder;
020fcc94
FB
973extern AVCodec dvvideo_decoder;
974extern AVCodec dvaudio_decoder;
bc8d1857
FB
975extern AVCodec wmav1_decoder;
976extern AVCodec wmav2_decoder;
4e66ab3b 977extern AVCodec mjpeg_decoder;
b135d9fb 978extern AVCodec mjpegb_decoder;
4b1f4f23 979extern AVCodec mp2_decoder;
a96b68b7 980extern AVCodec mp3_decoder;
3f95e843
FR
981extern AVCodec mace3_decoder;
982extern AVCodec mace6_decoder;
11f18faf 983extern AVCodec huffyuv_decoder;
3aca208a 984extern AVCodec oggvorbis_decoder;
de6d9b64 985
a96b68b7
FB
986/* pcm codecs */
987#define PCM_CODEC(id, name) \
988extern AVCodec name ## _decoder; \
f11d3f23 989extern AVCodec name ## _encoder
a96b68b7
FB
990
991PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
992PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
993PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
994PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
995PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
996PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
997PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
998PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
999
0147f198
FR
1000/* adpcm codecs */
1001
1002PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
1003PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
1004PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
1005
a96b68b7
FB
1006#undef PCM_CODEC
1007
1008/* dummy raw video codec */
de6d9b64
FB
1009extern AVCodec rawvideo_codec;
1010
1011/* the following codecs use external GPL libs */
de6d9b64
FB
1012extern AVCodec ac3_decoder;
1013
1014/* resample.c */
1015
1016struct ReSampleContext;
1017
1018typedef struct ReSampleContext ReSampleContext;
1019
1020ReSampleContext *audio_resample_init(int output_channels, int input_channels,
1021 int output_rate, int input_rate);
1022int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
1023void audio_resample_close(ReSampleContext *s);
1024
1025/* YUV420 format is assumed ! */
1026
1027struct ImgReSampleContext;
1028
1029typedef struct ImgReSampleContext ImgReSampleContext;
1030
1031ImgReSampleContext *img_resample_init(int output_width, int output_height,
1032 int input_width, int input_height);
ab6d194a
MN
1033
1034ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
1035 int iwidth, int iheight,
1036 int topBand, int bottomBand,
1037 int leftBand, int rightBand);
1038
de6d9b64
FB
1039void img_resample(ImgReSampleContext *s,
1040 AVPicture *output, AVPicture *input);
1041
1042void img_resample_close(ImgReSampleContext *s);
1043
219b06c6
FB
1044void avpicture_fill(AVPicture *picture, UINT8 *ptr,
1045 int pix_fmt, int width, int height);
1046int avpicture_get_size(int pix_fmt, int width, int height);
1e491e29 1047void avcodec_get_chroma_sub_sample(int fmt, int *h_shift, int *v_shift);
219b06c6
FB
1048
1049/* convert among pixel formats */
1050int img_convert(AVPicture *dst, int dst_pix_fmt,
1051 AVPicture *src, int pix_fmt,
1052 int width, int height);
1053
1054/* deinterlace a picture */
1055int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
de6d9b64
FB
1056 int pix_fmt, int width, int height);
1057
1058/* external high level API */
1059
1060extern AVCodec *first_avcodec;
1061
156e5023 1062/* returns LIBAVCODEC_VERSION_INT constant */
51a49663 1063unsigned avcodec_version(void);
8bceb6af 1064/* returns LIBAVCODEC_BUILD constant */
51a49663 1065unsigned avcodec_build(void);
de6d9b64
FB
1066void avcodec_init(void);
1067
51a49663
FB
1068void avcodec_set_bit_exact(void);
1069
de6d9b64
FB
1070void register_avcodec(AVCodec *format);
1071AVCodec *avcodec_find_encoder(enum CodecID id);
98f3b098 1072AVCodec *avcodec_find_encoder_by_name(const char *name);
de6d9b64
FB
1073AVCodec *avcodec_find_decoder(enum CodecID id);
1074AVCodec *avcodec_find_decoder_by_name(const char *name);
1075void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
1076
1e491e29 1077void avcodec_get_context_defaults(AVCodecContext *s);
7ffbb60e 1078AVCodecContext *avcodec_alloc_context(void);
492cd3a9 1079AVFrame *avcodec_alloc_frame(void);
1e491e29 1080
492cd3a9
MN
1081int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
1082void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
1e491e29 1083
de6d9b64
FB
1084int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
1085int avcodec_decode_audio(AVCodecContext *avctx, INT16 *samples,
1086 int *frame_size_ptr,
1087 UINT8 *buf, int buf_size);
492cd3a9 1088int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
de6d9b64
FB
1089 int *got_picture_ptr,
1090 UINT8 *buf, int buf_size);
917e06c8
FB
1091int avcodec_parse_frame(AVCodecContext *avctx, UINT8 **pdata,
1092 int *data_size_ptr,
1093 UINT8 *buf, int buf_size);
de6d9b64
FB
1094int avcodec_encode_audio(AVCodecContext *avctx, UINT8 *buf, int buf_size,
1095 const short *samples);
1096int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size,
492cd3a9 1097 const AVFrame *pict);
de6d9b64
FB
1098
1099int avcodec_close(AVCodecContext *avctx);
1100
1101void avcodec_register_all(void);
a96b68b7 1102
1c2a8c7f
MN
1103void avcodec_flush_buffers(AVCodecContext *avctx);
1104
e8f14793
ZK
1105/**
1106 * Interface for 0.5.0 version
1107 *
1108 * do not even think about it's usage for this moment
1109 */
1110
1111typedef struct {
1112 // compressed size used from given memory buffer
1113 int size;
1114 /// I/P/B frame type
1115 int frame_type;
1116} avc_enc_result_t;
1117
1118/**
1119 * Commands
1120 * order can't be changed - once it was defined
1121 */
1122typedef enum {
1123 // general commands
1124 AVC_OPEN_BY_NAME = 0xACA000,
1125 AVC_OPEN_BY_CODEC_ID,
1126 AVC_OPEN_BY_FOURCC,
1127 AVC_CLOSE,
1128
1129 AVC_FLUSH,
1130 // pin - struct { uint8_t* src, uint_t src_size }
1131 // pout - struct { AVPicture* img, consumed_bytes,
1132 AVC_DECODE,
1133 // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size }
1134 // pout - uint_t used_from_dest_size
1135 AVC_ENCODE,
1136
1137 // query/get video commands
1138 AVC_GET_VERSION = 0xACB000,
1139 AVC_GET_WIDTH,
1140 AVC_GET_HEIGHT,
1141 AVC_GET_DELAY,
1142 AVC_GET_QUANT_TABLE,
1143 // ...
1144
1145 // query/get audio commands
1146 AVC_GET_FRAME_SIZE = 0xABC000,
1147
1148 // maybe define some simple structure which
1149 // might be passed to the user - but they can't
1150 // contain any codec specific parts and these
1151 // calls are usualy necessary only few times
1152
1153 // set video commands
1154 AVC_SET_WIDTH = 0xACD000,
1155 AVC_SET_HEIGHT,
1156
1157 // set video encoding commands
1158 AVC_SET_FRAME_RATE = 0xACD800,
1159 AVC_SET_QUALITY,
1160 AVC_SET_HURRY_UP,
1161
1162 // set audio commands
1163 AVC_SET_SAMPLE_RATE = 0xACE000,
1164 AVC_SET_CHANNELS,
1165
1166} avc_cmd_t;
1167
1168/**
1169 * \param handle allocated private structure by libavcodec
1170 * for initialization pass NULL - will be returned pout
1171 * user is supposed to know nothing about its structure
1172 * \param cmd type of operation to be performed
1173 * \param pint input parameter
1174 * \param pout output parameter
1175 *
1176 * \returns command status - eventually for query command it might return
1177 * integer resulting value
1178 */
1179int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout);
1180
544eb99c 1181/* memory */
18f77016
ZK
1182void *av_malloc(unsigned int size);
1183void *av_mallocz(unsigned int size);
544eb99c
FB
1184void av_free(void *ptr);
1185void __av_freep(void **ptr);
1186#define av_freep(p) __av_freep((void **)(p))
855ea723
ZK
1187/* for static data only */
1188/* call av_free_static to release all staticaly allocated tables */
1189void av_free_static();
1190void *__av_mallocz_static(void** location, unsigned int size);
1191#define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s)
544eb99c 1192
a96b68b7 1193#endif /* AVCODEC_H */