avcodec.h 139 KB
Newer Older
1 2 3
/*
 * copyright (c) 2001 Fabrice Bellard
 *
4
 * This file is part of Libav.
5
 *
6
 * Libav 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
 * Libav 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 Libav; 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
Diego Biurrun's avatar
Diego Biurrun committed
26
 * external API header
27 28
 */

29
#include <errno.h>
30
#include "libavutil/samplefmt.h"
31
#include "libavutil/avutil.h"
32
#include "libavutil/cpu.h"
33
#include "libavutil/dict.h"
34
#include "libavutil/log.h"
35
#include "libavutil/pixfmt.h"
36
#include "libavutil/rational.h"
Fabrice Bellard's avatar
Fabrice Bellard committed
37

38
#include "libavcodec/version.h"
39

40
/**
Måns Rullgård's avatar
Måns Rullgård committed
41
 * Identify the syntax and semantics of the bitstream.
42 43 44 45 46
 * 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.
47
 *
Diego Biurrun's avatar
Diego Biurrun committed
48 49 50
 * 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.
51
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
52
enum CodecID {
53
    CODEC_ID_NONE,
54 55

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

Diego Biurrun's avatar
Diego Biurrun committed
214
    /* various PCM "codecs" */
215
    CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at the start of audio codecs
216
    CODEC_ID_PCM_S16LE= 0x10000,
Fabrice Bellard's avatar
Fabrice Bellard committed
217 218 219 220 221 222 223
    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,
224 225 226 227 228 229 230 231 232
    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,
233
    CODEC_ID_PCM_ZORK,
234
    CODEC_ID_PCM_S16LE_PLANAR,
235
    CODEC_ID_PCM_DVD,
236
    CODEC_ID_PCM_F32BE,
237 238 239
    CODEC_ID_PCM_F32LE,
    CODEC_ID_PCM_F64BE,
    CODEC_ID_PCM_F64LE,
240
    CODEC_ID_PCM_BLURAY,
241
    CODEC_ID_PCM_LXF,
242
    CODEC_ID_S302M,
243

Diego Biurrun's avatar
Diego Biurrun committed
244
    /* various ADPCM codecs */
245
    CODEC_ID_ADPCM_IMA_QT= 0x11000,
246
    CODEC_ID_ADPCM_IMA_WAV,
247 248
    CODEC_ID_ADPCM_IMA_DK3,
    CODEC_ID_ADPCM_IMA_DK4,
249
    CODEC_ID_ADPCM_IMA_WS,
250
    CODEC_ID_ADPCM_IMA_SMJPEG,
251
    CODEC_ID_ADPCM_MS,
252
    CODEC_ID_ADPCM_4XM,
253 254
    CODEC_ID_ADPCM_XA,
    CODEC_ID_ADPCM_ADX,
255
    CODEC_ID_ADPCM_EA,
256
    CODEC_ID_ADPCM_G726,
257
    CODEC_ID_ADPCM_CT,
258
    CODEC_ID_ADPCM_SWF,
259
    CODEC_ID_ADPCM_YAMAHA,
260 261 262
    CODEC_ID_ADPCM_SBPRO_4,
    CODEC_ID_ADPCM_SBPRO_3,
    CODEC_ID_ADPCM_SBPRO_2,
263
    CODEC_ID_ADPCM_THP,
Vitor Sessak's avatar
Vitor Sessak committed
264
    CODEC_ID_ADPCM_IMA_AMV,
265 266 267
    CODEC_ID_ADPCM_EA_R1,
    CODEC_ID_ADPCM_EA_R3,
    CODEC_ID_ADPCM_EA_R2,
Peter Ross's avatar
Peter Ross committed
268
    CODEC_ID_ADPCM_IMA_EA_SEAD,
Peter Ross's avatar
Peter Ross committed
269
    CODEC_ID_ADPCM_IMA_EA_EACS,
270
    CODEC_ID_ADPCM_EA_XAS,
271
    CODEC_ID_ADPCM_EA_MAXIS_XA,
272
    CODEC_ID_ADPCM_IMA_ISS,
273
    CODEC_ID_ADPCM_G722,
274

275 276
    /* AMR */
    CODEC_ID_AMR_NB= 0x12000,
277 278
    CODEC_ID_AMR_WB,

279
    /* RealAudio codecs*/
280
    CODEC_ID_RA_144= 0x13000,
281
    CODEC_ID_RA_288,
282 283

    /* various DPCM codecs */
284
    CODEC_ID_ROQ_DPCM= 0x14000,
285
    CODEC_ID_INTERPLAY_DPCM,
286
    CODEC_ID_XAN_DPCM,
287
    CODEC_ID_SOL_DPCM,
288

289
    /* audio codecs */
290
    CODEC_ID_MP2= 0x15000,
291
    CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
292 293 294 295 296 297 298 299 300 301 302 303
    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
304
    CODEC_ID_FLAC,
Roberto Togni's avatar
Roberto Togni committed
305
    CODEC_ID_MP3ADU,
306
    CODEC_ID_MP3ON4,
307
    CODEC_ID_SHORTEN,
308
    CODEC_ID_ALAC,
309
    CODEC_ID_WESTWOOD_SND1,
310
    CODEC_ID_GSM, ///< as in Berlin toast format
Roberto Togni's avatar
Roberto Togni committed
311
    CODEC_ID_QDM2,
312
    CODEC_ID_COOK,
313
    CODEC_ID_TRUESPEECH,
314
    CODEC_ID_TTA,
315
    CODEC_ID_SMACKAUDIO,
316
    CODEC_ID_QCELP,
317
    CODEC_ID_WAVPACK,
318
    CODEC_ID_DSICINAUDIO,
Kostya Shishkov's avatar
Kostya Shishkov committed
319
    CODEC_ID_IMC,
320
    CODEC_ID_MUSEPACK7,
321
    CODEC_ID_MLP,
Diego Biurrun's avatar
Diego Biurrun committed
322
    CODEC_ID_GSM_MS, /* as found in WAV */
Benjamin Larsson's avatar
Benjamin Larsson committed
323
    CODEC_ID_ATRAC3,
324
    CODEC_ID_VOXWARE,
Kostya Shishkov's avatar
Kostya Shishkov committed
325
    CODEC_ID_APE,
326
    CODEC_ID_NELLYMOSER,
327
    CODEC_ID_MUSEPACK8,
328
    CODEC_ID_SPEEX,
329 330
    CODEC_ID_WMAVOICE,
    CODEC_ID_WMAPRO,
331
    CODEC_ID_WMALOSSLESS,
Benjamin Larsson's avatar
Benjamin Larsson committed
332
    CODEC_ID_ATRAC3P,
333
    CODEC_ID_EAC3,
334
    CODEC_ID_SIPR,
Michael Niedermayer's avatar
Michael Niedermayer committed
335
    CODEC_ID_MP1,
Vitor Sessak's avatar
Vitor Sessak committed
336
    CODEC_ID_TWINVQ,
337
    CODEC_ID_TRUEHD,
338
    CODEC_ID_MP4ALS,
Benjamin Larsson's avatar
Benjamin Larsson committed
339
    CODEC_ID_ATRAC1,
Daniel Verkamp's avatar
Daniel Verkamp committed
340 341
    CODEC_ID_BINKAUDIO_RDFT,
    CODEC_ID_BINKAUDIO_DCT,
342
    CODEC_ID_AAC_LATM,
343
    CODEC_ID_QDMC,
344
    CODEC_ID_CELT,
345

346
    /* subtitle codecs */
347
    CODEC_ID_FIRST_SUBTITLE = 0x17000,          ///< A dummy ID pointing at the start of subtitle codecs.
348 349
    CODEC_ID_DVD_SUBTITLE= 0x17000,
    CODEC_ID_DVB_SUBTITLE,
350
    CODEC_ID_TEXT,  ///< raw UTF-8 text
351
    CODEC_ID_XSUB,
352
    CODEC_ID_SSA,
353
    CODEC_ID_MOV_TEXT,
354
    CODEC_ID_HDMV_PGS_SUBTITLE,
355
    CODEC_ID_DVB_TELETEXT,
356
    CODEC_ID_SRT,
357

Diego Biurrun's avatar
Diego Biurrun committed
358
    /* other specific kind of codecs (generally used for attachments) */
359
    CODEC_ID_FIRST_UNKNOWN = 0x18000,           ///< A dummy ID pointing at the start of various fake codecs.
360 361
    CODEC_ID_TTF= 0x18000,

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

364
    CODEC_ID_MPEG2TS= 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
Diego Biurrun's avatar
Diego Biurrun committed
365
                                * stream (only used by libavformat) */
Anton Khirnov's avatar
Anton Khirnov committed
366
    CODEC_ID_FFMETADATA=0x21000,   ///< Dummy codec for streams containing only metadata information.
Fabrice Bellard's avatar
Fabrice Bellard committed
367
};
368

369 370 371 372 373 374 375 376 377 378 379
#if FF_API_OLD_SAMPLE_FMT
#define SampleFormat AVSampleFormat

#define SAMPLE_FMT_NONE AV_SAMPLE_FMT_NONE
#define SAMPLE_FMT_U8   AV_SAMPLE_FMT_U8
#define SAMPLE_FMT_S16  AV_SAMPLE_FMT_S16
#define SAMPLE_FMT_S32  AV_SAMPLE_FMT_S32
#define SAMPLE_FMT_FLT  AV_SAMPLE_FMT_FLT
#define SAMPLE_FMT_DBL  AV_SAMPLE_FMT_DBL
#define SAMPLE_FMT_NB   AV_SAMPLE_FMT_NB
#endif
Fabrice Bellard's avatar
Fabrice Bellard committed
380

381
#if FF_API_OLD_AUDIOCONVERT
382
#include "libavutil/audioconvert.h"
383

384
/* Audio channel masks */
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
#define CH_FRONT_LEFT            AV_CH_FRONT_LEFT
#define CH_FRONT_RIGHT           AV_CH_FRONT_RIGHT
#define CH_FRONT_CENTER          AV_CH_FRONT_CENTER
#define CH_LOW_FREQUENCY         AV_CH_LOW_FREQUENCY
#define CH_BACK_LEFT             AV_CH_BACK_LEFT
#define CH_BACK_RIGHT            AV_CH_BACK_RIGHT
#define CH_FRONT_LEFT_OF_CENTER  AV_CH_FRONT_LEFT_OF_CENTER
#define CH_FRONT_RIGHT_OF_CENTER AV_CH_FRONT_RIGHT_OF_CENTER
#define CH_BACK_CENTER           AV_CH_BACK_CENTER
#define CH_SIDE_LEFT             AV_CH_SIDE_LEFT
#define CH_SIDE_RIGHT            AV_CH_SIDE_RIGHT
#define CH_TOP_CENTER            AV_CH_TOP_CENTER
#define CH_TOP_FRONT_LEFT        AV_CH_TOP_FRONT_LEFT
#define CH_TOP_FRONT_CENTER      AV_CH_TOP_FRONT_CENTER
#define CH_TOP_FRONT_RIGHT       AV_CH_TOP_FRONT_RIGHT
#define CH_TOP_BACK_LEFT         AV_CH_TOP_BACK_LEFT
#define CH_TOP_BACK_CENTER       AV_CH_TOP_BACK_CENTER
#define CH_TOP_BACK_RIGHT        AV_CH_TOP_BACK_RIGHT
#define CH_STEREO_LEFT           AV_CH_STEREO_LEFT
#define CH_STEREO_RIGHT          AV_CH_STEREO_RIGHT
405

406 407 408
/** Channel mask value used for AVCodecContext.request_channel_layout
    to indicate that the user requests the channel order of the decoder output
    to be the native codec channel order. */
409
#define CH_LAYOUT_NATIVE         AV_CH_LAYOUT_NATIVE
410

411
/* Audio channel convenience macros */
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
#define CH_LAYOUT_MONO           AV_CH_LAYOUT_MONO
#define CH_LAYOUT_STEREO         AV_CH_LAYOUT_STEREO
#define CH_LAYOUT_2_1            AV_CH_LAYOUT_2_1
#define CH_LAYOUT_SURROUND       AV_CH_LAYOUT_SURROUND
#define CH_LAYOUT_4POINT0        AV_CH_LAYOUT_4POINT0
#define CH_LAYOUT_2_2            AV_CH_LAYOUT_2_2
#define CH_LAYOUT_QUAD           AV_CH_LAYOUT_QUAD
#define CH_LAYOUT_5POINT0        AV_CH_LAYOUT_5POINT0
#define CH_LAYOUT_5POINT1        AV_CH_LAYOUT_5POINT1
#define CH_LAYOUT_5POINT0_BACK   AV_CH_LAYOUT_5POINT0_BACK
#define CH_LAYOUT_5POINT1_BACK   AV_CH_LAYOUT_5POINT1_BACK
#define CH_LAYOUT_7POINT0        AV_CH_LAYOUT_7POINT0
#define CH_LAYOUT_7POINT1        AV_CH_LAYOUT_7POINT1
#define CH_LAYOUT_7POINT1_WIDE   AV_CH_LAYOUT_7POINT1_WIDE
#define CH_LAYOUT_STEREO_DOWNMIX AV_CH_LAYOUT_STEREO_DOWNMIX
#endif
428

Fabrice Bellard's avatar
Fabrice Bellard committed
429
/* in bytes */
430
#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
Fabrice Bellard's avatar
Fabrice Bellard committed
431

432
/**
433
 * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
434 435
 * This is mainly needed because some optimized bitstream readers read
 * 32 or 64 bit at once and could read over the end.<br>
Diego Biurrun's avatar
Diego Biurrun committed
436 437
 * Note: If the first 23 bits of the additional bytes are not 0, then damaged
 * MPEG bitstreams could cause overread and segfault.
438
 */
439
#define FF_INPUT_BUFFER_PADDING_SIZE 8
440

441
/**
Diego Biurrun's avatar
Diego Biurrun committed
442 443
 * minimum encoding buffer size
 * Used to avoid some checks during header writing.
444 445 446
 */
#define FF_MIN_BUFFER_SIZE 16384

447

448
/**
449
 * motion estimation type.
450
 */
451
enum Motion_Est_ID {
452
    ME_ZERO = 1,    ///< no search, that is use 0,0 vector whenever one is needed
453 454 455
    ME_FULL,
    ME_LOG,
    ME_PHODS,
456 457 458 459 460
    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
461
    ME_TESA,        ///< transformed exhaustive search algorithm
462 463
};

