You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
avcodec/codec_internal: Add inlined version of av_codec_is_(de|en)coder
These functions check whether the AVCodec* is NULL, but this has already been checked at a lot of places in our codebase, so that it boils down to checking the is_decoder flag. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -1013,12 +1013,12 @@ static const AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *))
|
||||
|
||||
const AVCodec *avcodec_find_encoder(enum AVCodecID id)
|
||||
{
|
||||
return find_codec(id, av_codec_is_encoder);
|
||||
return find_codec(id, ff_codec_is_encoder);
|
||||
}
|
||||
|
||||
const AVCodec *avcodec_find_decoder(enum AVCodecID id)
|
||||
{
|
||||
return find_codec(id, av_codec_is_decoder);
|
||||
return find_codec(id, ff_codec_is_decoder);
|
||||
}
|
||||
|
||||
static const AVCodec *find_codec_by_name(const char *name, int (*x)(const AVCodec *))
|
||||
@@ -1041,10 +1041,10 @@ static const AVCodec *find_codec_by_name(const char *name, int (*x)(const AVCode
|
||||
|
||||
const AVCodec *avcodec_find_encoder_by_name(const char *name)
|
||||
{
|
||||
return find_codec_by_name(name, av_codec_is_encoder);
|
||||
return find_codec_by_name(name, ff_codec_is_encoder);
|
||||
}
|
||||
|
||||
const AVCodec *avcodec_find_decoder_by_name(const char *name)
|
||||
{
|
||||
return find_codec_by_name(name, av_codec_is_decoder);
|
||||
return find_codec_by_name(name, ff_codec_is_decoder);
|
||||
}
|
||||
|
@@ -190,7 +190,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
|
||||
avci = av_codec_is_decoder(codec) ?
|
||||
avci = ff_codec_is_decoder(codec) ?
|
||||
ff_decode_internal_alloc() :
|
||||
ff_encode_internal_alloc();
|
||||
if (!avci) {
|
||||
@@ -270,7 +270,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
|
||||
if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && !avctx->ch_layout.nb_channels
|
||||
&& !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) {
|
||||
av_log(avctx, AV_LOG_ERROR, "%s requires channel layout to be set\n",
|
||||
av_codec_is_decoder(codec) ? "Decoder" : "Encoder");
|
||||
ff_codec_is_decoder(codec) ? "Decoder" : "Encoder");
|
||||
ret = AVERROR(EINVAL);
|
||||
goto free_and_end;
|
||||
}
|
||||
@@ -290,13 +290,13 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
|
||||
|
||||
if ((avctx->codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) &&
|
||||
avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
|
||||
const char *codec_string = av_codec_is_encoder(codec) ? "encoder" : "decoder";
|
||||
const char *codec_string = ff_codec_is_encoder(codec) ? "encoder" : "decoder";
|
||||
const AVCodec *codec2;
|
||||
av_log(avctx, AV_LOG_ERROR,
|
||||
"The %s '%s' is experimental but experimental codecs are not enabled, "
|
||||
"add '-strict %d' if you want to use it.\n",
|
||||
codec_string, codec->name, FF_COMPLIANCE_EXPERIMENTAL);
|
||||
codec2 = av_codec_is_encoder(codec) ? avcodec_find_encoder(codec->id) : avcodec_find_decoder(codec->id);
|
||||
codec2 = ff_codec_is_encoder(codec) ? avcodec_find_encoder(codec->id) : avcodec_find_decoder(codec->id);
|
||||
if (!(codec2->capabilities & AV_CODEC_CAP_EXPERIMENTAL))
|
||||
av_log(avctx, AV_LOG_ERROR, "Alternatively use the non experimental %s '%s'.\n",
|
||||
codec_string, codec2->name);
|
||||
@@ -310,7 +310,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
|
||||
avctx->time_base.den = avctx->sample_rate;
|
||||
}
|
||||
|
||||
if (av_codec_is_encoder(avctx->codec))
|
||||
if (ff_codec_is_encoder(avctx->codec))
|
||||
ret = ff_encode_preinit(avctx);
|
||||
else
|
||||
ret = ff_decode_preinit(avctx);
|
||||
@@ -345,7 +345,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
|
||||
|
||||
ret=0;
|
||||
|
||||
if (av_codec_is_decoder(avctx->codec)) {
|
||||
if (ff_codec_is_decoder(avctx->codec)) {
|
||||
if (!avctx->bit_rate)
|
||||
avctx->bit_rate = get_bit_rate(avctx);
|
||||
|
||||
@@ -718,10 +718,10 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr
|
||||
{
|
||||
av_frame_unref(frame);
|
||||
|
||||
if (!avcodec_is_open(avctx))
|
||||
if (!avcodec_is_open(avctx) || !avctx->codec)
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
if (av_codec_is_decoder(avctx->codec))
|
||||
if (ff_codec_is_decoder(avctx->codec))
|
||||
return ff_decode_receive_frame(avctx, frame);
|
||||
return ff_encode_receive_frame(avctx, frame);
|
||||
}
|
||||
|
@@ -281,6 +281,31 @@ typedef struct FFCodec {
|
||||
int *out_num_configs);
|
||||
} FFCodec;
|
||||
|
||||
static av_always_inline const FFCodec *ffcodec(const AVCodec *codec)
|
||||
{
|
||||
return (const FFCodec*)codec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal version of av_codec_is_encoder(). Must not be called with
|
||||
* a NULL AVCodec*.
|
||||
*/
|
||||
static inline int ff_codec_is_encoder(const AVCodec *avcodec)
|
||||
{
|
||||
const FFCodec *const codec = ffcodec(avcodec);
|
||||
return !codec->is_decoder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal version of av_codec_is_decoder(). Must not be called with
|
||||
* a NULL AVCodec*.
|
||||
*/
|
||||
static inline int ff_codec_is_decoder(const AVCodec *avcodec)
|
||||
{
|
||||
const FFCodec *const codec = ffcodec(avcodec);
|
||||
return codec->is_decoder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation for avcodec_get_supported_config(). Will return the
|
||||
* relevant fields from AVCodec if present, or NULL otherwise.
|
||||
@@ -366,9 +391,4 @@ int ff_default_get_supported_config(const struct AVCodecContext *avctx,
|
||||
.p.field = (array) \
|
||||
ENABLE_DEPRECATION_WARNINGS
|
||||
|
||||
static av_always_inline const FFCodec *ffcodec(const AVCodec *codec)
|
||||
{
|
||||
return (const FFCodec*)codec;
|
||||
}
|
||||
|
||||
#endif /* AVCODEC_CODEC_INTERNAL_H */
|
||||
|
@@ -1706,7 +1706,7 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
|
||||
int override_dimensions = 1;
|
||||
int ret;
|
||||
|
||||
av_assert0(av_codec_is_decoder(avctx->codec));
|
||||
av_assert0(ff_codec_is_decoder(avctx->codec));
|
||||
|
||||
if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
|
||||
if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN ||
|
||||
|
@@ -69,7 +69,7 @@ static const AVClass *codec_child_class_iterate(void **iter)
|
||||
static AVClassCategory get_category(void *ptr)
|
||||
{
|
||||
AVCodecContext* avctx = ptr;
|
||||
if (avctx->codec && av_codec_is_decoder(avctx->codec))
|
||||
if (avctx->codec && ff_codec_is_decoder(avctx->codec))
|
||||
return AV_CLASS_CATEGORY_DECODER;
|
||||
else
|
||||
return AV_CLASS_CATEGORY_ENCODER;
|
||||
|
@@ -116,7 +116,7 @@ av_cold int ff_slice_thread_init(AVCodecContext *avctx)
|
||||
void (*mainfunc)(void *);
|
||||
|
||||
// We cannot do this in the encoder init as the threads are created before
|
||||
if (av_codec_is_encoder(avctx->codec) &&
|
||||
if (ff_codec_is_encoder(avctx->codec) &&
|
||||
avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO &&
|
||||
avctx->height > 2800)
|
||||
thread_count = avctx->thread_count = 1;
|
||||
|
Reference in New Issue
Block a user