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