1 #ifdef _WINDOWS
2 typedef signed char  int8_t;
3 typedef signed short int16_t;
4 typedef signed int   int32_t;
5 typedef signed __int64   int64_t;
6 typedef unsigned __int64 uint64_t;
7 #else
8 typedef u_int64_t uint64_t;
9 #endif
10 
11 typedef unsigned char  uint8_t;
12 typedef unsigned short uint16_t;
13 typedef unsigned int   uint32_t;
14 typedef int64_t offset_t;
15 
16 #define MAX_STREAMS 20
17 #define PKT_FLAG_KEY   0x0001
18 #define AV_TIME_BASE 1000000
19 
20 enum PixelFormat {
21     PIX_FMT_YUV420P,   ///< Planar YUV 4:2:0 (1 Cr & Cb sample per 2x2 Y samples)
22     PIX_FMT_YUV422,
23     PIX_FMT_RGB24,     ///< Packed pixel, 3 bytes per pixel, RGBRGB...
24     PIX_FMT_BGR24,     ///< Packed pixel, 3 bytes per pixel, BGRBGR...
25     PIX_FMT_YUV422P,   ///< Planar YUV 4:2:2 (1 Cr & Cb sample per 2x1 Y samples)
26     PIX_FMT_YUV444P,   ///< Planar YUV 4:4:4 (1 Cr & Cb sample per 1x1 Y samples)
27     PIX_FMT_RGB32,     ///< Packed pixel, 4 bytes per pixel, BGRABGRA..., stored in cpu endianness
28     PIX_FMT_YUV410P,   ///< Planar YUV 4:1:0 (1 Cr & Cb sample per 4x4 Y samples)
29     PIX_FMT_YUV411P,   ///< Planar YUV 4:1:1 (1 Cr & Cb sample per 4x1 Y samples)
30     PIX_FMT_RGB565,    ///< always stored in cpu endianness
31     PIX_FMT_RGB555,    ///< always stored in cpu endianness, most significant bit to 1
32     PIX_FMT_GRAY8,
33     PIX_FMT_MONOWHITE, ///< 0 is white
34     PIX_FMT_MONOBLACK, ///< 0 is black
35     PIX_FMT_PAL8,      ///< 8 bit with RGBA palette
36     PIX_FMT_YUVJ420P,  ///< Planar YUV 4:2:0 full scale (jpeg)
37     PIX_FMT_YUVJ422P,  ///< Planar YUV 4:2:2 full scale (jpeg)
38     PIX_FMT_YUVJ444P,  ///< Planar YUV 4:4:4 full scale (jpeg)
39     PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h)
40     PIX_FMT_XVMC_MPEG2_IDCT,
41     PIX_FMT_NB,
42 };
43 
44 enum CodecType {
45     CODEC_TYPE_UNKNOWN = -1,
46     CODEC_TYPE_VIDEO,
47     CODEC_TYPE_AUDIO,
48     CODEC_TYPE_DATA,
49 };
50 
51 
52 enum CodecID {
53     CODEC_ID_NONE,
54     CODEC_ID_MPEG1VIDEO,
55     CODEC_ID_MPEG2VIDEO, /* prefered ID for MPEG Video 1 or 2 decoding */
56     CODEC_ID_MPEG2VIDEO_XVMC,
57     CODEC_ID_H261,
58     CODEC_ID_H263,
59     CODEC_ID_RV10,
60     CODEC_ID_RV20,
61     CODEC_ID_MP2,
62     CODEC_ID_MP3, /* prefered ID for MPEG Audio layer 1, 2 or3 decoding */
63     CODEC_ID_VORBIS,
64     CODEC_ID_AC3,
65     CODEC_ID_MJPEG,
66     CODEC_ID_MJPEGB,
67     CODEC_ID_LJPEG,
68     CODEC_ID_SP5X,
69     CODEC_ID_MPEG4,
70     CODEC_ID_RAWVIDEO,
71     CODEC_ID_MSMPEG4V1,
72     CODEC_ID_MSMPEG4V2,
73     CODEC_ID_MSMPEG4V3,
74     CODEC_ID_WMV1,
75     CODEC_ID_WMV2,
76     CODEC_ID_H263P,
77     CODEC_ID_H263I,
78     CODEC_ID_FLV1,
79     CODEC_ID_SVQ1,
80     CODEC_ID_SVQ3,
81     CODEC_ID_DVVIDEO,
82     CODEC_ID_DVAUDIO,
83     CODEC_ID_WMAV1,
84     CODEC_ID_WMAV2,
85     CODEC_ID_MACE3,
86     CODEC_ID_MACE6,
87     CODEC_ID_HUFFYUV,
88     CODEC_ID_CYUV,
89     CODEC_ID_H264,
90     CODEC_ID_INDEO3,
91     CODEC_ID_VP3,
92     CODEC_ID_THEORA,
93     CODEC_ID_AAC,
94     CODEC_ID_MPEG4AAC,
95     CODEC_ID_ASV1,
96     CODEC_ID_ASV2,
97     CODEC_ID_FFV1,
98     CODEC_ID_4XM,
99     CODEC_ID_VCR1,
100     CODEC_ID_CLJR,
101     CODEC_ID_MDEC,
102     CODEC_ID_ROQ,
103     CODEC_ID_INTERPLAY_VIDEO,
104     CODEC_ID_XAN_WC3,
105     CODEC_ID_XAN_WC4,
106     CODEC_ID_RPZA,
107     CODEC_ID_CINEPAK,
108     CODEC_ID_WS_VQA,
109     CODEC_ID_MSRLE,
110     CODEC_ID_MSVIDEO1,
111     CODEC_ID_IDCIN,
112     CODEC_ID_8BPS,
113     CODEC_ID_SMC,
114     CODEC_ID_FLIC,
115     CODEC_ID_TRUEMOTION1,
116     CODEC_ID_VMDVIDEO,
117     CODEC_ID_VMDAUDIO,
118     CODEC_ID_MSZH,
119     CODEC_ID_ZLIB,
120     CODEC_ID_QTRLE,
121 
122     /* various pcm "codecs" */
123     CODEC_ID_PCM_S16LE,
124     CODEC_ID_PCM_S16BE,
125     CODEC_ID_PCM_U16LE,
126     CODEC_ID_PCM_U16BE,
127     CODEC_ID_PCM_S8,
128     CODEC_ID_PCM_U8,
129     CODEC_ID_PCM_MULAW,
130     CODEC_ID_PCM_ALAW,
131 
132     /* various adpcm codecs */
133     CODEC_ID_ADPCM_IMA_QT,
134     CODEC_ID_ADPCM_IMA_WAV,
135     CODEC_ID_ADPCM_IMA_DK3,
136     CODEC_ID_ADPCM_IMA_DK4,
137     CODEC_ID_ADPCM_IMA_WS,
138     CODEC_ID_ADPCM_IMA_SMJPEG,
139     CODEC_ID_ADPCM_MS,
140     CODEC_ID_ADPCM_4XM,
141     CODEC_ID_ADPCM_XA,
142     CODEC_ID_ADPCM_ADX,
143     CODEC_ID_ADPCM_EA,
144     CODEC_ID_ADPCM_G726,
145 
146 	/* AMR */
147     CODEC_ID_AMR_NB,
148     CODEC_ID_AMR_WB,
149 
150     /* RealAudio codecs*/
151     CODEC_ID_RA_144,
152     CODEC_ID_RA_288,
153 
154     /* various DPCM codecs */
155     CODEC_ID_ROQ_DPCM,
156     CODEC_ID_INTERPLAY_DPCM,
157     CODEC_ID_XAN_DPCM,
158 
159     CODEC_ID_FLAC,
160 
161     CODEC_ID_MPEG2TS, /* _FAKE_ codec to indicate a raw MPEG2 transport
162                          stream (only used by libavformat) */
163 };
164 
165 typedef struct {
166     unsigned char *buffer;
167     int buffer_size;
168     unsigned char *buf_ptr, *buf_end;
169     void *opaque;
170     int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
171     void (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
172     int (*seek)(void *opaque, offset_t offset, int whence);
173     offset_t pos; /* position in the file of the current buffer */
174     int must_flush; /* true if the next seek should flush */
175     int eof_reached; /* true if eof reached */
176     int write_flag;  /* true if open for writing */
177     int is_streamed;
178     int max_packet_size;
179     unsigned long checksum;
180     unsigned char *checksum_ptr;
181     unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
182 } ByteIOContext;
183 
184 
185 typedef struct AVCLASS AVClass;
186 struct AVCLASS {
187     const char* class_name;
188     const char* (*item_name)(void*); /* actually passing a pointer to an AVCodecContext
189 					or AVFormatContext, which begin with an AVClass.
190 					Needed because av_log is in libavcodec and has no visibility
191 					of AVIn/OutputFormat */
192 };
193 
194 #define FF_COMMON_FRAME \
195     /**\
196      * pointer to the picture planes.\
197      * this might be different from the first allocated byte\
198      * - encoding: \
199      * - decoding: \
200      */\
201     uint8_t *data[4];\
202     int linesize[4];\
203     /**\
204      * pointer to the first allocated byte of the picture. can be used in get_buffer/release_buffer\
205      * this isnt used by lavc unless the default get/release_buffer() is used\
206      * - encoding: \
207      * - decoding: \
208      */\
209     uint8_t *base[4];\
210     /**\
211      * 1 -> keyframe, 0-> not\
212      * - encoding: set by lavc\
213      * - decoding: set by lavc\
214      */\
215     int key_frame;\
216 \
217     /**\
218      * picture type of the frame, see ?_TYPE below.\
219      * - encoding: set by lavc for coded_picture (and set by user for input)\
220      * - decoding: set by lavc\
221      */\
222     int pict_type;\
223 \
224     /**\
225      * presentation timestamp in AV_TIME_BASE (=micro seconds currently) (time when frame should be shown to user)\
226      * if AV_NOPTS_VALUE then the frame_rate will be used as reference\
227      * - encoding: MUST be set by user\
228      * - decoding: set by lavc\
229      */\
230     int64_t pts;\
231 \
232     /**\
233      * picture number in bitstream order.\
234      * - encoding: set by\
235      * - decoding: set by lavc\
236      */\
237     int coded_picture_number;\
238     /**\
239      * picture number in display order.\
240      * - encoding: set by\
241      * - decoding: set by lavc\
242      */\
243     int display_picture_number;\
244 \
245     /**\
246      * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \
247      * - encoding: set by lavc for coded_picture (and set by user for input)\
248      * - decoding: set by lavc\
249      */\
250     int quality; \
251 \
252     /**\
253      * buffer age (1->was last buffer and dint change, 2->..., ...).\
254      * set to INT_MAX if the buffer has not been used yet \
255      * - encoding: unused\
256      * - decoding: MUST be set by get_buffer()\
257      */\
258     int age;\
259 \
260     /**\
261      * is this picture used as reference\
262      * - encoding: unused\
263      * - decoding: set by lavc (before get_buffer() call))\
264      */\
265     int reference;\
266 \
267     /**\
268      * QP table\
269      * - encoding: unused\
270      * - decoding: set by lavc\
271      */\
272     int8_t *qscale_table;\
273     /**\
274      * QP store stride\
275      * - encoding: unused\
276      * - decoding: set by lavc\
277      */\
278     int qstride;\
279 \
280     /**\
281      * mbskip_table[mb]>=1 if MB didnt change\
282      * stride= mb_width = (width+15)>>4\
283      * - encoding: unused\
284      * - decoding: set by lavc\
285      */\
286     uint8_t *mbskip_table;\
287 \
288     /**\
289      * Motion vector table\
290      * - encoding: set by user\
291      * - decoding: set by lavc\
292      */\
293     int16_t (*motion_val[2])[2];\
294 \
295     /**\
296      * Macroblock type table\
297      * mb_type_base + mb_width + 2\
298      * - encoding: set by user\
299      * - decoding: set by lavc\
300      */\
301     uint32_t *mb_type;\
302 \
303     /**\
304      * Macroblock size: (0->16x16, 1->8x8, 2-> 4x4, 3-> 2x2)\
305      * - encoding: unused\
306      * - decoding: set by lavc\
307      */\
308     uint8_t motion_subsample_log2;\
309 \
310     /**\
311      * for some private data of the user\
312      * - encoding: unused\
313      * - decoding: set by user\
314      */\
315     void *opaque;\
316 \
317     /**\
318      * error\
319      * - encoding: set by lavc if flags&CODEC_FLAG_PSNR\
320      * - decoding: unused\
321      */\
322     uint64_t error[4];\
323 \
324     /**\
325      * type of the buffer (to keep track of who has to dealloc data[*])\
326      * - encoding: set by the one who allocs it\
327      * - decoding: set by the one who allocs it\
328      * Note: user allocated (direct rendering) & internal buffers can not coexist currently\
329      */\
330     int type;\
331     \
332     /**\
333      * when decoding, this signal how much the picture must be delayed.\
334      * extra_delay = repeat_pict / (2*fps)\
335      * - encoding: unused\
336      * - decoding: set by lavc\
337      */\
338     int repeat_pict;\
339     \
340     /**\
341      * \
342      */\
343     int qscale_type;\
344     \
345     /**\
346      * The content of the picture is interlaced.\
347      * - encoding: set by user\
348      * - decoding: set by lavc (default 0)\
349      */\
350     int interlaced_frame;\
351     \
352     /**\
353      * if the content is interlaced, is top field displayed first.\
354      * - encoding: set by user\
355      * - decoding: set by lavc\
356      */\
357     int top_field_first;\
358     \
359     /**\
360      * Pan scan.\
361      * - encoding: set by user\
362      * - decoding: set by lavc\
363      */\
364     AVPanScan *pan_scan;\
365     \
366     /**\
367      * tell user application that palette has changed from previous frame.\
368      * - encoding: ??? (no palette-enabled encoder yet)\
369      * - decoding: set by lavc (default 0)\
370      */\
371     int palette_has_changed;\
372     \
373     /**\
374      * Codec suggestion on buffer type if != 0\
375      * - encoding: unused\
376      * - decoding: set by lavc (before get_buffer() call))\
377      */\
378     int buffer_hints;\
379 \
380     /**\
381      * DCT coeffitients\
382      * - encoding: unused\
383      * - decoding: set by lavc\
384      */\
385     short *dct_coeff;\
386 \
387     /**\
388      * Motion referece frame index\
389      * - encoding: set by user\
390      * - decoding: set by lavc\
391      */\
392     int8_t *ref_index[2];
393 
394 typedef struct AVPanScan{
395     /**
396      * id.
397      * - encoding: set by user.
398      * - decoding: set by lavc
399      */
400     int id;
401 
402     /**
403      * width and height in 1/16 pel
404      * - encoding: set by user.
405      * - decoding: set by lavc
406      */
407     int width;
408     int height;
409 
410     /**
411      * position of the top left corner in 1/16 pel for up to 3 fields/frames.
412      * - encoding: set by user.
413      * - decoding: set by lavc
414      */
415     int16_t position[3][2];
416 }AVPanScan;
417 
418 typedef struct AVFrame {
419     FF_COMMON_FRAME
420 } AVFrame;
421 
422 typedef struct RcOverride{
423     int start_frame;
424     int end_frame;
425     int qscale; // if this is 0 then quality_factor will be used instead
426     float quality_factor;
427 } RcOverride;
428 
429 typedef struct AVRational{
430     int num;
431     int den;
432 } AVRational;
433 
434 typedef struct AVCodecContext {
435     /**
436      * Info on struct for av_log
437      * - set by avcodec_alloc_context
438      */
439     AVClass *av_class;
440     /**
441      * the average bitrate.
442      * - encoding: set by user. unused for constant quantizer encoding
443      * - decoding: set by lavc. 0 or some bitrate if this info is available in the stream
444      */
445     int bit_rate;
446 
447     /**
448      * number of bits the bitstream is allowed to diverge from the reference.
449      *           the reference can be CBR (for CBR pass1) or VBR (for pass2)
450      * - encoding: set by user. unused for constant quantizer encoding
451      * - decoding: unused
452      */
453     int bit_rate_tolerance;
454 
455     /**
456      * CODEC_FLAG_*.
457      * - encoding: set by user.
458      * - decoding: set by user.
459      */
460     int flags;
461 
462     /**
463      * some codecs needs additionnal format info. It is stored here
464      * - encoding: set by user.
465      * - decoding: set by lavc. (FIXME is this ok?)
466      */
467     int sub_id;
468 
469     /**
470      * motion estimation algorithm used for video coding.
471      * - encoding: MUST be set by user.
472      * - decoding: unused
473      */
474     int me_method;
475 
476     /**
477      * some codecs need / can use extra-data like huffman tables.
478      * mjpeg: huffman tables
479      * rv10: additional flags
480      * mpeg4: global headers (they can be in the bitstream or here)
481      * - encoding: set/allocated/freed by lavc.
482      * - decoding: set/allocated/freed by user.
483      */
484     void *extradata;
485     int extradata_size;
486 
487     /* video only */
488     /**
489      * frames per sec multiplied by frame_rate_base.
490      * for variable fps this is the precission, so if the timestamps
491      * can be specified in msec precssion then this is 1000*frame_rate_base
492      * - encoding: MUST be set by user
493      * - decoding: set by lavc. 0 or the frame_rate if available
494      */
495     int frame_rate;
496 
497     /**
498      * width / height.
499      * - encoding: MUST be set by user.
500      * - decoding: set by user if known, codec should override / dynamically change if needed
501      */
502     int width, height;
503 
504 #define FF_ASPECT_EXTENDED 15
505 
506     /**
507      * the number of pictures in a group of pitures, or 0 for intra_only.
508      * - encoding: set by user.
509      * - decoding: unused
510      */
511     int gop_size;
512 
513     /**
514      * pixel format, see PIX_FMT_xxx.
515      * - encoding: FIXME: used by ffmpeg to decide whether an pix_fmt
516      *                    conversion is in order. This only works for
517      *                    codecs with one supported pix_fmt, we should
518      *                    do something for a generic case as well.
519      * - decoding: set by lavc.
520      */
521     enum PixelFormat pix_fmt;
522 
523     /**
524      * Frame rate emulation. If not zero lower layer (i.e. format handler)
525      * has to read frames at native frame rate.
526      * - encoding: set by user.
527      * - decoding: unused.
528      */
529     int rate_emu;
530 
531     /**
532      * if non NULL, 'draw_horiz_band' is called by the libavcodec
533      * decoder to draw an horizontal band. It improve cache usage. Not
534      * all codecs can do that. You must check the codec capabilities
535      * before
536      * - encoding: unused
537      * - decoding: set by user.
538      * @param height the height of the slice
539      * @param y the y position of the slice
540      * @param type 1->top field, 2->bottom field, 3->frame
541      * @param offset offset into the AVFrame.data from which the slice should be read
542      */
543     void (*draw_horiz_band)(struct AVCodecContext *s,
544 
545                             const AVFrame *src, int offset[4],
546                             int y, int type, int height);
547 
548     /* audio only */
549     int sample_rate; ///< samples per sec
550     int channels;
551     int sample_fmt;  ///< sample format, currenly unused
552 
553     /* the following data should not be initialized */
554     int frame_size;     ///< in samples, initialized when calling 'init'
555     int frame_number;   ///< audio or video frame number
556     int real_pict_num;  ///< returns the real picture number of previous encoded frame
557 
558     /**
559      * number of frames the decoded output will be delayed relative to
560      * the encoded input.
561      * - encoding: set by lavc.
562      * - decoding: unused
563      */
564     int delay;
565 
566     /* - encoding parameters */
567     float qcompress;  ///< amount of qscale change between easy & hard scenes (0.0-1.0)
568     float qblur;      ///< amount of qscale smoothing over time (0.0-1.0)
569 
570     /**
571      * minimum quantizer.
572      * - encoding: set by user.
573      * - decoding: unused
574      */
575     int qmin;
576 
577     /**
578      * maximum quantizer.
579      * - encoding: set by user.
580      * - decoding: unused
581      */
582     int qmax;
583 
584     /**
585      * maximum quantizer difference etween frames.
586      * - encoding: set by user.
587      * - decoding: unused
588      */
589     int max_qdiff;
590 
591     /**
592      * maximum number of b frames between non b frames.
593      * note: the output will be delayed by max_b_frames+1 relative to the input
594      * - encoding: set by user.
595      * - decoding: unused
596      */
597     int max_b_frames;
598 
599     /**
600      * qscale factor between ip and b frames.
601      * - encoding: set by user.
602      * - decoding: unused
603      */
604     float b_quant_factor;
605 
606     /** obsolete FIXME remove */
607     int rc_strategy;
608     int b_frame_strategy;
609 
610     /**
611      * hurry up amount.
612      * - encoding: unused
613      * - decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header
614      */
615     int hurry_up;
616 
617     struct AVCodec *codec;
618 
619     void *priv_data;
620 
621     /* unused, FIXME remove*/
622     int rtp_mode;
623 
624     int rtp_payload_size;   /* The size of the RTP payload, the coder will  */
625                             /* do it's best to deliver a chunk with size    */
626                             /* below rtp_payload_size, the chunk will start */
627                             /* with a start code on some codecs like H.263  */
628                             /* This doesn't take account of any particular  */
629                             /* headers inside the transmited RTP payload    */
630 
631 
632     /* The RTP callcack: This function is called  */
633     /* every time the encoder as a packet to send */
634     /* Depends on the encoder if the data starts  */
635     /* with a Start Code (it should) H.263 does   */
636     void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int packet_number);
637 
638     /* statistics, used for 2-pass encoding */
639     int mv_bits;
640     int header_bits;
641     int i_tex_bits;
642     int p_tex_bits;
643     int i_count;
644     int p_count;
645     int skip_count;
646     int misc_bits;
647 
648     /**
649      * number of bits used for the previously encoded frame.
650      * - encoding: set by lavc
651      * - decoding: unused
652      */
653     int frame_bits;
654 
655     /**
656      * private data of the user, can be used to carry app specific stuff.
657      * - encoding: set by user
658      * - decoding: set by user
659      */
660     void *opaque;
661 
662     char codec_name[32];
663     enum CodecType codec_type; /* see CODEC_TYPE_xxx */
664     enum CodecID codec_id; /* see CODEC_ID_xxx */
665 
666     /**
667      * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
668      * this is used to workaround some encoder bugs
669      * - encoding: set by user, if not then the default based on codec_id will be used
670      * - decoding: set by user, will be converted to upper case by lavc during init
671      */
672     unsigned int codec_tag;
673 
674     /**
675      * workaround bugs in encoders which sometimes cannot be detected automatically.
676      * - encoding: unused
677      * - decoding: set by user
678      */
679     int workaround_bugs;
680 #define FF_BUG_AUTODETECT       1  ///< autodetection
681 #define FF_BUG_OLD_MSMPEG4      2
682 #define FF_BUG_XVID_ILACE       4
683 #define FF_BUG_UMP4             8
684 #define FF_BUG_NO_PADDING       16
685 #define FF_BUG_AMV              32
686 #define FF_BUG_AC_VLC           0  ///< will be removed, libavcodec can now handle these non compliant files by default
687 #define FF_BUG_QPEL_CHROMA      64
688 #define FF_BUG_STD_QPEL         128
689 #define FF_BUG_QPEL_CHROMA2     256
690 #define FF_BUG_DIRECT_BLOCKSIZE 512
691 #define FF_BUG_EDGE             1024
692 #define FF_BUG_HPEL_CHROMA      2048
693 #define FF_BUG_DC_CLIP          4096
694 //#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100%
695 
696     /**
697      * luma single coeff elimination threshold.
698      * - encoding: set by user
699      * - decoding: unused
700      */
701     int luma_elim_threshold;
702 
703     /**
704      * chroma single coeff elimination threshold.
705      * - encoding: set by user
706      * - decoding: unused
707      */
708     int chroma_elim_threshold;
709 
710     /**
711      * strictly follow the std (MPEG4, ...).
712      * - encoding: set by user
713      * - decoding: unused
714      */
715     int strict_std_compliance;
716 
717     /**
718      * qscale offset between ip and b frames.
719      * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
720      * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
721      * - encoding: set by user.
722      * - decoding: unused
723      */
724     float b_quant_offset;
725 
726     /**
727      * error resilience higher values will detect more errors but may missdetect
728      * some more or less valid parts as errors.
729      * - encoding: unused
730      * - decoding: set by user
731      */
732     int error_resilience;
733 #define FF_ER_CAREFULL        1
734 #define FF_ER_COMPLIANT       2
735 #define FF_ER_AGGRESSIVE      3
736 #define FF_ER_VERY_AGGRESSIVE 4
737 
738     /**
739      * called at the beginning of each frame to get a buffer for it.
740      * if pic.reference is set then the frame will be read later by lavc
741      * avcodec_align_dimensions() should be used to find the required width and
742      * height, as they normally need to be rounded up to the next multiple of 16
743      * - encoding: unused
744      * - decoding: set by lavc, user can override
745      */
746     int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
747 
748     /**
749      * called to release buffers which where allocated with get_buffer.
750      * a released buffer can be reused in get_buffer()
751      * pic.data[*] must be set to NULL
752      * - encoding: unused
753      * - decoding: set by lavc, user can override
754      */
755     void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
756 
757     /**
758      * if 1 the stream has a 1 frame delay during decoding.
759      * - encoding: set by lavc
760      * - decoding: set by lavc
761      */
762     int has_b_frames;
763 
764     int block_align; ///< used by some WAV based audio codecs
765 
766     int parse_only; /* - decoding only: if true, only parsing is done
767                        (function avcodec_parse_frame()). The frame
768                        data is returned. Only MPEG codecs support this now. */
769 
770     /**
771      * 0-> h263 quant 1-> mpeg quant.
772      * - encoding: set by user.
773      * - decoding: unused
774      */
775     int mpeg_quant;
776 
777     /**
778      * pass1 encoding statistics output buffer.
779      * - encoding: set by lavc
780      * - decoding: unused
781      */
782     char *stats_out;
783 
784     /**
785      * pass2 encoding statistics input buffer.
786      * concatenated stuff from stats_out of pass1 should be placed here
787      * - encoding: allocated/set/freed by user
788      * - decoding: unused
789      */
790     char *stats_in;
791 
792     /**
793      * ratecontrol qmin qmax limiting method.
794      * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax
795      * - encoding: set by user.
796      * - decoding: unused
797      */
798     float rc_qsquish;
799 
800     float rc_qmod_amp;
801     int rc_qmod_freq;
802 
803     /**
804      * ratecontrol override, see RcOverride.
805      * - encoding: allocated/set/freed by user.
806      * - decoding: unused
807      */
808     RcOverride *rc_override;
809     int rc_override_count;
810 
811     /**
812      * rate control equation.
813      * - encoding: set by user
814      * - decoding: unused
815      */
816     char *rc_eq;
817 
818     /**
819      * maximum bitrate.
820      * - encoding: set by user.
821      * - decoding: unused
822      */
823     int rc_max_rate;
824 
825     /**
826      * minimum bitrate.
827      * - encoding: set by user.
828      * - decoding: unused
829      */
830     int rc_min_rate;
831 
832     /**
833      * decoder bitstream buffer size.
834      * - encoding: set by user.
835      * - decoding: unused
836      */
837     int rc_buffer_size;
838     float rc_buffer_aggressivity;
839 
840     /**
841      * qscale factor between p and i frames.
842      * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
843      * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
844      * - encoding: set by user.
845      * - decoding: unused
846      */
847     float i_quant_factor;
848 
849     /**
850      * qscale offset between p and i frames.
851      * - encoding: set by user.
852      * - decoding: unused
853      */
854     float i_quant_offset;
855 
856     /**
857      * initial complexity for pass1 ratecontrol.
858      * - encoding: set by user.
859      * - decoding: unused
860      */
861     float rc_initial_cplx;
862 
863     /**
864      * dct algorithm, see FF_DCT_* below.
865      * - encoding: set by user
866      * - decoding: unused
867      */
868     int dct_algo;
869 #define FF_DCT_AUTO    0
870 #define FF_DCT_FASTINT 1
871 #define FF_DCT_INT     2
872 #define FF_DCT_MMX     3
873 #define FF_DCT_MLIB    4
874 #define FF_DCT_ALTIVEC 5
875 #define FF_DCT_FAAN    6
876 
877     /**
878      * luminance masking (0-> disabled).
879      * - encoding: set by user
880      * - decoding: unused
881      */
882     float lumi_masking;
883 
884     /**
885      * temporary complexity masking (0-> disabled).
886      * - encoding: set by user
887      * - decoding: unused
888      */
889     float temporal_cplx_masking;
890 
891     /**
892      * spatial complexity masking (0-> disabled).
893      * - encoding: set by user
894      * - decoding: unused
895      */
896     float spatial_cplx_masking;
897 
898     /**
899      * p block masking (0-> disabled).
900      * - encoding: set by user
901      * - decoding: unused
902      */
903     float p_masking;
904 
905     /**
906      * darkness masking (0-> disabled).
907      * - encoding: set by user
908      * - decoding: unused
909      */
910     float dark_masking;
911 
912 
913     /* for binary compatibility */
914     int unused;
915 
916     /**
917      * idct algorithm, see FF_IDCT_* below.
918      * - encoding: set by user
919      * - decoding: set by user
920      */
921     int idct_algo;
922 #define FF_IDCT_AUTO         0
923 #define FF_IDCT_INT          1
924 #define FF_IDCT_SIMPLE       2
925 #define FF_IDCT_SIMPLEMMX    3
926 #define FF_IDCT_LIBMPEG2MMX  4
927 #define FF_IDCT_PS2          5
928 #define FF_IDCT_MLIB         6
929 #define FF_IDCT_ARM          7
930 #define FF_IDCT_ALTIVEC      8
931 #define FF_IDCT_SH4          9
932 #define FF_IDCT_SIMPLEARM    10
933 
934     /**
935      * slice count.
936      * - encoding: set by lavc
937      * - decoding: set by user (or 0)
938      */
939     int slice_count;
940     /**
941      * slice offsets in the frame in bytes.
942      * - encoding: set/allocated by lavc
943      * - decoding: set/allocated by user (or NULL)
944      */
945     int *slice_offset;
946 
947     /**
948      * error concealment flags.
949      * - encoding: unused
950      * - decoding: set by user
951      */
952     int error_concealment;
953 #define FF_EC_GUESS_MVS   1
954 #define FF_EC_DEBLOCK     2
955 
956     /**
957      * dsp_mask could be add used to disable unwanted CPU features
958      * CPU features (i.e. MMX, SSE. ...)
959      *
960      * with FORCE flag you may instead enable given CPU features
961      * (Dangerous: usable in case of misdetection, improper usage however will
962      * result into program crash)
963      */
964     unsigned dsp_mask;
965 #define FF_MM_FORCE	0x80000000 /* force usage of selected flags (OR) */
966     /* lower 16 bits - CPU features */
967 #ifdef HAVE_MMX
968 #define FF_MM_MMX	0x0001 /* standard MMX */
969 #define FF_MM_3DNOW	0x0004 /* AMD 3DNOW */
970 #define FF_MM_MMXEXT	0x0002 /* SSE integer functions or AMD MMX ext */
971 #define FF_MM_SSE	0x0008 /* SSE functions */
972 #define FF_MM_SSE2	0x0010 /* PIV SSE2 functions */
973 #endif /* HAVE_MMX */
974 
975     /**
976      * bits per sample/pixel from the demuxer (needed for huffyuv).
977      * - encoding: set by lavc
978      * - decoding: set by user
979      */
980      int bits_per_sample;
981 
982     /**
983      * prediction method (needed for huffyuv).
984      * - encoding: set by user
985      * - decoding: unused
986      */
987      int prediction_method;
988 #define FF_PRED_LEFT   0
989 #define FF_PRED_PLANE  1
990 #define FF_PRED_MEDIAN 2
991 
992     /**
993      * sample aspect ratio (0 if unknown).
994      * numerator and denominator must be relative prime and smaller then 256 for some video standards
995      * - encoding: set by user.
996      * - decoding: set by lavc.
997      */
998     AVRational sample_aspect_ratio;
999 
1000     /**
1001      * the picture in the bitstream.
1002      * - encoding: set by lavc
1003      * - decoding: set by lavc
1004      */
1005     AVFrame *coded_frame;
1006 
1007     /**
1008      * debug.
1009      * - encoding: set by user.
1010      * - decoding: set by user.
1011      */
1012     int debug;
1013 #define FF_DEBUG_PICT_INFO 1
1014 #define FF_DEBUG_RC        2
1015 #define FF_DEBUG_BITSTREAM 4
1016 #define FF_DEBUG_MB_TYPE   8
1017 #define FF_DEBUG_QP        16
1018 #define FF_DEBUG_MV        32
1019 #define FF_DEBUG_DCT_COEFF 0x00000040
1020 #define FF_DEBUG_SKIP      0x00000080
1021 #define FF_DEBUG_STARTCODE 0x00000100
1022 #define FF_DEBUG_PTS       0x00000200
1023 #define FF_DEBUG_ER        0x00000400
1024 #define FF_DEBUG_MMCO      0x00000800
1025 #define FF_DEBUG_BUGS      0x00001000
1026 #define FF_DEBUG_VIS_QP    0x00002000
1027 #define FF_DEBUG_VIS_MB_TYPE 0x00004000
1028 
1029     /**
1030      * debug.
1031      * - encoding: set by user.
1032      * - decoding: set by user.
1033      */
1034     int debug_mv;
1035 #define FF_DEBUG_VIS_MV_P_FOR  0x00000001 //visualize forward predicted MVs of P frames
1036 #define FF_DEBUG_VIS_MV_B_FOR  0x00000002 //visualize forward predicted MVs of B frames
1037 #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
1038 
1039     /**
1040      * error.
1041      * - encoding: set by lavc if flags&CODEC_FLAG_PSNR
1042      * - decoding: unused
1043      */
1044     uint64_t error[4];
1045 
1046     /**
1047      * minimum MB quantizer.
1048      * - encoding: set by user.
1049      * - decoding: unused
1050      */
1051     int mb_qmin;
1052 
1053     /**
1054      * maximum MB quantizer.
1055      * - encoding: set by user.
1056      * - decoding: unused
1057      */
1058     int mb_qmax;
1059 
1060     /**
1061      * motion estimation compare function.
1062      * - encoding: set by user.
1063      * - decoding: unused
1064      */
1065     int me_cmp;
1066     /**
1067      * subpixel motion estimation compare function.
1068      * - encoding: set by user.
1069      * - decoding: unused
1070      */
1071     int me_sub_cmp;
1072     /**
1073      * macroblock compare function (not supported yet).
1074      * - encoding: set by user.
1075      * - decoding: unused
1076      */
1077     int mb_cmp;
1078     /**
1079      * interlaced dct compare function
1080      * - encoding: set by user.
1081      * - decoding: unused
1082      */
1083     int ildct_cmp;
1084 #define FF_CMP_SAD  0
1085 #define FF_CMP_SSE  1
1086 #define FF_CMP_SATD 2
1087 #define FF_CMP_DCT  3
1088 #define FF_CMP_PSNR 4
1089 #define FF_CMP_BIT  5
1090 #define FF_CMP_RD   6
1091 #define FF_CMP_ZERO 7
1092 #define FF_CMP_VSAD 8
1093 #define FF_CMP_VSSE 9
1094 #define FF_CMP_NSSE 10
1095 #define FF_CMP_CHROMA 256
1096 
1097     /**
1098      * ME diamond size & shape.
1099      * - encoding: set by user.
1100      * - decoding: unused
1101      */
1102     int dia_size;
1103 
1104     /**
1105      * amount of previous MV predictors (2a+1 x 2a+1 square).
1106      * - encoding: set by user.
1107      * - decoding: unused
1108      */
1109     int last_predictor_count;
1110 
1111     /**
1112      * pre pass for motion estimation.
1113      * - encoding: set by user.
1114      * - decoding: unused
1115      */
1116     int pre_me;
1117 
1118     /**
1119      * motion estimation pre pass compare function.
1120      * - encoding: set by user.
1121      * - decoding: unused
1122      */
1123     int me_pre_cmp;
1124 
1125     /**
1126      * ME pre pass diamond size & shape.
1127      * - encoding: set by user.
1128      * - decoding: unused
1129      */
1130     int pre_dia_size;
1131 
1132     /**
1133      * subpel ME quality.
1134      * - encoding: set by user.
1135      * - decoding: unused
1136      */
1137     int me_subpel_quality;
1138 
1139     /**
1140      * callback to negotiate the pixelFormat.
1141      * @param fmt is the list of formats which are supported by the codec,
1142      * its terminated by -1 as 0 is a valid format, the formats are ordered by quality
1143      * the first is allways the native one
1144      * @return the choosen format
1145      * - encoding: unused
1146      * - decoding: set by user, if not set then the native format will always be choosen
1147      */
1148     enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt);
1149 
1150     /**
1151      * DTG active format information (additionnal aspect ratio
1152      * information only used in DVB MPEG2 transport streams). 0 if
1153      * not set.
1154      *
1155      * - encoding: unused.
1156      * - decoding: set by decoder
1157      */
1158     int dtg_active_format;
1159 #define FF_DTG_AFD_SAME         8
1160 #define FF_DTG_AFD_4_3          9
1161 #define FF_DTG_AFD_16_9         10
1162 #define FF_DTG_AFD_14_9         11
1163 #define FF_DTG_AFD_4_3_SP_14_9  13
1164 #define FF_DTG_AFD_16_9_SP_14_9 14
1165 #define FF_DTG_AFD_SP_4_3       15
1166 
1167     /**
1168      * Maximum motion estimation search range in subpel units.
1169      * if 0 then no limit
1170      *
1171      * - encoding: set by user.
1172      * - decoding: unused.
1173      */
1174     int me_range;
1175 
1176     /**
1177      * frame_rate_base.
1178      * for variable fps this is 1
1179      * - encoding: set by user.
1180      * - decoding: set by lavc.
1181      * @todo move this after frame_rate
1182      */
1183 
1184     int frame_rate_base;
1185     /**
1186      * intra quantizer bias.
1187      * - encoding: set by user.
1188      * - decoding: unused
1189      */
1190     int intra_quant_bias;
1191 #define FF_DEFAULT_QUANT_BIAS 999999
1192 
1193     /**
1194      * inter quantizer bias.
1195      * - encoding: set by user.
1196      * - decoding: unused
1197      */
1198     int inter_quant_bias;
1199 
1200     /**
1201      * color table ID.
1202      * - encoding: unused.
1203      * - decoding: which clrtable should be used for 8bit RGB images
1204      *             table have to be stored somewhere FIXME
1205      */
1206     int color_table_id;
1207 
1208     /**
1209      * internal_buffer count.
1210      * Dont touch, used by lavc default_get_buffer()
1211      */
1212     int internal_buffer_count;
1213 
1214     /**
1215      * internal_buffers.
1216      * Dont touch, used by lavc default_get_buffer()
1217      */
1218     void *internal_buffer;
1219 
1220 #define FF_LAMBDA_SHIFT 7
1221 #define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT)
1222 #define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
1223 #define FF_LAMBDA_MAX (256*128-1)
1224 
1225 #define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove
1226     /**
1227      * global quality for codecs which cannot change it per frame.
1228      * this should be proportional to MPEG1/2/4 qscale.
1229      * - encoding: set by user.
1230      * - decoding: unused
1231      */
1232     int global_quality;
1233 
1234 #define FF_CODER_TYPE_VLC   0
1235 #define FF_CODER_TYPE_AC    1
1236     /**
1237      * coder type
1238      * - encoding: set by user.
1239      * - decoding: unused
1240      */
1241     int coder_type;
1242 
1243     /**
1244      * context model
1245      * - encoding: set by user.
1246      * - decoding: unused
1247      */
1248     int context_model;
1249 
1250     /**
1251      * slice flags
1252      * - encoding: unused
1253      * - decoding: set by user.
1254      */
1255     int slice_flags;
1256 #define SLICE_FLAG_CODED_ORDER    0x0001 ///< draw_horiz_band() is called in coded order instead of display
1257 #define SLICE_FLAG_ALLOW_FIELD    0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
1258 #define SLICE_FLAG_ALLOW_PLANE    0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
1259 
1260     /**
1261      * XVideo Motion Acceleration
1262      * - encoding: forbidden
1263      * - decoding: set by decoder
1264      */
1265     int xvmc_acceleration;
1266 
1267     /**
1268      * macroblock decision mode
1269      * - encoding: set by user.
1270      * - decoding: unused
1271      */
1272     int mb_decision;
1273 #define FF_MB_DECISION_SIMPLE 0        ///< uses mb_cmp
1274 #define FF_MB_DECISION_BITS   1        ///< chooses the one which needs the fewest bits
1275 #define FF_MB_DECISION_RD     2        ///< rate distoration
1276 
1277     /**
1278      * custom intra quantization matrix
1279      * - encoding: set by user, can be NULL
1280      * - decoding: set by lavc
1281      */
1282     uint16_t *intra_matrix;
1283 
1284     /**
1285      * custom inter quantization matrix
1286      * - encoding: set by user, can be NULL
1287      * - decoding: set by lavc
1288      */
1289     uint16_t *inter_matrix;
1290 
1291     /**
1292      * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
1293      * this is used to workaround some encoder bugs
1294      * - encoding: unused
1295      * - decoding: set by user, will be converted to upper case by lavc during init
1296      */
1297     unsigned int stream_codec_tag;
1298 
1299     /**
1300      * scene change detection threshold.
1301      * 0 is default, larger means fewer detected scene changes
1302      * - encoding: set by user.
1303      * - decoding: unused
1304      */
1305     int scenechange_threshold;
1306 
1307     /**
1308      * minimum lagrange multipler
1309      * - encoding: set by user.
1310      * - decoding: unused
1311      */
1312     int lmin;
1313 
1314     /**
1315      * maximum lagrange multipler
1316      * - encoding: set by user.
1317      * - decoding: unused
1318      */
1319     int lmax;
1320 
1321     /**
1322      * Palette control structure
1323      * - encoding: ??? (no palette-enabled encoder yet)
1324      * - decoding: set by user.
1325      */
1326     struct AVPaletteControl *palctrl;
1327 
1328     /**
1329      * noise reduction strength
1330      * - encoding: set by user.
1331      * - decoding: unused
1332      */
1333     int noise_reduction;
1334 
1335     /**
1336      * called at the beginning of a frame to get cr buffer for it.
1337      * buffer type (size, hints) must be the same. lavc won't check it.
1338      * lavc will pass previous buffer in pic, function should return
1339      * same buffer or new buffer with old frame "painted" into it.
1340      * if pic.data[0] == NULL must behave like get_buffer().
1341      * - encoding: unused
1342      * - decoding: set by lavc, user can override
1343      */
1344     int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
1345 
1346     /**
1347      * number of bits which should be loaded into the rc buffer before decoding starts
1348      * - encoding: set by user.
1349      * - decoding: unused
1350      */
1351     int rc_initial_buffer_occupancy;
1352 
1353     /**
1354      *
1355      * - encoding: set by user.
1356      * - decoding: unused
1357      */
1358     int inter_threshold;
1359 
1360     /**
1361      * CODEC_FLAG2_*.
1362      * - encoding: set by user.
1363      * - decoding: set by user.
1364      */
1365     int flags2;
1366 
1367     /**
1368      * simulates errors in the bitstream to test error concealment.
1369      * - encoding: set by user.
1370      * - decoding: unused.
1371      */
1372     int error_rate;
1373 
1374     /**
1375      * MP3 antialias algorithm, see FF_AA_* below.
1376      * - encoding: unused
1377      * - decoding: set by user
1378      */
1379     int antialias_algo;
1380 #define FF_AA_AUTO    0
1381 #define FF_AA_FASTINT 1 //not implemented yet
1382 #define FF_AA_INT     2
1383 #define FF_AA_FLOAT   3
1384     /**
1385      * Quantizer noise shaping.
1386      * - encoding: set by user
1387      * - decoding: unused
1388      */
1389     int quantizer_noise_shaping;
1390 
1391     /**
1392      * Thread count.
1393      * is used to decide how many independant tasks should be passed to execute()
1394      * - encoding: set by user
1395      * - decoding: set by user
1396      */
1397     int thread_count;
1398 
1399     /**
1400      * the codec may call this to execute several independant things. it will return only after
1401      * finishing all tasks, the user may replace this with some multithreaded implementation, the
1402      * default implementation will execute the parts serially
1403      * @param count the number of things to execute
1404      * - encoding: set by lavc, user can override
1405      * - decoding: set by lavc, user can override
1406      */
1407     int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void **arg2, int *ret, int count);
1408 
1409     /**
1410      * Thread opaque.
1411      * can be used by execute() to store some per AVCodecContext stuff.
1412      * - encoding: set by execute()
1413      * - decoding: set by execute()
1414      */
1415     void *thread_opaque;
1416 
1417     /**
1418      * Motion estimation threshold. under which no motion estimation is
1419      * performed, but instead the user specified motion vectors are used
1420      *
1421      * - encoding: set by user
1422      * - decoding: unused
1423      */
1424      int me_threshold;
1425 
1426     /**
1427      * Macroblock threshold. under which the user specified macroblock types will be used
1428      * - encoding: set by user
1429      * - decoding: unused
1430      */
1431      int mb_threshold;
1432 
1433     /**
1434      * precision of the intra dc coefficient - 8.
1435      * - encoding: set by user
1436      * - decoding: unused
1437      */
1438      int intra_dc_precision;
1439 
1440     /**
1441      * noise vs. sse weight for the nsse comparsion function.
1442      * - encoding: set by user
1443      * - decoding: unused
1444      */
1445      int nsse_weight;
1446 
1447     /**
1448      * number of macroblock rows at the top which are skiped.
1449      * - encoding: unused
1450      * - decoding: set by user
1451      */
1452      int skip_top;
1453 
1454     /**
1455      * number of macroblock rows at the bottom which are skiped.
1456      * - encoding: unused
1457      * - decoding: set by user
1458      */
1459      int skip_bottom;
1460 } AVCodecContext;
1461 
1462 typedef struct AVFrac {
1463     int64_t val, num, den;
1464 } AVFrac;
1465 
1466 typedef struct AVIndexEntry {
1467     int64_t pos;
1468     int64_t timestamp;
1469 #define AVINDEX_KEYFRAME 0x0001
1470 /* the following 2 flags indicate that the next/prev keyframe is known, and scaning for it isnt needed */
1471     int flags;
1472     int min_distance;         /* min distance between this and the previous keyframe, used to avoid unneeded searching */
1473 } AVIndexEntry;
1474 
1475 typedef struct AVStream {
1476     int index;    /* stream index in AVFormatContext */
1477     int id;       /* format specific stream id */
1478     AVCodecContext codec; /* codec context */
1479     int r_frame_rate;     /* real frame rate of the stream */
1480     int r_frame_rate_base;/* real frame rate base of the stream */
1481     void *priv_data;
1482     /* internal data used in av_find_stream_info() */
1483     int64_t codec_info_duration;
1484     int codec_info_nb_frames;
1485     /* encoding: PTS generation when outputing stream */
1486     AVFrac pts;
1487     AVRational time_base;
1488     int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
1489     /* ffmpeg.c private use */
1490     int stream_copy; /* if TRUE, just copy stream */
1491     /* quality, as it has been removed from AVCodecContext and put in AVVideoFrame
1492      * MN:dunno if thats the right place, for it */
1493     float quality;
1494     /* decoding: position of the first frame of the component, in
1495        AV_TIME_BASE fractional seconds. */
1496     int64_t start_time;
1497     /* decoding: duration of the stream, in AV_TIME_BASE fractional
1498        seconds. */
1499     int64_t duration;
1500 
1501     /* av_read_frame() support */
1502     int need_parsing;
1503     struct AVCodecParserContext *parser;
1504 
1505     int64_t cur_dts;
1506     int last_IP_duration;
1507     int64_t last_IP_pts;
1508     /* av_seek_frame() support */
1509     AVIndexEntry *index_entries; /* only used if the format does not
1510                                     support seeking natively */
1511     int nb_index_entries;
1512     int index_entries_allocated_size;
1513 } AVStream;
1514 
1515 typedef struct AVPacket {
1516     int64_t pts; /* presentation time stamp in AV_TIME_BASE units (or
1517                     pts_den units in muxers or demuxers) */
1518     int64_t dts; /* decompression time stamp in AV_TIME_BASE units (or
1519                     pts_den units in muxers or demuxers) */
1520     uint8_t *data;
1521     int   size;
1522     int   stream_index;
1523     int   flags;
1524     int   duration; /* presentation duration (0 if not available) */
1525     void  (*destruct)(struct AVPacket *);
1526     void  *priv;
1527 } AVPacket;
1528 
1529 typedef struct AVFormatContext {
1530     AVClass *av_class; /* set by av_alloc_format_context */
1531     /* can only be iformat or oformat, not both at the same time */
1532     struct AVInputFormat *iformat;
1533     struct AVOutputFormat *oformat;
1534     void *priv_data;
1535     ByteIOContext pb;
1536     int nb_streams;
1537     AVStream *streams[MAX_STREAMS];
1538     char filename[1024]; /* input or output filename */
1539     /* stream info */
1540     int64_t timestamp;
1541     char title[512];
1542     char author[512];
1543     char copyright[512];
1544     char comment[512];
1545     char album[512];
1546     int year;  /* ID3 year, 0 if none */
1547     int track; /* track number, 0 if none */
1548     char genre[32]; /* ID3 genre */
1549 
1550     int ctx_flags; /* format specific flags, see AVFMTCTX_xx */
1551     /* private data for pts handling (do not modify directly) */
1552     /* This buffer is only needed when packets were already buffered but
1553        not decoded, for example to get the codec parameters in mpeg
1554        streams */
1555     struct AVPacketList *packet_buffer;
1556 
1557     /* decoding: position of the first frame of the component, in
1558        AV_TIME_BASE fractional seconds. NEVER set this value directly:
1559        it is deduced from the AVStream values.  */
1560     int64_t start_time;
1561     /* decoding: duration of the stream, in AV_TIME_BASE fractional
1562        seconds. NEVER set this value directly: it is deduced from the
1563        AVStream values.  */
1564     int64_t duration;
1565     /* decoding: total file size. 0 if unknown */
1566     int64_t file_size;
1567     /* decoding: total stream bitrate in bit/s, 0 if not
1568        available. Never set it directly if the file_size and the
1569        duration are known as ffmpeg can compute it automatically. */
1570     int bit_rate;
1571 
1572     /* av_read_frame() support */
1573     AVStream *cur_st;
1574     const uint8_t *cur_ptr;
1575     int cur_len;
1576     AVPacket cur_pkt;
1577 
1578     /* av_seek_frame() support */
1579     int64_t data_offset; /* offset of the first packet */
1580     int index_built;
1581 } AVFormatContext;
1582 
1583 typedef struct AVOption {
1584     /** options' name */
1585     const char *name; /* if name is NULL, it indicates a link to next */
1586     /** short English text help or const struct AVOption* subpointer */
1587     const char *help; //	const struct AVOption* sub;
1588     /** offset to context structure where the parsed value should be stored */
1589     int offset;
1590     /** options' type */
1591     int type;
1592 #define FF_OPT_TYPE_BOOL 1      ///< boolean - true,1,on  (or simply presence)
1593 #define FF_OPT_TYPE_DOUBLE 2    ///< double
1594 #define FF_OPT_TYPE_INT 3       ///< integer
1595 #define FF_OPT_TYPE_STRING 4    ///< string (finished with \0)
1596 #define FF_OPT_TYPE_MASK 0x1f	///< mask for types - upper bits are various flags
1597 //#define FF_OPT_TYPE_EXPERT 0x20 // flag for expert option
1598 #define FF_OPT_TYPE_FLAG (FF_OPT_TYPE_BOOL | 0x40)
1599 #define FF_OPT_TYPE_RCOVERRIDE (FF_OPT_TYPE_STRING | 0x80)
1600     /** min value  (min == max   ->  no limits) */
1601     double min;
1602     /** maximum value for double/int */
1603     double max;
1604     /** default boo [0,1]l/double/int value */
1605     double defval;
1606     /**
1607      * default string value (with optional semicolon delimited extra option-list
1608      * i.e.   option1;option2;option3
1609      * defval might select other then first argument as default
1610      */
1611     const char *defstr;
1612 #define FF_OPT_MAX_DEPTH 10
1613 } AVOption;
1614 
1615 
1616 typedef struct AVCodec {
1617     const char *name;
1618     enum CodecType type;
1619     int id;
1620     int priv_data_size;
1621     int (*init)(AVCodecContext *);
1622     int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
1623     int (*close)(AVCodecContext *);
1624     int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
1625                   uint8_t *buf, int buf_size);
1626     int capabilities;
1627     const AVOption *options;
1628     struct AVCodec *next;
1629     void (*flush)(AVCodecContext *);
1630     const AVRational *supported_framerates; ///array of supported framerates, or NULL if any, array is terminated by {0,0}
1631     const enum PixelFormat *pix_fmts;       ///array of supported pixel formats, or NULL if unknown, array is terminanted by -1
1632 } AVCodec;
1633 
1634 typedef struct AVProbeData {
1635     const char *filename;
1636     unsigned char *buf;
1637     int buf_size;
1638 } AVProbeData;
1639 
1640 typedef struct AVFormatParameters {
1641     int frame_rate;
1642     int frame_rate_base;
1643     int sample_rate;
1644     int channels;
1645     int width;
1646     int height;
1647     enum PixelFormat pix_fmt;
1648     struct AVImageFormat *image_format;
1649     int channel; /* used to select dv channel */
1650     const char *device; /* video4linux, audio or DV device */
1651     const char *standard; /* tv standard, NTSC, PAL, SECAM */
1652     int mpeg2ts_raw:1;  /* force raw MPEG2 transport stream output, if possible */
1653     int mpeg2ts_compute_pcr:1; /* compute exact PCR for each transport
1654                                   stream packet (only meaningful if
1655                                   mpeg2ts_raw is TRUE */
1656     int initial_pause:1;       /* do not begin to play the stream
1657                                   immediately (RTSP only) */
1658 } AVFormatParameters;
1659 
1660 typedef struct AVInputFormat {
1661     const char *name;
1662     const char *long_name;
1663     /* size of private data so that it can be allocated in the wrapper */
1664     int priv_data_size;
1665     /* tell if a given file has a chance of being parsing by this format */
1666     int (*read_probe)(AVProbeData *);
1667     /* read the format header and initialize the AVFormatContext
1668        structure. Return 0 if OK. 'ap' if non NULL contains
1669        additionnal paramters. Only used in raw format right
1670        now. 'av_new_stream' should be called to create new streams.  */
1671     int (*read_header)(struct AVFormatContext *,
1672                        AVFormatParameters *ap);
1673     /* read one packet and put it in 'pkt'. pts and flags are also
1674        set. 'av_new_stream' can be called only if the flag
1675        AVFMTCTX_NOHEADER is used. */
1676     int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
1677     /* close the stream. The AVFormatContext and AVStreams are not
1678        freed by this function */
1679     int (*read_close)(struct AVFormatContext *);
1680     /* seek at or before a given timestamp (given in AV_TIME_BASE
1681        units) relative to the frames in stream component stream_index */
1682     int (*read_seek)(struct AVFormatContext *,
1683                      int stream_index, int64_t timestamp);
1684     /**
1685      * gets the next timestamp in AV_TIME_BASE units.
1686      */
1687     int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
1688                               int64_t *pos, int64_t pos_limit);
1689     /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
1690     int flags;
1691     /* if extensions are defined, then no probe is done. You should
1692        usually not use extension format guessing because it is not
1693        reliable enough */
1694     const char *extensions;
1695     /* general purpose read only value that the format can use */
1696     int value;
1697 
1698     /* start/resume playing - only meaningful if using a network based format
1699        (RTSP) */
1700     int (*read_play)(struct AVFormatContext *);
1701 
1702     /* pause playing - only meaningful if using a network based format
1703        (RTSP) */
1704     int (*read_pause)(struct AVFormatContext *);
1705 
1706     /* private fields */
1707     struct AVInputFormat *next;
1708 } AVInputFormat;
1709 
1710 
1711 typedef struct AVPicture {
1712     uint8_t *data[4];
1713     int linesize[4];       ///< number of bytes per line
1714 } AVPicture;
1715 
1716 
av_free_packet(AVPacket * pkt)1717 static inline void av_free_packet(AVPacket *pkt)
1718 {
1719     if (pkt && pkt->destruct) {
1720 	    pkt->destruct(pkt);
1721     }
1722 }
1723