1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

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 <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-03-10 16:40:39 +01:00
parent 3e19e5062c
commit 47d7c6cd15
2 changed files with 14 additions and 7 deletions

View File

@ -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)

View File

@ -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)