Michael Niedermayer's avatar
Michael Niedermayer committed
464
enum AVDiscard{
Diego Biurrun's avatar
Diego Biurrun committed
465 466
    /* 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
467 468 469 470 471 472 473 474
    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
};

475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
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
};

512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
/**
 *  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
};

528
#if FF_API_FLAC_GLOBAL_OPTS
529 530 531
/**
 * LPC analysis type
 */
532
attribute_deprecated enum AVLPCType {
533 534 535 536 537 538 539
    AV_LPC_TYPE_DEFAULT     = -1, ///< use the codec default LPC type
    AV_LPC_TYPE_NONE        =  0, ///< do not use LPC prediction or use all zero coefficients
    AV_LPC_TYPE_FIXED       =  1, ///< fixed LPC coefficients
    AV_LPC_TYPE_LEVINSON    =  2, ///< Levinson-Durbin recursion
    AV_LPC_TYPE_CHOLESKY    =  3, ///< Cholesky factorization
    AV_LPC_TYPE_NB              , ///< Not part of ABI
};
540
#endif
541

542 543 544 545 546 547 548 549 550 551 552 553 554
enum AVAudioServiceType {
    AV_AUDIO_SERVICE_TYPE_MAIN              = 0,
    AV_AUDIO_SERVICE_TYPE_EFFECTS           = 1,
    AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED = 2,
    AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED  = 3,
    AV_AUDIO_SERVICE_TYPE_DIALOGUE          = 4,
    AV_AUDIO_SERVICE_TYPE_COMMENTARY        = 5,
    AV_AUDIO_SERVICE_TYPE_EMERGENCY         = 6,
    AV_AUDIO_SERVICE_TYPE_VOICE_OVER        = 7,
    AV_AUDIO_SERVICE_TYPE_KARAOKE           = 8,
    AV_AUDIO_SERVICE_TYPE_NB                   , ///< Not part of ABI
};

555 556 557
typedef struct RcOverride{
    int start_frame;
    int end_frame;
Diego Biurrun's avatar
Diego Biurrun committed
558
    int qscale; // If this is 0 then quality_factor will be used instead.
559 560 561
    float quality_factor;
} RcOverride;

562
#define FF_MAX_B_FRAMES 16
563

564
/* encoding support
Diego Biurrun's avatar
Diego Biurrun committed
565 566
   These flags can be passed in AVCodecContext.flags before initialization.
   Note: Not everything is supported yet.
567
*/
Fabrice Bellard's avatar
Fabrice Bellard committed
568

Diego Biurrun's avatar
Diego Biurrun committed
569 570 571 572 573
#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>.
574 575
/**
 * The parent program guarantees that the input for B-frames containing
Diego Biurrun's avatar
Diego Biurrun committed
576
 * streams is not written to for at least s->max_b_frames+1 frames, if
577 578
 * this is not set the input will be copied.
 */
579
#define CODEC_FLAG_INPUT_PRESERVED 0x0100
Diego Biurrun's avatar
Diego Biurrun committed
580 581 582 583 584 585 586
#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_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
587 588 589 590 591
#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_GLOBAL_HEADER  0x00400000 ///< Place global headers in extradata instead of every keyframe.
#define CODEC_FLAG_BITEXACT       0x00800000 ///< Use only bitexact stuff (except (I)DCT).
592
/* Fx : Flag for h263+ extra options */
Diego Biurrun's avatar
Diego Biurrun committed
593 594 595
#define CODEC_FLAG_AC_PRED        0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
#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.
Michael Niedermayer's avatar
Michael Niedermayer committed
596
#define CODEC_FLAG_LOOP_FILTER    0x00000800 ///< loop filter
597
#define CODEC_FLAG_INTERLACED_ME  0x20000000 ///< interlaced motion estimation
598
#define CODEC_FLAG_CLOSED_GOP     0x80000000
Diego Biurrun's avatar
Diego Biurrun committed
599 600 601 602
#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.
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
#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.
/**
 * @defgroup deprecated_flags Deprecated codec flags
 * Use corresponding private codec options instead.
 * @{
 */
#if FF_API_MPEGVIDEO_GLOBAL_OPTS
#define CODEC_FLAG_OBMC           0x00000001 ///< OBMC
#define CODEC_FLAG_H263P_AIV      0x00000008 ///< H.263 alternative inter VLC
#define CODEC_FLAG_PART   0x0080  ///< Use data partitioning.
#define CODEC_FLAG_ALT_SCAN       0x00100000 ///< Use alternate scan.
#define CODEC_FLAG_H263P_UMV      0x02000000 ///< unlimited motion vector
#define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000
#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< Will reserve space for SVCD scan offset user data.
#define CODEC_FLAG2_INTRA_VLC     0x00000800 ///< Use MPEG-2 intra VLC table.
#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format.
#define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer.
#endif
#if FF_API_MJPEG_GLOBAL_OPTS
#define CODEC_FLAG_EXTERN_HUFF     0x1000   ///< Use external Huffman table (for MJPEG).
#endif
625
#if FF_API_X264_GLOBAL_OPTS
Diego Biurrun's avatar
Diego Biurrun committed
626 627
#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
628
#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
629 630 631
#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
632
#define CODEC_FLAG2_BRDO          0x00000400 ///< B-frame rate-distortion optimization
633 634 635 636
#define CODEC_FLAG2_MBTREE        0x00040000 ///< Use macroblock tree ratecontrol (x264 only)
#define CODEC_FLAG2_PSY           0x00080000 ///< Use psycho visual optimizations.
#define CODEC_FLAG2_SSIM          0x00100000 ///< Compute SSIM during encoding, error[] values are undefined.
#define CODEC_FLAG2_INTRA_REFRESH 0x00200000 ///< Use periodic insertion of intra blocks instead of keyframes.
637
#endif
638
#if FF_API_SNOW_GLOBAL_OPTS
Diego Biurrun's avatar
Diego Biurrun committed
639
#define CODEC_FLAG2_MEMC_ONLY     0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC).
640
#endif
641
#if FF_API_LAME_GLOBAL_OPTS
642
#define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible
643
#endif
644 645 646
/**
 * @}
 */
647

648
/* Unsupported options :
649 650
 *              Syntax Arithmetic coding (SAC)
 *              Reference Picture Selection
651
 *              Independent Segment Decoding */
652
/* /Fx */
653 654
/* codec capabilities */

Diego Biurrun's avatar
Diego Biurrun committed
655
#define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback.
656
/**
657 658 659
 * Codec uses get_buffer() for allocating buffers and supports custom allocators.
 * If not set, it might not use get_buffer() at all or use operations that
 * assume the buffer was allocated by avcodec_default_get_buffer.
660 661
 */
#define CODEC_CAP_DR1             0x0002
Diego Biurrun's avatar
Diego Biurrun committed
662
/* If 'parse_only' field is true, then avcodec_parse_frame() can be used. */
663
#define CODEC_CAP_PARSE_ONLY      0x0004
664
#define CODEC_CAP_TRUNCATED       0x0008
Diego Biurrun's avatar
Diego Biurrun committed
665
/* Codec can export data for HW decoding (XvMC). */
666
#define CODEC_CAP_HWACCEL         0x0010
667
/**
Diego Biurrun's avatar
Diego Biurrun committed
668 669
 * 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.
670
 */
671
#define CODEC_CAP_DELAY           0x0020
672 673 674 675 676
/**
 * 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
677 678 679 680
/**
 * Codec can export data for HW decoding (VDPAU).
 */
#define CODEC_CAP_HWACCEL_VDPAU    0x0080
681 682
/**
 * Codec can output multiple frames per AVPacket
683 684 685 686 687 688 689 690
 * Normally demuxers return one frame at a time, demuxers which do not do
 * are connected to a parser to split what they return into proper frames.
 * This flag is reserved to the very rare category of codecs which have a
 * bitstream that cannot be split into frames without timeconsuming
 * operations like full decoding. Demuxers carring such bitstreams thus
 * may return multiple frames in a packet. This has many disadvantages like
 * prohibiting stream copy in many cases thus it should only be considered
 * as a last resort.
691 692
 */
#define CODEC_CAP_SUBFRAMES        0x0100
693 694 695 696 697
/**
 * Codec is experimental and is thus avoided in favor of non experimental
 * encoders
 */
#define CODEC_CAP_EXPERIMENTAL     0x0200
698 699 700 701
/**
 * Codec should fill in channel configuration and samplerate instead of container
 */
#define CODEC_CAP_CHANNEL_CONF     0x0400
702 703 704 705
/**
 * Codec is able to deal with negative linesizes
 */
#define CODEC_CAP_NEG_LINESIZES    0x0800
706 707 708 709
/**
 * Codec supports frame-level multithreading.
 */
#define CODEC_CAP_FRAME_THREADS    0x1000
710 711 712 713
/**
 * Codec supports slice-based (or partition-based) multithreading.
 */
#define CODEC_CAP_SLICE_THREADS    0x2000
714

Diego Biurrun's avatar
Diego Biurrun committed
715
//The following defines may change, don't expect compatibility if you use them.
716
#define MB_TYPE_INTRA4x4   0x0001
Diego Biurrun's avatar
Diego Biurrun committed
717 718
#define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific
#define MB_TYPE_INTRA_PCM  0x0004 //FIXME H.264-specific
719 720 721 722 723
#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
724
#define MB_TYPE_DIRECT2    0x0100 //FIXME
725 726 727 728 729 730 731 732 733 734 735 736 737 738
#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, ...)

739 740
/**
 * Pan Scan area.
Diego Biurrun's avatar
Diego Biurrun committed
741 742
 * This specifies the area which should be displayed.
 * Note there may be multiple such areas for one frame.
743 744 745
 */
typedef struct AVPanScan{
    /**
Diego Biurrun's avatar
Diego Biurrun committed
746 747 748
     * id
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
749 750 751 752 753
     */
    int id;

    /**
     * width and height in 1/16 pel
Diego Biurrun's avatar
Diego Biurrun committed
754 755
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
756 757 758 759 760
     */
    int width;
    int height;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
761 762 763
     * position of the top left corner in 1/16 pel for up to 3 fields/frames
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
764 765 766 767
     */
    int16_t position[3][2];
}AVPanScan;

768 769 770
#define FF_QSCALE_TYPE_MPEG1 0
#define FF_QSCALE_TYPE_MPEG2 1
#define FF_QSCALE_TYPE_H264  2
771
#define FF_QSCALE_TYPE_VP56  3
Michael Niedermayer's avatar
Michael Niedermayer committed
772 773

#define FF_BUFFER_TYPE_INTERNAL 1
Diego Biurrun's avatar
Diego Biurrun committed
774 775 776
#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
777

778 779 780 781 782 783 784 785 786 787
#if FF_API_OLD_FF_PICT_TYPES
/* DEPRECATED, directly use the AV_PICTURE_TYPE_* enum values */
#define FF_I_TYPE  AV_PICTURE_TYPE_I  ///< Intra
#define FF_P_TYPE  AV_PICTURE_TYPE_P  ///< Predicted
#define FF_B_TYPE  AV_PICTURE_TYPE_B  ///< Bi-dir predicted
#define FF_S_TYPE  AV_PICTURE_TYPE_S  ///< S(GMC)-VOP MPEG4
#define FF_SI_TYPE AV_PICTURE_TYPE_SI ///< Switching Intra
#define FF_SP_TYPE AV_PICTURE_TYPE_SP ///< Switching Predicted
#define FF_BI_TYPE AV_PICTURE_TYPE_BI
#endif
Michael Niedermayer's avatar
Michael Niedermayer committed
788

Diego Biurrun's avatar
Diego Biurrun committed
789 790 791 792
#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).
793

794 795 796 797
enum AVPacketSideDataType {
    AV_PKT_DATA_PALETTE,
};

798 799
typedef struct AVPacket {
    /**
800 801
     * Presentation timestamp in AVStream->time_base units; the time at which
     * the decompressed packet will be presented to the user.
802 803 804 805 806 807 808 809
     * 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;
    /**
810 811
     * Decompression timestamp in AVStream->time_base units; the time at which
     * the packet is decompressed.
812 813 814 815 816 817
     * Can be AV_NOPTS_VALUE if it is not stored in the file.
     */
    int64_t dts;
    uint8_t *data;
    int   size;
    int   stream_index;
818 819 820
    /**
     * A combination of AV_PKT_FLAG values
     */
821
    int   flags;
822 823 824 825 826 827 828 829 830 831 832
    /**
     * Additional packet data that can be provided by the container.
     * Packet can contain several types of side information.
     */
    struct {
        uint8_t *data;
        int      size;
        enum AVPacketSideDataType type;
    } *side_data;
    int side_data_elems;

833
    /**
834
     * Duration of this packet in AVStream->time_base units, 0 if unknown.
835 836 837 838 839 840 841 842
     * 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

    /**
843
     * Time difference in AVStream->time_base units from the pts of this
844 845 846 847 848 849
     * 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.
Aurelien Jacobs's avatar
Aurelien Jacobs committed
850 851
     * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
     * set.
852 853 854 855 856 857 858 859 860
     *
     * 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;
861 862
#define AV_PKT_FLAG_KEY     0x0001 ///< The packet contains a keyframe
#define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
863

864 865
/**
 * Audio Video Frame.
866 867 868
 * New fields can be added to the end of AVFRAME with minor version
 * bumps. Removal, reordering and changes to existing fields require
 * a major version bump.
Diego Biurrun's avatar
Diego Biurrun committed
869
 * sizeof(AVFrame) must not be used outside libav*.
870
 */
871
typedef struct AVFrame {
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
    /**
     * pointer to the picture planes.
     * This might be different from the first allocated byte
     * - encoding:
     * - decoding:
     */
    uint8_t *data[4];
    int linesize[4];
    /**
     * 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.
     * - encoding:
     * - decoding:
     */
    uint8_t *base[4];
    /**
     * 1 -> keyframe, 0-> not
     * - encoding: Set by libavcodec.
     * - decoding: Set by libavcodec.
     */
    int key_frame;

    /**
     * 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.
     */
    enum AVPictureType pict_type;

    /**
     * presentation timestamp in time_base units (time when frame should be shown to user)
     * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.
     * - encoding: MUST be set by user.
     * - decoding: Set by libavcodec.
     */
    int64_t pts;

    /**
     * picture number in bitstream order
     * - encoding: set by
     * - decoding: Set by libavcodec.
     */
    int coded_picture_number;
    /**
     * picture number in display order
     * - encoding: set by
     * - decoding: Set by libavcodec.
     */
    int display_picture_number;

    /**
     * quality (between 1 (good) and FF_LAMBDA_MAX (bad))
     * - encoding: Set by libavcodec. for coded_picture (and set by user for input).
     * - decoding: Set by libavcodec.
     */
    int quality;

    /**
     * buffer age (1->was last buffer and dint change, 2->..., ...).
     * Set to INT_MAX if the buffer has not been used yet.
     * - encoding: unused
     * - decoding: MUST be set by get_buffer().
     */
    int age;

    /**
     * is this picture used as reference
     * 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.
     * Set to 4 for delayed, non-reference frames.
     * - encoding: unused
     * - decoding: Set by libavcodec. (before get_buffer() call)).
     */
    int reference;

    /**
     * QP table
     * - encoding: unused
     * - decoding: Set by libavcodec.
     */
    int8_t *qscale_table;
    /**
     * QP store stride
     * - encoding: unused
     * - decoding: Set by libavcodec.
     */
    int qstride;

    /**
     * mbskip_table[mb]>=1 if MB didn't change
     * stride= mb_width = (width+15)>>4
     * - encoding: unused
     * - decoding: Set by libavcodec.
     */
    uint8_t *mbskip_table;

    /**
     * motion vector table
     * @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
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
     */
    int16_t (*motion_val[2])[2];

    /**
     * macroblock type table
     * mb_type_base + mb_width + 2
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
     */
    uint32_t *mb_type;

    /**
     * log2 of the size of the block which a single vector in motion_val represents:
     * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)
     * - encoding: unused
     * - decoding: Set by libavcodec.
     */
    uint8_t motion_subsample_log2;

    /**
     * for some private data of the user
     * - encoding: unused
     * - decoding: Set by user.
     */
    void *opaque;

    /**
     * error
     * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.
     * - decoding: unused
     */
    uint64_t error[4];

    /**
     * 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.
     */
    int type;

    /**
     * When decoding, this signals how much the picture must be delayed.
     * extra_delay = repeat_pict / (2*fps)
     * - encoding: unused
     * - decoding: Set by libavcodec.
     */
    int repeat_pict;

    /**
     *
     */
    int qscale_type;

    /**
     * The content of the picture is interlaced.
     * - encoding: Set by user.
     * - decoding: Set by libavcodec. (default 0)
     */
    int interlaced_frame;

    /**
     * If the content is interlaced, is top field displayed first.
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
     */
    int top_field_first;

    /**
     * Pan scan.
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
     */
    AVPanScan *pan_scan;

    /**
     * Tell user application that palette has changed from previous frame.
     * - encoding: ??? (no palette-enabled encoder yet)
     * - decoding: Set by libavcodec. (default 0).
     */
    int palette_has_changed;

    /**
     * codec suggestion on buffer type if != 0
     * - encoding: unused
     * - decoding: Set by libavcodec. (before get_buffer() call)).
     */
    int buffer_hints;

    /**
     * DCT coefficients
     * - encoding: unused
     * - decoding: Set by libavcodec.
     */
    short *dct_coeff;

    /**
     * motion reference frame index
     * the order in which these are stored can depend on the codec.
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
     */
    int8_t *ref_index[2];

    /**
     * reordered opaque 64bit (generally an integer or a double precision float
     * PTS but can be anything).
     * The user sets AVCodecContext.reordered_opaque to represent the input at
     * that time,
     * the decoder reorders values as needed and sets AVFrame.reordered_opaque
     * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque
     * @deprecated in favor of pkt_pts
     * - encoding: unused
     * - decoding: Read by user.
     */
    int64_t reordered_opaque;

    /**
     * hardware accelerator private data (Libav-allocated)
     * - encoding: unused
     * - decoding: Set by libavcodec
     */
    void *hwaccel_picture_private;

    /**
     * reordered pts from the last AVPacket that has been input into the decoder
     * - encoding: unused
     * - decoding: Read by user.
     */
    int64_t pkt_pts;

    /**
     * dts from the last AVPacket that has been input into the decoder
     * - encoding: unused
     * - decoding: Read by user.
     */
    int64_t pkt_dts;

    /**
     * the AVCodecContext which ff_thread_get_buffer() was last called on
     * - encoding: Set by libavcodec.
     * - decoding: Set by libavcodec.
     */
    struct AVCodecContext *owner;

    /**
     * used by multithreading to store frame-specific info
     * - encoding: Set by libavcodec.
     * - decoding: Set by libavcodec.
     */
    void *thread_opaque;
1130
} AVFrame;
Michael Niedermayer's avatar
Michael Niedermayer committed
1131

Michael Niedermayer's avatar
Michael Niedermayer committed
1132
/**
1133 1134
 * main external API structure.
 * New fields can be added to the end with minor version bumps.
Diego Biurrun's avatar
Diego Biurrun committed
1135
 * Removal, reordering and changes to existing fields require a major
1136
 * version bump.
Diego Biurrun's avatar
Diego Biurrun committed
1137
 * sizeof(AVCodecContext) must not be used outside libav*.
Michael Niedermayer's avatar
Michael Niedermayer committed
1138
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
1139
typedef struct AVCodecContext {
1140
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1141
     * information on struct for av_log
1142 1143
     * - set by avcodec_alloc_context
     */
1144
    const AVClass *av_class;
1145
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1146 1147 1148
     * 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.
1149
     */
Fabrice Bellard's avatar
Fabrice Bellard committed
1150
    int bit_rate;
1151 1152

    /**
1153
     * number of bits the bitstream is allowed to diverge from the reference.
1154
     *           the reference can be CBR (for CBR pass1) or VBR (for pass2)
Diego Biurrun's avatar
Diego Biurrun committed
1155
     * - encoding: Set by user; unused for constant quantizer encoding.
1156
     * - decoding: unused
1157
     */
1158
    int bit_rate_tolerance;
1159 1160

    /**
1161
     * CODEC_FLAG_*.
Diego Biurrun's avatar
Diego Biurrun committed
1162 1163
     * - encoding: Set by user.
     * - decoding: Set by user.
1164
     */
Fabrice Bellard's avatar
Fabrice Bellard committed
1165
    int flags;
1166 1167

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1168 1169 1170 1171 1172 1173
     * 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?)
1174 1175 1176 1177
     */
    int sub_id;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1178
     * Motion estimation algorithm used for video coding.
Robert Swain's avatar
Robert Swain committed
1179
     * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
1180
     * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific]
