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