tor-browser

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

codec.h (13232B)


      1 /*
      2 * AVCodec public API
      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_CODEC_H
     22 #define AVCODEC_CODEC_H
     23 
     24 #include <stdint.h>
     25 
     26 #include "libavutil/avutil.h"
     27 #include "libavutil/hwcontext.h"
     28 #include "libavutil/log.h"
     29 #include "libavutil/pixfmt.h"
     30 #include "libavutil/rational.h"
     31 #include "libavutil/samplefmt.h"
     32 
     33 #include "libavcodec/codec_id.h"
     34 #include "libavcodec/version_major.h"
     35 
     36 /**
     37 * @addtogroup lavc_core
     38 * @{
     39 */
     40 
     41 /**
     42 * Decoder can use draw_horiz_band callback.
     43 */
     44 #define AV_CODEC_CAP_DRAW_HORIZ_BAND (1 << 0)
     45 /**
     46 * Codec uses get_buffer() or get_encode_buffer() for allocating buffers and
     47 * supports custom allocators.
     48 * If not set, it might not use get_buffer() or get_encode_buffer() at all, or
     49 * use operations that assume the buffer was allocated by
     50 * avcodec_default_get_buffer2 or avcodec_default_get_encode_buffer.
     51 */
     52 #define AV_CODEC_CAP_DR1 (1 << 1)
     53 /**
     54 * Encoder or decoder requires flushing with NULL input at the end in order to
     55 * give the complete and correct output.
     56 *
     57 * NOTE: If this flag is not set, the codec is guaranteed to never be fed with
     58 *       with NULL data. The user can still send NULL data to the public encode
     59 *       or decode function, but libavcodec will not pass it along to the codec
     60 *       unless this flag is set.
     61 *
     62 * Decoders:
     63 * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL,
     64 * avpkt->size=0 at the end to get the delayed data until the decoder no longer
     65 * returns frames.
     66 *
     67 * Encoders:
     68 * The encoder needs to be fed with NULL data at the end of encoding until the
     69 * encoder no longer returns data.
     70 *
     71 * NOTE: For encoders implementing the AVCodec.encode2() function, setting this
     72 *       flag also means that the encoder must set the pts and duration for
     73 *       each output packet. If this flag is not set, the pts and duration will
     74 *       be determined by libavcodec from the input frame.
     75 */
     76 #define AV_CODEC_CAP_DELAY (1 << 5)
     77 /**
     78 * Codec can be fed a final frame with a smaller size.
     79 * This can be used to prevent truncation of the last audio samples.
     80 */
     81 #define AV_CODEC_CAP_SMALL_LAST_FRAME (1 << 6)
     82 
     83 /**
     84 * Codec can output multiple frames per AVPacket
     85 * Normally demuxers return one frame at a time, demuxers which do not do
     86 * are connected to a parser to split what they return into proper frames.
     87 * This flag is reserved to the very rare category of codecs which have a
     88 * bitstream that cannot be split into frames without timeconsuming
     89 * operations like full decoding. Demuxers carrying such bitstreams thus
     90 * may return multiple frames in a packet. This has many disadvantages like
     91 * prohibiting stream copy in many cases thus it should only be considered
     92 * as a last resort.
     93 */
     94 #define AV_CODEC_CAP_SUBFRAMES (1 << 8)
     95 /**
     96 * Codec is experimental and is thus avoided in favor of non experimental
     97 * encoders
     98 */
     99 #define AV_CODEC_CAP_EXPERIMENTAL (1 << 9)
    100 /**
    101 * Codec should fill in channel configuration and samplerate instead of
    102 * container
    103 */
    104 #define AV_CODEC_CAP_CHANNEL_CONF (1 << 10)
    105 /**
    106 * Codec supports frame-level multithreading.
    107 */
    108 #define AV_CODEC_CAP_FRAME_THREADS (1 << 12)
    109 /**
    110 * Codec supports slice-based (or partition-based) multithreading.
    111 */
    112 #define AV_CODEC_CAP_SLICE_THREADS (1 << 13)
    113 /**
    114 * Codec supports changed parameters at any point.
    115 */
    116 #define AV_CODEC_CAP_PARAM_CHANGE (1 << 14)
    117 /**
    118 * Codec supports multithreading through a method other than slice- or
    119 * frame-level multithreading. Typically this marks wrappers around
    120 * multithreading-capable external libraries.
    121 */
    122 #define AV_CODEC_CAP_OTHER_THREADS (1 << 15)
    123 /**
    124 * Audio encoder supports receiving a different number of samples in each call.
    125 */
    126 #define AV_CODEC_CAP_VARIABLE_FRAME_SIZE (1 << 16)
    127 /**
    128 * Decoder is not a preferred choice for probing.
    129 * This indicates that the decoder is not a good choice for probing.
    130 * It could for example be an expensive to spin up hardware decoder,
    131 * or it could simply not provide a lot of useful information about
    132 * the stream.
    133 * A decoder marked with this flag should only be used as last resort
    134 * choice for probing.
    135 */
    136 #define AV_CODEC_CAP_AVOID_PROBING (1 << 17)
    137 
    138 /**
    139 * Codec is backed by a hardware implementation. Typically used to
    140 * identify a non-hwaccel hardware decoder. For information about hwaccels, use
    141 * avcodec_get_hw_config() instead.
    142 */
    143 #define AV_CODEC_CAP_HARDWARE (1 << 18)
    144 
    145 /**
    146 * Codec is potentially backed by a hardware implementation, but not
    147 * necessarily. This is used instead of AV_CODEC_CAP_HARDWARE, if the
    148 * implementation provides some sort of internal fallback.
    149 */
    150 #define AV_CODEC_CAP_HYBRID (1 << 19)
    151 
    152 /**
    153 * This encoder can reorder user opaque values from input AVFrames and return
    154 * them with corresponding output packets.
    155 * @see AV_CODEC_FLAG_COPY_OPAQUE
    156 */
    157 #define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE (1 << 20)
    158 
    159 /**
    160 * This encoder can be flushed using avcodec_flush_buffers(). If this flag is
    161 * not set, the encoder must be closed and reopened to ensure that no frames
    162 * remain pending.
    163 */
    164 #define AV_CODEC_CAP_ENCODER_FLUSH (1 << 21)
    165 
    166 /**
    167 * The encoder is able to output reconstructed frame data, i.e. raw frames that
    168 * would be produced by decoding the encoded bitstream.
    169 *
    170 * Reconstructed frame output is enabled by the AV_CODEC_FLAG_RECON_FRAME flag.
    171 */
    172 #define AV_CODEC_CAP_ENCODER_RECON_FRAME (1 << 22)
    173 
    174 /**
    175 * AVProfile.
    176 */
    177 typedef struct AVProfile {
    178  int profile;
    179  const char* name;  ///< short name for the profile
    180 } AVProfile;
    181 
    182 /**
    183 * AVCodec.
    184 */
    185 typedef struct AVCodec {
    186  /**
    187   * Name of the codec implementation.
    188   * The name is globally unique among encoders and among decoders (but an
    189   * encoder and a decoder can share the same name).
    190   * This is the primary way to find a codec from the user perspective.
    191   */
    192  const char* name;
    193  /**
    194   * Descriptive name for the codec, meant to be more human readable than name.
    195   * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
    196   */
    197  const char* long_name;
    198  enum AVMediaType type;
    199  enum AVCodecID id;
    200  /**
    201   * Codec capabilities.
    202   * see AV_CODEC_CAP_*
    203   */
    204  int capabilities;
    205  uint8_t max_lowres;  ///< maximum value for lowres supported by the decoder
    206  const AVRational*
    207      supported_framerates;  ///< array of supported framerates, or NULL if any,
    208                             ///< array is terminated by {0,0}
    209  const enum AVPixelFormat*
    210      pix_fmts;  ///< array of supported pixel formats, or NULL if unknown,
    211                 ///< array is terminated by -1
    212  const int*
    213      supported_samplerates;  ///< array of supported audio samplerates, or NULL
    214                              ///< if unknown, array is terminated by 0
    215  const enum AVSampleFormat*
    216      sample_fmts;  ///< array of supported sample formats, or NULL if unknown,
    217                    ///< array is terminated by -1
    218 #if FF_API_OLD_CHANNEL_LAYOUT
    219  /**
    220   * @deprecated use ch_layouts instead
    221   */
    222  attribute_deprecated const uint64_t*
    223      channel_layouts;  ///< array of support channel layouts, or NULL if
    224                        ///< unknown. array is terminated by 0
    225 #endif
    226  const AVClass* priv_class;  ///< AVClass for the private context
    227  const AVProfile*
    228      profiles;  ///< array of recognized profiles, or NULL if unknown, array is
    229                 ///< terminated by {FF_PROFILE_UNKNOWN}
    230 
    231  /**
    232   * Group name of the codec implementation.
    233   * This is a short symbolic name of the wrapper backing this codec. A
    234   * wrapper uses some kind of external implementation for the codec, such
    235   * as an external library, or a codec implementation provided by the OS or
    236   * the hardware.
    237   * If this field is NULL, this is a builtin, libavcodec native codec.
    238   * If non-NULL, this will be the suffix in AVCodec.name in most cases
    239   * (usually AVCodec.name will be of the form "<codec_name>_<wrapper_name>").
    240   */
    241  const char* wrapper_name;
    242 
    243  /**
    244   * Array of supported channel layouts, terminated with a zeroed layout.
    245   */
    246  const AVChannelLayout* ch_layouts;
    247 } AVCodec;
    248 
    249 /**
    250 * Iterate over all registered codecs.
    251 *
    252 * @param opaque a pointer where libavcodec will store the iteration state. Must
    253 *               point to NULL to start the iteration.
    254 *
    255 * @return the next registered codec or NULL when the iteration is
    256 *         finished
    257 */
    258 const AVCodec* av_codec_iterate(void** opaque);
    259 
    260 /**
    261 * Find a registered decoder with a matching codec ID.
    262 *
    263 * @param id AVCodecID of the requested decoder
    264 * @return A decoder if one was found, NULL otherwise.
    265 */
    266 const AVCodec* avcodec_find_decoder(enum AVCodecID id);
    267 
    268 /**
    269 * Find a registered decoder with the specified name.
    270 *
    271 * @param name name of the requested decoder
    272 * @return A decoder if one was found, NULL otherwise.
    273 */
    274 const AVCodec* avcodec_find_decoder_by_name(const char* name);
    275 
    276 /**
    277 * Find a registered encoder with a matching codec ID.
    278 *
    279 * @param id AVCodecID of the requested encoder
    280 * @return An encoder if one was found, NULL otherwise.
    281 */
    282 const AVCodec* avcodec_find_encoder(enum AVCodecID id);
    283 
    284 /**
    285 * Find a registered encoder with the specified name.
    286 *
    287 * @param name name of the requested encoder
    288 * @return An encoder if one was found, NULL otherwise.
    289 */
    290 const AVCodec* avcodec_find_encoder_by_name(const char* name);
    291 /**
    292 * @return a non-zero number if codec is an encoder, zero otherwise
    293 */
    294 int av_codec_is_encoder(const AVCodec* codec);
    295 
    296 /**
    297 * @return a non-zero number if codec is a decoder, zero otherwise
    298 */
    299 int av_codec_is_decoder(const AVCodec* codec);
    300 
    301 /**
    302 * Return a name for the specified profile, if available.
    303 *
    304 * @param codec the codec that is searched for the given profile
    305 * @param profile the profile value for which a name is requested
    306 * @return A name for the profile if found, NULL otherwise.
    307 */
    308 const char* av_get_profile_name(const AVCodec* codec, int profile);
    309 
    310 enum {
    311  /**
    312   * The codec supports this format via the hw_device_ctx interface.
    313   *
    314   * When selecting this format, AVCodecContext.hw_device_ctx should
    315   * have been set to a device of the specified type before calling
    316   * avcodec_open2().
    317   */
    318  AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX = 0x01,
    319  /**
    320   * The codec supports this format via the hw_frames_ctx interface.
    321   *
    322   * When selecting this format for a decoder,
    323   * AVCodecContext.hw_frames_ctx should be set to a suitable frames
    324   * context inside the get_format() callback.  The frames context
    325   * must have been created on a device of the specified type.
    326   *
    327   * When selecting this format for an encoder,
    328   * AVCodecContext.hw_frames_ctx should be set to the context which
    329   * will be used for the input frames before calling avcodec_open2().
    330   */
    331  AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX = 0x02,
    332  /**
    333   * The codec supports this format by some internal method.
    334   *
    335   * This format can be selected without any additional configuration -
    336   * no device or frames context is required.
    337   */
    338  AV_CODEC_HW_CONFIG_METHOD_INTERNAL = 0x04,
    339  /**
    340   * The codec supports this format by some ad-hoc method.
    341   *
    342   * Additional settings and/or function calls are required.  See the
    343   * codec-specific documentation for details.  (Methods requiring
    344   * this sort of configuration are deprecated and others should be
    345   * used in preference.)
    346   */
    347  AV_CODEC_HW_CONFIG_METHOD_AD_HOC = 0x08,
    348 };
    349 
    350 typedef struct AVCodecHWConfig {
    351  /**
    352   * For decoders, a hardware pixel format which that decoder may be
    353   * able to decode to if suitable hardware is available.
    354   *
    355   * For encoders, a pixel format which the encoder may be able to
    356   * accept.  If set to AV_PIX_FMT_NONE, this applies to all pixel
    357   * formats supported by the codec.
    358   */
    359  enum AVPixelFormat pix_fmt;
    360  /**
    361   * Bit set of AV_CODEC_HW_CONFIG_METHOD_* flags, describing the possible
    362   * setup methods which can be used with this configuration.
    363   */
    364  int methods;
    365  /**
    366   * The device type associated with the configuration.
    367   *
    368   * Must be set for AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX and
    369   * AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, otherwise unused.
    370   */
    371  enum AVHWDeviceType device_type;
    372 } AVCodecHWConfig;
    373 
    374 /**
    375 * Retrieve supported hardware configurations for a codec.
    376 *
    377 * Values of index from zero to some maximum return the indexed configuration
    378 * descriptor; all other values return NULL.  If the codec does not support
    379 * any hardware configurations then it will always return NULL.
    380 */
    381 const AVCodecHWConfig* avcodec_get_hw_config(const AVCodec* codec, int index);
    382 
    383 /**
    384 * @}
    385 */
    386 
    387 #endif /* AVCODEC_CODEC_H */