1181 1182
     * - encoding: MUST be set by user.
     * - decoding: unused
1183 1184 1185 1186
     */
    int me_method;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1187 1188
     * some codecs need / can use extradata like Huffman tables.
     * mjpeg: Huffman tables
1189
     * rv10: additional flags
1190
     * mpeg4: global headers (they can be in the bitstream or here)
Diego Biurrun's avatar
Diego Biurrun committed
1191 1192 1193 1194 1195
     * 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.
1196
     */
1197
    uint8_t *extradata;
1198
    int extradata_size;
1199

1200
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1201 1202
     * This is the fundamental unit of time (in seconds) in terms
     * of which frame timestamps are represented. For fixed-fps content,
1203 1204
     * timebase should be 1/framerate and timestamp increments should be
     * identically 1.
Diego Biurrun's avatar
Diego Biurrun committed
1205 1206
     * - encoding: MUST be set by user.
     * - decoding: Set by libavcodec.
1207
     */
1208
    AVRational time_base;
1209

1210
    /* video only */
1211
    /**
1212
     * picture width / height.
1213
     * - encoding: MUST be set by user.
Diego Biurrun's avatar
Diego Biurrun committed
1214 1215 1216
     * - decoding: Set by libavcodec.
     * Note: For compatibility it is possible to set this instead of
     * coded_width/height before decoding.
1217
     */
Fabrice Bellard's avatar
Fabrice Bellard committed
1218
    int width, height;
1219

1220
#define FF_ASPECT_EXTENDED 15
1221 1222

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1223 1224
     * the number of pictures in a group of pictures, or 0 for intra_only
     * - encoding: Set by user.
1225
     * - decoding: unused
1226 1227 1228 1229
     */
    int gop_size;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1230
     * Pixel format, see PIX_FMT_xxx.
1231 1232
     * May be set by the demuxer if known from headers.
     * May be overriden by the decoder if it knows better.
Diego Biurrun's avatar
Diego Biurrun committed
1233
     * - encoding: Set by user.
1234
     * - decoding: Set by user if known, overridden by libavcodec if known
1235
     */
1236
    enum PixelFormat pix_fmt;
1237

1238
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1239 1240
     * If non NULL, 'draw_horiz_band' is called by the libavcodec
     * decoder to draw a horizontal band. It improves cache usage. Not
1241
     * all codecs can do that. You must check the codec capabilities
Diego Biurrun's avatar
Diego Biurrun committed
1242
     * beforehand.
1243 1244 1245 1246
     * When multithreading is used, it may be called from multiple threads
     * at the same time; threads might draw different parts of the same AVFrame,
     * or multiple AVFrames, and there is no guarantee that slices will be drawn
     * in order.
1247 1248 1249 1250 1251 1252 1253
     * 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.
1254
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1255
     * - decoding: Set by user.
1256 1257 1258 1259
     * @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
1260
     */
1261
    void (*draw_horiz_band)(struct AVCodecContext *s,
1262
                            const AVFrame *src, int offset[4],
1263
                            int y, int type, int height);
1264

Fabrice Bellard's avatar
Fabrice Bellard committed
1265
    /* audio only */
Diego Biurrun's avatar
Diego Biurrun committed
1266
    int sample_rate; ///< samples per second
1267
    int channels;    ///< number of audio channels
1268 1269

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1270 1271 1272
     * audio sample format
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
1273
     */
1274
    enum AVSampleFormat sample_fmt;  ///< sample format
Fabrice Bellard's avatar
Fabrice Bellard committed
1275

Diego Biurrun's avatar
Diego Biurrun committed
1276
    /* The following data should not be initialized. */
1277
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1278
     * Samples per packet, initialized when calling 'init'.
1279 1280
     */
    int frame_size;
1281 1282
    int frame_number;   ///< audio or video frame number

1283
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1284
     * Number of frames the decoded output will be delayed relative to
1285
     * the encoded input.
Diego Biurrun's avatar
Diego Biurrun committed
1286
     * - encoding: Set by libavcodec.
1287
     * - decoding: unused
1288 1289
     */
    int delay;
1290

1291 1292
    /* - encoding parameters */
    float qcompress;  ///< amount of qscale change between easy & hard scenes (0.0-1.0)
1293 1294
    float qblur;      ///< amount of qscale smoothing over time (0.0-1.0)

1295
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1296 1297
     * minimum quantizer
     * - encoding: Set by user.
1298
     * - decoding: unused
1299 1300 1301 1302
     */
    int qmin;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1303 1304
     * maximum quantizer
     * - encoding: Set by user.
1305
     * - decoding: unused
1306 1307 1308 1309
     */
    int qmax;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1310 1311
     * maximum quantizer difference between frames
     * - encoding: Set by user.
1312
     * - decoding: unused
1313 1314 1315 1316
     */
    int max_qdiff;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1317 1318 1319
     * 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.
1320
     * - decoding: unused
1321 1322 1323 1324
     */
    int max_b_frames;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1325
     * qscale factor between IP and B-frames
1326 1327
     * 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
1328
     * - encoding: Set by user.
1329
     * - decoding: unused
1330 1331
     */
    float b_quant_factor;
1332

1333 1334
    /** obsolete FIXME remove */
    int rc_strategy;
1335 1336
#define FF_RC_STRATEGY_XVID 1

1337
    int b_frame_strategy;
1338

Fabrice Bellard's avatar
Fabrice Bellard committed
1339
    struct AVCodec *codec;
1340

Fabrice Bellard's avatar
Fabrice Bellard committed
1341 1342
    void *priv_data;

Diego Biurrun's avatar
Diego Biurrun committed
1343
    int rtp_payload_size;   /* The size of the RTP payload: the coder will  */
Diego Biurrun's avatar
Diego Biurrun committed
1344
                            /* do its best to deliver a chunk with size     */
1345
                            /* below rtp_payload_size, the chunk will start */
Diego Biurrun's avatar
Diego Biurrun committed
1346
                            /* with a start code on some codecs like H.263. */
1347
                            /* This doesn't take account of any particular  */
Diego Biurrun's avatar
Diego Biurrun committed
1348
                            /* headers inside the transmitted RTP payload.  */
1349

1350

Diego Biurrun's avatar
Diego Biurrun committed
1351 1352 1353 1354 1355 1356
    /* 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.                  */
1357
    void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
1358

1359 1360 1361 1362 1363 1364 1365 1366
    /* 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;
1367
    int misc_bits;
1368

1369
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1370 1371
     * number of bits used for the previously encoded frame
     * - encoding: Set by libavcodec.
1372
     * - decoding: unused
1373
     */
1374
    int frame_bits;
1375

1376
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1377 1378 1379
     * Private data of the user, can be used to carry app specific stuff.
     * - encoding: Set by user.
     * - decoding: Set by user.
1380 1381 1382
     */
    void *opaque;

Fabrice Bellard's avatar
Fabrice Bellard committed
1383
    char codec_name[32];
1384
    enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
1385
    enum CodecID codec_id; /* see CODEC_ID_xxx */
1386

1387 1388
    /**
     * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Diego Biurrun's avatar
Diego Biurrun committed
1389 1390 1391 1392
     * 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.
1393
     * If the codec tag field in a container is larger than 32 bits then the demuxer should
Diego Biurrun's avatar
Diego Biurrun committed
1394
     * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
Michael Niedermayer's avatar
Michael Niedermayer committed
1395
     * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
Diego Biurrun's avatar
Diego Biurrun committed
1396 1397 1398
     * 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.
1399 1400
     */
    unsigned int codec_tag;
1401

1402
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1403 1404 1405
     * Work around bugs in encoders which sometimes cannot be detected automatically.
     * - encoding: Set by user
     * - decoding: Set by user
1406 1407
     */
    int workaround_bugs;
1408
#define FF_BUG_AUTODETECT       1  ///< autodetection
1409 1410 1411 1412
#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
1413
#define FF_BUG_AMV              32
Diego Biurrun's avatar
Diego Biurrun committed
1414
#define FF_BUG_AC_VLC           0  ///< Will be removed, libavcodec can now handle these non-compliant files by default.
1415
#define FF_BUG_QPEL_CHROMA      64
Michael Niedermayer's avatar
Michael Niedermayer committed
1416
#define FF_BUG_STD_QPEL         128
1417
#define FF_BUG_QPEL_CHROMA2     256
1418
#define FF_BUG_DIRECT_BLOCKSIZE 512
1419
#define FF_BUG_EDGE             1024
1420
#define FF_BUG_HPEL_CHROMA      2048
1421
#define FF_BUG_DC_CLIP          4096
Diego Biurrun's avatar
Diego Biurrun committed
1422
#define FF_BUG_MS               8192 ///< Work around various bugs in Microsoft's broken decoders.
1423
#define FF_BUG_TRUNCATED       16384
Diego Biurrun's avatar
Diego Biurrun committed
1424
//#define FF_BUG_FAKE_SCALABILITY 16 //Autodetection should work 100%.
1425

1426
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1427 1428
     * luma single coefficient elimination threshold
     * - encoding: Set by user.
1429
     * - decoding: unused
1430
     */
1431
    int luma_elim_threshold;
1432

1433
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1434 1435
     * chroma single coeff elimination threshold
     * - encoding: Set by user.
1436
     * - decoding: unused
1437
     */
1438
    int chroma_elim_threshold;
1439

1440
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1441 1442
     * strictly follow the standard (MPEG4, ...).
     * - encoding: Set by user.
1443 1444
     * - decoding: Set by user.
     * Setting this to STRICT or higher means the encoder and decoder will
1445
     * generally do stupid things, whereas setting it to unofficial or lower
1446 1447
     * will mean the encoder might produce output that is not supported by all
     * spec-compliant decoders. Decoders don't differentiate between normal,
1448
     * unofficial and experimental (that is, they always try to decode things
1449
     * when they can) unless they are explicitly asked to behave stupidly
1450
     * (=strictly conform to the specs)
1451 1452
     */
    int strict_std_compliance;
1453
#define FF_COMPLIANCE_VERY_STRICT   2 ///< Strictly conform to an older more strict version of the spec or reference software.
Diego Biurrun's avatar
Diego Biurrun committed
1454
#define FF_COMPLIANCE_STRICT        1 ///< Strictly conform to all the things in the spec no matter what consequences.
1455
#define FF_COMPLIANCE_NORMAL        0
1456
#define FF_COMPLIANCE_UNOFFICIAL   -1 ///< Allow unofficial extensions
Diego Biurrun's avatar
Diego Biurrun committed
1457
#define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
1458

1459
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1460 1461
     * qscale offset between IP and B-frames
     * - encoding: Set by user.
1462
     * - decoding: unused
1463 1464
     */
    float b_quant_offset;
1465

1466
    /**
1467
     * Error recognition; higher values will detect more errors but may
Diego Biurrun's avatar
Diego Biurrun committed
1468
     * misdetect some more or less valid parts as errors.
1469
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1470
     * - decoding: Set by user.
1471
     */
1472
    int error_recognition;
1473
#define FF_ER_CAREFUL         1
1474 1475
#define FF_ER_COMPLIANT       2
#define FF_ER_AGGRESSIVE      3
1476
#if FF_API_VERY_AGGRESSIVE
1477
#define FF_ER_VERY_AGGRESSIVE 4
1478
#define FF_ER_EXPLODE         5
1479 1480 1481
#else
#define FF_ER_EXPLODE         4
#endif /* FF_API_VERY_AGGRESSIVE */
1482

1483
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1484 1485
     * 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.
1486
     * avcodec_align_dimensions2() should be used to find the required width and
Diego Biurrun's avatar
Diego Biurrun committed
1487
     * height, as they normally need to be rounded up to the next multiple of 16.
1488 1489 1490
     * 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.
1491 1492 1493
     * If frame multithreading is used and thread_safe_callbacks is set,
     * it may be called from a different thread, but not from more than one at once.
     * Does not need to be reentrant.
1494
     * - encoding: unused
1495
     * - decoding: Set by libavcodec, user can override.
1496
     */
1497
    int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
1498

1499
    /**
Ramiro Polla's avatar
Ramiro Polla committed
1500
     * Called to release buffers which were allocated with get_buffer.
Diego Biurrun's avatar
Diego Biurrun committed
1501 1502
     * A released buffer can be reused in get_buffer().
     * pic.data[*] must be set to NULL.
1503 1504
     * May be called from a different thread if frame multithreading is used,
     * but not by more than one thread at once, so does not need to be reentrant.
1505
     * - encoding: unused
1506
     * - decoding: Set by libavcodec, user can override.
1507
     */
1508
    void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
Michael Niedermayer's avatar
Michael Niedermayer committed
1509

1510
    /**
1511
     * Size of the frame reordering buffer in the decoder.
1512
     * For MPEG-2 it is 1 IPB or 0 low delay IP.
Diego Biurrun's avatar
Diego Biurrun committed
1513 1514
     * - encoding: Set by libavcodec.
     * - decoding: Set by libavcodec.
1515 1516
     */
    int has_b_frames;
1517 1518 1519

    /**
     * number of bytes per packet if constant and known or 0
Diego Biurrun's avatar
Diego Biurrun committed
1520
     * Used by some WAV based audio codecs.
1521 1522
     */
    int block_align;
1523

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

1528
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1529 1530
     * 0-> h263 quant 1-> mpeg quant
     * - encoding: Set by user.
1531
     * - decoding: unused
1532 1533
     */
    int mpeg_quant;
1534

1535
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1536 1537
     * pass1 encoding statistics output buffer
     * - encoding: Set by libavcodec.
1538
     * - decoding: unused
1539
     */
1540
    char *stats_out;
1541

1542
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1543 1544 1545
     * pass2 encoding statistics input buffer
     * Concatenated stuff from stats_out of pass1 should be placed here.
     * - encoding: Allocated/set/freed by user.
1546
     * - decoding: unused
1547 1548
     */
    char *stats_in;
1549

1550
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1551 1552 1553
     * ratecontrol qmin qmax limiting method
     * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax.
     * - encoding: Set by user.
1554
     * - decoding: unused
1555
     */
1556
    float rc_qsquish;
1557

1558 1559
    float rc_qmod_amp;
    int rc_qmod_freq;
1560

1561
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1562 1563
     * ratecontrol override, see RcOverride
     * - encoding: Allocated/set/freed by user.
1564
     * - decoding: unused
1565
     */
1566 1567
    RcOverride *rc_override;
    int rc_override_count;
1568

1569
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1570 1571
     * rate control equation
     * - encoding: Set by user
1572
     * - decoding: unused
1573
     */
