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