]> git.sesse.net Git - ffmpeg/blob - libavcodec/avcodec.h
avcodec: add a new codec_id for CRYO APC IMA ADPCM.
[ffmpeg] / libavcodec / avcodec.h
1 /*
2  * copyright (c) 2001 Fabrice Bellard
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #ifndef AVCODEC_AVCODEC_H
22 #define AVCODEC_AVCODEC_H
23
24 /**
25  * @file
26  * external API header
27  */
28
29 #include <errno.h>
30 #include "libavutil/samplefmt.h"
31 #include "libavutil/avutil.h"
32 #include "libavutil/cpu.h"
33 #include "libavutil/dict.h"
34 #include "libavutil/log.h"
35 #include "libavutil/pixfmt.h"
36 #include "libavutil/rational.h"
37
38 #include "libavcodec/version.h"
39 /**
40  * @defgroup libavc Encoding/Decoding Library
41  * @{
42  *
43  * @defgroup lavc_decoding Decoding
44  * @{
45  * @}
46  *
47  * @defgroup lavc_encoding Encoding
48  * @{
49  * @}
50  *
51  * @defgroup lavc_codec Codecs
52  * @{
53  * @defgroup lavc_codec_native Native Codecs
54  * @{
55  * @}
56  * @defgroup lavc_codec_wrappers External library wrappers
57  * @{
58  * @}
59  * @defgroup lavc_codec_hwaccel Hardware Accelerators bridge
60  * @{
61  * @}
62  * @}
63  * @defgroup lavc_internal Internal
64  * @{
65  * @}
66  * @}
67  *
68  */
69
70
71 /**
72  * Identify the syntax and semantics of the bitstream.
73  * The principle is roughly:
74  * Two decoders with the same ID can decode the same streams.
75  * Two encoders with the same ID can encode compatible streams.
76  * There may be slight deviations from the principle due to implementation
77  * details.
78  *
79  * If you add a codec ID to this list, add it so that
80  * 1. no value of a existing codec ID changes (that would break ABI),
81  * 2. it is as close as possible to similar codecs.
82  */
83 enum CodecID {
84     CODEC_ID_NONE,
85
86     /* video codecs */
87     CODEC_ID_MPEG1VIDEO,
88     CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding
89     CODEC_ID_MPEG2VIDEO_XVMC,
90     CODEC_ID_H261,
91     CODEC_ID_H263,
92     CODEC_ID_RV10,
93     CODEC_ID_RV20,
94     CODEC_ID_MJPEG,
95     CODEC_ID_MJPEGB,
96     CODEC_ID_LJPEG,
97     CODEC_ID_SP5X,
98     CODEC_ID_JPEGLS,
99     CODEC_ID_MPEG4,
100     CODEC_ID_RAWVIDEO,
101     CODEC_ID_MSMPEG4V1,
102     CODEC_ID_MSMPEG4V2,
103     CODEC_ID_MSMPEG4V3,
104     CODEC_ID_WMV1,
105     CODEC_ID_WMV2,
106     CODEC_ID_H263P,
107     CODEC_ID_H263I,
108     CODEC_ID_FLV1,
109     CODEC_ID_SVQ1,
110     CODEC_ID_SVQ3,
111     CODEC_ID_DVVIDEO,
112     CODEC_ID_HUFFYUV,
113     CODEC_ID_CYUV,
114     CODEC_ID_H264,
115     CODEC_ID_INDEO3,
116     CODEC_ID_VP3,
117     CODEC_ID_THEORA,
118     CODEC_ID_ASV1,
119     CODEC_ID_ASV2,
120     CODEC_ID_FFV1,
121     CODEC_ID_4XM,
122     CODEC_ID_VCR1,
123     CODEC_ID_CLJR,
124     CODEC_ID_MDEC,
125     CODEC_ID_ROQ,
126     CODEC_ID_INTERPLAY_VIDEO,
127     CODEC_ID_XAN_WC3,
128     CODEC_ID_XAN_WC4,
129     CODEC_ID_RPZA,
130     CODEC_ID_CINEPAK,
131     CODEC_ID_WS_VQA,
132     CODEC_ID_MSRLE,
133     CODEC_ID_MSVIDEO1,
134     CODEC_ID_IDCIN,
135     CODEC_ID_8BPS,
136     CODEC_ID_SMC,
137     CODEC_ID_FLIC,
138     CODEC_ID_TRUEMOTION1,
139     CODEC_ID_VMDVIDEO,
140     CODEC_ID_MSZH,
141     CODEC_ID_ZLIB,
142     CODEC_ID_QTRLE,
143     CODEC_ID_SNOW,
144     CODEC_ID_TSCC,
145     CODEC_ID_ULTI,
146     CODEC_ID_QDRAW,
147     CODEC_ID_VIXL,
148     CODEC_ID_QPEG,
149     CODEC_ID_PNG,
150     CODEC_ID_PPM,
151     CODEC_ID_PBM,
152     CODEC_ID_PGM,
153     CODEC_ID_PGMYUV,
154     CODEC_ID_PAM,
155     CODEC_ID_FFVHUFF,
156     CODEC_ID_RV30,
157     CODEC_ID_RV40,
158     CODEC_ID_VC1,
159     CODEC_ID_WMV3,
160     CODEC_ID_LOCO,
161     CODEC_ID_WNV1,
162     CODEC_ID_AASC,
163     CODEC_ID_INDEO2,
164     CODEC_ID_FRAPS,
165     CODEC_ID_TRUEMOTION2,
166     CODEC_ID_BMP,
167     CODEC_ID_CSCD,
168     CODEC_ID_MMVIDEO,
169     CODEC_ID_ZMBV,
170     CODEC_ID_AVS,
171     CODEC_ID_SMACKVIDEO,
172     CODEC_ID_NUV,
173     CODEC_ID_KMVC,
174     CODEC_ID_FLASHSV,
175     CODEC_ID_CAVS,
176     CODEC_ID_JPEG2000,
177     CODEC_ID_VMNC,
178     CODEC_ID_VP5,
179     CODEC_ID_VP6,
180     CODEC_ID_VP6F,
181     CODEC_ID_TARGA,
182     CODEC_ID_DSICINVIDEO,
183     CODEC_ID_TIERTEXSEQVIDEO,
184     CODEC_ID_TIFF,
185     CODEC_ID_GIF,
186 #if LIBAVCODEC_VERSION_MAJOR == 53
187     CODEC_ID_FFH264,
188 #endif
189     CODEC_ID_DXA,
190     CODEC_ID_DNXHD,
191     CODEC_ID_THP,
192     CODEC_ID_SGI,
193     CODEC_ID_C93,
194     CODEC_ID_BETHSOFTVID,
195     CODEC_ID_PTX,
196     CODEC_ID_TXD,
197     CODEC_ID_VP6A,
198     CODEC_ID_AMV,
199     CODEC_ID_VB,
200     CODEC_ID_PCX,
201     CODEC_ID_SUNRAST,
202     CODEC_ID_INDEO4,
203     CODEC_ID_INDEO5,
204     CODEC_ID_MIMIC,
205     CODEC_ID_RL2,
206 #if LIBAVCODEC_VERSION_MAJOR == 53
207     CODEC_ID_8SVX_EXP,
208     CODEC_ID_8SVX_FIB,
209 #endif
210     CODEC_ID_ESCAPE124,
211     CODEC_ID_DIRAC,
212     CODEC_ID_BFI,
213     CODEC_ID_CMV,
214     CODEC_ID_MOTIONPIXELS,
215     CODEC_ID_TGV,
216     CODEC_ID_TGQ,
217     CODEC_ID_TQI,
218     CODEC_ID_AURA,
219     CODEC_ID_AURA2,
220     CODEC_ID_V210X,
221     CODEC_ID_TMV,
222     CODEC_ID_V210,
223     CODEC_ID_DPX,
224     CODEC_ID_MAD,
225     CODEC_ID_FRWU,
226     CODEC_ID_FLASHSV2,
227     CODEC_ID_CDGRAPHICS,
228     CODEC_ID_R210,
229     CODEC_ID_ANM,
230     CODEC_ID_BINKVIDEO,
231     CODEC_ID_IFF_ILBM,
232     CODEC_ID_IFF_BYTERUN1,
233     CODEC_ID_KGV1,
234     CODEC_ID_YOP,
235     CODEC_ID_VP8,
236     CODEC_ID_PICTOR,
237     CODEC_ID_ANSI,
238     CODEC_ID_A64_MULTI,
239     CODEC_ID_A64_MULTI5,
240     CODEC_ID_R10K,
241     CODEC_ID_MXPEG,
242     CODEC_ID_LAGARITH,
243     CODEC_ID_PRORES,
244     CODEC_ID_JV,
245     CODEC_ID_DFA,
246     CODEC_ID_WMV3IMAGE,
247     CODEC_ID_VC1IMAGE,
248 #if LIBAVCODEC_VERSION_MAJOR == 53
249     CODEC_ID_G723_1,
250     CODEC_ID_G729,
251 #endif
252     CODEC_ID_UTVIDEO,
253     CODEC_ID_BMV_VIDEO,
254     CODEC_ID_VBLE,
255     CODEC_ID_DXTORY,
256     CODEC_ID_V410,
257     CODEC_ID_XWD,
258
259     /* various PCM "codecs" */
260     CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at the start of audio codecs
261     CODEC_ID_PCM_S16LE = 0x10000,
262     CODEC_ID_PCM_S16BE,
263     CODEC_ID_PCM_U16LE,
264     CODEC_ID_PCM_U16BE,
265     CODEC_ID_PCM_S8,
266     CODEC_ID_PCM_U8,
267     CODEC_ID_PCM_MULAW,
268     CODEC_ID_PCM_ALAW,
269     CODEC_ID_PCM_S32LE,
270     CODEC_ID_PCM_S32BE,
271     CODEC_ID_PCM_U32LE,
272     CODEC_ID_PCM_U32BE,
273     CODEC_ID_PCM_S24LE,
274     CODEC_ID_PCM_S24BE,
275     CODEC_ID_PCM_U24LE,
276     CODEC_ID_PCM_U24BE,
277     CODEC_ID_PCM_S24DAUD,
278     CODEC_ID_PCM_ZORK,
279     CODEC_ID_PCM_S16LE_PLANAR,
280     CODEC_ID_PCM_DVD,
281     CODEC_ID_PCM_F32BE,
282     CODEC_ID_PCM_F32LE,
283     CODEC_ID_PCM_F64BE,
284     CODEC_ID_PCM_F64LE,
285     CODEC_ID_PCM_BLURAY,
286     CODEC_ID_PCM_LXF,
287     CODEC_ID_S302M,
288     CODEC_ID_PCM_S8_PLANAR,
289
290     /* various ADPCM codecs */
291     CODEC_ID_ADPCM_IMA_QT = 0x11000,
292     CODEC_ID_ADPCM_IMA_WAV,
293     CODEC_ID_ADPCM_IMA_DK3,
294     CODEC_ID_ADPCM_IMA_DK4,
295     CODEC_ID_ADPCM_IMA_WS,
296     CODEC_ID_ADPCM_IMA_SMJPEG,
297     CODEC_ID_ADPCM_MS,
298     CODEC_ID_ADPCM_4XM,
299     CODEC_ID_ADPCM_XA,
300     CODEC_ID_ADPCM_ADX,
301     CODEC_ID_ADPCM_EA,
302     CODEC_ID_ADPCM_G726,
303     CODEC_ID_ADPCM_CT,
304     CODEC_ID_ADPCM_SWF,
305     CODEC_ID_ADPCM_YAMAHA,
306     CODEC_ID_ADPCM_SBPRO_4,
307     CODEC_ID_ADPCM_SBPRO_3,
308     CODEC_ID_ADPCM_SBPRO_2,
309     CODEC_ID_ADPCM_THP,
310     CODEC_ID_ADPCM_IMA_AMV,
311     CODEC_ID_ADPCM_EA_R1,
312     CODEC_ID_ADPCM_EA_R3,
313     CODEC_ID_ADPCM_EA_R2,
314     CODEC_ID_ADPCM_IMA_EA_SEAD,
315     CODEC_ID_ADPCM_IMA_EA_EACS,
316     CODEC_ID_ADPCM_EA_XAS,
317     CODEC_ID_ADPCM_EA_MAXIS_XA,
318     CODEC_ID_ADPCM_IMA_ISS,
319     CODEC_ID_ADPCM_G722,
320     CODEC_ID_ADPCM_IMA_APC,
321
322     /* AMR */
323     CODEC_ID_AMR_NB = 0x12000,
324     CODEC_ID_AMR_WB,
325
326     /* RealAudio codecs*/
327     CODEC_ID_RA_144 = 0x13000,
328     CODEC_ID_RA_288,
329
330     /* various DPCM codecs */
331     CODEC_ID_ROQ_DPCM = 0x14000,
332     CODEC_ID_INTERPLAY_DPCM,
333     CODEC_ID_XAN_DPCM,
334     CODEC_ID_SOL_DPCM,
335
336     /* audio codecs */
337     CODEC_ID_MP2 = 0x15000,
338     CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
339     CODEC_ID_AAC,
340     CODEC_ID_AC3,
341     CODEC_ID_DTS,
342     CODEC_ID_VORBIS,
343     CODEC_ID_DVAUDIO,
344     CODEC_ID_WMAV1,
345     CODEC_ID_WMAV2,
346     CODEC_ID_MACE3,
347     CODEC_ID_MACE6,
348     CODEC_ID_VMDAUDIO,
349 #if LIBAVCODEC_VERSION_MAJOR == 53
350     CODEC_ID_SONIC,
351     CODEC_ID_SONIC_LS,
352 #endif
353     CODEC_ID_FLAC,
354     CODEC_ID_MP3ADU,
355     CODEC_ID_MP3ON4,
356     CODEC_ID_SHORTEN,
357     CODEC_ID_ALAC,
358     CODEC_ID_WESTWOOD_SND1,
359     CODEC_ID_GSM, ///< as in Berlin toast format
360     CODEC_ID_QDM2,
361     CODEC_ID_COOK,
362     CODEC_ID_TRUESPEECH,
363     CODEC_ID_TTA,
364     CODEC_ID_SMACKAUDIO,
365     CODEC_ID_QCELP,
366     CODEC_ID_WAVPACK,
367     CODEC_ID_DSICINAUDIO,
368     CODEC_ID_IMC,
369     CODEC_ID_MUSEPACK7,
370     CODEC_ID_MLP,
371     CODEC_ID_GSM_MS, /* as found in WAV */
372     CODEC_ID_ATRAC3,
373     CODEC_ID_VOXWARE,
374     CODEC_ID_APE,
375     CODEC_ID_NELLYMOSER,
376     CODEC_ID_MUSEPACK8,
377     CODEC_ID_SPEEX,
378     CODEC_ID_WMAVOICE,
379     CODEC_ID_WMAPRO,
380     CODEC_ID_WMALOSSLESS,
381     CODEC_ID_ATRAC3P,
382     CODEC_ID_EAC3,
383     CODEC_ID_SIPR,
384     CODEC_ID_MP1,
385     CODEC_ID_TWINVQ,
386     CODEC_ID_TRUEHD,
387     CODEC_ID_MP4ALS,
388     CODEC_ID_ATRAC1,
389     CODEC_ID_BINKAUDIO_RDFT,
390     CODEC_ID_BINKAUDIO_DCT,
391     CODEC_ID_AAC_LATM,
392     CODEC_ID_QDMC,
393     CODEC_ID_CELT,
394 #if LIBAVCODEC_VERSION_MAJOR > 53
395     CODEC_ID_G723_1,
396     CODEC_ID_G729,
397     CODEC_ID_8SVX_EXP,
398     CODEC_ID_8SVX_FIB,
399 #endif
400     CODEC_ID_BMV_AUDIO,
401
402     /* subtitle codecs */
403     CODEC_ID_FIRST_SUBTITLE = 0x17000,          ///< A dummy ID pointing at the start of subtitle codecs.
404     CODEC_ID_DVD_SUBTITLE = 0x17000,
405     CODEC_ID_DVB_SUBTITLE,
406     CODEC_ID_TEXT,  ///< raw UTF-8 text
407     CODEC_ID_XSUB,
408     CODEC_ID_SSA,
409     CODEC_ID_MOV_TEXT,
410     CODEC_ID_HDMV_PGS_SUBTITLE,
411     CODEC_ID_DVB_TELETEXT,
412     CODEC_ID_SRT,
413
414     /* other specific kind of codecs (generally used for attachments) */
415     CODEC_ID_FIRST_UNKNOWN = 0x18000,           ///< A dummy ID pointing at the start of various fake codecs.
416     CODEC_ID_TTF = 0x18000,
417
418     CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it
419
420     CODEC_ID_MPEG2TS = 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
421                                 * stream (only used by libavformat) */
422     CODEC_ID_MPEG4SYSTEMS = 0x20001, /**< _FAKE_ codec to indicate a MPEG-4 Systems
423                                 * stream (only used by libavformat) */
424     CODEC_ID_FFMETADATA = 0x21000,   ///< Dummy codec for streams containing only metadata information.
425 };
426
427 #if FF_API_OLD_SAMPLE_FMT
428 #define SampleFormat AVSampleFormat
429
430 #define SAMPLE_FMT_NONE AV_SAMPLE_FMT_NONE
431 #define SAMPLE_FMT_U8   AV_SAMPLE_FMT_U8
432 #define SAMPLE_FMT_S16  AV_SAMPLE_FMT_S16
433 #define SAMPLE_FMT_S32  AV_SAMPLE_FMT_S32
434 #define SAMPLE_FMT_FLT  AV_SAMPLE_FMT_FLT
435 #define SAMPLE_FMT_DBL  AV_SAMPLE_FMT_DBL
436 #define SAMPLE_FMT_NB   AV_SAMPLE_FMT_NB
437 #endif
438
439 #if FF_API_OLD_AUDIOCONVERT
440 #include "libavutil/audioconvert.h"
441
442 /* Audio channel masks */
443 #define CH_FRONT_LEFT            AV_CH_FRONT_LEFT
444 #define CH_FRONT_RIGHT           AV_CH_FRONT_RIGHT
445 #define CH_FRONT_CENTER          AV_CH_FRONT_CENTER
446 #define CH_LOW_FREQUENCY         AV_CH_LOW_FREQUENCY
447 #define CH_BACK_LEFT             AV_CH_BACK_LEFT
448 #define CH_BACK_RIGHT            AV_CH_BACK_RIGHT
449 #define CH_FRONT_LEFT_OF_CENTER  AV_CH_FRONT_LEFT_OF_CENTER
450 #define CH_FRONT_RIGHT_OF_CENTER AV_CH_FRONT_RIGHT_OF_CENTER
451 #define CH_BACK_CENTER           AV_CH_BACK_CENTER
452 #define CH_SIDE_LEFT             AV_CH_SIDE_LEFT
453 #define CH_SIDE_RIGHT            AV_CH_SIDE_RIGHT
454 #define CH_TOP_CENTER            AV_CH_TOP_CENTER
455 #define CH_TOP_FRONT_LEFT        AV_CH_TOP_FRONT_LEFT
456 #define CH_TOP_FRONT_CENTER      AV_CH_TOP_FRONT_CENTER
457 #define CH_TOP_FRONT_RIGHT       AV_CH_TOP_FRONT_RIGHT
458 #define CH_TOP_BACK_LEFT         AV_CH_TOP_BACK_LEFT
459 #define CH_TOP_BACK_CENTER       AV_CH_TOP_BACK_CENTER
460 #define CH_TOP_BACK_RIGHT        AV_CH_TOP_BACK_RIGHT
461 #define CH_STEREO_LEFT           AV_CH_STEREO_LEFT
462 #define CH_STEREO_RIGHT          AV_CH_STEREO_RIGHT
463
464 /** Channel mask value used for AVCodecContext.request_channel_layout
465     to indicate that the user requests the channel order of the decoder output
466     to be the native codec channel order. */
467 #define CH_LAYOUT_NATIVE         AV_CH_LAYOUT_NATIVE
468
469 /* Audio channel convenience macros */
470 #define CH_LAYOUT_MONO           AV_CH_LAYOUT_MONO
471 #define CH_LAYOUT_STEREO         AV_CH_LAYOUT_STEREO
472 #define CH_LAYOUT_2_1            AV_CH_LAYOUT_2_1
473 #define CH_LAYOUT_SURROUND       AV_CH_LAYOUT_SURROUND
474 #define CH_LAYOUT_4POINT0        AV_CH_LAYOUT_4POINT0
475 #define CH_LAYOUT_2_2            AV_CH_LAYOUT_2_2
476 #define CH_LAYOUT_QUAD           AV_CH_LAYOUT_QUAD
477 #define CH_LAYOUT_5POINT0        AV_CH_LAYOUT_5POINT0
478 #define CH_LAYOUT_5POINT1        AV_CH_LAYOUT_5POINT1
479 #define CH_LAYOUT_5POINT0_BACK   AV_CH_LAYOUT_5POINT0_BACK
480 #define CH_LAYOUT_5POINT1_BACK   AV_CH_LAYOUT_5POINT1_BACK
481 #define CH_LAYOUT_7POINT0        AV_CH_LAYOUT_7POINT0
482 #define CH_LAYOUT_7POINT1        AV_CH_LAYOUT_7POINT1
483 #define CH_LAYOUT_7POINT1_WIDE   AV_CH_LAYOUT_7POINT1_WIDE
484 #define CH_LAYOUT_STEREO_DOWNMIX AV_CH_LAYOUT_STEREO_DOWNMIX
485 #endif
486
487 #if FF_API_OLD_DECODE_AUDIO
488 /* in bytes */
489 #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
490 #endif
491
492 /**
493  * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
494  * This is mainly needed because some optimized bitstream readers read
495  * 32 or 64 bit at once and could read over the end.<br>
496  * Note: If the first 23 bits of the additional bytes are not 0, then damaged
497  * MPEG bitstreams could cause overread and segfault.
498  */
499 #define FF_INPUT_BUFFER_PADDING_SIZE 8
500
501 /**
502  * minimum encoding buffer size
503  * Used to avoid some checks during header writing.
504  */
505 #define FF_MIN_BUFFER_SIZE 16384
506
507
508 /**
509  * motion estimation type.
510  */
511 enum Motion_Est_ID {
512     ME_ZERO = 1,    ///< no search, that is use 0,0 vector whenever one is needed
513     ME_FULL,
514     ME_LOG,
515     ME_PHODS,
516     ME_EPZS,        ///< enhanced predictive zonal search
517     ME_X1,          ///< reserved for experiments
518     ME_HEX,         ///< hexagon based search
519     ME_UMH,         ///< uneven multi-hexagon search
520     ME_ITER,        ///< iterative search
521     ME_TESA,        ///< transformed exhaustive search algorithm
522 };
523
524 enum AVDiscard{
525     /* We leave some space between them for extensions (drop some
526      * keyframes for intra-only or drop just some bidir frames). */
527     AVDISCARD_NONE   =-16, ///< discard nothing
528     AVDISCARD_DEFAULT=  0, ///< discard useless packets like 0 size packets in avi
529     AVDISCARD_NONREF =  8, ///< discard all non reference
530     AVDISCARD_BIDIR  = 16, ///< discard all bidirectional frames
531     AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
532     AVDISCARD_ALL    = 48, ///< discard all
533 };
534
535 enum AVColorPrimaries{
536     AVCOL_PRI_BT709      =1, ///< also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
537     AVCOL_PRI_UNSPECIFIED=2,
538     AVCOL_PRI_BT470M     =4,
539     AVCOL_PRI_BT470BG    =5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
540     AVCOL_PRI_SMPTE170M  =6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
541     AVCOL_PRI_SMPTE240M  =7, ///< functionally identical to above
542     AVCOL_PRI_FILM       =8,
543     AVCOL_PRI_NB           , ///< Not part of ABI
544 };
545
546 enum AVColorTransferCharacteristic{
547     AVCOL_TRC_BT709      =1, ///< also ITU-R BT1361
548     AVCOL_TRC_UNSPECIFIED=2,
549     AVCOL_TRC_GAMMA22    =4, ///< also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
550     AVCOL_TRC_GAMMA28    =5, ///< also ITU-R BT470BG
551     AVCOL_TRC_NB           , ///< Not part of ABI
552 };
553
554 enum AVColorSpace{
555     AVCOL_SPC_RGB        =0,
556     AVCOL_SPC_BT709      =1, ///< also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
557     AVCOL_SPC_UNSPECIFIED=2,
558     AVCOL_SPC_FCC        =4,
559     AVCOL_SPC_BT470BG    =5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
560     AVCOL_SPC_SMPTE170M  =6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
561     AVCOL_SPC_SMPTE240M  =7,
562     AVCOL_SPC_NB           , ///< Not part of ABI
563 };
564
565 enum AVColorRange{
566     AVCOL_RANGE_UNSPECIFIED=0,
567     AVCOL_RANGE_MPEG       =1, ///< the normal 219*2^(n-8) "MPEG" YUV ranges
568     AVCOL_RANGE_JPEG       =2, ///< the normal     2^n-1   "JPEG" YUV ranges
569     AVCOL_RANGE_NB           , ///< Not part of ABI
570 };
571
572 /**
573  *  X   X      3 4 X      X are luma samples,
574  *             1 2        1-6 are possible chroma positions
575  *  X   X      5 6 X      0 is undefined/unknown position
576  */
577 enum AVChromaLocation{
578     AVCHROMA_LOC_UNSPECIFIED=0,
579     AVCHROMA_LOC_LEFT       =1, ///< mpeg2/4, h264 default
580     AVCHROMA_LOC_CENTER     =2, ///< mpeg1, jpeg, h263
581     AVCHROMA_LOC_TOPLEFT    =3, ///< DV
582     AVCHROMA_LOC_TOP        =4,
583     AVCHROMA_LOC_BOTTOMLEFT =5,
584     AVCHROMA_LOC_BOTTOM     =6,
585     AVCHROMA_LOC_NB           , ///< Not part of ABI
586 };
587
588 #if FF_API_FLAC_GLOBAL_OPTS
589 /**
590  * LPC analysis type
591  */
592 enum AVLPCType {
593     AV_LPC_TYPE_DEFAULT     = -1, ///< use the codec default LPC type
594     AV_LPC_TYPE_NONE        =  0, ///< do not use LPC prediction or use all zero coefficients
595     AV_LPC_TYPE_FIXED       =  1, ///< fixed LPC coefficients
596     AV_LPC_TYPE_LEVINSON    =  2, ///< Levinson-Durbin recursion
597     AV_LPC_TYPE_CHOLESKY    =  3, ///< Cholesky factorization
598     AV_LPC_TYPE_NB              , ///< Not part of ABI
599 };
600 #endif
601
602 enum AVAudioServiceType {
603     AV_AUDIO_SERVICE_TYPE_MAIN              = 0,
604     AV_AUDIO_SERVICE_TYPE_EFFECTS           = 1,
605     AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED = 2,
606     AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED  = 3,
607     AV_AUDIO_SERVICE_TYPE_DIALOGUE          = 4,
608     AV_AUDIO_SERVICE_TYPE_COMMENTARY        = 5,
609     AV_AUDIO_SERVICE_TYPE_EMERGENCY         = 6,
610     AV_AUDIO_SERVICE_TYPE_VOICE_OVER        = 7,
611     AV_AUDIO_SERVICE_TYPE_KARAOKE           = 8,
612     AV_AUDIO_SERVICE_TYPE_NB                   , ///< Not part of ABI
613 };
614
615 typedef struct RcOverride{
616     int start_frame;
617     int end_frame;
618     int qscale; // If this is 0 then quality_factor will be used instead.
619     float quality_factor;
620 } RcOverride;
621
622 #define FF_MAX_B_FRAMES 16
623
624 /* encoding support
625    These flags can be passed in AVCodecContext.flags before initialization.
626    Note: Not everything is supported yet.
627 */
628
629 #define CODEC_FLAG_QSCALE 0x0002  ///< Use fixed qscale.
630 #define CODEC_FLAG_4MV    0x0004  ///< 4 MV per MB allowed / advanced prediction for H.263.
631 #define CODEC_FLAG_QPEL   0x0010  ///< Use qpel MC.
632 #define CODEC_FLAG_GMC    0x0020  ///< Use GMC.
633 #define CODEC_FLAG_MV0    0x0040  ///< Always try a MB with MV=<0,0>.
634 /**
635  * The parent program guarantees that the input for B-frames containing
636  * streams is not written to for at least s->max_b_frames+1 frames, if
637  * this is not set the input will be copied.
638  */
639 #define CODEC_FLAG_INPUT_PRESERVED 0x0100
640 #define CODEC_FLAG_PASS1           0x0200   ///< Use internal 2pass ratecontrol in first pass mode.
641 #define CODEC_FLAG_PASS2           0x0400   ///< Use internal 2pass ratecontrol in second pass mode.
642 #define CODEC_FLAG_GRAY            0x2000   ///< Only decode/encode grayscale.
643 #define CODEC_FLAG_EMU_EDGE        0x4000   ///< Don't draw edges.
644 #define CODEC_FLAG_PSNR            0x8000   ///< error[?] variables will be set during encoding.
645 #define CODEC_FLAG_TRUNCATED       0x00010000 /** Input bitstream might be truncated at a random
646                                                   location instead of only at frame boundaries. */
647 #define CODEC_FLAG_NORMALIZE_AQP  0x00020000 ///< Normalize adaptive quantization.
648 #define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT.
649 #define CODEC_FLAG_LOW_DELAY      0x00080000 ///< Force low delay.
650 #define CODEC_FLAG_GLOBAL_HEADER  0x00400000 ///< Place global headers in extradata instead of every keyframe.
651 #define CODEC_FLAG_BITEXACT       0x00800000 ///< Use only bitexact stuff (except (I)DCT).
652 /* Fx : Flag for h263+ extra options */
653 #define CODEC_FLAG_AC_PRED        0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
654 #define CODEC_FLAG_CBP_RD         0x04000000 ///< Use rate distortion optimization for cbp.
655 #define CODEC_FLAG_QP_RD          0x08000000 ///< Use rate distortion optimization for qp selectioon.
656 #define CODEC_FLAG_LOOP_FILTER    0x00000800 ///< loop filter
657 #define CODEC_FLAG_INTERLACED_ME  0x20000000 ///< interlaced motion estimation
658 #define CODEC_FLAG_CLOSED_GOP     0x80000000
659 #define CODEC_FLAG2_FAST          0x00000001 ///< Allow non spec compliant speedup tricks.
660 #define CODEC_FLAG2_STRICT_GOP    0x00000002 ///< Strictly enforce GOP size.
661 #define CODEC_FLAG2_NO_OUTPUT     0x00000004 ///< Skip bitstream encoding.
662 #define CODEC_FLAG2_LOCAL_HEADER  0x00000008 ///< Place global headers at every keyframe instead of in extradata.
663 #define CODEC_FLAG2_SKIP_RD       0x00004000 ///< RD optimal MB level residual skipping
664 #define CODEC_FLAG2_CHUNKS        0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
665 /**
666  * @defgroup deprecated_flags Deprecated codec flags
667  * Use corresponding private codec options instead.
668  * @{
669  */
670 #if FF_API_MPEGVIDEO_GLOBAL_OPTS
671 #define CODEC_FLAG_OBMC           0x00000001 ///< OBMC
672 #define CODEC_FLAG_H263P_AIV      0x00000008 ///< H.263 alternative inter VLC
673 #define CODEC_FLAG_PART   0x0080  ///< Use data partitioning.
674 #define CODEC_FLAG_ALT_SCAN       0x00100000 ///< Use alternate scan.
675 #define CODEC_FLAG_H263P_UMV      0x02000000 ///< unlimited motion vector
676 #define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000
677 #define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< Will reserve space for SVCD scan offset user data.
678 #define CODEC_FLAG2_INTRA_VLC     0x00000800 ///< Use MPEG-2 intra VLC table.
679 #define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format.
680 #define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer.
681 #endif
682 #if FF_API_MJPEG_GLOBAL_OPTS
683 #define CODEC_FLAG_EXTERN_HUFF     0x1000   ///< Use external Huffman table (for MJPEG).
684 #endif
685 #if FF_API_X264_GLOBAL_OPTS
686 #define CODEC_FLAG2_BPYRAMID      0x00000010 ///< H.264 allow B-frames to be used as references.
687 #define CODEC_FLAG2_WPRED         0x00000020 ///< H.264 weighted biprediction for B-frames
688 #define CODEC_FLAG2_MIXED_REFS    0x00000040 ///< H.264 one reference per partition, as opposed to one reference per macroblock
689 #define CODEC_FLAG2_8X8DCT        0x00000080 ///< H.264 high profile 8x8 transform
690 #define CODEC_FLAG2_FASTPSKIP     0x00000100 ///< H.264 fast pskip
691 #define CODEC_FLAG2_AUD           0x00000200 ///< H.264 access unit delimiters
692 #define CODEC_FLAG2_BRDO          0x00000400 ///< B-frame rate-distortion optimization
693 #define CODEC_FLAG2_MBTREE        0x00040000 ///< Use macroblock tree ratecontrol (x264 only)
694 #define CODEC_FLAG2_PSY           0x00080000 ///< Use psycho visual optimizations.
695 #define CODEC_FLAG2_SSIM          0x00100000 ///< Compute SSIM during encoding, error[] values are undefined.
696 #define CODEC_FLAG2_INTRA_REFRESH 0x00200000 ///< Use periodic insertion of intra blocks instead of keyframes.
697 #endif
698 #if FF_API_SNOW_GLOBAL_OPTS
699 #define CODEC_FLAG2_MEMC_ONLY     0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC).
700 #endif
701 #if FF_API_LAME_GLOBAL_OPTS
702 #define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible
703 #endif
704 /**
705  * @}
706  */
707
708 /* Unsupported options :
709  *              Syntax Arithmetic coding (SAC)
710  *              Reference Picture Selection
711  *              Independent Segment Decoding */
712 /* /Fx */
713 /* codec capabilities */
714
715 #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback.
716 /**
717  * Codec uses get_buffer() for allocating buffers and supports custom allocators.
718  * If not set, it might not use get_buffer() at all or use operations that
719  * assume the buffer was allocated by avcodec_default_get_buffer.
720  */
721 #define CODEC_CAP_DR1             0x0002
722 #if FF_API_PARSE_FRAME
723 /* If 'parse_only' field is true, then avcodec_parse_frame() can be used. */
724 #define CODEC_CAP_PARSE_ONLY      0x0004
725 #endif
726 #define CODEC_CAP_TRUNCATED       0x0008
727 /* Codec can export data for HW decoding (XvMC). */
728 #define CODEC_CAP_HWACCEL         0x0010
729 /**
730  * Encoder or decoder requires flushing with NULL input at the end in order to
731  * give the complete and correct output.
732  *
733  * NOTE: If this flag is not set, the codec is guaranteed to never be fed with
734  *       with NULL data. The user can still send NULL data to the public encode
735  *       or decode function, but libavcodec will not pass it along to the codec
736  *       unless this flag is set.
737  *
738  * Decoders:
739  * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL,
740  * avpkt->size=0 at the end to get the delayed data until the decoder no longer
741  * returns frames.
742  *
743  * Encoders:
744  * The encoder needs to be fed with NULL data at the end of encoding until the
745  * encoder no longer returns data.
746  *
747  * NOTE: For encoders implementing the AVCodec.encode2() function, setting this
748  *       flag also means that the encoder must set the pts and duration for
749  *       each output packet. If this flag is not set, the pts and duration will
750  *       be determined by libavcodec from the input frame.
751  */
752 #define CODEC_CAP_DELAY           0x0020
753 /**
754  * Codec can be fed a final frame with a smaller size.
755  * This can be used to prevent truncation of the last audio samples.
756  */
757 #define CODEC_CAP_SMALL_LAST_FRAME 0x0040
758 /**
759  * Codec can export data for HW decoding (VDPAU).
760  */
761 #define CODEC_CAP_HWACCEL_VDPAU    0x0080
762 /**
763  * Codec can output multiple frames per AVPacket
764  * Normally demuxers return one frame at a time, demuxers which do not do
765  * are connected to a parser to split what they return into proper frames.
766  * This flag is reserved to the very rare category of codecs which have a
767  * bitstream that cannot be split into frames without timeconsuming
768  * operations like full decoding. Demuxers carring such bitstreams thus
769  * may return multiple frames in a packet. This has many disadvantages like
770  * prohibiting stream copy in many cases thus it should only be considered
771  * as a last resort.
772  */
773 #define CODEC_CAP_SUBFRAMES        0x0100
774 /**
775  * Codec is experimental and is thus avoided in favor of non experimental
776  * encoders
777  */
778 #define CODEC_CAP_EXPERIMENTAL     0x0200
779 /**
780  * Codec should fill in channel configuration and samplerate instead of container
781  */
782 #define CODEC_CAP_CHANNEL_CONF     0x0400
783 /**
784  * Codec is able to deal with negative linesizes
785  */
786 #define CODEC_CAP_NEG_LINESIZES    0x0800
787 /**
788  * Codec supports frame-level multithreading.
789  */
790 #define CODEC_CAP_FRAME_THREADS    0x1000
791 /**
792  * Codec supports slice-based (or partition-based) multithreading.
793  */
794 #define CODEC_CAP_SLICE_THREADS    0x2000
795 /**
796  * Codec supports changed parameters at any point.
797  */
798 #define CODEC_CAP_PARAM_CHANGE     0x4000
799 /**
800  * Codec supports avctx->thread_count == 0 (auto).
801  */
802 #define CODEC_CAP_AUTO_THREADS     0x8000
803 /**
804  * Audio encoder supports receiving a different number of samples in each call.
805  */
806 #define CODEC_CAP_VARIABLE_FRAME_SIZE 0x10000
807
808 //The following defines may change, don't expect compatibility if you use them.
809 #define MB_TYPE_INTRA4x4   0x0001
810 #define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific
811 #define MB_TYPE_INTRA_PCM  0x0004 //FIXME H.264-specific
812 #define MB_TYPE_16x16      0x0008
813 #define MB_TYPE_16x8       0x0010
814 #define MB_TYPE_8x16       0x0020
815 #define MB_TYPE_8x8        0x0040
816 #define MB_TYPE_INTERLACED 0x0080
817 #define MB_TYPE_DIRECT2    0x0100 //FIXME
818 #define MB_TYPE_ACPRED     0x0200
819 #define MB_TYPE_GMC        0x0400
820 #define MB_TYPE_SKIP       0x0800
821 #define MB_TYPE_P0L0       0x1000
822 #define MB_TYPE_P1L0       0x2000
823 #define MB_TYPE_P0L1       0x4000
824 #define MB_TYPE_P1L1       0x8000
825 #define MB_TYPE_L0         (MB_TYPE_P0L0 | MB_TYPE_P1L0)
826 #define MB_TYPE_L1         (MB_TYPE_P0L1 | MB_TYPE_P1L1)
827 #define MB_TYPE_L0L1       (MB_TYPE_L0   | MB_TYPE_L1)
828 #define MB_TYPE_QUANT      0x00010000
829 #define MB_TYPE_CBP        0x00020000
830 //Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...)
831
832 /**
833  * Pan Scan area.
834  * This specifies the area which should be displayed.
835  * Note there may be multiple such areas for one frame.
836  */
837 typedef struct AVPanScan{
838     /**
839      * id
840      * - encoding: Set by user.
841      * - decoding: Set by libavcodec.
842      */
843     int id;
844
845     /**
846      * width and height in 1/16 pel
847      * - encoding: Set by user.
848      * - decoding: Set by libavcodec.
849      */
850     int width;
851     int height;
852
853     /**
854      * position of the top left corner in 1/16 pel for up to 3 fields/frames
855      * - encoding: Set by user.
856      * - decoding: Set by libavcodec.
857      */
858     int16_t position[3][2];
859 }AVPanScan;
860
861 #define FF_QSCALE_TYPE_MPEG1 0
862 #define FF_QSCALE_TYPE_MPEG2 1
863 #define FF_QSCALE_TYPE_H264  2
864 #define FF_QSCALE_TYPE_VP56  3
865
866 #define FF_BUFFER_TYPE_INTERNAL 1
867 #define FF_BUFFER_TYPE_USER     2 ///< direct rendering buffers (image is (de)allocated by user)
868 #define FF_BUFFER_TYPE_SHARED   4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared.
869 #define FF_BUFFER_TYPE_COPY     8 ///< Just a (modified) copy of some other buffer, don't deallocate anything.
870
871 #if FF_API_OLD_FF_PICT_TYPES
872 /* DEPRECATED, directly use the AV_PICTURE_TYPE_* enum values */
873 #define FF_I_TYPE  AV_PICTURE_TYPE_I  ///< Intra
874 #define FF_P_TYPE  AV_PICTURE_TYPE_P  ///< Predicted
875 #define FF_B_TYPE  AV_PICTURE_TYPE_B  ///< Bi-dir predicted
876 #define FF_S_TYPE  AV_PICTURE_TYPE_S  ///< S(GMC)-VOP MPEG4
877 #define FF_SI_TYPE AV_PICTURE_TYPE_SI ///< Switching Intra
878 #define FF_SP_TYPE AV_PICTURE_TYPE_SP ///< Switching Predicted
879 #define FF_BI_TYPE AV_PICTURE_TYPE_BI
880 #endif
881
882 #define FF_BUFFER_HINTS_VALID    0x01 // Buffer hints value is meaningful (if 0 ignore).
883 #define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer.
884 #define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content.
885 #define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update).
886
887 enum AVPacketSideDataType {
888     AV_PKT_DATA_PALETTE,
889     AV_PKT_DATA_NEW_EXTRADATA,
890     AV_PKT_DATA_PARAM_CHANGE,
891 };
892
893 typedef struct AVPacket {
894     /**
895      * Presentation timestamp in AVStream->time_base units; the time at which
896      * the decompressed packet will be presented to the user.
897      * Can be AV_NOPTS_VALUE if it is not stored in the file.
898      * pts MUST be larger or equal to dts as presentation cannot happen before
899      * decompression, unless one wants to view hex dumps. Some formats misuse
900      * the terms dts and pts/cts to mean something different. Such timestamps
901      * must be converted to true pts/dts before they are stored in AVPacket.
902      */
903     int64_t pts;
904     /**
905      * Decompression timestamp in AVStream->time_base units; the time at which
906      * the packet is decompressed.
907      * Can be AV_NOPTS_VALUE if it is not stored in the file.
908      */
909     int64_t dts;
910     uint8_t *data;
911     int   size;
912     int   stream_index;
913     /**
914      * A combination of AV_PKT_FLAG values
915      */
916     int   flags;
917     /**
918      * Additional packet data that can be provided by the container.
919      * Packet can contain several types of side information.
920      */
921     struct {
922         uint8_t *data;
923         int      size;
924         enum AVPacketSideDataType type;
925     } *side_data;
926     int side_data_elems;
927
928     /**
929      * Duration of this packet in AVStream->time_base units, 0 if unknown.
930      * Equals next_pts - this_pts in presentation order.
931      */
932     int   duration;
933     void  (*destruct)(struct AVPacket *);
934     void  *priv;
935     int64_t pos;                            ///< byte position in stream, -1 if unknown
936
937     /**
938      * Time difference in AVStream->time_base units from the pts of this
939      * packet to the point at which the output from the decoder has converged
940      * independent from the availability of previous frames. That is, the
941      * frames are virtually identical no matter if decoding started from
942      * the very first frame or from this keyframe.
943      * Is AV_NOPTS_VALUE if unknown.
944      * This field is not the display duration of the current packet.
945      * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
946      * set.
947      *
948      * The purpose of this field is to allow seeking in streams that have no
949      * keyframes in the conventional sense. It corresponds to the
950      * recovery point SEI in H.264 and match_time_delta in NUT. It is also
951      * essential for some types of subtitle streams to ensure that all
952      * subtitles are correctly displayed after seeking.
953      */
954     int64_t convergence_duration;
955 } AVPacket;
956 #define AV_PKT_FLAG_KEY     0x0001 ///< The packet contains a keyframe
957 #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
958
959 /**
960  * An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
961  * u32le param_flags
962  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT)
963  *     s32le channel_count
964  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT)
965  *     u64le channel_layout
966  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE)
967  *     s32le sample_rate
968  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS)
969  *     s32le width
970  *     s32le height
971  */
972
973 enum AVSideDataParamChangeFlags {
974     AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT  = 0x0001,
975     AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002,
976     AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE    = 0x0004,
977     AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS     = 0x0008,
978 };
979
980 /**
981  * Audio Video Frame.
982  * New fields can be added to the end of AVFRAME with minor version
983  * bumps. Removal, reordering and changes to existing fields require
984  * a major version bump.
985  * sizeof(AVFrame) must not be used outside libav*.
986  */
987 typedef struct AVFrame {
988 #if FF_API_DATA_POINTERS
989 #define AV_NUM_DATA_POINTERS 4
990 #else
991 #define AV_NUM_DATA_POINTERS 8
992 #endif
993     /**
994      * pointer to the picture/channel planes.
995      * This might be different from the first allocated byte
996      * - encoding: Set by user
997      * - decoding: set by AVCodecContext.get_buffer()
998      */
999     uint8_t *data[AV_NUM_DATA_POINTERS];
1000
1001     /**
1002      * Size, in bytes, of the data for each picture/channel plane.
1003      *
1004      * For audio, only linesize[0] may be set. For planar audio, each channel
1005      * plane must be the same size.
1006      *
1007      * - encoding: Set by user (video only)
1008      * - decoding: set by AVCodecContext.get_buffer()
1009      */
1010     int linesize[AV_NUM_DATA_POINTERS];
1011
1012     /**
1013      * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.
1014      * This isn't used by libavcodec unless the default get/release_buffer() is used.
1015      * - encoding:
1016      * - decoding:
1017      */
1018     uint8_t *base[AV_NUM_DATA_POINTERS];
1019     /**
1020      * 1 -> keyframe, 0-> not
1021      * - encoding: Set by libavcodec.
1022      * - decoding: Set by libavcodec.
1023      */
1024     int key_frame;
1025
1026     /**
1027      * Picture type of the frame, see ?_TYPE below.
1028      * - encoding: Set by libavcodec. for coded_picture (and set by user for input).
1029      * - decoding: Set by libavcodec.
1030      */
1031     enum AVPictureType pict_type;
1032
1033     /**
1034      * presentation timestamp in time_base units (time when frame should be shown to user)
1035      * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.
1036      * - encoding: MUST be set by user.
1037      * - decoding: Set by libavcodec.
1038      */
1039     int64_t pts;
1040
1041     /**
1042      * picture number in bitstream order
1043      * - encoding: set by
1044      * - decoding: Set by libavcodec.
1045      */
1046     int coded_picture_number;
1047     /**
1048      * picture number in display order
1049      * - encoding: set by
1050      * - decoding: Set by libavcodec.
1051      */
1052     int display_picture_number;
1053
1054     /**
1055      * quality (between 1 (good) and FF_LAMBDA_MAX (bad))
1056      * - encoding: Set by libavcodec. for coded_picture (and set by user for input).
1057      * - decoding: Set by libavcodec.
1058      */
1059     int quality;
1060
1061 #if FF_API_AVFRAME_AGE
1062     /**
1063      * @deprecated unused
1064      */
1065     attribute_deprecated int age;
1066 #endif
1067
1068     /**
1069      * is this picture used as reference
1070      * The values for this are the same as the MpegEncContext.picture_structure
1071      * variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
1072      * Set to 4 for delayed, non-reference frames.
1073      * - encoding: unused
1074      * - decoding: Set by libavcodec. (before get_buffer() call)).
1075      */
1076     int reference;
1077
1078     /**
1079      * QP table
1080      * - encoding: unused
1081      * - decoding: Set by libavcodec.
1082      */
1083     int8_t *qscale_table;
1084     /**
1085      * QP store stride
1086      * - encoding: unused
1087      * - decoding: Set by libavcodec.
1088      */
1089     int qstride;
1090
1091     /**
1092      * mbskip_table[mb]>=1 if MB didn't change
1093      * stride= mb_width = (width+15)>>4
1094      * - encoding: unused
1095      * - decoding: Set by libavcodec.
1096      */
1097     uint8_t *mbskip_table;
1098
1099     /**
1100      * motion vector table
1101      * @code
1102      * example:
1103      * int mv_sample_log2= 4 - motion_subsample_log2;
1104      * int mb_width= (width+15)>>4;
1105      * int mv_stride= (mb_width << mv_sample_log2) + 1;
1106      * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];
1107      * @endcode
1108      * - encoding: Set by user.
1109      * - decoding: Set by libavcodec.
1110      */
1111     int16_t (*motion_val[2])[2];
1112
1113     /**
1114      * macroblock type table
1115      * mb_type_base + mb_width + 2
1116      * - encoding: Set by user.
1117      * - decoding: Set by libavcodec.
1118      */
1119     uint32_t *mb_type;
1120
1121     /**
1122      * log2 of the size of the block which a single vector in motion_val represents:
1123      * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)
1124      * - encoding: unused
1125      * - decoding: Set by libavcodec.
1126      */
1127     uint8_t motion_subsample_log2;
1128
1129     /**
1130      * for some private data of the user
1131      * - encoding: unused
1132      * - decoding: Set by user.
1133      */
1134     void *opaque;
1135
1136     /**
1137      * error
1138      * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.
1139      * - decoding: unused
1140      */
1141     uint64_t error[AV_NUM_DATA_POINTERS];
1142
1143     /**
1144      * type of the buffer (to keep track of who has to deallocate data[*])
1145      * - encoding: Set by the one who allocates it.
1146      * - decoding: Set by the one who allocates it.
1147      * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.
1148      */
1149     int type;
1150
1151     /**
1152      * When decoding, this signals how much the picture must be delayed.
1153      * extra_delay = repeat_pict / (2*fps)
1154      * - encoding: unused
1155      * - decoding: Set by libavcodec.
1156      */
1157     int repeat_pict;
1158
1159     /**
1160      *
1161      */
1162     int qscale_type;
1163
1164     /**
1165      * The content of the picture is interlaced.
1166      * - encoding: Set by user.
1167      * - decoding: Set by libavcodec. (default 0)
1168      */
1169     int interlaced_frame;
1170
1171     /**
1172      * If the content is interlaced, is top field displayed first.
1173      * - encoding: Set by user.
1174      * - decoding: Set by libavcodec.
1175      */
1176     int top_field_first;
1177
1178     /**
1179      * Pan scan.
1180      * - encoding: Set by user.
1181      * - decoding: Set by libavcodec.
1182      */
1183     AVPanScan *pan_scan;
1184
1185     /**
1186      * Tell user application that palette has changed from previous frame.
1187      * - encoding: ??? (no palette-enabled encoder yet)
1188      * - decoding: Set by libavcodec. (default 0).
1189      */
1190     int palette_has_changed;
1191
1192     /**
1193      * codec suggestion on buffer type if != 0
1194      * - encoding: unused
1195      * - decoding: Set by libavcodec. (before get_buffer() call)).
1196      */
1197     int buffer_hints;
1198
1199     /**
1200      * DCT coefficients
1201      * - encoding: unused
1202      * - decoding: Set by libavcodec.
1203      */
1204     short *dct_coeff;
1205
1206     /**
1207      * motion reference frame index
1208      * the order in which these are stored can depend on the codec.
1209      * - encoding: Set by user.
1210      * - decoding: Set by libavcodec.
1211      */
1212     int8_t *ref_index[2];
1213
1214     /**
1215      * reordered opaque 64bit (generally an integer or a double precision float
1216      * PTS but can be anything).
1217      * The user sets AVCodecContext.reordered_opaque to represent the input at
1218      * that time,
1219      * the decoder reorders values as needed and sets AVFrame.reordered_opaque
1220      * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque
1221      * @deprecated in favor of pkt_pts
1222      * - encoding: unused
1223      * - decoding: Read by user.
1224      */
1225     int64_t reordered_opaque;
1226
1227     /**
1228      * hardware accelerator private data (Libav-allocated)
1229      * - encoding: unused
1230      * - decoding: Set by libavcodec
1231      */
1232     void *hwaccel_picture_private;
1233
1234     /**
1235      * reordered pts from the last AVPacket that has been input into the decoder
1236      * - encoding: unused
1237      * - decoding: Read by user.
1238      */
1239     int64_t pkt_pts;
1240
1241     /**
1242      * dts from the last AVPacket that has been input into the decoder
1243      * - encoding: unused
1244      * - decoding: Read by user.
1245      */
1246     int64_t pkt_dts;
1247
1248     /**
1249      * the AVCodecContext which ff_thread_get_buffer() was last called on
1250      * - encoding: Set by libavcodec.
1251      * - decoding: Set by libavcodec.
1252      */
1253     struct AVCodecContext *owner;
1254
1255     /**
1256      * used by multithreading to store frame-specific info
1257      * - encoding: Set by libavcodec.
1258      * - decoding: Set by libavcodec.
1259      */
1260     void *thread_opaque;
1261
1262     /**
1263      * number of audio samples (per channel) described by this frame
1264      * - encoding: unused
1265      * - decoding: Set by libavcodec
1266      */
1267     int nb_samples;
1268
1269     /**
1270      * pointers to the data planes/channels.
1271      *
1272      * For video, this should simply point to data[].
1273      *
1274      * For planar audio, each channel has a separate data pointer, and
1275      * linesize[0] contains the size of each channel buffer.
1276      * For packed audio, there is just one data pointer, and linesize[0]
1277      * contains the total size of the buffer for all channels.
1278      *
1279      * Note: Both data and extended_data will always be set by get_buffer(),
1280      * but for planar audio with more channels that can fit in data,
1281      * extended_data must be used by the decoder in order to access all
1282      * channels.
1283      *
1284      * encoding: unused
1285      * decoding: set by AVCodecContext.get_buffer()
1286      */
1287     uint8_t **extended_data;
1288
1289     /**
1290      * sample aspect ratio for the video frame, 0/1 if unknown\unspecified
1291      * - encoding: unused
1292      * - decoding: Read by user.
1293      */
1294     AVRational sample_aspect_ratio;
1295
1296     /**
1297      * width and height of the video frame
1298      * - encoding: unused
1299      * - decoding: Read by user.
1300      */
1301     int width, height;
1302
1303     /**
1304      * format of the frame, -1 if unknown or unset
1305      * Values correspond to enum PixelFormat for video frames,
1306      * enum AVSampleFormat for audio)
1307      * - encoding: unused
1308      * - decoding: Read by user.
1309      */
1310     int format;
1311 } AVFrame;
1312
1313 struct AVCodecInternal;
1314
1315 enum AVFieldOrder {
1316     AV_FIELD_UNKNOWN,
1317     AV_FIELD_PROGRESSIVE,
1318     AV_FIELD_TT,          //< Top coded_first, top displayed first
1319     AV_FIELD_BB,          //< Bottom coded first, bottom displayed first
1320     AV_FIELD_TB,          //< Top coded first, bottom displayed first
1321     AV_FIELD_BT,          //< Bottom coded first, top displayed first
1322 };
1323
1324 /**
1325  * main external API structure.
1326  * New fields can be added to the end with minor version bumps.
1327  * Removal, reordering and changes to existing fields require a major
1328  * version bump.
1329  * sizeof(AVCodecContext) must not be used outside libav*.
1330  */
1331 typedef struct AVCodecContext {
1332     /**
1333      * information on struct for av_log
1334      * - set by avcodec_alloc_context3
1335      */
1336     const AVClass *av_class;
1337     /**
1338      * the average bitrate
1339      * - encoding: Set by user; unused for constant quantizer encoding.
1340      * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream.
1341      */
1342     int bit_rate;
1343
1344     /**
1345      * number of bits the bitstream is allowed to diverge from the reference.
1346      *           the reference can be CBR (for CBR pass1) or VBR (for pass2)
1347      * - encoding: Set by user; unused for constant quantizer encoding.
1348      * - decoding: unused
1349      */
1350     int bit_rate_tolerance;
1351
1352     /**
1353      * CODEC_FLAG_*.
1354      * - encoding: Set by user.
1355      * - decoding: Set by user.
1356      */
1357     int flags;
1358
1359     /**
1360      * Some codecs need additional format info. It is stored here.
1361      * If any muxer uses this then ALL demuxers/parsers AND encoders for the
1362      * specific codec MUST set it correctly otherwise stream copy breaks.
1363      * In general use of this field by muxers is not recommended.
1364      * - encoding: Set by libavcodec.
1365      * - decoding: Set by libavcodec. (FIXME: Is this OK?)
1366      */
1367     int sub_id;
1368
1369     /**
1370      * Motion estimation algorithm used for video coding.
1371      * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
1372      * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific]
1373      * - encoding: MUST be set by user.
1374      * - decoding: unused
1375      */
1376     int me_method;
1377
1378     /**
1379      * some codecs need / can use extradata like Huffman tables.
1380      * mjpeg: Huffman tables
1381      * rv10: additional flags
1382      * mpeg4: global headers (they can be in the bitstream or here)
1383      * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
1384      * than extradata_size to avoid prolems if it is read with the bitstream reader.
1385      * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
1386      * - encoding: Set/allocated/freed by libavcodec.
1387      * - decoding: Set/allocated/freed by user.
1388      */
1389     uint8_t *extradata;
1390     int extradata_size;
1391
1392     /**
1393      * This is the fundamental unit of time (in seconds) in terms
1394      * of which frame timestamps are represented. For fixed-fps content,
1395      * timebase should be 1/framerate and timestamp increments should be
1396      * identically 1.
1397      * - encoding: MUST be set by user.
1398      * - decoding: Set by libavcodec.
1399      */
1400     AVRational time_base;
1401
1402     /* video only */
1403     /**
1404      * picture width / height.
1405      * - encoding: MUST be set by user.
1406      * - decoding: Set by libavcodec.
1407      * Note: For compatibility it is possible to set this instead of
1408      * coded_width/height before decoding.
1409      */
1410     int width, height;
1411
1412 #define FF_ASPECT_EXTENDED 15
1413
1414     /**
1415      * the number of pictures in a group of pictures, or 0 for intra_only
1416      * - encoding: Set by user.
1417      * - decoding: unused
1418      */
1419     int gop_size;
1420
1421     /**
1422      * Pixel format, see PIX_FMT_xxx.
1423      * May be set by the demuxer if known from headers.
1424      * May be overriden by the decoder if it knows better.
1425      * - encoding: Set by user.
1426      * - decoding: Set by user if known, overridden by libavcodec if known
1427      */
1428     enum PixelFormat pix_fmt;
1429
1430     /**
1431      * If non NULL, 'draw_horiz_band' is called by the libavcodec
1432      * decoder to draw a horizontal band. It improves cache usage. Not
1433      * all codecs can do that. You must check the codec capabilities
1434      * beforehand.
1435      * When multithreading is used, it may be called from multiple threads
1436      * at the same time; threads might draw different parts of the same AVFrame,
1437      * or multiple AVFrames, and there is no guarantee that slices will be drawn
1438      * in order.
1439      * The function is also used by hardware acceleration APIs.
1440      * It is called at least once during frame decoding to pass
1441      * the data needed for hardware render.
1442      * In that mode instead of pixel data, AVFrame points to
1443      * a structure specific to the acceleration API. The application
1444      * reads the structure and can change some fields to indicate progress
1445      * or mark state.
1446      * - encoding: unused
1447      * - decoding: Set by user.
1448      * @param height the height of the slice
1449      * @param y the y position of the slice
1450      * @param type 1->top field, 2->bottom field, 3->frame
1451      * @param offset offset into the AVFrame.data from which the slice should be read
1452      */
1453     void (*draw_horiz_band)(struct AVCodecContext *s,
1454                             const AVFrame *src, int offset[AV_NUM_DATA_POINTERS],
1455                             int y, int type, int height);
1456
1457     /* audio only */
1458     int sample_rate; ///< samples per second
1459     int channels;    ///< number of audio channels
1460
1461     /**
1462      * audio sample format
1463      * - encoding: Set by user.
1464      * - decoding: Set by libavcodec.
1465      */
1466     enum AVSampleFormat sample_fmt;  ///< sample format
1467
1468     /* The following data should not be initialized. */
1469     /**
1470      * Samples per packet, initialized when calling 'init'.
1471      */
1472     int frame_size;
1473     int frame_number;   ///< audio or video frame number
1474
1475     /**
1476      * Number of frames the decoded output will be delayed relative to
1477      * the encoded input.
1478      * - encoding: Set by libavcodec.
1479      * - decoding: unused
1480      */
1481     int delay;
1482
1483     /* - encoding parameters */
1484     float qcompress;  ///< amount of qscale change between easy & hard scenes (0.0-1.0)
1485     float qblur;      ///< amount of qscale smoothing over time (0.0-1.0)
1486
1487     /**
1488      * minimum quantizer
1489      * - encoding: Set by user.
1490      * - decoding: unused
1491      */
1492     int qmin;
1493
1494     /**
1495      * maximum quantizer
1496      * - encoding: Set by user.
1497      * - decoding: unused
1498      */
1499     int qmax;
1500
1501     /**
1502      * maximum quantizer difference between frames
1503      * - encoding: Set by user.
1504      * - decoding: unused
1505      */
1506     int max_qdiff;
1507
1508     /**
1509      * maximum number of B-frames between non-B-frames
1510      * Note: The output will be delayed by max_b_frames+1 relative to the input.
1511      * - encoding: Set by user.
1512      * - decoding: unused
1513      */
1514     int max_b_frames;
1515
1516     /**
1517      * qscale factor between IP and B-frames
1518      * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
1519      * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
1520      * - encoding: Set by user.
1521      * - decoding: unused
1522      */
1523     float b_quant_factor;
1524
1525     /** obsolete FIXME remove */
1526     int rc_strategy;
1527 #define FF_RC_STRATEGY_XVID 1
1528
1529     int b_frame_strategy;
1530
1531     struct AVCodec *codec;
1532
1533     void *priv_data;
1534
1535     int rtp_payload_size;   /* The size of the RTP payload: the coder will  */
1536                             /* do its best to deliver a chunk with size     */
1537                             /* below rtp_payload_size, the chunk will start */
1538                             /* with a start code on some codecs like H.263. */
1539                             /* This doesn't take account of any particular  */
1540                             /* headers inside the transmitted RTP payload.  */
1541
1542
1543     /* The RTP callback: This function is called    */
1544     /* every time the encoder has a packet to send. */
1545     /* It depends on the encoder if the data starts */
1546     /* with a Start Code (it should). H.263 does.   */
1547     /* mb_nb contains the number of macroblocks     */
1548     /* encoded in the RTP payload.                  */
1549     void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
1550
1551     /* statistics, used for 2-pass encoding */
1552     int mv_bits;
1553     int header_bits;
1554     int i_tex_bits;
1555     int p_tex_bits;
1556     int i_count;
1557     int p_count;
1558     int skip_count;
1559     int misc_bits;
1560
1561     /**
1562      * number of bits used for the previously encoded frame
1563      * - encoding: Set by libavcodec.
1564      * - decoding: unused
1565      */
1566     int frame_bits;
1567
1568     /**
1569      * Private data of the user, can be used to carry app specific stuff.
1570      * - encoding: Set by user.
1571      * - decoding: Set by user.
1572      */
1573     void *opaque;
1574
1575     char codec_name[32];
1576     enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
1577     enum CodecID codec_id; /* see CODEC_ID_xxx */
1578
1579     /**
1580      * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
1581      * This is used to work around some encoder bugs.
1582      * A demuxer should set this to what is stored in the field used to identify the codec.
1583      * If there are multiple such fields in a container then the demuxer should choose the one
1584      * which maximizes the information about the used codec.
1585      * If the codec tag field in a container is larger than 32 bits then the demuxer should
1586      * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
1587      * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
1588      * first.
1589      * - encoding: Set by user, if not then the default based on codec_id will be used.
1590      * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
1591      */
1592     unsigned int codec_tag;
1593
1594     /**
1595      * Work around bugs in encoders which sometimes cannot be detected automatically.
1596      * - encoding: Set by user
1597      * - decoding: Set by user
1598      */
1599     int workaround_bugs;
1600 #define FF_BUG_AUTODETECT       1  ///< autodetection
1601 #define FF_BUG_OLD_MSMPEG4      2
1602 #define FF_BUG_XVID_ILACE       4
1603 #define FF_BUG_UMP4             8
1604 #define FF_BUG_NO_PADDING       16
1605 #define FF_BUG_AMV              32
1606 #define FF_BUG_AC_VLC           0  ///< Will be removed, libavcodec can now handle these non-compliant files by default.
1607 #define FF_BUG_QPEL_CHROMA      64
1608 #define FF_BUG_STD_QPEL         128
1609 #define FF_BUG_QPEL_CHROMA2     256
1610 #define FF_BUG_DIRECT_BLOCKSIZE 512
1611 #define FF_BUG_EDGE             1024
1612 #define FF_BUG_HPEL_CHROMA      2048
1613 #define FF_BUG_DC_CLIP          4096
1614 #define FF_BUG_MS               8192 ///< Work around various bugs in Microsoft's broken decoders.
1615 #define FF_BUG_TRUNCATED       16384
1616 //#define FF_BUG_FAKE_SCALABILITY 16 //Autodetection should work 100%.
1617
1618     /**
1619      * luma single coefficient elimination threshold
1620      * - encoding: Set by user.
1621      * - decoding: unused
1622      */
1623     int luma_elim_threshold;
1624
1625     /**
1626      * chroma single coeff elimination threshold
1627      * - encoding: Set by user.
1628      * - decoding: unused
1629      */
1630     int chroma_elim_threshold;
1631
1632     /**
1633      * strictly follow the standard (MPEG4, ...).
1634      * - encoding: Set by user.
1635      * - decoding: Set by user.
1636      * Setting this to STRICT or higher means the encoder and decoder will
1637      * generally do stupid things, whereas setting it to unofficial or lower
1638      * will mean the encoder might produce output that is not supported by all
1639      * spec-compliant decoders. Decoders don't differentiate between normal,
1640      * unofficial and experimental (that is, they always try to decode things
1641      * when they can) unless they are explicitly asked to behave stupidly
1642      * (=strictly conform to the specs)
1643      */
1644     int strict_std_compliance;
1645 #define FF_COMPLIANCE_VERY_STRICT   2 ///< Strictly conform to an older more strict version of the spec or reference software.
1646 #define FF_COMPLIANCE_STRICT        1 ///< Strictly conform to all the things in the spec no matter what consequences.
1647 #define FF_COMPLIANCE_NORMAL        0
1648 #define FF_COMPLIANCE_UNOFFICIAL   -1 ///< Allow unofficial extensions
1649 #define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
1650
1651     /**
1652      * qscale offset between IP and B-frames
1653      * - encoding: Set by user.
1654      * - decoding: unused
1655      */
1656     float b_quant_offset;
1657
1658 #if FF_API_ER
1659     /**
1660      * Error recognition; higher values will detect more errors but may
1661      * misdetect some more or less valid parts as errors.
1662      * - encoding: unused
1663      * - decoding: Set by user.
1664      */
1665     attribute_deprecated int error_recognition;
1666 #define FF_ER_CAREFUL         1
1667 #define FF_ER_COMPLIANT       2
1668 #define FF_ER_AGGRESSIVE      3
1669 #define FF_ER_VERY_AGGRESSIVE 4
1670 #define FF_ER_EXPLODE         5
1671 #endif /* FF_API_ER */
1672
1673     /**
1674      * Called at the beginning of each frame to get a buffer for it.
1675      *
1676      * The function will set AVFrame.data[], AVFrame.linesize[].
1677      * AVFrame.extended_data[] must also be set, but it should be the same as
1678      * AVFrame.data[] except for planar audio with more channels than can fit
1679      * in AVFrame.data[]. In that case, AVFrame.data[] shall still contain as
1680      * many data pointers as it can hold.
1681      *
1682      * if CODEC_CAP_DR1 is not set then get_buffer() must call
1683      * avcodec_default_get_buffer() instead of providing buffers allocated by
1684      * some other means.
1685      *
1686      * AVFrame.data[] should be 32- or 16-byte-aligned unless the CPU doesn't
1687      * need it. avcodec_default_get_buffer() aligns the output buffer properly,
1688      * but if get_buffer() is overridden then alignment considerations should
1689      * be taken into account.
1690      *
1691      * @see avcodec_default_get_buffer()
1692      *
1693      * Video:
1694      *
1695      * If pic.reference is set then the frame will be read later by libavcodec.
1696      * avcodec_align_dimensions2() should be used to find the required width and
1697      * height, as they normally need to be rounded up to the next multiple of 16.
1698      *
1699      * If frame multithreading is used and thread_safe_callbacks is set,
1700      * it may be called from a different thread, but not from more than one at
1701      * once. Does not need to be reentrant.
1702      *
1703      * @see release_buffer(), reget_buffer()
1704      * @see avcodec_align_dimensions2()
1705      *
1706      * Audio:
1707      *
1708      * Decoders request a buffer of a particular size by setting
1709      * AVFrame.nb_samples prior to calling get_buffer(). The decoder may,
1710      * however, utilize only part of the buffer by setting AVFrame.nb_samples
1711      * to a smaller value in the output frame.
1712      *
1713      * Decoders cannot use the buffer after returning from
1714      * avcodec_decode_audio4(), so they will not call release_buffer(), as it
1715      * is assumed to be released immediately upon return.
1716      *
1717      * As a convenience, av_samples_get_buffer_size() and
1718      * av_samples_fill_arrays() in libavutil may be used by custom get_buffer()
1719      * functions to find the required data size and to fill data pointers and
1720      * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
1721      * since all planes must be the same size.
1722      *
1723      * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
1724      *
1725      * - encoding: unused
1726      * - decoding: Set by libavcodec, user can override.
1727      */
1728     int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
1729
1730     /**
1731      * Called to release buffers which were allocated with get_buffer.
1732      * A released buffer can be reused in get_buffer().
1733      * pic.data[*] must be set to NULL.
1734      * May be called from a different thread if frame multithreading is used,
1735      * but not by more than one thread at once, so does not need to be reentrant.
1736      * - encoding: unused
1737      * - decoding: Set by libavcodec, user can override.
1738      */
1739     void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
1740
1741     /**
1742      * Size of the frame reordering buffer in the decoder.
1743      * For MPEG-2 it is 1 IPB or 0 low delay IP.
1744      * - encoding: Set by libavcodec.
1745      * - decoding: Set by libavcodec.
1746      */
1747     int has_b_frames;
1748
1749     /**
1750      * number of bytes per packet if constant and known or 0
1751      * Used by some WAV based audio codecs.
1752      */
1753     int block_align;
1754
1755 #if FF_API_PARSE_FRAME
1756     /**
1757      * If true, only parsing is done. The frame data is returned.
1758      * Only MPEG audio decoders support this now.
1759      * - encoding: unused
1760      * - decoding: Set by user
1761      */
1762     attribute_deprecated int parse_only;
1763 #endif
1764
1765     /**
1766      * 0-> h263 quant 1-> mpeg quant
1767      * - encoding: Set by user.
1768      * - decoding: unused
1769      */
1770     int mpeg_quant;
1771
1772     /**
1773      * pass1 encoding statistics output buffer
1774      * - encoding: Set by libavcodec.
1775      * - decoding: unused
1776      */
1777     char *stats_out;
1778
1779     /**
1780      * pass2 encoding statistics input buffer
1781      * Concatenated stuff from stats_out of pass1 should be placed here.
1782      * - encoding: Allocated/set/freed by user.
1783      * - decoding: unused
1784      */
1785     char *stats_in;
1786
1787     /**
1788      * ratecontrol qmin qmax limiting method
1789      * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax.
1790      * - encoding: Set by user.
1791      * - decoding: unused
1792      */
1793     float rc_qsquish;
1794
1795     float rc_qmod_amp;
1796     int rc_qmod_freq;
1797
1798     /**
1799      * ratecontrol override, see RcOverride
1800      * - encoding: Allocated/set/freed by user.
1801      * - decoding: unused
1802      */
1803     RcOverride *rc_override;
1804     int rc_override_count;
1805
1806     /**
1807      * rate control equation
1808      * - encoding: Set by user
1809      * - decoding: unused
1810      */
1811     const char *rc_eq;
1812
1813     /**
1814      * maximum bitrate
1815      * - encoding: Set by user.
1816      * - decoding: unused
1817      */
1818     int rc_max_rate;
1819
1820     /**
1821      * minimum bitrate
1822      * - encoding: Set by user.
1823      * - decoding: unused
1824      */
1825     int rc_min_rate;
1826
1827     /**
1828      * decoder bitstream buffer size
1829      * - encoding: Set by user.
1830      * - decoding: unused
1831      */
1832     int rc_buffer_size;
1833     float rc_buffer_aggressivity;
1834
1835     /**
1836      * qscale factor between P and I-frames
1837      * If > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset).
1838      * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
1839      * - encoding: Set by user.
1840      * - decoding: unused
1841      */
1842     float i_quant_factor;
1843
1844     /**
1845      * qscale offset between P and I-frames
1846      * - encoding: Set by user.
1847      * - decoding: unused
1848      */
1849     float i_quant_offset;
1850
1851     /**
1852      * initial complexity for pass1 ratecontrol
1853      * - encoding: Set by user.
1854      * - decoding: unused
1855      */
1856     float rc_initial_cplx;
1857
1858     /**
1859      * DCT algorithm, see FF_DCT_* below
1860      * - encoding: Set by user.
1861      * - decoding: unused
1862      */
1863     int dct_algo;
1864 #define FF_DCT_AUTO    0
1865 #define FF_DCT_FASTINT 1
1866 #define FF_DCT_INT     2
1867 #define FF_DCT_MMX     3
1868 #define FF_DCT_MLIB    4
1869 #define FF_DCT_ALTIVEC 5
1870 #define FF_DCT_FAAN    6
1871
1872     /**
1873      * luminance masking (0-> disabled)
1874      * - encoding: Set by user.
1875      * - decoding: unused
1876      */
1877     float lumi_masking;
1878
1879     /**
1880      * temporary complexity masking (0-> disabled)
1881      * - encoding: Set by user.
1882      * - decoding: unused
1883      */
1884     float temporal_cplx_masking;
1885
1886     /**
1887      * spatial complexity masking (0-> disabled)
1888      * - encoding: Set by user.
1889      * - decoding: unused
1890      */
1891     float spatial_cplx_masking;
1892
1893     /**
1894      * p block masking (0-> disabled)
1895      * - encoding: Set by user.
1896      * - decoding: unused
1897      */
1898     float p_masking;
1899
1900     /**
1901      * darkness masking (0-> disabled)
1902      * - encoding: Set by user.
1903      * - decoding: unused
1904      */
1905     float dark_masking;
1906
1907     /**
1908      * IDCT algorithm, see FF_IDCT_* below.
1909      * - encoding: Set by user.
1910      * - decoding: Set by user.
1911      */
1912     int idct_algo;
1913 #define FF_IDCT_AUTO          0
1914 #define FF_IDCT_INT           1
1915 #define FF_IDCT_SIMPLE        2
1916 #define FF_IDCT_SIMPLEMMX     3
1917 #define FF_IDCT_LIBMPEG2MMX   4
1918 #define FF_IDCT_PS2           5
1919 #define FF_IDCT_MLIB          6
1920 #define FF_IDCT_ARM           7
1921 #define FF_IDCT_ALTIVEC       8
1922 #define FF_IDCT_SH4           9
1923 #define FF_IDCT_SIMPLEARM     10
1924 #define FF_IDCT_H264          11
1925 #define FF_IDCT_VP3           12
1926 #define FF_IDCT_IPP           13
1927 #define FF_IDCT_XVIDMMX       14
1928 #define FF_IDCT_CAVS          15
1929 #define FF_IDCT_SIMPLEARMV5TE 16
1930 #define FF_IDCT_SIMPLEARMV6   17
1931 #define FF_IDCT_SIMPLEVIS     18
1932 #define FF_IDCT_WMV2          19
1933 #define FF_IDCT_FAAN          20
1934 #define FF_IDCT_EA            21
1935 #define FF_IDCT_SIMPLENEON    22
1936 #define FF_IDCT_SIMPLEALPHA   23
1937 #define FF_IDCT_BINK          24
1938
1939     /**
1940      * slice count
1941      * - encoding: Set by libavcodec.
1942      * - decoding: Set by user (or 0).
1943      */
1944     int slice_count;
1945     /**
1946      * slice offsets in the frame in bytes
1947      * - encoding: Set/allocated by libavcodec.
1948      * - decoding: Set/allocated by user (or NULL).
1949      */
1950     int *slice_offset;
1951
1952     /**
1953      * error concealment flags
1954      * - encoding: unused
1955      * - decoding: Set by user.
1956      */
1957     int error_concealment;
1958 #define FF_EC_GUESS_MVS   1
1959 #define FF_EC_DEBLOCK     2
1960
1961     /**
1962      * dsp_mask could be add used to disable unwanted CPU features
1963      * CPU features (i.e. MMX, SSE. ...)
1964      *
1965      * With the FORCE flag you may instead enable given CPU features.
1966      * (Dangerous: Usable in case of misdetection, improper usage however will
1967      * result into program crash.)
1968      */
1969     unsigned dsp_mask;
1970
1971     /**
1972      * bits per sample/pixel from the demuxer (needed for huffyuv).
1973      * - encoding: Set by libavcodec.
1974      * - decoding: Set by user.
1975      */
1976      int bits_per_coded_sample;
1977
1978     /**
1979      * prediction method (needed for huffyuv)
1980      * - encoding: Set by user.
1981      * - decoding: unused
1982      */
1983      int prediction_method;
1984 #define FF_PRED_LEFT   0
1985 #define FF_PRED_PLANE  1
1986 #define FF_PRED_MEDIAN 2
1987
1988     /**
1989      * sample aspect ratio (0 if unknown)
1990      * That is the width of a pixel divided by the height of the pixel.
1991      * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
1992      * - encoding: Set by user.
1993      * - decoding: Set by libavcodec.
1994      */
1995     AVRational sample_aspect_ratio;
1996
1997     /**
1998      * the picture in the bitstream
1999      * - encoding: Set by libavcodec.
2000      * - decoding: Set by libavcodec.
2001      */
2002     AVFrame *coded_frame;
2003
2004     /**
2005      * debug
2006      * - encoding: Set by user.
2007      * - decoding: Set by user.
2008      */
2009     int debug;
2010 #define FF_DEBUG_PICT_INFO   1
2011 #define FF_DEBUG_RC          2
2012 #define FF_DEBUG_BITSTREAM   4
2013 #define FF_DEBUG_MB_TYPE     8
2014 #define FF_DEBUG_QP          16
2015 #define FF_DEBUG_MV          32
2016 #define FF_DEBUG_DCT_COEFF   0x00000040
2017 #define FF_DEBUG_SKIP        0x00000080
2018 #define FF_DEBUG_STARTCODE   0x00000100
2019 #define FF_DEBUG_PTS         0x00000200
2020 #define FF_DEBUG_ER          0x00000400
2021 #define FF_DEBUG_MMCO        0x00000800
2022 #define FF_DEBUG_BUGS        0x00001000
2023 #define FF_DEBUG_VIS_QP      0x00002000
2024 #define FF_DEBUG_VIS_MB_TYPE 0x00004000
2025 #define FF_DEBUG_BUFFERS     0x00008000
2026 #define FF_DEBUG_THREADS     0x00010000
2027
2028     /**
2029      * debug
2030      * - encoding: Set by user.
2031      * - decoding: Set by user.
2032      */
2033     int debug_mv;
2034 #define FF_DEBUG_VIS_MV_P_FOR  0x00000001 //visualize forward predicted MVs of P frames
2035 #define FF_DEBUG_VIS_MV_B_FOR  0x00000002 //visualize forward predicted MVs of B frames
2036 #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
2037
2038     /**
2039      * error
2040      * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR.
2041      * - decoding: unused
2042      */
2043     uint64_t error[AV_NUM_DATA_POINTERS];
2044
2045     /**
2046      * motion estimation comparison function
2047      * - encoding: Set by user.
2048      * - decoding: unused
2049      */
2050     int me_cmp;
2051     /**
2052      * subpixel motion estimation comparison function
2053      * - encoding: Set by user.
2054      * - decoding: unused
2055      */
2056     int me_sub_cmp;
2057     /**
2058      * macroblock comparison function (not supported yet)
2059      * - encoding: Set by user.
2060      * - decoding: unused
2061      */
2062     int mb_cmp;
2063     /**
2064      * interlaced DCT comparison function
2065      * - encoding: Set by user.
2066      * - decoding: unused
2067      */
2068     int ildct_cmp;
2069 #define FF_CMP_SAD    0
2070 #define FF_CMP_SSE    1
2071 #define FF_CMP_SATD   2
2072 #define FF_CMP_DCT    3
2073 #define FF_CMP_PSNR   4
2074 #define FF_CMP_BIT    5
2075 #define FF_CMP_RD     6
2076 #define FF_CMP_ZERO   7
2077 #define FF_CMP_VSAD   8
2078 #define FF_CMP_VSSE   9
2079 #define FF_CMP_NSSE   10
2080 #define FF_CMP_W53    11
2081 #define FF_CMP_W97    12
2082 #define FF_CMP_DCTMAX 13
2083 #define FF_CMP_DCT264 14
2084 #define FF_CMP_CHROMA 256
2085
2086     /**
2087      * ME diamond size & shape
2088      * - encoding: Set by user.
2089      * - decoding: unused
2090      */
2091     int dia_size;
2092
2093     /**
2094      * amount of previous MV predictors (2a+1 x 2a+1 square)
2095      * - encoding: Set by user.
2096      * - decoding: unused
2097      */
2098     int last_predictor_count;
2099
2100     /**
2101      * prepass for motion estimation
2102      * - encoding: Set by user.
2103      * - decoding: unused
2104      */
2105     int pre_me;
2106
2107     /**
2108      * motion estimation prepass comparison function
2109      * - encoding: Set by user.
2110      * - decoding: unused
2111      */
2112     int me_pre_cmp;
2113
2114     /**
2115      * ME prepass diamond size & shape
2116      * - encoding: Set by user.
2117      * - decoding: unused
2118      */
2119     int pre_dia_size;
2120
2121     /**
2122      * subpel ME quality
2123      * - encoding: Set by user.
2124      * - decoding: unused
2125      */
2126     int me_subpel_quality;
2127
2128     /**
2129      * callback to negotiate the pixelFormat
2130      * @param fmt is the list of formats which are supported by the codec,
2131      * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
2132      * The first is always the native one.
2133      * @return the chosen format
2134      * - encoding: unused
2135      * - decoding: Set by user, if not set the native format will be chosen.
2136      */
2137     enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt);
2138
2139     /**
2140      * DTG active format information (additional aspect ratio
2141      * information only used in DVB MPEG-2 transport streams)
2142      * 0 if not set.
2143      *
2144      * - encoding: unused
2145      * - decoding: Set by decoder.
2146      */
2147     int dtg_active_format;
2148 #define FF_DTG_AFD_SAME         8
2149 #define FF_DTG_AFD_4_3          9
2150 #define FF_DTG_AFD_16_9         10
2151 #define FF_DTG_AFD_14_9         11
2152 #define FF_DTG_AFD_4_3_SP_14_9  13
2153 #define FF_DTG_AFD_16_9_SP_14_9 14
2154 #define FF_DTG_AFD_SP_4_3       15
2155
2156     /**
2157      * maximum motion estimation search range in subpel units
2158      * If 0 then no limit.
2159      *
2160      * - encoding: Set by user.
2161      * - decoding: unused
2162      */
2163     int me_range;
2164
2165     /**
2166      * intra quantizer bias
2167      * - encoding: Set by user.
2168      * - decoding: unused
2169      */
2170     int intra_quant_bias;
2171 #define FF_DEFAULT_QUANT_BIAS 999999
2172
2173     /**
2174      * inter quantizer bias
2175      * - encoding: Set by user.
2176      * - decoding: unused
2177      */
2178     int inter_quant_bias;
2179
2180     /**
2181      * color table ID
2182      * - encoding: unused
2183      * - decoding: Which clrtable should be used for 8bit RGB images.
2184      *             Tables have to be stored somewhere. FIXME
2185      */
2186     int color_table_id;
2187
2188 #if FF_API_INTERNAL_CONTEXT
2189     /**
2190      * internal_buffer count
2191      * Don't touch, used by libavcodec default_get_buffer().
2192      * @deprecated this field was moved to an internal context
2193      */
2194     attribute_deprecated int internal_buffer_count;
2195
2196     /**
2197      * internal_buffers
2198      * Don't touch, used by libavcodec default_get_buffer().
2199      * @deprecated this field was moved to an internal context
2200      */
2201     attribute_deprecated void *internal_buffer;
2202 #endif
2203
2204     /**
2205      * Global quality for codecs which cannot change it per frame.
2206      * This should be proportional to MPEG-1/2/4 qscale.
2207      * - encoding: Set by user.
2208      * - decoding: unused
2209      */
2210     int global_quality;
2211
2212 #define FF_CODER_TYPE_VLC       0
2213 #define FF_CODER_TYPE_AC        1
2214 #define FF_CODER_TYPE_RAW       2
2215 #define FF_CODER_TYPE_RLE       3
2216 #define FF_CODER_TYPE_DEFLATE   4
2217     /**
2218      * coder type
2219      * - encoding: Set by user.
2220      * - decoding: unused
2221      */
2222     int coder_type;
2223
2224     /**
2225      * context model
2226      * - encoding: Set by user.
2227      * - decoding: unused
2228      */
2229     int context_model;
2230 #if 0
2231     /**
2232      *
2233      * - encoding: unused
2234      * - decoding: Set by user.
2235      */
2236     uint8_t * (*realloc)(struct AVCodecContext *s, uint8_t *buf, int buf_size);
2237 #endif
2238
2239     /**
2240      * slice flags
2241      * - encoding: unused
2242      * - decoding: Set by user.
2243      */
2244     int slice_flags;
2245 #define SLICE_FLAG_CODED_ORDER    0x0001 ///< draw_horiz_band() is called in coded order instead of display
2246 #define SLICE_FLAG_ALLOW_FIELD    0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
2247 #define SLICE_FLAG_ALLOW_PLANE    0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
2248
2249     /**
2250      * XVideo Motion Acceleration
2251      * - encoding: forbidden
2252      * - decoding: set by decoder
2253      */
2254     int xvmc_acceleration;
2255
2256     /**
2257      * macroblock decision mode
2258      * - encoding: Set by user.
2259      * - decoding: unused
2260      */
2261     int mb_decision;
2262 #define FF_MB_DECISION_SIMPLE 0        ///< uses mb_cmp
2263 #define FF_MB_DECISION_BITS   1        ///< chooses the one which needs the fewest bits
2264 #define FF_MB_DECISION_RD     2        ///< rate distortion
2265
2266     /**
2267      * custom intra quantization matrix
2268      * - encoding: Set by user, can be NULL.
2269      * - decoding: Set by libavcodec.
2270      */
2271     uint16_t *intra_matrix;
2272
2273     /**
2274      * custom inter quantization matrix
2275      * - encoding: Set by user, can be NULL.
2276      * - decoding: Set by libavcodec.
2277      */
2278     uint16_t *inter_matrix;
2279
2280     /**
2281      * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
2282      * This is used to work around some encoder bugs.
2283      * - encoding: unused
2284      * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
2285      */
2286     unsigned int stream_codec_tag;
2287
2288     /**
2289      * scene change detection threshold
2290      * 0 is default, larger means fewer detected scene changes.
2291      * - encoding: Set by user.
2292      * - decoding: unused
2293      */
2294     int scenechange_threshold;
2295
2296     /**
2297      * minimum Lagrange multipler
2298      * - encoding: Set by user.
2299      * - decoding: unused
2300      */
2301     int lmin;
2302
2303     /**
2304      * maximum Lagrange multipler
2305      * - encoding: Set by user.
2306      * - decoding: unused
2307      */
2308     int lmax;
2309
2310 #if FF_API_PALETTE_CONTROL
2311     /**
2312      * palette control structure
2313      * - encoding: ??? (no palette-enabled encoder yet)
2314      * - decoding: Set by user.
2315      */
2316     struct AVPaletteControl *palctrl;
2317 #endif
2318
2319     /**
2320      * noise reduction strength
2321      * - encoding: Set by user.
2322      * - decoding: unused
2323      */
2324     int noise_reduction;
2325
2326     /**
2327      * Called at the beginning of a frame to get cr buffer for it.
2328      * Buffer type (size, hints) must be the same. libavcodec won't check it.
2329      * libavcodec will pass previous buffer in pic, function should return
2330      * same buffer or new buffer with old frame "painted" into it.
2331      * If pic.data[0] == NULL must behave like get_buffer().
2332      * if CODEC_CAP_DR1 is not set then reget_buffer() must call
2333      * avcodec_default_reget_buffer() instead of providing buffers allocated by
2334      * some other means.
2335      * - encoding: unused
2336      * - decoding: Set by libavcodec, user can override.
2337      */
2338     int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
2339
2340     /**
2341      * Number of bits which should be loaded into the rc buffer before decoding starts.
2342      * - encoding: Set by user.
2343      * - decoding: unused
2344      */
2345     int rc_initial_buffer_occupancy;
2346
2347     /**
2348      *
2349      * - encoding: Set by user.
2350      * - decoding: unused
2351      */
2352     int inter_threshold;
2353
2354     /**
2355      * CODEC_FLAG2_*
2356      * - encoding: Set by user.
2357      * - decoding: Set by user.
2358      */
2359     int flags2;
2360
2361     /**
2362      * Simulates errors in the bitstream to test error concealment.
2363      * - encoding: Set by user.
2364      * - decoding: unused
2365      */
2366     int error_rate;
2367
2368 #if FF_API_ANTIALIAS_ALGO
2369     /**
2370      * MP3 antialias algorithm, see FF_AA_* below.
2371      * - encoding: unused
2372      * - decoding: Set by user.
2373      */
2374     attribute_deprecated int antialias_algo;
2375 #define FF_AA_AUTO    0
2376 #define FF_AA_FASTINT 1 //not implemented yet
2377 #define FF_AA_INT     2
2378 #define FF_AA_FLOAT   3
2379 #endif
2380
2381     /**
2382      * quantizer noise shaping
2383      * - encoding: Set by user.
2384      * - decoding: unused
2385      */
2386     int quantizer_noise_shaping;
2387
2388     /**
2389      * thread count
2390      * is used to decide how many independent tasks should be passed to execute()
2391      * - encoding: Set by user.
2392      * - decoding: Set by user.
2393      */
2394     int thread_count;
2395
2396     /**
2397      * The codec may call this to execute several independent things.
2398      * It will return only after finishing all tasks.
2399      * The user may replace this with some multithreaded implementation,
2400      * the default implementation will execute the parts serially.
2401      * @param count the number of things to execute
2402      * - encoding: Set by libavcodec, user can override.
2403      * - decoding: Set by libavcodec, user can override.
2404      */
2405     int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
2406
2407     /**
2408      * thread opaque
2409      * Can be used by execute() to store some per AVCodecContext stuff.
2410      * - encoding: set by execute()
2411      * - decoding: set by execute()
2412      */
2413     void *thread_opaque;
2414
2415     /**
2416      * Motion estimation threshold below which no motion estimation is
2417      * performed, but instead the user specified motion vectors are used.
2418      *
2419      * - encoding: Set by user.
2420      * - decoding: unused
2421      */
2422      int me_threshold;
2423
2424     /**
2425      * Macroblock threshold below which the user specified macroblock types will be used.
2426      * - encoding: Set by user.
2427      * - decoding: unused
2428      */
2429      int mb_threshold;
2430
2431     /**
2432      * precision of the intra DC coefficient - 8
2433      * - encoding: Set by user.
2434      * - decoding: unused
2435      */
2436      int intra_dc_precision;
2437
2438     /**
2439      * noise vs. sse weight for the nsse comparsion function
2440      * - encoding: Set by user.
2441      * - decoding: unused
2442      */
2443      int nsse_weight;
2444
2445     /**
2446      * Number of macroblock rows at the top which are skipped.
2447      * - encoding: unused
2448      * - decoding: Set by user.
2449      */
2450      int skip_top;
2451
2452     /**
2453      * Number of macroblock rows at the bottom which are skipped.
2454      * - encoding: unused
2455      * - decoding: Set by user.
2456      */
2457      int skip_bottom;
2458
2459     /**
2460      * profile
2461      * - encoding: Set by user.
2462      * - decoding: Set by libavcodec.
2463      */
2464      int profile;
2465 #define FF_PROFILE_UNKNOWN -99
2466 #define FF_PROFILE_RESERVED -100
2467
2468 #define FF_PROFILE_AAC_MAIN 0
2469 #define FF_PROFILE_AAC_LOW  1
2470 #define FF_PROFILE_AAC_SSR  2
2471 #define FF_PROFILE_AAC_LTP  3
2472
2473 #define FF_PROFILE_DTS         20
2474 #define FF_PROFILE_DTS_ES      30
2475 #define FF_PROFILE_DTS_96_24   40
2476 #define FF_PROFILE_DTS_HD_HRA  50
2477 #define FF_PROFILE_DTS_HD_MA   60
2478
2479 #define FF_PROFILE_MPEG2_422    0
2480 #define FF_PROFILE_MPEG2_HIGH   1
2481 #define FF_PROFILE_MPEG2_SS     2
2482 #define FF_PROFILE_MPEG2_SNR_SCALABLE  3
2483 #define FF_PROFILE_MPEG2_MAIN   4
2484 #define FF_PROFILE_MPEG2_SIMPLE 5
2485
2486 #define FF_PROFILE_H264_CONSTRAINED  (1<<9)  // 8+1; constraint_set1_flag
2487 #define FF_PROFILE_H264_INTRA        (1<<11) // 8+3; constraint_set3_flag
2488
2489 #define FF_PROFILE_H264_BASELINE             66
2490 #define FF_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
2491 #define FF_PROFILE_H264_MAIN                 77
2492 #define FF_PROFILE_H264_EXTENDED             88
2493 #define FF_PROFILE_H264_HIGH                 100
2494 #define FF_PROFILE_H264_HIGH_10              110
2495 #define FF_PROFILE_H264_HIGH_10_INTRA        (110|FF_PROFILE_H264_INTRA)
2496 #define FF_PROFILE_H264_HIGH_422             122
2497 #define FF_PROFILE_H264_HIGH_422_INTRA       (122|FF_PROFILE_H264_INTRA)
2498 #define FF_PROFILE_H264_HIGH_444             144
2499 #define FF_PROFILE_H264_HIGH_444_PREDICTIVE  244
2500 #define FF_PROFILE_H264_HIGH_444_INTRA       (244|FF_PROFILE_H264_INTRA)
2501 #define FF_PROFILE_H264_CAVLC_444            44
2502
2503 #define FF_PROFILE_VC1_SIMPLE   0
2504 #define FF_PROFILE_VC1_MAIN     1
2505 #define FF_PROFILE_VC1_COMPLEX  2
2506 #define FF_PROFILE_VC1_ADVANCED 3
2507
2508 #define FF_PROFILE_MPEG4_SIMPLE                     0
2509 #define FF_PROFILE_MPEG4_SIMPLE_SCALABLE            1
2510 #define FF_PROFILE_MPEG4_CORE                       2
2511 #define FF_PROFILE_MPEG4_MAIN                       3
2512 #define FF_PROFILE_MPEG4_N_BIT                      4
2513 #define FF_PROFILE_MPEG4_SCALABLE_TEXTURE           5
2514 #define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION      6
2515 #define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE     7
2516 #define FF_PROFILE_MPEG4_HYBRID                     8
2517 #define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME         9
2518 #define FF_PROFILE_MPEG4_CORE_SCALABLE             10
2519 #define FF_PROFILE_MPEG4_ADVANCED_CODING           11
2520 #define FF_PROFILE_MPEG4_ADVANCED_CORE             12
2521 #define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
2522 #define FF_PROFILE_MPEG4_SIMPLE_STUDIO             14
2523 #define FF_PROFILE_MPEG4_ADVANCED_SIMPLE           15
2524
2525     /**
2526      * level
2527      * - encoding: Set by user.
2528      * - decoding: Set by libavcodec.
2529      */
2530      int level;
2531 #define FF_LEVEL_UNKNOWN -99
2532
2533     /**
2534      * low resolution decoding, 1-> 1/2 size, 2->1/4 size
2535      * - encoding: unused
2536      * - decoding: Set by user.
2537      */
2538      int lowres;
2539
2540     /**
2541      * Bitstream width / height, may be different from width/height if lowres enabled.
2542      * - encoding: unused
2543      * - decoding: Set by user before init if known. Codec should override / dynamically change if needed.
2544      */
2545     int coded_width, coded_height;
2546
2547     /**
2548      * frame skip threshold
2549      * - encoding: Set by user.
2550      * - decoding: unused
2551      */
2552     int frame_skip_threshold;
2553
2554     /**
2555      * frame skip factor
2556      * - encoding: Set by user.
2557      * - decoding: unused
2558      */
2559     int frame_skip_factor;
2560
2561     /**
2562      * frame skip exponent
2563      * - encoding: Set by user.
2564      * - decoding: unused
2565      */
2566     int frame_skip_exp;
2567
2568     /**
2569      * frame skip comparison function
2570      * - encoding: Set by user.
2571      * - decoding: unused
2572      */
2573     int frame_skip_cmp;
2574
2575     /**
2576      * Border processing masking, raises the quantizer for mbs on the borders
2577      * of the picture.
2578      * - encoding: Set by user.
2579      * - decoding: unused
2580      */
2581     float border_masking;
2582
2583     /**
2584      * minimum MB lagrange multipler
2585      * - encoding: Set by user.
2586      * - decoding: unused
2587      */
2588     int mb_lmin;
2589
2590     /**
2591      * maximum MB lagrange multipler
2592      * - encoding: Set by user.
2593      * - decoding: unused
2594      */
2595     int mb_lmax;
2596
2597     /**
2598      *
2599      * - encoding: Set by user.
2600      * - decoding: unused
2601      */
2602     int me_penalty_compensation;
2603
2604     /**
2605      *
2606      * - encoding: unused
2607      * - decoding: Set by user.
2608      */
2609     enum AVDiscard skip_loop_filter;
2610
2611     /**
2612      *
2613      * - encoding: unused
2614      * - decoding: Set by user.
2615      */
2616     enum AVDiscard skip_idct;
2617
2618     /**
2619      *
2620      * - encoding: unused
2621      * - decoding: Set by user.
2622      */
2623     enum AVDiscard skip_frame;
2624
2625     /**
2626      *
2627      * - encoding: Set by user.
2628      * - decoding: unused
2629      */
2630     int bidir_refine;
2631
2632     /**
2633      *
2634      * - encoding: Set by user.
2635      * - decoding: unused
2636      */
2637     int brd_scale;
2638
2639 #if FF_API_X264_GLOBAL_OPTS
2640     /**
2641      * constant rate factor - quality-based VBR - values ~correspond to qps
2642      * - encoding: Set by user.
2643      * - decoding: unused
2644      *   @deprecated use 'crf' libx264 private option
2645      */
2646     attribute_deprecated float crf;
2647
2648     /**
2649      * constant quantization parameter rate control method
2650      * - encoding: Set by user.
2651      * - decoding: unused
2652      *   @deprecated use 'cqp' libx264 private option
2653      */
2654     attribute_deprecated int cqp;
2655 #endif
2656
2657     /**
2658      * minimum GOP size
2659      * - encoding: Set by user.
2660      * - decoding: unused
2661      */
2662     int keyint_min;
2663
2664     /**
2665      * number of reference frames
2666      * - encoding: Set by user.
2667      * - decoding: Set by lavc.
2668      */
2669     int refs;
2670
2671     /**
2672      * chroma qp offset from luma
2673      * - encoding: Set by user.
2674      * - decoding: unused
2675      */
2676     int chromaoffset;
2677
2678 #if FF_API_X264_GLOBAL_OPTS
2679     /**
2680      * Influence how often B-frames are used.
2681      * - encoding: Set by user.
2682      * - decoding: unused
2683      */
2684     attribute_deprecated int bframebias;
2685 #endif
2686
2687     /**
2688      * trellis RD quantization
2689      * - encoding: Set by user.
2690      * - decoding: unused
2691      */
2692     int trellis;
2693
2694 #if FF_API_X264_GLOBAL_OPTS
2695     /**
2696      * Reduce fluctuations in qp (before curve compression).
2697      * - encoding: Set by user.
2698      * - decoding: unused
2699      */
2700     attribute_deprecated float complexityblur;
2701
2702     /**
2703      * in-loop deblocking filter alphac0 parameter
2704      * alpha is in the range -6...6
2705      * - encoding: Set by user.
2706      * - decoding: unused
2707      */
2708     attribute_deprecated int deblockalpha;
2709
2710     /**
2711      * in-loop deblocking filter beta parameter
2712      * beta is in the range -6...6
2713      * - encoding: Set by user.
2714      * - decoding: unused
2715      */
2716     attribute_deprecated int deblockbeta;
2717
2718     /**
2719      * macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4
2720      * - encoding: Set by user.
2721      * - decoding: unused
2722      */
2723     attribute_deprecated int partitions;
2724 #define X264_PART_I4X4 0x001  /* Analyze i4x4 */
2725 #define X264_PART_I8X8 0x002  /* Analyze i8x8 (requires 8x8 transform) */
2726 #define X264_PART_P8X8 0x010  /* Analyze p16x8, p8x16 and p8x8 */
2727 #define X264_PART_P4X4 0x020  /* Analyze p8x4, p4x8, p4x4 */
2728 #define X264_PART_B8X8 0x100  /* Analyze b16x8, b8x16 and b8x8 */
2729
2730     /**
2731      * direct MV prediction mode - 0 (none), 1 (spatial), 2 (temporal), 3 (auto)
2732      * - encoding: Set by user.
2733      * - decoding: unused
2734      */
2735     attribute_deprecated int directpred;
2736 #endif
2737
2738     /**
2739      * Audio cutoff bandwidth (0 means "automatic")
2740      * - encoding: Set by user.
2741      * - decoding: unused
2742      */
2743     int cutoff;
2744
2745     /**
2746      * Multiplied by qscale for each frame and added to scene_change_score.
2747      * - encoding: Set by user.
2748      * - decoding: unused
2749      */
2750     int scenechange_factor;
2751
2752     /**
2753      *
2754      * Note: Value depends upon the compare function used for fullpel ME.
2755      * - encoding: Set by user.
2756      * - decoding: unused
2757      */
2758     int mv0_threshold;
2759
2760     /**
2761      * Adjust sensitivity of b_frame_strategy 1.
2762      * - encoding: Set by user.
2763      * - decoding: unused
2764      */
2765     int b_sensitivity;
2766
2767     /**
2768      * - encoding: Set by user.
2769      * - decoding: unused
2770      */
2771     int compression_level;
2772 #define FF_COMPRESSION_DEFAULT -1
2773
2774     /**
2775      * - encoding: Set by user.
2776      * - decoding: unused
2777      */
2778     int min_prediction_order;
2779
2780     /**
2781      * - encoding: Set by user.
2782      * - decoding: unused
2783      */
2784     int max_prediction_order;
2785
2786 #if FF_API_FLAC_GLOBAL_OPTS
2787     /**
2788      * @name FLAC options
2789      * @deprecated Use FLAC encoder private options instead.
2790      * @{
2791      */
2792
2793     /**
2794      * LPC coefficient precision - used by FLAC encoder
2795      * - encoding: Set by user.
2796      * - decoding: unused
2797      */
2798     attribute_deprecated int lpc_coeff_precision;
2799
2800     /**
2801      * search method for selecting prediction order
2802      * - encoding: Set by user.
2803      * - decoding: unused
2804      */
2805     attribute_deprecated int prediction_order_method;
2806
2807     /**
2808      * - encoding: Set by user.
2809      * - decoding: unused
2810      */
2811     attribute_deprecated int min_partition_order;
2812
2813     /**
2814      * - encoding: Set by user.
2815      * - decoding: unused
2816      */
2817     attribute_deprecated int max_partition_order;
2818     /**
2819      * @}
2820      */
2821 #endif
2822
2823     /**
2824      * GOP timecode frame start number, in non drop frame format
2825      * - encoding: Set by user.
2826      * - decoding: unused
2827      */
2828     int64_t timecode_frame_start;
2829
2830 #if FF_API_REQUEST_CHANNELS
2831     /**
2832      * Decoder should decode to this many channels if it can (0 for default)
2833      * - encoding: unused
2834      * - decoding: Set by user.
2835      * @deprecated Deprecated in favor of request_channel_layout.
2836      */
2837     int request_channels;
2838 #endif
2839
2840 #if FF_API_DRC_SCALE
2841     /**
2842      * Percentage of dynamic range compression to be applied by the decoder.
2843      * The default value is 1.0, corresponding to full compression.
2844      * - encoding: unused
2845      * - decoding: Set by user.
2846      * @deprecated use AC3 decoder private option instead.
2847      */
2848     attribute_deprecated float drc_scale;
2849 #endif
2850
2851     /**
2852      * opaque 64bit number (generally a PTS) that will be reordered and
2853      * output in AVFrame.reordered_opaque
2854      * @deprecated in favor of pkt_pts
2855      * - encoding: unused
2856      * - decoding: Set by user.
2857      */
2858     int64_t reordered_opaque;
2859
2860     /**
2861      * Bits per sample/pixel of internal libavcodec pixel/sample format.
2862      * - encoding: set by user.
2863      * - decoding: set by libavcodec.
2864      */
2865     int bits_per_raw_sample;
2866
2867     /**
2868      * Audio channel layout.
2869      * - encoding: set by user.
2870      * - decoding: set by libavcodec.
2871      */
2872     uint64_t channel_layout;
2873
2874     /**
2875      * Request decoder to use this channel layout if it can (0 for default)
2876      * - encoding: unused
2877      * - decoding: Set by user.
2878      */
2879     uint64_t request_channel_layout;
2880
2881     /**
2882      * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
2883      * - encoding: Set by user.
2884      * - decoding: unused.
2885      */
2886     float rc_max_available_vbv_use;
2887
2888     /**
2889      * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
2890      * - encoding: Set by user.
2891      * - decoding: unused.
2892      */
2893     float rc_min_vbv_overflow_use;
2894
2895     /**
2896      * Hardware accelerator in use
2897      * - encoding: unused.
2898      * - decoding: Set by libavcodec
2899      */
2900     struct AVHWAccel *hwaccel;
2901
2902     /**
2903      * For some codecs, the time base is closer to the field rate than the frame rate.
2904      * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
2905      * if no telecine is used ...
2906      *
2907      * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
2908      */
2909     int ticks_per_frame;
2910
2911     /**
2912      * Hardware accelerator context.
2913      * For some hardware accelerators, a global context needs to be
2914      * provided by the user. In that case, this holds display-dependent
2915      * data Libav cannot instantiate itself. Please refer to the
2916      * Libav HW accelerator documentation to know how to fill this
2917      * is. e.g. for VA API, this is a struct vaapi_context.
2918      * - encoding: unused
2919      * - decoding: Set by user
2920      */
2921     void *hwaccel_context;
2922
2923     /**
2924      * Chromaticity coordinates of the source primaries.
2925      * - encoding: Set by user
2926      * - decoding: Set by libavcodec
2927      */
2928     enum AVColorPrimaries color_primaries;
2929
2930     /**
2931      * Color Transfer Characteristic.
2932      * - encoding: Set by user
2933      * - decoding: Set by libavcodec
2934      */
2935     enum AVColorTransferCharacteristic color_trc;
2936
2937     /**
2938      * YUV colorspace type.
2939      * - encoding: Set by user
2940      * - decoding: Set by libavcodec
2941      */
2942     enum AVColorSpace colorspace;
2943
2944     /**
2945      * MPEG vs JPEG YUV range.
2946      * - encoding: Set by user
2947      * - decoding: Set by libavcodec
2948      */
2949     enum AVColorRange color_range;
2950
2951     /**
2952      * This defines the location of chroma samples.
2953      * - encoding: Set by user
2954      * - decoding: Set by libavcodec
2955      */
2956     enum AVChromaLocation chroma_sample_location;
2957
2958     /**
2959      * The codec may call this to execute several independent things.
2960      * It will return only after finishing all tasks.
2961      * The user may replace this with some multithreaded implementation,
2962      * the default implementation will execute the parts serially.
2963      * Also see avcodec_thread_init and e.g. the --enable-pthread configure option.
2964      * @param c context passed also to func
2965      * @param count the number of things to execute
2966      * @param arg2 argument passed unchanged to func
2967      * @param ret return values of executed functions, must have space for "count" values. May be NULL.
2968      * @param func function that will be called count times, with jobnr from 0 to count-1.
2969      *             threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no
2970      *             two instances of func executing at the same time will have the same threadnr.
2971      * @return always 0 currently, but code should handle a future improvement where when any call to func
2972      *         returns < 0 no further calls to func may be done and < 0 is returned.
2973      * - encoding: Set by libavcodec, user can override.
2974      * - decoding: Set by libavcodec, user can override.
2975      */
2976     int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count);
2977
2978 #if FF_API_X264_GLOBAL_OPTS
2979     /**
2980      * explicit P-frame weighted prediction analysis method
2981      * 0: off
2982      * 1: fast blind weighting (one reference duplicate with -1 offset)
2983      * 2: smart weighting (full fade detection analysis)
2984      * - encoding: Set by user.
2985      * - decoding: unused
2986      */
2987     attribute_deprecated int weighted_p_pred;
2988
2989     /**
2990      * AQ mode
2991      * 0: Disabled
2992      * 1: Variance AQ (complexity mask)
2993      * 2: Auto-variance AQ (experimental)
2994      * - encoding: Set by user
2995      * - decoding: unused
2996      */
2997     attribute_deprecated int aq_mode;
2998
2999     /**
3000      * AQ strength
3001      * Reduces blocking and blurring in flat and textured areas.
3002      * - encoding: Set by user
3003      * - decoding: unused
3004      */
3005     attribute_deprecated float aq_strength;
3006
3007     /**
3008      * PSY RD
3009      * Strength of psychovisual optimization
3010      * - encoding: Set by user
3011      * - decoding: unused
3012      */
3013     attribute_deprecated float psy_rd;
3014
3015     /**
3016      * PSY trellis
3017      * Strength of psychovisual optimization
3018      * - encoding: Set by user
3019      * - decoding: unused
3020      */
3021     attribute_deprecated float psy_trellis;
3022
3023     /**
3024      * RC lookahead
3025      * Number of frames for frametype and ratecontrol lookahead
3026      * - encoding: Set by user
3027      * - decoding: unused
3028      */
3029     attribute_deprecated int rc_lookahead;
3030
3031     /**
3032      * Constant rate factor maximum
3033      * With CRF encoding mode and VBV restrictions enabled, prevents quality from being worse
3034      * than crf_max, even if doing so would violate VBV restrictions.
3035      * - encoding: Set by user.
3036      * - decoding: unused
3037      */
3038     attribute_deprecated float crf_max;
3039 #endif
3040
3041     int log_level_offset;
3042
3043 #if FF_API_FLAC_GLOBAL_OPTS
3044     /**
3045      * Determine which LPC analysis algorithm to use.
3046      * - encoding: Set by user
3047      * - decoding: unused
3048      */
3049     attribute_deprecated enum AVLPCType lpc_type;
3050
3051     /**
3052      * Number of passes to use for Cholesky factorization during LPC analysis
3053      * - encoding: Set by user
3054      * - decoding: unused
3055      */
3056     attribute_deprecated int lpc_passes;
3057 #endif
3058
3059     /**
3060      * Number of slices.
3061      * Indicates number of picture subdivisions. Used for parallelized
3062      * decoding.
3063      * - encoding: Set by user
3064      * - decoding: unused
3065      */
3066     int slices;
3067
3068     /**
3069      * Header containing style information for text subtitles.
3070      * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
3071      * [Script Info] and [V4+ Styles] section, plus the [Events] line and
3072      * the Format line following. It shouldn't include any Dialogue line.
3073      * - encoding: Set/allocated/freed by user (before avcodec_open2())
3074      * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2())
3075      */
3076     uint8_t *subtitle_header;
3077     int subtitle_header_size;
3078
3079     /**
3080      * Current packet as passed into the decoder, to avoid having
3081      * to pass the packet into every function. Currently only valid
3082      * inside lavc and get/release_buffer callbacks.
3083      * - decoding: set by avcodec_decode_*, read by get_buffer() for setting pkt_pts
3084      * - encoding: unused
3085      */
3086     AVPacket *pkt;
3087
3088 #if FF_API_INTERNAL_CONTEXT
3089     /**
3090      * Whether this is a copy of the context which had init() called on it.
3091      * This is used by multithreading - shared tables and picture pointers
3092      * should be freed from the original context only.
3093      * - encoding: Set by libavcodec.
3094      * - decoding: Set by libavcodec.
3095      *
3096      * @deprecated this field has been moved to an internal context
3097      */
3098     attribute_deprecated int is_copy;
3099 #endif
3100
3101     /**
3102      * Which multithreading methods to use.
3103      * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread,
3104      * so clients which cannot provide future frames should not use it.
3105      *
3106      * - encoding: Set by user, otherwise the default is used.
3107      * - decoding: Set by user, otherwise the default is used.
3108      */
3109     int thread_type;
3110 #define FF_THREAD_FRAME   1 ///< Decode more than one frame at once
3111 #define FF_THREAD_SLICE   2 ///< Decode more than one part of a single frame at once
3112
3113     /**
3114      * Which multithreading methods are in use by the codec.
3115      * - encoding: Set by libavcodec.
3116      * - decoding: Set by libavcodec.
3117      */
3118     int active_thread_type;
3119
3120     /**
3121      * Set by the client if its custom get_buffer() callback can be called
3122      * from another thread, which allows faster multithreaded decoding.
3123      * draw_horiz_band() will be called from other threads regardless of this setting.
3124      * Ignored if the default get_buffer() is used.
3125      * - encoding: Set by user.
3126      * - decoding: Set by user.
3127      */
3128     int thread_safe_callbacks;
3129
3130     /**
3131      * VBV delay coded in the last frame (in periods of a 27 MHz clock).
3132      * Used for compliant TS muxing.
3133      * - encoding: Set by libavcodec.
3134      * - decoding: unused.
3135      */
3136     uint64_t vbv_delay;
3137
3138     /**
3139      * Type of service that the audio stream conveys.
3140      * - encoding: Set by user.
3141      * - decoding: Set by libavcodec.
3142      */
3143     enum AVAudioServiceType audio_service_type;
3144
3145     /**
3146      * Used to request a sample format from the decoder.
3147      * - encoding: unused.
3148      * - decoding: Set by user.
3149      */
3150     enum AVSampleFormat request_sample_fmt;
3151
3152     /**
3153      * Error recognition; may misdetect some more or less valid parts as errors.
3154      * - encoding: unused
3155      * - decoding: Set by user.
3156      */
3157     int err_recognition;
3158 #define AV_EF_CRCCHECK  (1<<0)
3159 #define AV_EF_BITSTREAM (1<<1)
3160 #define AV_EF_BUFFER    (1<<2)
3161 #define AV_EF_EXPLODE   (1<<3)
3162
3163     /**
3164      * Private context used for internal data.
3165      *
3166      * Unlike priv_data, this is not codec-specific. It is used in general
3167      * libavcodec functions.
3168      */
3169     struct AVCodecInternal *internal;
3170
3171     /** Field order
3172      * - encoding: set by libavcodec
3173      * - decoding: Set by libavcodec
3174      */
3175     enum AVFieldOrder field_order;
3176 } AVCodecContext;
3177
3178 /**
3179  * AVProfile.
3180  */
3181 typedef struct AVProfile {
3182     int profile;
3183     const char *name; ///< short name for the profile
3184 } AVProfile;
3185
3186 typedef struct AVCodecDefault AVCodecDefault;
3187
3188 /**
3189  * AVCodec.
3190  */
3191 typedef struct AVCodec {
3192     /**
3193      * Name of the codec implementation.
3194      * The name is globally unique among encoders and among decoders (but an
3195      * encoder and a decoder can share the same name).
3196      * This is the primary way to find a codec from the user perspective.
3197      */
3198     const char *name;
3199     enum AVMediaType type;
3200     enum CodecID id;
3201     int priv_data_size;
3202     int (*init)(AVCodecContext *);
3203     int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
3204     int (*close)(AVCodecContext *);
3205     int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
3206     /**
3207      * Codec capabilities.
3208      * see CODEC_CAP_*
3209      */
3210     int capabilities;
3211     struct AVCodec *next;
3212     /**
3213      * Flush buffers.
3214      * Will be called when seeking
3215      */
3216     void (*flush)(AVCodecContext *);
3217     const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
3218     const enum PixelFormat *pix_fmts;       ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
3219     /**
3220      * Descriptive name for the codec, meant to be more human readable than name.
3221      * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
3222      */
3223     const char *long_name;
3224     const int *supported_samplerates;       ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
3225     const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
3226     const uint64_t *channel_layouts;         ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
3227     uint8_t max_lowres;                     ///< maximum value for lowres supported by the decoder
3228     const AVClass *priv_class;              ///< AVClass for the private context
3229     const AVProfile *profiles;              ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
3230
3231     /**
3232      * @name Frame-level threading support functions
3233      * @{
3234      */
3235     /**
3236      * If defined, called on thread contexts when they are created.
3237      * If the codec allocates writable tables in init(), re-allocate them here.
3238      * priv_data will be set to a copy of the original.
3239      */
3240     int (*init_thread_copy)(AVCodecContext *);
3241     /**
3242      * Copy necessary context variables from a previous thread context to the current one.
3243      * If not defined, the next thread will start automatically; otherwise, the codec
3244      * must call ff_thread_finish_setup().
3245      *
3246      * dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
3247      */
3248     int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
3249     /** @} */
3250
3251     /**
3252      * Private codec-specific defaults.
3253      */
3254     const AVCodecDefault *defaults;
3255
3256     /**
3257      * Initialize codec static data, called from avcodec_register().
3258      */
3259     void (*init_static_data)(struct AVCodec *codec);
3260
3261     /**
3262      * Encode data to an AVPacket.
3263      *
3264      * @param      avctx          codec context
3265      * @param      avpkt          output AVPacket (may contain a user-provided buffer)
3266      * @param[in]  frame          AVFrame containing the raw data to be encoded
3267      * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
3268      *                            non-empty packet was returned in avpkt.
3269      * @return 0 on success, negative error code on failure
3270      */
3271     int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,
3272                    int *got_packet_ptr);
3273 } AVCodec;
3274
3275 /**
3276  * AVHWAccel.
3277  */
3278 typedef struct AVHWAccel {
3279     /**
3280      * Name of the hardware accelerated codec.
3281      * The name is globally unique among encoders and among decoders (but an
3282      * encoder and a decoder can share the same name).
3283      */
3284     const char *name;
3285
3286     /**
3287      * Type of codec implemented by the hardware accelerator.
3288      *
3289      * See AVMEDIA_TYPE_xxx
3290      */
3291     enum AVMediaType type;
3292
3293     /**
3294      * Codec implemented by the hardware accelerator.
3295      *
3296      * See CODEC_ID_xxx
3297      */
3298     enum CodecID id;
3299
3300     /**
3301      * Supported pixel format.
3302      *
3303      * Only hardware accelerated formats are supported here.
3304      */
3305     enum PixelFormat pix_fmt;
3306
3307     /**
3308      * Hardware accelerated codec capabilities.
3309      * see FF_HWACCEL_CODEC_CAP_*
3310      */
3311     int capabilities;
3312
3313     struct AVHWAccel *next;
3314
3315     /**
3316      * Called at the beginning of each frame or field picture.
3317      *
3318      * Meaningful frame information (codec specific) is guaranteed to
3319      * be parsed at this point. This function is mandatory.
3320      *
3321      * Note that buf can be NULL along with buf_size set to 0.
3322      * Otherwise, this means the whole frame is available at this point.
3323      *
3324      * @param avctx the codec context
3325      * @param buf the frame data buffer base
3326      * @param buf_size the size of the frame in bytes
3327      * @return zero if successful, a negative value otherwise
3328      */
3329     int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
3330
3331     /**
3332      * Callback for each slice.
3333      *
3334      * Meaningful slice information (codec specific) is guaranteed to
3335      * be parsed at this point. This function is mandatory.
3336      *
3337      * @param avctx the codec context
3338      * @param buf the slice data buffer base
3339      * @param buf_size the size of the slice in bytes
3340      * @return zero if successful, a negative value otherwise
3341      */
3342     int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
3343
3344     /**
3345      * Called at the end of each frame or field picture.
3346      *
3347      * The whole picture is parsed at this point and can now be sent
3348      * to the hardware accelerator. This function is mandatory.
3349      *
3350      * @param avctx the codec context
3351      * @return zero if successful, a negative value otherwise
3352      */
3353     int (*end_frame)(AVCodecContext *avctx);
3354
3355     /**
3356      * Size of HW accelerator private data.
3357      *
3358      * Private data is allocated with av_mallocz() before
3359      * AVCodecContext.get_buffer() and deallocated after
3360      * AVCodecContext.release_buffer().
3361      */
3362     int priv_data_size;
3363 } AVHWAccel;
3364
3365 /**
3366  * four components are given, that's all.
3367  * the last component is alpha
3368  */
3369 typedef struct AVPicture {
3370     uint8_t *data[AV_NUM_DATA_POINTERS];
3371     int linesize[AV_NUM_DATA_POINTERS];     ///< number of bytes per line
3372 } AVPicture;
3373
3374 #define AVPALETTE_SIZE 1024
3375 #define AVPALETTE_COUNT 256
3376 #if FF_API_PALETTE_CONTROL
3377 /**
3378  * AVPaletteControl
3379  * This structure defines a method for communicating palette changes
3380  * between and demuxer and a decoder.
3381  *
3382  * @deprecated Use AVPacket to send palette changes instead.
3383  * This is totally broken.
3384  */
3385 typedef struct AVPaletteControl {
3386
3387     /* Demuxer sets this to 1 to indicate the palette has changed;
3388      * decoder resets to 0. */
3389     int palette_changed;
3390
3391     /* 4-byte ARGB palette entries, stored in native byte order; note that
3392      * the individual palette components should be on a 8-bit scale; if
3393      * the palette data comes from an IBM VGA native format, the component
3394      * data is probably 6 bits in size and needs to be scaled. */
3395     unsigned int palette[AVPALETTE_COUNT];
3396
3397 } AVPaletteControl attribute_deprecated;
3398 #endif
3399
3400 enum AVSubtitleType {
3401     SUBTITLE_NONE,
3402
3403     SUBTITLE_BITMAP,                ///< A bitmap, pict will be set
3404
3405     /**
3406      * Plain text, the text field must be set by the decoder and is
3407      * authoritative. ass and pict fields may contain approximations.
3408      */
3409     SUBTITLE_TEXT,
3410
3411     /**
3412      * Formatted text, the ass field must be set by the decoder and is
3413      * authoritative. pict and text fields may contain approximations.
3414      */
3415     SUBTITLE_ASS,
3416 };
3417
3418 typedef struct AVSubtitleRect {
3419     int x;         ///< top left corner  of pict, undefined when pict is not set
3420     int y;         ///< top left corner  of pict, undefined when pict is not set
3421     int w;         ///< width            of pict, undefined when pict is not set
3422     int h;         ///< height           of pict, undefined when pict is not set
3423     int nb_colors; ///< number of colors in pict, undefined when pict is not set
3424
3425     /**
3426      * data+linesize for the bitmap of this subtitle.
3427      * can be set for text/ass as well once they where rendered
3428      */
3429     AVPicture pict;
3430     enum AVSubtitleType type;
3431
3432     char *text;                     ///< 0 terminated plain UTF-8 text
3433
3434     /**
3435      * 0 terminated ASS/SSA compatible event line.
3436      * The pressentation of this is unaffected by the other values in this
3437      * struct.
3438      */
3439     char *ass;
3440 } AVSubtitleRect;
3441
3442 typedef struct AVSubtitle {
3443     uint16_t format; /* 0 = graphics */
3444     uint32_t start_display_time; /* relative to packet pts, in ms */
3445     uint32_t end_display_time; /* relative to packet pts, in ms */
3446     unsigned num_rects;
3447     AVSubtitleRect **rects;
3448     int64_t pts;    ///< Same as packet pts, in AV_TIME_BASE
3449 } AVSubtitle;
3450
3451 /* packet functions */
3452
3453 /**
3454  * @deprecated use NULL instead
3455  */
3456 attribute_deprecated void av_destruct_packet_nofree(AVPacket *pkt);
3457
3458 /**
3459  * Default packet destructor.
3460  */
3461 void av_destruct_packet(AVPacket *pkt);
3462
3463 /**
3464  * Initialize optional fields of a packet with default values.
3465  *
3466  * @param pkt packet
3467  */
3468 void av_init_packet(AVPacket *pkt);
3469
3470 /**
3471  * Allocate the payload of a packet and initialize its fields with
3472  * default values.
3473  *
3474  * @param pkt packet
3475  * @param size wanted payload size
3476  * @return 0 if OK, AVERROR_xxx otherwise
3477  */
3478 int av_new_packet(AVPacket *pkt, int size);
3479
3480 /**
3481  * Reduce packet size, correctly zeroing padding
3482  *
3483  * @param pkt packet
3484  * @param size new size
3485  */
3486 void av_shrink_packet(AVPacket *pkt, int size);
3487
3488 /**
3489  * Increase packet size, correctly zeroing padding
3490  *
3491  * @param pkt packet
3492  * @param grow_by number of bytes by which to increase the size of the packet
3493  */
3494 int av_grow_packet(AVPacket *pkt, int grow_by);
3495
3496 /**
3497  * @warning This is a hack - the packet memory allocation stuff is broken. The
3498  * packet is allocated if it was not really allocated.
3499  */
3500 int av_dup_packet(AVPacket *pkt);
3501
3502 /**
3503  * Free a packet.
3504  *
3505  * @param pkt packet to free
3506  */
3507 void av_free_packet(AVPacket *pkt);
3508
3509 /**
3510  * Allocate new information of a packet.
3511  *
3512  * @param pkt packet
3513  * @param type side information type
3514  * @param size side information size
3515  * @return pointer to fresh allocated data or NULL otherwise
3516  */
3517 uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
3518                                  int size);
3519
3520 /**
3521  * Get side information from packet.
3522  *
3523  * @param pkt packet
3524  * @param type desired side information type
3525  * @param size pointer for side information size to store (optional)
3526  * @return pointer to data if present or NULL otherwise
3527  */
3528 uint8_t* av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
3529                                  int *size);
3530
3531 /* resample.c */
3532
3533 struct ReSampleContext;
3534 struct AVResampleContext;
3535
3536 typedef struct ReSampleContext ReSampleContext;
3537
3538 /**
3539  *  Initialize audio resampling context.
3540  *
3541  * @param output_channels  number of output channels
3542  * @param input_channels   number of input channels
3543  * @param output_rate      output sample rate
3544  * @param input_rate       input sample rate
3545  * @param sample_fmt_out   requested output sample format
3546  * @param sample_fmt_in    input sample format
3547  * @param filter_length    length of each FIR filter in the filterbank relative to the cutoff frequency
3548  * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
3549  * @param linear           if 1 then the used FIR filter will be linearly interpolated
3550                            between the 2 closest, if 0 the closest will be used
3551  * @param cutoff           cutoff frequency, 1.0 corresponds to half the output sampling rate
3552  * @return allocated ReSampleContext, NULL if error occurred
3553  */
3554 ReSampleContext *av_audio_resample_init(int output_channels, int input_channels,
3555                                         int output_rate, int input_rate,
3556                                         enum AVSampleFormat sample_fmt_out,
3557                                         enum AVSampleFormat sample_fmt_in,
3558                                         int filter_length, int log2_phase_count,
3559                                         int linear, double cutoff);
3560
3561 int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
3562
3563 /**
3564  * Free resample context.
3565  *
3566  * @param s a non-NULL pointer to a resample context previously
3567  *          created with av_audio_resample_init()
3568  */
3569 void audio_resample_close(ReSampleContext *s);
3570
3571
3572 /**
3573  * Initialize an audio resampler.
3574  * Note, if either rate is not an integer then simply scale both rates up so they are.
3575  * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq
3576  * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
3577  * @param linear If 1 then the used FIR filter will be linearly interpolated
3578                  between the 2 closest, if 0 the closest will be used
3579  * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
3580  */
3581 struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff);
3582
3583 /**
3584  * Resample an array of samples using a previously configured context.
3585  * @param src an array of unconsumed samples
3586  * @param consumed the number of samples of src which have been consumed are returned here
3587  * @param src_size the number of unconsumed samples available
3588  * @param dst_size the amount of space in samples available in dst
3589  * @param update_ctx If this is 0 then the context will not be modified, that way several channels can be resampled with the same context.
3590  * @return the number of samples written in dst or -1 if an error occurred
3591  */
3592 int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
3593
3594
3595 /**
3596  * Compensate samplerate/timestamp drift. The compensation is done by changing
3597  * the resampler parameters, so no audible clicks or similar distortions occur
3598  * @param compensation_distance distance in output samples over which the compensation should be performed
3599  * @param sample_delta number of output samples which should be output less
3600  *
3601  * example: av_resample_compensate(c, 10, 500)
3602  * here instead of 510 samples only 500 samples would be output
3603  *
3604  * note, due to rounding the actual compensation might be slightly different,
3605  * especially if the compensation_distance is large and the in_rate used during init is small
3606  */
3607 void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
3608 void av_resample_close(struct AVResampleContext *c);
3609
3610 /**
3611  * Allocate memory for a picture.  Call avpicture_free() to free it.
3612  *
3613  * @see avpicture_fill()
3614  *
3615  * @param picture the picture to be filled in
3616  * @param pix_fmt the format of the picture
3617  * @param width the width of the picture
3618  * @param height the height of the picture
3619  * @return zero if successful, a negative value if not
3620  */
3621 int avpicture_alloc(AVPicture *picture, enum PixelFormat pix_fmt, int width, int height);
3622
3623 /**
3624  * Free a picture previously allocated by avpicture_alloc().
3625  * The data buffer used by the AVPicture is freed, but the AVPicture structure
3626  * itself is not.
3627  *
3628  * @param picture the AVPicture to be freed
3629  */
3630 void avpicture_free(AVPicture *picture);
3631
3632 /**
3633  * Fill in the AVPicture fields.
3634  * The fields of the given AVPicture are filled in by using the 'ptr' address
3635  * which points to the image data buffer. Depending on the specified picture
3636  * format, one or multiple image data pointers and line sizes will be set.
3637  * If a planar format is specified, several pointers will be set pointing to
3638  * the different picture planes and the line sizes of the different planes
3639  * will be stored in the lines_sizes array.
3640  * Call with ptr == NULL to get the required size for the ptr buffer.
3641  *
3642  * To allocate the buffer and fill in the AVPicture fields in one call,
3643  * use avpicture_alloc().
3644  *
3645  * @param picture AVPicture whose fields are to be filled in
3646  * @param ptr Buffer which will contain or contains the actual image data
3647  * @param pix_fmt The format in which the picture data is stored.
3648  * @param width the width of the image in pixels
3649  * @param height the height of the image in pixels
3650  * @return size of the image data in bytes
3651  */
3652 int avpicture_fill(AVPicture *picture, uint8_t *ptr,
3653                    enum PixelFormat pix_fmt, int width, int height);
3654
3655 /**
3656  * Copy pixel data from an AVPicture into a buffer.
3657  * The data is stored compactly, without any gaps for alignment or padding
3658  * which may be applied by avpicture_fill().
3659  *
3660  * @see avpicture_get_size()
3661  *
3662  * @param[in] src AVPicture containing image data
3663  * @param[in] pix_fmt The format in which the picture data is stored.
3664  * @param[in] width the width of the image in pixels.
3665  * @param[in] height the height of the image in pixels.
3666  * @param[out] dest A buffer into which picture data will be copied.
3667  * @param[in] dest_size The size of 'dest'.
3668  * @return The number of bytes written to dest, or a negative value (error code) on error.
3669  */
3670 int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, int height,
3671                      unsigned char *dest, int dest_size);
3672
3673 /**
3674  * Calculate the size in bytes that a picture of the given width and height
3675  * would occupy if stored in the given picture format.
3676  * Note that this returns the size of a compact representation as generated
3677  * by avpicture_layout(), which can be smaller than the size required for e.g.
3678  * avpicture_fill().
3679  *
3680  * @param pix_fmt the given picture format
3681  * @param width the width of the image
3682  * @param height the height of the image
3683  * @return Image data size in bytes or -1 on error (e.g. too large dimensions).
3684  */
3685 int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height);
3686 void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift);
3687
3688 #if FF_API_GET_PIX_FMT_NAME
3689 /**
3690  * @deprecated Deprecated in favor of av_get_pix_fmt_name().
3691  */
3692 attribute_deprecated
3693 const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt);
3694 #endif
3695
3696 void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
3697
3698 /**
3699  * Return a value representing the fourCC code associated to the
3700  * pixel format pix_fmt, or 0 if no associated fourCC code can be
3701  * found.
3702  */
3703 unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat pix_fmt);
3704
3705 /**
3706  * Put a string representing the codec tag codec_tag in buf.
3707  *
3708  * @param buf_size size in bytes of buf
3709  * @return the length of the string that would have been generated if
3710  * enough space had been available, excluding the trailing null
3711  */
3712 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag);
3713
3714 #define FF_LOSS_RESOLUTION  0x0001 /**< loss due to resolution change */
3715 #define FF_LOSS_DEPTH       0x0002 /**< loss due to color depth change */
3716 #define FF_LOSS_COLORSPACE  0x0004 /**< loss due to color space conversion */
3717 #define FF_LOSS_ALPHA       0x0008 /**< loss of alpha bits */
3718 #define FF_LOSS_COLORQUANT  0x0010 /**< loss due to color quantization */
3719 #define FF_LOSS_CHROMA      0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */
3720
3721 /**
3722  * Compute what kind of losses will occur when converting from one specific
3723  * pixel format to another.
3724  * When converting from one pixel format to another, information loss may occur.
3725  * For example, when converting from RGB24 to GRAY, the color information will
3726  * be lost. Similarly, other losses occur when converting from some formats to
3727  * other formats. These losses can involve loss of chroma, but also loss of
3728  * resolution, loss of color depth, loss due to the color space conversion, loss
3729  * of the alpha bits or loss due to color quantization.
3730  * avcodec_get_fix_fmt_loss() informs you about the various types of losses
3731  * which will occur when converting from one pixel format to another.
3732  *
3733  * @param[in] dst_pix_fmt destination pixel format
3734  * @param[in] src_pix_fmt source pixel format
3735  * @param[in] has_alpha Whether the source pixel format alpha channel is used.
3736  * @return Combination of flags informing you what kind of losses will occur.
3737  */
3738 int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_pix_fmt,
3739                              int has_alpha);
3740
3741 /**
3742  * Find the best pixel format to convert to given a certain source pixel
3743  * format.  When converting from one pixel format to another, information loss
3744  * may occur.  For example, when converting from RGB24 to GRAY, the color
3745  * information will be lost. Similarly, other losses occur when converting from
3746  * some formats to other formats. avcodec_find_best_pix_fmt() searches which of
3747  * the given pixel formats should be used to suffer the least amount of loss.
3748  * The pixel formats from which it chooses one, are determined by the
3749  * pix_fmt_mask parameter.
3750  *
3751  * @code
3752  * src_pix_fmt = PIX_FMT_YUV420P;
3753  * pix_fmt_mask = (1 << PIX_FMT_YUV422P) || (1 << PIX_FMT_RGB24);
3754  * dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss);
3755  * @endcode
3756  *
3757  * @param[in] pix_fmt_mask bitmask determining which pixel format to choose from
3758  * @param[in] src_pix_fmt source pixel format
3759  * @param[in] has_alpha Whether the source pixel format alpha channel is used.
3760  * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
3761  * @return The best pixel format to convert to or -1 if none was found.
3762  */
3763 enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt,
3764                               int has_alpha, int *loss_ptr);
3765
3766 #if FF_API_GET_ALPHA_INFO
3767 #define FF_ALPHA_TRANSP       0x0001 /* image has some totally transparent pixels */
3768 #define FF_ALPHA_SEMI_TRANSP  0x0002 /* image has some transparent pixels */
3769
3770 /**
3771  * Tell if an image really has transparent alpha values.
3772  * @return ored mask of FF_ALPHA_xxx constants
3773  */
3774 attribute_deprecated
3775 int img_get_alpha_info(const AVPicture *src,
3776                        enum PixelFormat pix_fmt, int width, int height);
3777 #endif
3778
3779 /* deinterlace a picture */
3780 /* deinterlace - if not supported return -1 */
3781 int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
3782                           enum PixelFormat pix_fmt, int width, int height);
3783
3784 /* external high level API */
3785
3786 /**
3787  * If c is NULL, returns the first registered codec,
3788  * if c is non-NULL, returns the next registered codec after c,
3789  * or NULL if c is the last one.
3790  */
3791 AVCodec *av_codec_next(AVCodec *c);
3792
3793 /**
3794  * Return the LIBAVCODEC_VERSION_INT constant.
3795  */
3796 unsigned avcodec_version(void);
3797
3798 /**
3799  * Return the libavcodec build-time configuration.
3800  */
3801 const char *avcodec_configuration(void);
3802
3803 /**
3804  * Return the libavcodec license.
3805  */
3806 const char *avcodec_license(void);
3807
3808 #if FF_API_AVCODEC_INIT
3809 /**
3810  * @deprecated this function is called automatically from avcodec_register()
3811  * and avcodec_register_all(), there is no need to call it manually
3812  */
3813 attribute_deprecated
3814 void avcodec_init(void);
3815 #endif
3816
3817 /**
3818  * Register the codec codec and initialize libavcodec.
3819  *
3820  * @warning either this function or avcodec_register_all() must be called
3821  * before any other libavcodec functions.
3822  *
3823  * @see avcodec_register_all()
3824  */
3825 void avcodec_register(AVCodec *codec);
3826
3827 /**
3828  * Find a registered encoder with a matching codec ID.
3829  *
3830  * @param id CodecID of the requested encoder
3831  * @return An encoder if one was found, NULL otherwise.
3832  */
3833 AVCodec *avcodec_find_encoder(enum CodecID id);
3834
3835 /**
3836  * Find a registered encoder with the specified name.
3837  *
3838  * @param name name of the requested encoder
3839  * @return An encoder if one was found, NULL otherwise.
3840  */
3841 AVCodec *avcodec_find_encoder_by_name(const char *name);
3842
3843 /**
3844  * Find a registered decoder with a matching codec ID.
3845  *
3846  * @param id CodecID of the requested decoder
3847  * @return A decoder if one was found, NULL otherwise.
3848  */
3849 AVCodec *avcodec_find_decoder(enum CodecID id);
3850
3851 /**
3852  * Find a registered decoder with the specified name.
3853  *
3854  * @param name name of the requested decoder
3855  * @return A decoder if one was found, NULL otherwise.
3856  */
3857 AVCodec *avcodec_find_decoder_by_name(const char *name);
3858 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
3859
3860 /**
3861  * Return a name for the specified profile, if available.
3862  *
3863  * @param codec the codec that is searched for the given profile
3864  * @param profile the profile value for which a name is requested
3865  * @return A name for the profile if found, NULL otherwise.
3866  */
3867 const char *av_get_profile_name(const AVCodec *codec, int profile);
3868
3869 #if FF_API_ALLOC_CONTEXT
3870 /**
3871  * Set the fields of the given AVCodecContext to default values.
3872  *
3873  * @param s The AVCodecContext of which the fields should be set to default values.
3874  * @deprecated use avcodec_get_context_defaults3
3875  */
3876 attribute_deprecated
3877 void avcodec_get_context_defaults(AVCodecContext *s);
3878
3879 /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
3880  *  we WILL change its arguments and name a few times! */
3881 attribute_deprecated
3882 void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType);
3883 #endif
3884
3885 /**
3886  * Set the fields of the given AVCodecContext to default values corresponding
3887  * to the given codec (defaults may be codec-dependent).
3888  *
3889  * Do not call this function if a non-NULL codec has been passed
3890  * to avcodec_alloc_context3() that allocated this AVCodecContext.
3891  * If codec is non-NULL, it is illegal to call avcodec_open2() with a
3892  * different codec on this AVCodecContext.
3893  */
3894 int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec);
3895
3896 #if FF_API_ALLOC_CONTEXT
3897 /**
3898  * Allocate an AVCodecContext and set its fields to default values.  The
3899  * resulting struct can be deallocated by simply calling av_free().
3900  *
3901  * @return An AVCodecContext filled with default values or NULL on failure.
3902  * @see avcodec_get_context_defaults
3903  *
3904  * @deprecated use avcodec_alloc_context3()
3905  */
3906 attribute_deprecated
3907 AVCodecContext *avcodec_alloc_context(void);
3908
3909 /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
3910  *  we WILL change its arguments and name a few times! */
3911 attribute_deprecated
3912 AVCodecContext *avcodec_alloc_context2(enum AVMediaType);
3913 #endif
3914
3915 /**
3916  * Allocate an AVCodecContext and set its fields to default values.  The
3917  * resulting struct can be deallocated by simply calling av_free().
3918  *
3919  * @param codec if non-NULL, allocate private data and initialize defaults
3920  *              for the given codec. It is illegal to then call avcodec_open2()
3921  *              with a different codec.
3922  *
3923  * @return An AVCodecContext filled with default values or NULL on failure.
3924  * @see avcodec_get_context_defaults
3925  */
3926 AVCodecContext *avcodec_alloc_context3(AVCodec *codec);
3927
3928 /**
3929  * Copy the settings of the source AVCodecContext into the destination
3930  * AVCodecContext. The resulting destination codec context will be
3931  * unopened, i.e. you are required to call avcodec_open2() before you
3932  * can use this AVCodecContext to decode/encode video/audio data.
3933  *
3934  * @param dest target codec context, should be initialized with
3935  *             avcodec_alloc_context3(), but otherwise uninitialized
3936  * @param src source codec context
3937  * @return AVERROR() on error (e.g. memory allocation error), 0 on success
3938  */
3939 int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
3940
3941 /**
3942  * Set the fields of the given AVFrame to default values.
3943  *
3944  * @param pic The AVFrame of which the fields should be set to default values.
3945  */
3946 void avcodec_get_frame_defaults(AVFrame *pic);
3947
3948 /**
3949  * Allocate an AVFrame and set its fields to default values.  The resulting
3950  * struct can be deallocated by simply calling av_free().
3951  *
3952  * @return An AVFrame filled with default values or NULL on failure.
3953  * @see avcodec_get_frame_defaults
3954  */
3955 AVFrame *avcodec_alloc_frame(void);
3956
3957 int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
3958 void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
3959 int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
3960
3961 /**
3962  * Return the amount of padding in pixels which the get_buffer callback must
3963  * provide around the edge of the image for codecs which do not have the
3964  * CODEC_FLAG_EMU_EDGE flag.
3965  *
3966  * @return Required padding in pixels.
3967  */
3968 unsigned avcodec_get_edge_width(void);
3969 /**
3970  * Modify width and height values so that they will result in a memory
3971  * buffer that is acceptable for the codec if you do not use any horizontal
3972  * padding.
3973  *
3974  * May only be used if a codec with CODEC_CAP_DR1 has been opened.
3975  * If CODEC_FLAG_EMU_EDGE is not set, the dimensions must have been increased
3976  * according to avcodec_get_edge_width() before.
3977  */
3978 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
3979 /**
3980  * Modify width and height values so that they will result in a memory
3981  * buffer that is acceptable for the codec if you also ensure that all
3982  * line sizes are a multiple of the respective linesize_align[i].
3983  *
3984  * May only be used if a codec with CODEC_CAP_DR1 has been opened.
3985  * If CODEC_FLAG_EMU_EDGE is not set, the dimensions must have been increased
3986  * according to avcodec_get_edge_width() before.
3987  */
3988 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
3989                                int linesize_align[AV_NUM_DATA_POINTERS]);
3990
3991 enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt);
3992
3993 #if FF_API_THREAD_INIT
3994 /**
3995  * @deprecated Set s->thread_count before calling avcodec_open2() instead of calling this.
3996  */
3997 attribute_deprecated
3998 int avcodec_thread_init(AVCodecContext *s, int thread_count);
3999 #endif
4000
4001 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
4002 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
4003 //FIXME func typedef
4004
4005 #if FF_API_AVCODEC_OPEN
4006 /**
4007  * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
4008  * function the context has to be allocated.
4009  *
4010  * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
4011  * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
4012  * retrieving a codec.
4013  *
4014  * @warning This function is not thread safe!
4015  *
4016  * @code
4017  * avcodec_register_all();
4018  * codec = avcodec_find_decoder(CODEC_ID_H264);
4019  * if (!codec)
4020  *     exit(1);
4021  *
4022  * context = avcodec_alloc_context3(codec);
4023  *
4024  * if (avcodec_open(context, codec) < 0)
4025  *     exit(1);
4026  * @endcode
4027  *
4028  * @param avctx The context which will be set up to use the given codec.
4029  * @param codec The codec to use within the context.
4030  * @return zero on success, a negative value on error
4031  * @see avcodec_alloc_context3, avcodec_find_decoder, avcodec_find_encoder, avcodec_close
4032  *
4033  * @deprecated use avcodec_open2
4034  */
4035 attribute_deprecated
4036 int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
4037 #endif
4038
4039 /**
4040  * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
4041  * function the context has to be allocated with avcodec_alloc_context3().
4042  *
4043  * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
4044  * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
4045  * retrieving a codec.
4046  *
4047  * @warning This function is not thread safe!
4048  *
4049  * @code
4050  * avcodec_register_all();
4051  * av_dict_set(&opts, "b", "2.5M", 0);
4052  * codec = avcodec_find_decoder(CODEC_ID_H264);
4053  * if (!codec)
4054  *     exit(1);
4055  *
4056  * context = avcodec_alloc_context3(codec);
4057  *
4058  * if (avcodec_open2(context, codec, opts) < 0)
4059  *     exit(1);
4060  * @endcode
4061  *
4062  * @param avctx The context to initialize.
4063  * @param options A dictionary filled with AVCodecContext and codec-private options.
4064  *                On return this object will be filled with options that were not found.
4065  *
4066  * @return zero on success, a negative value on error
4067  * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
4068  *      av_dict_set(), av_opt_find().
4069  */
4070 int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options);
4071
4072 #if FF_API_OLD_DECODE_AUDIO
4073 /**
4074  * Wrapper function which calls avcodec_decode_audio4.
4075  *
4076  * @deprecated Use avcodec_decode_audio4 instead.
4077  *
4078  * Decode the audio frame of size avpkt->size from avpkt->data into samples.
4079  * Some decoders may support multiple frames in a single AVPacket, such
4080  * decoders would then just decode the first frame. In this case,
4081  * avcodec_decode_audio3 has to be called again with an AVPacket that contains
4082  * the remaining data in order to decode the second frame etc.
4083  * If no frame
4084  * could be outputted, frame_size_ptr is zero. Otherwise, it is the
4085  * decompressed frame size in bytes.
4086  *
4087  * @warning You must set frame_size_ptr to the allocated size of the
4088  * output buffer before calling avcodec_decode_audio3().
4089  *
4090  * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
4091  * the actual read bytes because some optimized bitstream readers read 32 or 64
4092  * bits at once and could read over the end.
4093  *
4094  * @warning The end of the input buffer avpkt->data should be set to 0 to ensure that
4095  * no overreading happens for damaged MPEG streams.
4096  *
4097  * @warning You must not provide a custom get_buffer() when using
4098  * avcodec_decode_audio3().  Doing so will override it with
4099  * avcodec_default_get_buffer.  Use avcodec_decode_audio4() instead,
4100  * which does allow the application to provide a custom get_buffer().
4101  *
4102  * @note You might have to align the input buffer avpkt->data and output buffer
4103  * samples. The alignment requirements depend on the CPU: On some CPUs it isn't
4104  * necessary at all, on others it won't work at all if not aligned and on others
4105  * it will work but it will have an impact on performance.
4106  *
4107  * In practice, avpkt->data should have 4 byte alignment at minimum and
4108  * samples should be 16 byte aligned unless the CPU doesn't need it
4109  * (AltiVec and SSE do).
4110  *
4111  * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay
4112  * between input and output, these need to be fed with avpkt->data=NULL,
4113  * avpkt->size=0 at the end to return the remaining frames.
4114  *
4115  * @param avctx the codec context
4116  * @param[out] samples the output buffer, sample type in avctx->sample_fmt
4117  *                     If the sample format is planar, each channel plane will
4118  *                     be the same size, with no padding between channels.
4119  * @param[in,out] frame_size_ptr the output buffer size in bytes
4120  * @param[in] avpkt The input AVPacket containing the input buffer.
4121  *            You can create such packet with av_init_packet() and by then setting
4122  *            data and size, some decoders might in addition need other fields.
4123  *            All decoders are designed to use the least fields possible though.
4124  * @return On error a negative value is returned, otherwise the number of bytes
4125  * used or zero if no frame data was decompressed (used) from the input AVPacket.
4126  */
4127 attribute_deprecated int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
4128                          int *frame_size_ptr,
4129                          AVPacket *avpkt);
4130 #endif
4131
4132 /**
4133  * Decode the audio frame of size avpkt->size from avpkt->data into frame.
4134  *
4135  * Some decoders may support multiple frames in a single AVPacket. Such
4136  * decoders would then just decode the first frame. In this case,
4137  * avcodec_decode_audio4 has to be called again with an AVPacket containing
4138  * the remaining data in order to decode the second frame, etc...
4139  * Even if no frames are returned, the packet needs to be fed to the decoder
4140  * with remaining data until it is completely consumed or an error occurs.
4141  *
4142  * @warning The input buffer, avpkt->data must be FF_INPUT_BUFFER_PADDING_SIZE
4143  *          larger than the actual read bytes because some optimized bitstream
4144  *          readers read 32 or 64 bits at once and could read over the end.
4145  *
4146  * @note You might have to align the input buffer. The alignment requirements
4147  *       depend on the CPU and the decoder.
4148  *
4149  * @param      avctx the codec context
4150  * @param[out] frame The AVFrame in which to store decoded audio samples.
4151  *                   Decoders request a buffer of a particular size by setting
4152  *                   AVFrame.nb_samples prior to calling get_buffer(). The
4153  *                   decoder may, however, only utilize part of the buffer by
4154  *                   setting AVFrame.nb_samples to a smaller value in the
4155  *                   output frame.
4156  * @param[out] got_frame_ptr Zero if no frame could be decoded, otherwise it is
4157  *                           non-zero.
4158  * @param[in]  avpkt The input AVPacket containing the input buffer.
4159  *                   At least avpkt->data and avpkt->size should be set. Some
4160  *                   decoders might also require additional fields to be set.
4161  * @return A negative error code is returned if an error occurred during
4162  *         decoding, otherwise the number of bytes consumed from the input
4163  *         AVPacket is returned.
4164  */
4165 int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,
4166                           int *got_frame_ptr, AVPacket *avpkt);
4167
4168 /**
4169  * Decode the video frame of size avpkt->size from avpkt->data into picture.
4170  * Some decoders may support multiple frames in a single AVPacket, such
4171  * decoders would then just decode the first frame.
4172  *
4173  * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
4174  * the actual read bytes because some optimized bitstream readers read 32 or 64
4175  * bits at once and could read over the end.
4176  *
4177  * @warning The end of the input buffer buf should be set to 0 to ensure that
4178  * no overreading happens for damaged MPEG streams.
4179  *
4180  * @note You might have to align the input buffer avpkt->data.
4181  * The alignment requirements depend on the CPU: on some CPUs it isn't
4182  * necessary at all, on others it won't work at all if not aligned and on others
4183  * it will work but it will have an impact on performance.
4184  *
4185  * In practice, avpkt->data should have 4 byte alignment at minimum.
4186  *
4187  * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay
4188  * between input and output, these need to be fed with avpkt->data=NULL,
4189  * avpkt->size=0 at the end to return the remaining frames.
4190  *
4191  * @param avctx the codec context
4192  * @param[out] picture The AVFrame in which the decoded video frame will be stored.
4193  *             Use avcodec_alloc_frame to get an AVFrame, the codec will
4194  *             allocate memory for the actual bitmap.
4195  *             with default get/release_buffer(), the decoder frees/reuses the bitmap as it sees fit.
4196  *             with overridden get/release_buffer() (needs CODEC_CAP_DR1) the user decides into what buffer the decoder
4197  *                   decodes and the decoder tells the user once it does not need the data anymore,
4198  *                   the user app can at this point free/reuse/keep the memory as it sees fit.
4199  *
4200  * @param[in] avpkt The input AVpacket containing the input buffer.
4201  *            You can create such packet with av_init_packet() and by then setting
4202  *            data and size, some decoders might in addition need other fields like
4203  *            flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least
4204  *            fields possible.
4205  * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
4206  * @return On error a negative value is returned, otherwise the number of bytes
4207  * used or zero if no frame could be decompressed.
4208  */
4209 int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
4210                          int *got_picture_ptr,
4211                          AVPacket *avpkt);
4212
4213 /**
4214  * Decode a subtitle message.
4215  * Return a negative value on error, otherwise return the number of bytes used.
4216  * If no subtitle could be decompressed, got_sub_ptr is zero.
4217  * Otherwise, the subtitle is stored in *sub.
4218  * Note that CODEC_CAP_DR1 is not available for subtitle codecs. This is for
4219  * simplicity, because the performance difference is expect to be negligible
4220  * and reusing a get_buffer written for video codecs would probably perform badly
4221  * due to a potentially very different allocation pattern.
4222  *
4223  * @param avctx the codec context
4224  * @param[out] sub The AVSubtitle in which the decoded subtitle will be stored, must be
4225                    freed with avsubtitle_free if *got_sub_ptr is set.
4226  * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero.
4227  * @param[in] avpkt The input AVPacket containing the input buffer.
4228  */
4229 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
4230                             int *got_sub_ptr,
4231                             AVPacket *avpkt);
4232
4233 /**
4234  * Free all allocated data in the given subtitle struct.
4235  *
4236  * @param sub AVSubtitle to free.
4237  */
4238 void avsubtitle_free(AVSubtitle *sub);
4239
4240 #if FF_API_OLD_ENCODE_AUDIO
4241 /**
4242  * Encode an audio frame from samples into buf.
4243  *
4244  * @deprecated Use avcodec_encode_audio2 instead.
4245  *
4246  * @note The output buffer should be at least FF_MIN_BUFFER_SIZE bytes large.
4247  * However, for codecs with avctx->frame_size equal to 0 (e.g. PCM) the user
4248  * will know how much space is needed because it depends on the value passed
4249  * in buf_size as described below. In that case a lower value can be used.
4250  *
4251  * @param avctx the codec context
4252  * @param[out] buf the output buffer
4253  * @param[in] buf_size the output buffer size
4254  * @param[in] samples the input buffer containing the samples
4255  * The number of samples read from this buffer is frame_size*channels,
4256  * both of which are defined in avctx.
4257  * For codecs which have avctx->frame_size equal to 0 (e.g. PCM) the number of
4258  * samples read from samples is equal to:
4259  * buf_size * 8 / (avctx->channels * av_get_bits_per_sample(avctx->codec_id))
4260  * This also implies that av_get_bits_per_sample() must not return 0 for these
4261  * codecs.
4262  * @return On error a negative value is returned, on success zero or the number
4263  * of bytes used to encode the data read from the input buffer.
4264  */
4265 int attribute_deprecated avcodec_encode_audio(AVCodecContext *avctx,
4266                                               uint8_t *buf, int buf_size,
4267                                               const short *samples);
4268 #endif
4269
4270 /**
4271  * Encode a frame of audio.
4272  *
4273  * Takes input samples from frame and writes the next output packet, if
4274  * available, to avpkt. The output packet does not necessarily contain data for
4275  * the most recent frame, as encoders can delay, split, and combine input frames
4276  * internally as needed.
4277  *
4278  * @param avctx     codec context
4279  * @param avpkt     output AVPacket.
4280  *                  The user can supply an output buffer by setting
4281  *                  avpkt->data and avpkt->size prior to calling the
4282  *                  function, but if the size of the user-provided data is not
4283  *                  large enough, encoding will fail. All other AVPacket fields
4284  *                  will be reset by the encoder using av_init_packet(). If
4285  *                  avpkt->data is NULL, the encoder will allocate it.
4286  *                  The encoder will set avpkt->size to the size of the
4287  *                  output packet.
4288  * @param[in] frame AVFrame containing the raw audio data to be encoded.
4289  *                  May be NULL when flushing an encoder that has the
4290  *                  CODEC_CAP_DELAY capability set.
4291  *                  There are 2 codec capabilities that affect the allowed
4292  *                  values of frame->nb_samples.
4293  *                  If CODEC_CAP_SMALL_LAST_FRAME is set, then only the final
4294  *                  frame may be smaller than avctx->frame_size, and all other
4295  *                  frames must be equal to avctx->frame_size.
4296  *                  If CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
4297  *                  can have any number of samples.
4298  *                  If neither is set, frame->nb_samples must be equal to
4299  *                  avctx->frame_size for all frames.
4300  * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
4301  *                            output packet is non-empty, and to 0 if it is
4302  *                            empty. If the function returns an error, the
4303  *                            packet can be assumed to be invalid, and the
4304  *                            value of got_packet_ptr is undefined and should
4305  *                            not be used.
4306  * @return          0 on success, negative error code on failure
4307  */
4308 int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt,
4309                           const AVFrame *frame, int *got_packet_ptr);
4310
4311 /**
4312  * Fill audio frame data and linesize.
4313  * AVFrame extended_data channel pointers are allocated if necessary for
4314  * planar audio.
4315  *
4316  * @param frame       the AVFrame
4317  *                    frame->nb_samples must be set prior to calling the
4318  *                    function. This function fills in frame->data,
4319  *                    frame->extended_data, frame->linesize[0].
4320  * @param nb_channels channel count
4321  * @param sample_fmt  sample format
4322  * @param buf         buffer to use for frame data
4323  * @param buf_size    size of buffer
4324  * @param align       plane size sample alignment
4325  * @return            0 on success, negative error code on failure
4326  */
4327 int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
4328                              enum AVSampleFormat sample_fmt, const uint8_t *buf,
4329                              int buf_size, int align);
4330
4331 /**
4332  * Encode a video frame from pict into buf.
4333  * The input picture should be
4334  * stored using a specific format, namely avctx.pix_fmt.
4335  *
4336  * @param avctx the codec context
4337  * @param[out] buf the output buffer for the bitstream of encoded frame
4338  * @param[in] buf_size the size of the output buffer in bytes
4339  * @param[in] pict the input picture to encode
4340  * @return On error a negative value is returned, on success zero or the number
4341  * of bytes used from the output buffer.
4342  */
4343 int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
4344                          const AVFrame *pict);
4345 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
4346                             const AVSubtitle *sub);
4347
4348 int avcodec_close(AVCodecContext *avctx);
4349
4350 /**
4351  * Register all the codecs, parsers and bitstream filters which were enabled at
4352  * configuration time. If you do not call this function you can select exactly
4353  * which formats you want to support, by using the individual registration
4354  * functions.
4355  *
4356  * @see avcodec_register
4357  * @see av_register_codec_parser
4358  * @see av_register_bitstream_filter
4359  */
4360 void avcodec_register_all(void);
4361
4362 /**
4363  * Flush buffers, should be called when seeking or when switching to a different stream.
4364  */
4365 void avcodec_flush_buffers(AVCodecContext *avctx);
4366
4367 void avcodec_default_free_buffers(AVCodecContext *s);
4368
4369 /* misc useful functions */
4370
4371 #if FF_API_OLD_FF_PICT_TYPES
4372 /**
4373  * Return a single letter to describe the given picture type pict_type.
4374  *
4375  * @param[in] pict_type the picture type
4376  * @return A single character representing the picture type.
4377  * @deprecated Use av_get_picture_type_char() instead.
4378  */
4379 attribute_deprecated
4380 char av_get_pict_type_char(int pict_type);
4381 #endif
4382
4383 /**
4384  * Return codec bits per sample.
4385  *
4386  * @param[in] codec_id the codec
4387  * @return Number of bits per sample or zero if unknown for the given codec.
4388  */
4389 int av_get_bits_per_sample(enum CodecID codec_id);
4390
4391 #if FF_API_OLD_SAMPLE_FMT
4392 /**
4393  * @deprecated Use av_get_bytes_per_sample() instead.
4394  */
4395 attribute_deprecated
4396 int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt);
4397 #endif
4398
4399 /* frame parsing */
4400 typedef struct AVCodecParserContext {
4401     void *priv_data;
4402     struct AVCodecParser *parser;
4403     int64_t frame_offset; /* offset of the current frame */
4404     int64_t cur_offset; /* current offset
4405                            (incremented by each av_parser_parse()) */
4406     int64_t next_frame_offset; /* offset of the next frame */
4407     /* video info */
4408     int pict_type; /* XXX: Put it back in AVCodecContext. */
4409     /**
4410      * This field is used for proper frame duration computation in lavf.
4411      * It signals, how much longer the frame duration of the current frame
4412      * is compared to normal frame duration.
4413      *
4414      * frame_duration = (1 + repeat_pict) * time_base
4415      *
4416      * It is used by codecs like H.264 to display telecined material.
4417      */
4418     int repeat_pict; /* XXX: Put it back in AVCodecContext. */
4419     int64_t pts;     /* pts of the current frame */
4420     int64_t dts;     /* dts of the current frame */
4421
4422     /* private data */
4423     int64_t last_pts;
4424     int64_t last_dts;
4425     int fetch_timestamp;
4426
4427 #define AV_PARSER_PTS_NB 4
4428     int cur_frame_start_index;
4429     int64_t cur_frame_offset[AV_PARSER_PTS_NB];
4430     int64_t cur_frame_pts[AV_PARSER_PTS_NB];
4431     int64_t cur_frame_dts[AV_PARSER_PTS_NB];
4432
4433     int flags;
4434 #define PARSER_FLAG_COMPLETE_FRAMES           0x0001
4435 #define PARSER_FLAG_ONCE                      0x0002
4436 /// Set if the parser has a valid file offset
4437 #define PARSER_FLAG_FETCHED_OFFSET            0x0004
4438
4439     int64_t offset;      ///< byte offset from starting packet start
4440     int64_t cur_frame_end[AV_PARSER_PTS_NB];
4441
4442     /**
4443      * Set by parser to 1 for key frames and 0 for non-key frames.
4444      * It is initialized to -1, so if the parser doesn't set this flag,
4445      * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
4446      * will be used.
4447      */
4448     int key_frame;
4449
4450     /**
4451      * Time difference in stream time base units from the pts of this
4452      * packet to the point at which the output from the decoder has converged
4453      * independent from the availability of previous frames. That is, the
4454      * frames are virtually identical no matter if decoding started from
4455      * the very first frame or from this keyframe.
4456      * Is AV_NOPTS_VALUE if unknown.
4457      * This field is not the display duration of the current frame.
4458      * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
4459      * set.
4460      *
4461      * The purpose of this field is to allow seeking in streams that have no
4462      * keyframes in the conventional sense. It corresponds to the
4463      * recovery point SEI in H.264 and match_time_delta in NUT. It is also
4464      * essential for some types of subtitle streams to ensure that all
4465      * subtitles are correctly displayed after seeking.
4466      */
4467     int64_t convergence_duration;
4468
4469     // Timestamp generation support:
4470     /**
4471      * Synchronization point for start of timestamp generation.
4472      *
4473      * Set to >0 for sync point, 0 for no sync point and <0 for undefined
4474      * (default).
4475      *
4476      * For example, this corresponds to presence of H.264 buffering period
4477      * SEI message.
4478      */
4479     int dts_sync_point;
4480
4481     /**
4482      * Offset of the current timestamp against last timestamp sync point in
4483      * units of AVCodecContext.time_base.
4484      *
4485      * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
4486      * contain a valid timestamp offset.
4487      *
4488      * Note that the timestamp of sync point has usually a nonzero
4489      * dts_ref_dts_delta, which refers to the previous sync point. Offset of
4490      * the next frame after timestamp sync point will be usually 1.
4491      *
4492      * For example, this corresponds to H.264 cpb_removal_delay.
4493      */
4494     int dts_ref_dts_delta;
4495
4496     /**
4497      * Presentation delay of current frame in units of AVCodecContext.time_base.
4498      *
4499      * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
4500      * contain valid non-negative timestamp delta (presentation time of a frame
4501      * must not lie in the past).
4502      *
4503      * This delay represents the difference between decoding and presentation
4504      * time of the frame.
4505      *
4506      * For example, this corresponds to H.264 dpb_output_delay.
4507      */
4508     int pts_dts_delta;
4509
4510     /**
4511      * Position of the packet in file.
4512      *
4513      * Analogous to cur_frame_pts/dts
4514      */
4515     int64_t cur_frame_pos[AV_PARSER_PTS_NB];
4516
4517     /**
4518      * Byte position of currently parsed frame in stream.
4519      */
4520     int64_t pos;
4521
4522     /**
4523      * Previous frame byte position.
4524      */
4525     int64_t last_pos;
4526 } AVCodecParserContext;
4527
4528 typedef struct AVCodecParser {
4529     int codec_ids[5]; /* several codec IDs are permitted */
4530     int priv_data_size;
4531     int (*parser_init)(AVCodecParserContext *s);
4532     int (*parser_parse)(AVCodecParserContext *s,
4533                         AVCodecContext *avctx,
4534                         const uint8_t **poutbuf, int *poutbuf_size,
4535                         const uint8_t *buf, int buf_size);
4536     void (*parser_close)(AVCodecParserContext *s);
4537     int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
4538     struct AVCodecParser *next;
4539 } AVCodecParser;
4540
4541 AVCodecParser *av_parser_next(AVCodecParser *c);
4542
4543 void av_register_codec_parser(AVCodecParser *parser);
4544 AVCodecParserContext *av_parser_init(int codec_id);
4545
4546 /**
4547  * Parse a packet.
4548  *
4549  * @param s             parser context.
4550  * @param avctx         codec context.
4551  * @param poutbuf       set to pointer to parsed buffer or NULL if not yet finished.
4552  * @param poutbuf_size  set to size of parsed buffer or zero if not yet finished.
4553  * @param buf           input buffer.
4554  * @param buf_size      input length, to signal EOF, this should be 0 (so that the last frame can be output).
4555  * @param pts           input presentation timestamp.
4556  * @param dts           input decoding timestamp.
4557  * @param pos           input byte position in stream.
4558  * @return the number of bytes of the input bitstream used.
4559  *
4560  * Example:
4561  * @code
4562  *   while(in_len){
4563  *       len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
4564  *                                        in_data, in_len,
4565  *                                        pts, dts, pos);
4566  *       in_data += len;
4567  *       in_len  -= len;
4568  *
4569  *       if(size)
4570  *          decode_frame(data, size);
4571  *   }
4572  * @endcode
4573  */
4574 int av_parser_parse2(AVCodecParserContext *s,
4575                      AVCodecContext *avctx,
4576                      uint8_t **poutbuf, int *poutbuf_size,
4577                      const uint8_t *buf, int buf_size,
4578                      int64_t pts, int64_t dts,
4579                      int64_t pos);
4580
4581 int av_parser_change(AVCodecParserContext *s,
4582                      AVCodecContext *avctx,
4583                      uint8_t **poutbuf, int *poutbuf_size,
4584                      const uint8_t *buf, int buf_size, int keyframe);
4585 void av_parser_close(AVCodecParserContext *s);
4586
4587
4588 typedef struct AVBitStreamFilterContext {
4589     void *priv_data;
4590     struct AVBitStreamFilter *filter;
4591     AVCodecParserContext *parser;
4592     struct AVBitStreamFilterContext *next;
4593 } AVBitStreamFilterContext;
4594
4595
4596 typedef struct AVBitStreamFilter {
4597     const char *name;
4598     int priv_data_size;
4599     int (*filter)(AVBitStreamFilterContext *bsfc,
4600                   AVCodecContext *avctx, const char *args,
4601                   uint8_t **poutbuf, int *poutbuf_size,
4602                   const uint8_t *buf, int buf_size, int keyframe);
4603     void (*close)(AVBitStreamFilterContext *bsfc);
4604     struct AVBitStreamFilter *next;
4605 } AVBitStreamFilter;
4606
4607 void av_register_bitstream_filter(AVBitStreamFilter *bsf);
4608 AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
4609 int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
4610                                AVCodecContext *avctx, const char *args,
4611                                uint8_t **poutbuf, int *poutbuf_size,
4612                                const uint8_t *buf, int buf_size, int keyframe);
4613 void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);
4614
4615 AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f);
4616
4617 /* memory */
4618
4619 /**
4620  * Reallocate the given block if it is not large enough, otherwise do nothing.
4621  *
4622  * @see av_realloc
4623  */
4624 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
4625
4626 /**
4627  * Allocate a buffer, reusing the given one if large enough.
4628  *
4629  * Contrary to av_fast_realloc the current buffer contents might not be
4630  * preserved and on error the old buffer is freed, thus no special
4631  * handling to avoid memleaks is necessary.
4632  *
4633  * @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer
4634  * @param size size of the buffer *ptr points to
4635  * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
4636  *                 *size 0 if an error occurred.
4637  */
4638 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
4639
4640 /**
4641  * Copy image src to dst. Wraps av_picture_data_copy() above.
4642  */
4643 void av_picture_copy(AVPicture *dst, const AVPicture *src,
4644                      enum PixelFormat pix_fmt, int width, int height);
4645
4646 /**
4647  * Crop image top and left side.
4648  */
4649 int av_picture_crop(AVPicture *dst, const AVPicture *src,
4650                     enum PixelFormat pix_fmt, int top_band, int left_band);
4651
4652 /**
4653  * Pad image.
4654  */
4655 int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, enum PixelFormat pix_fmt,
4656             int padtop, int padbottom, int padleft, int padright, int *color);
4657
4658 /**
4659  * Encode extradata length to a buffer. Used by xiph codecs.
4660  *
4661  * @param s buffer to write to; must be at least (v/255+1) bytes long
4662  * @param v size of extradata in bytes
4663  * @return number of bytes written to the buffer.
4664  */
4665 unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
4666
4667 /**
4668  * Log a generic warning message about a missing feature. This function is
4669  * intended to be used internally by Libav (libavcodec, libavformat, etc.)
4670  * only, and would normally not be used by applications.
4671  * @param[in] avc a pointer to an arbitrary struct of which the first field is
4672  * a pointer to an AVClass struct
4673  * @param[in] feature string containing the name of the missing feature
4674  * @param[in] want_sample indicates if samples are wanted which exhibit this feature.
4675  * If want_sample is non-zero, additional verbage will be added to the log
4676  * message which tells the user how to report samples to the development
4677  * mailing list.
4678  */
4679 void av_log_missing_feature(void *avc, const char *feature, int want_sample);
4680
4681 /**
4682  * Log a generic warning message asking for a sample. This function is
4683  * intended to be used internally by Libav (libavcodec, libavformat, etc.)
4684  * only, and would normally not be used by applications.
4685  * @param[in] avc a pointer to an arbitrary struct of which the first field is
4686  * a pointer to an AVClass struct
4687  * @param[in] msg string containing an optional message, or NULL if no message
4688  */
4689 void av_log_ask_for_sample(void *avc, const char *msg, ...) av_printf_format(2, 3);
4690
4691 /**
4692  * Register the hardware accelerator hwaccel.
4693  */
4694 void av_register_hwaccel(AVHWAccel *hwaccel);
4695
4696 /**
4697  * If hwaccel is NULL, returns the first registered hardware accelerator,
4698  * if hwaccel is non-NULL, returns the next registered hardware accelerator
4699  * after hwaccel, or NULL if hwaccel is the last one.
4700  */
4701 AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel);
4702
4703
4704 /**
4705  * Lock operation used by lockmgr
4706  */
4707 enum AVLockOp {
4708   AV_LOCK_CREATE,  ///< Create a mutex
4709   AV_LOCK_OBTAIN,  ///< Lock the mutex
4710   AV_LOCK_RELEASE, ///< Unlock the mutex
4711   AV_LOCK_DESTROY, ///< Free mutex resources
4712 };
4713
4714 /**
4715  * Register a user provided lock manager supporting the operations
4716  * specified by AVLockOp. mutex points to a (void *) where the
4717  * lockmgr should store/get a pointer to a user allocated mutex. It's
4718  * NULL upon AV_LOCK_CREATE and != NULL for all other ops.
4719  *
4720  * @param cb User defined callback. Note: Libav may invoke calls to this
4721  *           callback during the call to av_lockmgr_register().
4722  *           Thus, the application must be prepared to handle that.
4723  *           If cb is set to NULL the lockmgr will be unregistered.
4724  *           Also note that during unregistration the previously registered
4725  *           lockmgr callback may also be invoked.
4726  */
4727 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op));
4728
4729 /**
4730  * Get the type of the given codec.
4731  */
4732 enum AVMediaType avcodec_get_type(enum CodecID codec_id);
4733
4734 /**
4735  * Get the AVClass for AVCodecContext. It can be used in combination with
4736  * AV_OPT_SEARCH_FAKE_OBJ for examining options.
4737  *
4738  * @see av_opt_find().
4739  */
4740 const AVClass *avcodec_get_class(void);
4741
4742 #endif /* AVCODEC_AVCODEC_H */