avcodec.h 121 KB
Newer Older
1 2 3
/*
 * copyright (c) 2001 Fabrice Bellard
 *
4 5 6
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
7 8
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * FFmpeg is distributed in the hope that it will be useful,
12 13 14 15 16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with FFmpeg; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 20
 */

21 22
#ifndef AVCODEC_AVCODEC_H
#define AVCODEC_AVCODEC_H
Fabrice Bellard's avatar
Fabrice Bellard committed
23

24
/**
25
 * @file libavcodec/avcodec.h
Diego Biurrun's avatar
Diego Biurrun committed
26
 * external API header
27 28
 */

29
#include <errno.h>
30
#include "libavutil/avutil.h"
Fabrice Bellard's avatar
Fabrice Bellard committed
31

32
#define LIBAVCODEC_VERSION_MAJOR 52
33
#define LIBAVCODEC_VERSION_MINOR 36
34
#define LIBAVCODEC_VERSION_MICRO  0
35

36 37 38 39 40 41
#define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                               LIBAVCODEC_VERSION_MINOR, \
                                               LIBAVCODEC_VERSION_MICRO)
#define LIBAVCODEC_VERSION      AV_VERSION(LIBAVCODEC_VERSION_MAJOR,    \
                                           LIBAVCODEC_VERSION_MINOR,    \
                                           LIBAVCODEC_VERSION_MICRO)
42
#define LIBAVCODEC_BUILD        LIBAVCODEC_VERSION_INT
Michael Niedermayer's avatar
Michael Niedermayer committed
43

44
#define LIBAVCODEC_IDENT        "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
Alex Beregszaszi's avatar
Alex Beregszaszi committed
45

46
#define AV_NOPTS_VALUE          INT64_C(0x8000000000000000)
47 48
#define AV_TIME_BASE            1000000
#define AV_TIME_BASE_Q          (AVRational){1, AV_TIME_BASE}
49

50
/**
51 52 53 54 55 56
 * Identifies the syntax and semantics of the bitstream.
 * The principle is roughly:
 * Two decoders with the same ID can decode the same streams.
 * Two encoders with the same ID can encode compatible streams.
 * There may be slight deviations from the principle due to implementation
 * details.
57
 *
Diego Biurrun's avatar
Diego Biurrun committed
58 59 60
 * If you add a codec ID to this list, add it so that
 * 1. no value of a existing codec ID changes (that would break ABI),
 * 2. it is as close as possible to similar codecs.
61
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
62
enum CodecID {
63
    CODEC_ID_NONE,
64 65

    /* video codecs */
Fabrice Bellard's avatar
Fabrice Bellard committed
66
    CODEC_ID_MPEG1VIDEO,
67
    CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding
Ivan Kalvachev's avatar
Ivan Kalvachev committed
68
    CODEC_ID_MPEG2VIDEO_XVMC,
69
    CODEC_ID_H261,
Fabrice Bellard's avatar
Fabrice Bellard committed
70 71
    CODEC_ID_H263,
    CODEC_ID_RV10,
Michael Niedermayer's avatar
Michael Niedermayer committed
72
    CODEC_ID_RV20,
Fabrice Bellard's avatar
Fabrice Bellard committed
73
    CODEC_ID_MJPEG,
74
    CODEC_ID_MJPEGB,
75
    CODEC_ID_LJPEG,
76
    CODEC_ID_SP5X,
77
    CODEC_ID_JPEGLS,
78
    CODEC_ID_MPEG4,
Fabrice Bellard's avatar
Fabrice Bellard committed
79
    CODEC_ID_RAWVIDEO,
80 81 82
    CODEC_ID_MSMPEG4V1,
    CODEC_ID_MSMPEG4V2,
    CODEC_ID_MSMPEG4V3,
83
    CODEC_ID_WMV1,
84
    CODEC_ID_WMV2,
Fabrice Bellard's avatar
Fabrice Bellard committed
85 86
    CODEC_ID_H263P,
    CODEC_ID_H263I,
87
    CODEC_ID_FLV1,
Nick Kurshev's avatar
Nick Kurshev committed
88
    CODEC_ID_SVQ1,
89
    CODEC_ID_SVQ3,
Fabrice Bellard's avatar
Fabrice Bellard committed
90
    CODEC_ID_DVVIDEO,
Michael Niedermayer's avatar
Michael Niedermayer committed
91
    CODEC_ID_HUFFYUV,
92
    CODEC_ID_CYUV,
93
    CODEC_ID_H264,
94
    CODEC_ID_INDEO3,
95
    CODEC_ID_VP3,
96
    CODEC_ID_THEORA,
Michael Niedermayer's avatar
Michael Niedermayer committed
97
    CODEC_ID_ASV1,
Michael Niedermayer's avatar
Michael Niedermayer committed
98
    CODEC_ID_ASV2,
99
    CODEC_ID_FFV1,
100
    CODEC_ID_4XM,
Michael Niedermayer's avatar
Michael Niedermayer committed
101
    CODEC_ID_VCR1,
Alex Beregszaszi's avatar
Alex Beregszaszi committed
102
    CODEC_ID_CLJR,
103
    CODEC_ID_MDEC,
104 105
    CODEC_ID_ROQ,
    CODEC_ID_INTERPLAY_VIDEO,
106 107
    CODEC_ID_XAN_WC3,
    CODEC_ID_XAN_WC4,
108 109 110 111 112
    CODEC_ID_RPZA,
    CODEC_ID_CINEPAK,
    CODEC_ID_WS_VQA,
    CODEC_ID_MSRLE,
    CODEC_ID_MSVIDEO1,
113
    CODEC_ID_IDCIN,
Roberto Togni's avatar
Roberto Togni committed
114
    CODEC_ID_8BPS,
115
    CODEC_ID_SMC,
Mike Melanson's avatar
Mike Melanson committed
116
    CODEC_ID_FLIC,
117
    CODEC_ID_TRUEMOTION1,
118
    CODEC_ID_VMDVIDEO,
119 120
    CODEC_ID_MSZH,
    CODEC_ID_ZLIB,
121
    CODEC_ID_QTRLE,
122
    CODEC_ID_SNOW,
123
    CODEC_ID_TSCC,
124
    CODEC_ID_ULTI,
125
    CODEC_ID_QDRAW,
126
    CODEC_ID_VIXL,
127
    CODEC_ID_QPEG,
128 129 130 131 132 133 134
    CODEC_ID_XVID,
    CODEC_ID_PNG,
    CODEC_ID_PPM,
    CODEC_ID_PBM,
    CODEC_ID_PGM,
    CODEC_ID_PGMYUV,
    CODEC_ID_PAM,
135
    CODEC_ID_FFVHUFF,
136 137
    CODEC_ID_RV30,
    CODEC_ID_RV40,
138
    CODEC_ID_VC1,
139
    CODEC_ID_WMV3,
140
    CODEC_ID_LOCO,
141
    CODEC_ID_WNV1,
142
    CODEC_ID_AASC,
143
    CODEC_ID_INDEO2,
144
    CODEC_ID_FRAPS,
145
    CODEC_ID_TRUEMOTION2,
Måns Rullgård's avatar
Måns Rullgård committed
146
    CODEC_ID_BMP,
147
    CODEC_ID_CSCD,
148
    CODEC_ID_MMVIDEO,
149
    CODEC_ID_ZMBV,
150
    CODEC_ID_AVS,
151
    CODEC_ID_SMACKVIDEO,
152
    CODEC_ID_NUV,
153
    CODEC_ID_KMVC,
154
    CODEC_ID_FLASHSV,
155
    CODEC_ID_CAVS,
156
    CODEC_ID_JPEG2000,
157
    CODEC_ID_VMNC,
158 159 160
    CODEC_ID_VP5,
    CODEC_ID_VP6,
    CODEC_ID_VP6F,
Kostya Shishkov's avatar
Kostya Shishkov committed
161
    CODEC_ID_TARGA,
162
    CODEC_ID_DSICINVIDEO,
163
    CODEC_ID_TIERTEXSEQVIDEO,
Kostya Shishkov's avatar
Kostya Shishkov committed
164
    CODEC_ID_TIFF,
165
    CODEC_ID_GIF,
166
    CODEC_ID_FFH264,
167
    CODEC_ID_DXA,
Baptiste Coudurier's avatar
Baptiste Coudurier committed
168
    CODEC_ID_DNXHD,
169
    CODEC_ID_THP,
170
    CODEC_ID_SGI,
171
    CODEC_ID_C93,
172
    CODEC_ID_BETHSOFTVID,
173
    CODEC_ID_PTX,
Ivo van Poorten's avatar
Ivo van Poorten committed
174
    CODEC_ID_TXD,
175
    CODEC_ID_VP6A,
Vladimir Voroshilov's avatar
Vladimir Voroshilov committed
176
    CODEC_ID_AMV,
177
    CODEC_ID_VB,
178
    CODEC_ID_PCX,
Ivo van Poorten's avatar
Ivo van Poorten committed
179
    CODEC_ID_SUNRAST,
180 181
    CODEC_ID_INDEO4,
    CODEC_ID_INDEO5,
Ramiro Polla's avatar
Ramiro Polla committed
182
    CODEC_ID_MIMIC,
Sascha Sommer's avatar
Sascha Sommer committed
183
    CODEC_ID_RL2,
Jai Menon's avatar
Jai Menon committed
184 185
    CODEC_ID_8SVX_EXP,
    CODEC_ID_8SVX_FIB,
Eli Friedman's avatar
Eli Friedman committed
186
    CODEC_ID_ESCAPE124,
Michael Niedermayer's avatar
Michael Niedermayer committed
187
    CODEC_ID_DIRAC,
Sisir Koppaka's avatar
Sisir Koppaka committed
188
    CODEC_ID_BFI,
Peter Ross's avatar
Peter Ross committed
189
    CODEC_ID_CMV,
190
    CODEC_ID_MOTIONPIXELS,
Peter Ross's avatar
Peter Ross committed
191
    CODEC_ID_TGV,
192
    CODEC_ID_TGQ,
Peter Ross's avatar
Peter Ross committed
193
    CODEC_ID_TQI,
194 195
    CODEC_ID_AURA,
    CODEC_ID_AURA2,
196
    CODEC_ID_V210X,
197
    CODEC_ID_TMV,
198
    CODEC_ID_V210,
199
    CODEC_ID_DPX,
200
    CODEC_ID_MAD,
Fabrice Bellard's avatar
Fabrice Bellard committed
201

Diego Biurrun's avatar
Diego Biurrun committed
202
    /* various PCM "codecs" */
203
    CODEC_ID_PCM_S16LE= 0x10000,
Fabrice Bellard's avatar
Fabrice Bellard committed
204 205 206 207 208 209 210
    CODEC_ID_PCM_S16BE,
    CODEC_ID_PCM_U16LE,
    CODEC_ID_PCM_U16BE,
    CODEC_ID_PCM_S8,
    CODEC_ID_PCM_U8,
    CODEC_ID_PCM_MULAW,
    CODEC_ID_PCM_ALAW,
211 212 213 214 215 216 217 218 219
    CODEC_ID_PCM_S32LE,
    CODEC_ID_PCM_S32BE,
    CODEC_ID_PCM_U32LE,
    CODEC_ID_PCM_U32BE,
    CODEC_ID_PCM_S24LE,
    CODEC_ID_PCM_S24BE,
    CODEC_ID_PCM_U24LE,
    CODEC_ID_PCM_U24BE,
    CODEC_ID_PCM_S24DAUD,
220
    CODEC_ID_PCM_ZORK,
221
    CODEC_ID_PCM_S16LE_PLANAR,
222
    CODEC_ID_PCM_DVD,
223
    CODEC_ID_PCM_F32BE,
224 225 226
    CODEC_ID_PCM_F32LE,
    CODEC_ID_PCM_F64BE,
    CODEC_ID_PCM_F64LE,
227
    CODEC_ID_PCM_BLURAY,
228

Diego Biurrun's avatar
Diego Biurrun committed
229
    /* various ADPCM codecs */
230
    CODEC_ID_ADPCM_IMA_QT= 0x11000,
231
    CODEC_ID_ADPCM_IMA_WAV,
232 233
    CODEC_ID_ADPCM_IMA_DK3,
    CODEC_ID_ADPCM_IMA_DK4,
234
    CODEC_ID_ADPCM_IMA_WS,
235
    CODEC_ID_ADPCM_IMA_SMJPEG,
236
    CODEC_ID_ADPCM_MS,
237
    CODEC_ID_ADPCM_4XM,
238 239
    CODEC_ID_ADPCM_XA,
    CODEC_ID_ADPCM_ADX,
240
    CODEC_ID_ADPCM_EA,
241
    CODEC_ID_ADPCM_G726,
242
    CODEC_ID_ADPCM_CT,
243
    CODEC_ID_ADPCM_SWF,
244
    CODEC_ID_ADPCM_YAMAHA,
245 246 247
    CODEC_ID_ADPCM_SBPRO_4,
    CODEC_ID_ADPCM_SBPRO_3,
    CODEC_ID_ADPCM_SBPRO_2,
248
    CODEC_ID_ADPCM_THP,
Vitor Sessak's avatar
Vitor Sessak committed
249
    CODEC_ID_ADPCM_IMA_AMV,
250 251 252
    CODEC_ID_ADPCM_EA_R1,
    CODEC_ID_ADPCM_EA_R3,
    CODEC_ID_ADPCM_EA_R2,
Peter Ross's avatar
Peter Ross committed
253
    CODEC_ID_ADPCM_IMA_EA_SEAD,
Peter Ross's avatar
Peter Ross committed
254
    CODEC_ID_ADPCM_IMA_EA_EACS,
255
    CODEC_ID_ADPCM_EA_XAS,
256
    CODEC_ID_ADPCM_EA_MAXIS_XA,
257
    CODEC_ID_ADPCM_IMA_ISS,
258

259 260
    /* AMR */
    CODEC_ID_AMR_NB= 0x12000,
261 262
    CODEC_ID_AMR_WB,

263
    /* RealAudio codecs*/
264
    CODEC_ID_RA_144= 0x13000,
265
    CODEC_ID_RA_288,
266 267

    /* various DPCM codecs */
268
    CODEC_ID_ROQ_DPCM= 0x14000,
269
    CODEC_ID_INTERPLAY_DPCM,
270
    CODEC_ID_XAN_DPCM,
271
    CODEC_ID_SOL_DPCM,
272

273
    /* audio codecs */
274
    CODEC_ID_MP2= 0x15000,
275
    CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
276 277 278 279 280 281 282 283 284 285 286 287
    CODEC_ID_AAC,
    CODEC_ID_AC3,
    CODEC_ID_DTS,
    CODEC_ID_VORBIS,
    CODEC_ID_DVAUDIO,
    CODEC_ID_WMAV1,
    CODEC_ID_WMAV2,
    CODEC_ID_MACE3,
    CODEC_ID_MACE6,
    CODEC_ID_VMDAUDIO,
    CODEC_ID_SONIC,
    CODEC_ID_SONIC_LS,
Michael Niedermayer's avatar
Michael Niedermayer committed
288
    CODEC_ID_FLAC,
Roberto Togni's avatar
Roberto Togni committed
289
    CODEC_ID_MP3ADU,
290
    CODEC_ID_MP3ON4,
291
    CODEC_ID_SHORTEN,
292
    CODEC_ID_ALAC,
293
    CODEC_ID_WESTWOOD_SND1,
294
    CODEC_ID_GSM, ///< as in Berlin toast format
Roberto Togni's avatar
Roberto Togni committed
295
    CODEC_ID_QDM2,
296
    CODEC_ID_COOK,
297
    CODEC_ID_TRUESPEECH,
298
    CODEC_ID_TTA,
299
    CODEC_ID_SMACKAUDIO,
300
    CODEC_ID_QCELP,
301
    CODEC_ID_WAVPACK,
302
    CODEC_ID_DSICINAUDIO,
Kostya Shishkov's avatar
Kostya Shishkov committed
303
    CODEC_ID_IMC,
304
    CODEC_ID_MUSEPACK7,
305
    CODEC_ID_MLP,
Diego Biurrun's avatar
Diego Biurrun committed
306
    CODEC_ID_GSM_MS, /* as found in WAV */
Benjamin Larsson's avatar
Benjamin Larsson committed
307
    CODEC_ID_ATRAC3,
308
    CODEC_ID_VOXWARE,
Kostya Shishkov's avatar
Kostya Shishkov committed
309
    CODEC_ID_APE,
310
    CODEC_ID_NELLYMOSER,
311
    CODEC_ID_MUSEPACK8,
312
    CODEC_ID_SPEEX,
313 314
    CODEC_ID_WMAVOICE,
    CODEC_ID_WMAPRO,
315
    CODEC_ID_WMALOSSLESS,
Benjamin Larsson's avatar
Benjamin Larsson committed
316
    CODEC_ID_ATRAC3P,
317
    CODEC_ID_EAC3,
318
    CODEC_ID_SIPR,
Michael Niedermayer's avatar
Michael Niedermayer committed
319
    CODEC_ID_MP1,
Vitor Sessak's avatar
Vitor Sessak committed
320
    CODEC_ID_TWINVQ,
321
    CODEC_ID_TRUEHD,
322
    CODEC_ID_MP4ALS,
Benjamin Larsson's avatar
Benjamin Larsson committed
323
    CODEC_ID_ATRAC1,
324

325
    /* subtitle codecs */
326 327
    CODEC_ID_DVD_SUBTITLE= 0x17000,
    CODEC_ID_DVB_SUBTITLE,
328
    CODEC_ID_TEXT,  ///< raw UTF-8 text
329
    CODEC_ID_XSUB,
330
    CODEC_ID_SSA,
331
    CODEC_ID_MOV_TEXT,
332
    CODEC_ID_HDMV_PGS_SUBTITLE,
333

Diego Biurrun's avatar
Diego Biurrun committed
334
    /* other specific kind of codecs (generally used for attachments) */
335 336
    CODEC_ID_TTF= 0x18000,

337 338
    CODEC_ID_PROBE= 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it

339
    CODEC_ID_MPEG2TS= 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
Diego Biurrun's avatar
Diego Biurrun committed
340
                                * stream (only used by libavformat) */
Fabrice Bellard's avatar
Fabrice Bellard committed
341
};
342

Fabrice Bellard's avatar
Fabrice Bellard committed
343
enum CodecType {
344
    CODEC_TYPE_UNKNOWN = -1,
Fabrice Bellard's avatar
Fabrice Bellard committed
345 346
    CODEC_TYPE_VIDEO,
    CODEC_TYPE_AUDIO,
347
    CODEC_TYPE_DATA,
348
    CODEC_TYPE_SUBTITLE,
349
    CODEC_TYPE_ATTACHMENT,
350
    CODEC_TYPE_NB
Fabrice Bellard's avatar
Fabrice Bellard committed
351 352
};

353 354 355
/**
 * all in native-endian format
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
356
enum SampleFormat {
357
    SAMPLE_FMT_NONE = -1,
358 359
    SAMPLE_FMT_U8,              ///< unsigned 8 bits
    SAMPLE_FMT_S16,             ///< signed 16 bits
360
    SAMPLE_FMT_S32,             ///< signed 32 bits
361
    SAMPLE_FMT_FLT,             ///< float
Peter Ross's avatar
Peter Ross committed
362
    SAMPLE_FMT_DBL,             ///< double
363
    SAMPLE_FMT_NB               ///< Number of sample formats. DO NOT USE if dynamically linking to libavcodec
Fabrice Bellard's avatar
Fabrice Bellard committed
364 365
};

366
/* Audio channel masks */
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
#define CH_FRONT_LEFT             0x00000001
#define CH_FRONT_RIGHT            0x00000002
#define CH_FRONT_CENTER           0x00000004
#define CH_LOW_FREQUENCY          0x00000008
#define CH_BACK_LEFT              0x00000010
#define CH_BACK_RIGHT             0x00000020
#define CH_FRONT_LEFT_OF_CENTER   0x00000040
#define CH_FRONT_RIGHT_OF_CENTER  0x00000080
#define CH_BACK_CENTER            0x00000100
#define CH_SIDE_LEFT              0x00000200
#define CH_SIDE_RIGHT             0x00000400
#define CH_TOP_CENTER             0x00000800
#define CH_TOP_FRONT_LEFT         0x00001000
#define CH_TOP_FRONT_CENTER       0x00002000
#define CH_TOP_FRONT_RIGHT        0x00004000
#define CH_TOP_BACK_LEFT          0x00008000
#define CH_TOP_BACK_CENTER        0x00010000
#define CH_TOP_BACK_RIGHT         0x00020000
#define CH_STEREO_LEFT            0x20000000  ///< Stereo downmix.
#define CH_STEREO_RIGHT           0x40000000  ///< See CH_STEREO_LEFT.
387 388

