tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

avcodec.h (108859B)


      1 /*
      2 * copyright (c) 2001 Fabrice Bellard
      3 *
      4 * This file is part of FFmpeg.
      5 *
      6 * FFmpeg is free software; you can redistribute it and/or
      7 * modify it under the terms of the GNU Lesser General Public
      8 * License as published by the Free Software Foundation; either
      9 * version 2.1 of the License, or (at your option) any later version.
     10 *
     11 * FFmpeg is distributed in the hope that it will be useful,
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14 * Lesser General Public License for more details.
     15 *
     16 * You should have received a copy of the GNU Lesser General Public
     17 * License along with FFmpeg; if not, write to the Free Software
     18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     19 */
     20 
     21 #ifndef AVCODEC_AVCODEC_H
     22 #define AVCODEC_AVCODEC_H
     23 
     24 /**
     25 * @file
     26 * @ingroup libavc
     27 * Libavcodec external API header
     28 */
     29 
     30 #include "libavutil/samplefmt.h"
     31 #include "libavutil/attributes.h"
     32 #include "libavutil/avutil.h"
     33 #include "libavutil/buffer.h"
     34 #include "libavutil/dict.h"
     35 #include "libavutil/frame.h"
     36 #include "libavutil/log.h"
     37 #include "libavutil/pixfmt.h"
     38 #include "libavutil/rational.h"
     39 
     40 #include "codec.h"
     41 #include "codec_desc.h"
     42 #include "codec_par.h"
     43 #include "codec_id.h"
     44 #include "defs.h"
     45 #include "packet.h"
     46 #include "version.h"
     47 
     48 /**
     49 * @defgroup libavc libavcodec
     50 * Encoding/Decoding Library
     51 *
     52 * @{
     53 *
     54 * @defgroup lavc_decoding Decoding
     55 * @{
     56 * @}
     57 *
     58 * @defgroup lavc_encoding Encoding
     59 * @{
     60 * @}
     61 *
     62 * @defgroup lavc_codec Codecs
     63 * @{
     64 * @defgroup lavc_codec_native Native Codecs
     65 * @{
     66 * @}
     67 * @defgroup lavc_codec_wrappers External library wrappers
     68 * @{
     69 * @}
     70 * @defgroup lavc_codec_hwaccel Hardware Accelerators bridge
     71 * @{
     72 * @}
     73 * @}
     74 * @defgroup lavc_internal Internal
     75 * @{
     76 * @}
     77 * @}
     78 */
     79 
     80 /**
     81 * @ingroup libavc
     82 * @defgroup lavc_encdec send/receive encoding and decoding API overview
     83 * @{
     84 *
     85 * The avcodec_send_packet()/avcodec_receive_frame()/avcodec_send_frame()/
     86 * avcodec_receive_packet() functions provide an encode/decode API, which
     87 * decouples input and output.
     88 *
     89 * The API is very similar for encoding/decoding and audio/video, and works as
     90 * follows:
     91 * - Set up and open the AVCodecContext as usual.
     92 * - Send valid input:
     93 *   - For decoding, call avcodec_send_packet() to give the decoder raw
     94 *     compressed data in an AVPacket.
     95 *   - For encoding, call avcodec_send_frame() to give the encoder an AVFrame
     96 *     containing uncompressed audio or video.
     97 *
     98 *   In both cases, it is recommended that AVPackets and AVFrames are
     99 *   refcounted, or libavcodec might have to copy the input data. (libavformat
    100 *   always returns refcounted AVPackets, and av_frame_get_buffer() allocates
    101 *   refcounted AVFrames.)
    102 * - Receive output in a loop. Periodically call one of the avcodec_receive_*()
    103 *   functions and process their output:
    104 *   - For decoding, call avcodec_receive_frame(). On success, it will return
    105 *     an AVFrame containing uncompressed audio or video data.
    106 *   - For encoding, call avcodec_receive_packet(). On success, it will return
    107 *     an AVPacket with a compressed frame.
    108 *
    109 *   Repeat this call until it returns AVERROR(EAGAIN) or an error. The
    110 *   AVERROR(EAGAIN) return value means that new input data is required to
    111 *   return new output. In this case, continue with sending input. For each
    112 *   input frame/packet, the codec will typically return 1 output frame/packet,
    113 *   but it can also be 0 or more than 1.
    114 *
    115 * At the beginning of decoding or encoding, the codec might accept multiple
    116 * input frames/packets without returning a frame, until its internal buffers
    117 * are filled. This situation is handled transparently if you follow the steps
    118 * outlined above.
    119 *
    120 * In theory, sending input can result in EAGAIN - this should happen only if
    121 * not all output was received. You can use this to structure alternative decode
    122 * or encode loops other than the one suggested above. For example, you could
    123 * try sending new input on each iteration, and try to receive output if that
    124 * returns EAGAIN.
    125 *
    126 * End of stream situations. These require "flushing" (aka draining) the codec,
    127 * as the codec might buffer multiple frames or packets internally for
    128 * performance or out of necessity (consider B-frames).
    129 * This is handled as follows:
    130 * - Instead of valid input, send NULL to the avcodec_send_packet() (decoding)
    131 *   or avcodec_send_frame() (encoding) functions. This will enter draining
    132 *   mode.
    133 * - Call avcodec_receive_frame() (decoding) or avcodec_receive_packet()
    134 *   (encoding) in a loop until AVERROR_EOF is returned. The functions will
    135 *   not return AVERROR(EAGAIN), unless you forgot to enter draining mode.
    136 * - Before decoding can be resumed again, the codec has to be reset with
    137 *   avcodec_flush_buffers().
    138 *
    139 * Using the API as outlined above is highly recommended. But it is also
    140 * possible to call functions outside of this rigid schema. For example, you can
    141 * call avcodec_send_packet() repeatedly without calling
    142 * avcodec_receive_frame(). In this case, avcodec_send_packet() will succeed
    143 * until the codec's internal buffer has been filled up (which is typically of
    144 * size 1 per output frame, after initial input), and then reject input with
    145 * AVERROR(EAGAIN). Once it starts rejecting input, you have no choice but to
    146 * read at least some output.
    147 *
    148 * Not all codecs will follow a rigid and predictable dataflow; the only
    149 * guarantee is that an AVERROR(EAGAIN) return value on a send/receive call on
    150 * one end implies that a receive/send call on the other end will succeed, or
    151 * at least will not fail with AVERROR(EAGAIN). In general, no codec will
    152 * permit unlimited buffering of input or output.
    153 *
    154 * A codec is not allowed to return AVERROR(EAGAIN) for both sending and
    155 * receiving. This would be an invalid state, which could put the codec user
    156 * into an endless loop. The API has no concept of time either: it cannot happen
    157 * that trying to do avcodec_send_packet() results in AVERROR(EAGAIN), but a
    158 * repeated call 1 second later accepts the packet (with no other receive/flush
    159 * API calls involved). The API is a strict state machine, and the passage of
    160 * time is not supposed to influence it. Some timing-dependent behavior might
    161 * still be deemed acceptable in certain cases. But it must never result in both
    162 * send/receive returning EAGAIN at the same time at any point. It must also
    163 * absolutely be avoided that the current state is "unstable" and can
    164 * "flip-flop" between the send/receive APIs allowing progress. For example,
    165 * it's not allowed that the codec randomly decides that it actually wants to
    166 * consume a packet now instead of returning a frame, after it just returned
    167 * AVERROR(EAGAIN) on an avcodec_send_packet() call.
    168 * @}
    169 */
    170 
    171 /**
    172 * @defgroup lavc_core Core functions/structures.
    173 * @ingroup libavc
    174 *
    175 * Basic definitions, functions for querying libavcodec capabilities,
    176 * allocating core structures, etc.
    177 * @{
    178 */
    179 
    180 /**
    181 * @ingroup lavc_encoding
    182 * minimum encoding buffer size
    183 * Used to avoid some checks during header writing.
    184 */
    185 #define AV_INPUT_BUFFER_MIN_SIZE 16384
    186 
    187 /**
    188 * @ingroup lavc_encoding
    189 */
    190 typedef struct RcOverride {
    191  int start_frame;
    192  int end_frame;
    193  int qscale;  // If this is 0 then quality_factor will be used instead.
    194  float quality_factor;
    195 } RcOverride;
    196 
    197 /* encoding support
    198   These flags can be passed in AVCodecContext.flags before initialization.
    199   Note: Not everything is supported yet.
    200 */
    201 
    202 /**
    203 * Allow decoders to produce frames with data planes that are not aligned
    204 * to CPU requirements (e.g. due to cropping).
    205 */
    206 #define AV_CODEC_FLAG_UNALIGNED (1 << 0)
    207 /**
    208 * Use fixed qscale.
    209 */
    210 #define AV_CODEC_FLAG_QSCALE (1 << 1)
    211 /**
    212 * 4 MV per MB allowed / advanced prediction for H.263.
    213 */
    214 #define AV_CODEC_FLAG_4MV (1 << 2)
    215 /**
    216 * Output even those frames that might be corrupted.
    217 */
    218 #define AV_CODEC_FLAG_OUTPUT_CORRUPT (1 << 3)
    219 /**
    220 * Use qpel MC.
    221 */
    222 #define AV_CODEC_FLAG_QPEL (1 << 4)
    223 /**
    224 * Don't output frames whose parameters differ from first
    225 * decoded frame in stream.
    226 */
    227 #define AV_CODEC_FLAG_DROPCHANGED (1 << 5)
    228 /**
    229 * Use internal 2pass ratecontrol in first pass mode.
    230 */
    231 #define AV_CODEC_FLAG_PASS1 (1 << 9)
    232 /**
    233 * Use internal 2pass ratecontrol in second pass mode.
    234 */
    235 #define AV_CODEC_FLAG_PASS2 (1 << 10)
    236 /**
    237 * loop filter.
    238 */
    239 #define AV_CODEC_FLAG_LOOP_FILTER (1 << 11)
    240 /**
    241 * Only decode/encode grayscale.
    242 */
    243 #define AV_CODEC_FLAG_GRAY (1 << 13)
    244 /**
    245 * error[?] variables will be set during encoding.
    246 */
    247 #define AV_CODEC_FLAG_PSNR (1 << 15)
    248 #if FF_API_FLAG_TRUNCATED
    249 /**
    250 * Input bitstream might be truncated at a random location
    251 * instead of only at frame boundaries.
    252 *
    253 * @deprecated use codec parsers for packetizing input
    254 */
    255 #  define AV_CODEC_FLAG_TRUNCATED (1 << 16)
    256 #endif
    257 /**
    258 * Use interlaced DCT.
    259 */
    260 #define AV_CODEC_FLAG_INTERLACED_DCT (1 << 18)
    261 /**
    262 * Force low delay.
    263 */
    264 #define AV_CODEC_FLAG_LOW_DELAY (1 << 19)
    265 /**
    266 * Place global headers in extradata instead of every keyframe.
    267 */
    268 #define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
    269 /**
    270 * Use only bitexact stuff (except (I)DCT).
    271 */
    272 #define AV_CODEC_FLAG_BITEXACT (1 << 23)
    273 /* Fx : Flag for H.263+ extra options */
    274 /**
    275 * H.263 advanced intra coding / MPEG-4 AC prediction
    276 */
    277 #define AV_CODEC_FLAG_AC_PRED (1 << 24)
    278 /**
    279 * interlaced motion estimation
    280 */
    281 #define AV_CODEC_FLAG_INTERLACED_ME (1 << 29)
    282 #define AV_CODEC_FLAG_CLOSED_GOP (1U << 31)
    283 
    284 /**
    285 * Allow non spec compliant speedup tricks.
    286 */
    287 #define AV_CODEC_FLAG2_FAST (1 << 0)
    288 /**
    289 * Skip bitstream encoding.
    290 */
    291 #define AV_CODEC_FLAG2_NO_OUTPUT (1 << 2)
    292 /**
    293 * Place global headers at every keyframe instead of in extradata.
    294 */
    295 #define AV_CODEC_FLAG2_LOCAL_HEADER (1 << 3)
    296 
    297 /**
    298 * timecode is in drop frame format. DEPRECATED!!!!
    299 */
    300 #define AV_CODEC_FLAG2_DROP_FRAME_TIMECODE (1 << 13)
    301 
    302 /**
    303 * Input bitstream might be truncated at a packet boundaries
    304 * instead of only at frame boundaries.
    305 */
    306 #define AV_CODEC_FLAG2_CHUNKS (1 << 15)
    307 /**
    308 * Discard cropping information from SPS.
    309 */
    310 #define AV_CODEC_FLAG2_IGNORE_CROP (1 << 16)
    311 
    312 /**
    313 * Show all frames before the first keyframe
    314 */
    315 #define AV_CODEC_FLAG2_SHOW_ALL (1 << 22)
    316 /**
    317 * Export motion vectors through frame side data
    318 */
    319 #define AV_CODEC_FLAG2_EXPORT_MVS (1 << 28)
    320 /**
    321 * Do not skip samples and export skip information as frame side data
    322 */
    323 #define AV_CODEC_FLAG2_SKIP_MANUAL (1 << 29)
    324 /**
    325 * Do not reset ASS ReadOrder field on flush (subtitles decoding)
    326 */
    327 #define AV_CODEC_FLAG2_RO_FLUSH_NOOP (1 << 30)
    328 
    329 /* Unsupported options :
    330 *              Syntax Arithmetic coding (SAC)
    331 *              Reference Picture Selection
    332 *              Independent Segment Decoding */
    333 /* /Fx */
    334 /* codec capabilities */
    335 
    336 /* Exported side data.
    337   These flags can be passed in AVCodecContext.export_side_data before
    338   initialization.
    339 */
    340 /**
    341 * Export motion vectors through frame side data
    342 */
    343 #define AV_CODEC_EXPORT_DATA_MVS (1 << 0)
    344 /**
    345 * Export encoder Producer Reference Time through packet side data
    346 */
    347 #define AV_CODEC_EXPORT_DATA_PRFT (1 << 1)
    348 /**
    349 * Decoding only.
    350 * Export the AVVideoEncParams structure through frame side data.
    351 */
    352 #define AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS (1 << 2)
    353 /**
    354 * Decoding only.
    355 * Do not apply film grain, export it instead.
    356 */
    357 #define AV_CODEC_EXPORT_DATA_FILM_GRAIN (1 << 3)
    358 
    359 /**
    360 * The decoder will keep a reference to the frame and may reuse it later.
    361 */
    362 #define AV_GET_BUFFER_FLAG_REF (1 << 0)
    363 
    364 /**
    365 * The encoder will keep a reference to the packet and may reuse it later.
    366 */
    367 #define AV_GET_ENCODE_BUFFER_FLAG_REF (1 << 0)
    368 
    369 struct AVCodecInternal;
    370 
    371 /**
    372 * main external API structure.
    373 * New fields can be added to the end with minor version bumps.
    374 * Removal, reordering and changes to existing fields require a major
    375 * version bump.
    376 * You can use AVOptions (av_opt* / av_set/get*()) to access these fields from
    377 * user applications. The name string for AVOptions options matches the
    378 * associated command line parameter name and can be found in
    379 * libavcodec/options_table.h The AVOption/command line parameter names differ
    380 * in some cases from the C structure field names for historic reasons or
    381 * brevity. sizeof(AVCodecContext) must not be used outside libav*.
    382 */
    383 typedef struct AVCodecContext {
    384  /**
    385   * information on struct for av_log
    386   * - set by avcodec_alloc_context3
    387   */
    388  const AVClass* av_class;
    389  int log_level_offset;
    390 
    391  enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
    392  const struct AVCodec* codec;
    393  enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
    394 
    395  /**
    396   * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
    397   * This is used to work around some encoder bugs.
    398   * A demuxer should set this to what is stored in the field used to identify
    399   * the codec. If there are multiple such fields in a container then the
    400   * demuxer should choose the one which maximizes the information about the
    401   * used codec. If the codec tag field in a container is larger than 32 bits
    402   * then the demuxer should remap the longer ID to 32 bits with a table or
    403   * other structure. Alternatively a new extra_codec_tag + size could be added
    404   * but for this a clear advantage must be demonstrated first.
    405   * - encoding: Set by user, if not then the default based on codec_id will be
    406   * used.
    407   * - decoding: Set by user, will be converted to uppercase by libavcodec
    408   * during init.
    409   */
    410  unsigned int codec_tag;
    411 
    412  void* priv_data;
    413 
    414  /**
    415   * Private context used for internal data.
    416   *
    417   * Unlike priv_data, this is not codec-specific. It is used in general
    418   * libavcodec functions.
    419   */
    420  struct AVCodecInternal* internal;
    421 
    422  /**
    423   * Private data of the user, can be used to carry app specific stuff.
    424   * - encoding: Set by user.
    425   * - decoding: Set by user.
    426   */
    427  void* opaque;
    428 
    429  /**
    430   * the average bitrate
    431   * - encoding: Set by user; unused for constant quantizer encoding.
    432   * - decoding: Set by user, may be overwritten by libavcodec
    433   *             if this info is available in the stream
    434   */
    435  int64_t bit_rate;
    436 
    437  /**
    438   * number of bits the bitstream is allowed to diverge from the reference.
    439   *           the reference can be CBR (for CBR pass1) or VBR (for pass2)
    440   * - encoding: Set by user; unused for constant quantizer encoding.
    441   * - decoding: unused
    442   */
    443  int bit_rate_tolerance;
    444 
    445  /**
    446   * Global quality for codecs which cannot change it per frame.
    447   * This should be proportional to MPEG-1/2/4 qscale.
    448   * - encoding: Set by user.
    449   * - decoding: unused
    450   */
    451  int global_quality;
    452 
    453  /**
    454   * - encoding: Set by user.
    455   * - decoding: unused
    456   */
    457  int compression_level;
    458 #define FF_COMPRESSION_DEFAULT -1
    459 
    460  /**
    461   * AV_CODEC_FLAG_*.
    462   * - encoding: Set by user.
    463   * - decoding: Set by user.
    464   */
    465  int flags;
    466 
    467  /**
    468   * AV_CODEC_FLAG2_*
    469   * - encoding: Set by user.
    470   * - decoding: Set by user.
    471   */
    472  int flags2;
    473 
    474  /**
    475   * some codecs need / can use extradata like Huffman tables.
    476   * MJPEG: Huffman tables
    477   * rv10: additional flags
    478   * MPEG-4: global headers (they can be in the bitstream or here)
    479   * The allocated memory should be AV_INPUT_BUFFER_PADDING_SIZE bytes larger
    480   * than extradata_size to avoid problems if it is read with the bitstream
    481   * reader. The bytewise contents of extradata must not depend on the
    482   * architecture or CPU endianness. Must be allocated with the av_malloc()
    483   * family of functions.
    484   * - encoding: Set/allocated/freed by libavcodec.
    485   * - decoding: Set/allocated/freed by user.
    486   */
    487  uint8_t* extradata;
    488  int extradata_size;
    489 
    490  /**
    491   * This is the fundamental unit of time (in seconds) in terms
    492   * of which frame timestamps are represented. For fixed-fps content,
    493   * timebase should be 1/framerate and timestamp increments should be
    494   * identically 1.
    495   * This often, but not always is the inverse of the frame rate or field rate
    496   * for video. 1/time_base is not the average frame rate if the frame rate is
    497   * not constant.
    498   *
    499   * Like containers, elementary streams also can store timestamps, 1/time_base
    500   * is the unit in which these timestamps are specified.
    501   * As example of such codec time base see ISO/IEC 14496-2:2001(E)
    502   * vop_time_increment_resolution and fixed_vop_rate
    503   * (fixed_vop_rate == 0 implies that it is different from the framerate)
    504   *
    505   * - encoding: MUST be set by user.
    506   * - decoding: the use of this field for decoding is deprecated.
    507   *             Use framerate instead.
    508   */
    509  AVRational time_base;
    510 
    511  /**
    512   * For some codecs, the time base is closer to the field rate than the frame
    513   * rate. Most notably, H.264 and MPEG-2 specify time_base as half of frame
    514   * duration if no telecine is used ...
    515   *
    516   * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it
    517   * to 2.
    518   */
    519  int ticks_per_frame;
    520 
    521  /**
    522   * Codec delay.
    523   *
    524   * Encoding: Number of frames delay there will be from the encoder input to
    525   *           the decoder output. (we assume the decoder matches the spec)
    526   * Decoding: Number of frames delay in addition to what a standard decoder
    527   *           as specified in the spec would produce.
    528   *
    529   * Video:
    530   *   Number of frames the decoded output will be delayed relative to the
    531   *   encoded input.
    532   *
    533   * Audio:
    534   *   For encoding, this field is unused (see initial_padding).
    535   *
    536   *   For decoding, this is the number of samples the decoder needs to
    537   *   output before the decoder's output is valid. When seeking, you should
    538   *   start decoding this many samples prior to your desired seek point.
    539   *
    540   * - encoding: Set by libavcodec.
    541   * - decoding: Set by libavcodec.
    542   */
    543  int delay;
    544 
    545  /* video only */
    546  /**
    547   * picture width / height.
    548   *
    549   * @note Those fields may not match the values of the last
    550   * AVFrame output by avcodec_receive_frame() due frame
    551   * reordering.
    552   *
    553   * - encoding: MUST be set by user.
    554   * - decoding: May be set by the user before opening the decoder if known e.g.
    555   *             from the container. Some decoders will require the dimensions
    556   *             to be set by the caller. During decoding, the decoder may
    557   *             overwrite those values as required while parsing the data.
    558   */
    559  int width, height;
    560 
    561  /**
    562   * Bitstream width / height, may be different from width/height e.g. when
    563   * the decoded frame is cropped before being output or lowres is enabled.
    564   *
    565   * @note Those field may not match the value of the last
    566   * AVFrame output by avcodec_receive_frame() due frame
    567   * reordering.
    568   *
    569   * - encoding: unused
    570   * - decoding: May be set by the user before opening the decoder if known
    571   *             e.g. from the container. During decoding, the decoder may
    572   *             overwrite those values as required while parsing the data.
    573   */
    574  int coded_width, coded_height;
    575 
    576  /**
    577   * the number of pictures in a group of pictures, or 0 for intra_only
    578   * - encoding: Set by user.
    579   * - decoding: unused
    580   */
    581  int gop_size;
    582 
    583  /**
    584   * Pixel format, see AV_PIX_FMT_xxx.
    585   * May be set by the demuxer if known from headers.
    586   * May be overridden by the decoder if it knows better.
    587   *
    588   * @note This field may not match the value of the last
    589   * AVFrame output by avcodec_receive_frame() due frame
    590   * reordering.
    591   *
    592   * - encoding: Set by user.
    593   * - decoding: Set by user if known, overridden by libavcodec while
    594   *             parsing the data.
    595   */
    596  enum AVPixelFormat pix_fmt;
    597 
    598  /**
    599   * If non NULL, 'draw_horiz_band' is called by the libavcodec
    600   * decoder to draw a horizontal band. It improves cache usage. Not
    601   * all codecs can do that. You must check the codec capabilities
    602   * beforehand.
    603   * When multithreading is used, it may be called from multiple threads
    604   * at the same time; threads might draw different parts of the same AVFrame,
    605   * or multiple AVFrames, and there is no guarantee that slices will be drawn
    606   * in order.
    607   * The function is also used by hardware acceleration APIs.
    608   * It is called at least once during frame decoding to pass
    609   * the data needed for hardware render.
    610   * In that mode instead of pixel data, AVFrame points to
    611   * a structure specific to the acceleration API. The application
    612   * reads the structure and can change some fields to indicate progress
    613   * or mark state.
    614   * - encoding: unused
    615   * - decoding: Set by user.
    616   * @param height the height of the slice
    617   * @param y the y position of the slice
    618   * @param type 1->top field, 2->bottom field, 3->frame
    619   * @param offset offset into the AVFrame.data from which the slice should be
    620   * read
    621   */
    622  void (*draw_horiz_band)(struct AVCodecContext* s, const AVFrame* src,
    623                          int offset[AV_NUM_DATA_POINTERS], int y, int type,
    624                          int height);
    625 
    626  /**
    627   * Callback to negotiate the pixel format. Decoding only, may be set by the
    628   * caller before avcodec_open2().
    629   *
    630   * Called by some decoders to select the pixel format that will be used for
    631   * the output frames. This is mainly used to set up hardware acceleration,
    632   * then the provided format list contains the corresponding hwaccel pixel
    633   * formats alongside the "software" one. The software pixel format may also
    634   * be retrieved from \ref sw_pix_fmt.
    635   *
    636   * This callback will be called when the coded frame properties (such as
    637   * resolution, pixel format, etc.) change and more than one output format is
    638   * supported for those new properties. If a hardware pixel format is chosen
    639   * and initialization for it fails, the callback may be called again
    640   * immediately.
    641   *
    642   * This callback may be called from different threads if the decoder is
    643   * multi-threaded, but not from more than one thread simultaneously.
    644   *
    645   * @param fmt list of formats which may be used in the current
    646   *            configuration, terminated by AV_PIX_FMT_NONE.
    647   * @warning Behavior is undefined if the callback returns a value other
    648   *          than one of the formats in fmt or AV_PIX_FMT_NONE.
    649   * @return the chosen format or AV_PIX_FMT_NONE
    650   */
    651  enum AVPixelFormat (*get_format)(struct AVCodecContext* s,
    652                                   const enum AVPixelFormat* fmt);
    653 
    654  /**
    655   * maximum number of B-frames between non-B-frames
    656   * Note: The output will be delayed by max_b_frames+1 relative to the input.
    657   * - encoding: Set by user.
    658   * - decoding: unused
    659   */
    660  int max_b_frames;
    661 
    662  /**
    663   * qscale factor between IP and B-frames
    664   * If > 0 then the last P-frame quantizer will be used (q=
    665   * lastp_q*factor+offset). If < 0 then normal ratecontrol will be done (q=
    666   * -normal_q*factor+offset).
    667   * - encoding: Set by user.
    668   * - decoding: unused
    669   */
    670  float b_quant_factor;
    671 
    672  /**
    673   * qscale offset between IP and B-frames
    674   * - encoding: Set by user.
    675   * - decoding: unused
    676   */
    677  float b_quant_offset;
    678 
    679  /**
    680   * Size of the frame reordering buffer in the decoder.
    681   * For MPEG-2 it is 1 IPB or 0 low delay IP.
    682   * - encoding: Set by libavcodec.
    683   * - decoding: Set by libavcodec.
    684   */
    685  int has_b_frames;
    686 
    687  /**
    688   * qscale factor between P- and I-frames
    689   * If > 0 then the last P-frame quantizer will be used (q = lastp_q * factor +
    690   * offset). If < 0 then normal ratecontrol will be done (q=
    691   * -normal_q*factor+offset).
    692   * - encoding: Set by user.
    693   * - decoding: unused
    694   */
    695  float i_quant_factor;
    696 
    697  /**
    698   * qscale offset between P and I-frames
    699   * - encoding: Set by user.
    700   * - decoding: unused
    701   */
    702  float i_quant_offset;
    703 
    704  /**
    705   * luminance masking (0-> disabled)
    706   * - encoding: Set by user.
    707   * - decoding: unused
    708   */
    709  float lumi_masking;
    710 
    711  /**
    712   * temporary complexity masking (0-> disabled)
    713   * - encoding: Set by user.
    714   * - decoding: unused
    715   */
    716  float temporal_cplx_masking;
    717 
    718  /**
    719   * spatial complexity masking (0-> disabled)
    720   * - encoding: Set by user.
    721   * - decoding: unused
    722   */
    723  float spatial_cplx_masking;
    724 
    725  /**
    726   * p block masking (0-> disabled)
    727   * - encoding: Set by user.
    728   * - decoding: unused
    729   */
    730  float p_masking;
    731 
    732  /**
    733   * darkness masking (0-> disabled)
    734   * - encoding: Set by user.
    735   * - decoding: unused
    736   */
    737  float dark_masking;
    738 
    739  /**
    740   * slice count
    741   * - encoding: Set by libavcodec.
    742   * - decoding: Set by user (or 0).
    743   */
    744  int slice_count;
    745 
    746  /**
    747   * slice offsets in the frame in bytes
    748   * - encoding: Set/allocated by libavcodec.
    749   * - decoding: Set/allocated by user (or NULL).
    750   */
    751  int* slice_offset;
    752 
    753  /**
    754   * sample aspect ratio (0 if unknown)
    755   * That is the width of a pixel divided by the height of the pixel.
    756   * Numerator and denominator must be relatively prime and smaller than 256 for
    757   * some video standards.
    758   * - encoding: Set by user.
    759   * - decoding: Set by libavcodec.
    760   */
    761  AVRational sample_aspect_ratio;
    762 
    763  /**
    764   * motion estimation comparison function
    765   * - encoding: Set by user.
    766   * - decoding: unused
    767   */
    768  int me_cmp;
    769  /**
    770   * subpixel motion estimation comparison function
    771   * - encoding: Set by user.
    772   * - decoding: unused
    773   */
    774  int me_sub_cmp;
    775  /**
    776   * macroblock comparison function (not supported yet)
    777   * - encoding: Set by user.
    778   * - decoding: unused
    779   */
    780  int mb_cmp;
    781  /**
    782   * interlaced DCT comparison function
    783   * - encoding: Set by user.
    784   * - decoding: unused
    785   */
    786  int ildct_cmp;
    787 #define FF_CMP_SAD 0
    788 #define FF_CMP_SSE 1
    789 #define FF_CMP_SATD 2
    790 #define FF_CMP_DCT 3
    791 #define FF_CMP_PSNR 4
    792 #define FF_CMP_BIT 5
    793 #define FF_CMP_RD 6
    794 #define FF_CMP_ZERO 7
    795 #define FF_CMP_VSAD 8
    796 #define FF_CMP_VSSE 9
    797 #define FF_CMP_NSSE 10
    798 #define FF_CMP_W53 11
    799 #define FF_CMP_W97 12
    800 #define FF_CMP_DCTMAX 13
    801 #define FF_CMP_DCT264 14
    802 #define FF_CMP_MEDIAN_SAD 15
    803 #define FF_CMP_CHROMA 256
    804 
    805  /**
    806   * ME diamond size & shape
    807   * - encoding: Set by user.
    808   * - decoding: unused
    809   */
    810  int dia_size;
    811 
    812  /**
    813   * amount of previous MV predictors (2a+1 x 2a+1 square)
    814   * - encoding: Set by user.
    815   * - decoding: unused
    816   */
    817  int last_predictor_count;
    818 
    819  /**
    820   * motion estimation prepass comparison function
    821   * - encoding: Set by user.
    822   * - decoding: unused
    823   */
    824  int me_pre_cmp;
    825 
    826  /**
    827   * ME prepass diamond size & shape
    828   * - encoding: Set by user.
    829   * - decoding: unused
    830   */
    831  int pre_dia_size;
    832 
    833  /**
    834   * subpel ME quality
    835   * - encoding: Set by user.
    836   * - decoding: unused
    837   */
    838  int me_subpel_quality;
    839 
    840  /**
    841   * maximum motion estimation search range in subpel units
    842   * If 0 then no limit.
    843   *
    844   * - encoding: Set by user.
    845   * - decoding: unused
    846   */
    847  int me_range;
    848 
    849  /**
    850   * slice flags
    851   * - encoding: unused
    852   * - decoding: Set by user.
    853   */
    854  int slice_flags;
    855 #define SLICE_FLAG_CODED_ORDER \
    856  0x0001  ///< draw_horiz_band() is called in coded order instead of display
    857 #define SLICE_FLAG_ALLOW_FIELD \
    858  0x0002  ///< allow draw_horiz_band() with field slices (MPEG-2 field pics)
    859 #define SLICE_FLAG_ALLOW_PLANE \
    860  0x0004  ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
    861 
    862  /**
    863   * macroblock decision mode
    864   * - encoding: Set by user.
    865   * - decoding: unused
    866   */
    867  int mb_decision;
    868 #define FF_MB_DECISION_SIMPLE 0  ///< uses mb_cmp
    869 #define FF_MB_DECISION_BITS 1  ///< chooses the one which needs the fewest bits
    870 #define FF_MB_DECISION_RD 2    ///< rate distortion
    871 
    872  /**
    873   * custom intra quantization matrix
    874   * Must be allocated with the av_malloc() family of functions, and will be
    875   * freed in avcodec_free_context().
    876   * - encoding: Set/allocated by user, freed by libavcodec. Can be NULL.
    877   * - decoding: Set/allocated/freed by libavcodec.
    878   */
    879  uint16_t* intra_matrix;
    880 
    881  /**
    882   * custom inter quantization matrix
    883   * Must be allocated with the av_malloc() family of functions, and will be
    884   * freed in avcodec_free_context().
    885   * - encoding: Set/allocated by user, freed by libavcodec. Can be NULL.
    886   * - decoding: Set/allocated/freed by libavcodec.
    887   */
    888  uint16_t* inter_matrix;
    889 
    890  /**
    891   * precision of the intra DC coefficient - 8
    892   * - encoding: Set by user.
    893   * - decoding: Set by libavcodec
    894   */
    895  int intra_dc_precision;
    896 
    897  /**
    898   * Number of macroblock rows at the top which are skipped.
    899   * - encoding: unused
    900   * - decoding: Set by user.
    901   */
    902  int skip_top;
    903 
    904  /**
    905   * Number of macroblock rows at the bottom which are skipped.
    906   * - encoding: unused
    907   * - decoding: Set by user.
    908   */
    909  int skip_bottom;
    910 
    911  /**
    912   * minimum MB Lagrange multiplier
    913   * - encoding: Set by user.
    914   * - decoding: unused
    915   */
    916  int mb_lmin;
    917 
    918  /**
    919   * maximum MB Lagrange multiplier
    920   * - encoding: Set by user.
    921   * - decoding: unused
    922   */
    923  int mb_lmax;
    924 
    925  /**
    926   * - encoding: Set by user.
    927   * - decoding: unused
    928   */
    929  int bidir_refine;
    930 
    931  /**
    932   * minimum GOP size
    933   * - encoding: Set by user.
    934   * - decoding: unused
    935   */
    936  int keyint_min;
    937 
    938  /**
    939   * number of reference frames
    940   * - encoding: Set by user.
    941   * - decoding: Set by lavc.
    942   */
    943  int refs;
    944 
    945  /**
    946   * Note: Value depends upon the compare function used for fullpel ME.
    947   * - encoding: Set by user.
    948   * - decoding: unused
    949   */
    950  int mv0_threshold;
    951 
    952  /**
    953   * Chromaticity coordinates of the source primaries.
    954   * - encoding: Set by user
    955   * - decoding: Set by libavcodec
    956   */
    957  enum AVColorPrimaries color_primaries;
    958 
    959  /**
    960   * Color Transfer Characteristic.
    961   * - encoding: Set by user
    962   * - decoding: Set by libavcodec
    963   */
    964  enum AVColorTransferCharacteristic color_trc;
    965 
    966  /**
    967   * YUV colorspace type.
    968   * - encoding: Set by user
    969   * - decoding: Set by libavcodec
    970   */
    971  enum AVColorSpace colorspace;
    972 
    973  /**
    974   * MPEG vs JPEG YUV range.
    975   * - encoding: Set by user
    976   * - decoding: Set by libavcodec
    977   */
    978  enum AVColorRange color_range;
    979 
    980  /**
    981   * This defines the location of chroma samples.
    982   * - encoding: Set by user
    983   * - decoding: Set by libavcodec
    984   */
    985  enum AVChromaLocation chroma_sample_location;
    986 
    987  /**
    988   * Number of slices.
    989   * Indicates number of picture subdivisions. Used for parallelized
    990   * decoding.
    991   * - encoding: Set by user
    992   * - decoding: unused
    993   */
    994  int slices;
    995 
    996  /** Field order
    997   * - encoding: set by libavcodec
    998   * - decoding: Set by user.
    999   */
   1000  enum AVFieldOrder field_order;
   1001 
   1002  /* audio only */
   1003  int sample_rate;  ///< samples per second
   1004  int channels;     ///< number of audio channels
   1005 
   1006  /**
   1007   * audio sample format
   1008   * - encoding: Set by user.
   1009   * - decoding: Set by libavcodec.
   1010   */
   1011  enum AVSampleFormat sample_fmt;  ///< sample format
   1012 
   1013  /* The following data should not be initialized. */
   1014  /**
   1015   * Number of samples per channel in an audio frame.
   1016   *
   1017   * - encoding: set by libavcodec in avcodec_open2(). Each submitted frame
   1018   *   except the last must contain exactly frame_size samples per channel.
   1019   *   May be 0 when the codec has AV_CODEC_CAP_VARIABLE_FRAME_SIZE set, then
   1020   * the frame size is not restricted.
   1021   * - decoding: may be set by some decoders to indicate constant frame size
   1022   */
   1023  int frame_size;
   1024 
   1025  /**
   1026   * Frame counter, set by libavcodec.
   1027   *
   1028   * - decoding: total number of frames returned from the decoder so far.
   1029   * - encoding: total number of frames passed to the encoder so far.
   1030   *
   1031   *   @note the counter is not incremented if encoding/decoding resulted in
   1032   *   an error.
   1033   */
   1034  int frame_number;
   1035 
   1036  /**
   1037   * number of bytes per packet if constant and known or 0
   1038   * Used by some WAV based audio codecs.
   1039   */
   1040  int block_align;
   1041 
   1042  /**
   1043   * Audio cutoff bandwidth (0 means "automatic")
   1044   * - encoding: Set by user.
   1045   * - decoding: unused
   1046   */
   1047  int cutoff;
   1048 
   1049  /**
   1050   * Audio channel layout.
   1051   * - encoding: set by user.
   1052   * - decoding: set by user, may be overwritten by libavcodec.
   1053   */
   1054  uint64_t channel_layout;
   1055 
   1056  /**
   1057   * Request decoder to use this channel layout if it can (0 for default)
   1058   * - encoding: unused
   1059   * - decoding: Set by user.
   1060   */
   1061  uint64_t request_channel_layout;
   1062 
   1063  /**
   1064   * Type of service that the audio stream conveys.
   1065   * - encoding: Set by user.
   1066   * - decoding: Set by libavcodec.
   1067   */
   1068  enum AVAudioServiceType audio_service_type;
   1069 
   1070  /**
   1071   * desired sample format
   1072   * - encoding: Not used.
   1073   * - decoding: Set by user.
   1074   * Decoder will decode to this format if it can.
   1075   */
   1076  enum AVSampleFormat request_sample_fmt;
   1077 
   1078  /**
   1079   * This callback is called at the beginning of each frame to get data
   1080   * buffer(s) for it. There may be one contiguous buffer for all the data or
   1081   * there may be a buffer per each data plane or anything in between. What
   1082   * this means is, you may set however many entries in buf[] you feel
   1083   * necessary. Each buffer must be reference-counted using the AVBuffer API
   1084   * (see description of buf[] below).
   1085   *
   1086   * The following fields will be set in the frame before this callback is
   1087   * called:
   1088   * - format
   1089   * - width, height (video only)
   1090   * - sample_rate, channel_layout, nb_samples (audio only)
   1091   * Their values may differ from the corresponding values in
   1092   * AVCodecContext. This callback must use the frame values, not the codec
   1093   * context values, to calculate the required buffer size.
   1094   *
   1095   * This callback must fill the following fields in the frame:
   1096   * - data[]
   1097   * - linesize[]
   1098   * - extended_data:
   1099   *   * if the data is planar audio with more than 8 channels, then this
   1100   *     callback must allocate and fill extended_data to contain all pointers
   1101   *     to all data planes. data[] must hold as many pointers as it can.
   1102   *     extended_data must be allocated with av_malloc() and will be freed in
   1103   *     av_frame_unref().
   1104   *   * otherwise extended_data must point to data
   1105   * - buf[] must contain one or more pointers to AVBufferRef structures. Each
   1106   * of the frame's data and extended_data pointers must be contained in these.
   1107   * That is, one AVBufferRef for each allocated chunk of memory, not
   1108   * necessarily one AVBufferRef per data[] entry. See: av_buffer_create(),
   1109   * av_buffer_alloc(), and av_buffer_ref().
   1110   * - extended_buf and nb_extended_buf must be allocated with av_malloc() by
   1111   *   this callback and filled with the extra buffers if there are more
   1112   *   buffers than buf[] can hold. extended_buf will be freed in
   1113   *   av_frame_unref().
   1114   *
   1115   * If AV_CODEC_CAP_DR1 is not set then get_buffer2() must call
   1116   * avcodec_default_get_buffer2() instead of providing buffers allocated by
   1117   * some other means.
   1118   *
   1119   * Each data plane must be aligned to the maximum required by the target
   1120   * CPU.
   1121   *
   1122   * @see avcodec_default_get_buffer2()
   1123   *
   1124   * Video:
   1125   *
   1126   * If AV_GET_BUFFER_FLAG_REF is set in flags then the frame may be reused
   1127   * (read and/or written to if it is writable) later by libavcodec.
   1128   *
   1129   * avcodec_align_dimensions2() should be used to find the required width and
   1130   * height, as they normally need to be rounded up to the next multiple of 16.
   1131   *
   1132   * Some decoders do not support linesizes changing between frames.
   1133   *
   1134   * If frame multithreading is used, this callback may be called from a
   1135   * different thread, but not from more than one at once. Does not need to be
   1136   * reentrant.
   1137   *
   1138   * @see avcodec_align_dimensions2()
   1139   *
   1140   * Audio:
   1141   *
   1142   * Decoders request a buffer of a particular size by setting
   1143   * AVFrame.nb_samples prior to calling get_buffer2(). The decoder may,
   1144   * however, utilize only part of the buffer by setting AVFrame.nb_samples
   1145   * to a smaller value in the output frame.
   1146   *
   1147   * As a convenience, av_samples_get_buffer_size() and
   1148   * av_samples_fill_arrays() in libavutil may be used by custom get_buffer2()
   1149   * functions to find the required data size and to fill data pointers and
   1150   * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
   1151   * since all planes must be the same size.
   1152   *
   1153   * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
   1154   *
   1155   * - encoding: unused
   1156   * - decoding: Set by libavcodec, user can override.
   1157   */
   1158  int (*get_buffer2)(struct AVCodecContext* s, AVFrame* frame, int flags);
   1159 
   1160  /* - encoding parameters */
   1161  float qcompress;  ///< amount of qscale change between easy & hard scenes
   1162                    ///< (0.0-1.0)
   1163  float qblur;      ///< amount of qscale smoothing over time (0.0-1.0)
   1164 
   1165  /**
   1166   * minimum quantizer
   1167   * - encoding: Set by user.
   1168   * - decoding: unused
   1169   */
   1170  int qmin;
   1171 
   1172  /**
   1173   * maximum quantizer
   1174   * - encoding: Set by user.
   1175   * - decoding: unused
   1176   */
   1177  int qmax;
   1178 
   1179  /**
   1180   * maximum quantizer difference between frames
   1181   * - encoding: Set by user.
   1182   * - decoding: unused
   1183   */
   1184  int max_qdiff;
   1185 
   1186  /**
   1187   * decoder bitstream buffer size
   1188   * - encoding: Set by user.
   1189   * - decoding: unused
   1190   */
   1191  int rc_buffer_size;
   1192 
   1193  /**
   1194   * ratecontrol override, see RcOverride
   1195   * - encoding: Allocated/set/freed by user.
   1196   * - decoding: unused
   1197   */
   1198  int rc_override_count;
   1199  RcOverride* rc_override;
   1200 
   1201  /**
   1202   * maximum bitrate
   1203   * - encoding: Set by user.
   1204   * - decoding: Set by user, may be overwritten by libavcodec.
   1205   */
   1206  int64_t rc_max_rate;
   1207 
   1208  /**
   1209   * minimum bitrate
   1210   * - encoding: Set by user.
   1211   * - decoding: unused
   1212   */
   1213  int64_t rc_min_rate;
   1214 
   1215  /**
   1216   * Ratecontrol attempt to use, at maximum, <value> of what can be used without
   1217   * an underflow.
   1218   * - encoding: Set by user.
   1219   * - decoding: unused.
   1220   */
   1221  float rc_max_available_vbv_use;
   1222 
   1223  /**
   1224   * Ratecontrol attempt to use, at least, <value> times the amount needed to
   1225   * prevent a vbv overflow.
   1226   * - encoding: Set by user.
   1227   * - decoding: unused.
   1228   */
   1229  float rc_min_vbv_overflow_use;
   1230 
   1231  /**
   1232   * Number of bits which should be loaded into the rc buffer before decoding
   1233   * starts.
   1234   * - encoding: Set by user.
   1235   * - decoding: unused
   1236   */
   1237  int rc_initial_buffer_occupancy;
   1238 
   1239  /**
   1240   * trellis RD quantization
   1241   * - encoding: Set by user.
   1242   * - decoding: unused
   1243   */
   1244  int trellis;
   1245 
   1246  /**
   1247   * pass1 encoding statistics output buffer
   1248   * - encoding: Set by libavcodec.
   1249   * - decoding: unused
   1250   */
   1251  char* stats_out;
   1252 
   1253  /**
   1254   * pass2 encoding statistics input buffer
   1255   * Concatenated stuff from stats_out of pass1 should be placed here.
   1256   * - encoding: Allocated/set/freed by user.
   1257   * - decoding: unused
   1258   */
   1259  char* stats_in;
   1260 
   1261  /**
   1262   * Work around bugs in encoders which sometimes cannot be detected
   1263   * automatically.
   1264   * - encoding: Set by user
   1265   * - decoding: Set by user
   1266   */
   1267  int workaround_bugs;
   1268 #define FF_BUG_AUTODETECT 1  ///< autodetection
   1269 #define FF_BUG_XVID_ILACE 4
   1270 #define FF_BUG_UMP4 8
   1271 #define FF_BUG_NO_PADDING 16
   1272 #define FF_BUG_AMV 32
   1273 #define FF_BUG_QPEL_CHROMA 64
   1274 #define FF_BUG_STD_QPEL 128
   1275 #define FF_BUG_QPEL_CHROMA2 256
   1276 #define FF_BUG_DIRECT_BLOCKSIZE 512
   1277 #define FF_BUG_EDGE 1024
   1278 #define FF_BUG_HPEL_CHROMA 2048
   1279 #define FF_BUG_DC_CLIP 4096
   1280 #define FF_BUG_MS \
   1281  8192  ///< Work around various bugs in Microsoft's broken decoders.
   1282 #define FF_BUG_TRUNCATED 16384
   1283 #define FF_BUG_IEDGE 32768
   1284 
   1285  /**
   1286   * strictly follow the standard (MPEG-4, ...).
   1287   * - encoding: Set by user.
   1288   * - decoding: Set by user.
   1289   * Setting this to STRICT or higher means the encoder and decoder will
   1290   * generally do stupid things, whereas setting it to unofficial or lower
   1291   * will mean the encoder might produce output that is not supported by all
   1292   * spec-compliant decoders. Decoders don't differentiate between normal,
   1293   * unofficial and experimental (that is, they always try to decode things
   1294   * when they can) unless they are explicitly asked to behave stupidly
   1295   * (=strictly conform to the specs)
   1296   */
   1297  int strict_std_compliance;
   1298 #define FF_COMPLIANCE_VERY_STRICT \
   1299  2  ///< Strictly conform to an older more strict version of the spec or
   1300     ///< reference software.
   1301 #define FF_COMPLIANCE_STRICT \
   1302  1  ///< Strictly conform to all the things in the spec no matter what
   1303     ///< consequences.
   1304 #define FF_COMPLIANCE_NORMAL 0
   1305 #define FF_COMPLIANCE_UNOFFICIAL -1  ///< Allow unofficial extensions
   1306 #define FF_COMPLIANCE_EXPERIMENTAL \
   1307  -2  ///< Allow nonstandardized experimental things.
   1308 
   1309  /**
   1310   * error concealment flags
   1311   * - encoding: unused
   1312   * - decoding: Set by user.
   1313   */
   1314  int error_concealment;
   1315 #define FF_EC_GUESS_MVS 1
   1316 #define FF_EC_DEBLOCK 2
   1317 #define FF_EC_FAVOR_INTER 256
   1318 
   1319  /**
   1320   * debug
   1321   * - encoding: Set by user.
   1322   * - decoding: Set by user.
   1323   */
   1324  int debug;
   1325 #define FF_DEBUG_PICT_INFO 1
   1326 #define FF_DEBUG_RC 2
   1327 #define FF_DEBUG_BITSTREAM 4
   1328 #define FF_DEBUG_MB_TYPE 8
   1329 #define FF_DEBUG_QP 16
   1330 #define FF_DEBUG_DCT_COEFF 0x00000040
   1331 #define FF_DEBUG_SKIP 0x00000080
   1332 #define FF_DEBUG_STARTCODE 0x00000100
   1333 #define FF_DEBUG_ER 0x00000400
   1334 #define FF_DEBUG_MMCO 0x00000800
   1335 #define FF_DEBUG_BUGS 0x00001000
   1336 #define FF_DEBUG_BUFFERS 0x00008000
   1337 #define FF_DEBUG_THREADS 0x00010000
   1338 #define FF_DEBUG_GREEN_MD 0x00800000
   1339 #define FF_DEBUG_NOMC 0x01000000
   1340 
   1341  /**
   1342   * Error recognition; may misdetect some more or less valid parts as errors.
   1343   * - encoding: Set by user.
   1344   * - decoding: Set by user.
   1345   */
   1346  int err_recognition;
   1347 
   1348 /**
   1349 * Verify checksums embedded in the bitstream (could be of either encoded or
   1350 * decoded data, depending on the codec) and print an error message on mismatch.
   1351 * If AV_EF_EXPLODE is also set, a mismatching checksum will result in the
   1352 * decoder returning an error.
   1353 */
   1354 #define AV_EF_CRCCHECK (1 << 0)
   1355 #define AV_EF_BITSTREAM (1 << 1)  ///< detect bitstream specification deviations
   1356 #define AV_EF_BUFFER (1 << 2)     ///< detect improper bitstream length
   1357 #define AV_EF_EXPLODE (1 << 3)    ///< abort decoding on minor error detection
   1358 
   1359 #define AV_EF_IGNORE_ERR (1 << 15)  ///< ignore errors and continue
   1360 #define AV_EF_CAREFUL \
   1361  (1 << 16)  ///< consider things that violate the spec, are fast to calculate
   1362             ///< and have not been seen in the wild as errors
   1363 #define AV_EF_COMPLIANT \
   1364  (1 << 17)  ///< consider all spec non compliances as errors
   1365 #define AV_EF_AGGRESSIVE \
   1366  (1 << 18)  ///< consider things that a sane encoder should not do as an error
   1367 
   1368  /**
   1369   * opaque 64-bit number (generally a PTS) that will be reordered and
   1370   * output in AVFrame.reordered_opaque
   1371   * - encoding: Set by libavcodec to the reordered_opaque of the input
   1372   *             frame corresponding to the last returned packet. Only
   1373   *             supported by encoders with the
   1374   *             AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE capability.
   1375   * - decoding: Set by user.
   1376   */
   1377  int64_t reordered_opaque;
   1378 
   1379  /**
   1380   * Hardware accelerator in use
   1381   * - encoding: unused.
   1382   * - decoding: Set by libavcodec
   1383   */
   1384  const struct AVHWAccel* hwaccel;
   1385 
   1386  /**
   1387   * Hardware accelerator context.
   1388   * For some hardware accelerators, a global context needs to be
   1389   * provided by the user. In that case, this holds display-dependent
   1390   * data FFmpeg cannot instantiate itself. Please refer to the
   1391   * FFmpeg HW accelerator documentation to know how to fill this.
   1392   * - encoding: unused
   1393   * - decoding: Set by user
   1394   */
   1395  void* hwaccel_context;
   1396 
   1397  /**
   1398   * error
   1399   * - encoding: Set by libavcodec if flags & AV_CODEC_FLAG_PSNR.
   1400   * - decoding: unused
   1401   */
   1402  uint64_t error[AV_NUM_DATA_POINTERS];
   1403 
   1404  /**
   1405   * DCT algorithm, see FF_DCT_* below
   1406   * - encoding: Set by user.
   1407   * - decoding: unused
   1408   */
   1409  int dct_algo;
   1410 #define FF_DCT_AUTO 0
   1411 #define FF_DCT_FASTINT 1
   1412 #define FF_DCT_INT 2
   1413 #define FF_DCT_MMX 3
   1414 #define FF_DCT_ALTIVEC 5
   1415 #define FF_DCT_FAAN 6
   1416 
   1417  /**
   1418   * IDCT algorithm, see FF_IDCT_* below.
   1419   * - encoding: Set by user.
   1420   * - decoding: Set by user.
   1421   */
   1422  int idct_algo;
   1423 #define FF_IDCT_AUTO 0
   1424 #define FF_IDCT_INT 1
   1425 #define FF_IDCT_SIMPLE 2
   1426 #define FF_IDCT_SIMPLEMMX 3
   1427 #define FF_IDCT_ARM 7
   1428 #define FF_IDCT_ALTIVEC 8
   1429 #define FF_IDCT_SIMPLEARM 10
   1430 #define FF_IDCT_XVID 14
   1431 #define FF_IDCT_SIMPLEARMV5TE 16
   1432 #define FF_IDCT_SIMPLEARMV6 17
   1433 #define FF_IDCT_FAAN 20
   1434 #define FF_IDCT_SIMPLENEON 22
   1435 #define FF_IDCT_NONE \
   1436  24 /* Used by XvMC to extract IDCT coefficients with FF_IDCT_PERM_NONE */
   1437 #define FF_IDCT_SIMPLEAUTO 128
   1438 
   1439  /**
   1440   * bits per sample/pixel from the demuxer (needed for huffyuv).
   1441   * - encoding: Set by libavcodec.
   1442   * - decoding: Set by user.
   1443   */
   1444  int bits_per_coded_sample;
   1445 
   1446  /**
   1447   * Bits per sample/pixel of internal libavcodec pixel/sample format.
   1448   * - encoding: set by user.
   1449   * - decoding: set by libavcodec.
   1450   */
   1451  int bits_per_raw_sample;
   1452 
   1453  /**
   1454   * low resolution decoding, 1-> 1/2 size, 2->1/4 size
   1455   * - encoding: unused
   1456   * - decoding: Set by user.
   1457   */
   1458  int lowres;
   1459 
   1460  /**
   1461   * thread count
   1462   * is used to decide how many independent tasks should be passed to execute()
   1463   * - encoding: Set by user.
   1464   * - decoding: Set by user.
   1465   */
   1466  int thread_count;
   1467 
   1468  /**
   1469   * Which multithreading methods to use.
   1470   * Use of FF_THREAD_FRAME will increase decoding delay by one frame per
   1471   * thread, so clients which cannot provide future frames should not use it.
   1472   *
   1473   * - encoding: Set by user, otherwise the default is used.
   1474   * - decoding: Set by user, otherwise the default is used.
   1475   */
   1476  int thread_type;
   1477 #define FF_THREAD_FRAME 1  ///< Decode more than one frame at once
   1478 #define FF_THREAD_SLICE \
   1479  2  ///< Decode more than one part of a single frame at once
   1480 
   1481  /**
   1482   * Which multithreading methods are in use by the codec.
   1483   * - encoding: Set by libavcodec.
   1484   * - decoding: Set by libavcodec.
   1485   */
   1486  int active_thread_type;
   1487 
   1488 #if FF_API_THREAD_SAFE_CALLBACKS
   1489  /**
   1490   * Set by the client if its custom get_buffer() callback can be called
   1491   * synchronously from another thread, which allows faster multithreaded
   1492   * decoding. draw_horiz_band() will be called from other threads regardless of
   1493   * this setting. Ignored if the default get_buffer() is used.
   1494   * - encoding: Set by user.
   1495   * - decoding: Set by user.
   1496   *
   1497   * @deprecated the custom get_buffer2() callback should always be
   1498   *   thread-safe. Thread-unsafe get_buffer2() implementations will be
   1499   *   invalid starting with LIBAVCODEC_VERSION_MAJOR=60; in other words,
   1500   *   libavcodec will behave as if this field was always set to 1.
   1501   *   Callers that want to be forward compatible with future libavcodec
   1502   *   versions should wrap access to this field in
   1503   *     #if LIBAVCODEC_VERSION_MAJOR < 60
   1504   */
   1505  attribute_deprecated int thread_safe_callbacks;
   1506 #endif
   1507 
   1508  /**
   1509   * The codec may call this to execute several independent things.
   1510   * It will return only after finishing all tasks.
   1511   * The user may replace this with some multithreaded implementation,
   1512   * the default implementation will execute the parts serially.
   1513   * @param count the number of things to execute
   1514   * - encoding: Set by libavcodec, user can override.
   1515   * - decoding: Set by libavcodec, user can override.
   1516   */
   1517  int (*execute)(struct AVCodecContext* c,
   1518                 int (*func)(struct AVCodecContext* c2, void* arg), void* arg2,
   1519                 int* ret, int count, int size);
   1520 
   1521  /**
   1522   * The codec may call this to execute several independent things.
   1523   * It will return only after finishing all tasks.
   1524   * The user may replace this with some multithreaded implementation,
   1525   * the default implementation will execute the parts serially.
   1526   * Also see avcodec_thread_init and e.g. the --enable-pthread configure
   1527   * option.
   1528   * @param c context passed also to func
   1529   * @param count the number of things to execute
   1530   * @param arg2 argument passed unchanged to func
   1531   * @param ret return values of executed functions, must have space for "count"
   1532   * values. May be NULL.
   1533   * @param func function that will be called count times, with jobnr from 0 to
   1534   * count-1. threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS
   1535   * and so that no two instances of func executing at the same time will have
   1536   * the same threadnr.
   1537   * @return always 0 currently, but code should handle a future improvement
   1538   * where when any call to func returns < 0 no further calls to func may be
   1539   * done and < 0 is returned.
   1540   * - encoding: Set by libavcodec, user can override.
   1541   * - decoding: Set by libavcodec, user can override.
   1542   */
   1543  int (*execute2)(struct AVCodecContext* c,
   1544                  int (*func)(struct AVCodecContext* c2, void* arg, int jobnr,
   1545                              int threadnr),
   1546                  void* arg2, int* ret, int count);
   1547 
   1548  /**
   1549   * noise vs. sse weight for the nsse comparison function
   1550   * - encoding: Set by user.
   1551   * - decoding: unused
   1552   */
   1553  int nsse_weight;
   1554 
   1555  /**
   1556   * profile
   1557   * - encoding: Set by user.
   1558   * - decoding: Set by libavcodec.
   1559   */
   1560  int profile;
   1561 #define FF_PROFILE_UNKNOWN -99
   1562 #define FF_PROFILE_RESERVED -100
   1563 
   1564 #define FF_PROFILE_AAC_MAIN 0
   1565 #define FF_PROFILE_AAC_LOW 1
   1566 #define FF_PROFILE_AAC_SSR 2
   1567 #define FF_PROFILE_AAC_LTP 3
   1568 #define FF_PROFILE_AAC_HE 4
   1569 #define FF_PROFILE_AAC_HE_V2 28
   1570 #define FF_PROFILE_AAC_LD 22
   1571 #define FF_PROFILE_AAC_ELD 38
   1572 #define FF_PROFILE_MPEG2_AAC_LOW 128
   1573 #define FF_PROFILE_MPEG2_AAC_HE 131
   1574 
   1575 #define FF_PROFILE_DNXHD 0
   1576 #define FF_PROFILE_DNXHR_LB 1
   1577 #define FF_PROFILE_DNXHR_SQ 2
   1578 #define FF_PROFILE_DNXHR_HQ 3
   1579 #define FF_PROFILE_DNXHR_HQX 4
   1580 #define FF_PROFILE_DNXHR_444 5
   1581 
   1582 #define FF_PROFILE_DTS 20
   1583 #define FF_PROFILE_DTS_ES 30
   1584 #define FF_PROFILE_DTS_96_24 40
   1585 #define FF_PROFILE_DTS_HD_HRA 50
   1586 #define FF_PROFILE_DTS_HD_MA 60
   1587 #define FF_PROFILE_DTS_EXPRESS 70
   1588 
   1589 #define FF_PROFILE_MPEG2_422 0
   1590 #define FF_PROFILE_MPEG2_HIGH 1
   1591 #define FF_PROFILE_MPEG2_SS 2
   1592 #define FF_PROFILE_MPEG2_SNR_SCALABLE 3
   1593 #define FF_PROFILE_MPEG2_MAIN 4
   1594 #define FF_PROFILE_MPEG2_SIMPLE 5
   1595 
   1596 #define FF_PROFILE_H264_CONSTRAINED (1 << 9)  // 8+1; constraint_set1_flag
   1597 #define FF_PROFILE_H264_INTRA (1 << 11)       // 8+3; constraint_set3_flag
   1598 
   1599 #define FF_PROFILE_H264_BASELINE 66
   1600 #define FF_PROFILE_H264_CONSTRAINED_BASELINE (66 | FF_PROFILE_H264_CONSTRAINED)
   1601 #define FF_PROFILE_H264_MAIN 77
   1602 #define FF_PROFILE_H264_EXTENDED 88
   1603 #define FF_PROFILE_H264_HIGH 100
   1604 #define FF_PROFILE_H264_HIGH_10 110
   1605 #define FF_PROFILE_H264_HIGH_10_INTRA (110 | FF_PROFILE_H264_INTRA)
   1606 #define FF_PROFILE_H264_MULTIVIEW_HIGH 118
   1607 #define FF_PROFILE_H264_HIGH_422 122
   1608 #define FF_PROFILE_H264_HIGH_422_INTRA (122 | FF_PROFILE_H264_INTRA)
   1609 #define FF_PROFILE_H264_STEREO_HIGH 128
   1610 #define FF_PROFILE_H264_HIGH_444 144
   1611 #define FF_PROFILE_H264_HIGH_444_PREDICTIVE 244
   1612 #define FF_PROFILE_H264_HIGH_444_INTRA (244 | FF_PROFILE_H264_INTRA)
   1613 #define FF_PROFILE_H264_CAVLC_444 44
   1614 
   1615 #define FF_PROFILE_VC1_SIMPLE 0
   1616 #define FF_PROFILE_VC1_MAIN 1
   1617 #define FF_PROFILE_VC1_COMPLEX 2
   1618 #define FF_PROFILE_VC1_ADVANCED 3
   1619 
   1620 #define FF_PROFILE_MPEG4_SIMPLE 0
   1621 #define FF_PROFILE_MPEG4_SIMPLE_SCALABLE 1
   1622 #define FF_PROFILE_MPEG4_CORE 2
   1623 #define FF_PROFILE_MPEG4_MAIN 3
   1624 #define FF_PROFILE_MPEG4_N_BIT 4
   1625 #define FF_PROFILE_MPEG4_SCALABLE_TEXTURE 5
   1626 #define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6
   1627 #define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7
   1628 #define FF_PROFILE_MPEG4_HYBRID 8
   1629 #define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME 9
   1630 #define FF_PROFILE_MPEG4_CORE_SCALABLE 10
   1631 #define FF_PROFILE_MPEG4_ADVANCED_CODING 11
   1632 #define FF_PROFILE_MPEG4_ADVANCED_CORE 12
   1633 #define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
   1634 #define FF_PROFILE_MPEG4_SIMPLE_STUDIO 14
   1635 #define FF_PROFILE_MPEG4_ADVANCED_SIMPLE 15
   1636 
   1637 #define FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0 1
   1638 #define FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1 2
   1639 #define FF_PROFILE_JPEG2000_CSTREAM_NO_RESTRICTION 32768
   1640 #define FF_PROFILE_JPEG2000_DCINEMA_2K 3
   1641 #define FF_PROFILE_JPEG2000_DCINEMA_4K 4
   1642 
   1643 #define FF_PROFILE_VP9_0 0
   1644 #define FF_PROFILE_VP9_1 1
   1645 #define FF_PROFILE_VP9_2 2
   1646 #define FF_PROFILE_VP9_3 3
   1647 
   1648 #define FF_PROFILE_HEVC_MAIN 1
   1649 #define FF_PROFILE_HEVC_MAIN_10 2
   1650 #define FF_PROFILE_HEVC_MAIN_STILL_PICTURE 3
   1651 #define FF_PROFILE_HEVC_REXT 4
   1652 
   1653 #define FF_PROFILE_VVC_MAIN_10 1
   1654 #define FF_PROFILE_VVC_MAIN_10_444 33
   1655 
   1656 #define FF_PROFILE_AV1_MAIN 0
   1657 #define FF_PROFILE_AV1_HIGH 1
   1658 #define FF_PROFILE_AV1_PROFESSIONAL 2
   1659 
   1660 #define FF_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT 0xc0
   1661 #define FF_PROFILE_MJPEG_HUFFMAN_EXTENDED_SEQUENTIAL_DCT 0xc1
   1662 #define FF_PROFILE_MJPEG_HUFFMAN_PROGRESSIVE_DCT 0xc2
   1663 #define FF_PROFILE_MJPEG_HUFFMAN_LOSSLESS 0xc3
   1664 #define FF_PROFILE_MJPEG_JPEG_LS 0xf7
   1665 
   1666 #define FF_PROFILE_SBC_MSBC 1
   1667 
   1668 #define FF_PROFILE_PRORES_PROXY 0
   1669 #define FF_PROFILE_PRORES_LT 1
   1670 #define FF_PROFILE_PRORES_STANDARD 2
   1671 #define FF_PROFILE_PRORES_HQ 3
   1672 #define FF_PROFILE_PRORES_4444 4
   1673 #define FF_PROFILE_PRORES_XQ 5
   1674 
   1675 #define FF_PROFILE_ARIB_PROFILE_A 0
   1676 #define FF_PROFILE_ARIB_PROFILE_C 1
   1677 
   1678 #define FF_PROFILE_KLVA_SYNC 0
   1679 #define FF_PROFILE_KLVA_ASYNC 1
   1680 
   1681  /**
   1682   * level
   1683   * - encoding: Set by user.
   1684   * - decoding: Set by libavcodec.
   1685   */
   1686  int level;
   1687 #define FF_LEVEL_UNKNOWN -99
   1688 
   1689  /**
   1690   * Skip loop filtering for selected frames.
   1691   * - encoding: unused
   1692   * - decoding: Set by user.
   1693   */
   1694  enum AVDiscard skip_loop_filter;
   1695 
   1696  /**
   1697   * Skip IDCT/dequantization for selected frames.
   1698   * - encoding: unused
   1699   * - decoding: Set by user.
   1700   */
   1701  enum AVDiscard skip_idct;
   1702 
   1703  /**
   1704   * Skip decoding for selected frames.
   1705   * - encoding: unused
   1706   * - decoding: Set by user.
   1707   */
   1708  enum AVDiscard skip_frame;
   1709 
   1710  /**
   1711   * Header containing style information for text subtitles.
   1712   * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
   1713   * [Script Info] and [V4+ Styles] section, plus the [Events] line and
   1714   * the Format line following. It shouldn't include any Dialogue line.
   1715   * - encoding: Set/allocated/freed by user (before avcodec_open2())
   1716   * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2())
   1717   */
   1718  uint8_t* subtitle_header;
   1719  int subtitle_header_size;
   1720 
   1721  /**
   1722   * Audio only. The number of "priming" samples (padding) inserted by the
   1723   * encoder at the beginning of the audio. I.e. this number of leading
   1724   * decoded samples must be discarded by the caller to get the original audio
   1725   * without leading padding.
   1726   *
   1727   * - decoding: unused
   1728   * - encoding: Set by libavcodec. The timestamps on the output packets are
   1729   *             adjusted by the encoder so that they always refer to the
   1730   *             first sample of the data actually contained in the packet,
   1731   *             including any added padding.  E.g. if the timebase is
   1732   *             1/samplerate and the timestamp of the first input sample is
   1733   *             0, the timestamp of the first output packet will be
   1734   *             -initial_padding.
   1735   */
   1736  int initial_padding;
   1737 
   1738  /**
   1739   * - decoding: For codecs that store a framerate value in the compressed
   1740   *             bitstream, the decoder may export it here. { 0, 1} when
   1741   *             unknown.
   1742   * - encoding: May be used to signal the framerate of CFR content to an
   1743   *             encoder.
   1744   */
   1745  AVRational framerate;
   1746 
   1747  /**
   1748   * Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
   1749   * - encoding: unused.
   1750   * - decoding: Set by libavcodec before calling get_format()
   1751   */
   1752  enum AVPixelFormat sw_pix_fmt;
   1753 
   1754  /**
   1755   * Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
   1756   * - encoding unused.
   1757   * - decoding set by user.
   1758   */
   1759  AVRational pkt_timebase;
   1760 
   1761  /**
   1762   * AVCodecDescriptor
   1763   * - encoding: unused.
   1764   * - decoding: set by libavcodec.
   1765   */
   1766  const AVCodecDescriptor* codec_descriptor;
   1767 
   1768  /**
   1769   * Current statistics for PTS correction.
   1770   * - decoding: maintained and used by libavcodec, not intended to be used by
   1771   * user apps
   1772   * - encoding: unused
   1773   */
   1774  int64_t
   1775      pts_correction_num_faulty_pts;  /// Number of incorrect PTS values so far
   1776  int64_t
   1777      pts_correction_num_faulty_dts;  /// Number of incorrect DTS values so far
   1778  int64_t pts_correction_last_pts;    /// PTS of the last frame
   1779  int64_t pts_correction_last_dts;    /// DTS of the last frame
   1780 
   1781  /**
   1782   * Character encoding of the input subtitles file.
   1783   * - decoding: set by user
   1784   * - encoding: unused
   1785   */
   1786  char* sub_charenc;
   1787 
   1788  /**
   1789   * Subtitles character encoding mode. Formats or codecs might be adjusting
   1790   * this setting (if they are doing the conversion themselves for instance).
   1791   * - decoding: set by libavcodec
   1792   * - encoding: unused
   1793   */
   1794  int sub_charenc_mode;
   1795 #define FF_SUB_CHARENC_MODE_DO_NOTHING \
   1796  -1  ///< do nothing (demuxer outputs a stream supposed to be already in UTF-8,
   1797      ///< or the codec is bitmap for instance)
   1798 #define FF_SUB_CHARENC_MODE_AUTOMATIC \
   1799  0  ///< libavcodec will select the mode itself
   1800 #define FF_SUB_CHARENC_MODE_PRE_DECODER \
   1801  1  ///< the AVPacket data needs to be recoded to UTF-8 before being fed to the
   1802     ///< decoder, requires iconv
   1803 #define FF_SUB_CHARENC_MODE_IGNORE \
   1804  2  ///< neither convert the subtitles, nor check them for valid UTF-8
   1805 
   1806  /**
   1807   * Skip processing alpha if supported by codec.
   1808   * Note that if the format uses pre-multiplied alpha (common with VP6,
   1809   * and recommended due to better video quality/compression)
   1810   * the image will look as if alpha-blended onto a black background.
   1811   * However for formats that do not use pre-multiplied alpha
   1812   * there might be serious artefacts (though e.g. libswscale currently
   1813   * assumes pre-multiplied alpha anyway).
   1814   *
   1815   * - decoding: set by user
   1816   * - encoding: unused
   1817   */
   1818  int skip_alpha;
   1819 
   1820  /**
   1821   * Number of samples to skip after a discontinuity
   1822   * - decoding: unused
   1823   * - encoding: set by libavcodec
   1824   */
   1825  int seek_preroll;
   1826 
   1827 #if FF_API_DEBUG_MV
   1828  /**
   1829   * @deprecated unused
   1830   */
   1831  attribute_deprecated int debug_mv;
   1832 #  define FF_DEBUG_VIS_MV_P_FOR \
   1833    0x00000001  // visualize forward predicted MVs of P frames
   1834 #  define FF_DEBUG_VIS_MV_B_FOR \
   1835    0x00000002  // visualize forward predicted MVs of B frames
   1836 #  define FF_DEBUG_VIS_MV_B_BACK \
   1837    0x00000004  // visualize backward predicted MVs of B frames
   1838 #endif
   1839 
   1840  /**
   1841   * custom intra quantization matrix
   1842   * - encoding: Set by user, can be NULL.
   1843   * - decoding: unused.
   1844   */
   1845  uint16_t* chroma_intra_matrix;
   1846 
   1847  /**
   1848   * dump format separator.
   1849   * can be ", " or "\n      " or anything else
   1850   * - encoding: Set by user.
   1851   * - decoding: Set by user.
   1852   */
   1853  uint8_t* dump_separator;
   1854 
   1855  /**
   1856   * ',' separated list of allowed decoders.
   1857   * If NULL then all are allowed
   1858   * - encoding: unused
   1859   * - decoding: set by user
   1860   */
   1861  char* codec_whitelist;
   1862 
   1863  /**
   1864   * Properties of the stream that gets decoded
   1865   * - encoding: unused
   1866   * - decoding: set by libavcodec
   1867   */
   1868  unsigned properties;
   1869 #define FF_CODEC_PROPERTY_LOSSLESS 0x00000001
   1870 #define FF_CODEC_PROPERTY_CLOSED_CAPTIONS 0x00000002
   1871 #define FF_CODEC_PROPERTY_FILM_GRAIN 0x00000004
   1872 
   1873  /**
   1874   * Additional data associated with the entire coded stream.
   1875   *
   1876   * - decoding: unused
   1877   * - encoding: may be set by libavcodec after avcodec_open2().
   1878   */
   1879  AVPacketSideData* coded_side_data;
   1880  int nb_coded_side_data;
   1881 
   1882  /**
   1883   * A reference to the AVHWFramesContext describing the input (for encoding)
   1884   * or output (decoding) frames. The reference is set by the caller and
   1885   * afterwards owned (and freed) by libavcodec - it should never be read by
   1886   * the caller after being set.
   1887   *
   1888   * - decoding: This field should be set by the caller from the get_format()
   1889   *             callback. The previous reference (if any) will always be
   1890   *             unreffed by libavcodec before the get_format() call.
   1891   *
   1892   *             If the default get_buffer2() is used with a hwaccel pixel
   1893   *             format, then this AVHWFramesContext will be used for
   1894   *             allocating the frame buffers.
   1895   *
   1896   * - encoding: For hardware encoders configured to use a hwaccel pixel
   1897   *             format, this field should be set by the caller to a reference
   1898   *             to the AVHWFramesContext describing input frames.
   1899   *             AVHWFramesContext.format must be equal to
   1900   *             AVCodecContext.pix_fmt.
   1901   *
   1902   *             This field should be set before avcodec_open2() is called.
   1903   */
   1904  AVBufferRef* hw_frames_ctx;
   1905 
   1906 #if FF_API_SUB_TEXT_FORMAT
   1907  /**
   1908   * @deprecated unused
   1909   */
   1910  attribute_deprecated int sub_text_format;
   1911 #  define FF_SUB_TEXT_FMT_ASS 0
   1912 #endif
   1913 
   1914  /**
   1915   * Audio only. The amount of padding (in samples) appended by the encoder to
   1916   * the end of the audio. I.e. this number of decoded samples must be
   1917   * discarded by the caller from the end of the stream to get the original
   1918   * audio without any trailing padding.
   1919   *
   1920   * - decoding: unused
   1921   * - encoding: unused
   1922   */
   1923  int trailing_padding;
   1924 
   1925  /**
   1926   * The number of pixels per image to maximally accept.
   1927   *
   1928   * - decoding: set by user
   1929   * - encoding: set by user
   1930   */
   1931  int64_t max_pixels;
   1932 
   1933  /**
   1934   * A reference to the AVHWDeviceContext describing the device which will
   1935   * be used by a hardware encoder/decoder.  The reference is set by the
   1936   * caller and afterwards owned (and freed) by libavcodec.
   1937   *
   1938   * This should be used if either the codec device does not require
   1939   * hardware frames or any that are used are to be allocated internally by
   1940   * libavcodec.  If the user wishes to supply any of the frames used as
   1941   * encoder input or decoder output then hw_frames_ctx should be used
   1942   * instead.  When hw_frames_ctx is set in get_format() for a decoder, this
   1943   * field will be ignored while decoding the associated stream segment, but
   1944   * may again be used on a following one after another get_format() call.
   1945   *
   1946   * For both encoders and decoders this field should be set before
   1947   * avcodec_open2() is called and must not be written to thereafter.
   1948   *
   1949   * Note that some decoders may require this field to be set initially in
   1950   * order to support hw_frames_ctx at all - in that case, all frames
   1951   * contexts used must be created on the same device.
   1952   */
   1953  AVBufferRef* hw_device_ctx;
   1954 
   1955  /**
   1956   * Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated
   1957   * decoding (if active).
   1958   * - encoding: unused
   1959   * - decoding: Set by user (either before avcodec_open2(), or in the
   1960   *             AVCodecContext.get_format callback)
   1961   */
   1962  int hwaccel_flags;
   1963 
   1964  /**
   1965   * Video decoding only. Certain video codecs support cropping, meaning that
   1966   * only a sub-rectangle of the decoded frame is intended for display.  This
   1967   * option controls how cropping is handled by libavcodec.
   1968   *
   1969   * When set to 1 (the default), libavcodec will apply cropping internally.
   1970   * I.e. it will modify the output frame width/height fields and offset the
   1971   * data pointers (only by as much as possible while preserving alignment, or
   1972   * by the full amount if the AV_CODEC_FLAG_UNALIGNED flag is set) so that
   1973   * the frames output by the decoder refer only to the cropped area. The
   1974   * crop_* fields of the output frames will be zero.
   1975   *
   1976   * When set to 0, the width/height fields of the output frames will be set
   1977   * to the coded dimensions and the crop_* fields will describe the cropping
   1978   * rectangle. Applying the cropping is left to the caller.
   1979   *
   1980   * @warning When hardware acceleration with opaque output frames is used,
   1981   * libavcodec is unable to apply cropping from the top/left border.
   1982   *
   1983   * @note when this option is set to zero, the width/height fields of the
   1984   * AVCodecContext and output AVFrames have different meanings. The codec
   1985   * context fields store display dimensions (with the coded dimensions in
   1986   * coded_width/height), while the frame fields store the coded dimensions
   1987   * (with the display dimensions being determined by the crop_* fields).
   1988   */
   1989  int apply_cropping;
   1990 
   1991  /*
   1992   * Video decoding only.  Sets the number of extra hardware frames which
   1993   * the decoder will allocate for use by the caller.  This must be set
   1994   * before avcodec_open2() is called.
   1995   *
   1996   * Some hardware decoders require all frames that they will use for
   1997   * output to be defined in advance before decoding starts.  For such
   1998   * decoders, the hardware frame pool must therefore be of a fixed size.
   1999   * The extra frames set here are on top of any number that the decoder
   2000   * needs internally in order to operate normally (for example, frames
   2001   * used as reference pictures).
   2002   */
   2003  int extra_hw_frames;
   2004 
   2005  /**
   2006   * The percentage of damaged samples to discard a frame.
   2007   *
   2008   * - decoding: set by user
   2009   * - encoding: unused
   2010   */
   2011  int discard_damaged_percentage;
   2012 
   2013  /**
   2014   * The number of samples per frame to maximally accept.
   2015   *
   2016   * - decoding: set by user
   2017   * - encoding: set by user
   2018   */
   2019  int64_t max_samples;
   2020 
   2021  /**
   2022   * Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of
   2023   * metadata exported in frame, packet, or coded stream side data by
   2024   * decoders and encoders.
   2025   *
   2026   * - decoding: set by user
   2027   * - encoding: set by user
   2028   */
   2029  int export_side_data;
   2030 
   2031  /**
   2032   * This callback is called at the beginning of each packet to get a data
   2033   * buffer for it.
   2034   *
   2035   * The following field will be set in the packet before this callback is
   2036   * called:
   2037   * - size
   2038   * This callback must use the above value to calculate the required buffer
   2039   * size, which must padded by at least AV_INPUT_BUFFER_PADDING_SIZE bytes.
   2040   *
   2041   * In some specific cases, the encoder may not use the entire buffer allocated
   2042   * by this callback. This will be reflected in the size value in the packet
   2043   * once returned by avcodec_receive_packet().
   2044   *
   2045   * This callback must fill the following fields in the packet:
   2046   * - data: alignment requirements for AVPacket apply, if any. Some
   2047   * architectures and encoders may benefit from having aligned data.
   2048   * - buf: must contain a pointer to an AVBufferRef structure. The packet's
   2049   *   data pointer must be contained in it. See: av_buffer_create(),
   2050   * av_buffer_alloc(), and av_buffer_ref().
   2051   *
   2052   * If AV_CODEC_CAP_DR1 is not set then get_encode_buffer() must call
   2053   * avcodec_default_get_encode_buffer() instead of providing a buffer allocated
   2054   * by some other means.
   2055   *
   2056   * The flags field may contain a combination of AV_GET_ENCODE_BUFFER_FLAG_
   2057   * flags. They may be used for example to hint what use the buffer may get
   2058   * after being created. Implementations of this callback may ignore flags they
   2059   * don't understand. If AV_GET_ENCODE_BUFFER_FLAG_REF is set in flags then the
   2060   * packet may be reused (read and/or written to if it is writable) later by
   2061   * libavcodec.
   2062   *
   2063   * This callback must be thread-safe, as when frame threading is used, it may
   2064   * be called from multiple threads simultaneously.
   2065   *
   2066   * @see avcodec_default_get_encode_buffer()
   2067   *
   2068   * - encoding: Set by libavcodec, user can override.
   2069   * - decoding: unused
   2070   */
   2071  int (*get_encode_buffer)(struct AVCodecContext* s, AVPacket* pkt, int flags);
   2072 } AVCodecContext;
   2073 
   2074 struct MpegEncContext;
   2075 
   2076 /**
   2077 * @defgroup lavc_hwaccel AVHWAccel
   2078 *
   2079 * @note  Nothing in this structure should be accessed by the user.  At some
   2080 *        point in future it will not be externally visible at all.
   2081 *
   2082 * @{
   2083 */
   2084 typedef struct AVHWAccel {
   2085  /**
   2086   * Name of the hardware accelerated codec.
   2087   * The name is globally unique among encoders and among decoders (but an
   2088   * encoder and a decoder can share the same name).
   2089   */
   2090  const char* name;
   2091 
   2092  /**
   2093   * Type of codec implemented by the hardware accelerator.
   2094   *
   2095   * See AVMEDIA_TYPE_xxx
   2096   */
   2097  enum AVMediaType type;
   2098 
   2099  /**
   2100   * Codec implemented by the hardware accelerator.
   2101   *
   2102   * See AV_CODEC_ID_xxx
   2103   */
   2104  enum AVCodecID id;
   2105 
   2106  /**
   2107   * Supported pixel format.
   2108   *
   2109   * Only hardware accelerated formats are supported here.
   2110   */
   2111  enum AVPixelFormat pix_fmt;
   2112 
   2113  /**
   2114   * Hardware accelerated codec capabilities.
   2115   * see AV_HWACCEL_CODEC_CAP_*
   2116   */
   2117  int capabilities;
   2118 
   2119  /*****************************************************************
   2120   * No fields below this line are part of the public API. They
   2121   * may not be used outside of libavcodec and can be changed and
   2122   * removed at will.
   2123   * New public fields should be added right above.
   2124   *****************************************************************
   2125   */
   2126 
   2127  /**
   2128   * Allocate a custom buffer
   2129   */
   2130  int (*alloc_frame)(AVCodecContext* avctx, AVFrame* frame);
   2131 
   2132  /**
   2133   * Called at the beginning of each frame or field picture.
   2134   *
   2135   * Meaningful frame information (codec specific) is guaranteed to
   2136   * be parsed at this point. This function is mandatory.
   2137   *
   2138   * Note that buf can be NULL along with buf_size set to 0.
   2139   * Otherwise, this means the whole frame is available at this point.
   2140   *
   2141   * @param avctx the codec context
   2142   * @param buf the frame data buffer base
   2143   * @param buf_size the size of the frame in bytes
   2144   * @return zero if successful, a negative value otherwise
   2145   */
   2146  int (*start_frame)(AVCodecContext* avctx, const uint8_t* buf,
   2147                     uint32_t buf_size);
   2148 
   2149  /**
   2150   * Callback for parameter data (SPS/PPS/VPS etc).
   2151   *
   2152   * Useful for hardware decoders which keep persistent state about the
   2153   * video parameters, and need to receive any changes to update that state.
   2154   *
   2155   * @param avctx the codec context
   2156   * @param type the nal unit type
   2157   * @param buf the nal unit data buffer
   2158   * @param buf_size the size of the nal unit in bytes
   2159   * @return zero if successful, a negative value otherwise
   2160   */
   2161  int (*decode_params)(AVCodecContext* avctx, int type, const uint8_t* buf,
   2162                       uint32_t buf_size);
   2163 
   2164  /**
   2165   * Callback for each slice.
   2166   *
   2167   * Meaningful slice information (codec specific) is guaranteed to
   2168   * be parsed at this point. This function is mandatory.
   2169   * The only exception is XvMC, that works on MB level.
   2170   *
   2171   * @param avctx the codec context
   2172   * @param buf the slice data buffer base
   2173   * @param buf_size the size of the slice in bytes
   2174   * @return zero if successful, a negative value otherwise
   2175   */
   2176  int (*decode_slice)(AVCodecContext* avctx, const uint8_t* buf,
   2177                      uint32_t buf_size);
   2178 
   2179  /**
   2180   * Called at the end of each frame or field picture.
   2181   *
   2182   * The whole picture is parsed at this point and can now be sent
   2183   * to the hardware accelerator. This function is mandatory.
   2184   *
   2185   * @param avctx the codec context
   2186   * @return zero if successful, a negative value otherwise
   2187   */
   2188  int (*end_frame)(AVCodecContext* avctx);
   2189 
   2190  /**
   2191   * Size of per-frame hardware accelerator private data.
   2192   *
   2193   * Private data is allocated with av_mallocz() before
   2194   * AVCodecContext.get_buffer() and deallocated after
   2195   * AVCodecContext.release_buffer().
   2196   */
   2197  int frame_priv_data_size;
   2198 
   2199  /**
   2200   * Called for every Macroblock in a slice.
   2201   *
   2202   * XvMC uses it to replace the ff_mpv_reconstruct_mb().
   2203   * Instead of decoding to raw picture, MB parameters are
   2204   * stored in an array provided by the video driver.
   2205   *
   2206   * @param s the mpeg context
   2207   */
   2208  void (*decode_mb)(struct MpegEncContext* s);
   2209 
   2210  /**
   2211   * Initialize the hwaccel private data.
   2212   *
   2213   * This will be called from ff_get_format(), after hwaccel and
   2214   * hwaccel_context are set and the hwaccel private data in AVCodecInternal
   2215   * is allocated.
   2216   */
   2217  int (*init)(AVCodecContext* avctx);
   2218 
   2219  /**
   2220   * Uninitialize the hwaccel private data.
   2221   *
   2222   * This will be called from get_format() or avcodec_close(), after hwaccel
   2223   * and hwaccel_context are already uninitialized.
   2224   */
   2225  int (*uninit)(AVCodecContext* avctx);
   2226 
   2227  /**
   2228   * Size of the private data to allocate in
   2229   * AVCodecInternal.hwaccel_priv_data.
   2230   */
   2231  int priv_data_size;
   2232 
   2233  /**
   2234   * Internal hwaccel capabilities.
   2235   */
   2236  int caps_internal;
   2237 
   2238  /**
   2239   * Fill the given hw_frames context with current codec parameters. Called
   2240   * from get_format. Refer to avcodec_get_hw_frames_parameters() for
   2241   * details.
   2242   *
   2243   * This CAN be called before AVHWAccel.init is called, and you must assume
   2244   * that avctx->hwaccel_priv_data is invalid.
   2245   */
   2246  int (*frame_params)(AVCodecContext* avctx, AVBufferRef* hw_frames_ctx);
   2247 } AVHWAccel;
   2248 
   2249 /**
   2250 * HWAccel is experimental and is thus avoided in favor of non experimental
   2251 * codecs
   2252 */
   2253 #define AV_HWACCEL_CODEC_CAP_EXPERIMENTAL 0x0200
   2254 
   2255 /**
   2256 * Hardware acceleration should be used for decoding even if the codec level
   2257 * used is unknown or higher than the maximum supported level reported by the
   2258 * hardware driver.
   2259 *
   2260 * It's generally a good idea to pass this flag unless you have a specific
   2261 * reason not to, as hardware tends to under-report supported levels.
   2262 */
   2263 #define AV_HWACCEL_FLAG_IGNORE_LEVEL (1 << 0)
   2264 
   2265 /**
   2266 * Hardware acceleration can output YUV pixel formats with a different chroma
   2267 * sampling than 4:2:0 and/or other than 8 bits per component.
   2268 */
   2269 #define AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH (1 << 1)
   2270 
   2271 /**
   2272 * Hardware acceleration should still be attempted for decoding when the
   2273 * codec profile does not match the reported capabilities of the hardware.
   2274 *
   2275 * For example, this can be used to try to decode baseline profile H.264
   2276 * streams in hardware - it will often succeed, because many streams marked
   2277 * as baseline profile actually conform to constrained baseline profile.
   2278 *
   2279 * @warning If the stream is actually not supported then the behaviour is
   2280 *          undefined, and may include returning entirely incorrect output
   2281 *          while indicating success.
   2282 */
   2283 #define AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH (1 << 2)
   2284 
   2285 /**
   2286 * @}
   2287 */
   2288 
   2289 enum AVSubtitleType {
   2290  SUBTITLE_NONE,
   2291 
   2292  SUBTITLE_BITMAP,  ///< A bitmap, pict will be set
   2293 
   2294  /**
   2295   * Plain text, the text field must be set by the decoder and is
   2296   * authoritative. ass and pict fields may contain approximations.
   2297   */
   2298  SUBTITLE_TEXT,
   2299 
   2300  /**
   2301   * Formatted text, the ass field must be set by the decoder and is
   2302   * authoritative. pict and text fields may contain approximations.
   2303   */
   2304  SUBTITLE_ASS,
   2305 };
   2306 
   2307 #define AV_SUBTITLE_FLAG_FORCED 0x00000001
   2308 
   2309 typedef struct AVSubtitleRect {
   2310  int x;          ///< top left corner  of pict, undefined when pict is not set
   2311  int y;          ///< top left corner  of pict, undefined when pict is not set
   2312  int w;          ///< width            of pict, undefined when pict is not set
   2313  int h;          ///< height           of pict, undefined when pict is not set
   2314  int nb_colors;  ///< number of colors in pict, undefined when pict is not set
   2315 
   2316  /**
   2317   * data+linesize for the bitmap of this subtitle.
   2318   * Can be set for text/ass as well once they are rendered.
   2319   */
   2320  uint8_t* data[4];
   2321  int linesize[4];
   2322 
   2323  enum AVSubtitleType type;
   2324 
   2325  char* text;  ///< 0 terminated plain UTF-8 text
   2326 
   2327  /**
   2328   * 0 terminated ASS/SSA compatible event line.
   2329   * The presentation of this is unaffected by the other values in this
   2330   * struct.
   2331   */
   2332  char* ass;
   2333 
   2334  int flags;
   2335 } AVSubtitleRect;
   2336 
   2337 typedef struct AVSubtitle {
   2338  uint16_t format;             /* 0 = graphics */
   2339  uint32_t start_display_time; /* relative to packet pts, in ms */
   2340  uint32_t end_display_time;   /* relative to packet pts, in ms */
   2341  unsigned num_rects;
   2342  AVSubtitleRect** rects;
   2343  int64_t pts;  ///< Same as packet pts, in AV_TIME_BASE
   2344 } AVSubtitle;
   2345 
   2346 /**
   2347 * Return the LIBAVCODEC_VERSION_INT constant.
   2348 */
   2349 unsigned avcodec_version(void);
   2350 
   2351 /**
   2352 * Return the libavcodec build-time configuration.
   2353 */
   2354 const char* avcodec_configuration(void);
   2355 
   2356 /**
   2357 * Return the libavcodec license.
   2358 */
   2359 const char* avcodec_license(void);
   2360 
   2361 /**
   2362 * Allocate an AVCodecContext and set its fields to default values. The
   2363 * resulting struct should be freed with avcodec_free_context().
   2364 *
   2365 * @param codec if non-NULL, allocate private data and initialize defaults
   2366 *              for the given codec. It is illegal to then call avcodec_open2()
   2367 *              with a different codec.
   2368 *              If NULL, then the codec-specific defaults won't be initialized,
   2369 *              which may result in suboptimal default settings (this is
   2370 *              important mainly for encoders, e.g. libx264).
   2371 *
   2372 * @return An AVCodecContext filled with default values or NULL on failure.
   2373 */
   2374 AVCodecContext* avcodec_alloc_context3(const AVCodec* codec);
   2375 
   2376 /**
   2377 * Free the codec context and everything associated with it and write NULL to
   2378 * the provided pointer.
   2379 */
   2380 void avcodec_free_context(AVCodecContext** avctx);
   2381 
   2382 /**
   2383 * Get the AVClass for AVCodecContext. It can be used in combination with
   2384 * AV_OPT_SEARCH_FAKE_OBJ for examining options.
   2385 *
   2386 * @see av_opt_find().
   2387 */
   2388 const AVClass* avcodec_get_class(void);
   2389 
   2390 #if FF_API_GET_FRAME_CLASS
   2391 /**
   2392 * @deprecated This function should not be used.
   2393 */
   2394 attribute_deprecated const AVClass* avcodec_get_frame_class(void);
   2395 #endif
   2396 
   2397 /**
   2398 * Get the AVClass for AVSubtitleRect. It can be used in combination with
   2399 * AV_OPT_SEARCH_FAKE_OBJ for examining options.
   2400 *
   2401 * @see av_opt_find().
   2402 */
   2403 const AVClass* avcodec_get_subtitle_rect_class(void);
   2404 
   2405 /**
   2406 * Fill the parameters struct based on the values from the supplied codec
   2407 * context. Any allocated fields in par are freed and replaced with duplicates
   2408 * of the corresponding fields in codec.
   2409 *
   2410 * @return >= 0 on success, a negative AVERROR code on failure
   2411 */
   2412 int avcodec_parameters_from_context(AVCodecParameters* par,
   2413                                    const AVCodecContext* codec);
   2414 
   2415 /**
   2416 * Fill the codec context based on the values from the supplied codec
   2417 * parameters. Any allocated fields in codec that have a corresponding field in
   2418 * par are freed and replaced with duplicates of the corresponding field in par.
   2419 * Fields in codec that do not have a counterpart in par are not touched.
   2420 *
   2421 * @return >= 0 on success, a negative AVERROR code on failure.
   2422 */
   2423 int avcodec_parameters_to_context(AVCodecContext* codec,
   2424                                  const AVCodecParameters* par);
   2425 
   2426 /**
   2427 * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
   2428 * function the context has to be allocated with avcodec_alloc_context3().
   2429 *
   2430 * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
   2431 * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
   2432 * retrieving a codec.
   2433 *
   2434 * @warning This function is not thread safe!
   2435 *
   2436 * @note Always call this function before using decoding routines (such as
   2437 * @ref avcodec_receive_frame()).
   2438 *
   2439 * @code
   2440 * av_dict_set(&opts, "b", "2.5M", 0);
   2441 * codec = avcodec_find_decoder(AV_CODEC_ID_H264);
   2442 * if (!codec)
   2443 *     exit(1);
   2444 *
   2445 * context = avcodec_alloc_context3(codec);
   2446 *
   2447 * if (avcodec_open2(context, codec, opts) < 0)
   2448 *     exit(1);
   2449 * @endcode
   2450 *
   2451 * @param avctx The context to initialize.
   2452 * @param codec The codec to open this context for. If a non-NULL codec has been
   2453 *              previously passed to avcodec_alloc_context3() or
   2454 *              for this context, then this parameter MUST be either NULL or
   2455 *              equal to the previously passed codec.
   2456 * @param options A dictionary filled with AVCodecContext and codec-private
   2457 * options. On return this object will be filled with options that were not
   2458 * found.
   2459 *
   2460 * @return zero on success, a negative value on error
   2461 * @see avcodec_alloc_context3(), avcodec_find_decoder(),
   2462 * avcodec_find_encoder(), av_dict_set(), av_opt_find().
   2463 */
   2464 int avcodec_open2(AVCodecContext* avctx, const AVCodec* codec,
   2465                  AVDictionary** options);
   2466 
   2467 /**
   2468 * Close a given AVCodecContext and free all the data associated with it
   2469 * (but not the AVCodecContext itself).
   2470 *
   2471 * Calling this function on an AVCodecContext that hasn't been opened will free
   2472 * the codec-specific data allocated in avcodec_alloc_context3() with a non-NULL
   2473 * codec. Subsequent calls will do nothing.
   2474 *
   2475 * @note Do not use this function. Use avcodec_free_context() to destroy a
   2476 * codec context (either open or closed). Opening and closing a codec context
   2477 * multiple times is not supported anymore -- use multiple codec contexts
   2478 * instead.
   2479 */
   2480 int avcodec_close(AVCodecContext* avctx);
   2481 
   2482 /**
   2483 * Free all allocated data in the given subtitle struct.
   2484 *
   2485 * @param sub AVSubtitle to free.
   2486 */
   2487 void avsubtitle_free(AVSubtitle* sub);
   2488 
   2489 /**
   2490 * @}
   2491 */
   2492 
   2493 /**
   2494 * @addtogroup lavc_decoding
   2495 * @{
   2496 */
   2497 
   2498 /**
   2499 * The default callback for AVCodecContext.get_buffer2(). It is made public so
   2500 * it can be called by custom get_buffer2() implementations for decoders without
   2501 * AV_CODEC_CAP_DR1 set.
   2502 */
   2503 int avcodec_default_get_buffer2(AVCodecContext* s, AVFrame* frame, int flags);
   2504 
   2505 /**
   2506 * The default callback for AVCodecContext.get_encode_buffer(). It is made
   2507 * public so it can be called by custom get_encode_buffer() implementations for
   2508 * encoders without AV_CODEC_CAP_DR1 set.
   2509 */
   2510 int avcodec_default_get_encode_buffer(AVCodecContext* s, AVPacket* pkt,
   2511                                      int flags);
   2512 
   2513 /**
   2514 * Modify width and height values so that they will result in a memory
   2515 * buffer that is acceptable for the codec if you do not use any horizontal
   2516 * padding.
   2517 *
   2518 * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.
   2519 */
   2520 void avcodec_align_dimensions(AVCodecContext* s, int* width, int* height);
   2521 
   2522 /**
   2523 * Modify width and height values so that they will result in a memory
   2524 * buffer that is acceptable for the codec if you also ensure that all
   2525 * line sizes are a multiple of the respective linesize_align[i].
   2526 *
   2527 * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.
   2528 */
   2529 void avcodec_align_dimensions2(AVCodecContext* s, int* width, int* height,
   2530                               int linesize_align[AV_NUM_DATA_POINTERS]);
   2531 
   2532 /**
   2533 * Converts AVChromaLocation to swscale x/y chroma position.
   2534 *
   2535 * The positions represent the chroma (0,0) position in a coordinates system
   2536 * with luma (0,0) representing the origin and luma(1,1) representing 256,256
   2537 *
   2538 * @param xpos  horizontal chroma sample position
   2539 * @param ypos  vertical   chroma sample position
   2540 */
   2541 int avcodec_enum_to_chroma_pos(int* xpos, int* ypos, enum AVChromaLocation pos);
   2542 
   2543 /**
   2544 * Converts swscale x/y chroma position to AVChromaLocation.
   2545 *
   2546 * The positions represent the chroma (0,0) position in a coordinates system
   2547 * with luma (0,0) representing the origin and luma(1,1) representing 256,256
   2548 *
   2549 * @param xpos  horizontal chroma sample position
   2550 * @param ypos  vertical   chroma sample position
   2551 */
   2552 enum AVChromaLocation avcodec_chroma_pos_to_enum(int xpos, int ypos);
   2553 
   2554 /**
   2555 * Decode a subtitle message.
   2556 * Return a negative value on error, otherwise return the number of bytes used.
   2557 * If no subtitle could be decompressed, got_sub_ptr is zero.
   2558 * Otherwise, the subtitle is stored in *sub.
   2559 * Note that AV_CODEC_CAP_DR1 is not available for subtitle codecs. This is for
   2560 * simplicity, because the performance difference is expected to be negligible
   2561 * and reusing a get_buffer written for video codecs would probably perform
   2562 * badly due to a potentially very different allocation pattern.
   2563 *
   2564 * Some decoders (those marked with AV_CODEC_CAP_DELAY) have a delay between
   2565 * input and output. This means that for some packets they will not immediately
   2566 * produce decoded output and need to be flushed at the end of decoding to get
   2567 * all the decoded data. Flushing is done by calling this function with packets
   2568 * with avpkt->data set to NULL and avpkt->size set to 0 until it stops
   2569 * returning subtitles. It is safe to flush even those decoders that are not
   2570 * marked with AV_CODEC_CAP_DELAY, then no subtitles will be returned.
   2571 *
   2572 * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
   2573 * before packets may be fed to the decoder.
   2574 *
   2575 * @param avctx the codec context
   2576 * @param[out] sub The preallocated AVSubtitle in which the decoded subtitle
   2577 * will be stored, must be freed with avsubtitle_free if *got_sub_ptr is set.
   2578 * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed,
   2579 * otherwise, it is nonzero.
   2580 * @param[in] avpkt The input AVPacket containing the input buffer.
   2581 */
   2582 int avcodec_decode_subtitle2(AVCodecContext* avctx, AVSubtitle* sub,
   2583                             int* got_sub_ptr, AVPacket* avpkt);
   2584 
   2585 /**
   2586 * Supply raw packet data as input to a decoder.
   2587 *
   2588 * Internally, this call will copy relevant AVCodecContext fields, which can
   2589 * influence decoding per-packet, and apply them when the packet is actually
   2590 * decoded. (For example AVCodecContext.skip_frame, which might direct the
   2591 * decoder to drop the frame contained by the packet sent with this function.)
   2592 *
   2593 * @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE
   2594 *          larger than the actual read bytes because some optimized bitstream
   2595 *          readers read 32 or 64 bits at once and could read over the end.
   2596 *
   2597 * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
   2598 *       before packets may be fed to the decoder.
   2599 *
   2600 * @param avctx codec context
   2601 * @param[in] avpkt The input AVPacket. Usually, this will be a single video
   2602 *                  frame, or several complete audio frames.
   2603 *                  Ownership of the packet remains with the caller, and the
   2604 *                  decoder will not write to the packet. The decoder may create
   2605 *                  a reference to the packet data (or copy it if the packet is
   2606 *                  not reference-counted).
   2607 *                  Unlike with older APIs, the packet is always fully consumed,
   2608 *                  and if it contains multiple frames (e.g. some audio codecs),
   2609 *                  will require you to call avcodec_receive_frame() multiple
   2610 *                  times afterwards before you can send a new packet.
   2611 *                  It can be NULL (or an AVPacket with data set to NULL and
   2612 *                  size set to 0); in this case, it is considered a flush
   2613 *                  packet, which signals the end of the stream. Sending the
   2614 *                  first flush packet will return success. Subsequent ones are
   2615 *                  unnecessary and will return AVERROR_EOF. If the decoder
   2616 *                  still has frames buffered, it will return them after sending
   2617 *                  a flush packet.
   2618 *
   2619 * @return 0 on success, otherwise negative error code:
   2620 *      AVERROR(EAGAIN):   input is not accepted in the current state - user
   2621 *                         must read output with avcodec_receive_frame() (once
   2622 *                         all output is read, the packet should be resent, and
   2623 *                         the call will not fail with EAGAIN).
   2624 *      AVERROR_EOF:       the decoder has been flushed, and no new packets can
   2625 *                         be sent to it (also returned if more than 1 flush
   2626 *                         packet is sent)
   2627 *      AVERROR(EINVAL):   codec not opened, it is an encoder, or requires flush
   2628 *      AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
   2629 *      other errors: legitimate decoding errors
   2630 */
   2631 int avcodec_send_packet(AVCodecContext* avctx, const AVPacket* avpkt);
   2632 
   2633 /**
   2634 * Return decoded output data from a decoder.
   2635 *
   2636 * @param avctx codec context
   2637 * @param frame This will be set to a reference-counted video or audio
   2638 *              frame (depending on the decoder type) allocated by the
   2639 *              decoder. Note that the function will always call
   2640 *              av_frame_unref(frame) before doing anything else.
   2641 *
   2642 * @return
   2643 *      0:                 success, a frame was returned
   2644 *      AVERROR(EAGAIN):   output is not available in this state - user must try
   2645 *                         to send new input
   2646 *      AVERROR_EOF:       the decoder has been fully flushed, and there will be
   2647 *                         no more output frames
   2648 *      AVERROR(EINVAL):   codec not opened, or it is an encoder
   2649 *      AVERROR_INPUT_CHANGED:   current decoded frame has changed parameters
   2650 *                               with respect to first decoded frame. Applicable
   2651 *                               when flag AV_CODEC_FLAG_DROPCHANGED is set.
   2652 *      other negative values: legitimate decoding errors
   2653 */
   2654 int avcodec_receive_frame(AVCodecContext* avctx, AVFrame* frame);
   2655 
   2656 /**
   2657 * Supply a raw video or audio frame to the encoder. Use
   2658 * avcodec_receive_packet() to retrieve buffered output packets.
   2659 *
   2660 * @param avctx     codec context
   2661 * @param[in] frame AVFrame containing the raw audio or video frame to be
   2662 * encoded. Ownership of the frame remains with the caller, and the encoder will
   2663 * not write to the frame. The encoder may create a reference to the frame data
   2664 * (or copy it if the frame is not reference-counted). It can be NULL, in which
   2665 * case it is considered a flush packet.  This signals the end of the stream. If
   2666 * the encoder still has packets buffered, it will return them after this call.
   2667 * Once flushing mode has been entered, additional flush packets are ignored,
   2668 * and sending frames will return AVERROR_EOF.
   2669 *
   2670 *                  For audio:
   2671 *                  If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
   2672 *                  can have any number of samples.
   2673 *                  If it is not set, frame->nb_samples must be equal to
   2674 *                  avctx->frame_size for all frames except the last.
   2675 *                  The final frame may be smaller than avctx->frame_size.
   2676 * @return 0 on success, otherwise negative error code:
   2677 *      AVERROR(EAGAIN):   input is not accepted in the current state - user
   2678 *                         must read output with avcodec_receive_packet() (once
   2679 *                         all output is read, the packet should be resent, and
   2680 *                         the call will not fail with EAGAIN).
   2681 *      AVERROR_EOF:       the encoder has been flushed, and no new frames can
   2682 *                         be sent to it
   2683 *      AVERROR(EINVAL):   codec not opened, it is a decoder, or requires flush
   2684 *      AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
   2685 *      other errors: legitimate encoding errors
   2686 */
   2687 int avcodec_send_frame(AVCodecContext* avctx, const AVFrame* frame);
   2688 
   2689 /**
   2690 * Read encoded data from the encoder.
   2691 *
   2692 * @param avctx codec context
   2693 * @param avpkt This will be set to a reference-counted packet allocated by the
   2694 *              encoder. Note that the function will always call
   2695 *              av_packet_unref(avpkt) before doing anything else.
   2696 * @return 0 on success, otherwise negative error code:
   2697 *      AVERROR(EAGAIN):   output is not available in the current state - user
   2698 *                         must try to send input
   2699 *      AVERROR_EOF:       the encoder has been fully flushed, and there will be
   2700 *                         no more output packets
   2701 *      AVERROR(EINVAL):   codec not opened, or it is a decoder
   2702 *      other errors: legitimate encoding errors
   2703 */
   2704 int avcodec_receive_packet(AVCodecContext* avctx, AVPacket* avpkt);
   2705 
   2706 /**
   2707 * Create and return a AVHWFramesContext with values adequate for hardware
   2708 * decoding. This is meant to get called from the get_format callback, and is
   2709 * a helper for preparing a AVHWFramesContext for AVCodecContext.hw_frames_ctx.
   2710 * This API is for decoding with certain hardware acceleration modes/APIs only.
   2711 *
   2712 * The returned AVHWFramesContext is not initialized. The caller must do this
   2713 * with av_hwframe_ctx_init().
   2714 *
   2715 * Calling this function is not a requirement, but makes it simpler to avoid
   2716 * codec or hardware API specific details when manually allocating frames.
   2717 *
   2718 * Alternatively to this, an API user can set AVCodecContext.hw_device_ctx,
   2719 * which sets up AVCodecContext.hw_frames_ctx fully automatically, and makes
   2720 * it unnecessary to call this function or having to care about
   2721 * AVHWFramesContext initialization at all.
   2722 *
   2723 * There are a number of requirements for calling this function:
   2724 *
   2725 * - It must be called from get_format with the same avctx parameter that was
   2726 *   passed to get_format. Calling it outside of get_format is not allowed, and
   2727 *   can trigger undefined behavior.
   2728 * - The function is not always supported (see description of return values).
   2729 *   Even if this function returns successfully, hwaccel initialization could
   2730 *   fail later. (The degree to which implementations check whether the stream
   2731 *   is actually supported varies. Some do this check only after the user's
   2732 *   get_format callback returns.)
   2733 * - The hw_pix_fmt must be one of the choices suggested by get_format. If the
   2734 *   user decides to use a AVHWFramesContext prepared with this API function,
   2735 *   the user must return the same hw_pix_fmt from get_format.
   2736 * - The device_ref passed to this function must support the given hw_pix_fmt.
   2737 * - After calling this API function, it is the user's responsibility to
   2738 *   initialize the AVHWFramesContext (returned by the out_frames_ref
   2739 * parameter), and to set AVCodecContext.hw_frames_ctx to it. If done, this must
   2740 * be done before returning from get_format (this is implied by the normal
   2741 *   AVCodecContext.hw_frames_ctx API rules).
   2742 * - The AVHWFramesContext parameters may change every time time get_format is
   2743 *   called. Also, AVCodecContext.hw_frames_ctx is reset before get_format. So
   2744 *   you are inherently required to go through this process again on every
   2745 *   get_format call.
   2746 * - It is perfectly possible to call this function without actually using
   2747 *   the resulting AVHWFramesContext. One use-case might be trying to reuse a
   2748 *   previously initialized AVHWFramesContext, and calling this API function
   2749 *   only to test whether the required frame parameters have changed.
   2750 * - Fields that use dynamically allocated values of any kind must not be set
   2751 *   by the user unless setting them is explicitly allowed by the documentation.
   2752 *   If the user sets AVHWFramesContext.free and AVHWFramesContext.user_opaque,
   2753 *   the new free callback must call the potentially set previous free callback.
   2754 *   This API call may set any dynamically allocated fields, including the free
   2755 *   callback.
   2756 *
   2757 * The function will set at least the following fields on AVHWFramesContext
   2758 * (potentially more, depending on hwaccel API):
   2759 *
   2760 * - All fields set by av_hwframe_ctx_alloc().
   2761 * - Set the format field to hw_pix_fmt.
   2762 * - Set the sw_format field to the most suited and most versatile format. (An
   2763 *   implication is that this will prefer generic formats over opaque formats
   2764 *   with arbitrary restrictions, if possible.)
   2765 * - Set the width/height fields to the coded frame size, rounded up to the
   2766 *   API-specific minimum alignment.
   2767 * - Only _if_ the hwaccel requires a pre-allocated pool: set the
   2768 * initial_pool_size field to the number of maximum reference surfaces possible
   2769 * with the codec, plus 1 surface for the user to work (meaning the user can
   2770 * safely reference at most 1 decoded surface at a time), plus additional
   2771 * buffering introduced by frame threading. If the hwaccel does not require
   2772 * pre-allocation, the field is left to 0, and the decoder will allocate new
   2773 * surfaces on demand during decoding.
   2774 * - Possibly AVHWFramesContext.hwctx fields, depending on the underlying
   2775 *   hardware API.
   2776 *
   2777 * Essentially, out_frames_ref returns the same as av_hwframe_ctx_alloc(), but
   2778 * with basic frame parameters set.
   2779 *
   2780 * The function is stateless, and does not change the AVCodecContext or the
   2781 * device_ref AVHWDeviceContext.
   2782 *
   2783 * @param avctx The context which is currently calling get_format, and which
   2784 *              implicitly contains all state needed for filling the returned
   2785 *              AVHWFramesContext properly.
   2786 * @param device_ref A reference to the AVHWDeviceContext describing the device
   2787 *                   which will be used by the hardware decoder.
   2788 * @param hw_pix_fmt The hwaccel format you are going to return from get_format.
   2789 * @param out_frames_ref On success, set to a reference to an _uninitialized_
   2790 *                       AVHWFramesContext, created from the given device_ref.
   2791 *                       Fields will be set to values required for decoding.
   2792 *                       Not changed if an error is returned.
   2793 * @return zero on success, a negative value on error. The following error codes
   2794 *         have special semantics:
   2795 *      AVERROR(ENOENT): the decoder does not support this functionality. Setup
   2796 *                       is always manual, or it is a decoder which does not
   2797 *                       support setting AVCodecContext.hw_frames_ctx at all,
   2798 *                       or it is a software format.
   2799 *      AVERROR(EINVAL): it is known that hardware decoding is not supported for
   2800 *                       this configuration, or the device_ref is not supported
   2801 *                       for the hwaccel referenced by hw_pix_fmt.
   2802 */
   2803 int avcodec_get_hw_frames_parameters(AVCodecContext* avctx,
   2804                                     AVBufferRef* device_ref,
   2805                                     enum AVPixelFormat hw_pix_fmt,
   2806                                     AVBufferRef** out_frames_ref);
   2807 
   2808 /**
   2809 * @defgroup lavc_parsing Frame parsing
   2810 * @{
   2811 */
   2812 
   2813 enum AVPictureStructure {
   2814  AV_PICTURE_STRUCTURE_UNKNOWN,       //< unknown
   2815  AV_PICTURE_STRUCTURE_TOP_FIELD,     //< coded as top field
   2816  AV_PICTURE_STRUCTURE_BOTTOM_FIELD,  //< coded as bottom field
   2817  AV_PICTURE_STRUCTURE_FRAME,         //< coded as frame
   2818 };
   2819 
   2820 typedef struct AVCodecParserContext {
   2821  void* priv_data;
   2822  const struct AVCodecParser* parser;
   2823  int64_t frame_offset;      /* offset of the current frame */
   2824  int64_t cur_offset;        /* current offset
   2825                                (incremented by each av_parser_parse()) */
   2826  int64_t next_frame_offset; /* offset of the next frame */
   2827  /* video info */
   2828  int pict_type; /* XXX: Put it back in AVCodecContext. */
   2829  /**
   2830   * This field is used for proper frame duration computation in lavf.
   2831   * It signals, how much longer the frame duration of the current frame
   2832   * is compared to normal frame duration.
   2833   *
   2834   * frame_duration = (1 + repeat_pict) * time_base
   2835   *
   2836   * It is used by codecs like H.264 to display telecined material.
   2837   */
   2838  int repeat_pict; /* XXX: Put it back in AVCodecContext. */
   2839  int64_t pts;     /* pts of the current frame */
   2840  int64_t dts;     /* dts of the current frame */
   2841 
   2842  /* private data */
   2843  int64_t last_pts;
   2844  int64_t last_dts;
   2845  int fetch_timestamp;
   2846 
   2847 #define AV_PARSER_PTS_NB 4
   2848  int cur_frame_start_index;
   2849  int64_t cur_frame_offset[AV_PARSER_PTS_NB];
   2850  int64_t cur_frame_pts[AV_PARSER_PTS_NB];
   2851  int64_t cur_frame_dts[AV_PARSER_PTS_NB];
   2852 
   2853  int flags;
   2854 #define PARSER_FLAG_COMPLETE_FRAMES 0x0001
   2855 #define PARSER_FLAG_ONCE 0x0002
   2856 /// Set if the parser has a valid file offset
   2857 #define PARSER_FLAG_FETCHED_OFFSET 0x0004
   2858 #define PARSER_FLAG_USE_CODEC_TS 0x1000
   2859 
   2860  int64_t offset;  ///< byte offset from starting packet start
   2861  int64_t cur_frame_end[AV_PARSER_PTS_NB];
   2862 
   2863  /**
   2864   * Set by parser to 1 for key frames and 0 for non-key frames.
   2865   * It is initialized to -1, so if the parser doesn't set this flag,
   2866   * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
   2867   * will be used.
   2868   */
   2869  int key_frame;
   2870 
   2871  // Timestamp generation support:
   2872  /**
   2873   * Synchronization point for start of timestamp generation.
   2874   *
   2875   * Set to >0 for sync point, 0 for no sync point and <0 for undefined
   2876   * (default).
   2877   *
   2878   * For example, this corresponds to presence of H.264 buffering period
   2879   * SEI message.
   2880   */
   2881  int dts_sync_point;
   2882 
   2883  /**
   2884   * Offset of the current timestamp against last timestamp sync point in
   2885   * units of AVCodecContext.time_base.
   2886   *
   2887   * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
   2888   * contain a valid timestamp offset.
   2889   *
   2890   * Note that the timestamp of sync point has usually a nonzero
   2891   * dts_ref_dts_delta, which refers to the previous sync point. Offset of
   2892   * the next frame after timestamp sync point will be usually 1.
   2893   *
   2894   * For example, this corresponds to H.264 cpb_removal_delay.
   2895   */
   2896  int dts_ref_dts_delta;
   2897 
   2898  /**
   2899   * Presentation delay of current frame in units of AVCodecContext.time_base.
   2900   *
   2901   * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
   2902   * contain valid non-negative timestamp delta (presentation time of a frame
   2903   * must not lie in the past).
   2904   *
   2905   * This delay represents the difference between decoding and presentation
   2906   * time of the frame.
   2907   *
   2908   * For example, this corresponds to H.264 dpb_output_delay.
   2909   */
   2910  int pts_dts_delta;
   2911 
   2912  /**
   2913   * Position of the packet in file.
   2914   *
   2915   * Analogous to cur_frame_pts/dts
   2916   */
   2917  int64_t cur_frame_pos[AV_PARSER_PTS_NB];
   2918 
   2919  /**
   2920   * Byte position of currently parsed frame in stream.
   2921   */
   2922  int64_t pos;
   2923 
   2924  /**
   2925   * Previous frame byte position.
   2926   */
   2927  int64_t last_pos;
   2928 
   2929  /**
   2930   * Duration of the current frame.
   2931   * For audio, this is in units of 1 / AVCodecContext.sample_rate.
   2932   * For all other types, this is in units of AVCodecContext.time_base.
   2933   */
   2934  int duration;
   2935 
   2936  enum AVFieldOrder field_order;
   2937 
   2938  /**
   2939   * Indicate whether a picture is coded as a frame, top field or bottom field.
   2940   *
   2941   * For example, H.264 field_pic_flag equal to 0 corresponds to
   2942   * AV_PICTURE_STRUCTURE_FRAME. An H.264 picture with field_pic_flag
   2943   * equal to 1 and bottom_field_flag equal to 0 corresponds to
   2944   * AV_PICTURE_STRUCTURE_TOP_FIELD.
   2945   */
   2946  enum AVPictureStructure picture_structure;
   2947 
   2948  /**
   2949   * Picture number incremented in presentation or output order.
   2950   * This field may be reinitialized at the first picture of a new sequence.
   2951   *
   2952   * For example, this corresponds to H.264 PicOrderCnt.
   2953   */
   2954  int output_picture_number;
   2955 
   2956  /**
   2957   * Dimensions of the decoded video intended for presentation.
   2958   */
   2959  int width;
   2960  int height;
   2961 
   2962  /**
   2963   * Dimensions of the coded video.
   2964   */
   2965  int coded_width;
   2966  int coded_height;
   2967 
   2968  /**
   2969   * The format of the coded data, corresponds to enum AVPixelFormat for video
   2970   * and for enum AVSampleFormat for audio.
   2971   *
   2972   * Note that a decoder can have considerable freedom in how exactly it
   2973   * decodes the data, so the format reported here might be different from the
   2974   * one returned by a decoder.
   2975   */
   2976  int format;
   2977 } AVCodecParserContext;
   2978 
   2979 typedef struct AVCodecParser {
   2980  int codec_ids[7]; /* several codec IDs are permitted */
   2981  int priv_data_size;
   2982  int (*parser_init)(AVCodecParserContext* s);
   2983  /* This callback never returns an error, a negative value means that
   2984   * the frame start was in a previous packet. */
   2985  int (*parser_parse)(AVCodecParserContext* s, AVCodecContext* avctx,
   2986                      const uint8_t** poutbuf, int* poutbuf_size,
   2987                      const uint8_t* buf, int buf_size);
   2988  void (*parser_close)(AVCodecParserContext* s);
   2989  int (*split)(AVCodecContext* avctx, const uint8_t* buf, int buf_size);
   2990 } AVCodecParser;
   2991 
   2992 /**
   2993 * Iterate over all registered codec parsers.
   2994 *
   2995 * @param opaque a pointer where libavcodec will store the iteration state. Must
   2996 *               point to NULL to start the iteration.
   2997 *
   2998 * @return the next registered codec parser or NULL when the iteration is
   2999 *         finished
   3000 */
   3001 const AVCodecParser* av_parser_iterate(void** opaque);
   3002 
   3003 AVCodecParserContext* av_parser_init(int codec_id);
   3004 
   3005 /**
   3006 * Parse a packet.
   3007 *
   3008 * @param s             parser context.
   3009 * @param avctx         codec context.
   3010 * @param poutbuf       set to pointer to parsed buffer or NULL if not yet
   3011 finished.
   3012 * @param poutbuf_size  set to size of parsed buffer or zero if not yet
   3013 finished.
   3014 * @param buf           input buffer.
   3015 * @param buf_size      buffer size in bytes without the padding. I.e. the full
   3016 buffer size is assumed to be buf_size + AV_INPUT_BUFFER_PADDING_SIZE. To signal
   3017 EOF, this should be 0 (so that the last frame can be output).
   3018 * @param pts           input presentation timestamp.
   3019 * @param dts           input decoding timestamp.
   3020 * @param pos           input byte position in stream.
   3021 * @return the number of bytes of the input bitstream used.
   3022 *
   3023 * Example:
   3024 * @code
   3025 *   while(in_len){
   3026 *       len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
   3027 *                                        in_data, in_len,
   3028 *                                        pts, dts, pos);
   3029 *       in_data += len;
   3030 *       in_len  -= len;
   3031 *
   3032 *       if(size)
   3033 *          decode_frame(data, size);
   3034 *   }
   3035 * @endcode
   3036 */
   3037 int av_parser_parse2(AVCodecParserContext* s, AVCodecContext* avctx,
   3038                     uint8_t** poutbuf, int* poutbuf_size, const uint8_t* buf,
   3039                     int buf_size, int64_t pts, int64_t dts, int64_t pos);
   3040 
   3041 void av_parser_close(AVCodecParserContext* s);
   3042 
   3043 /**
   3044 * @}
   3045 * @}
   3046 */
   3047 
   3048 /**
   3049 * @addtogroup lavc_encoding
   3050 * @{
   3051 */
   3052 
   3053 int avcodec_encode_subtitle(AVCodecContext* avctx, uint8_t* buf, int buf_size,
   3054                            const AVSubtitle* sub);
   3055 
   3056 /**
   3057 * @}
   3058 */
   3059 
   3060 /**
   3061 * @defgroup lavc_misc Utility functions
   3062 * @ingroup libavc
   3063 *
   3064 * Miscellaneous utility functions related to both encoding and decoding
   3065 * (or neither).
   3066 * @{
   3067 */
   3068 
   3069 /**
   3070 * @defgroup lavc_misc_pixfmt Pixel formats
   3071 *
   3072 * Functions for working with pixel formats.
   3073 * @{
   3074 */
   3075 
   3076 /**
   3077 * Return a value representing the fourCC code associated to the
   3078 * pixel format pix_fmt, or 0 if no associated fourCC code can be
   3079 * found.
   3080 */
   3081 unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat pix_fmt);
   3082 
   3083 /**
   3084 * Find the best pixel format to convert to given a certain source pixel
   3085 * format.  When converting from one pixel format to another, information loss
   3086 * may occur.  For example, when converting from RGB24 to GRAY, the color
   3087 * information will be lost. Similarly, other losses occur when converting from
   3088 * some formats to other formats. avcodec_find_best_pix_fmt_of_2() searches
   3089 * which of the given pixel formats should be used to suffer the least amount of
   3090 * loss. The pixel formats from which it chooses one, are determined by the
   3091 * pix_fmt_list parameter.
   3092 *
   3093 *
   3094 * @param[in] pix_fmt_list AV_PIX_FMT_NONE terminated array of pixel formats to
   3095 * choose from
   3096 * @param[in] src_pix_fmt source pixel format
   3097 * @param[in] has_alpha Whether the source pixel format alpha channel is used.
   3098 * @param[out] loss_ptr Combination of flags informing you what kind of losses
   3099 * will occur.
   3100 * @return The best pixel format to convert to or -1 if none was found.
   3101 */
   3102 enum AVPixelFormat avcodec_find_best_pix_fmt_of_list(
   3103    const enum AVPixelFormat* pix_fmt_list, enum AVPixelFormat src_pix_fmt,
   3104    int has_alpha, int* loss_ptr);
   3105 
   3106 enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext* s,
   3107                                              const enum AVPixelFormat* fmt);
   3108 
   3109 /**
   3110 * @}
   3111 */
   3112 
   3113 void avcodec_string(char* buf, int buf_size, AVCodecContext* enc, int encode);
   3114 
   3115 int avcodec_default_execute(AVCodecContext* c,
   3116                            int (*func)(AVCodecContext* c2, void* arg2),
   3117                            void* arg, int* ret, int count, int size);
   3118 int avcodec_default_execute2(AVCodecContext* c,
   3119                             int (*func)(AVCodecContext* c2, void* arg2, int,
   3120                                         int),
   3121                             void* arg, int* ret, int count);
   3122 // FIXME func typedef
   3123 
   3124 /**
   3125 * Fill AVFrame audio data and linesize pointers.
   3126 *
   3127 * The buffer buf must be a preallocated buffer with a size big enough
   3128 * to contain the specified samples amount. The filled AVFrame data
   3129 * pointers will point to this buffer.
   3130 *
   3131 * AVFrame extended_data channel pointers are allocated if necessary for
   3132 * planar audio.
   3133 *
   3134 * @param frame       the AVFrame
   3135 *                    frame->nb_samples must be set prior to calling the
   3136 *                    function. This function fills in frame->data,
   3137 *                    frame->extended_data, frame->linesize[0].
   3138 * @param nb_channels channel count
   3139 * @param sample_fmt  sample format
   3140 * @param buf         buffer to use for frame data
   3141 * @param buf_size    size of buffer
   3142 * @param align       plane size sample alignment (0 = default)
   3143 * @return            >=0 on success, negative error code on failure
   3144 * @todo return the size in bytes required to store the samples in
   3145 * case of success, at the next libavutil bump
   3146 */
   3147 int avcodec_fill_audio_frame(AVFrame* frame, int nb_channels,
   3148                             enum AVSampleFormat sample_fmt, const uint8_t* buf,
   3149                             int buf_size, int align);
   3150 
   3151 /**
   3152 * Reset the internal codec state / flush internal buffers. Should be called
   3153 * e.g. when seeking or when switching to a different stream.
   3154 *
   3155 * @note for decoders, this function just releases any references the decoder
   3156 * might keep internally, but the caller's references remain valid.
   3157 *
   3158 * @note for encoders, this function will only do something if the encoder
   3159 * declares support for AV_CODEC_CAP_ENCODER_FLUSH. When called, the encoder
   3160 * will drain any remaining packets, and can then be re-used for a different
   3161 * stream (as opposed to sending a null frame which will leave the encoder
   3162 * in a permanent EOF state after draining). This can be desirable if the
   3163 * cost of tearing down and replacing the encoder instance is high.
   3164 */
   3165 void avcodec_flush_buffers(AVCodecContext* avctx);
   3166 
   3167 /**
   3168 * Return audio frame duration.
   3169 *
   3170 * @param avctx        codec context
   3171 * @param frame_bytes  size of the frame, or 0 if unknown
   3172 * @return             frame duration, in samples, if known. 0 if not able to
   3173 *                     determine.
   3174 */
   3175 int av_get_audio_frame_duration(AVCodecContext* avctx, int frame_bytes);
   3176 
   3177 /* memory */
   3178 
   3179 /**
   3180 * Same behaviour av_fast_malloc but the buffer has additional
   3181 * AV_INPUT_BUFFER_PADDING_SIZE at the end which will always be 0.
   3182 *
   3183 * In addition the whole buffer will initially and after resizes
   3184 * be 0-initialized so that no uninitialized data will ever appear.
   3185 */
   3186 void av_fast_padded_malloc(void* ptr, unsigned int* size, size_t min_size);
   3187 
   3188 /**
   3189 * Same behaviour av_fast_padded_malloc except that buffer will always
   3190 * be 0-initialized after call.
   3191 */
   3192 void av_fast_padded_mallocz(void* ptr, unsigned int* size, size_t min_size);
   3193 
   3194 /**
   3195 * @return a positive value if s is open (i.e. avcodec_open2() was called on it
   3196 * with no corresponding avcodec_close()), 0 otherwise.
   3197 */
   3198 int avcodec_is_open(AVCodecContext* s);
   3199 
   3200 /**
   3201 * @}
   3202 */
   3203 
   3204 #endif /* AVCODEC_AVCODEC_H */