4 * This file is part of FFmpeg.
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.
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.
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
21 #ifndef AVCODEC_CODEC_H
22 #define AVCODEC_CODEC_H
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"
33 #include "libavcodec/codec_id.h"
34 #include "libavcodec/version_major.h"
37 * @addtogroup lavc_core
42 * Decoder can use draw_horiz_band callback.
44 #define AV_CODEC_CAP_DRAW_HORIZ_BAND (1 << 0)
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.
52 #define AV_CODEC_CAP_DR1 (1 << 1)
54 * Encoder or decoder requires flushing with NULL input at the end in order to
55 * give the complete and correct output.
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.
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
68 * The encoder needs to be fed with NULL data at the end of encoding until the
69 * encoder no longer returns data.
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.
76 #define AV_CODEC_CAP_DELAY (1 << 5)
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.
81 #define AV_CODEC_CAP_SMALL_LAST_FRAME (1 << 6)
84 * Codec is experimental and is thus avoided in favor of non experimental
87 #define AV_CODEC_CAP_EXPERIMENTAL (1 << 9)
89 * Codec should fill in channel configuration and samplerate instead of container
91 #define AV_CODEC_CAP_CHANNEL_CONF (1 << 10)
93 * Codec supports frame-level multithreading.
95 #define AV_CODEC_CAP_FRAME_THREADS (1 << 12)
97 * Codec supports slice-based (or partition-based) multithreading.
99 #define AV_CODEC_CAP_SLICE_THREADS (1 << 13)
101 * Codec supports changed parameters at any point.
103 #define AV_CODEC_CAP_PARAM_CHANGE (1 << 14)
105 * Codec supports multithreading through a method other than slice- or
106 * frame-level multithreading. Typically this marks wrappers around
107 * multithreading-capable external libraries.
109 #define AV_CODEC_CAP_OTHER_THREADS (1 << 15)
111 * Audio encoder supports receiving a different number of samples in each call.
113 #define AV_CODEC_CAP_VARIABLE_FRAME_SIZE (1 << 16)
115 * Decoder is not a preferred choice for probing.
116 * This indicates that the decoder is not a good choice for probing.
117 * It could for example be an expensive to spin up hardware decoder,
118 * or it could simply not provide a lot of useful information about
120 * A decoder marked with this flag should only be used as last resort
121 * choice for probing.
123 #define AV_CODEC_CAP_AVOID_PROBING (1 << 17)
126 * Codec is backed by a hardware implementation. Typically used to
127 * identify a non-hwaccel hardware decoder. For information about hwaccels, use
128 * avcodec_get_hw_config() instead.
130 #define AV_CODEC_CAP_HARDWARE (1 << 18)
133 * Codec is potentially backed by a hardware implementation, but not
134 * necessarily. This is used instead of AV_CODEC_CAP_HARDWARE, if the
135 * implementation provides some sort of internal fallback.
137 #define AV_CODEC_CAP_HYBRID (1 << 19)
140 * This encoder can reorder user opaque values from input AVFrames and return
141 * them with corresponding output packets.
142 * @see AV_CODEC_FLAG_COPY_OPAQUE
144 #define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE (1 << 20)
147 * This encoder can be flushed using avcodec_flush_buffers(). If this flag is
148 * not set, the encoder must be closed and reopened to ensure that no frames
151 #define AV_CODEC_CAP_ENCODER_FLUSH (1 << 21)
154 * The encoder is able to output reconstructed frame data, i.e. raw frames that
155 * would be produced by decoding the encoded bitstream.
157 * Reconstructed frame output is enabled by the AV_CODEC_FLAG_RECON_FRAME flag.
159 #define AV_CODEC_CAP_ENCODER_RECON_FRAME (1 << 22)
164 typedef struct AVProfile
{
166 const char *name
; ///< short name for the profile
172 typedef struct AVCodec
{
174 * Name of the codec implementation.
175 * The name is globally unique among encoders and among decoders (but an
176 * encoder and a decoder can share the same name).
177 * This is the primary way to find a codec from the user perspective.
181 * Descriptive name for the codec, meant to be more human readable than name.
182 * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
184 const char *long_name
;
185 enum AVMediaType type
;
188 * Codec capabilities.
192 uint8_t max_lowres
; ///< maximum value for lowres supported by the decoder
195 * Deprecated codec capabilities.
198 const AVRational
*supported_framerates
; ///< @deprecated use avcodec_get_supported_config()
200 const enum AVPixelFormat
*pix_fmts
; ///< @deprecated use avcodec_get_supported_config()
202 const int *supported_samplerates
; ///< @deprecated use avcodec_get_supported_config()
204 const enum AVSampleFormat
*sample_fmts
; ///< @deprecated use avcodec_get_supported_config()
206 const AVClass
*priv_class
; ///< AVClass for the private context
207 const AVProfile
*profiles
; ///< array of recognized profiles, or NULL if unknown, array is terminated by {AV_PROFILE_UNKNOWN}
210 * Group name of the codec implementation.
211 * This is a short symbolic name of the wrapper backing this codec. A
212 * wrapper uses some kind of external implementation for the codec, such
213 * as an external library, or a codec implementation provided by the OS or
215 * If this field is NULL, this is a builtin, libavcodec native codec.
216 * If non-NULL, this will be the suffix in AVCodec.name in most cases
217 * (usually AVCodec.name will be of the form "<codec_name>_<wrapper_name>").
219 const char *wrapper_name
;
222 * Array of supported channel layouts, terminated with a zeroed layout.
223 * @deprecated use avcodec_get_supported_config()
226 const AVChannelLayout
*ch_layouts
;
230 * Iterate over all registered codecs.
232 * @param opaque a pointer where libavcodec will store the iteration state. Must
233 * point to NULL to start the iteration.
235 * @return the next registered codec or NULL when the iteration is
238 const AVCodec
*av_codec_iterate(void **opaque
);
241 * Find a registered decoder with a matching codec ID.
243 * @param id AVCodecID of the requested decoder
244 * @return A decoder if one was found, NULL otherwise.
246 const AVCodec
*avcodec_find_decoder(enum AVCodecID id
);
249 * Find a registered decoder with the specified name.
251 * @param name name of the requested decoder
252 * @return A decoder if one was found, NULL otherwise.
254 const AVCodec
*avcodec_find_decoder_by_name(const char *name
);
257 * Find a registered encoder with a matching codec ID.
259 * @param id AVCodecID of the requested encoder
260 * @return An encoder if one was found, NULL otherwise.
262 const AVCodec
*avcodec_find_encoder(enum AVCodecID id
);
265 * Find a registered encoder with the specified name.
267 * @param name name of the requested encoder
268 * @return An encoder if one was found, NULL otherwise.
270 const AVCodec
*avcodec_find_encoder_by_name(const char *name
);
272 * @return a non-zero number if codec is an encoder, zero otherwise
274 int av_codec_is_encoder(const AVCodec
*codec
);
277 * @return a non-zero number if codec is a decoder, zero otherwise
279 int av_codec_is_decoder(const AVCodec
*codec
);
282 * Return a name for the specified profile, if available.
284 * @param codec the codec that is searched for the given profile
285 * @param profile the profile value for which a name is requested
286 * @return A name for the profile if found, NULL otherwise.
288 const char *av_get_profile_name(const AVCodec
*codec
, int profile
);
292 * The codec supports this format via the hw_device_ctx interface.
294 * When selecting this format, AVCodecContext.hw_device_ctx should
295 * have been set to a device of the specified type before calling
298 AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
= 0x01,
300 * The codec supports this format via the hw_frames_ctx interface.
302 * When selecting this format for a decoder,
303 * AVCodecContext.hw_frames_ctx should be set to a suitable frames
304 * context inside the get_format() callback. The frames context
305 * must have been created on a device of the specified type.
307 * When selecting this format for an encoder,
308 * AVCodecContext.hw_frames_ctx should be set to the context which
309 * will be used for the input frames before calling avcodec_open2().
311 AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
= 0x02,
313 * The codec supports this format by some internal method.
315 * This format can be selected without any additional configuration -
316 * no device or frames context is required.
318 AV_CODEC_HW_CONFIG_METHOD_INTERNAL
= 0x04,
320 * The codec supports this format by some ad-hoc method.
322 * Additional settings and/or function calls are required. See the
323 * codec-specific documentation for details. (Methods requiring
324 * this sort of configuration are deprecated and others should be
325 * used in preference.)
327 AV_CODEC_HW_CONFIG_METHOD_AD_HOC
= 0x08,
330 typedef struct AVCodecHWConfig
{
332 * For decoders, a hardware pixel format which that decoder may be
333 * able to decode to if suitable hardware is available.
335 * For encoders, a pixel format which the encoder may be able to
336 * accept. If set to AV_PIX_FMT_NONE, this applies to all pixel
337 * formats supported by the codec.
339 enum AVPixelFormat pix_fmt
;
341 * Bit set of AV_CODEC_HW_CONFIG_METHOD_* flags, describing the possible
342 * setup methods which can be used with this configuration.
346 * The device type associated with the configuration.
348 * Must be set for AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX and
349 * AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, otherwise unused.
351 enum AVHWDeviceType device_type
;
355 * Retrieve supported hardware configurations for a codec.
357 * Values of index from zero to some maximum return the indexed configuration
358 * descriptor; all other values return NULL. If the codec does not support
359 * any hardware configurations then it will always return NULL.
361 const AVCodecHWConfig
*avcodec_get_hw_config(const AVCodec
*codec
, int index
);
367 #endif /* AVCODEC_CODEC_H */