/* Audio channel convenience macros */
389 390
#define CH_LAYOUT_MONO              (CH_FRONT_CENTER)
#define CH_LAYOUT_STEREO            (CH_FRONT_LEFT|CH_FRONT_RIGHT)
391
#define CH_LAYOUT_2_1               (CH_LAYOUT_STEREO|CH_BACK_CENTER)
392
#define CH_LAYOUT_SURROUND          (CH_LAYOUT_STEREO|CH_FRONT_CENTER)
393 394
#define CH_LAYOUT_4POINT0           (CH_LAYOUT_SURROUND|CH_BACK_CENTER)
#define CH_LAYOUT_2_2               (CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT)
395 396 397
#define CH_LAYOUT_QUAD              (CH_LAYOUT_STEREO|CH_BACK_LEFT|CH_BACK_RIGHT)
#define CH_LAYOUT_5POINT0           (CH_LAYOUT_SURROUND|CH_SIDE_LEFT|CH_SIDE_RIGHT)
#define CH_LAYOUT_5POINT1           (CH_LAYOUT_5POINT0|CH_LOW_FREQUENCY)
398 399
#define CH_LAYOUT_5POINT0_BACK      (CH_LAYOUT_SURROUND|CH_BACK_LEFT|CH_BACK_RIGHT)
#define CH_LAYOUT_5POINT1_BACK      (CH_LAYOUT_5POINT0_BACK|CH_LOW_FREQUENCY)
400
#define CH_LAYOUT_7POINT0           (CH_LAYOUT_5POINT0|CH_BACK_LEFT|CH_BACK_RIGHT)
401
#define CH_LAYOUT_7POINT1           (CH_LAYOUT_5POINT1|CH_BACK_LEFT|CH_BACK_RIGHT)
402
#define CH_LAYOUT_7POINT1_WIDE      (CH_LAYOUT_5POINT1_BACK|\
403 404
                                          CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER)
#define CH_LAYOUT_STEREO_DOWNMIX    (CH_STEREO_LEFT|CH_STEREO_RIGHT)
405

Fabrice Bellard's avatar
Fabrice Bellard committed
406
/* in bytes */
407
#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
Fabrice Bellard's avatar
Fabrice Bellard committed
408

409
/**
410
 * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Diego Biurrun's avatar
Diego Biurrun committed
411 412 413 414
 * This is mainly needed because some optimized bitstream readers read
 * 32 or 64 bit at once and could read over the end.<br>
 * Note: If the first 23 bits of the additional bytes are not 0, then damaged
 * MPEG bitstreams could cause overread and segfault.
415 416 417
 */
#define FF_INPUT_BUFFER_PADDING_SIZE 8

418
/**
Diego Biurrun's avatar
Diego Biurrun committed
419 420
 * minimum encoding buffer size
 * Used to avoid some checks during header writing.
421 422 423
 */
#define FF_MIN_BUFFER_SIZE 16384

424

425
/**
426
 * motion estimation type.
427
 */
428
enum Motion_Est_ID {
429
    ME_ZERO = 1,    ///< no search, that is use 0,0 vector whenever one is needed
430 431 432
    ME_FULL,
    ME_LOG,
    ME_PHODS,
433 434 435 436 437
    ME_EPZS,        ///< enhanced predictive zonal search
    ME_X1,          ///< reserved for experiments
    ME_HEX,         ///< hexagon based search
    ME_UMH,         ///< uneven multi-hexagon search
    ME_ITER,        ///< iterative search
Loren Merritt's avatar
Loren Merritt committed
438
    ME_TESA,        ///< transformed exhaustive search algorithm
439 440
};

Michael Niedermayer's avatar
Michael Niedermayer committed
441
enum AVDiscard{
Diego Biurrun's avatar
Diego Biurrun committed
442 443
    /* We leave some space between them for extensions (drop some
     * keyframes for intra-only or drop just some bidir frames). */
Michael Niedermayer's avatar
Michael Niedermayer committed
444 445 446 447 448 449 450 451
    AVDISCARD_NONE   =-16, ///< discard nothing
    AVDISCARD_DEFAULT=  0, ///< discard useless packets like 0 size packets in avi
    AVDISCARD_NONREF =  8, ///< discard all non reference
    AVDISCARD_BIDIR  = 16, ///< discard all bidirectional frames
    AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
    AVDISCARD_ALL    = 48, ///< discard all
};

452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
enum AVColorPrimaries{
    AVCOL_PRI_BT709      =1, ///< also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
    AVCOL_PRI_UNSPECIFIED=2,
    AVCOL_PRI_BT470M     =4,
    AVCOL_PRI_BT470BG    =5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
    AVCOL_PRI_SMPTE170M  =6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
    AVCOL_PRI_SMPTE240M  =7, ///< functionally identical to above
    AVCOL_PRI_FILM       =8,
    AVCOL_PRI_NB           , ///< Not part of ABI
};

enum AVColorTransferCharacteristic{
    AVCOL_TRC_BT709      =1, ///< also ITU-R BT1361
    AVCOL_TRC_UNSPECIFIED=2,
    AVCOL_TRC_GAMMA22    =4, ///< also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
    AVCOL_TRC_GAMMA28    =5, ///< also ITU-R BT470BG
    AVCOL_TRC_NB           , ///< Not part of ABI
};

enum AVColorSpace{
    AVCOL_SPC_RGB        =0,
    AVCOL_SPC_BT709      =1, ///< also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
    AVCOL_SPC_UNSPECIFIED=2,
    AVCOL_SPC_FCC        =4,
    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
    AVCOL_SPC_SMPTE170M  =6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
    AVCOL_SPC_SMPTE240M  =7,
    AVCOL_SPC_NB           , ///< Not part of ABI
};

enum AVColorRange{
    AVCOL_RANGE_UNSPECIFIED=0,
    AVCOL_RANGE_MPEG       =1, ///< the normal 219*2^(n-8) "MPEG" YUV ranges
    AVCOL_RANGE_JPEG       =2, ///< the normal     2^n-1   "JPEG" YUV ranges
    AVCOL_RANGE_NB           , ///< Not part of ABI
};

489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
/**
 *  X   X      3 4 X      X are luma samples,
 *             1 2        1-6 are possible chroma positions
 *  X   X      5 6 X      0 is undefined/unknown position
 */
enum AVChromaLocation{
    AVCHROMA_LOC_UNSPECIFIED=0,
    AVCHROMA_LOC_LEFT       =1, ///< mpeg2/4, h264 default
    AVCHROMA_LOC_CENTER     =2, ///< mpeg1, jpeg, h263
    AVCHROMA_LOC_TOPLEFT    =3, ///< DV
    AVCHROMA_LOC_TOP        =4,
    AVCHROMA_LOC_BOTTOMLEFT =5,
    AVCHROMA_LOC_BOTTOM     =6,
    AVCHROMA_LOC_NB           , ///< Not part of ABI
};

505 506 507
typedef struct RcOverride{
    int start_frame;
    int end_frame;
Diego Biurrun's avatar
Diego Biurrun committed
508
    int qscale; // If this is 0 then quality_factor will be used instead.
509 510 511
    float quality_factor;
} RcOverride;

512
#define FF_MAX_B_FRAMES 16
513

514
/* encoding support
Diego Biurrun's avatar
Diego Biurrun committed
515 516
   These flags can be passed in AVCodecContext.flags before initialization.
   Note: Not everything is supported yet.
517
*/
Fabrice Bellard's avatar
Fabrice Bellard committed
518

Diego Biurrun's avatar
Diego Biurrun committed
519 520 521 522 523 524
#define CODEC_FLAG_QSCALE 0x0002  ///< Use fixed qscale.
#define CODEC_FLAG_4MV    0x0004  ///< 4 MV per MB allowed / advanced prediction for H.263.
#define CODEC_FLAG_QPEL   0x0010  ///< Use qpel MC.
#define CODEC_FLAG_GMC    0x0020  ///< Use GMC.
#define CODEC_FLAG_MV0    0x0040  ///< Always try a MB with MV=<0,0>.
#define CODEC_FLAG_PART   0x0080  ///< Use data partitioning.
525 526
/**
 * The parent program guarantees that the input for B-frames containing
Diego Biurrun's avatar
Diego Biurrun committed
527
 * streams is not written to for at least s->max_b_frames+1 frames, if
528 529
 * this is not set the input will be copied.
 */
530
#define CODEC_FLAG_INPUT_PRESERVED 0x0100
Diego Biurrun's avatar
Diego Biurrun committed
531 532 533 534 535 536 537 538
#define CODEC_FLAG_PASS1           0x0200   ///< Use internal 2pass ratecontrol in first pass mode.
#define CODEC_FLAG_PASS2           0x0400   ///< Use internal 2pass ratecontrol in second pass mode.
#define CODEC_FLAG_EXTERN_HUFF     0x1000   ///< Use external Huffman table (for MJPEG).
#define CODEC_FLAG_GRAY            0x2000   ///< Only decode/encode grayscale.
#define CODEC_FLAG_EMU_EDGE        0x4000   ///< Don't draw edges.
#define CODEC_FLAG_PSNR            0x8000   ///< error[?] variables will be set during encoding.
#define CODEC_FLAG_TRUNCATED       0x00010000 /** Input bitstream might be truncated at a random
                                                  location instead of only at frame boundaries. */
Diego Biurrun's avatar
Diego Biurrun committed
539 540 541 542 543 544
#define CODEC_FLAG_NORMALIZE_AQP  0x00020000 ///< Normalize adaptive quantization.
#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT.
#define CODEC_FLAG_LOW_DELAY      0x00080000 ///< Force low delay.
#define CODEC_FLAG_ALT_SCAN       0x00100000 ///< Use alternate scan.
#define CODEC_FLAG_GLOBAL_HEADER  0x00400000 ///< Place global headers in extradata instead of every keyframe.
#define CODEC_FLAG_BITEXACT       0x00800000 ///< Use only bitexact stuff (except (I)DCT).
545
/* Fx : Flag for h263+ extra options */
Diego Biurrun's avatar
Diego Biurrun committed
546 547 548 549 550
#define CODEC_FLAG_AC_PRED        0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
#define CODEC_FLAG_H263P_UMV      0x02000000 ///< unlimited motion vector
#define CODEC_FLAG_CBP_RD         0x04000000 ///< Use rate distortion optimization for cbp.
#define CODEC_FLAG_QP_RD          0x08000000 ///< Use rate distortion optimization for qp selectioon.
#define CODEC_FLAG_H263P_AIV      0x00000008 ///< H.263 alternative inter VLC
Michael Niedermayer's avatar
Michael Niedermayer committed
551 552
#define CODEC_FLAG_OBMC           0x00000001 ///< OBMC
#define CODEC_FLAG_LOOP_FILTER    0x00000800 ///< loop filter
553 554
#define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000
#define CODEC_FLAG_INTERLACED_ME  0x20000000 ///< interlaced motion estimation
Diego Biurrun's avatar
Diego Biurrun committed
555
#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< Will reserve space for SVCD scan offset user data.
556
#define CODEC_FLAG_CLOSED_GOP     0x80000000
Diego Biurrun's avatar
Diego Biurrun committed
557 558 559 560 561 562
#define CODEC_FLAG2_FAST          0x00000001 ///< Allow non spec compliant speedup tricks.
#define CODEC_FLAG2_STRICT_GOP    0x00000002 ///< Strictly enforce GOP size.
#define CODEC_FLAG2_NO_OUTPUT     0x00000004 ///< Skip bitstream encoding.
#define CODEC_FLAG2_LOCAL_HEADER  0x00000008 ///< Place global headers at every keyframe instead of in extradata.
#define CODEC_FLAG2_BPYRAMID      0x00000010 ///< H.264 allow B-frames to be used as references.
#define CODEC_FLAG2_WPRED         0x00000020 ///< H.264 weighted biprediction for B-frames
563
#define CODEC_FLAG2_MIXED_REFS    0x00000040 ///< H.264 one reference per partition, as opposed to one reference per macroblock
Robert Swain's avatar
Robert Swain committed
564 565 566
#define CODEC_FLAG2_8X8DCT        0x00000080 ///< H.264 high profile 8x8 transform
#define CODEC_FLAG2_FASTPSKIP     0x00000100 ///< H.264 fast pskip
#define CODEC_FLAG2_AUD           0x00000200 ///< H.264 access unit delimiters
Diego Biurrun's avatar
Diego Biurrun committed
567 568 569 570 571 572 573
#define CODEC_FLAG2_BRDO          0x00000400 ///< B-frame rate-distortion optimization
#define CODEC_FLAG2_INTRA_VLC     0x00000800 ///< Use MPEG-2 intra VLC table.
#define CODEC_FLAG2_MEMC_ONLY     0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC).
#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format.
#define CODEC_FLAG2_SKIP_RD       0x00004000 ///< RD optimal MB level residual skipping
#define CODEC_FLAG2_CHUNKS        0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
#define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer.
574
#define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible
575

576
/* Unsupported options :
577 578
 *              Syntax Arithmetic coding (SAC)
 *              Reference Picture Selection
579
 *              Independent Segment Decoding */
580
/* /Fx */
581 582
/* codec capabilities */

Diego Biurrun's avatar
Diego Biurrun committed
583
#define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback.
584 585 586 587 588
/**
 * Codec uses get_buffer() for allocating buffers.
 * direct rendering method 1
 */
#define CODEC_CAP_DR1             0x0002
Diego Biurrun's avatar
Diego Biurrun committed
589
/* If 'parse_only' field is true, then avcodec_parse_frame() can be used. */
590
#define CODEC_CAP_PARSE_ONLY      0x0004
591
#define CODEC_CAP_TRUNCATED       0x0008
Diego Biurrun's avatar
Diego Biurrun committed
592
/* Codec can export data for HW decoding (XvMC). */
593
#define CODEC_CAP_HWACCEL         0x0010
594
/**
Diego Biurrun's avatar
Diego Biurrun committed
595 596
 * Codec has a nonzero delay and needs to be fed with NULL at the end to get the delayed data.
 * If this is not set, the codec is guaranteed to never be fed with NULL data.
597
 */
598
#define CODEC_CAP_DELAY           0x0020
599 600 601 602 603
/**
 * Codec can be fed a final frame with a smaller size.
 * This can be used to prevent truncation of the last audio samples.
 */
#define CODEC_CAP_SMALL_LAST_FRAME 0x0040
604 605 606 607
/**
 * Codec can export data for HW decoding (VDPAU).
 */
#define CODEC_CAP_HWACCEL_VDPAU    0x0080
608 609 610 611
/**
 * Codec can output multiple frames per AVPacket
 */
#define CODEC_CAP_SUBFRAMES        0x0100
612

Diego Biurrun's avatar
Diego Biurrun committed
613
//The following defines may change, don't expect compatibility if you use them.
614
#define MB_TYPE_INTRA4x4   0x0001
Diego Biurrun's avatar
Diego Biurrun committed
615 616
#define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific
#define MB_TYPE_INTRA_PCM  0x0004 //FIXME H.264-specific
617 618 619 620 621
#define MB_TYPE_16x16      0x0008
#define MB_TYPE_16x8       0x0010
#define MB_TYPE_8x16       0x0020
#define MB_TYPE_8x8        0x0040
#define MB_TYPE_INTERLACED 0x0080
Diego Biurrun's avatar
Diego Biurrun committed
622
#define MB_TYPE_DIRECT2    0x0100 //FIXME
623 624 625 626 627 628 629 630 631 632 633 634 635 636
#define MB_TYPE_ACPRED     0x0200
#define MB_TYPE_GMC        0x0400
#define MB_TYPE_SKIP       0x0800
#define MB_TYPE_P0L0       0x1000
#define MB_TYPE_P1L0       0x2000
#define MB_TYPE_P0L1       0x4000
#define MB_TYPE_P1L1       0x8000
#define MB_TYPE_L0         (MB_TYPE_P0L0 | MB_TYPE_P1L0)
#define MB_TYPE_L1         (MB_TYPE_P0L1 | MB_TYPE_P1L1)
#define MB_TYPE_L0L1       (MB_TYPE_L0   | MB_TYPE_L1)
#define MB_TYPE_QUANT      0x00010000
#define MB_TYPE_CBP        0x00020000
//Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...)

637 638
/**
 * Pan Scan area.
Diego Biurrun's avatar
Diego Biurrun committed
639 640
 * This specifies the area which should be displayed.
 * Note there may be multiple such areas for one frame.
641 642 643
 */
typedef struct AVPanScan{
    /**
Diego Biurrun's avatar
Diego Biurrun committed
644 645 646
     * id
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
647 648 649 650 651
     */
    int id;

    /**
     * width and height in 1/16 pel
Diego Biurrun's avatar
Diego Biurrun committed
652 653
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
654 655 656 657 658
     */
    int width;
    int height;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
659 660 661
     * position of the top left corner in 1/16 pel for up to 3 fields/frames
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
662 663 664 665
     */
    int16_t position[3][2];
}AVPanScan;

666
#define FF_COMMON_FRAME \
667 668
    /**\
     * pointer to the picture planes.\
Diego Biurrun's avatar
Diego Biurrun committed
669
     * This might be different from the first allocated byte\
670 671 672
     * - encoding: \
     * - decoding: \
     */\
Michael Niedermayer's avatar
Michael Niedermayer committed
673 674 675
    uint8_t *data[4];\
    int linesize[4];\
    /**\
Diego Biurrun's avatar
Diego Biurrun committed
676 677
     * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.\
     * This isn't used by libavcodec unless the default get/release_buffer() is used.\
678 679
     * - encoding: \
     * - decoding: \
Michael Niedermayer's avatar
Michael Niedermayer committed
680 681 682 683
     */\
    uint8_t *base[4];\
    /**\
     * 1 -> keyframe, 0-> not\
Diego Biurrun's avatar
Diego Biurrun committed
684 685
     * - encoding: Set by libavcodec.\
     * - decoding: Set by libavcodec.\
Michael Niedermayer's avatar
Michael Niedermayer committed
686 687 688 689
     */\
    int key_frame;\
\
    /**\
Diego Biurrun's avatar
Diego Biurrun committed
690 691 692
     * Picture type of the frame, see ?_TYPE below.\
     * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\
     * - decoding: Set by libavcodec.\
Michael Niedermayer's avatar
Michael Niedermayer committed
693 694 695 696
     */\
    int pict_type;\
\
    /**\
697
     * presentation timestamp in time_base units (time when frame should be shown to user)\
Diego Biurrun's avatar
Diego Biurrun committed
698 699 700
     * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.\
     * - encoding: MUST be set by user.\
     * - decoding: Set by libavcodec.\
Michael Niedermayer's avatar
Michael Niedermayer committed
701
     */\
702
    int64_t pts;\
Michael Niedermayer's avatar
Michael Niedermayer committed
703 704
\
    /**\
Diego Biurrun's avatar
Diego Biurrun committed
705
     * picture number in bitstream order\
706
     * - encoding: set by\
Diego Biurrun's avatar
Diego Biurrun committed
707
     * - decoding: Set by libavcodec.\
Michael Niedermayer's avatar
Michael Niedermayer committed
708 709 710
     */\
    int coded_picture_number;\
    /**\
Diego Biurrun's avatar
Diego Biurrun committed
711
     * picture number in display order\
712
     * - encoding: set by\
Diego Biurrun's avatar
Diego Biurrun committed
713
     * - decoding: Set by libavcodec.\
Michael Niedermayer's avatar
Michael Niedermayer committed
714 715 716 717
     */\
    int display_picture_number;\
\
    /**\
718
     * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \
Diego Biurrun's avatar
Diego Biurrun committed
719 720
     * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\
     * - decoding: Set by libavcodec.\
Michael Niedermayer's avatar
Michael Niedermayer committed
721
     */\
722
    int quality; \