Luca Abeni's avatar
Luca Abeni committed
1574
    const char *rc_eq;
1575

1576
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1577 1578
     * maximum bitrate
     * - encoding: Set by user.
1579
     * - decoding: unused
1580
     */
1581
    int rc_max_rate;
1582

1583
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1584 1585
     * minimum bitrate
     * - encoding: Set by user.
1586
     * - decoding: unused
1587
     */
1588
    int rc_min_rate;
1589

1590
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1591 1592
     * decoder bitstream buffer size
     * - encoding: Set by user.
1593
     * - decoding: unused
1594
     */
1595 1596
    int rc_buffer_size;
    float rc_buffer_aggressivity;
1597 1598

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1599 1600 1601 1602
     * 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.
1603
     * - decoding: unused
1604 1605
     */
    float i_quant_factor;
1606

1607
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1608 1609
     * qscale offset between P and I-frames
     * - encoding: Set by user.
1610
     * - decoding: unused
1611 1612
     */
    float i_quant_offset;
1613

1614
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1615 1616
     * initial complexity for pass1 ratecontrol
     * - encoding: Set by user.
1617
     * - decoding: unused
1618
     */
1619
    float rc_initial_cplx;
1620

1621
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1622 1623
     * DCT algorithm, see FF_DCT_* below
     * - encoding: Set by user.
1624
     * - decoding: unused
1625
     */
1626
    int dct_algo;
1627
#define FF_DCT_AUTO    0
1628
#define FF_DCT_FASTINT 1
1629 1630 1631
#define FF_DCT_INT     2
#define FF_DCT_MMX     3
#define FF_DCT_MLIB    4
1632
#define FF_DCT_ALTIVEC 5
1633
#define FF_DCT_FAAN    6
1634

1635
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1636 1637
     * luminance masking (0-> disabled)
     * - encoding: Set by user.
1638
     * - decoding: unused
1639 1640
     */
    float lumi_masking;
1641

1642
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1643 1644
     * temporary complexity masking (0-> disabled)
     * - encoding: Set by user.
1645
     * - decoding: unused
1646 1647
     */
    float temporal_cplx_masking;
1648

1649
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1650 1651
     * spatial complexity masking (0-> disabled)
     * - encoding: Set by user.
1652
     * - decoding: unused
1653 1654
     */
    float spatial_cplx_masking;
1655

1656
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1657 1658
     * p block masking (0-> disabled)
     * - encoding: Set by user.
1659
     * - decoding: unused
1660 1661
     */
    float p_masking;
1662

1663
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1664 1665
     * darkness masking (0-> disabled)
     * - encoding: Set by user.
1666
     * - decoding: unused
1667 1668
     */
    float dark_masking;
1669

1670
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1671 1672 1673
     * IDCT algorithm, see FF_IDCT_* below.
     * - encoding: Set by user.
     * - decoding: Set by user.
1674 1675
     */
    int idct_algo;
Diego Biurrun's avatar
Diego Biurrun committed
1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691
#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
1692
#define FF_IDCT_SIMPLEARMV5TE 16
Diego Biurrun's avatar
Diego Biurrun committed
1693
#define FF_IDCT_SIMPLEARMV6   17
1694
#define FF_IDCT_SIMPLEVIS     18
1695
#define FF_IDCT_WMV2          19
1696
#define FF_IDCT_FAAN          20
1697
#define FF_IDCT_EA            21
1698
#define FF_IDCT_SIMPLENEON    22
1699
#define FF_IDCT_SIMPLEALPHA   23
Kostya Shishkov's avatar
Kostya Shishkov committed
1700
#define FF_IDCT_BINK          24
1701

1702
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1703 1704 1705
     * slice count
     * - encoding: Set by libavcodec.
     * - decoding: Set by user (or 0).
1706 1707 1708
     */
    int slice_count;
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1709 1710 1711
     * slice offsets in the frame in bytes
     * - encoding: Set/allocated by libavcodec.
     * - decoding: Set/allocated by user (or NULL).
1712 1713 1714
     */
    int *slice_offset;

1715
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1716
     * error concealment flags
1717
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1718
     * - decoding: Set by user.
1719 1720 1721 1722 1723
     */
    int error_concealment;
#define FF_EC_GUESS_MVS   1
#define FF_EC_DEBLOCK     2

Zdenek Kabelac's avatar
Zdenek Kabelac committed
1724
    /**
1725
     * dsp_mask could be add used to disable unwanted CPU features
Zdenek Kabelac's avatar
Zdenek Kabelac committed
1726
     * CPU features (i.e. MMX, SSE. ...)
1727
     *
Diego Biurrun's avatar
Diego Biurrun committed
1728 1729 1730
     * 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.)
1731 1732
     */
    unsigned dsp_mask;
1733

Michael Niedermayer's avatar
Michael Niedermayer committed
1734
    /**
1735
     * bits per sample/pixel from the demuxer (needed for huffyuv).
Diego Biurrun's avatar
Diego Biurrun committed
1736 1737
     * - encoding: Set by libavcodec.
     * - decoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
1738
     */
1739
     int bits_per_coded_sample;
1740

Michael Niedermayer's avatar
Michael Niedermayer committed
1741
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1742 1743
     * prediction method (needed for huffyuv)
     * - encoding: Set by user.
1744
     * - decoding: unused
Michael Niedermayer's avatar
Michael Niedermayer committed
1745 1746 1747 1748 1749
     */
     int prediction_method;
#define FF_PRED_LEFT   0
#define FF_PRED_PLANE  1
#define FF_PRED_MEDIAN 2
1750

1751
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1752
     * sample aspect ratio (0 if unknown)
1753
     * That is the width of a pixel divided by the height of the pixel.
Diego Biurrun's avatar
Diego Biurrun committed
1754 1755 1756
     * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
1757
     */
Michael Niedermayer's avatar
Michael Niedermayer committed
1758
    AVRational sample_aspect_ratio;
Michael Niedermayer's avatar
Michael Niedermayer committed
1759 1760

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1761 1762 1763
     * the picture in the bitstream
     * - encoding: Set by libavcodec.
     * - decoding: Set by libavcodec.
Michael Niedermayer's avatar
Michael Niedermayer committed
1764
     */
1765
    AVFrame *coded_frame;
1766 1767

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1768 1769 1770
     * debug
     * - encoding: Set by user.
     * - decoding: Set by user.
1771 1772
     */
    int debug;
Diego Biurrun's avatar
Diego Biurrun committed
1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786
#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
1787
#define FF_DEBUG_VIS_MB_TYPE 0x00004000
1788
#define FF_DEBUG_BUFFERS     0x00008000
1789
#define FF_DEBUG_THREADS     0x00010000
1790

1791
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1792 1793 1794
     * debug
     * - encoding: Set by user.
     * - decoding: Set by user.
1795 1796 1797 1798 1799 1800
     */
    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

1801
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1802 1803
     * error
     * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR.
1804
     * - decoding: unused
1805 1806
     */
    uint64_t error[4];
1807

Michael Niedermayer's avatar
Michael Niedermayer committed
1808
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1809 1810
     * motion estimation comparison function
     * - encoding: Set by user.
1811
     * - decoding: unused
Michael Niedermayer's avatar
Michael Niedermayer committed
1812 1813 1814
     */
    int me_cmp;
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1815 1816
     * subpixel motion estimation comparison function
     * - encoding: Set by user.
1817
     * - decoding: unused
Michael Niedermayer's avatar
Michael Niedermayer committed
1818 1819 1820
     */
    int me_sub_cmp;
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1821 1822
     * macroblock comparison function (not supported yet)
     * - encoding: Set by user.
1823
     * - decoding: unused
Michael Niedermayer's avatar
Michael Niedermayer committed
1824 1825
     */
    int mb_cmp;
1826
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1827 1828
     * interlaced DCT comparison function
     * - encoding: Set by user.
1829 1830 1831
     * - decoding: unused
     */
    int ildct_cmp;
Diego Biurrun's avatar
Diego Biurrun committed
1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844
#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
1845
#define FF_CMP_DCTMAX 13
1846
#define FF_CMP_DCT264 14
Michael Niedermayer's avatar
Michael Niedermayer committed
1847
#define FF_CMP_CHROMA 256
1848

Michael Niedermayer's avatar
Michael Niedermayer committed
1849
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1850 1851
     * ME diamond size & shape
     * - encoding: Set by user.
1852
     * - decoding: unused
Michael Niedermayer's avatar
Michael Niedermayer committed
1853 1854
     */
    int dia_size;
1855 1856

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1857 1858
     * amount of previous MV predictors (2a+1 x 2a+1 square)
     * - encoding: Set by user.
1859
     * - decoding: unused
1860 1861
     */
    int last_predictor_count;
1862

1863
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1864 1865
     * prepass for motion estimation
     * - encoding: Set by user.
1866
     * - decoding: unused
1867 1868
     */
    int pre_me;
1869

1870
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1871 1872
     * motion estimation prepass comparison function
     * - encoding: Set by user.
1873
     * - decoding: unused
1874 1875
     */
    int me_pre_cmp;
Michael Niedermayer's avatar
Michael Niedermayer committed
1876

1877
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1878 1879
     * ME prepass diamond size & shape
     * - encoding: Set by user.
1880
     * - decoding: unused
1881 1882 1883
     */
    int pre_dia_size;

Michael Niedermayer's avatar
Michael Niedermayer committed
1884
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1885 1886
     * subpel ME quality
     * - encoding: Set by user.
1887
     * - decoding: unused
Michael Niedermayer's avatar
Michael Niedermayer committed
1888 1889 1890
     */
    int me_subpel_quality;

Michael Niedermayer's avatar
Michael Niedermayer committed
1891
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1892
     * callback to negotiate the pixelFormat
Michael Niedermayer's avatar
Michael Niedermayer committed
1893
     * @param fmt is the list of formats which are supported by the codec,
Diego Biurrun's avatar
Diego Biurrun committed
1894 1895 1896
     * 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
1897
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1898
     * - decoding: Set by user, if not set the native format will be chosen.
Michael Niedermayer's avatar
Michael Niedermayer committed
1899
     */
Ivan Kalvachev's avatar
Ivan Kalvachev committed
1900
    enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt);
1901 1902

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1903 1904 1905
     * DTG active format information (additional aspect ratio
     * information only used in DVB MPEG-2 transport streams)
     * 0 if not set.
1906
     *
Diego Biurrun's avatar
Diego Biurrun committed
1907 1908
     * - encoding: unused
     * - decoding: Set by decoder.
1909 1910 1911 1912 1913 1914 1915 1916 1917 1918
     */
    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

1919
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1920 1921
     * maximum motion estimation search range in subpel units
     * If 0 then no limit.
1922
     *
Diego Biurrun's avatar
Diego Biurrun committed
1923 1924
     * - encoding: Set by user.
     * - decoding: unused
1925
     */
Zdenek Kabelac's avatar
Zdenek Kabelac committed
1926
    int me_range;
1927

1928
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1929 1930
     * intra quantizer bias
     * - encoding: Set by user.
1931 1932 1933 1934
     * - decoding: unused
     */
    int intra_quant_bias;
#define FF_DEFAULT_QUANT_BIAS 999999
1935

1936
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1937 1938
     * inter quantizer bias
     * - encoding: Set by user.
1939 1940 1941
     * - decoding: unused
     */
    int inter_quant_bias;
1942 1943

    /**
Diego Biurrun's avatar
Diego Biurrun committed
1944 1945 1946 1947
     * color table ID
     * - encoding: unused
     * - decoding: Which clrtable should be used for 8bit RGB images.
     *             Tables have to be stored somewhere. FIXME
1948 1949
     */
    int color_table_id;
1950

1951
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1952 1953
     * internal_buffer count
     * Don't touch, used by libavcodec default_get_buffer().
1954 1955
     */
    int internal_buffer_count;
1956

1957
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1958 1959
     * internal_buffers
     * Don't touch, used by libavcodec default_get_buffer().
1960 1961
     */
    void *internal_buffer;
1962

Michael Niedermayer's avatar
Michael Niedermayer committed
1963
    /**
Diego Biurrun's avatar
Diego Biurrun committed
1964 1965 1966
     * 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
1967 1968 1969
     * - decoding: unused
     */
    int global_quality;
1970

Michael Niedermayer's avatar
Michael Niedermayer committed
1971 1972
#define FF_CODER_TYPE_VLC       0
#define FF_CODER_TYPE_AC        1
1973 1974 1975
#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
1976 1977
    /**
     * coder type
Diego Biurrun's avatar
Diego Biurrun committed
1978
     * - encoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
1979 1980 1981 1982 1983 1984
     * - decoding: unused
     */
    int coder_type;

    /**
     * context model
Diego Biurrun's avatar
Diego Biurrun committed
1985
     * - encoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
1986 1987 1988
     * - decoding: unused
     */
    int context_model;
1989 1990 1991 1992
#if 0
    /**
     *
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
1993
     * - decoding: Set by user.
1994 1995 1996
     */
    uint8_t * (*realloc)(struct AVCodecContext *s, uint8_t *buf, int buf_size);
#endif
1997

1998 1999 2000
    /**
     * slice flags
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2001
     * - decoding: Set by user.
2002 2003 2004 2005 2006 2007
     */
    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
2008 2009 2010 2011 2012 2013
    /**
     * XVideo Motion Acceleration
     * - encoding: forbidden
     * - decoding: set by decoder
     */
    int xvmc_acceleration;
2014

2015 2016
    /**
     * macroblock decision mode
Diego Biurrun's avatar
Diego Biurrun committed
2017
     * - encoding: Set by user.
2018 2019 2020 2021 2022
     * - 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
2023
#define FF_MB_DECISION_RD     2        ///< rate distortion
2024 2025 2026

    /**
     * custom intra quantization matrix
Diego Biurrun's avatar
Diego Biurrun committed
2027 2028
     * - encoding: Set by user, can be NULL.
     * - decoding: Set by libavcodec.
2029 2030 2031 2032 2033
     */
    uint16_t *intra_matrix;

    /**
     * custom inter quantization matrix
Diego Biurrun's avatar
Diego Biurrun committed
2034 2035
     * - encoding: Set by user, can be NULL.
     * - decoding: Set by libavcodec.
2036 2037
     */
    uint16_t *inter_matrix;
2038

2039 2040
    /**
     * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Diego Biurrun's avatar
Diego Biurrun committed
2041
     * This is used to work around some encoder bugs.
2042
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2043
     * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
2044 2045
     */
    unsigned int stream_codec_tag;
2046 2047

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2048 2049 2050
     * scene change detection threshold
     * 0 is default, larger means fewer detected scene changes.
     * - encoding: Set by user.
2051 2052 2053
     * - decoding: unused
     */
    int scenechange_threshold;
2054 2055

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2056 2057
     * minimum Lagrange multipler
     * - encoding: Set by user.
2058 2059 2060 2061 2062
     * - decoding: unused
     */
    int lmin;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2063 2064
     * maximum Lagrange multipler
     * - encoding: Set by user.
2065 2066 2067
     * - decoding: unused
     */
    int lmax;
2068

2069
#if FF_API_PALETTE_CONTROL
2070
    /**
Diego Biurrun's avatar
Diego Biurrun committed
2071
     * palette control structure
2072
     * - encoding: ??? (no palette-enabled encoder yet)
Diego Biurrun's avatar
Diego Biurrun committed
2073
     * - decoding: Set by user.
2074 2075
     */
    struct AVPaletteControl *palctrl;
2076
#endif
2077 2078 2079

    /**
     * noise reduction strength
Diego Biurrun's avatar
Diego Biurrun committed
2080
     * - encoding: Set by user.
2081 2082 2083
     * - decoding: unused
     */
    int noise_reduction;
2084

2085
    /**
Diego Biurrun's avatar
Diego Biurrun committed
2086 2087 2088
     * 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
2089
     * same buffer or new buffer with old frame "painted" into it.
Diego Biurrun's avatar
Diego Biurrun committed
2090
     * If pic.data[0] == NULL must behave like get_buffer().
2091 2092 2093
     * 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.
2094
     * - encoding: unused
2095
     * - decoding: Set by libavcodec, user can override.
2096
     */
2097
    int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
2098 2099

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2100 2101
     * Number of bits which should be loaded into the rc buffer before decoding starts.
     * - encoding: Set by user.
2102 2103 2104 2105 2106 2107
     * - decoding: unused
     */
    int rc_initial_buffer_occupancy;

    /**
     *
Diego Biurrun's avatar
Diego Biurrun committed
2108
     * - encoding: Set by user.
2109 2110 2111 2112 2113
     * - decoding: unused
     */
    int inter_threshold;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2114 2115 2116
     * CODEC_FLAG2_*
     * - encoding: Set by user.
     * - decoding: Set by user.
