FFmpeg: libavcodec/tests/avcodec.c Source File
Go to the documentation of this file. 1 /*
2 * This file is part of FFmpeg.
3 *
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.
8 *
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.
13 *
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
17 */
18
24
26 {
28 return ret ?
ret :
"unknown";
29 }
30
31 #define AV_LOG(...) av_log(NULL, AV_LOG_FATAL, __VA_ARGS__)
32 #define ERR_INTERNAL(msg, ...) \
33 do { \
34 AV_LOG(msg, codec->name __VA_ARGS__); \
35 ret = 1; \
36 } while (0)
37 #define ERR(msg) ERR_INTERNAL(msg, )
38 #define ERR_EXT(msg, ...) ERR_INTERNAL(msg, , __VA_ARGS__)
39
41 {
44 return 1;
46 return 0;
51 AV_LOG(
"Option %s offset %d nonsensical\n",
52 opt->name, opt->offset);
53 return 1;
54 }
55 }
56 return 0;
57 }
58
59 #define ARRAY_CHECK(field, var, type, is_sentinel, check, sentinel_check) \
60 do { \
61 const type *ptr = codec->field; \
62 if (!ptr) \
63 break; \
64 type var = *ptr; \
65 if (is_sentinel) { \
66 ERR("Codec %s sets " #field ", but without valid elements.\n"); \
67 break; \
68 } \
69 do { \
70 if (!(check)) { \
71 ERR("Codec's %s " #field " array contains invalid element\n");\
72 break; \
73 } \
74 ++ptr; \
75 var = *ptr; \
76 } while (!(is_sentinel)); \
77 if (!(sentinel_check)) { \
78 ERR("Codec's %s " #field " array has malformed sentinel\n"); \
79 break; \
80 } \
81 } while (0)
82
87
91 int is_decoder = 0, is_encoder = 0;
92
94 AV_LOG(
"Codec for format %s has no name\n",
97 continue;
98 }
102 ERR_EXT(
"Codec %s has unsupported type %s\n",
108 ERR(
"Non-audio codec %s has audio-only fields set\n");
113 ERR(
"Non-audio codec %s has audio-only capabilities set\n");
114 } else {
116 ARRAY_CHECK(supported_samplerates, sample_rate,
int, sample_rate == 0,
117 sample_rate > 0, 1);
124 }
129 ERR(
"Non-video codec %s has video-only fields set\n");
132 ERR(
"Non-video codec %s exports cropping\n");
133 }
136 ERR(
"Codec %s wants mainfunction despite not being "
137 "slice-threading capable");
142 ERR(
"Codec %s has private-only threading support\n");
143
148 is_decoder = 1;
149 break;
153 is_encoder = 1;
154 break;
155 default:
156 ERR(
"Codec %s has unknown cb_type\n");
157 continue;
158 }
161 ERR(
"Codec %s cb_type and av_codec_is_(de|en)coder inconsistent.\n");
162 continue;
163 }
164 #define CHECK(TYPE, type) (codec2->cb_type == FF_CODEC_CB_TYPE_ ## TYPE && !codec2->cb.type)
166 CHECK(RECEIVE_PACKET, receive_packet) ||
169 ERR_EXT(
"Codec %s does not implement its %s callback.\n",
170 is_decoder ? "decoding" : "encoding");
171 }
172 #undef CHECK
173 if (is_encoder) {
175 ERR(
"Encoder %s is both subtitle encoder and not subtitle encoder.");
177 ERR(
"Encoder %s has decoder-only thread functions or bsf.\n");
183 }
190 }
199 ERR(
"Encoder %s has decoder-only capabilities set\n");
202 ERR(
"Frame-threaded encoder %s claims to support flushing\n");
205 ERR(
"Frame-threaded encoder %s claims to have delay\n");
206
209 ERR(
"EOF_FLUSH encoder %s is not marked as having delay\n");
210 } else {
213 ERR(
"Non-frame-threaded decoder %s has update_thread_context set");
215 ERR(
"Subtitle decoder %s does not implement decode_sub callback\n");
217 ERR(
"Automatic bitstream filtering unsupported for subtitles; "
218 "yet decoder %s has it set\n");
223 ERR(
"Decoder %s has encoder-only capabilities\n");
226 ERR(
"Decoder %s is marked as setting pkt_dts when it doesn't have"
227 "any effect\n");
230 ERR(
"Decoder %s sets pix_fmts or supported_framerates.\n");
232 }
234 ERR_EXT(
"Private context of codec %s is impossibly-sized (size %d).",
237 ERR(
"Codec %s lacks a corresponding descriptor\n");
238 }
else if (
desc->type != codec->
type)
239 ERR_EXT(
"The type of AVCodec %s and its AVCodecDescriptor differ: "
240 "%s vs %s\n",
242 }
244 }
int(* update_thread_context)(struct AVCodecContext *dst, const struct AVCodecContext *src)
Copy necessary context variables from a previous thread context to the current one.
#define FF_ENABLE_DEPRECATION_WARNINGS
#define FF_CODEC_CAP_SLICE_THREAD_HAS_MF
Codec initializes slice-based threading with a main function.
AVPixelFormat
Pixel format.
#define ENCODE(type, endian, src, dst, n, shift, offset)
Write PCM samples macro.
@ FF_CODEC_CB_TYPE_RECEIVE_PACKET
const AVClass * priv_class
AVClass for the private context.
static enum AVSampleFormat sample_fmts[]
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define FF_CODEC_CAP_EOF_FLUSH
The encoder has AV_CODEC_CAP_DELAY set, but does not actually have delay - it only wants to be flushe...
int capabilities
Codec capabilities.
@ FF_CODEC_CB_TYPE_ENCODE_SUB
int nb_channels
Number of channels in this layout.
const attribute_deprecated AVRational * supported_framerates
Deprecated codec capabilities.
AVCodec p
The public AVCodec.
const attribute_deprecated int * supported_samplerates
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
#define AV_CODEC_CAP_ENCODER_FLUSH
This encoder can be flushed using avcodec_flush_buffers().
@ FF_CODEC_CB_TYPE_DECODE
#define FF_CODEC_CAP_USES_PROGRESSFRAMES
The decoder might make use of the ProgressFrame API.
int(* update_thread_context_for_user)(struct AVCodecContext *dst, const struct AVCodecContext *src)
Copy variables back to the user-facing context.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
This struct describes the properties of a single codec described by an AVCodecID.
static int priv_data_size_wrong(const FFCodec *codec)
static enum AVPixelFormat pix_fmt
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
static enum AVPixelFormat pix_fmts[]
@ FF_CODEC_CB_TYPE_ENCODE
static int receive_frame(AVFilterLink *inlink, AVFrame *out)
#define ARRAY_CHECK(field, var, type, is_sentinel, check, sentinel_check)
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Describe the class of an AVClass context structure.
unsigned color_ranges
This field determines the video color ranges supported by an encoder.
Rational number (pair of numerator and denominator).
static const char * get_type_string(enum AVMediaType type)
@ FF_CODEC_CB_TYPE_DECODE_SUB
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
int av_codec_is_decoder(const AVCodec *codec)
@ AV_SAMPLE_FMT_NB
Number of sample formats. DO NOT USE if linking dynamically.
const attribute_deprecated AVChannelLayout * ch_layouts
Array of supported channel layouts, terminated with a zeroed layout.
An AVChannelLayout holds information about the channel layout of audio data.
attribute_deprecated enum AVPixelFormat * pix_fmts
#define FF_CODEC_CAP_SETS_FRAME_PROPS
Codec handles output frame properties internally instead of letting the internal logic derive them fr...
#define FF_CODEC_CAP_EXPORTS_CROPPING
The decoder sets the cropping fields in the output frames manually.
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
static const av_always_inline FFCodec * ffcodec(const AVCodec *codec)
#define DECODE(size, endian, src, dst, n, shift, offset)
Read PCM samples macro.
static void encode(AVCodecContext *ctx, AVFrame *frame, AVPacket *pkt, FILE *output)
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
int av_codec_is_encoder(const AVCodec *codec)
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
unsigned caps_internal
Internal codec capabilities FF_CODEC_CAP_*.
AVSampleFormat
Audio sample formats.
static const AVChannelLayout ch_layouts[]
const char * name
Name of the codec implementation.
#define FF_CODEC_CAP_SETS_PKT_DTS
Decoders marked with FF_CODEC_CAP_SETS_PKT_DTS want to set AVFrame.pkt_dts manually.
attribute_deprecated enum AVSampleFormat * sample_fmts
const AVCodec * av_codec_iterate(void **opaque)
Iterate over all registered codecs.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
const struct AVOption * option
An array of options for the structure or NULL.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
@ FF_CODEC_CB_TYPE_RECEIVE_FRAME
unsigned cb_type
This field determines the type of the codec (decoder/encoder) and also the exact callback cb implemen...
const char * bsfs
Decoding only, a comma-separated list of bitstream filters to apply to packets before decoding.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
unsigned alpha_modes
This field determines the alpha modes supported by an encoder.
#define CHECK(TYPE, type)
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
#define AV_CODEC_CAP_AVOID_PROBING
Decoder is not a preferred choice for probing.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Generated on Tue Nov 18 2025 19:22:01 for FFmpeg by
doxygen
1.8.17