Michael Niedermayer's avatar
Michael Niedermayer committed
723 724 725
\
    /**\
     * buffer age (1->was last buffer and dint change, 2->..., ...).\
Diego Biurrun's avatar
Diego Biurrun committed
726
     * Set to INT_MAX if the buffer has not been used yet.\
727
     * - encoding: unused\
Diego Biurrun's avatar
Diego Biurrun committed
728
     * - decoding: MUST be set by get_buffer().\
Michael Niedermayer's avatar
Michael Niedermayer committed
729 730 731 732 733
     */\
    int age;\
\
    /**\
     * is this picture used as reference\
734 735
     * The values for this are the same as the MpegEncContext.picture_structure\
     * variable, that is 1->top field, 2->bottom field, 3->frame/both fields.\
736
     * Set to 4 for delayed, non-reference frames.\
737
     * - encoding: unused\
Diego Biurrun's avatar
Diego Biurrun committed
738
     * - decoding: Set by libavcodec. (before get_buffer() call)).\
Michael Niedermayer's avatar
Michael Niedermayer committed
739 740 741 742 743
     */\
    int reference;\
\
    /**\
     * QP table\
744
     * - encoding: unused\
Diego Biurrun's avatar
Diego Biurrun committed
745
     * - decoding: Set by libavcodec.\
Michael Niedermayer's avatar
Michael Niedermayer committed
746 747 748 749
     */\
    int8_t *qscale_table;\
    /**\
     * QP store stride\
750
     * - encoding: unused\
Diego Biurrun's avatar
Diego Biurrun committed
751
     * - decoding: Set by libavcodec.\
Michael Niedermayer's avatar
Michael Niedermayer committed
752 753 754 755
     */\
    int qstride;\
\
    /**\
Diego Biurrun's avatar
Diego Biurrun committed
756
     * mbskip_table[mb]>=1 if MB didn't change\
Michael Niedermayer's avatar
Michael Niedermayer committed
757
     * stride= mb_width = (width+15)>>4\
758
     * - encoding: unused\
Diego Biurrun's avatar
Diego Biurrun committed
759
     * - decoding: Set by libavcodec.\
Michael Niedermayer's avatar
Michael Niedermayer committed
760 761
     */\
    uint8_t *mbskip_table;\
762 763
\
    /**\
Diego Biurrun's avatar
Diego Biurrun committed
764
     * motion vector table\
Michael Niedermayer's avatar
Michael Niedermayer committed
765 766 767 768 769 770 771
     * @code\
     * example:\
     * int mv_sample_log2= 4 - motion_subsample_log2;\
     * int mb_width= (width+15)>>4;\
     * int mv_stride= (mb_width << mv_sample_log2) + 1;\
     * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];\
     * @endcode\
Diego Biurrun's avatar
Diego Biurrun committed
772 773
     * - encoding: Set by user.\
     * - decoding: Set by libavcodec.\
774 775 776 777
     */\
    int16_t (*motion_val[2])[2];\
\
    /**\
Diego Biurrun's avatar
Diego Biurrun committed
778
     * macroblock type table\
779
     * mb_type_base + mb_width + 2\
Diego Biurrun's avatar
Diego Biurrun committed
780 781
     * - encoding: Set by user.\
     * - decoding: Set by libavcodec.\
782 783 784 785
     */\
    uint32_t *mb_type;\
\
    /**\
786 787
     * log2 of the size of the block which a single vector in motion_val represents: \
     * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)\
788
     * - encoding: unused\
Diego Biurrun's avatar
Diego Biurrun committed
789
     * - decoding: Set by libavcodec.\
790 791
     */\
    uint8_t motion_subsample_log2;\
Michael Niedermayer's avatar
Michael Niedermayer committed
792 793 794
\
    /**\
     * for some private data of the user\
795
     * - encoding: unused\
Diego Biurrun's avatar
Diego Biurrun committed
796
     * - decoding: Set by user.\
Michael Niedermayer's avatar
Michael Niedermayer committed
797 798
     */\
    void *opaque;\
799 800 801
\
    /**\
     * error\
Diego Biurrun's avatar
Diego Biurrun committed
802
     * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.\
803
     * - decoding: unused\
804 805
     */\
    uint64_t error[4];\
Michael Niedermayer's avatar
Michael Niedermayer committed
806 807
\
    /**\
Diego Biurrun's avatar
Diego Biurrun committed
808 809 810 811
     * type of the buffer (to keep track of who has to deallocate data[*])\
     * - encoding: Set by the one who allocates it.\
     * - decoding: Set by the one who allocates it.\
     * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.\
Michael Niedermayer's avatar
Michael Niedermayer committed
812 813
     */\
    int type;\
814 815
    \
    /**\
Diego Biurrun's avatar
Diego Biurrun committed
816
     * When decoding, this signals how much the picture must be delayed.\
817
     * extra_delay = repeat_pict / (2*fps)\
818
     * - encoding: unused\
Diego Biurrun's avatar
Diego Biurrun committed
819
     * - decoding: Set by libavcodec.\
820
     */\
Michael Niedermayer's avatar
Michael Niedermayer committed
821 822 823 824 825 826
    int repeat_pict;\
    \
    /**\
     * \
     */\
    int qscale_type;\
827 828 829
    \
    /**\
     * The content of the picture is interlaced.\
Diego Biurrun's avatar
Diego Biurrun committed
830 831
     * - encoding: Set by user.\
     * - decoding: Set by libavcodec. (default 0)\
832 833 834 835
     */\
    int interlaced_frame;\
    \
    /**\
Diego Biurrun's avatar
Diego Biurrun committed
836 837 838
     * If the content is interlaced, is top field displayed first.\
     * - encoding: Set by user.\
     * - decoding: Set by libavcodec.\
839
     */\
840
    int top_field_first;\
841 842 843
    \
    /**\
     * Pan scan.\
Diego Biurrun's avatar
Diego Biurrun committed
844 845
     * - encoding: Set by user.\
     * - decoding: Set by libavcodec.\
846 847
     */\
    AVPanScan *pan_scan;\
848 849
    \
    /**\
Diego Biurrun's avatar
Diego Biurrun committed
850
     * Tell user application that palette has changed from previous frame.\
851
     * - encoding: ??? (no palette-enabled encoder yet)\
Diego Biurrun's avatar
Diego Biurrun committed
852
     * - decoding: Set by libavcodec. (default 0).\
853 854
     */\
    int palette_has_changed;\
855 856
    \
    /**\
Diego Biurrun's avatar
Diego Biurrun committed
857
     * codec suggestion on buffer type if != 0\
858
     * - encoding: unused\
Diego Biurrun's avatar
Diego Biurrun committed
859
     * - decoding: Set by libavcodec. (before get_buffer() call)).\
860 861
     */\
    int buffer_hints;\
862 863
\
    /**\
Diego Biurrun's avatar
Diego Biurrun committed
864
     * DCT coefficients\
865
     * - encoding: unused\
Diego Biurrun's avatar
Diego Biurrun committed
866
     * - decoding: Set by libavcodec.\
867 868
     */\
    short *dct_coeff;\
869 870
\
    /**\
Diego Biurrun's avatar
Diego Biurrun committed
871 872 873
     * motion referece frame index\
     * - encoding: Set by user.\
     * - decoding: Set by libavcodec.\
874
     */\
875 876 877 878 879 880 881 882 883
    int8_t *ref_index[2];\
\
    /**\
     * reordered opaque 64bit number (generally a PTS) from AVCodecContext.reordered_opaque\
     * output in AVFrame.reordered_opaque\
     * - encoding: unused\
     * - decoding: Read by user.\
     */\
    int64_t reordered_opaque;\
884 885 886 887 888 889
\
    /**\
     * hardware accelerator private data (FFmpeg allocated)\
     * - encoding: unused\
     * - decoding: Set by libavcodec\
     */\
890
    void *hwaccel_picture_private;\
891

892

893 894 895
#define FF_QSCALE_TYPE_MPEG1 0
#define FF_QSCALE_TYPE_MPEG2 1
#define FF_QSCALE_TYPE_H264  2
Michael Niedermayer's avatar
Michael Niedermayer committed
896 897

#define FF_BUFFER_TYPE_INTERNAL 1
Diego Biurrun's avatar
Diego Biurrun committed
898 899 900
#define FF_BUFFER_TYPE_USER     2 ///< direct rendering buffers (image is (de)allocated by user)
#define FF_BUFFER_TYPE_SHARED   4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared.
#define FF_BUFFER_TYPE_COPY     8 ///< Just a (modified) copy of some other buffer, don't deallocate anything.
Michael Niedermayer's avatar
Michael Niedermayer committed
901

Michael Niedermayer's avatar
Michael Niedermayer committed
902

903 904 905 906 907 908
#define FF_I_TYPE  1 ///< Intra
#define FF_P_TYPE  2 ///< Predicted
#define FF_B_TYPE  3 ///< Bi-dir predicted
#define FF_S_TYPE  4 ///< S(GMC)-VOP MPEG4
#define FF_SI_TYPE 5 ///< Switching Intra
#define FF_SP_TYPE 6 ///< Switching Predicted
909
#define FF_BI_TYPE 7
Michael Niedermayer's avatar
Michael Niedermayer committed
910

Diego Biurrun's avatar
Diego Biurrun committed
911 912 913 914
#define FF_BUFFER_HINTS_VALID    0x01 // Buffer hints value is meaningful (if 0 ignore).
#define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer.
#define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content.
#define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update).
915

916 917
typedef struct AVPacket {
    /**
918 919
     * Presentation timestamp in AVStream->time_base units; the time at which
     * the decompressed packet will be presented to the user.
920 921 922 923 924 925 926 927
     * Can be AV_NOPTS_VALUE if it is not stored in the file.
     * pts MUST be larger or equal to dts as presentation cannot happen before
     * decompression, unless one wants to view hex dumps. Some formats misuse
     * the terms dts and pts/cts to mean something different. Such timestamps
     * must be converted to true pts/dts before they are stored in AVPacket.
     */
    int64_t pts;
    /**
928 929
     * Decompression timestamp in AVStream->time_base units; the time at which
     * the packet is decompressed.
930 931 932 933 934 935 936 937
     * Can be AV_NOPTS_VALUE if it is not stored in the file.
     */
    int64_t dts;
    uint8_t *data;
    int   size;
    int   stream_index;
    int   flags;
    /**
938
     * Duration of this packet in AVStream->time_base units, 0 if unknown.
939 940 941 942 943 944 945 946
     * Equals next_pts - this_pts in presentation order.
     */
    int   duration;
    void  (*destruct)(struct AVPacket *);
    void  *priv;
    int64_t pos;                            ///< byte position in stream, -1 if unknown

    /**
947
     * Time difference in AVStream->time_base units from the pts of this
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
     * packet to the point at which the output from the decoder has converged
     * independent from the availability of previous frames. That is, the
     * frames are virtually identical no matter if decoding started from
     * the very first frame or from this keyframe.
     * Is AV_NOPTS_VALUE if unknown.
     * This field is not the display duration of the current packet.
     *
     * The purpose of this field is to allow seeking in streams that have no
     * keyframes in the conventional sense. It corresponds to the
     * recovery point SEI in H.264 and match_time_delta in NUT. It is also
     * essential for some types of subtitle streams to ensure that all
     * subtitles are correctly displayed after seeking.
     */
    int64_t convergence_duration;
} AVPacket;
963 964 965 966
#define AV_PKT_FLAG_KEY   0x0001
#if LIBAVCODEC_VERSION_MAJOR < 53
#define PKT_FLAG_KEY AV_PKT_FLAG_KEY
#endif
967

968 969
/**
 * Audio Video Frame.
970 971
 * New fields can be added to the end of FF_COMMON_FRAME with minor version
 * bumps.
Diego Biurrun's avatar
Diego Biurrun committed
972
 * Removal, reordering and changes to existing fields require a major
973 974
 * version bump. No fields should be added into AVFrame before or after
 * FF_COMMON_FRAME!
Diego Biurrun's avatar
Diego Biurrun committed
975
 * sizeof(AVFrame) must not be used outside libav*.
976
 */
977 978 979
typedef struct AVFrame {
    FF_COMMON_FRAME
} AVFrame;
Michael Niedermayer's avatar
Michael Niedermayer committed
980

Michael Niedermayer's avatar
Michael Niedermayer committed
981
/**
982 983
 * main external API structure.
 * New fields can be added to the end with minor version bumps.
Diego Biurrun's avatar
Diego Biurrun committed
984
 * Removal, reordering and changes to existing fields require a major
985
 * version bump.
Diego Biurrun's avatar
Diego Biurrun committed
986
 * sizeof(AVCodecContext) must not be used outside libav*.
Michael Niedermayer's avatar
Michael Niedermayer committed
987
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
988
typedef struct AVCodecContext {
989
    /**
Diego Biurrun's avatar
Diego Biurrun committed
990
     * information on struct for av_log
991 992
     * - set by avcodec_alloc_context
     */
993
    const AVClass *av_class;
994
    /**
Diego Biurrun's avatar
Diego Biurrun committed
995 996 997
     * the average bitrate
     * - encoding: Set by user; unused for constant quantizer encoding.
     * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream.
998
     */
Fabrice Bellard's avatar
Fabrice Bellard committed
999
    int bit_rate;
1000 1001

    /**
1002
     * number of bits the bitstream is allowed to diverge from the reference.
1003
     *           the reference can be CBR (for CBR pass1) or VBR (for pass2)
Diego Biurrun's avatar
Diego Biurrun committed
1004
     * - encoding: Set by user; unused for constant quantizer encoding.
1005
     * - decoding: unused
1006
     */
1007
    int bit_rate_tolerance;
1008 1009

    /**
1010
     * CODEC_FLAG_*.
Diego Biurrun's avatar
Diego Biurrun committed
1011 1012
     * - encoding: Set by user.
     * - decoding: Set by user.
1013
     */
Fabrice Bellard's avatar
Fabrice Bellard committed
1014
    int flags;
1015 1016

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1017 1018 1019 1020 1021 1022
     * Some codecs need additional format info. It is stored here.
     * If any muxer uses this then ALL demuxers/parsers AND encoders for the
     * specific codec MUST set it correctly otherwise stream copy breaks.
     * In general use of this field by muxers is not recommanded.
     * - encoding: Set by libavcodec.
     * - decoding: Set by libavcodec. (FIXME: Is this OK?)
1023 1024 1025 1026
     */
    int sub_id;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1027
     * Motion estimation algorithm used for video coding.
Robert Swain's avatar
Robert Swain committed
1028
     * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
1029
     * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific]
1030 1031
     * - encoding: MUST be set by user.
     * - decoding: unused
1032 1033 1034 1035
     */
    int me_method;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1036 1037
     * some codecs need / can use extradata like Huffman tables.
     * mjpeg: Huffman tables
1038
     * rv10: additional flags
1039
     * mpeg4: global headers (they can be in the bitstream or here)
Diego Biurrun's avatar
Diego Biurrun committed
1040 1041 1042 1043 1044
     * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
     * than extradata_size to avoid prolems if it is read with the bitstream reader.
     * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
     * - encoding: Set/allocated/freed by libavcodec.
     * - decoding: Set/allocated/freed by user.
1045
     */
1046
    uint8_t *extradata;
1047
    int extradata_size;
1048

1049
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1050 1051
     * This is the fundamental unit of time (in seconds) in terms
     * of which frame timestamps are represented. For fixed-fps content,
1052 1053
     * timebase should be 1/framerate and timestamp increments should be
     * identically 1.
Diego Biurrun's avatar
Diego Biurrun committed
1054 1055
     * - encoding: MUST be set by user.
     * - decoding: Set by libavcodec.
1056
     */
1057
    AVRational time_base;
1058

1059
    /* video only */
1060
    /**
1061
     * picture width / height.
1062
     * - encoding: MUST be set by user.
Diego Biurrun's avatar
Diego Biurrun committed
1063 1064 1065
     * - decoding: Set by libavcodec.
     * Note: For compatibility it is possible to set this instead of
     * coded_width/height before decoding.
1066
     */
Fabrice Bellard's avatar
Fabrice Bellard committed
1067
    int width, height;
1068

1069
#define FF_ASPECT_EXTENDED 15
1070 1071

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1072 1073
     * the number of pictures in a group of pictures, or 0 for intra_only
     * - encoding: Set by user.
1074
     * - decoding: unused
1075 1076 1077 1078
     */
    int gop_size;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1079 1080 1081
     * Pixel format, see PIX_FMT_xxx.
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
1082
     */
1083
    enum PixelFormat pix_fmt;
1084

1085
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1086
     * Frame rate emulation. If not zero, the lower layer (i.e. format handler)
1087
     * has to read frames at native frame rate.
Diego Biurrun's avatar
Diego Biurrun committed
1088 1089
     * - encoding: Set by user.
     * - decoding: unused
1090 1091
     */
    int rate_emu;
1092

1093
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1094 1095
     * If non NULL, 'draw_horiz_band' is called by the libavcodec
     * decoder to draw a horizontal band. It improves cache usage. Not
1096
     * all codecs can do that. You must check the codec capabilities
Diego Biurrun's avatar
Diego Biurrun committed
1097
     * beforehand.
1098 1099 1100 1101 1102 1103 1104
     * The function is also used by hardware acceleration APIs.
     * It is called at least once during frame decoding to pass
     * the data needed for hardware render.
     * In that mode instead of pixel data, AVFrame points to
     * a structure specific to the acceleration API. The application
     * reads the structure and can change some fields to indicate progress
     * or mark state.
1105
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1106
     * - decoding: Set by user.
1107 1108 1109 1110
     * @param height the height of the slice
     * @param y the y position of the slice
     * @param type 1->top field, 2->bottom field, 3->frame
     * @param offset offset into the AVFrame.data from which the slice should be read
1111
     */
1112
    void (*draw_horiz_band)(struct AVCodecContext *s,
1113
                            const AVFrame *src, int offset[4],
1114
                            int y, int type, int height);
1115

Fabrice Bellard's avatar
Fabrice Bellard committed
1116
    /* audio only */
Diego Biurrun's avatar
Diego Biurrun committed
1117
    int sample_rate; ///< samples per second
1118
    int channels;    ///< number of audio channels
1119 1120

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1121 1122 1123
     * audio sample format
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
1124
     */
1125
    enum SampleFormat sample_fmt;  ///< sample format
Fabrice Bellard's avatar
Fabrice Bellard committed
1126

Diego Biurrun's avatar
Diego Biurrun committed
1127
    /* The following data should not be initialized. */
1128
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1129
     * Samples per packet, initialized when calling 'init'.
1130 1131
     */
    int frame_size;
1132
    int frame_number;   ///< audio or video frame number
1133
#if LIBAVCODEC_VERSION_MAJOR < 53
Diego Biurrun's avatar
Diego Biurrun committed
1134
    int real_pict_num;  ///< Returns the real picture number of previous encoded frame.
1135
#endif
1136

1137
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1138
     * Number of frames the decoded output will be delayed relative to
1139
     * the encoded input.
Diego Biurrun's avatar
Diego Biurrun committed
1140
     * - encoding: Set by libavcodec.
1141
     * - decoding: unused
1142 1143
     */
    int delay;
1144

1145 1146
    /* - encoding parameters */
    float qcompress;  ///< amount of qscale change between easy & hard scenes (0.0-1.0)
1147 1148
    float qblur;      ///< amount of qscale smoothing over time (0.0-1.0)

1149
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1150 1151
     * minimum quantizer
     * - encoding: Set by user.
1152
     * - decoding: unused
1153 1154 1155 1156
     */
    int qmin;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1157 1158
     * maximum quantizer
     * - encoding: Set by user.
1159
     * - decoding: unused
1160 1161 1162 1163
     */
    int qmax;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1164 1165
     * maximum quantizer difference between frames
     * - encoding: Set by user.
1166
     * - decoding: unused
1167 1168 1169 1170
     */
    int max_qdiff;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1171 1172 1173
     * maximum number of B-frames between non-B-frames
     * Note: The output will be delayed by max_b_frames+1 relative to the input.
     * - encoding: Set by user.
1174
     * - decoding: unused
1175 1176 1177 1178
     */
    int max_b_frames;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1179
     * qscale factor between IP and B-frames
1180 1181
     * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
     * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
Diego Biurrun's avatar
Diego Biurrun committed
1182
     * - encoding: Set by user.
1183
     * - decoding: unused
1184 1185
     */
    float b_quant_factor;
1186

1187 1188
    /** obsolete FIXME remove */
    int rc_strategy;