2117 2118
     */
    int flags2;
2119 2120

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2121 2122 2123
     * Simulates errors in the bitstream to test error concealment.
     * - encoding: Set by user.
     * - decoding: unused
2124 2125
     */
    int error_rate;
2126

2127
#if FF_API_ANTIALIAS_ALGO
2128 2129 2130
    /**
     * MP3 antialias algorithm, see FF_AA_* below.
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2131
     * - decoding: Set by user.
2132
     */
2133
    attribute_deprecated int antialias_algo;
2134 2135 2136 2137
#define FF_AA_AUTO    0
#define FF_AA_FASTINT 1 //not implemented yet
#define FF_AA_INT     2
#define FF_AA_FLOAT   3
2138 2139
#endif

2140
    /**
Diego Biurrun's avatar
Diego Biurrun committed
2141 2142
     * quantizer noise shaping
     * - encoding: Set by user.
2143 2144 2145
     * - decoding: unused
     */
    int quantizer_noise_shaping;
2146 2147

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2148
     * thread count
2149
     * is used to decide how many independent tasks should be passed to execute()
Diego Biurrun's avatar
Diego Biurrun committed
2150 2151
     * - encoding: Set by user.
     * - decoding: Set by user.
2152 2153
     */
    int thread_count;
2154

2155
    /**
Diego Biurrun's avatar
Diego Biurrun committed
2156 2157 2158 2159
     * 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.
2160
     * @param count the number of things to execute
Diego Biurrun's avatar
Diego Biurrun committed
2161 2162
     * - encoding: Set by libavcodec, user can override.
     * - decoding: Set by libavcodec, user can override.
2163
     */
2164
    int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
2165

2166
    /**
Diego Biurrun's avatar
Diego Biurrun committed
2167 2168
     * thread opaque
     * Can be used by execute() to store some per AVCodecContext stuff.
2169 2170 2171 2172
     * - encoding: set by execute()
     * - decoding: set by execute()
     */
    void *thread_opaque;
2173 2174

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2175 2176
     * Motion estimation threshold below which no motion estimation is
     * performed, but instead the user specified motion vectors are used.
2177
     *
Diego Biurrun's avatar
Diego Biurrun committed
2178
     * - encoding: Set by user.
2179
     * - decoding: unused
2180
     */
2181
     int me_threshold;
2182 2183

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2184 2185
     * Macroblock threshold below which the user specified macroblock types will be used.
     * - encoding: Set by user.
2186 2187 2188
     * - decoding: unused
     */
     int mb_threshold;
2189 2190

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2191 2192
     * precision of the intra DC coefficient - 8
     * - encoding: Set by user.
2193 2194 2195
     * - decoding: unused
     */
     int intra_dc_precision;
Michael Niedermayer's avatar
Michael Niedermayer committed
2196 2197

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2198 2199
     * noise vs. sse weight for the nsse comparsion function
     * - encoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
2200 2201 2202
     * - decoding: unused
     */
     int nsse_weight;
2203 2204

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2205
     * Number of macroblock rows at the top which are skipped.
2206
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2207
     * - decoding: Set by user.
2208 2209 2210 2211
     */
     int skip_top;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2212
     * Number of macroblock rows at the bottom which are skipped.
2213
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2214
     * - decoding: Set by user.
2215 2216
     */
     int skip_bottom;
2217 2218 2219

    /**
     * profile
Diego Biurrun's avatar
Diego Biurrun committed
2220 2221
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
2222 2223 2224
     */
     int profile;
#define FF_PROFILE_UNKNOWN -99
2225
#define FF_PROFILE_RESERVED -100
2226

2227
#define FF_PROFILE_AAC_MAIN 0
Diego Biurrun's avatar
Diego Biurrun committed
2228 2229 2230
#define FF_PROFILE_AAC_LOW  1
#define FF_PROFILE_AAC_SSR  2
#define FF_PROFILE_AAC_LTP  3
2231

2232 2233 2234 2235 2236 2237
#define FF_PROFILE_DTS         20
#define FF_PROFILE_DTS_ES      30
#define FF_PROFILE_DTS_96_24   40
#define FF_PROFILE_DTS_HD_HRA  50
#define FF_PROFILE_DTS_HD_MA   60

2238 2239 2240 2241 2242 2243 2244
#define FF_PROFILE_MPEG2_422    0
#define FF_PROFILE_MPEG2_HIGH   1
#define FF_PROFILE_MPEG2_SS     2
#define FF_PROFILE_MPEG2_SNR_SCALABLE  3
#define FF_PROFILE_MPEG2_MAIN   4
#define FF_PROFILE_MPEG2_SIMPLE 5

2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256
#define FF_PROFILE_H264_CONSTRAINED  (1<<9)  // 8+1; constraint_set1_flag
#define FF_PROFILE_H264_INTRA        (1<<11) // 8+3; constraint_set3_flag

#define FF_PROFILE_H264_BASELINE             66
#define FF_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
#define FF_PROFILE_H264_MAIN                 77
#define FF_PROFILE_H264_EXTENDED             88
#define FF_PROFILE_H264_HIGH                 100
#define FF_PROFILE_H264_HIGH_10              110
#define FF_PROFILE_H264_HIGH_10_INTRA        (110|FF_PROFILE_H264_INTRA)
#define FF_PROFILE_H264_HIGH_422             122
#define FF_PROFILE_H264_HIGH_422_INTRA       (122|FF_PROFILE_H264_INTRA)
2257
#define FF_PROFILE_H264_HIGH_444             144
2258 2259 2260
#define FF_PROFILE_H264_HIGH_444_PREDICTIVE  244
#define FF_PROFILE_H264_HIGH_444_INTRA       (244|FF_PROFILE_H264_INTRA)
#define FF_PROFILE_H264_CAVLC_444            44
2261

2262 2263 2264 2265 2266
#define FF_PROFILE_VC1_SIMPLE   0
#define FF_PROFILE_VC1_MAIN     1
#define FF_PROFILE_VC1_COMPLEX  2
#define FF_PROFILE_VC1_ADVANCED 3

2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283
#define FF_PROFILE_MPEG4_SIMPLE                     0
#define FF_PROFILE_MPEG4_SIMPLE_SCALABLE            1
#define FF_PROFILE_MPEG4_CORE                       2
#define FF_PROFILE_MPEG4_MAIN                       3
#define FF_PROFILE_MPEG4_N_BIT                      4
#define FF_PROFILE_MPEG4_SCALABLE_TEXTURE           5
#define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION      6
#define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE     7
#define FF_PROFILE_MPEG4_HYBRID                     8
#define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME         9
#define FF_PROFILE_MPEG4_CORE_SCALABLE             10
#define FF_PROFILE_MPEG4_ADVANCED_CODING           11
#define FF_PROFILE_MPEG4_ADVANCED_CORE             12
#define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
#define FF_PROFILE_MPEG4_SIMPLE_STUDIO             14
#define FF_PROFILE_MPEG4_ADVANCED_SIMPLE           15

2284 2285
    /**
     * level
Diego Biurrun's avatar
Diego Biurrun committed
2286 2287
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
2288 2289 2290
     */
     int level;
#define FF_LEVEL_UNKNOWN -99
2291 2292

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2293
     * low resolution decoding, 1-> 1/2 size, 2->1/4 size
2294
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2295
     * - decoding: Set by user.
2296 2297
     */
     int lowres;
2298 2299

    /**
2300
     * Bitstream width / height, may be different from width/height if lowres enabled.
2301
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2302
     * - decoding: Set by user before init if known. Codec should override / dynamically change if needed.
2303 2304
     */
    int coded_width, coded_height;
Michael Niedermayer's avatar
Michael Niedermayer committed
2305 2306 2307

    /**
     * frame skip threshold
Diego Biurrun's avatar
Diego Biurrun committed
2308
     * - encoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
2309 2310 2311 2312 2313 2314
     * - decoding: unused
     */
    int frame_skip_threshold;

    /**
     * frame skip factor
Diego Biurrun's avatar
Diego Biurrun committed
2315
     * - encoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
2316 2317 2318
     * - decoding: unused
     */
    int frame_skip_factor;
2319 2320 2321

    /**
     * frame skip exponent
Diego Biurrun's avatar
Diego Biurrun committed
2322
     * - encoding: Set by user.
2323 2324 2325 2326 2327
     * - decoding: unused
     */
    int frame_skip_exp;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2328 2329
     * frame skip comparison function
     * - encoding: Set by user.
2330 2331 2332
     * - decoding: unused
     */
    int frame_skip_cmp;
2333 2334

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2335
     * Border processing masking, raises the quantizer for mbs on the borders
2336
     * of the picture.
Diego Biurrun's avatar
Diego Biurrun committed
2337
     * - encoding: Set by user.
2338 2339 2340
     * - decoding: unused
     */
    float border_masking;
2341 2342

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2343 2344
     * minimum MB lagrange multipler
     * - encoding: Set by user.
2345 2346 2347 2348 2349
     * - decoding: unused
     */
    int mb_lmin;

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2350 2351
     * maximum MB lagrange multipler
     * - encoding: Set by user.
2352 2353 2354
     * - decoding: unused
     */
    int mb_lmax;
2355 2356

    /**
2357
     *
Diego Biurrun's avatar
Diego Biurrun committed
2358
     * - encoding: Set by user.
2359 2360 2361
     * - decoding: unused
     */
    int me_penalty_compensation;
Michael Niedermayer's avatar
Michael Niedermayer committed
2362 2363

    /**
2364
     *
Michael Niedermayer's avatar
Michael Niedermayer committed
2365
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2366
     * - decoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
2367 2368 2369 2370
     */
    enum AVDiscard skip_loop_filter;

    /**
2371
     *
Michael Niedermayer's avatar
Michael Niedermayer committed
2372
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2373
     * - decoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
2374 2375 2376 2377
     */
    enum AVDiscard skip_idct;

    /**
2378
     *
Michael Niedermayer's avatar
Michael Niedermayer committed
2379
     * - encoding: unused
Diego Biurrun's avatar
Diego Biurrun committed
2380
     * - decoding: Set by user.
Michael Niedermayer's avatar
Michael Niedermayer committed
2381 2382
     */
    enum AVDiscard skip_frame;
2383 2384 2385

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

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

2398
#if FF_API_X264_GLOBAL_OPTS
Robert Swain's avatar
Robert Swain committed
2399 2400
    /**
     * constant rate factor - quality-based VBR - values ~correspond to qps
Diego Biurrun's avatar
Diego Biurrun committed
2401
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2402
     * - decoding: unused
2403
     *   @deprecated use 'crf' libx264 private option
Robert Swain's avatar
Robert Swain committed
2404
     */
2405
    attribute_deprecated float crf;
Robert Swain's avatar
Robert Swain committed
2406 2407 2408

    /**
     * constant quantization parameter rate control method
Diego Biurrun's avatar
Diego Biurrun committed
2409
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2410
     * - decoding: unused
2411
     *   @deprecated use 'cqp' libx264 private option
Robert Swain's avatar
Robert Swain committed
2412
     */
2413 2414
    attribute_deprecated int cqp;
#endif
Robert Swain's avatar
Robert Swain committed
2415 2416

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2417 2418
     * minimum GOP size
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2419 2420 2421 2422 2423 2424
     * - decoding: unused
     */
    int keyint_min;

    /**
     * number of reference frames
Diego Biurrun's avatar
Diego Biurrun committed
2425
     * - encoding: Set by user.
2426
     * - decoding: Set by lavc.
Robert Swain's avatar
Robert Swain committed
2427 2428 2429 2430 2431
     */
    int refs;

    /**
     * chroma qp offset from luma
Diego Biurrun's avatar
Diego Biurrun committed
2432
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2433 2434 2435 2436
     * - decoding: unused
     */
    int chromaoffset;

2437
#if FF_API_X264_GLOBAL_OPTS
Robert Swain's avatar
Robert Swain committed
2438
    /**
Diego Biurrun's avatar
Diego Biurrun committed
2439 2440
     * Influences how often B-frames are used.
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2441 2442
     * - decoding: unused
     */
2443 2444
    attribute_deprecated int bframebias;
#endif
Robert Swain's avatar
Robert Swain committed
2445 2446 2447

    /**
     * trellis RD quantization
Diego Biurrun's avatar
Diego Biurrun committed
2448
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2449 2450 2451 2452
     * - decoding: unused
     */
    int trellis;

2453
#if FF_API_X264_GLOBAL_OPTS
Robert Swain's avatar
Robert Swain committed
2454
    /**
Diego Biurrun's avatar
Diego Biurrun committed
2455 2456
     * Reduce fluctuations in qp (before curve compression).
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2457 2458
     * - decoding: unused
     */
2459
    attribute_deprecated float complexityblur;
Robert Swain's avatar
Robert Swain committed
2460 2461 2462 2463

    /**
     * in-loop deblocking filter alphac0 parameter
     * alpha is in the range -6...6
Diego Biurrun's avatar
Diego Biurrun committed
2464
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2465 2466
     * - decoding: unused
     */
2467
    attribute_deprecated int deblockalpha;
Robert Swain's avatar
Robert Swain committed
2468 2469 2470 2471

    /**
     * in-loop deblocking filter beta parameter
     * beta is in the range -6...6
Diego Biurrun's avatar
Diego Biurrun committed
2472
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2473 2474
     * - decoding: unused
     */
2475
    attribute_deprecated int deblockbeta;
Robert Swain's avatar
Robert Swain committed
2476 2477 2478

    /**
     * macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4
Diego Biurrun's avatar
Diego Biurrun committed
2479
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2480 2481
     * - decoding: unused
     */
2482
    attribute_deprecated int partitions;
2483 2484 2485 2486 2487
#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
2488 2489

    /**
2490
     * direct MV prediction mode - 0 (none), 1 (spatial), 2 (temporal), 3 (auto)
Diego Biurrun's avatar
Diego Biurrun committed
2491
     * - encoding: Set by user.
Robert Swain's avatar
Robert Swain committed
2492 2493
     * - decoding: unused
     */
2494 2495
    attribute_deprecated int directpred;
#endif
2496

2497
    /**
2498
     * Audio cutoff bandwidth (0 means "automatic")
Diego Biurrun's avatar
Diego Biurrun committed
2499
     * - encoding: Set by user.
2500 2501 2502
     * - decoding: unused
     */
    int cutoff;
2503 2504

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2505 2506
     * Multiplied by qscale for each frame and added to scene_change_score.
     * - encoding: Set by user.
2507 2508 2509
     * - decoding: unused
     */
    int scenechange_factor;
2510 2511 2512

    /**
     *
Diego Biurrun's avatar
Diego Biurrun committed
2513 2514
     * Note: Value depends upon the compare function used for fullpel ME.
     * - encoding: Set by user.
2515 2516 2517
     * - decoding: unused
     */
    int mv0_threshold;
2518 2519

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2520 2521
     * Adjusts sensitivity of b_frame_strategy 1.
     * - encoding: Set by user.
2522 2523 2524
     * - decoding: unused
     */
    int b_sensitivity;
2525 2526

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2527
     * - encoding: Set by user.
2528 2529 2530 2531 2532 2533
     * - decoding: unused
     */
    int compression_level;
#define FF_COMPRESSION_DEFAULT -1

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2534 2535
     * - encoding: Set by user.
     * - decoding: unused
2536
     */
2537
    int min_prediction_order;
2538 2539

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2540 2541
     * - encoding: Set by user.
     * - decoding: unused
2542
     */
2543 2544 2545 2546
    int max_prediction_order;

#if FF_API_FLAC_GLOBAL_OPTS
    /**
2547
     * @name FLAC options
2548 2549 2550
     * @deprecated Use FLAC encoder private options instead.
     * @{
     */
2551 2552

    /**
2553
     * LPC coefficient precision - used by FLAC encoder
Diego Biurrun's avatar
Diego Biurrun committed
2554 2555
     * - encoding: Set by user.
     * - decoding: unused
2556
     */
2557
    attribute_deprecated int lpc_coeff_precision;
2558 2559 2560

    /**
     * search method for selecting prediction order
Diego Biurrun's avatar
Diego Biurrun committed
2561 2562
     * - encoding: Set by user.
     * - decoding: unused
2563
     */
2564
    attribute_deprecated int prediction_order_method;
2565 2566

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2567 2568
     * - encoding: Set by user.
     * - decoding: unused
2569
     */
2570
    attribute_deprecated int min_partition_order;
