2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19#ifndef AVCODEC_CODEC_INTERNAL_H
20#define AVCODEC_CODEC_INTERNAL_H
30 * The codec is not known to be init-threadsafe (i.e. it might be unsafe
31 * to initialize this codec and another codec concurrently, typically because
32 * the codec calls external APIs that are not known to be thread-safe).
33 * Therefore calling the codec's init function needs to be guarded with a lock.
35 #define FF_CODEC_CAP_NOT_INIT_THREADSAFE (1 << 0)
37 * The codec allows calling the close function for deallocation even if
38 * the init function returned a failure. Without this capability flag, a
39 * codec does such cleanup internally when returning failures from the
40 * init function and does not expect the close function to be called at
43 #define FF_CODEC_CAP_INIT_CLEANUP (1 << 1)
45 * Decoders marked with FF_CODEC_CAP_SETS_PKT_DTS want to set
46 * AVFrame.pkt_dts manually. If the flag is set, decode.c won't overwrite
47 * this field. If it's unset, decode.c tries to guess the pkt_dts field
48 * from the input AVPacket.
50 #define FF_CODEC_CAP_SETS_PKT_DTS (1 << 2)
52 * The decoder extracts and fills its parameters even if the frame is
53 * skipped due to the skip_frame setting.
55 #define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM (1 << 3)
57 * The decoder sets the cropping fields in the output frames manually.
58 * If this cap is set, the generic code will initialize output frame
59 * dimensions to coded rather than display values.
61 #define FF_CODEC_CAP_EXPORTS_CROPPING (1 << 4)
63 * Codec initializes slice-based threading with a main function
65 #define FF_CODEC_CAP_SLICE_THREAD_HAS_MF (1 << 5)
67 * The decoder might make use of the ProgressFrame API.
69 #define FF_CODEC_CAP_USES_PROGRESSFRAMES (1 << 6)
71 * Codec handles avctx->thread_count == 0 (auto) internally.
73 #define FF_CODEC_CAP_AUTO_THREADS (1 << 7)
75 * Codec handles output frame properties internally instead of letting the
76 * internal logic derive them from AVCodecInternal.last_pkt_props.
78 #define FF_CODEC_CAP_SETS_FRAME_PROPS (1 << 8)
80 * Codec supports embedded ICC profiles (AV_FRAME_DATA_ICC_PROFILE).
82 #define FF_CODEC_CAP_ICC_PROFILES (1 << 9)
84 * The encoder has AV_CODEC_CAP_DELAY set, but does not actually have delay - it
85 * only wants to be flushed at the end to update some context variables (e.g.
86 * 2pass stats) or produce a trailing packet. Besides that it immediately
87 * produces exactly one output packet per each input frame, just as no-delay
90 #define FF_CODEC_CAP_EOF_FLUSH (1 << 10)
93 * FFCodec.codec_tags termination value
95 #define FF_CODEC_TAGS_END -1
109 /* The codec is a decoder using the decode callback;
110 * audio and video codecs only. */
112 /* The codec is a decoder using the decode_sub callback;
113 * subtitle codecs only. */
115 /* The codec is a decoder using the receive_frame callback;
116 * audio and video codecs only. */
118 /* The codec is an encoder using the encode callback;
119 * audio and video codecs only. */
121 /* The codec is an encoder using the encode_sub callback;
122 * subtitle codecs only. */
124 /* The codec is an encoder using the receive_packet callback;
125 * audio and video codecs only. */
131 * The public AVCodec. See codec.h for it.
136 * Internal codec capabilities FF_CODEC_CAP_*.
146 * This field determines the video color ranges supported by an encoder.
147 * Should be set to a bitmask of AVCOL_RANGE_MPEG and AVCOL_RANGE_JPEG.
152 * This field determines the alpha modes supported by an encoder.
153 * Should be set to a bitmask of AVALPHA_MODE_PREMULTIPLIED and AVALPHA_MODE_STRAIGHT.
158 * This field determines the type of the codec (decoder/encoder)
159 * and also the exact callback cb implemented by the codec.
160 * cb_type uses enum FFCodecType values.
166 * @name Frame-level threading support functions
170 * Copy necessary context variables from a previous thread context to the current one.
171 * If not defined, the next thread will start automatically; otherwise, the codec
172 * must call ff_thread_finish_setup().
174 * dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
179 * Copy variables back to the user-facing context
185 * Private codec-specific defaults.
193 * Decode to an AVFrame.
194 * cb is in this state if cb_type is FF_CODEC_CB_TYPE_DECODE.
196 * @param avctx codec context
197 * @param[out] frame AVFrame for output
198 * @param[out] got_frame_ptr decoder sets to 0 or 1 to indicate that
199 * a non-empty frame was returned in frame.
200 * @param[in] avpkt AVPacket containing the data to be decoded
201 * @return amount of bytes read from the packet on success,
202 * negative error code on failure
205 int *got_frame_ptr,
struct AVPacket *avpkt);
207 * Decode subtitle data to an AVSubtitle.
208 * cb is in this state if cb_type is FF_CODEC_CB_TYPE_DECODE_SUB.
210 * Apart from that this is like the decode callback.
213 int *got_frame_ptr,
const struct AVPacket *avpkt);
215 * Decode API with decoupled packet/frame dataflow.
216 * cb is in this state if cb_type is FF_CODEC_CB_TYPE_RECEIVE_FRAME.
218 * This function is called to get one output frame. It should call
219 * ff_decode_get_packet() to obtain input data.
223 * Encode data to an AVPacket.
224 * cb is in this state if cb_type is FF_CODEC_CB_TYPE_ENCODE
226 * @param avctx codec context
227 * @param[out] avpkt output AVPacket
228 * @param[in] frame AVFrame containing the input to be encoded
229 * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
230 * non-empty packet was returned in avpkt.
231 * @return 0 on success, negative error code on failure
236 * Encode subtitles to a raw buffer.
237 * cb is in this state if cb_type is FF_CODEC_CB_TYPE_ENCODE_SUB.
242 * Encode API with decoupled frame/packet dataflow.
243 * cb is in this state if cb_type is FF_CODEC_CB_TYPE_RECEIVE_PACKET.
245 * This function is called to get one output packet.
246 * It should call ff_encode_get_frame() to obtain input data.
255 * Will be called when seeking
261 * Encoding only. Reconfigure the encoder
262 * Called by avcodec_encode_reconfigure()
267 * Decoding only, a comma-separated list of bitstream filters to apply to
268 * packets before decoding.
274 * Array of pointers to hardware configurations supported by the codec,
275 * or NULL if no hardware supported. The array is terminated by a NULL
278 * The user can only access this field via avcodec_get_hw_config().
283 * List of supported codec_tags, terminated by FF_CODEC_TAGS_END.
288 * Custom callback for avcodec_get_supported_config(). If absent,
289 * ff_default_get_supported_config() will be used. `out_num_configs` will
290 * always be set to a valid pointer.
296 const void **out_configs,
297 int *out_num_configs);
298#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
303 /// Video-only fields
308 /// Audio-only fields
323 * Internal version of av_codec_is_encoder(). Must not be called with
333 * Internal version of av_codec_is_decoder(). Must not be called with
343 * Default implementation for avcodec_get_supported_config(). Will return the
344 * relevant fields from AVCodec if present, or NULL otherwise.
346 * For AVCODEC_CONFIG_COLOR_RANGE, the output will depend on the bitmask in
347 * FFCodec.color_ranges, with a value of 0 returning NULL.
353 const void **out_configs,
354 int *out_num_configs);
357#define CODEC_LONG_NAME(str) .p.long_name = NULL
359 #define CODEC_LONG_NAME(str) .p.long_name = str
363#define UPDATE_THREAD_CONTEXT(func) \
364 .update_thread_context = (func)
365#define UPDATE_THREAD_CONTEXT_FOR_USER(func) \
366 .update_thread_context_for_user = (func)
368 #define UPDATE_THREAD_CONTEXT(func) \
369 .update_thread_context = NULL
370 #define UPDATE_THREAD_CONTEXT_FOR_USER(func) \
371 .update_thread_context_for_user = NULL
374 #define FF_CODEC_DECODE_CB(func) \
376 .cb_type = FF_CODEC_CB_TYPE_DECODE, \
378 #define FF_CODEC_DECODE_SUB_CB(func) \
380 .cb_type = FF_CODEC_CB_TYPE_DECODE_SUB, \
381 .cb.decode_sub = (func)
382 #define FF_CODEC_RECEIVE_FRAME_CB(func) \
384 .cb_type = FF_CODEC_CB_TYPE_RECEIVE_FRAME, \
385 .cb.receive_frame = (func)
386 #define FF_CODEC_ENCODE_CB(func) \
388 .cb_type = FF_CODEC_CB_TYPE_ENCODE, \
390 #define FF_CODEC_ENCODE_SUB_CB(func) \
392 .cb_type = FF_CODEC_CB_TYPE_ENCODE_SUB, \
393 .cb.encode_sub = (func)
394 #define FF_CODEC_RECEIVE_PACKET_CB(func) \
396 .cb_type = FF_CODEC_CB_TYPE_RECEIVE_PACKET, \
397 .cb.receive_packet = (func)
399 #define CODEC_CH_LAYOUTS(...) CODEC_CH_LAYOUTS_ARRAY(((const AVChannelLayout[]) { __VA_ARGS__, { 0 } }))
400 #define CODEC_CH_LAYOUTS_ARRAY(array) CODEC_ARRAY(ch_layouts, (array))
402 #define CODEC_SAMPLERATES(...) CODEC_SAMPLERATES_ARRAY(((const int[]) { __VA_ARGS__, 0 }))
403 #define CODEC_SAMPLERATES_ARRAY(array) CODEC_ARRAY(supported_samplerates, (array))
405 #define CODEC_SAMPLEFMTS(...) CODEC_SAMPLEFMTS_ARRAY(((const enum AVSampleFormat[]) { __VA_ARGS__, AV_SAMPLE_FMT_NONE }))
406 #define CODEC_SAMPLEFMTS_ARRAY(array) CODEC_ARRAY(sample_fmts, (array))
408 #define CODEC_FRAMERATES(...) CODEC_FRAMERATES_ARRAY(((const AVRational[]) { __VA_ARGS__, { 0, 0 } }))
409 #define CODEC_FRAMERATES_ARRAY(array) CODEC_ARRAY(supported_framerates, (array))
411 #define CODEC_PIXFMTS(...) CODEC_PIXFMTS_ARRAY(((const enum AVPixelFormat[]) { __VA_ARGS__, AV_PIX_FMT_NONE }))
412 #define CODEC_PIXFMTS_ARRAY(array) CODEC_ARRAY(pix_fmts, (array))
414 #define CODEC_ARRAY(field, array) \
417#endif /* AVCODEC_CODEC_INTERNAL_H */
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Libavcodec external API header.
#define flags(name, subs,...)
int ff_default_get_supported_config(const struct AVCodecContext *avctx, const AVCodec *codec, enum AVCodecConfig config, unsigned flags, const void **out_configs, int *out_num_configs)
Default implementation for avcodec_get_supported_config().
@ FF_CODEC_CB_TYPE_ENCODE
@ FF_CODEC_CB_TYPE_RECEIVE_PACKET
@ FF_CODEC_CB_TYPE_DECODE_SUB
@ FF_CODEC_CB_TYPE_RECEIVE_FRAME
@ FF_CODEC_CB_TYPE_ENCODE_SUB
@ FF_CODEC_CB_TYPE_DECODE
static av_always_inline const FFCodec * ffcodec(const AVCodec *codec)
static int ff_codec_is_decoder(const AVCodec *avcodec)
Internal version of av_codec_is_decoder().
static int ff_codec_is_encoder(const AVCodec *avcodec)
Internal version of av_codec_is_encoder().
AVSampleFormat
Audio sample formats.
Macro definitions for various function/variable attributes.
AVPixelFormat
Pixel format.
An AVChannelLayout holds information about the channel layout of audio data.
main external API structure.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
int(* update_thread_context)(struct AVCodecContext *dst, const struct AVCodecContext *src)
Copy necessary context variables from a previous thread context to the current one.
AVCodec p
The public AVCodec.
enum AVSampleFormat * sample_fmts
const AVChannelLayout * ch_layouts
int(* init)(struct AVCodecContext *)
int(* receive_frame)(struct AVCodecContext *avctx, struct AVFrame *frame)
Decode API with decoupled packet/frame dataflow.
const struct AVCodecHWConfigInternal *const * hw_configs
Array of pointers to hardware configurations supported by the codec, or NULL if no hardware supported...
int(* update_thread_context_for_user)(struct AVCodecContext *dst, const struct AVCodecContext *src)
Copy variables back to the user-facing context.
unsigned cb_type
This field determines the type of the codec (decoder/encoder) and also the exact callback cb implemen...
const int * supported_samplerates
const char * bsfs
Decoding only, a comma-separated list of bitstream filters to apply to packets before decoding.
void(* flush)(struct AVCodecContext *)
Flush buffers.
int(* decode_sub)(struct AVCodecContext *avctx, struct AVSubtitle *sub, int *got_frame_ptr, const struct AVPacket *avpkt)
Decode subtitle data to an AVSubtitle.
unsigned alpha_modes
This field determines the alpha modes supported by an encoder.
const FFCodecDefault * defaults
Private codec-specific defaults.
int(* decode)(struct AVCodecContext *avctx, struct AVFrame *frame, int *got_frame_ptr, struct AVPacket *avpkt)
Decode to an AVFrame.
const uint32_t * codec_tags
List of supported codec_tags, terminated by FF_CODEC_TAGS_END.
int(* receive_packet)(struct AVCodecContext *avctx, struct AVPacket *avpkt)
Encode API with decoupled frame/packet dataflow.
int(* reconf)(struct AVCodecContext *avctx, struct AVDictionary **dict)
Encoding only.
int(* encode_sub)(struct AVCodecContext *avctx, uint8_t *buf, int buf_size, const struct AVSubtitle *sub)
Encode subtitles to a raw buffer.
const AVRational * supported_framerates
unsigned is_decoder
Is this a decoder?
int(* encode)(struct AVCodecContext *avctx, struct AVPacket *avpkt, const struct AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
enum AVPixelFormat * pix_fmts
unsigned caps_internal
Internal codec capabilities FF_CODEC_CAP_*.
int(* close)(struct AVCodecContext *)
int(* get_supported_config)(const struct AVCodecContext *avctx, const AVCodec *codec, enum AVCodecConfig config, unsigned flags, const void **out_configs, int *out_num_configs)
Custom callback for avcodec_get_supported_config().
unsigned color_ranges
This field determines the video color ranges supported by an encoder.
static double cb(void *priv, double x, double y)