1189 1190
#define FF_RC_STRATEGY_XVID 1

1191
    int b_frame_strategy;
1192

1193
    /**
1194 1195 1196
     * hurry up amount
     * - encoding: unused
     * - decoding: Set by user. 1-> Skip B-frames, 2-> Skip IDCT/dequant too, 5-> Skip everything except header
1197
     * @deprecated Deprecated in favor of skip_idct and skip_frame.
1198 1199
     */
    int hurry_up;
1200

Fabrice Bellard's avatar
Fabrice Bellard committed
1201
    struct AVCodec *codec;
1202

Fabrice Bellard's avatar
Fabrice Bellard committed
1203 1204
    void *priv_data;

Diego Biurrun's avatar
Diego Biurrun committed
1205
    int rtp_payload_size;   /* The size of the RTP payload: the coder will  */
Diego Biurrun's avatar
Diego Biurrun committed
1206
                            /* do its best to deliver a chunk with size     */
1207
                            /* below rtp_payload_size, the chunk will start */
Diego Biurrun's avatar
Diego Biurrun committed
1208
                            /* with a start code on some codecs like H.263. */
1209
                            /* This doesn't take account of any particular  */
Diego Biurrun's avatar
Diego Biurrun committed
1210
                            /* headers inside the transmitted RTP payload.  */
1211

1212

Diego Biurrun's avatar
Diego Biurrun committed
1213 1214 1215 1216 1217 1218
    /* The RTP callback: This function is called    */
    /* every time the encoder has a packet to send. */
    /* It depends on the encoder if the data starts */
    /* with a Start Code (it should). H.263 does.   */
    /* mb_nb contains the number of macroblocks     */
    /* encoded in the RTP payload.                  */
1219
    void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
1220

1221 1222 1223 1224 1225 1226 1227 1228
    /* statistics, used for 2-pass encoding */
    int mv_bits;
    int header_bits;
    int i_tex_bits;
    int p_tex_bits;
    int i_count;
    int p_count;
    int skip_count;
1229
    int misc_bits;
1230

1231
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1232 1233
     * number of bits used for the previously encoded frame
     * - encoding: Set by libavcodec.
1234
     * - decoding: unused
1235
     */
1236
    int frame_bits;
1237

1238
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1239 1240 1241
     * Private data of the user, can be used to carry app specific stuff.
     * - encoding: Set by user.
     * - decoding: Set by user.
1242 1243 1244
     */
    void *opaque;

Fabrice Bellard's avatar
Fabrice Bellard committed
1245
    char codec_name[32];
1246 1247
    enum CodecType codec_type; /* see CODEC_TYPE_xxx */
    enum CodecID codec_id; /* see CODEC_ID_xxx */
1248

1249 1250
    /**
     * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Diego Biurrun's avatar
Diego Biurrun committed
1251 1252 1253 1254 1255 1256
     * This is used to work around some encoder bugs.
     * A demuxer should set this to what is stored in the field used to identify the codec.
     * If there are multiple such fields in a container then the demuxer should choose the one
     * which maximizes the information about the used codec.
     * If the codec tag field in a container is larger then 32 bits then the demuxer should
     * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
Michael Niedermayer's avatar
Michael Niedermayer committed
1257
     * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
Diego Biurrun's avatar
Diego Biurrun committed
1258 1259 1260
     * first.
     * - encoding: Set by user, if not then the default based on codec_id will be used.
     * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
1261 1262
     */
    unsigned int codec_tag;
1263

1264
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1265 1266 1267
     * Work around bugs in encoders which sometimes cannot be detected automatically.
     * - encoding: Set by user
     * - decoding: Set by user
1268 1269
     */
    int workaround_bugs;
1270
#define FF_BUG_AUTODETECT       1  ///< autodetection
1271 1272 1273 1274
#define FF_BUG_OLD_MSMPEG4      2
#define FF_BUG_XVID_ILACE       4
#define FF_BUG_UMP4             8
#define FF_BUG_NO_PADDING       16
Michael Niedermayer's avatar
Michael Niedermayer committed
1275
#define FF_BUG_AMV              32
Diego Biurrun's avatar
Diego Biurrun committed
1276
#define FF_BUG_AC_VLC           0  ///< Will be removed, libavcodec can now handle these non-compliant files by default.
1277
#define FF_BUG_QPEL_CHROMA      64
Michael Niedermayer's avatar
Michael Niedermayer committed
1278
#define FF_BUG_STD_QPEL         128
1279
#define FF_BUG_QPEL_CHROMA2     256
1280
#define FF_BUG_DIRECT_BLOCKSIZE 512
1281
#define FF_BUG_EDGE             1024
1282
#define FF_BUG_HPEL_CHROMA      2048
1283
#define FF_BUG_DC_CLIP          4096
Diego Biurrun's avatar
Diego Biurrun committed
1284 1285
#define FF_BUG_MS               8192 ///< Work around various bugs in Microsoft's broken decoders.
//#define FF_BUG_FAKE_SCALABILITY 16 //Autodetection should work 100%.
1286

1287
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1288 1289
     * luma single coefficient elimination threshold
     * - encoding: Set by user.
1290
     * - decoding: unused
1291
     */
1292
    int luma_elim_threshold;
1293

1294
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1295 1296
     * chroma single coeff elimination threshold
     * - encoding: Set by user.
1297
     * - decoding: unused
1298
     */
1299
    int chroma_elim_threshold;
1300

1301
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1302 1303
     * strictly follow the standard (MPEG4, ...).
     * - encoding: Set by user.
1304 1305 1306 1307 1308 1309 1310 1311
     * - decoding: Set by user.
     * Setting this to STRICT or higher means the encoder and decoder will
     * generally do stupid things. While setting it to inofficial or lower
     * will mean the encoder might use things that are not supported by all
     * spec compliant decoders. Decoders make no difference between normal,
     * inofficial and experimental, that is they always try to decode things
     * when they can unless they are explicitly asked to behave stupid
     * (=strictly conform to the specs)
1312 1313
     */
    int strict_std_compliance;
Diego Biurrun's avatar
Diego Biurrun committed
1314 1315
#define FF_COMPLIANCE_VERY_STRICT   2 ///< Strictly conform to a older more strict version of the spec or reference software.
#define FF_COMPLIANCE_STRICT        1 ///< Strictly conform to all the things in the spec no matter what consequences.
1316
#define FF_COMPLIANCE_NORMAL        0
Diego Biurrun's avatar
Diego Biurrun committed
1317 1318
#define FF_COMPLIANCE_INOFFICIAL   -1 ///< Allow inofficial extensions.
#define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
1319

1320
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1321 1322
     * qscale offset between IP and B-frames
     * - encoding: Set by user.
1323
     * - decoding: unused
1324 1325
     */
    float b_quant_offset;
1326

1327
    /**
1328
     * Error recognization; higher values will detect more errors but may
Diego Biurrun's avatar
Diego Biurrun committed
1329
     * misdetect some more or less valid parts as errors.
1330
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1331
     * - decoding: Set by user.
1332
     */
1333
    int error_recognition;
1334
#define FF_ER_CAREFUL         1
1335 1336 1337
#define FF_ER_COMPLIANT       2
#define FF_ER_AGGRESSIVE      3
#define FF_ER_VERY_AGGRESSIVE 4
1338

1339
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1340 1341
     * Called at the beginning of each frame to get a buffer for it.
     * If pic.reference is set then the frame will be read later by libavcodec.
1342
     * avcodec_align_dimensions() should be used to find the required width and
Diego Biurrun's avatar
Diego Biurrun committed
1343
     * height, as they normally need to be rounded up to the next multiple of 16.
1344 1345 1346
     * if CODEC_CAP_DR1 is not set then get_buffer() must call
     * avcodec_default_get_buffer() instead of providing buffers allocated by
     * some other means.
1347
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1348
     * - decoding: Set by libavcodec., user can override.
1349
     */
1350
    int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
1351

1352
    /**
Ramiro Polla's avatar
Ramiro Polla committed
1353
     * Called to release buffers which were allocated with get_buffer.
Diego Biurrun's avatar
Diego Biurrun committed
1354 1355
     * A released buffer can be reused in get_buffer().
     * pic.data[*] must be set to NULL.
1356
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1357
     * - decoding: Set by libavcodec., user can override.
1358
     */
1359
    void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
Michael Niedermayer's avatar
Michael Niedermayer committed
1360

1361
    /**
1362
     * Size of the frame reordering buffer in the decoder.
1363
     * For MPEG-2 it is 1 IPB or 0 low delay IP.
Diego Biurrun's avatar
Diego Biurrun committed
1364 1365
     * - encoding: Set by libavcodec.
     * - decoding: Set by libavcodec.
1366 1367
     */
    int has_b_frames;
1368 1369 1370

    /**
     * number of bytes per packet if constant and known or 0
Diego Biurrun's avatar
Diego Biurrun committed
1371
     * Used by some WAV based audio codecs.
1372 1373
     */
    int block_align;
1374

Diego Biurrun's avatar
Diego Biurrun committed
1375
    int parse_only; /* - decoding only: If true, only parsing is done
1376 1377
                       (function avcodec_parse_frame()). The frame
                       data is returned. Only MPEG codecs support this now. */
1378

1379
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1380 1381
     * 0-> h263 quant 1-> mpeg quant
     * - encoding: Set by user.
1382
     * - decoding: unused
1383 1384
     */
    int mpeg_quant;
1385

1386
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1387 1388
     * pass1 encoding statistics output buffer
     * - encoding: Set by libavcodec.
1389
     * - decoding: unused
1390
     */
1391
    char *stats_out;
1392

1393
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1394 1395 1396
     * pass2 encoding statistics input buffer
     * Concatenated stuff from stats_out of pass1 should be placed here.
     * - encoding: Allocated/set/freed by user.
1397
     * - decoding: unused
1398 1399
     */
    char *stats_in;
1400

1401
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1402 1403 1404
     * ratecontrol qmin qmax limiting method
     * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax.
     * - encoding: Set by user.
1405
     * - decoding: unused
1406
     */
1407
    float rc_qsquish;
1408

1409 1410
    float rc_qmod_amp;
    int rc_qmod_freq;
1411

1412
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1413 1414
     * ratecontrol override, see RcOverride
     * - encoding: Allocated/set/freed by user.
1415
     * - decoding: unused
1416
     */
1417 1418
    RcOverride *rc_override;
    int rc_override_count;
1419

1420
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1421 1422
     * rate control equation
     * - encoding: Set by user
1423
     * - decoding: unused
1424
     */
Luca Abeni's avatar
Luca Abeni committed
1425
    const char *rc_eq;
1426

1427
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1428 1429
     * maximum bitrate
     * - encoding: Set by user.
1430
     * - decoding: unused
1431
     */
1432
    int rc_max_rate;
1433

1434
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1435 1436
     * minimum bitrate
     * - encoding: Set by user.
1437
     * - decoding: unused
1438
     */
1439
    int rc_min_rate;
1440

1441
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1442 1443
     * decoder bitstream buffer size
     * - encoding: Set by user.
1444
     * - decoding: unused
1445
     */
1446 1447
    int rc_buffer_size;
    float rc_buffer_aggressivity;
1448 1449

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1450 1451 1452 1453
     * qscale factor between P and I-frames
     * If > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset).
     * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
     * - encoding: Set by user.
1454
     * - decoding: unused
1455 1456
     */
    float i_quant_factor;
1457

1458
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1459 1460
     * qscale offset between P and I-frames
     * - encoding: Set by user.
1461
     * - decoding: unused
1462 1463
     */
    float i_quant_offset;
1464

1465
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1466 1467
     * initial complexity for pass1 ratecontrol
     * - encoding: Set by user.
1468
     * - decoding: unused
1469
     */
1470
    float rc_initial_cplx;
1471

1472
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1473 1474
     * DCT algorithm, see FF_DCT_* below
     * - encoding: Set by user.
1475
     * - decoding: unused
1476
     */
1477
    int dct_algo;
1478
#define FF_DCT_AUTO    0
1479
#define FF_DCT_FASTINT 1
1480 1481 1482
#define FF_DCT_INT     2
#define FF_DCT_MMX     3
#define FF_DCT_MLIB    4
1483
#define FF_DCT_ALTIVEC 5
1484
#define FF_DCT_FAAN    6
1485

1486
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1487 1488
     * luminance masking (0-> disabled)
     * - encoding: Set by user.
1489
     * - decoding: unused
1490 1491
     */
    float lumi_masking;
1492

1493
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1494 1495
     * temporary complexity masking (0-> disabled)
     * - encoding: Set by user.
1496
     * - decoding: unused
1497 1498
     */
    float temporal_cplx_masking;
1499

1500
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1501 1502
     * spatial complexity masking (0-> disabled)
     * - encoding: Set by user.
1503
     * - decoding: unused
1504 1505
     */
    float spatial_cplx_masking;
1506

1507
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1508 1509
     * p block masking (0-> disabled)
     * - encoding: Set by user.
1510
     * - decoding: unused
1511 1512
     */
    float p_masking;
1513

1514
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1515 1516
     * darkness masking (0-> disabled)
     * - encoding: Set by user.
1517
     * - decoding: unused
1518 1519
     */
    float dark_masking;
1520

1521
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1522 1523 1524
     * IDCT algorithm, see FF_IDCT_* below.
     * - encoding: Set by user.
     * - decoding: Set by user.
1525 1526
     */
    int idct_algo;
Diego Biurrun's avatar
Diego Biurrun committed
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542
#define FF_IDCT_AUTO          0
#define FF_IDCT_INT           1
#define FF_IDCT_SIMPLE        2
#define FF_IDCT_SIMPLEMMX     3
#define FF_IDCT_LIBMPEG2MMX   4
#define FF_IDCT_PS2           5
#define FF_IDCT_MLIB          6
#define FF_IDCT_ARM           7
#define FF_IDCT_ALTIVEC       8
#define FF_IDCT_SH4           9
#define FF_IDCT_SIMPLEARM     10
#define FF_IDCT_H264          11
#define FF_IDCT_VP3           12
#define FF_IDCT_IPP           13
#define FF_IDCT_XVIDMMX       14
#define FF_IDCT_CAVS          15
Måns Rullgård's avatar
Måns Rullgård committed
1543
#define FF_IDCT_SIMPLEARMV5TE 16
Diego Biurrun's avatar
Diego Biurrun committed
1544
#define FF_IDCT_SIMPLEARMV6   17
1545
#define FF_IDCT_SIMPLEVIS     18
1546
#define FF_IDCT_WMV2          19
1547
#define FF_IDCT_FAAN          20
1548
#define FF_IDCT_EA            21
1549
#define FF_IDCT_SIMPLENEON    22
1550
#define FF_IDCT_SIMPLEALPHA   23
1551

1552
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1553 1554 1555
     * slice count
     * - encoding: Set by libavcodec.
     * - decoding: Set by user (or 0).
1556 1557 1558
     */
    int slice_count;
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1559 1560 1561
     * slice offsets in the frame in bytes
     * - encoding: Set/allocated by libavcodec.
     * - decoding: Set/allocated by user (or NULL).
1562 1563 1564
     */
    int *slice_offset;

1565
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1566
     * error concealment flags
1567
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1568
     * - decoding: Set by user.
1569 1570 1571 1572 1573
     */
    int error_concealment;
#define FF_EC_GUESS_MVS   1
#define FF_EC_DEBLOCK     2

Zdenek Kabelac's avatar
Zdenek Kabelac committed
1574
    /**
1575
     * dsp_mask could be add used to disable unwanted CPU features
Zdenek Kabelac's avatar
Zdenek Kabelac committed
1576
     * CPU features (i.e. MMX, SSE. ...)
1577
     *
Diego Biurrun's avatar
Diego Biurrun committed
1578 1579 1580
     * With the FORCE flag you may instead enable given CPU features.
     * (Dangerous: Usable in case of misdetection, improper usage however will
     * result into program crash.)
1581 1582
     */
    unsigned dsp_mask;
Diego Biurrun's avatar
Diego Biurrun committed
1583
#define FF_MM_FORCE    0x80000000 /* Force usage of selected flags (OR) */
1584
    /* lower 16 bits - CPU features */
1585 1586
#define FF_MM_MMX      0x0001 ///< standard MMX
#define FF_MM_3DNOW    0x0004 ///< AMD 3DNOW
1587
#if LIBAVCODEC_VERSION_MAJOR < 53
1588
#define FF_MM_MMXEXT   0x0002 ///< SSE integer functions or AMD MMX ext
1589 1590
#endif
#define FF_MM_MMX2     0x0002 ///< SSE integer functions or AMD MMX ext
1591 1592 1593 1594 1595
#define FF_MM_SSE      0x0008 ///< SSE functions
#define FF_MM_SSE2     0x0010 ///< PIV SSE2 functions
#define FF_MM_3DNOWEXT 0x0020 ///< AMD 3DNowExt
#define FF_MM_SSE3     0x0040 ///< Prescott SSE3 functions
#define FF_MM_SSSE3    0x0080 ///< Conroe SSSE3 functions
1596 1597
#define FF_MM_SSE4     0x0100 ///< Penryn SSE4.1 functions
#define FF_MM_SSE42    0x0200 ///< Nehalem SSE4.2 functions
1598
#define FF_MM_IWMMXT   0x0100 ///< XScale IWMMXT
1599
#define FF_MM_ALTIVEC  0x0001 ///< standard AltiVec
Michael Niedermayer's avatar
Michael Niedermayer committed
1600 1601

    /**
1602
     * bits per sample/pixel from the demuxer (needed for huffyuv).
Diego Biurrun's avatar
Diego Biurrun committed
1603 1604
     * - encoding: Set by libavcodec.
     * - decoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
1605
     */
1606
     int bits_per_coded_sample;
1607

Michael Niedermayer's avatar
Michael Niedermayer committed
1608
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1609 1610
     * prediction method (needed for huffyuv)
     * - encoding: Set by user.
1611
     * - decoding: unused
Michael Niedermayer's avatar
Michael Niedermayer committed
1612 1613 1614 1615 1616
     */
     int prediction_method;
#define FF_PRED_LEFT   0
#define FF_PRED_PLANE  1
#define FF_PRED_MEDIAN 2
1617

1618
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1619
     * sample aspect ratio (0 if unknown)
1620
     * That is the width of a pixel divided by the height of the pixel.
Diego Biurrun's avatar
Diego Biurrun committed
1621 1622 1623
     * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
1624
     */
Michael Niedermayer's avatar
Michael Niedermayer committed
1625
    AVRational sample_aspect_ratio;
Michael Niedermayer's avatar
Michael Niedermayer committed
1626 1627

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1628 1629 1630
     * the picture in the bitstream
     * - encoding: Set by libavcodec.
     * - decoding: Set by libavcodec.
Michael Niedermayer's avatar
Michael Niedermayer committed
1631
     */
1632
    AVFrame *coded_frame;
1633 1634

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1635 1636 1637
     * debug
     * - encoding: Set by user.
     * - decoding: Set by user.
1638 1639
     */
    int debug;
Diego Biurrun's avatar
Diego Biurrun committed
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653
#define FF_DEBUG_PICT_INFO   1
#define FF_DEBUG_RC          2
#define FF_DEBUG_BITSTREAM   4
#define FF_DEBUG_MB_TYPE     8
#define FF_DEBUG_QP          16
#define FF_DEBUG_MV          32
#define FF_DEBUG_DCT_COEFF   0x00000040
#define FF_DEBUG_SKIP        0x00000080
#define FF_DEBUG_STARTCODE   0x00000100
#define FF_DEBUG_PTS         0x00000200
#define FF_DEBUG_ER          0x00000400
#define FF_DEBUG_MMCO        0x00000800
#define FF_DEBUG_BUGS        0x00001000
#define FF_DEBUG_VIS_QP      0x00002000
1654
#define FF_DEBUG_VIS_MB_TYPE 0x00004000
1655
#define FF_DEBUG_BUFFERS     0x00008000
1656

1657
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1658 1659 1660
     * debug
     * - encoding: Set by user.
     * - decoding: Set by user.
1661 1662 1663 1664 1665 1666
     */
    int debug_mv;
#define FF_DEBUG_VIS_MV_P_FOR  0x00000001 //visualize forward predicted MVs of P frames
#define FF_DEBUG_VIS_MV_B_FOR  0x00000002 //visualize forward predicted MVs of B frames
#define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames

1667
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1668 1669
     * error
     * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR.