2571 2572

    /**
Diego Biurrun's avatar
Diego Biurrun committed
2573 2574
     * - encoding: Set by user.
     * - decoding: unused
2575
     */
2576 2577 2578 2579 2580
    attribute_deprecated int max_partition_order;
    /**
     * @}
     */
#endif
2581 2582 2583

    /**
     * GOP timecode frame start number, in non drop frame format
Diego Biurrun's avatar
Diego Biurrun committed
2584 2585
     * - encoding: Set by user.
     * - decoding: unused
2586 2587
     */
    int64_t timecode_frame_start;
2588

2589
#if FF_API_REQUEST_CHANNELS
2590
    /**
2591 2592 2593
     * Decoder should decode to this many channels if it can (0 for default)
     * - encoding: unused
     * - decoding: Set by user.
2594
     * @deprecated Deprecated in favor of request_channel_layout.
2595 2596
     */
    int request_channels;
2597
#endif
2598

2599
#if FF_API_DRC_SCALE
2600 2601 2602 2603 2604
    /**
     * 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.
2605
     * @deprecated use AC3 decoder private option instead.
2606
     */
2607 2608
    attribute_deprecated float drc_scale;
#endif
2609 2610 2611 2612

    /**
     * opaque 64bit number (generally a PTS) that will be reordered and
     * output in AVFrame.reordered_opaque
2613
     * @deprecated in favor of pkt_pts
2614 2615 2616 2617
     * - encoding: unused
     * - decoding: Set by user.
     */
    int64_t reordered_opaque;
2618 2619 2620 2621 2622 2623 2624

    /**
     * Bits per sample/pixel of internal libavcodec pixel/sample format.
     * - encoding: set by user.
     * - decoding: set by libavcodec.
     */
    int bits_per_raw_sample;
2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638

    /**
     * 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;
2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652

    /**
     * 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;
2653 2654 2655 2656 2657 2658 2659

    /**
     * Hardware accelerator in use
     * - encoding: unused.
     * - decoding: Set by libavcodec
     */
    struct AVHWAccel *hwaccel;
2660 2661 2662 2663 2664 2665 2666 2667 2668

    /**
     * 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;
2669 2670 2671 2672 2673

    /**
     * Hardware accelerator context.
     * For some hardware accelerators, a global context needs to be
     * provided by the user. In that case, this holds display-dependent
2674 2675
     * data Libav cannot instantiate itself. Please refer to the
     * Libav HW accelerator documentation to know how to fill this
2676 2677 2678 2679 2680
     * is. e.g. for VA API, this is a struct vaapi_context.
     * - encoding: unused
     * - decoding: Set by user
     */
    void *hwaccel_context;
2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708

    /**
     * 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;
2709 2710 2711 2712 2713 2714

    /**
     * This defines the location of chroma samples.
     * - encoding: Set by user
     * - decoding: Set by libavcodec
     */
2715
    enum AVChromaLocation chroma_sample_location;
2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735

    /**
     * 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.
     * Also see avcodec_thread_init and e.g. the --enable-pthread configure option.
     * @param c context passed also to func
     * @param count the number of things to execute
     * @param arg2 argument passed unchanged to func
     * @param ret return values of executed functions, must have space for "count" values. May be NULL.
     * @param func function that will be called count times, with jobnr from 0 to count-1.
     *             threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no
     *             two instances of func executing at the same time will have the same threadnr.
     * @return always 0 currently, but code should handle a future improvement where when any call to func
     *         returns < 0 no further calls to func may be done and < 0 is returned.
     * - encoding: Set by libavcodec, user can override.
     * - decoding: Set by libavcodec, user can override.
     */
    int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count);
2736

2737
#if FF_API_X264_GLOBAL_OPTS
2738 2739 2740 2741 2742 2743 2744 2745
    /**
     * explicit P-frame weighted prediction analysis method
     * 0: off
     * 1: fast blind weighting (one reference duplicate with -1 offset)
     * 2: smart weighting (full fade detection analysis)
     * - encoding: Set by user.
     * - decoding: unused
     */
2746
    attribute_deprecated int weighted_p_pred;
2747 2748 2749 2750 2751 2752 2753 2754 2755

    /**
     * AQ mode
     * 0: Disabled
     * 1: Variance AQ (complexity mask)
     * 2: Auto-variance AQ (experimental)
     * - encoding: Set by user
     * - decoding: unused
     */
2756
    attribute_deprecated int aq_mode;
2757 2758 2759 2760 2761 2762 2763

    /**
     * AQ strength
     * Reduces blocking and blurring in flat and textured areas.
     * - encoding: Set by user
     * - decoding: unused
     */
2764
    attribute_deprecated float aq_strength;
2765 2766 2767 2768 2769 2770 2771

    /**
     * PSY RD
     * Strength of psychovisual optimization
     * - encoding: Set by user
     * - decoding: unused
     */
2772
    attribute_deprecated float psy_rd;
2773 2774 2775 2776 2777 2778 2779

    /**
     * PSY trellis
     * Strength of psychovisual optimization
     * - encoding: Set by user
     * - decoding: unused
     */
2780
    attribute_deprecated float psy_trellis;
2781 2782 2783 2784 2785 2786 2787

    /**
     * RC lookahead
     * Number of frames for frametype and ratecontrol lookahead
     * - encoding: Set by user
     * - decoding: unused
     */
2788
    attribute_deprecated int rc_lookahead;
2789 2790 2791 2792 2793 2794 2795 2796

    /**
     * Constant rate factor maximum
     * With CRF encoding mode and VBV restrictions enabled, prevents quality from being worse
     * than crf_max, even if doing so would violate VBV restrictions.
     * - encoding: Set by user.
     * - decoding: unused
     */
2797 2798
    attribute_deprecated float crf_max;
#endif
2799 2800

    int log_level_offset;
2801

2802
#if FF_API_FLAC_GLOBAL_OPTS
2803 2804 2805 2806 2807
    /**
     * Determines which LPC analysis algorithm to use.
     * - encoding: Set by user
     * - decoding: unused
     */
2808
    attribute_deprecated enum AVLPCType lpc_type;
2809 2810 2811 2812 2813 2814

    /**
     * Number of passes to use for Cholesky factorization during LPC analysis
     * - encoding: Set by user
     * - decoding: unused
     */
2815 2816
    attribute_deprecated int lpc_passes;
#endif
2817 2818 2819 2820 2821 2822 2823 2824 2825

    /**
     * Number of slices.
     * Indicates number of picture subdivisions. Used for parallelized
     * decoding.
     * - encoding: Set by user
     * - decoding: unused
     */
    int slices;
2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836

    /**
     * Header containing style information for text subtitles.
     * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
     * [Script Info] and [V4+ Styles] section, plus the [Events] line and
     * the Format line following. It shouldn't include any Dialogue line.
     * - encoding: Set/allocated/freed by user (before avcodec_open())
     * - decoding: Set/allocated/freed by libavcodec (by avcodec_open())
     */
    uint8_t *subtitle_header;
    int subtitle_header_size;
2837 2838 2839 2840 2841 2842 2843 2844 2845

    /**
     * Current packet as passed into the decoder, to avoid having
     * to pass the packet into every function. Currently only valid
     * inside lavc and get/release_buffer callbacks.
     * - decoding: set by avcodec_decode_*, read by get_buffer() for setting pkt_pts
     * - encoding: unused
     */
    AVPacket *pkt;
2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864

    /**
     * Whether this is a copy of the context which had init() called on it.
     * This is used by multithreading - shared tables and picture pointers
     * should be freed from the original context only.
     * - encoding: Set by libavcodec.
     * - decoding: Set by libavcodec.
     */
    int is_copy;

    /**
     * Which multithreading methods to use.
     * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread,
     * so clients which cannot provide future frames should not use it.
     *
     * - encoding: Set by user, otherwise the default is used.
     * - decoding: Set by user, otherwise the default is used.
     */
    int thread_type;
2865 2866
#define FF_THREAD_FRAME   1 ///< Decode more than one frame at once
#define FF_THREAD_SLICE   2 ///< Decode more than one part of a single frame at once
2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883

    /**
     * Which multithreading methods are in use by the codec.
     * - encoding: Set by libavcodec.
     * - decoding: Set by libavcodec.
     */
    int active_thread_type;

    /**
     * Set by the client if its custom get_buffer() callback can be called
     * from another thread, which allows faster multithreaded decoding.
     * draw_horiz_band() will be called from other threads regardless of this setting.
     * Ignored if the default get_buffer() is used.
     * - encoding: Set by user.
     * - decoding: Set by user.
     */
    int thread_safe_callbacks;
2884 2885 2886 2887 2888 2889 2890 2891

    /**
     * VBV delay coded in the last frame (in periods of a 27 MHz clock).
     * Used for compliant TS muxing.
     * - encoding: Set by libavcodec.
     * - decoding: unused.
     */
    uint64_t vbv_delay;
2892 2893 2894 2895 2896 2897 2898

    /**
     * Type of service that the audio stream conveys.
     * - encoding: Set by user.
     * - decoding: Set by libavcodec.
     */
    enum AVAudioServiceType audio_service_type;
2899 2900 2901 2902 2903 2904 2905

    /**
     * Used to request a sample format from the decoder.
     * - encoding: unused.
     * - decoding: Set by user.
     */
    enum AVSampleFormat request_sample_fmt;
Fabrice Bellard's avatar
Fabrice Bellard committed
2906 2907
} AVCodecContext;

2908 2909 2910 2911 2912 2913 2914 2915
/**
 * AVProfile.
 */
typedef struct AVProfile {
    int profile;
    const char *name; ///< short name for the profile
} AVProfile;

2916 2917
typedef struct AVCodecDefault AVCodecDefault;

2918 2919 2920
/**
 * AVCodec.
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
2921
typedef struct AVCodec {
2922 2923 2924 2925 2926 2927
    /**
     * 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.
     */
2928
    const char *name;
2929
    enum AVMediaType type;
Michael Niedermayer's avatar
Michael Niedermayer committed
2930
    enum CodecID id;
Fabrice Bellard's avatar
Fabrice Bellard committed
2931 2932
    int priv_data_size;
    int (*init)(AVCodecContext *);
2933
    int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
Fabrice Bellard's avatar
Fabrice Bellard committed
2934
    int (*close)(AVCodecContext *);
2935
    int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
2936 2937 2938 2939
    /**
     * Codec capabilities.
     * see CODEC_CAP_*
     */
2940
    int capabilities;
Fabrice Bellard's avatar
Fabrice Bellard committed
2941
    struct AVCodec *next;
2942 2943 2944 2945
    /**
     * Flush buffers.
     * Will be called when seeking
     */
Michael Niedermayer's avatar
Michael Niedermayer committed
2946
    void (*flush)(AVCodecContext *);
2947
    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
2948
    const enum PixelFormat *pix_fmts;       ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
2949
    /**
2950 2951
     * 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.
2952 2953
     */
    const char *long_name;
2954
    const int *supported_samplerates;       ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
2955
    const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
2956
    const int64_t *channel_layouts;         ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
2957
    uint8_t max_lowres;                     ///< maximum value for lowres supported by the decoder
2958
    const AVClass *priv_class;              ///< AVClass for the private context
2959
    const AVProfile *profiles;              ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
2960 2961

    /**
2962
     * @name Frame-level threading support functions
2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979
     * @{
     */
    /**
     * If defined, called on thread contexts when they are created.
     * If the codec allocates writable tables in init(), re-allocate them here.
     * priv_data will be set to a copy of the original.
     */
    int (*init_thread_copy)(AVCodecContext *);
    /**
     * Copy necessary context variables from a previous thread context to the current one.
     * If not defined, the next thread will start automatically; otherwise, the codec
     * must call ff_thread_finish_setup().
     *
     * dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
     */
    int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
    /** @} */
2980 2981 2982 2983 2984

    /**
     * Private codec-specific defaults.
     */
    const AVCodecDefault *defaults;
Fabrice Bellard's avatar
Fabrice Bellard committed
2985 2986
} AVCodec;

2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000
/**
 * 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.
     *
3001
     * See AVMEDIA_TYPE_xxx
3002
     */
3003
    enum AVMediaType type;
3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032

    /**
     * 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.
     *
3033
     * Note that buf can be NULL along with buf_size set to 0.
3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065
     * 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);
3066 3067 3068 3069

    /**
     * Size of HW accelerator private data.
     *
3070 3071 3072
     * Private data is allocated with av_mallocz() before
     * AVCodecContext.get_buffer() and deallocated after
     * AVCodecContext.release_buffer().
3073 3074
     */
    int priv_data_size;
3075 3076
} AVHWAccel;

3077
/**
3078 3079 3080
 * four components are given, that's all.
 * the last component is alpha
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
3081
typedef struct AVPicture {
3082
    uint8_t *data[4];
Michael Niedermayer's avatar
Michael Niedermayer committed
3083
    int linesize[4];       ///< number of bytes per line
Fabrice Bellard's avatar
Fabrice Bellard committed
3084 3085
} AVPicture;

3086 3087
#define AVPALETTE_SIZE 1024
#define AVPALETTE_COUNT 256
3088
#if FF_API_PALETTE_CONTROL
3089
/**
3090 3091 3092 3093
 * AVPaletteControl
 * This structure defines a method for communicating palette changes
 * between and demuxer and a decoder.
 *
3094
 * @deprecated Use AVPacket to send palette changes instead.
3095
 * This is totally broken.
3096 3097 3098
 */
typedef struct AVPaletteControl {

Diego Biurrun's avatar
Diego Biurrun committed
3099 3100
    /* Demuxer sets this to 1 to indicate the palette has changed;
     * decoder resets to 0. */
3101 3102
    int palette_changed;

3103 3104
    /* 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
3105 3106
     * the palette data comes from an IBM VGA native format, the component
     * data is probably 6 bits in size and needs to be scaled. */
3107
    unsigned int palette[AVPALETTE_COUNT];
3108

3109
} AVPaletteControl attribute_deprecated;
3110
#endif
3111

3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129
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,
};

3130
typedef struct AVSubtitleRect {
3131 3132 3133 3134 3135
    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
3136 3137 3138 3139 3140 3141

    /**
     * data+linesize for the bitmap of this subtitle.
     * can be set for text/ass as well once they where rendered
     */
    AVPicture pict;
3142 3143 3144 3145 3146 3147 3148 3149 3150 3151
    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;
3152 3153 3154 3155 3156 3157
} 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 */
3158
    unsigned num_rects;
3159
    AVSubtitleRect **rects;
3160
    int64_t pts;    ///< Same as packet pts, in AV_TIME_BASE
3161 3162
} AVSubtitle;

3163 3164
/* packet functions */

3165 3166 3167 3168
/**
 * @deprecated use NULL instead
 */
attribute_deprecated void av_destruct_packet_nofree(AVPacket *pkt);
3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191

/**
 * 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);

3192 3193 3194 3195 3196 3197 3198 3199
/**
 * Reduce packet size, correctly zeroing padding
 *
 * @param pkt packet
 * @param size new size
 */
void av_shrink_packet(AVPacket *pkt, int size);

3200 3201 3202 3203 3204 3205 3206 3207
/**
 * Increase packet size, correctly zeroing padding
 *
 * @param pkt packet
 * @param grow_by number of bytes by which to increase the size of the packet
 */
int av_grow_packet(AVPacket *pkt, int grow_by);

3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218
/**
 * @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
3219
void av_free_packet(AVPacket *pkt);
3220

3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242
/**
 * Allocate new information of a packet.
 *
 * @param pkt packet
 * @param type side information type
 * @param size side information size
 * @return pointer to fresh allocated data or NULL otherwise
 */
uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
                                 int size);

/**
 * Get side information from packet.
 *
 * @param pkt packet
 * @param type desired side information type
 * @param size pointer for side information size to store (optional)
 * @return pointer to data if present or NULL otherwise
 */
uint8_t* av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
                                 int *size);

Fabrice Bellard's avatar
Fabrice Bellard committed
3243 3244 3245
/* resample.c */

struct ReSampleContext;
3246
struct AVResampleContext;
Fabrice Bellard's avatar
Fabrice Bellard committed
3247 3248 3249

typedef struct ReSampleContext ReSampleContext;

