From bc8357f6ab0bcbc53e21b619dde4e3471fa7885d Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Mon, 10 Mar 2025 16:40:39 +0100 Subject: [PATCH 2/3] avcodec/codec_internal: Add dedicated is_decoder flag to FFCodec Allows to simplify av_codec_is_decoder() and av_codec_is_encoder(). Signed-off-by: Andreas Rheinhardt --- libavcodec/codec_internal.h | 13 ++++++++++++- libavcodec/utils.c | 8 ++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h index b2df8e729a..2b9c7354a0 100644 --- a/libavcodec/codec_internal.h +++ b/libavcodec/codec_internal.h @@ -133,7 +133,12 @@ typedef struct FFCodec { /** * Internal codec capabilities FF_CODEC_CAP_*. */ - unsigned caps_internal:27; + unsigned caps_internal:26; + + /** + * Is this a decoder? + */ + unsigned is_decoder:1; /** * This field determines the video color ranges supported by an encoder. @@ -309,21 +314,27 @@ int ff_default_get_supported_config(const struct AVCodecContext *avctx, #endif #define FF_CODEC_DECODE_CB(func) \ + .is_decoder = 1, \ .cb_type = FF_CODEC_CB_TYPE_DECODE, \ .cb.decode = (func) #define FF_CODEC_DECODE_SUB_CB(func) \ + .is_decoder = 1, \ .cb_type = FF_CODEC_CB_TYPE_DECODE_SUB, \ .cb.decode_sub = (func) #define FF_CODEC_RECEIVE_FRAME_CB(func) \ + .is_decoder = 1, \ .cb_type = FF_CODEC_CB_TYPE_RECEIVE_FRAME, \ .cb.receive_frame = (func) #define FF_CODEC_ENCODE_CB(func) \ + .is_decoder = 0, \ .cb_type = FF_CODEC_CB_TYPE_ENCODE, \ .cb.encode = (func) #define FF_CODEC_ENCODE_SUB_CB(func) \ + .is_decoder = 0, \ .cb_type = FF_CODEC_CB_TYPE_ENCODE_SUB, \ .cb.encode_sub = (func) #define FF_CODEC_RECEIVE_PACKET_CB(func) \ + .is_decoder = 0, \ .cb_type = FF_CODEC_CB_TYPE_RECEIVE_PACKET, \ .cb.receive_packet = (func) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 0aa5a6f55e..90867ed6b1 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -79,17 +79,13 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size) int av_codec_is_encoder(const AVCodec *avcodec) { const FFCodec *const codec = ffcodec(avcodec); - return codec && (codec->cb_type == FF_CODEC_CB_TYPE_ENCODE || - codec->cb_type == FF_CODEC_CB_TYPE_ENCODE_SUB || - codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_PACKET); + return codec && !codec->is_decoder; } int av_codec_is_decoder(const AVCodec *avcodec) { const FFCodec *const codec = ffcodec(avcodec); - return codec && (codec->cb_type == FF_CODEC_CB_TYPE_DECODE || - codec->cb_type == FF_CODEC_CB_TYPE_DECODE_SUB || - codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME); + return codec && codec->is_decoder; } int ff_set_dimensions(AVCodecContext *s, int width, int height) -- 2.45.2