1670
     * - decoding: unused
1671 1672
     */
    uint64_t error[4];
1673

Michael Niedermayer's avatar
Michael Niedermayer committed
1674
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1675
     * minimum MB quantizer
1676
     * - encoding: unused
1677
     * - decoding: unused
Michael Niedermayer's avatar
Michael Niedermayer committed
1678 1679 1680 1681
     */
    int mb_qmin;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1682
     * maximum MB quantizer
1683
     * - encoding: unused
1684
     * - decoding: unused
Michael Niedermayer's avatar
Michael Niedermayer committed
1685 1686
     */
    int mb_qmax;
1687

Michael Niedermayer's avatar
Michael Niedermayer committed
1688
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1689 1690
     * motion estimation comparison function
     * - encoding: Set by user.
1691
     * - decoding: unused
Michael Niedermayer's avatar
Michael Niedermayer committed
1692 1693 1694
     */
    int me_cmp;
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1695 1696
     * subpixel motion estimation comparison function
     * - encoding: Set by user.
1697
     * - decoding: unused
Michael Niedermayer's avatar
Michael Niedermayer committed
1698 1699 1700
     */
    int me_sub_cmp;
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1701 1702
     * macroblock comparison function (not supported yet)
     * - encoding: Set by user.
1703
     * - decoding: unused
Michael Niedermayer's avatar
Michael Niedermayer committed
1704 1705
     */
    int mb_cmp;
1706
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1707 1708
     * interlaced DCT comparison function
     * - encoding: Set by user.
1709 1710 1711
     * - decoding: unused
     */
    int ildct_cmp;
Diego Biurrun's avatar
Diego Biurrun committed
1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724
#define FF_CMP_SAD    0
#define FF_CMP_SSE    1
#define FF_CMP_SATD   2
#define FF_CMP_DCT    3
#define FF_CMP_PSNR   4
#define FF_CMP_BIT    5
#define FF_CMP_RD     6
#define FF_CMP_ZERO   7
#define FF_CMP_VSAD   8
#define FF_CMP_VSSE   9
#define FF_CMP_NSSE   10
#define FF_CMP_W53    11
#define FF_CMP_W97    12
1725
#define FF_CMP_DCTMAX 13
1726
#define FF_CMP_DCT264 14
Michael Niedermayer's avatar
Michael Niedermayer committed
1727
#define FF_CMP_CHROMA 256
1728

Michael Niedermayer's avatar
Michael Niedermayer committed
1729
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1730 1731
     * ME diamond size & shape
     * - encoding: Set by user.
1732
     * - decoding: unused
Michael Niedermayer's avatar
Michael Niedermayer committed
1733 1734
     */
    int dia_size;
1735 1736

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1737 1738
     * amount of previous MV predictors (2a+1 x 2a+1 square)
     * - encoding: Set by user.
1739
     * - decoding: unused
1740 1741
     */
    int last_predictor_count;
1742

1743
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1744 1745
     * prepass for motion estimation
     * - encoding: Set by user.
1746
     * - decoding: unused
1747 1748
     */
    int pre_me;
1749

1750
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1751 1752
     * motion estimation prepass comparison function
     * - encoding: Set by user.
1753
     * - decoding: unused
1754 1755
     */
    int me_pre_cmp;
Michael Niedermayer's avatar
Michael Niedermayer committed
1756

1757
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1758 1759
     * ME prepass diamond size & shape
     * - encoding: Set by user.
1760
     * - decoding: unused
1761 1762 1763
     */
    int pre_dia_size;

Michael Niedermayer's avatar
Michael Niedermayer committed
1764
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1765 1766
     * subpel ME quality
     * - encoding: Set by user.
1767
     * - decoding: unused
Michael Niedermayer's avatar
Michael Niedermayer committed
1768 1769 1770
     */
    int me_subpel_quality;

Michael Niedermayer's avatar
Michael Niedermayer committed
1771
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1772
     * callback to negotiate the pixelFormat
Michael Niedermayer's avatar
Michael Niedermayer committed
1773
     * @param fmt is the list of formats which are supported by the codec,
Diego Biurrun's avatar
Diego Biurrun committed
1774 1775 1776
     * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
     * The first is always the native one.
     * @return the chosen format
1777
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1778
     * - decoding: Set by user, if not set the native format will be chosen.
Michael Niedermayer's avatar
Michael Niedermayer committed
1779
     */
Ivan Kalvachev's avatar
Ivan Kalvachev committed
1780
    enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt);
1781 1782

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1783 1784 1785
     * DTG active format information (additional aspect ratio
     * information only used in DVB MPEG-2 transport streams)
     * 0 if not set.
1786
     *
Diego Biurrun's avatar
Diego Biurrun committed
1787 1788
     * - encoding: unused
     * - decoding: Set by decoder.
1789 1790 1791 1792 1793 1794 1795 1796 1797 1798
     */
    int dtg_active_format;
#define FF_DTG_AFD_SAME         8
#define FF_DTG_AFD_4_3          9
#define FF_DTG_AFD_16_9         10
#define FF_DTG_AFD_14_9         11
#define FF_DTG_AFD_4_3_SP_14_9  13
#define FF_DTG_AFD_16_9_SP_14_9 14
#define FF_DTG_AFD_SP_4_3       15

1799
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1800 1801
     * maximum motion estimation search range in subpel units
     * If 0 then no limit.
1802
     *
Diego Biurrun's avatar
Diego Biurrun committed
1803 1804
     * - encoding: Set by user.
     * - decoding: unused
1805
     */
Zdenek Kabelac's avatar
Zdenek Kabelac committed
1806
    int me_range;
1807

1808
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1809 1810
     * intra quantizer bias
     * - encoding: Set by user.
1811 1812 1813 1814
     * - decoding: unused
     */
    int intra_quant_bias;
#define FF_DEFAULT_QUANT_BIAS 999999
1815

1816
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1817 1818
     * inter quantizer bias
     * - encoding: Set by user.
1819 1820 1821
     * - decoding: unused
     */
    int inter_quant_bias;
1822 1823

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1824 1825 1826 1827
     * color table ID
     * - encoding: unused
     * - decoding: Which clrtable should be used for 8bit RGB images.
     *             Tables have to be stored somewhere. FIXME
1828 1829
     */
    int color_table_id;
1830

1831
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1832 1833
     * internal_buffer count
     * Don't touch, used by libavcodec default_get_buffer().
1834 1835
     */
    int internal_buffer_count;
1836

1837
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1838 1839
     * internal_buffers
     * Don't touch, used by libavcodec default_get_buffer().
1840 1841
     */
    void *internal_buffer;
1842 1843 1844 1845 1846 1847 1848

#define FF_LAMBDA_SHIFT 7
#define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT)
#define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
#define FF_LAMBDA_MAX (256*128-1)

#define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove
Michael Niedermayer's avatar
Michael Niedermayer committed
1849
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1850 1851 1852
     * Global quality for codecs which cannot change it per frame.
     * This should be proportional to MPEG-1/2/4 qscale.
     * - encoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
1853 1854 1855
     * - decoding: unused
     */
    int global_quality;
1856

Michael Niedermayer's avatar
Michael Niedermayer committed
1857 1858
#define FF_CODER_TYPE_VLC       0
#define FF_CODER_TYPE_AC        1
1859 1860 1861
#define FF_CODER_TYPE_RAW       2
#define FF_CODER_TYPE_RLE       3
#define FF_CODER_TYPE_DEFLATE   4
Michael Niedermayer's avatar
Michael Niedermayer committed
1862 1863
    /**
     * coder type
Diego Biurrun's avatar
Diego Biurrun committed
1864
     * - encoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
1865 1866 1867 1868 1869 1870
     * - decoding: unused
     */
    int coder_type;

    /**
     * context model
Diego Biurrun's avatar
Diego Biurrun committed
1871
     * - encoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
1872 1873 1874
     * - decoding: unused
     */
    int context_model;
1875 1876 1877 1878
#if 0
    /**
     *
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1879
     * - decoding: Set by user.
1880 1881 1882
     */
    uint8_t * (*realloc)(struct AVCodecContext *s, uint8_t *buf, int buf_size);
#endif
1883

1884 1885 1886
    /**
     * slice flags
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1887
     * - decoding: Set by user.
1888 1889 1890 1891 1892 1893
     */
    int slice_flags;
#define SLICE_FLAG_CODED_ORDER    0x0001 ///< draw_horiz_band() is called in coded order instead of display
#define SLICE_FLAG_ALLOW_FIELD    0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
#define SLICE_FLAG_ALLOW_PLANE    0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)

Ivan Kalvachev's avatar
Ivan Kalvachev committed
1894 1895 1896 1897 1898 1899
    /**
     * XVideo Motion Acceleration
     * - encoding: forbidden
     * - decoding: set by decoder
     */
    int xvmc_acceleration;
1900

1901 1902
    /**
     * macroblock decision mode
Diego Biurrun's avatar
Diego Biurrun committed
1903
     * - encoding: Set by user.
1904 1905 1906 1907 1908
     * - decoding: unused
     */
    int mb_decision;
#define FF_MB_DECISION_SIMPLE 0        ///< uses mb_cmp
#define FF_MB_DECISION_BITS   1        ///< chooses the one which needs the fewest bits
1909
#define FF_MB_DECISION_RD     2        ///< rate distortion
1910 1911 1912

    /**
     * custom intra quantization matrix
Diego Biurrun's avatar
Diego Biurrun committed
1913 1914
     * - encoding: Set by user, can be NULL.
     * - decoding: Set by libavcodec.
1915 1916 1917 1918 1919
     */
    uint16_t *intra_matrix;

    /**
     * custom inter quantization matrix
Diego Biurrun's avatar
Diego Biurrun committed
1920 1921
     * - encoding: Set by user, can be NULL.
     * - decoding: Set by libavcodec.
1922 1923
     */
    uint16_t *inter_matrix;
1924

1925 1926
    /**
     * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Diego Biurrun's avatar
Diego Biurrun committed
1927
     * This is used to work around some encoder bugs.
1928
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1929
     * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
1930 1931
     */
    unsigned int stream_codec_tag;
1932 1933

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1934 1935 1936
     * scene change detection threshold
     * 0 is default, larger means fewer detected scene changes.
     * - encoding: Set by user.
1937 1938 1939
     * - decoding: unused
     */
    int scenechange_threshold;
1940 1941

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1942 1943
     * minimum Lagrange multipler
     * - encoding: Set by user.
1944 1945 1946 1947 1948
     * - decoding: unused
     */
    int lmin;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1949 1950
     * maximum Lagrange multipler
     * - encoding: Set by user.
1951 1952 1953
     * - decoding: unused
     */
    int lmax;
1954 1955

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1956
     * palette control structure
1957
     * - encoding: ??? (no palette-enabled encoder yet)
Diego Biurrun's avatar
Diego Biurrun committed
1958
     * - decoding: Set by user.
1959 1960
     */
    struct AVPaletteControl *palctrl;
1961 1962 1963

    /**
     * noise reduction strength
Diego Biurrun's avatar
Diego Biurrun committed
1964
     * - encoding: Set by user.
1965 1966 1967
     * - decoding: unused
     */
    int noise_reduction;
1968

1969
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1970 1971 1972
     * Called at the beginning of a frame to get cr buffer for it.
     * Buffer type (size, hints) must be the same. libavcodec won't check it.
     * libavcodec will pass previous buffer in pic, function should return
1973
     * same buffer or new buffer with old frame "painted" into it.
Diego Biurrun's avatar
Diego Biurrun committed
1974
     * If pic.data[0] == NULL must behave like get_buffer().
1975 1976 1977
     * if CODEC_CAP_DR1 is not set then reget_buffer() must call
     * avcodec_default_reget_buffer() instead of providing buffers allocated by
     * some other means.
1978
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1979
     * - decoding: Set by libavcodec., user can override
1980
     */
1981
    int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
1982 1983

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1984 1985
     * Number of bits which should be loaded into the rc buffer before decoding starts.
     * - encoding: Set by user.
1986 1987 1988 1989 1990 1991
     * - decoding: unused
     */
    int rc_initial_buffer_occupancy;

    /**
     *
Diego Biurrun's avatar
Diego Biurrun committed
1992
     * - encoding: Set by user.
1993 1994 1995 1996 1997
     * - decoding: unused
     */
    int inter_threshold;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1998 1999 2000
     * CODEC_FLAG2_*
     * - encoding: Set by user.
     * - decoding: Set by user.
2001 2002
     */
    int flags2;
2003 2004

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2005 2006 2007
     * Simulates errors in the bitstream to test error concealment.
     * - encoding: Set by user.
     * - decoding: unused
2008 2009
     */
    int error_rate;
2010

2011 2012 2013
    /**
     * MP3 antialias algorithm, see FF_AA_* below.
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2014
     * - decoding: Set by user.
2015 2016 2017 2018 2019 2020
     */
    int antialias_algo;
#define FF_AA_AUTO    0
#define FF_AA_FASTINT 1 //not implemented yet
#define FF_AA_INT     2
#define FF_AA_FLOAT   3
2021
    /**
Diego Biurrun's avatar
Diego Biurrun committed
2022 2023
     * quantizer noise shaping
     * - encoding: Set by user.
2024 2025 2026
     * - decoding: unused
     */
    int quantizer_noise_shaping;
2027 2028

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2029
     * thread count
2030
     * is used to decide how many independent tasks should be passed to execute()
Diego Biurrun's avatar
Diego Biurrun committed
2031 2032
     * - encoding: Set by user.
     * - decoding: Set by user.
2033 2034
     */
    int thread_count;
2035

2036
    /**
Diego Biurrun's avatar
Diego Biurrun committed
2037 2038 2039 2040
     * The codec may call this to execute several independent things.
     * It will return only after finishing all tasks.
     * The user may replace this with some multithreaded implementation,
     * the default implementation will execute the parts serially.
2041
     * @param count the number of things to execute
Diego Biurrun's avatar
Diego Biurrun committed
2042 2043
     * - encoding: Set by libavcodec, user can override.
     * - decoding: Set by libavcodec, user can override.
2044
     */
2045
    int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
2046

2047
    /**
Diego Biurrun's avatar
Diego Biurrun committed
2048 2049
     * thread opaque
     * Can be used by execute() to store some per AVCodecContext stuff.
2050 2051 2052 2053
     * - encoding: set by execute()
     * - decoding: set by execute()
     */
    void *thread_opaque;
2054 2055

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2056 2057
     * Motion estimation threshold below which no motion estimation is
     * performed, but instead the user specified motion vectors are used.
2058
     *
Diego Biurrun's avatar
Diego Biurrun committed
2059
     * - encoding: Set by user.
2060
     * - decoding: unused
2061
     */
2062
     int me_threshold;
2063 2064

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2065 2066
     * Macroblock threshold below which the user specified macroblock types will be used.
     * - encoding: Set by user.
2067 2068 2069
     * - decoding: unused
     */
     int mb_threshold;
2070 2071

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2072 2073
     * precision of the intra DC coefficient - 8
     * - encoding: Set by user.
2074 2075 2076
     * - decoding: unused
     */
     int intra_dc_precision;
Michael Niedermayer's avatar
Michael Niedermayer committed
2077 2078

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2079 2080
     * noise vs. sse weight for the nsse comparsion function
     * - encoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
2081 2082 2083
     * - decoding: unused
     */
     int nsse_weight;
2084 2085

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2086
     * Number of macroblock rows at the top which are skipped.
2087
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2088
     * - decoding: Set by user.
2089 2090 2091 2092
     */
     int skip_top;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2093
     * Number of macroblock rows at the bottom which are skipped.
2094
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2095
     * - decoding: Set by user.
2096 2097
     */
     int skip_bottom;
2098 2099 2100

    /**
     * profile
Diego Biurrun's avatar
Diego Biurrun committed
2101 2102
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
2103 2104 2105
     */
     int profile;
#define FF_PROFILE_UNKNOWN -99
2106
#define FF_PROFILE_AAC_MAIN 0
Diego Biurrun's avatar
Diego Biurrun committed
2107 2108 2109
#define FF_PROFILE_AAC_LOW  1
#define FF_PROFILE_AAC_SSR  2
#define FF_PROFILE_AAC_LTP  3
2110 2111 2112

    /**
     * level
Diego Biurrun's avatar
Diego Biurrun committed
2113 2114
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
2115 2116 2117
     */
     int level;
#define FF_LEVEL_UNKNOWN -99
2118 2119

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2120
     * low resolution decoding, 1-> 1/2 size, 2->1/4 size
2121
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2122
     * - decoding: Set by user.
2123 2124
     */
     int lowres;
2125 2126

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2127 2128
     * Bitstream width / height, may be different from width/height if lowres
     * or other things are used.
2129
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2130
     * - decoding: Set by user before init if known. Codec should override / dynamically change if needed.
2131 2132
     */
    int coded_width, coded_height;
Michael Niedermayer's avatar
Michael Niedermayer committed
2133 2134 2135

    /**
     * frame skip threshold
Diego Biurrun's avatar
Diego Biurrun committed
2136
     * - encoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
2137 2138 2139 2140 2141 2142
     * - decoding: unused
     */
    int frame_skip_threshold;

    /**
     * frame skip factor
Diego Biurrun's avatar
Diego Biurrun committed
2143
     * - encoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
2144 2145 2146
     * - decoding: unused
     */
    int frame_skip_factor;
2147 2148 2149

    /**
     * frame skip exponent
Diego Biurrun's avatar
Diego Biurrun committed
2150
     * - encoding: Set by user.
2151 2152 2153 2154 2155
     * - decoding: unused
     */
    int frame_skip_exp;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2156 2157
     * frame skip comparison function
     * - encoding: Set by user.
2158 2159 2160
     * - decoding: unused
     */
    int frame_skip_cmp;
2161 2162

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2163
     * Border processing masking, raises the quantizer for mbs on the borders
2164
     * of the picture.
Diego Biurrun's avatar
Diego Biurrun committed
2165
     * - encoding: Set by user.
2166 2167 2168
     * - decoding: unused
     */
    float border_masking;
2169 2170

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2171 2172
     * minimum MB lagrange multipler
     * - encoding: Set by user.
2173 2174 2175 2176 2177
     * - decoding: unused
     */
    int mb_lmin;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2178 2179
     * maximum MB lagrange multipler
     * - encoding: Set by user.
2180 2181 2182
     * - decoding: unused
     */
    int mb_lmax;
2183 2184

    /**
2185
     *
Diego Biurrun's avatar
Diego Biurrun committed
2186
     * - encoding: Set by user.
2187 2188 2189
     * - decoding: unused
     */
    int me_penalty_compensation;
Michael Niedermayer's avatar
Michael Niedermayer committed
2190 2191

    /**
2192
     *
Michael Niedermayer's avatar
Michael Niedermayer committed
2193
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2194
     * - decoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
2195 2196 2197 2198
     */
    enum AVDiscard skip_loop_filter;

    /**
2199
     *
Michael Niedermayer's avatar
Michael Niedermayer committed
2200
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2201
     * - decoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
2202 2203 2204 2205
     */
    enum AVDiscard skip_idct;

    /**
2206
     *
Michael Niedermayer's avatar
Michael Niedermayer committed
2207
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2208
     * - decoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
2209 2210
     */
    enum AVDiscard skip_frame;
2211 2212 2213

    /**
     *
Diego Biurrun's avatar
Diego Biurrun committed
2214
     * - encoding: Set by user.
2215 2216 2217
     * - decoding: unused
     */
    int bidir_refine;
2218 2219 2220

    /**
     *
Diego Biurrun's avatar
Diego Biurrun committed
2221
     * - encoding: Set by user.
2222 2223 2224
     * - decoding: unused
     */
    int brd_scale;
Robert Swain's avatar
Robert Swain committed
2225 2226 2227

    /**
     * constant rate factor - quality-based VBR - values ~correspond to qps
Diego Biurrun's avatar
Diego Biurrun committed
2228
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2229 2230
     * - decoding: unused
     */
2231
    float crf;