3250
/**
3251
 *  Initialize audio resampling context.
3252 3253 3254 3255 3256 3257 3258
 *
 * @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
3259
 * @param filter_length    length of each FIR filter in the filterbank relative to the cutoff frequency
3260
 * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
3261
 * @param linear           if 1 then the used FIR filter will be linearly interpolated
3262 3263 3264 3265 3266 3267
                           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,
3268 3269
                                        enum AVSampleFormat sample_fmt_out,
                                        enum AVSampleFormat sample_fmt_in,
3270 3271 3272
                                        int filter_length, int log2_phase_count,
                                        int linear, double cutoff);

Fabrice Bellard's avatar
Fabrice Bellard committed
3273
int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
3274 3275 3276 3277 3278 3279 3280

/**
 * Free resample context.
 *
 * @param s a non-NULL pointer to a resample context previously
 *          created with av_audio_resample_init()
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
3281 3282
void audio_resample_close(ReSampleContext *s);

3283 3284

/**
3285
 * Initialize an audio resampler.
3286
 * Note, if either rate is not an integer then simply scale both rates up so they are.
3287 3288 3289 3290 3291
 * @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
3292
 */
3293
struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff);
3294 3295

/**
3296
 * Resample an array of samples using a previously configured context.
3297 3298 3299 3300 3301 3302 3303
 * @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
 */
3304
int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
3305 3306 3307


/**
3308
 * Compensate samplerate/timestamp drift. The compensation is done by changing
3309 3310 3311 3312 3313 3314 3315 3316 3317 3318
 * 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
3319
void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
3320
void av_resample_close(struct AVResampleContext *c);
3321

Drew Hess's avatar
Drew Hess committed
3322
/**
3323 3324
 * Allocate memory for a picture.  Call avpicture_free() to free it.
 *
3325
 * @see avpicture_fill()
Drew Hess's avatar
Drew Hess committed
3326
 *
Diego Biurrun's avatar
Diego Biurrun committed
3327 3328 3329 3330 3331
 * @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
3332
 */
3333
int avpicture_alloc(AVPicture *picture, enum PixelFormat pix_fmt, int width, int height);
Drew Hess's avatar
Drew Hess committed
3334

3335 3336
/**
 * Free a picture previously allocated by avpicture_alloc().
3337 3338
 * The data buffer used by the AVPicture is freed, but the AVPicture structure
 * itself is not.
3339
 *
Diego Biurrun's avatar
Diego Biurrun committed
3340
 * @param picture the AVPicture to be freed
3341
 */
Drew Hess's avatar
Drew Hess committed
3342 3343
void avpicture_free(AVPicture *picture);

3344
/**
Diego Biurrun's avatar
Diego Biurrun committed
3345
 * Fill in the AVPicture fields.
3346 3347 3348 3349 3350 3351
 * 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.
3352
 * Call with ptr == NULL to get the required size for the ptr buffer.
3353
 *
3354 3355 3356
 * To allocate the buffer and fill in the AVPicture fields in one call,
 * use avpicture_alloc().
 *
Diego Biurrun's avatar
Diego Biurrun committed
3357
 * @param picture AVPicture whose fields are to be filled in
3358
 * @param ptr Buffer which will contain or contains the actual image data
Diego Biurrun's avatar
Diego Biurrun committed
3359 3360 3361 3362
 * @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
3363
 */
3364
int avpicture_fill(AVPicture *picture, uint8_t *ptr,
3365
                   enum PixelFormat pix_fmt, int width, int height);
3366 3367 3368 3369 3370 3371

/**
 * Copy pixel data from an AVPicture into a buffer.
 * The data is stored compactly, without any gaps for alignment or padding
 * which may be applied by avpicture_fill().
 *
3372
 * @see avpicture_get_size()
3373 3374 3375 3376 3377 3378 3379 3380 3381
 *
 * @param[in] src AVPicture containing image data
 * @param[in] pix_fmt The format in which the picture data is stored.
 * @param[in] width the width of the image in pixels.
 * @param[in] height the height of the image in pixels.
 * @param[out] dest A buffer into which picture data will be copied.
 * @param[in] dest_size The size of 'dest'.
 * @return The number of bytes written to dest, or a negative value (error code) on error.
 */
3382
int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, int height,
3383
                     unsigned char *dest, int dest_size);
3384 3385 3386 3387

/**
 * Calculate the size in bytes that a picture of the given width and height
 * would occupy if stored in the given picture format.
3388
 * Note that this returns the size of a compact representation as generated
3389 3390
 * by avpicture_layout(), which can be smaller than the size required for e.g.
 * avpicture_fill().
3391
 *
Diego Biurrun's avatar
Diego Biurrun committed
3392 3393 3394
 * @param pix_fmt the given picture format
 * @param width the width of the image
 * @param height the height of the image
3395
 * @return Image data size in bytes or -1 on error (e.g. too large dimensions).
3396
 */
3397 3398
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);
3399 3400 3401 3402 3403 3404

#if FF_API_GET_PIX_FMT_NAME
/**
 * @deprecated Deprecated in favor of av_get_pix_fmt_name().
 */
attribute_deprecated
3405
const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt);
3406 3407
#endif

3408
void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
3409

3410
/**
3411
 * Return a value representing the fourCC code associated to the
3412 3413 3414 3415
 * pixel format pix_fmt, or 0 if no associated fourCC code can be
 * found.
 */
unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat pix_fmt);
3416

3417
/**
3418
 * Put a string representing the codec tag codec_tag in buf.
3419 3420 3421 3422 3423 3424 3425
 *
 * @param buf_size size in bytes of buf
 * @return the length of the string that would have been generated if
 * enough space had been available, excluding the trailing null
 */
size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag);

3426 3427 3428 3429 3430 3431
#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) */
3432

3433
/**
3434
 * Compute what kind of losses will occur when converting from one specific
3435 3436 3437 3438 3439 3440 3441
 * 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
3442 3443
 * avcodec_get_fix_fmt_loss() informs you about the various types of losses
 * which will occur when converting from one pixel format to another.
3444
 *
Diego Biurrun's avatar
Diego Biurrun committed
3445 3446
 * @param[in] dst_pix_fmt destination pixel format
 * @param[in] src_pix_fmt source pixel format
3447 3448
 * @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.
3449
 */
3450
int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_pix_fmt,
3451
                             int has_alpha);
3452 3453

/**
3454
 * Find the best pixel format to convert to given a certain source pixel
3455 3456 3457 3458
 * 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
3459 3460
 * 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
3461
 * pix_fmt_mask parameter.
3462 3463 3464 3465 3466 3467 3468
 *
 * @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
3469 3470
 * @param[in] pix_fmt_mask bitmask determining which pixel format to choose from
 * @param[in] src_pix_fmt source pixel format
3471 3472 3473
 * @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.
3474
 */
3475
enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt,
3476 3477
                              int has_alpha, int *loss_ptr);

3478 3479
#define FF_ALPHA_TRANSP       0x0001 /* image has some totally transparent pixels */
#define FF_ALPHA_SEMI_TRANSP  0x0002 /* image has some transparent pixels */
3480 3481 3482 3483 3484

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

3488
/* deinterlace a picture */
3489
/* deinterlace - if not supported return -1 */
3490
int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
3491
                          enum PixelFormat pix_fmt, int width, int height);
Fabrice Bellard's avatar
Fabrice Bellard committed
3492 3493 3494

/* external high level API */

3495 3496
/**
 * If c is NULL, returns the first registered codec,
3497
 * if c is non-NULL, returns the next registered codec after c,
3498 3499
 * or NULL if c is the last one.
 */
3500
AVCodec *av_codec_next(AVCodec *c);
Fabrice Bellard's avatar
Fabrice Bellard committed
3501

3502
/**
3503
 * Return the LIBAVCODEC_VERSION_INT constant.
3504
 */
3505
unsigned avcodec_version(void);
3506

3507
/**
3508
 * Return the libavcodec build-time configuration.
3509
 */
3510
const char *avcodec_configuration(void);
3511 3512

/**
3513
 * Return the libavcodec license.
3514
 */
3515
const char *avcodec_license(void);
3516

3517
#if FF_API_AVCODEC_INIT
3518
/**
3519 3520
 * @deprecated this function is called automatically from avcodec_register()
 * and avcodec_register_all(), there is no need to call it manually
3521
 */
3522
attribute_deprecated
Fabrice Bellard's avatar
Fabrice Bellard committed
3523
void avcodec_init(void);
3524
#endif
Fabrice Bellard's avatar
Fabrice Bellard committed
3525

3526
/**
3527
 * Register the codec codec and initialize libavcodec.
3528
 *
3529 3530 3531 3532
 * @warning either this function or avcodec_register_all() must be called
 * before any other libavcodec functions.
 *
 * @see avcodec_register_all()
3533
 */
3534
void avcodec_register(AVCodec *codec);
3535 3536

/**
3537
 * Find a registered encoder with a matching codec ID.
3538
 *
Diego Biurrun's avatar
Diego Biurrun committed
3539
 * @param id CodecID of the requested encoder
3540 3541
 * @return An encoder if one was found, NULL otherwise.
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
3542
AVCodec *avcodec_find_encoder(enum CodecID id);
3543 3544

/**
3545
 * Find a registered encoder with the specified name.
3546
 *
Diego Biurrun's avatar
Diego Biurrun committed
3547
 * @param name name of the requested encoder
3548 3549
 * @return An encoder if one was found, NULL otherwise.
 */
3550
AVCodec *avcodec_find_encoder_by_name(const char *name);
3551 3552

/**
3553
 * Find a registered decoder with a matching codec ID.
3554
 *
Diego Biurrun's avatar
Diego Biurrun committed
3555
 * @param id CodecID of the requested decoder
3556 3557
 * @return A decoder if one was found, NULL otherwise.
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
3558
AVCodec *avcodec_find_decoder(enum CodecID id);
3559 3560

/**
3561
 * Find a registered decoder with the specified name.
3562
 *
Diego Biurrun's avatar
Diego Biurrun committed
3563
 * @param name name of the requested decoder
3564 3565
 * @return A decoder if one was found, NULL otherwise.
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
3566 3567 3568
AVCodec *avcodec_find_decoder_by_name(const char *name);
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);

3569 3570 3571 3572 3573 3574 3575 3576 3577
/**
 * Return a name for the specified profile, if available.
 *
 * @param codec the codec that is searched for the given profile
 * @param profile the profile value for which a name is requested
 * @return A name for the profile if found, NULL otherwise.
 */
const char *av_get_profile_name(const AVCodec *codec, int profile);

3578
/**
3579
 * Set the fields of the given AVCodecContext to default values.
3580 3581 3582
 *
 * @param s The AVCodecContext of which the fields should be set to default values.
 */
Michael Niedermayer's avatar
Michael Niedermayer committed
3583
void avcodec_get_context_defaults(AVCodecContext *s);
3584

3585 3586
/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
 *  we WILL change its arguments and name a few times! */
3587
void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType);
3588

3589 3590 3591 3592
/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
 *  we WILL change its arguments and name a few times! */
int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec);

3593
#if FF_API_ALLOC_CONTEXT
3594
/**
3595
 * Allocate an AVCodecContext and set its fields to default values.  The
3596 3597 3598 3599
 * 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
3600 3601
 *
 * @deprecated use avcodec_alloc_context3()
3602
 */
3603
attribute_deprecated
Falk Hüffner's avatar
Falk Hüffner committed
3604
AVCodecContext *avcodec_alloc_context(void);
3605

3606 3607
/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
 *  we WILL change its arguments and name a few times! */
3608
attribute_deprecated
3609
AVCodecContext *avcodec_alloc_context2(enum AVMediaType);
3610
#endif
3611

3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624
/**
 * Allocate an AVCodecContext and set its fields to default values.  The
 * resulting struct can be deallocated by simply calling av_free().
 *
 * @param codec if non-NULL, allocate private data and initialize defaults
 *              for the given codec. It is illegal to then call avcodec_open()
 *              with a different codec.
 *
 * @return An AVCodecContext filled with default values or NULL on failure.
 * @see avcodec_get_context_defaults
 *
 * @deprecated use avcodec_alloc_context3()
 */
3625 3626
AVCodecContext *avcodec_alloc_context3(AVCodec *codec);

3627 3628 3629 3630 3631 3632 3633
/**
 * Copy the settings of the source AVCodecContext into the destination
 * AVCodecContext. The resulting destination codec context will be
 * unopened, i.e. you are required to call avcodec_open() before you
 * can use this AVCodecContext to decode/encode video/audio data.
 *
 * @param dest target codec context, should be initialized with
3634
 *             avcodec_alloc_context3(), but otherwise uninitialized
3635 3636 3637 3638 3639
 * @param src source codec context
 * @return AVERROR() on error (e.g. memory allocation error), 0 on success
 */
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);

3640
/**
3641
 * Set the fields of the given AVFrame to default values.
3642 3643 3644
 *
 * @param pic The AVFrame of which the fields should be set to default values.
 */
Falk Hüffner's avatar
Falk Hüffner committed
3645
void avcodec_get_frame_defaults(AVFrame *pic);
3646 3647

/**
3648
 * Allocate an AVFrame and set its fields to default values.  The resulting
3649 3650 3651 3652 3653
 * 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
 */
3654
AVFrame *avcodec_alloc_frame(void);
Michael Niedermayer's avatar
Michael Niedermayer committed
3655

3656 3657
int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
3658
int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
3659 3660

/**
3661
 * Return the amount of padding in pixels which the get_buffer callback must
3662 3663 3664 3665 3666 3667
 * provide around the edge of the image for codecs which do not have the
 * CODEC_FLAG_EMU_EDGE flag.
 *
 * @return Required padding in pixels.
 */
unsigned avcodec_get_edge_width(void);
3668
/**
3669
 * Modify width and height values so that they will result in a memory
3670 3671
 * buffer that is acceptable for the codec if you do not use any horizontal
 * padding.
3672 3673 3674 3675
 *
 * May only be used if a codec with CODEC_CAP_DR1 has been opened.
 * If CODEC_FLAG_EMU_EDGE is not set, the dimensions must have been increased
 * according to avcodec_get_edge_width() before.
3676
 */
3677
void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
3678
/**
3679
 * Modify width and height values so that they will result in a memory
3680 3681
 * buffer that is acceptable for the codec if you also ensure that all
 * line sizes are a multiple of the respective linesize_align[i].
3682 3683 3684 3685
 *
 * May only be used if a codec with CODEC_CAP_DR1 has been opened.
 * If CODEC_FLAG_EMU_EDGE is not set, the dimensions must have been increased
 * according to avcodec_get_edge_width() before.
3686 3687 3688
 */
void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
                               int linesize_align[4]);
3689

3690
enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt);
Michael Niedermayer's avatar
Michael Niedermayer committed
3691

3692 3693 3694 3695 3696 3697 3698 3699
#if FF_API_THREAD_INIT
/**
 * @deprecated Set s->thread_count before calling avcodec_open() instead of calling this.
 */
attribute_deprecated
int avcodec_thread_init(AVCodecContext *s, int thread_count);
#endif

3700
int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
3701
int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
3702 3703
//FIXME func typedef

3704
#if FF_API_AVCODEC_OPEN
Michael Niedermayer's avatar
Michael Niedermayer committed
3705
/**
3706
 * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
3707 3708 3709 3710 3711 3712
 * 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
3713
 * @warning This function is not thread safe!
3714 3715
 *
 * @code
3716
 * avcodec_register_all();
3717 3718 3719 3720
 * codec = avcodec_find_decoder(CODEC_ID_H264);
 * if (!codec)
 *     exit(1);
 *
3721
 * context = avcodec_alloc_context3(codec);
3722 3723 3724 3725 3726
 *
 * if (avcodec_open(context, codec) < 0)
 *     exit(1);
 * @endcode
 *
Diego Biurrun's avatar
Diego Biurrun committed
3727
 * @param avctx The context which will be set up to use the given codec.
3728
 * @param codec The codec to use within the context.
Diego Biurrun's avatar
Diego Biurrun committed
3729
 * @return zero on success, a negative value on error
3730
 * @see avcodec_alloc_context3, avcodec_find_decoder, avcodec_find_encoder, avcodec_close
3731 3732
 *
 * @deprecated use avcodec_open2
Michael Niedermayer's avatar
Michael Niedermayer committed
3733
 */
3734
attribute_deprecated
Fabrice Bellard's avatar
Fabrice Bellard committed
3735
int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769
#endif

/**
 * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
 * function the context has to be allocated with avcodec_alloc_context().
 *
 * 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.
 *
 * @warning This function is not thread safe!
 *
 * @code
 * avcodec_register_all();
 * av_dict_set(&opts, "b", "2.5M", 0);
 * codec = avcodec_find_decoder(CODEC_ID_H264);
 * if (!codec)
 *     exit(1);
 *
 * context = avcodec_alloc_context();
 *
 * if (avcodec_open(context, codec, opts) < 0)
 *     exit(1);
 * @endcode
 *
 * @param avctx The context to initialize.
 * @param options A dictionary filled with AVCodecContext and codec-private options.
 *                On return this object will be filled with options that were not found.
 *
 * @return zero on success, a negative value on error
 * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
 *      av_dict_set(), av_opt_find().
 */