Robert Swain's avatar
Robert Swain committed
2232 2233 2234

    /**
     * constant quantization parameter rate control method
Diego Biurrun's avatar
Diego Biurrun committed
2235
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2236 2237 2238 2239 2240
     * - decoding: unused
     */
    int cqp;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2241 2242
     * minimum GOP size
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2243 2244 2245 2246 2247 2248
     * - decoding: unused
     */
    int keyint_min;

    /**
     * number of reference frames
Diego Biurrun's avatar
Diego Biurrun committed
2249
     * - encoding: Set by user.
2250
     * - decoding: Set by lavc.
Robert Swain's avatar
Robert Swain committed
2251 2252 2253 2254 2255
     */
    int refs;

    /**
     * chroma qp offset from luma
Diego Biurrun's avatar
Diego Biurrun committed
2256
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2257 2258 2259 2260 2261
     * - decoding: unused
     */
    int chromaoffset;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2262 2263
     * Influences how often B-frames are used.
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2264 2265 2266 2267 2268 2269
     * - decoding: unused
     */
    int bframebias;

    /**
     * trellis RD quantization
Diego Biurrun's avatar
Diego Biurrun committed
2270
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2271 2272 2273 2274 2275
     * - decoding: unused
     */
    int trellis;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2276 2277
     * Reduce fluctuations in qp (before curve compression).
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2278 2279 2280 2281 2282 2283 2284
     * - decoding: unused
     */
    float complexityblur;

    /**
     * in-loop deblocking filter alphac0 parameter
     * alpha is in the range -6...6
Diego Biurrun's avatar
Diego Biurrun committed
2285
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2286 2287 2288 2289 2290 2291 2292
     * - decoding: unused
     */
    int deblockalpha;

    /**
     * in-loop deblocking filter beta parameter
     * beta is in the range -6...6
Diego Biurrun's avatar
Diego Biurrun committed
2293
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2294 2295 2296 2297 2298 2299
     * - decoding: unused
     */
    int deblockbeta;

    /**
     * macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4
Diego Biurrun's avatar
Diego Biurrun committed
2300
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2301 2302 2303
     * - decoding: unused
     */
    int partitions;
2304 2305 2306 2307 2308
#define X264_PART_I4X4 0x001  /* Analyze i4x4 */
#define X264_PART_I8X8 0x002  /* Analyze i8x8 (requires 8x8 transform) */
#define X264_PART_P8X8 0x010  /* Analyze p16x8, p8x16 and p8x8 */
#define X264_PART_P4X4 0x020  /* Analyze p8x4, p4x8, p4x4 */
#define X264_PART_B8X8 0x100  /* Analyze b16x8, b8x16 and b8x8 */
Robert Swain's avatar
Robert Swain committed
2309 2310

    /**
2311
     * direct MV prediction mode - 0 (none), 1 (spatial), 2 (temporal), 3 (auto)
Diego Biurrun's avatar
Diego Biurrun committed
2312
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2313 2314 2315
     * - decoding: unused
     */
    int directpred;
2316

2317
    /**
2318
     * Audio cutoff bandwidth (0 means "automatic")
Diego Biurrun's avatar
Diego Biurrun committed
2319
     * - encoding: Set by user.
2320 2321 2322
     * - decoding: unused
     */
    int cutoff;
2323 2324

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2325 2326
     * Multiplied by qscale for each frame and added to scene_change_score.
     * - encoding: Set by user.
2327 2328 2329
     * - decoding: unused
     */
    int scenechange_factor;
2330 2331 2332

    /**
     *
Diego Biurrun's avatar
Diego Biurrun committed
2333 2334
     * Note: Value depends upon the compare function used for fullpel ME.
     * - encoding: Set by user.
2335 2336 2337
     * - decoding: unused
     */
    int mv0_threshold;
2338 2339

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2340 2341
     * Adjusts sensitivity of b_frame_strategy 1.
     * - encoding: Set by user.
2342 2343 2344
     * - decoding: unused
     */
    int b_sensitivity;
2345 2346

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2347
     * - encoding: Set by user.
2348 2349 2350 2351 2352 2353
     * - decoding: unused
     */
    int compression_level;
#define FF_COMPRESSION_DEFAULT -1

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2354 2355 2356
     * Sets whether to use LPC mode - used by FLAC encoder.
     * - encoding: Set by user.
     * - decoding: unused
2357 2358 2359 2360 2361
     */
    int use_lpc;

    /**
     * LPC coefficient precision - used by FLAC encoder
Diego Biurrun's avatar
Diego Biurrun committed
2362 2363
     * - encoding: Set by user.
     * - decoding: unused
2364 2365 2366 2367
     */
    int lpc_coeff_precision;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2368 2369
     * - encoding: Set by user.
     * - decoding: unused
2370 2371 2372 2373
     */
    int min_prediction_order;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2374 2375
     * - encoding: Set by user.
     * - decoding: unused
2376 2377 2378 2379 2380
     */
    int max_prediction_order;

    /**
     * search method for selecting prediction order
Diego Biurrun's avatar
Diego Biurrun committed
2381 2382
     * - encoding: Set by user.
     * - decoding: unused
2383 2384 2385 2386
     */
    int prediction_order_method;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2387 2388
     * - encoding: Set by user.
     * - decoding: unused
2389 2390 2391 2392
     */
    int min_partition_order;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2393 2394
     * - encoding: Set by user.
     * - decoding: unused
2395 2396
     */
    int max_partition_order;
2397 2398 2399

    /**
     * GOP timecode frame start number, in non drop frame format
Diego Biurrun's avatar
Diego Biurrun committed
2400 2401
     * - encoding: Set by user.
     * - decoding: unused
2402 2403
     */
    int64_t timecode_frame_start;
2404

2405
#if LIBAVCODEC_VERSION_MAJOR < 53
2406
    /**
2407 2408 2409
     * Decoder should decode to this many channels if it can (0 for default)
     * - encoding: unused
     * - decoding: Set by user.
2410
     * @deprecated Deprecated in favor of request_channel_layout.
2411 2412
     */
    int request_channels;
2413
#endif
2414 2415 2416 2417 2418 2419 2420 2421

    /**
     * Percentage of dynamic range compression to be applied by the decoder.
     * The default value is 1.0, corresponding to full compression.
     * - encoding: unused
     * - decoding: Set by user.
     */
    float drc_scale;
2422 2423 2424 2425 2426 2427 2428 2429

    /**
     * opaque 64bit number (generally a PTS) that will be reordered and
     * output in AVFrame.reordered_opaque
     * - encoding: unused
     * - decoding: Set by user.
     */
    int64_t reordered_opaque;
2430 2431 2432 2433 2434 2435 2436 2437

    /**
     * Bits per sample/pixel of internal libavcodec pixel/sample format.
     * This field is applicable only when sample_fmt is SAMPLE_FMT_S32.
     * - encoding: set by user.
     * - decoding: set by libavcodec.
     */
    int bits_per_raw_sample;
2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451

    /**
     * Audio channel layout.
     * - encoding: set by user.
     * - decoding: set by libavcodec.
     */
    int64_t channel_layout;

    /**
     * Request decoder to use this channel layout if it can (0 for default)
     * - encoding: unused
     * - decoding: Set by user.
     */
    int64_t request_channel_layout;
2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465

    /**
     * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
     * - encoding: Set by user.
     * - decoding: unused.
     */
    float rc_max_available_vbv_use;

    /**
     * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
     * - encoding: Set by user.
     * - decoding: unused.
     */
    float rc_min_vbv_overflow_use;
2466 2467 2468 2469 2470 2471 2472

    /**
     * Hardware accelerator in use
     * - encoding: unused.
     * - decoding: Set by libavcodec
     */
    struct AVHWAccel *hwaccel;
2473 2474 2475 2476 2477 2478 2479 2480 2481

    /**
     * For some codecs, the time base is closer to the field rate than the frame rate.
     * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
     * if no telecine is used ...
     *
     * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
     */
    int ticks_per_frame;
2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493

    /**
     * Hardware accelerator context.
     * For some hardware accelerators, a global context needs to be
     * provided by the user. In that case, this holds display-dependent
     * data FFmpeg cannot instantiate itself. Please refer to the
     * FFmpeg HW accelerator documentation to know how to fill this
     * is. e.g. for VA API, this is a struct vaapi_context.
     * - encoding: unused
     * - decoding: Set by user
     */
    void *hwaccel_context;
2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521

    /**
     * Chromaticity coordinates of the source primaries.
     * - encoding: Set by user
     * - decoding: Set by libavcodec
     */
    enum AVColorPrimaries color_primaries;

    /**
     * Color Transfer Characteristic.
     * - encoding: Set by user
     * - decoding: Set by libavcodec
     */
    enum AVColorTransferCharacteristic color_trc;

    /**
     * YUV colorspace type.
     * - encoding: Set by user
     * - decoding: Set by libavcodec
     */
    enum AVColorSpace colorspace;

    /**
     * MPEG vs JPEG YUV range.
     * - encoding: Set by user
     * - decoding: Set by libavcodec
     */
    enum AVColorRange color_range;
2522 2523 2524 2525 2526 2527 2528

    /**
     * This defines the location of chroma samples.
     * - encoding: Set by user
     * - decoding: Set by libavcodec
     */
     enum AVChromaLocation chroma_sample_location;
Fabrice Bellard's avatar
Fabrice Bellard committed
2529 2530
} AVCodecContext;

2531 2532 2533
/**
 * AVCodec.
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
2534
typedef struct AVCodec {
2535 2536 2537 2538 2539 2540
    /**
     * Name of the codec implementation.
     * The name is globally unique among encoders and among decoders (but an
     * encoder and a decoder can share the same name).
     * This is the primary way to find a codec from the user perspective.
     */
2541
    const char *name;
Zdenek Kabelac's avatar
Zdenek Kabelac committed
2542
    enum CodecType type;
Michael Niedermayer's avatar
Michael Niedermayer committed
2543
    enum CodecID id;
Fabrice Bellard's avatar
Fabrice Bellard committed
2544 2545
    int priv_data_size;
    int (*init)(AVCodecContext *);
2546
    int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
Fabrice Bellard's avatar
Fabrice Bellard committed
2547
    int (*close)(AVCodecContext *);
2548
    int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
2549 2550 2551 2552
    /**
     * Codec capabilities.
     * see CODEC_CAP_*
     */
2553
    int capabilities;
Fabrice Bellard's avatar
Fabrice Bellard committed
2554
    struct AVCodec *next;
2555 2556 2557 2558
    /**
     * Flush buffers.
     * Will be called when seeking
     */
Michael Niedermayer's avatar
Michael Niedermayer committed
2559
    void (*flush)(AVCodecContext *);
2560
    const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
Benoit Fouet's avatar
Benoit Fouet committed
2561
    const enum PixelFormat *pix_fmts;       ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
2562
    /**
2563 2564
     * Descriptive name for the codec, meant to be more human readable than name.
     * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
2565 2566
     */
    const char *long_name;
2567
    const int *supported_samplerates;       ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
2568
    const enum SampleFormat *sample_fmts;   ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
2569
    const int64_t *channel_layouts;         ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
Fabrice Bellard's avatar
Fabrice Bellard committed
2570 2571
} AVCodec;

2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617
/**
 * AVHWAccel.
 */
typedef struct AVHWAccel {
    /**
     * Name of the hardware accelerated codec.
     * The name is globally unique among encoders and among decoders (but an
     * encoder and a decoder can share the same name).
     */
    const char *name;

    /**
     * Type of codec implemented by the hardware accelerator.
     *
     * See CODEC_TYPE_xxx
     */
    enum CodecType type;

    /**
     * Codec implemented by the hardware accelerator.
     *
     * See CODEC_ID_xxx
     */
    enum CodecID id;

    /**
     * Supported pixel format.
     *
     * Only hardware accelerated formats are supported here.
     */
    enum PixelFormat pix_fmt;

    /**
     * Hardware accelerated codec capabilities.
     * see FF_HWACCEL_CODEC_CAP_*
     */
    int capabilities;

    struct AVHWAccel *next;

    /**
     * Called at the beginning of each frame or field picture.
     *
     * Meaningful frame information (codec specific) is guaranteed to
     * be parsed at this point. This function is mandatory.
     *
2618
     * Note that buf can be NULL along with buf_size set to 0.
2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650
     * Otherwise, this means the whole frame is available at this point.
     *
     * @param avctx the codec context
     * @param buf the frame data buffer base
     * @param buf_size the size of the frame in bytes
     * @return zero if successful, a negative value otherwise
     */
    int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);

    /**
     * Callback for each slice.
     *
     * Meaningful slice information (codec specific) is guaranteed to
     * be parsed at this point. This function is mandatory.
     *
     * @param avctx the codec context
     * @param buf the slice data buffer base
     * @param buf_size the size of the slice in bytes
     * @return zero if successful, a negative value otherwise
     */
    int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);

    /**
     * Called at the end of each frame or field picture.
     *
     * The whole picture is parsed at this point and can now be sent
     * to the hardware accelerator. This function is mandatory.
     *
     * @param avctx the codec context
     * @return zero if successful, a negative value otherwise
     */
    int (*end_frame)(AVCodecContext *avctx);
2651 2652 2653 2654

    /**
     * Size of HW accelerator private data.
     *
2655 2656 2657
     * Private data is allocated with av_mallocz() before
     * AVCodecContext.get_buffer() and deallocated after
     * AVCodecContext.release_buffer().
2658 2659
     */
    int priv_data_size;
2660 2661
} AVHWAccel;

2662
/**
2663 2664 2665
 * four components are given, that's all.
 * the last component is alpha
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
2666
typedef struct AVPicture {
2667
    uint8_t *data[4];
Michael Niedermayer's avatar
Michael Niedermayer committed
2668
    int linesize[4];       ///< number of bytes per line
Fabrice Bellard's avatar
Fabrice Bellard committed
2669 2670
} AVPicture;

2671
#if LIBAVCODEC_VERSION_MAJOR < 53
2672
/**
2673 2674 2675 2676
 * AVPaletteControl
 * This structure defines a method for communicating palette changes
 * between and demuxer and a decoder.
 *
2677
 * @deprecated Use AVPacket to send palette changes instead.
2678
 * This is totally broken.
2679
 */
2680
#define AVPALETTE_SIZE 1024
Michael Niedermayer's avatar
Michael Niedermayer committed
2681
#define AVPALETTE_COUNT 256
2682 2683
typedef struct AVPaletteControl {

Diego Biurrun's avatar
Diego Biurrun committed
2684 2685
    /* Demuxer sets this to 1 to indicate the palette has changed;
     * decoder resets to 0. */
2686 2687
    int palette_changed;

2688 2689
    /* 4-byte ARGB palette entries, stored in native byte order; note that
     * the individual palette components should be on a 8-bit scale; if
Diego Biurrun's avatar
Diego Biurrun committed
2690 2691
     * the palette data comes from an IBM VGA native format, the component
     * data is probably 6 bits in size and needs to be scaled. */
2692
    unsigned int palette[AVPALETTE_COUNT];
2693

2694
} AVPaletteControl attribute_deprecated;
2695
#endif
2696

2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714
enum AVSubtitleType {
    SUBTITLE_NONE,

    SUBTITLE_BITMAP,                ///< A bitmap, pict will be set

    /**
     * Plain text, the text field must be set by the decoder and is
     * authoritative. ass and pict fields may contain approximations.
     */
    SUBTITLE_TEXT,

    /**
     * Formatted text, the ass field must be set by the decoder and is
     * authoritative. pict and text fields may contain approximations.
     */
    SUBTITLE_ASS,
};

2715
typedef struct AVSubtitleRect {
2716 2717 2718 2719 2720
    int x;         ///< top left corner  of pict, undefined when pict is not set
    int y;         ///< top left corner  of pict, undefined when pict is not set
    int w;         ///< width            of pict, undefined when pict is not set
    int h;         ///< height           of pict, undefined when pict is not set
    int nb_colors; ///< number of colors in pict, undefined when pict is not set
2721 2722 2723 2724 2725 2726

    /**
     * data+linesize for the bitmap of this subtitle.
     * can be set for text/ass as well once they where rendered
     */
    AVPicture pict;
2727 2728 2729 2730 2731 2732 2733 2734 2735 2736
    enum AVSubtitleType type;

    char *text;                     ///< 0 terminated plain UTF-8 text

    /**
     * 0 terminated ASS/SSA compatible event line.
     * The pressentation of this is unaffected by the other values in this
     * struct.
     */
    char *ass;
2737 2738 2739 2740 2741 2742
} AVSubtitleRect;

typedef struct AVSubtitle {
    uint16_t format; /* 0 = graphics */
    uint32_t start_display_time; /* relative to packet pts, in ms */
    uint32_t end_display_time; /* relative to packet pts, in ms */
2743
    unsigned num_rects;
2744
    AVSubtitleRect **rects;
2745
    int64_t pts;    ///< Same as packet pts, in AV_TIME_BASE
2746 2747
} AVSubtitle;

2748 2749
/* packet functions */

2750 2751 2752 2753
/**
 * @deprecated use NULL instead
 */
attribute_deprecated void av_destruct_packet_nofree(AVPacket *pkt);
2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776

/**
 * Default packet destructor.
 */
void av_destruct_packet(AVPacket *pkt);

/**
 * Initialize optional fields of a packet with default values.
 *
 * @param pkt packet
 */
void av_init_packet(AVPacket *pkt);

/**
 * Allocate the payload of a packet and initialize its fields with
 * default values.
 *
 * @param pkt packet
 * @param size wanted payload size
 * @return 0 if OK, AVERROR_xxx otherwise
 */
int av_new_packet(AVPacket *pkt, int size);

2777 2778 2779 2780 2781 2782 2783 2784
/**
 * Reduce packet size, correctly zeroing padding
 *
 * @param pkt packet
 * @param size new size
 */
void av_shrink_packet(AVPacket *pkt, int size);

2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795
/**
 * @warning This is a hack - the packet memory allocation stuff is broken. The
 * packet is allocated if it was not really allocated.
 */
int av_dup_packet(AVPacket *pkt);

/**
 * Free a packet.
 *
 * @param pkt packet to free
 */
Ramiro Polla's avatar
Ramiro Polla committed
2796
void av_free_packet(AVPacket *pkt);
2797

Fabrice Bellard's avatar
Fabrice Bellard committed
2798 2799 2800
/* resample.c */

struct ReSampleContext;
2801
struct AVResampleContext;
Fabrice Bellard's avatar
Fabrice Bellard committed
2802 2803 2804

typedef struct ReSampleContext ReSampleContext;

2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834
#if LIBAVCODEC_VERSION_MAJOR < 53
/**
 * @deprecated Use av_audio_resample_init() instead.
 */
attribute_deprecated ReSampleContext *audio_resample_init(int output_channels, int input_channels,
                                                          int output_rate, int input_rate);
#endif
/**
 *  Initializes audio resampling context
 *
 * @param output_channels  number of output channels
 * @param input_channels   number of input channels
 * @param output_rate      output sample rate
 * @param input_rate       input sample rate
 * @param sample_fmt_out   requested output sample format
 * @param sample_fmt_in    input sample format
 * @param filter_length    length of each FIR filter in the filterbank relative to the cutoff freq
 * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
 * @param linear           If 1 then the used FIR filter will be linearly interpolated
                           between the 2 closest, if 0 the closest will be used
 * @param cutoff           cutoff frequency, 1.0 corresponds to half the output sampling rate
 * @return allocated ReSampleContext, NULL if error occured
 */
ReSampleContext *av_audio_resample_init(int output_channels, int input_channels,
                                        int output_rate, int input_rate,
                                        enum SampleFormat sample_fmt_out,
                                        enum SampleFormat sample_fmt_in,
                                        int filter_length, int log2_phase_count,
                                        int linear, double cutoff);

Fabrice Bellard's avatar
Fabrice Bellard committed
2835 2836 2837
int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
void audio_resample_close(ReSampleContext *s);

2838 2839 2840 2841

/**
 * Initializes an audio resampler.
 * Note, if either rate is not an integer then simply scale both rates up so they are.
2842 2843 2844 2845 2846
 * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq
 * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
 * @param linear If 1 then the used FIR filter will be linearly interpolated
                 between the 2 closest, if 0 the closest will be used
 * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
2847
 */
2848
struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff);
2849 2850 2851 2852 2853 2854 2855 2856 2857 2858

/**
 * resamples.
 * @param src an array of unconsumed samples
 * @param consumed the number of samples of src which have been consumed are returned here
 * @param src_size the number of unconsumed samples available
 * @param dst_size the amount of space in samples available in dst
 * @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.
 * @return the number of samples written in dst or -1 if an error occurred
 */
2859
int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873


/**
 * Compensates samplerate/timestamp drift. The compensation is done by changing
 * the resampler parameters, so no audible clicks or similar distortions occur
 * @param compensation_distance distance in output samples over which the compensation should be performed
 * @param sample_delta number of output samples which should be output less
 *
 * example: av_resample_compensate(c, 10, 500)
 * here instead of 510 samples only 500 samples would be output
 *
 * note, due to rounding the actual compensation might be slightly different,
 * especially if the compensation_distance is large and the in_rate used during init is small
 */
Michael Niedermayer's avatar
Michael Niedermayer committed
2874
void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
2875
void av_resample_close(struct AVResampleContext *c);
2876

Drew Hess's avatar
Drew Hess committed
2877 2878 2879
/**
 * Allocate memory for a picture.  Call avpicture_free to free it.
 *
Diego Biurrun's avatar
Diego Biurrun committed
2880 2881 2882 2883 2884
 * @param picture the picture to be filled in
 * @param pix_fmt the format of the picture
 * @param width the width of the picture
 * @param height the height of the picture
 * @return zero if successful, a negative value if not
Drew Hess's avatar
Drew Hess committed
2885
 */
2886
int avpicture_alloc(AVPicture *picture, enum PixelFormat pix_fmt, int width, int height);
Drew Hess's avatar
Drew Hess committed
2887

2888 2889 2890
/**
 * Free a picture previously allocated by avpicture_alloc().
 *
Diego Biurrun's avatar
Diego Biurrun committed
2891
 * @param picture the AVPicture to be freed
2892
 */
Drew Hess's avatar
Drew Hess committed
2893 2894
void avpicture_free(AVPicture *picture);

2895
/**
Diego Biurrun's avatar
Diego Biurrun committed
2896
 * Fill in the AVPicture fields.
2897 2898 2899 2900 2901 2902
 * The fields of the given AVPicture are filled in by using the 'ptr' address
 * which points to the image data buffer. Depending on the specified picture
 * format, one or multiple image data pointers and line sizes will be set.
 * If a planar format is specified, several pointers will be set pointing to
 * the different picture planes and the line sizes of the different planes
 * will be stored in the lines_sizes array.
2903
 * Call with ptr == NULL to get the required size for the ptr buffer.
2904
 *
Diego Biurrun's avatar
Diego Biurrun committed
2905
 * @param picture AVPicture whose fields are to be filled in
2906
 * @param ptr Buffer which will contain or contains the actual image data
Diego Biurrun's avatar
Diego Biurrun committed
2907 2908 2909 2910
 * @param pix_fmt The format in which the picture data is stored.
 * @param width the width of the image in pixels
 * @param height the height of the image in pixels
 * @return size of the image data in bytes
2911
 */
2912
int avpicture_fill(AVPicture *picture, uint8_t *ptr,
2913
                   enum PixelFormat pix_fmt, int width, int height);
2914
int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, int height,
2915
                     unsigned char *dest, int dest_size);
2916 2917 2918 2919

/**
 * Calculate the size in bytes that a picture of the given width and height
 * would occupy if stored in the given picture format.
2920 2921 2922
 * Note that this returns the size of a compact representation as generated
 * by avpicture_layout, which can be smaller than the size required for e.g.
 * avpicture_fill.
2923
 *
Diego Biurrun's avatar
Diego Biurrun committed
2924 2925 2926
 * @param pix_fmt the given picture format
 * @param width the width of the image
 * @param height the height of the image
2927
 * @return Image data size in bytes or -1 on error (e.g. too large dimensions).
2928
 */
2929 2930 2931
int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height);
void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift);
const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt);
2932
void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
2933 2934

/**
2935
 * Returns the pixel format corresponding to the name name.
2936
 *
2937
 * If there is no pixel format with name name, then looks for a
2938
 * pixel format with the name corresponding to the native endian
2939
 * format of name.
2940 2941 2942
 * For example in a little-endian system, first looks for "gray16",
 * then for "gray16le".
 *
2943
 * Finally if no pixel format has been found, returns PIX_FMT_NONE.
2944
 */
2945
enum PixelFormat avcodec_get_pix_fmt(const char* name);
2946
unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat p);
2947

2948 2949 2950 2951 2952 2953
#define FF_LOSS_RESOLUTION  0x0001 /**< loss due to resolution change */
#define FF_LOSS_DEPTH       0x0002 /**< loss due to color depth change */
#define FF_LOSS_COLORSPACE  0x0004 /**< loss due to color space conversion */
#define FF_LOSS_ALPHA       0x0008 /**< loss of alpha bits */
#define FF_LOSS_COLORQUANT  0x0010 /**< loss due to color quantization */
#define FF_LOSS_CHROMA      0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */
2954

2955
/**
2956 2957 2958 2959 2960 2961 2962 2963
 * Computes what kind of losses will occur when converting from one specific
 * pixel format to another.
 * When converting from one pixel format to another, information loss may occur.
 * For example, when converting from RGB24 to GRAY, the color information will
 * be lost. Similarly, other losses occur when converting from some formats to
 * other formats. These losses can involve loss of chroma, but also loss of
 * resolution, loss of color depth, loss due to the color space conversion, loss
 * of the alpha bits or loss due to color quantization.
Diego Biurrun's avatar
Diego Biurrun committed
2964 2965
 * avcodec_get_fix_fmt_loss() informs you about the various types of losses
 * which will occur when converting from one pixel format to another.
2966
 *
Diego Biurrun's avatar
Diego Biurrun committed
2967 2968
 * @param[in] dst_pix_fmt destination pixel format
 * @param[in] src_pix_fmt source pixel format
2969 2970
 * @param[in] has_alpha Whether the source pixel format alpha channel is used.
 * @return Combination of flags informing you what kind of losses will occur.
2971
 */
2972
int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_pix_fmt,
2973
                             int has_alpha);
2974 2975

/**
2976 2977 2978 2979 2980
 * Finds the best pixel format to convert to given a certain source pixel
 * format.  When converting from one pixel format to another, information loss
 * may occur.  For example, when converting from RGB24 to GRAY, the color
 * information will be lost. Similarly, other losses occur when converting from
 * some formats to other formats. avcodec_find_best_pix_fmt() searches which of
Diego Biurrun's avatar
Diego Biurrun committed
2981 2982
 * the given pixel formats should be used to suffer the least amount of loss.
 * The pixel formats from which it chooses one, are determined by the
2983
 * pix_fmt_mask parameter.
2984 2985 2986 2987 2988 2989 2990
 *
 * @code
 * src_pix_fmt = PIX_FMT_YUV420P;
 * pix_fmt_mask = (1 << PIX_FMT_YUV422P) || (1 << PIX_FMT_RGB24);
 * dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss);
 * @endcode
 *
Diego Biurrun's avatar
Diego Biurrun committed
2991 2992
 * @param[in] pix_fmt_mask bitmask determining which pixel format to choose from
 * @param[in] src_pix_fmt source pixel format
2993 2994 2995
 * @param[in] has_alpha Whether the source pixel format alpha channel is used.
 * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
 * @return The best pixel format to convert to or -1 if none was found.
2996
 */
2997
enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt,
2998 2999
                              int has_alpha, int *loss_ptr);

3000 3001 3002 3003 3004

/**
 * Print in buf the string corresponding to the pixel format with
 * number pix_fmt, or an header if pix_fmt is negative.
 *
3005 3006 3007
 * @param[in] buf the buffer where to write the string
 * @param[in] buf_size the size of buf
 * @param[in] pix_fmt the number of the pixel format to print the corresponding info string, or
3008 3009 3010
 * a negative value to print the corresponding header.
 * Meaningful values for obtaining a pixel format info vary from 0 to PIX_FMT_NB -1.
 */
3011
void avcodec_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt);
3012

3013 3014
#define FF_ALPHA_TRANSP       0x0001 /* image has some totally transparent pixels */
#define FF_ALPHA_SEMI_TRANSP  0x0002 /* image has some transparent pixels */
3015 3016 3017 3018 3019

/**
 * Tell if an image really has transparent alpha values.
 * @return ored mask of FF_ALPHA_xxx constants
 */
3020
int img_get_alpha_info(const AVPicture *src,
3021
                       enum PixelFormat pix_fmt, int width, int height);
3022

3023
/* deinterlace a picture */
3024
/* deinterlace - if not supported return -1 */
3025
int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
3026
                          enum PixelFormat pix_fmt, int width, int height);
Fabrice Bellard's avatar
Fabrice Bellard committed
3027 3028 3029

/* external high level API */

3030 3031
/**
 * If c is NULL, returns the first registered codec,
3032
 * if c is non-NULL, returns the next registered codec after c,
3033 3034
 * or NULL if c is the last one.
 */
3035
AVCodec *av_codec_next(AVCodec *c);
Fabrice Bellard's avatar
Fabrice Bellard committed
3036

3037 3038 3039
/**
 * Returns the LIBAVCODEC_VERSION_INT constant.
 */
3040
unsigned avcodec_version(void);
3041

3042 3043 3044
/**
 * Initializes libavcodec.
 *
3045
 * @warning This function must be called before any other libavcodec
3046 3047
 * function.
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
3048 3049
void avcodec_init(void);

3050
#if LIBAVCODEC_VERSION_MAJOR < 53
3051 3052 3053 3054
/**
 * @deprecated Deprecated in favor of avcodec_register().
 */
attribute_deprecated void register_avcodec(AVCodec *codec);
3055
#endif
3056

3057
/**
3058
 * Register the codec codec and initialize libavcodec.
3059 3060 3061
 *
 * @see avcodec_init()
 */
3062
void avcodec_register(AVCodec *codec);
3063 3064

/**
3065
 * Finds a registered encoder with a matching codec ID.
3066
 *
Diego Biurrun's avatar
Diego Biurrun committed
3067
 * @param id CodecID of the requested encoder
3068 3069
 * @return An encoder if one was found, NULL otherwise.
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
3070
AVCodec *avcodec_find_encoder(enum CodecID id);
3071 3072

/**
3073
 * Finds a registered encoder with the specified name.
3074
 *
Diego Biurrun's avatar
Diego Biurrun committed
3075
 * @param name name of the requested encoder
3076 3077
 * @return An encoder if one was found, NULL otherwise.
 */
3078
AVCodec *avcodec_find_encoder_by_name(const char *name);
3079 3080

/**
3081
 * Finds a registered decoder with a matching codec ID.
3082
 *
Diego Biurrun's avatar
Diego Biurrun committed
3083
 * @param id CodecID of the requested decoder
3084 3085
 * @return A decoder if one was found, NULL otherwise.
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
3086
AVCodec *avcodec_find_decoder(enum CodecID id);
3087 3088

/**
3089
 * Finds a registered decoder with the specified name.
3090
 *
Diego Biurrun's avatar
Diego Biurrun committed
3091
 * @param name name of the requested decoder
3092 3093
 * @return A decoder if one was found, NULL otherwise.
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
3094 3095 3096
AVCodec *avcodec_find_decoder_by_name(const char *name);
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);

3097 3098 3099 3100 3101
/**
 * Sets the fields of the given AVCodecContext to default values.
 *
 * @param s The AVCodecContext of which the fields should be set to default values.
 */
Michael Niedermayer's avatar
Michael Niedermayer committed
3102
void avcodec_get_context_defaults(AVCodecContext *s);
3103

3104 3105 3106 3107
/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
 *  we WILL change its arguments and name a few times! */
void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType);

3108 3109 3110 3111 3112 3113 3114
/**
 * Allocates an AVCodecContext and sets its fields to default values.  The
 * resulting struct can be deallocated by simply calling av_free().
 *
 * @return An AVCodecContext filled with default values or NULL on failure.
 * @see avcodec_get_context_defaults
 */
Falk Hüffner's avatar
Falk Hüffner committed
3115
AVCodecContext *avcodec_alloc_context(void);
3116

3117 3118 3119 3120
/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
 *  we WILL change its arguments and name a few times! */
AVCodecContext *avcodec_alloc_context2(enum CodecType);

3121 3122 3123 3124 3125
/**
 * Sets the fields of the given AVFrame to default values.
 *
 * @param pic The AVFrame of which the fields should be set to default values.
 */
Falk Hüffner's avatar
Falk Hüffner committed
3126
void avcodec_get_frame_defaults(AVFrame *pic);
3127 3128 3129 3130 3131 3132 3133 3134

/**
 * Allocates an AVFrame and sets its fields to default values.  The resulting
 * struct can be deallocated by simply calling av_free().
 *
 * @return An AVFrame filled with default values or NULL on failure.
 * @see avcodec_get_frame_defaults
 */
3135
AVFrame *avcodec_alloc_frame(void);
Michael Niedermayer's avatar
Michael Niedermayer committed
3136

3137 3138
int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
3139 3140
int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
3141 3142 3143 3144 3145 3146 3147 3148 3149

/**
 * Checks if the given dimension of a picture is valid, meaning that all
 * bytes of the picture can be addressed with a signed int.
 *
 * @param[in] w Width of the picture.
 * @param[in] h Height of the picture.
 * @return Zero if valid, a negative value if invalid.
 */
3150
int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h);
3151
enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt);
Michael Niedermayer's avatar
Michael Niedermayer committed
3152

Michael Niedermayer's avatar
Michael Niedermayer committed
3153 3154
int avcodec_thread_init(AVCodecContext *s, int thread_count);
void avcodec_thread_free(AVCodecContext *s);
3155 3156
int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
3157 3158
//FIXME func typedef

Michael Niedermayer's avatar
Michael Niedermayer committed
3159
/**
3160 3161 3162 3163 3164 3165 3166
 * Initializes the AVCodecContext to use the given AVCodec. Prior to using this
 * function the context has to be allocated.
 *
 * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
 * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
 * retrieving a codec.
 *
Diego Biurrun's avatar
Diego Biurrun committed
3167
 * @warning This function is not thread safe!
3168 3169
 *
 * @code
3170
 * avcodec_register_all();
3171 3172 3173 3174 3175 3176 3177 3178 3179 3180
 * codec = avcodec_find_decoder(CODEC_ID_H264);
 * if (!codec)
 *     exit(1);
 *
 * context = avcodec_alloc_context();
 *
 * if (avcodec_open(context, codec) < 0)
 *     exit(1);
 * @endcode
 *
Diego Biurrun's avatar
Diego Biurrun committed
3181
 * @param avctx The context which will be set up to use the given codec.
3182
 * @param codec The codec to use within the context.
Diego Biurrun's avatar
Diego Biurrun committed
3183
 * @return zero on success, a negative value on error
3184
 * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder
Michael Niedermayer's avatar
Michael Niedermayer committed
3185
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
3186
int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
Michael Niedermayer's avatar
Michael Niedermayer committed
3187

3188
#if LIBAVCODEC_VERSION_MAJOR < 53
3189
/**
3190
 * Decodes an audio frame from buf into samples.
3191 3192
 * Wrapper function which calls avcodec_decode_audio3.
 *
3193
 * @deprecated Use avcodec_decode_audio3 instead.
3194 3195 3196 3197 3198 3199 3200
 * @param avctx the codec context
 * @param[out] samples the output buffer
 * @param[in,out] frame_size_ptr the output buffer size in bytes
 * @param[in] buf the input buffer
 * @param[in] buf_size the input buffer size in bytes
 * @return On error a negative value is returned, otherwise the number of bytes
 * used or zero if no frame could be decompressed.
3201 3202 3203 3204 3205 3206 3207
 */
attribute_deprecated int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
                         int *frame_size_ptr,
                         const uint8_t *buf, int buf_size);
#endif

/**
3208 3209 3210 3211
 * Decodes the audio frame of size avpkt->size from avpkt->data into samples.
 * Some decoders may support multiple frames in a single AVPacket, such
 * decoders would then just decode the first frame.
 * If no frame
3212 3213
 * could be decompressed, frame_size_ptr is zero. Otherwise, it is the
 * decompressed frame size in bytes.
3214
 *
3215
 * @warning You must set frame_size_ptr to the allocated size of the
3216
 * output buffer before calling avcodec_decode_audio3().
3217
 *
3218
 * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
3219 3220 3221
 * the actual read bytes because some optimized bitstream readers read 32 or 64
 * bits at once and could read over the end.
 *
3222
 * @warning The end of the input buffer avpkt->data should be set to 0 to ensure that
3223
 * no overreading happens for damaged MPEG streams.
3224
 *
3225
 * @note You might have to align the input buffer avpkt->data and output buffer
Diego Biurrun's avatar
Diego Biurrun committed
3226
 * samples. The alignment requirements depend on the CPU: On some CPUs it isn't
3227
 * necessary at all, on others it won't work at all if not aligned and on others
3228 3229 3230 3231 3232
 * it will work but it will have an impact on performance.
 *
 * In practice, avpkt->data should have 4 byte alignment at minimum and
 * samples should be 16 byte aligned unless the CPU doesn't need it
 * (AltiVec and SSE do).
3233
 *
Diego Biurrun's avatar
Diego Biurrun committed
3234
 * @param avctx the codec context
3235
 * @param[out] samples the output buffer, sample type in avctx->sample_fmt
Diego Biurrun's avatar
Diego Biurrun committed
3236
 * @param[in,out] frame_size_ptr the output buffer size in bytes
3237
 * @param[in] avpkt The input AVPacket containing the input buffer.
3238 3239 3240
 *            You can create such packet with av_init_packet() and by then setting
 *            data and size, some decoders might in addition need other fields.
 *            All decoders are designed to use the least fields possible though.
3241 3242
 * @return On error a negative value is returned, otherwise the number of bytes
 * used or zero if no frame could be decompressed.
3243
 */
3244
int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
Fabrice Bellard's avatar
Fabrice Bellard committed
3245
                         int *frame_size_ptr,
3246
                         AVPacket *avpkt);
3247

3248
#if LIBAVCODEC_VERSION_MAJOR < 53
3249
/**
3250
 * Decodes a video frame from buf into picture.
3251 3252
 * Wrapper function which calls avcodec_decode_video2.
 *
3253
 * @deprecated Use avcodec_decode_video2 instead.
3254 3255 3256 3257 3258 3259 3260
 * @param avctx the codec context
 * @param[out] picture The AVFrame in which the decoded video frame will be stored.
 * @param[in] buf the input buffer
 * @param[in] buf_size the size of the input buffer in bytes
 * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
 * @return On error a negative value is returned, otherwise the number of bytes
 * used or zero if no frame could be decompressed.
3261 3262 3263 3264 3265 3266 3267
 */
attribute_deprecated int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
                         int *got_picture_ptr,
                         const uint8_t *buf, int buf_size);
#endif

/**
3268
 * Decodes the video frame of size avpkt->size from avpkt->data into picture.
3269 3270
 * Some decoders may support multiple frames in a single AVPacket, such
 * decoders would then just decode the first frame.
3271
 *
3272
 * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
3273 3274 3275
 * the actual read bytes because some optimized bitstream readers read 32 or 64
 * bits at once and could read over the end.
 *
3276
 * @warning The end of the input buffer buf should be set to 0 to ensure that
3277 3278
 * no overreading happens for damaged MPEG streams.
 *
3279 3280
 * @note You might have to align the input buffer avpkt->data.
 * The alignment requirements depend on the CPU: on some CPUs it isn't
3281
 * necessary at all, on others it won't work at all if not aligned and on others
3282 3283 3284
 * it will work but it will have an impact on performance.
 *
 * In practice, avpkt->data should have 4 byte alignment at minimum.
3285
 *
3286
 * @note Some codecs have a delay between input and output, these need to be
3287
 * feeded with avpkt->data=NULL, avpkt->size=0 at the end to return the remaining frames.
3288
 *
Diego Biurrun's avatar
Diego Biurrun committed
3289
 * @param avctx the codec context
3290
 * @param[out] picture The AVFrame in which the decoded video frame will be stored.
3291
 * @param[in] avpkt The input AVpacket containing the input buffer.
3292 3293 3294 3295
 *            You can create such packet with av_init_packet() and by then setting
 *            data and size, some decoders might in addition need other fields like
 *            flags&PKT_FLAG_KEY. All decoders are designed to use the least
 *            fields possible.
Diego Biurrun's avatar
Diego Biurrun committed
3296
 * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
3297 3298 3299
 * @return On error a negative value is returned, otherwise the number of bytes
 * used or zero if no frame could be decompressed.
 */
3300
int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
Fabrice Bellard's avatar
Fabrice Bellard committed
3301
                         int *got_picture_ptr,