int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options);
Michael Niedermayer's avatar
Michael Niedermayer committed
3770

3771
/**
3772
 * Decode the audio frame of size avpkt->size from avpkt->data into samples.
3773
 * Some decoders may support multiple frames in a single AVPacket, such
3774 3775 3776
 * decoders would then just decode the first frame. In this case,
 * avcodec_decode_audio3 has to be called again with an AVPacket that contains
 * the remaining data in order to decode the second frame etc.
3777
 * If no frame
3778
 * could be outputted, frame_size_ptr is zero. Otherwise, it is the
3779
 * decompressed frame size in bytes.
3780
 *
3781
 * @warning You must set frame_size_ptr to the allocated size of the
3782
 * output buffer before calling avcodec_decode_audio3().
3783
 *
3784
 * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
3785 3786 3787
 * the actual read bytes because some optimized bitstream readers read 32 or 64
 * bits at once and could read over the end.
 *
3788
 * @warning The end of the input buffer avpkt->data should be set to 0 to ensure that
3789
 * no overreading happens for damaged MPEG streams.
3790
 *
3791
 * @note You might have to align the input buffer avpkt->data and output buffer
Diego Biurrun's avatar
Diego Biurrun committed
3792
 * samples. The alignment requirements depend on the CPU: On some CPUs it isn't
3793
 * necessary at all, on others it won't work at all if not aligned and on others
3794 3795 3796 3797 3798
 * 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).
3799
 *
Diego Biurrun's avatar
Diego Biurrun committed
3800
 * @param avctx the codec context
3801
 * @param[out] samples the output buffer, sample type in avctx->sample_fmt
Diego Biurrun's avatar
Diego Biurrun committed
3802
 * @param[in,out] frame_size_ptr the output buffer size in bytes
3803
 * @param[in] avpkt The input AVPacket containing the input buffer.
3804 3805 3806
 *            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.
3807
 * @return On error a negative value is returned, otherwise the number of bytes
3808
 * used or zero if no frame data was decompressed (used) from the input AVPacket.
3809
 */
3810
int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
Fabrice Bellard's avatar
Fabrice Bellard committed
3811
                         int *frame_size_ptr,
3812
                         AVPacket *avpkt);
3813

3814
/**
3815
 * Decode the video frame of size avpkt->size from avpkt->data into picture.
3816 3817
 * Some decoders may support multiple frames in a single AVPacket, such
 * decoders would then just decode the first frame.
3818
 *
3819
 * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
3820 3821 3822
 * the actual read bytes because some optimized bitstream readers read 32 or 64
 * bits at once and could read over the end.
 *
3823
 * @warning The end of the input buffer buf should be set to 0 to ensure that
3824 3825
 * no overreading happens for damaged MPEG streams.
 *
3826 3827
 * @note You might have to align the input buffer avpkt->data.
 * The alignment requirements depend on the CPU: on some CPUs it isn't
3828
 * necessary at all, on others it won't work at all if not aligned and on others
3829 3830 3831
 * it will work but it will have an impact on performance.
 *
 * In practice, avpkt->data should have 4 byte alignment at minimum.
3832
 *
3833
 * @note Some codecs have a delay between input and output, these need to be
3834
 * fed with avpkt->data=NULL, avpkt->size=0 at the end to return the remaining frames.
3835
 *
Diego Biurrun's avatar
Diego Biurrun committed
3836
 * @param avctx the codec context
3837
 * @param[out] picture The AVFrame in which the decoded video frame will be stored.
3838 3839
 *             Use avcodec_alloc_frame to get an AVFrame, the codec will
 *             allocate memory for the actual bitmap.
3840
 *             with default get/release_buffer(), the decoder frees/reuses the bitmap as it sees fit.
3841
 *             with overridden get/release_buffer() (needs CODEC_CAP_DR1) the user decides into what buffer the decoder
3842 3843 3844
 *                   decodes and the decoder tells the user once it does not need the data anymore,
 *                   the user app can at this point free/reuse/keep the memory as it sees fit.
 *
3845
 * @param[in] avpkt The input AVpacket containing the input buffer.
3846 3847
 *            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
3848
 *            flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least
3849
 *            fields possible.
Diego Biurrun's avatar
Diego Biurrun committed
3850
 * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
3851 3852 3853
 * @return On error a negative value is returned, otherwise the number of bytes
 * used or zero if no frame could be decompressed.
 */
3854
int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
Fabrice Bellard's avatar
Fabrice Bellard committed
3855
                         int *got_picture_ptr,
3856
                         AVPacket *avpkt);
3857

3858
/**
3859
 * Decode a subtitle message.
Måns Rullgård's avatar
Måns Rullgård committed
3860
 * Return a negative value on error, otherwise return the number of bytes used.
3861 3862
 * If no subtitle could be decompressed, got_sub_ptr is zero.
 * Otherwise, the subtitle is stored in *sub.
3863 3864 3865 3866
 * Note that CODEC_CAP_DR1 is not available for subtitle codecs. This is for
 * simplicity, because the performance difference is expect to be negligible
 * and reusing a get_buffer written for video codecs would probably perform badly
 * due to a potentially very different allocation pattern.
3867 3868
 *
 * @param avctx the codec context
3869 3870
 * @param[out] sub The AVSubtitle in which the decoded subtitle will be stored, must be
                   freed with avsubtitle_free if *got_sub_ptr is set.
3871 3872 3873 3874 3875 3876
 * @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);
3877 3878 3879 3880 3881 3882 3883 3884

/**
 * Frees all allocated data in the given subtitle struct.
 *
 * @param sub AVSubtitle to free.
 */
void avsubtitle_free(AVSubtitle *sub);

3885
int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata,
3886
                        int *data_size_ptr,
3887
                        uint8_t *buf, int buf_size);
3888 3889

/**
3890
 * Encode an audio frame from samples into buf.
3891
 *
3892
 * @note The output buffer should be at least FF_MIN_BUFFER_SIZE bytes large.
3893
 * However, for PCM audio the user will know how much space is needed
3894
 * because it depends on the value passed in buf_size as described
3895
 * below. In that case a lower value can be used.
3896
 *
Diego Biurrun's avatar
Diego Biurrun committed
3897 3898 3899 3900
 * @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
3901
 * The number of samples read from this buffer is frame_size*channels,
3902 3903 3904
 * 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
3905
 * @return On error a negative value is returned, on success zero or the number
3906
 * of bytes used to encode the data read from the input buffer.
3907
 */
3908
int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
Fabrice Bellard's avatar
Fabrice Bellard committed
3909
                         const short *samples);
3910 3911

/**
3912
 * Encode a video frame from pict into buf.
3913
 * The input picture should be
3914
 * stored using a specific format, namely avctx.pix_fmt.
3915
 *
Diego Biurrun's avatar
Diego Biurrun committed
3916 3917 3918 3919
 * @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
3920
 * @return On error a negative value is returned, on success zero or the number
3921
 * of bytes used from the output buffer.
3922
 */
3923
int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
3924
                         const AVFrame *pict);
3925
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
3926
                            const AVSubtitle *sub);
Fabrice Bellard's avatar
Fabrice Bellard committed
3927 3928 3929

int avcodec_close(AVCodecContext *avctx);

3930 3931 3932 3933 3934 3935
/**
 * 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.
 *
3936
 * @see avcodec_register
3937 3938 3939
 * @see av_register_codec_parser
 * @see av_register_bitstream_filter
 */
Fabrice Bellard's avatar
Fabrice Bellard committed
3940
void avcodec_register_all(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
3941

3942 3943 3944
/**
 * Flush buffers, should be called when seeking or when switching to a different stream.
 */
3945 3946
void avcodec_flush_buffers(AVCodecContext *avctx);

3947 3948
void avcodec_default_free_buffers(AVCodecContext *s);

Panagiotis Issaris's avatar
Panagiotis Issaris committed
3949
/* misc useful functions */
Michael Niedermayer's avatar
Michael Niedermayer committed
3950

3951
#if FF_API_OLD_FF_PICT_TYPES
Michael Niedermayer's avatar
Michael Niedermayer committed
3952
/**
3953
 * Return a single letter to describe the given picture type pict_type.
3954
 *
Diego Biurrun's avatar
Diego Biurrun committed
3955
 * @param[in] pict_type the picture type
3956
 * @return A single character representing the picture type.
3957
 * @deprecated Use av_get_picture_type_char() instead.
Michael Niedermayer's avatar
Michael Niedermayer committed
3958
 */
3959
attribute_deprecated
Michael Niedermayer's avatar
Michael Niedermayer committed
3960
char av_get_pict_type_char(int pict_type);
3961
#endif
Michael Niedermayer's avatar
Michael Niedermayer committed
3962

3963
/**
3964
 * Return codec bits per sample.
3965
 *
Diego Biurrun's avatar
Diego Biurrun committed
3966
 * @param[in] codec_id the codec
3967
 * @return Number of bits per sample or zero if unknown for the given codec.
3968 3969
 */
int av_get_bits_per_sample(enum CodecID codec_id);
3970

3971
#if FF_API_OLD_SAMPLE_FMT
3972
/**
3973
 * @deprecated Use av_get_bytes_per_sample() instead.
3974
 */
3975
attribute_deprecated
3976
int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt);
3977
#endif
3978

3979 3980 3981 3982 3983
/* frame parsing */
typedef struct AVCodecParserContext {
    void *priv_data;
    struct AVCodecParser *parser;
    int64_t frame_offset; /* offset of the current frame */
3984
    int64_t cur_offset; /* current offset
3985
                           (incremented by each av_parser_parse()) */
3986
    int64_t next_frame_offset; /* offset of the next frame */
3987
    /* video info */
Diego Biurrun's avatar
Diego Biurrun committed
3988
    int pict_type; /* XXX: Put it back in AVCodecContext. */
3989 3990 3991 3992 3993
    /**
     * 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.
     *
3994
     * frame_duration = (1 + repeat_pict) * time_base
3995 3996 3997
     *
     * It is used by codecs like H.264 to display telecined material.
     */
Diego Biurrun's avatar
Diego Biurrun committed
3998
    int repeat_pict; /* XXX: Put it back in AVCodecContext. */
3999 4000 4001 4002 4003 4004
    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;
4005
    int fetch_timestamp;
4006 4007 4008 4009 4010 4011

#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];
4012

4013 4014
    int flags;
#define PARSER_FLAG_COMPLETE_FRAMES           0x0001
4015
#define PARSER_FLAG_ONCE                      0x0002
Michael Chinen's avatar
Michael Chinen committed
4016 4017
/// Set if the parser has a valid file offset
#define PARSER_FLAG_FETCHED_OFFSET            0x0004
4018 4019

    int64_t offset;      ///< byte offset from starting packet start
4020
    int64_t cur_frame_end[AV_PARSER_PTS_NB];
4021

4022
    /**
4023 4024
     * 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,
4025
     * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
4026 4027 4028
     * will be used.
     */
    int key_frame;
4029 4030 4031 4032 4033 4034 4035 4036 4037

    /**
     * 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.
Aurelien Jacobs's avatar
Aurelien Jacobs committed
4038 4039
     * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
     * set.
4040 4041 4042 4043 4044 4045 4046 4047
     *
     * 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;
4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088

    // 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;
4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105

    /**
     * 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;
4106 4107 4108
} AVCodecParserContext;

typedef struct AVCodecParser {
Michael Niedermayer's avatar
Michael Niedermayer committed
4109
    int codec_ids[5]; /* several codec IDs are permitted */
4110 4111
    int priv_data_size;
    int (*parser_init)(AVCodecParserContext *s);
4112
    int (*parser_parse)(AVCodecParserContext *s,
4113
                        AVCodecContext *avctx,
4114
                        const uint8_t **poutbuf, int *poutbuf_size,
4115 4116
                        const uint8_t *buf, int buf_size);
    void (*parser_close)(AVCodecParserContext *s);
4117
    int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
4118 4119 4120
    struct AVCodecParser *next;
} AVCodecParser;

4121
AVCodecParser *av_parser_next(AVCodecParser *c);
4122 4123 4124

void av_register_codec_parser(AVCodecParser *parser);
AVCodecParserContext *av_parser_init(int codec_id);
4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160

/**
 * 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);

4161 4162
int av_parser_change(AVCodecParserContext *s,
                     AVCodecContext *avctx,
4163
                     uint8_t **poutbuf, int *poutbuf_size,
4164
                     const uint8_t *buf, int buf_size, int keyframe);
4165 4166
void av_parser_close(AVCodecParserContext *s);

4167 4168

typedef struct AVBitStreamFilterContext {
4169
    void *priv_data;
4170 4171 4172 4173 4174 4175 4176 4177
    struct AVBitStreamFilter *filter;
    AVCodecParserContext *parser;
    struct AVBitStreamFilterContext *next;
} AVBitStreamFilterContext;


typedef struct AVBitStreamFilter {
    const char *name;
4178
    int priv_data_size;
4179 4180 4181 4182
    int (*filter)(AVBitStreamFilterContext *bsfc,
                  AVCodecContext *avctx, const char *args,
                  uint8_t **poutbuf, int *poutbuf_size,
                  const uint8_t *buf, int buf_size, int keyframe);
4183
    void (*close)(AVBitStreamFilterContext *bsfc);
4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194
    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);

4195
AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f);
4196

4197
/* memory */
4198 4199

/**
4200
 * Reallocate the given block if it is not large enough, otherwise do nothing.
4201 4202
 *
 * @see av_realloc
4203
 */
4204
void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
4205

4206
/**
4207
 * Allocate a buffer, reusing the given one if large enough.
4208 4209 4210 4211 4212 4213 4214 4215 4216 4217
 *
 * 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.
 */
4218
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
4219 4220 4221

/**
 * Copy image src to dst. Wraps av_picture_data_copy() above.
4222
 */
4223
void av_picture_copy(AVPicture *dst, const AVPicture *src,
4224
                     enum PixelFormat pix_fmt, int width, int height);
4225

4226
/**
Diego Biurrun's avatar
Diego Biurrun committed
4227
 * Crop image top and left side.
4228
 */
4229
int av_picture_crop(AVPicture *dst, const AVPicture *src,
4230
                    enum PixelFormat pix_fmt, int top_band, int left_band);
4231

4232
/**
Diego Biurrun's avatar
Diego Biurrun committed
4233
 * Pad image.
4234
 */
4235
int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, enum PixelFormat pix_fmt,
4236 4237
            int padtop, int padbottom, int padleft, int padright, int *color);

4238
/**
4239
 * Encode extradata length to a buffer. Used by xiph codecs.
4240 4241 4242 4243 4244
 *
 * @param s buffer to write to; must be at least (v/255+1) bytes long
 * @param v size of extradata in bytes
 * @return number of bytes written to the buffer.
 */
4245
unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
4246

4247
/**
4248
 * Logs a generic warning message about a missing feature. This function is
4249
 * intended to be used internally by Libav (libavcodec, libavformat, etc.)
4250
 * only, and would normally not be used by applications.
4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261
 * @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);

/**
4262
 * Log a generic warning message asking for a sample. This function is
4263
 * intended to be used internally by Libav (libavcodec, libavformat, etc.)
4264
 * only, and would normally not be used by applications.
4265 4266 4267 4268
 * @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
 */
4269
void av_log_ask_for_sample(void *avc, const char *msg, ...) av_printf_format(2, 3);
4270

4271
/**
4272
 * Register the hardware accelerator hwaccel.
4273 4274 4275 4276 4277 4278 4279 4280 4281 4282
 */
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);

4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295

/**
 * 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
4296
 * specified by AVLockOp. mutex points to a (void *) where the
4297 4298 4299
 * lockmgr should store/get a pointer to a user allocated mutex. It's
 * NULL upon AV_LOCK_CREATE and != NULL for all other ops.
 *
4300
 * @param cb User defined callback. Note: Libav may invoke calls to this
4301 4302 4303 4304 4305 4306 4307 4308
 *           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));

4309 4310 4311 4312 4313
/**
 * Get the type of the given codec.
 */
enum AVMediaType avcodec_get_type(enum CodecID codec_id);

4314 4315 4316 4317 4318 4319 4320 4321
/**
 * Get the AVClass for AVCodecContext. It can be used in combination with
 * AV_OPT_SEARCH_FAKE_OBJ for examining options.
 *
 * @see av_opt_find().
 */
const AVClass *avcodec_get_class(void);

4322
#endif /* AVCODEC_AVCODEC_H */