3302
                         AVPacket *avpkt);
3303

3304
#if LIBAVCODEC_VERSION_MAJOR < 53
Diego Biurrun's avatar
Diego Biurrun committed
3305 3306 3307
/* Decode a subtitle message. Return -1 if error, otherwise return the
 * number of bytes used. If no subtitle could be decompressed,
 * got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */
3308
attribute_deprecated int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
3309 3310
                            int *got_sub_ptr,
                            const uint8_t *buf, int buf_size);
3311 3312 3313 3314
#endif

/**
 * Decodes a subtitle message.
3315
 * Returns a negative value on error, otherwise returns the number of bytes used.
3316 3317
 * If no subtitle could be decompressed, got_sub_ptr is zero.
 * Otherwise, the subtitle is stored in *sub.
3318 3319 3320 3321 3322 3323 3324 3325 3326
 *
 * @param avctx the codec context
 * @param[out] sub The AVSubtitle in which the decoded subtitle will be stored.
 * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero.
 * @param[in] avpkt The input AVPacket containing the input buffer.
 */
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
                            int *got_sub_ptr,
                            AVPacket *avpkt);
3327
int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata,
3328
                        int *data_size_ptr,
3329
                        uint8_t *buf, int buf_size);
3330 3331

/**
3332
 * Encodes an audio frame from samples into buf.
3333
 *
3334
 * @note The output buffer should be at least FF_MIN_BUFFER_SIZE bytes large.
3335
 * However, for PCM audio the user will know how much space is needed
3336
 * because it depends on the value passed in buf_size as described
3337
 * below. In that case a lower value can be used.
3338
 *
Diego Biurrun's avatar
Diego Biurrun committed
3339 3340 3341 3342
 * @param avctx the codec context
 * @param[out] buf the output buffer
 * @param[in] buf_size the output buffer size
 * @param[in] samples the input buffer containing the samples
3343
 * The number of samples read from this buffer is frame_size*channels,
3344 3345 3346
 * both of which are defined in avctx.
 * For PCM audio the number of samples read from samples is equal to
 * buf_size * input_sample_size / output_sample_size.
Diego Biurrun's avatar
Diego Biurrun committed
3347
 * @return On error a negative value is returned, on success zero or the number
3348
 * of bytes used to encode the data read from the input buffer.
3349
 */
3350
int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
Fabrice Bellard's avatar
Fabrice Bellard committed
3351
                         const short *samples);
3352 3353

/**
3354
 * Encodes a video frame from pict into buf.
3355
 * The input picture should be
3356
 * stored using a specific format, namely avctx.pix_fmt.
3357
 *
Diego Biurrun's avatar
Diego Biurrun committed
3358 3359 3360 3361
 * @param avctx the codec context
 * @param[out] buf the output buffer for the bitstream of encoded frame
 * @param[in] buf_size the size of the output buffer in bytes
 * @param[in] pict the input picture to encode
3362
 * @return On error a negative value is returned, on success zero or the number
3363
 * of bytes used from the output buffer.
3364
 */
3365
int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
3366
                         const AVFrame *pict);
3367
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
3368
                            const AVSubtitle *sub);
Fabrice Bellard's avatar
Fabrice Bellard committed
3369 3370 3371

int avcodec_close(AVCodecContext *avctx);

3372 3373 3374 3375 3376 3377
/**
 * Register all the codecs, parsers and bitstream filters which were enabled at
 * configuration time. If you do not call this function you can select exactly
 * which formats you want to support, by using the individual registration
 * functions.
 *
3378
 * @see avcodec_register
3379 3380 3381
 * @see av_register_codec_parser
 * @see av_register_bitstream_filter
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
3382
void avcodec_register_all(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
3383

3384 3385 3386
/**
 * Flush buffers, should be called when seeking or when switching to a different stream.
 */
3387 3388
void avcodec_flush_buffers(AVCodecContext *avctx);

3389 3390
void avcodec_default_free_buffers(AVCodecContext *s);

Panagiotis Issaris's avatar
Panagiotis Issaris committed
3391
/* misc useful functions */
Michael Niedermayer's avatar
Michael Niedermayer committed
3392 3393

/**
3394
 * Returns a single letter to describe the given picture type pict_type.
3395
 *
Diego Biurrun's avatar
Diego Biurrun committed
3396
 * @param[in] pict_type the picture type
3397
 * @return A single character representing the picture type.
Michael Niedermayer's avatar
Michael Niedermayer committed
3398 3399 3400
 */
char av_get_pict_type_char(int pict_type);

3401
/**
3402 3403
 * Returns codec bits per sample.
 *
Diego Biurrun's avatar
Diego Biurrun committed
3404
 * @param[in] codec_id the codec
3405
 * @return Number of bits per sample or zero if unknown for the given codec.
3406 3407
 */
int av_get_bits_per_sample(enum CodecID codec_id);
3408

3409 3410 3411 3412 3413 3414 3415 3416
/**
 * Returns sample format bits per sample.
 *
 * @param[in] sample_fmt the sample format
 * @return Number of bits per sample or zero if unknown for the given sample format.
 */
int av_get_bits_per_sample_format(enum SampleFormat sample_fmt);

3417 3418 3419 3420 3421
/* frame parsing */
typedef struct AVCodecParserContext {
    void *priv_data;
    struct AVCodecParser *parser;
    int64_t frame_offset; /* offset of the current frame */
3422
    int64_t cur_offset; /* current offset
3423
                           (incremented by each av_parser_parse()) */
3424
    int64_t next_frame_offset; /* offset of the next frame */
3425
    /* video info */
Diego Biurrun's avatar
Diego Biurrun committed
3426
    int pict_type; /* XXX: Put it back in AVCodecContext. */
3427 3428 3429 3430 3431
    /**
     * This field is used for proper frame duration computation in lavf.
     * It signals, how much longer the frame duration of the current frame
     * is compared to normal frame duration.
     *
3432
     * frame_duration = (1 + repeat_pict) * time_base
3433 3434 3435
     *
     * It is used by codecs like H.264 to display telecined material.
     */
Diego Biurrun's avatar
Diego Biurrun committed
3436
    int repeat_pict; /* XXX: Put it back in AVCodecContext. */
3437 3438 3439 3440 3441 3442
    int64_t pts;     /* pts of the current frame */
    int64_t dts;     /* dts of the current frame */

    /* private data */
    int64_t last_pts;
    int64_t last_dts;
3443
    int fetch_timestamp;
3444 3445 3446 3447 3448 3449

#define AV_PARSER_PTS_NB 4
    int cur_frame_start_index;
    int64_t cur_frame_offset[AV_PARSER_PTS_NB];
    int64_t cur_frame_pts[AV_PARSER_PTS_NB];
    int64_t cur_frame_dts[AV_PARSER_PTS_NB];
3450

3451 3452
    int flags;
#define PARSER_FLAG_COMPLETE_FRAMES           0x0001
3453 3454

    int64_t offset;      ///< byte offset from starting packet start
3455
    int64_t cur_frame_end[AV_PARSER_PTS_NB];
3456 3457 3458 3459 3460 3461 3462 3463

    /*!
     * Set by parser to 1 for key frames and 0 for non-key frames.
     * It is initialized to -1, so if the parser doesn't set this flag,
     * old-style fallback using FF_I_TYPE picture type as key frames
     * will be used.
     */
    int key_frame;
3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480

    /**
     * Time difference in stream time base units from the pts of this
     * packet to the point at which the output from the decoder has converged
     * independent from the availability of previous frames. That is, the
     * frames are virtually identical no matter if decoding started from
     * the very first frame or from this keyframe.
     * Is AV_NOPTS_VALUE if unknown.
     * This field is not the display duration of the current frame.
     *
     * The purpose of this field is to allow seeking in streams that have no
     * keyframes in the conventional sense. It corresponds to the
     * recovery point SEI in H.264 and match_time_delta in NUT. It is also
     * essential for some types of subtitle streams to ensure that all
     * subtitles are correctly displayed after seeking.
     */
    int64_t convergence_duration;
3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521

    // Timestamp generation support:
    /**
     * Synchronization point for start of timestamp generation.
     *
     * Set to >0 for sync point, 0 for no sync point and <0 for undefined
     * (default).
     *
     * For example, this corresponds to presence of H.264 buffering period
     * SEI message.
     */
    int dts_sync_point;

    /**
     * Offset of the current timestamp against last timestamp sync point in
     * units of AVCodecContext.time_base.
     *
     * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
     * contain a valid timestamp offset.
     *
     * Note that the timestamp of sync point has usually a nonzero
     * dts_ref_dts_delta, which refers to the previous sync point. Offset of
     * the next frame after timestamp sync point will be usually 1.
     *
     * For example, this corresponds to H.264 cpb_removal_delay.
     */
    int dts_ref_dts_delta;

    /**
     * Presentation delay of current frame in units of AVCodecContext.time_base.
     *
     * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
     * contain valid non-negative timestamp delta (presentation time of a frame
     * must not lie in the past).
     *
     * This delay represents the difference between decoding and presentation
     * time of the frame.
     *
     * For example, this corresponds to H.264 dpb_output_delay.
     */
    int pts_dts_delta;
3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538

    /**
     * Position of the packet in file.
     *
     * Analogous to cur_frame_pts/dts
     */
    int64_t cur_frame_pos[AV_PARSER_PTS_NB];

    /**
     * Byte position of currently parsed frame in stream.
     */
    int64_t pos;

    /**
     * Previous frame byte position.
     */
    int64_t last_pos;
3539 3540 3541
} AVCodecParserContext;

typedef struct AVCodecParser {
Michael Niedermayer's avatar
Michael Niedermayer committed
3542
    int codec_ids[5]; /* several codec IDs are permitted */
3543 3544
    int priv_data_size;
    int (*parser_init)(AVCodecParserContext *s);
3545
    int (*parser_parse)(AVCodecParserContext *s,
3546
                        AVCodecContext *avctx,
3547
                        const uint8_t **poutbuf, int *poutbuf_size,
3548 3549
                        const uint8_t *buf, int buf_size);
    void (*parser_close)(AVCodecParserContext *s);
3550
    int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
3551 3552 3553
    struct AVCodecParser *next;
} AVCodecParser;

3554
AVCodecParser *av_parser_next(AVCodecParser *c);
3555 3556 3557

void av_register_codec_parser(AVCodecParser *parser);
AVCodecParserContext *av_parser_init(int codec_id);
3558

3559
#if LIBAVCODEC_VERSION_MAJOR < 53
3560
attribute_deprecated
3561
int av_parser_parse(AVCodecParserContext *s,
3562
                    AVCodecContext *avctx,
3563
                    uint8_t **poutbuf, int *poutbuf_size,
3564 3565
                    const uint8_t *buf, int buf_size,
                    int64_t pts, int64_t dts);
3566
#endif
3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602

/**
 * Parse a packet.
 *
 * @param s             parser context.
 * @param avctx         codec context.
 * @param poutbuf       set to pointer to parsed buffer or NULL if not yet finished.
 * @param poutbuf_size  set to size of parsed buffer or zero if not yet finished.
 * @param buf           input buffer.
 * @param buf_size      input length, to signal EOF, this should be 0 (so that the last frame can be output).
 * @param pts           input presentation timestamp.
 * @param dts           input decoding timestamp.
 * @param pos           input byte position in stream.
 * @return the number of bytes of the input bitstream used.
 *
 * Example:
 * @code
 *   while(in_len){
 *       len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
 *                                        in_data, in_len,
 *                                        pts, dts, pos);
 *       in_data += len;
 *       in_len  -= len;
 *
 *       if(size)
 *          decode_frame(data, size);
 *   }
 * @endcode
 */
int av_parser_parse2(AVCodecParserContext *s,
                     AVCodecContext *avctx,
                     uint8_t **poutbuf, int *poutbuf_size,
                     const uint8_t *buf, int buf_size,
                     int64_t pts, int64_t dts,
                     int64_t pos);

3603 3604
int av_parser_change(AVCodecParserContext *s,
                     AVCodecContext *avctx,
3605
                     uint8_t **poutbuf, int *poutbuf_size,
3606
                     const uint8_t *buf, int buf_size, int keyframe);
3607 3608
void av_parser_close(AVCodecParserContext *s);

3609 3610

typedef struct AVBitStreamFilterContext {
3611
    void *priv_data;
3612 3613 3614 3615 3616 3617 3618 3619
    struct AVBitStreamFilter *filter;
    AVCodecParserContext *parser;
    struct AVBitStreamFilterContext *next;
} AVBitStreamFilterContext;


typedef struct AVBitStreamFilter {
    const char *name;
3620
    int priv_data_size;
3621 3622 3623 3624
    int (*filter)(AVBitStreamFilterContext *bsfc,
                  AVCodecContext *avctx, const char *args,
                  uint8_t **poutbuf, int *poutbuf_size,
                  const uint8_t *buf, int buf_size, int keyframe);
3625
    void (*close)(AVBitStreamFilterContext *bsfc);
3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636
    struct AVBitStreamFilter *next;
} AVBitStreamFilter;

void av_register_bitstream_filter(AVBitStreamFilter *bsf);
AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
                               AVCodecContext *avctx, const char *args,
                               uint8_t **poutbuf, int *poutbuf_size,
                               const uint8_t *buf, int buf_size, int keyframe);
void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);

3637
AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f);
3638

3639
/* memory */
3640 3641

/**
3642 3643 3644 3645
 * Reallocates the given block if it is not large enough, otherwise it
 * does nothing.
 *
 * @see av_realloc
3646
 */
3647
void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
3648

3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662
/**
 * Allocates a buffer, reusing the given one if large enough.
 *
 * Contrary to av_fast_realloc the current buffer contents might not be
 * preserved and on error the old buffer is freed, thus no special
 * handling to avoid memleaks is necessary.
 *
 * @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer
 * @param size size of the buffer *ptr points to
 * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
 *                 *size 0 if an error occurred.
 */
void av_fast_malloc(void *ptr, unsigned int *size, unsigned int min_size);

3663 3664 3665
/**
 * Copy image 'src' to 'dst'.
 */
3666
void av_picture_copy(AVPicture *dst, const AVPicture *src,
3667
                     enum PixelFormat pix_fmt, int width, int height);
3668

3669
/**
Diego Biurrun's avatar
Diego Biurrun committed
3670
 * Crop image top and left side.
3671
 */
3672
int av_picture_crop(AVPicture *dst, const AVPicture *src,
3673
                    enum PixelFormat pix_fmt, int top_band, int left_band);
3674

3675
/**
Diego Biurrun's avatar
Diego Biurrun committed
3676
 * Pad image.
3677
 */
3678
int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, enum PixelFormat pix_fmt,
3679 3680
            int padtop, int padbottom, int padleft, int padright, int *color);

3681
unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
3682

3683
/**
3684
 * Parses str and put in width_ptr and height_ptr the detected values.
3685
 *
Diego Biurrun's avatar
Diego Biurrun committed
3686
 * @return 0 in case of a successful parsing, a negative value otherwise
3687 3688 3689 3690 3691 3692 3693 3694 3695 3696
 * @param[in] str the string to parse: it has to be a string in the format
 * <width>x<height> or a valid video frame size abbreviation.
 * @param[in,out] width_ptr pointer to the variable which will contain the detected
 * frame width value
 * @param[in,out] height_ptr pointer to the variable which will contain the detected
 * frame height value
 */
int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str);

/**
3697
 * Parses str and put in frame_rate the detected values.
3698
 *
Diego Biurrun's avatar
Diego Biurrun committed
3699
 * @return 0 in case of a successful parsing, a negative value otherwise
3700
 * @param[in] str the string to parse: it has to be a string in the format
3701
 * <frame_rate_num>/<frame_rate_den>, a float number or a valid video rate abbreviation
3702 3703 3704 3705 3706
 * @param[in,out] frame_rate pointer to the AVRational which will contain the detected
 * frame rate
 */
int av_parse_video_frame_rate(AVRational *frame_rate, const char *str);

3707 3708
/* error handling */
#if EINVAL > 0
Diego Biurrun's avatar
Diego Biurrun committed
3709 3710
#define AVERROR(e) (-(e)) /**< Returns a negative error code from a POSIX error code, to return from library functions. */
#define AVUNERROR(e) (-(e)) /**< Returns a POSIX error code from a library function error return value. */
3711
#else
Diego Biurrun's avatar
Diego Biurrun committed
3712
/* Some platforms have E* and errno already negated. */
3713 3714 3715 3716
#define AVERROR(e) (e)
#define AVUNERROR(e) (e)
#endif
#define AVERROR_UNKNOWN     AVERROR(EINVAL)  /**< unknown error */
Diego Biurrun's avatar
Diego Biurrun committed
3717 3718
#define AVERROR_IO          AVERROR(EIO)     /**< I/O error */
#define AVERROR_NUMEXPECTED AVERROR(EDOM)    /**< Number syntax expected in filename. */
3719 3720 3721
#define AVERROR_INVALIDDATA AVERROR(EINVAL)  /**< invalid data found */
#define AVERROR_NOMEM       AVERROR(ENOMEM)  /**< not enough memory */
#define AVERROR_NOFMT       AVERROR(EILSEQ)  /**< unknown format */
Diego Biurrun's avatar
Diego Biurrun committed
3722
#define AVERROR_NOTSUPP     AVERROR(ENOSYS)  /**< Operation not supported. */
Benoit Fouet's avatar
Benoit Fouet committed
3723
#define AVERROR_NOENT       AVERROR(ENOENT)  /**< No such file or directory. */
Peter Ross's avatar
Peter Ross committed
3724
#define AVERROR_EOF         AVERROR(EPIPE)   /**< End of file. */
3725
#define AVERROR_PATCHWELCOME    -MKTAG('P','A','W','E') /**< Not yet implemented in FFmpeg. Patches welcome. */
3726

3727
/**
3728 3729 3730
 * Logs a generic warning message about a missing feature. This function is
 * intended to be used internally by FFmpeg (libavcodec, libavformat, etc.)
 * only, and would normally not be used by applications.
3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741
 * @param[in] avc a pointer to an arbitrary struct of which the first field is
 * a pointer to an AVClass struct
 * @param[in] feature string containing the name of the missing feature
 * @param[in] want_sample indicates if samples are wanted which exhibit this feature.
 * If want_sample is non-zero, additional verbage will be added to the log
 * message which tells the user how to report samples to the development
 * mailing list.
 */
void av_log_missing_feature(void *avc, const char *feature, int want_sample);

/**
3742 3743 3744
 * Logs a generic warning message asking for a sample. This function is
 * intended to be used internally by FFmpeg (libavcodec, libavformat, etc.)
 * only, and would normally not be used by applications.
3745 3746 3747 3748 3749 3750
 * @param[in] avc a pointer to an arbitrary struct of which the first field is
 * a pointer to an AVClass struct
 * @param[in] msg string containing an optional message, or NULL if no message
 */
void av_log_ask_for_sample(void *avc, const char *msg);

3751
/**
3752
 * Registers the hardware accelerator hwaccel.
3753 3754 3755 3756 3757 3758 3759 3760 3761 3762
 */
void av_register_hwaccel(AVHWAccel *hwaccel);

/**
 * If hwaccel is NULL, returns the first registered hardware accelerator,
 * if hwaccel is non-NULL, returns the next registered hardware accelerator
 * after hwaccel, or NULL if hwaccel is the last one.
 */
AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel);

3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775

/**
 * Lock operation used by lockmgr
 */
enum AVLockOp {
  AV_LOCK_CREATE,  ///< Create a mutex
  AV_LOCK_OBTAIN,  ///< Lock the mutex
  AV_LOCK_RELEASE, ///< Unlock the mutex
  AV_LOCK_DESTROY, ///< Free mutex resources
};

/**
 * Register a user provided lock manager supporting the operations
3776
 * specified by AVLockOp. mutex points to a (void *) where the
3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788
 * lockmgr should store/get a pointer to a user allocated mutex. It's
 * NULL upon AV_LOCK_CREATE and != NULL for all other ops.
 *
 * @param cb User defined callback. Note: FFmpeg may invoke calls to this
 *           callback during the call to av_lockmgr_register().
 *           Thus, the application must be prepared to handle that.
 *           If cb is set to NULL the lockmgr will be unregistered.
 *           Also note that during unregistration the previously registered
 *           lockmgr callback may also be invoked.
 */
int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op));

3789
#endif /* AVCODEC_AVCODEC_H */