Skip to content

Commit 7dd9a44

Browse files
committed
vdec/lavc: remove metadata struct
It was used als for ug_codec<->av_codec, which is unneeded, already done in lavc_utils. This also causes that every new codec must have been added there. Keep just the preferred_encoder part.
1 parent d45c971 commit 7dd9a44

File tree

1 file changed

+30
-48
lines changed

1 file changed

+30
-48
lines changed

src/video_decompress/libavcodec.c

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ enum {
236236
};
237237

238238
struct decoder_info {
239-
codec_t ug_codec;
240239
enum AVCodecID avcodec_id;
241240
// Note:
242241
// Make sure that if adding hw decoders to prefered_decoders[] that
@@ -251,31 +250,28 @@ struct decoder_info {
251250
};
252251

253252
static const struct decoder_info decoders[] = {
254-
{ H264, AV_CODEC_ID_H264, { NULL /* "h264_cuvid" */ } },
255-
{ H265, AV_CODEC_ID_HEVC, { NULL /* "hevc_cuvid" */ } },
256-
{ JPEG, AV_CODEC_ID_MJPEG, { NULL } },
257-
{ J2K, AV_CODEC_ID_JPEG2000, { NULL } },
258-
{ J2KR, AV_CODEC_ID_JPEG2000, { NULL } },
259-
{ VP8, AV_CODEC_ID_VP8, { NULL } },
260-
{ VP9, AV_CODEC_ID_VP9, { NULL } },
261-
{ HFYU, AV_CODEC_ID_HUFFYUV, { NULL } },
262-
{ FFV1, AV_CODEC_ID_FFV1, { NULL } },
263-
{ AV1, AV_CODEC_ID_AV1, { "libdav1d" } },
264-
{ PRORES_4444, AV_CODEC_ID_PRORES, { NULL } },
265-
{ PRORES_4444_XQ, AV_CODEC_ID_PRORES, { NULL } },
266-
{ PRORES_422_HQ, AV_CODEC_ID_PRORES, { NULL } },
267-
{ PRORES_422, AV_CODEC_ID_PRORES, { NULL } },
268-
{ PRORES_422_PROXY, AV_CODEC_ID_PRORES, { NULL } },
269-
{ PRORES_422_LT, AV_CODEC_ID_PRORES, { NULL } },
270-
{ CFHD, AV_CODEC_ID_CFHD, { NULL } }
253+
// { AV_CODEC_ID_H264, { NULL /* "h264_cuvid" */ } },
254+
// { AV_CODEC_ID_HEVC, { NULL /* "hevc_cuvid" */ } },
255+
{ AV_CODEC_ID_AV1, { "libdav1d" } },
271256
};
272257

258+
/**
259+
* fills usable_decoders with decoders available for avcodec_id; if
260+
* preferrred_decoders in decoders is set, these will be listed first
261+
*/
273262
static bool
274-
get_usable_decoders(
263+
get_decoders(
275264
enum AVCodecID avcodec_id,
276-
const char *const preferred_decoders[static MAX_PREFERED + 1],
277265
const AVCodec *usable_decoders[static DEC_LEN])
278266
{
267+
const char *const *preferred_decoders = (const char *[]){ NULL };
268+
for (unsigned int i = 0; i < ARR_COUNT(decoders); ++i) {
269+
if (decoders[i].avcodec_id == avcodec_id) {
270+
preferred_decoders = decoders[i].preferred_decoders;
271+
break;
272+
}
273+
}
274+
279275
unsigned int codec_index = 0;
280276
// first try codec specified from cmdline if any
281277
const char *param = get_commandline_param("force-lavd-decoder");
@@ -351,26 +347,18 @@ ADD_TO_PARAM("use-hw-accel", "* use-hw-accel[=<api>|help]\n"
351347
static bool configure_with(struct state_libavcodec_decompress *s,
352348
struct video_desc desc, void *extradata, int extradata_size)
353349
{
354-
const struct decoder_info *dec = NULL;
355-
356350
s->consecutive_failed_decodes = 0;
357351

358-
for (unsigned int i = 0; i < sizeof decoders / sizeof decoders[0]; ++i) {
359-
if (decoders[i].ug_codec == desc.color_spec) {
360-
dec = &decoders[i];
361-
break;
362-
}
363-
}
364-
365-
if (dec == NULL) {
366-
log_msg(LOG_LEVEL_ERROR, "[lavd] Unsupported codec!!!\n");
352+
const enum AVCodecID avcodec_id = get_ug_to_av_codec(desc.color_spec);
353+
if (avcodec_id == AV_CODEC_ID_NONE) {
354+
MSG(ERROR, "Unsupported codec %s!!!\n",
355+
get_codec_name(desc.color_spec));
367356
return false;
368357
}
369358

370359
// priority list of decoders that can be used for the codec
371360
const AVCodec *usable_decoders[DEC_LEN] = { NULL };
372-
if (!get_usable_decoders(dec->avcodec_id, dec->preferred_decoders,
373-
usable_decoders)) {
361+
if (!get_decoders(avcodec_id, usable_decoders)) {
374362
return false;
375363
}
376364

@@ -1198,22 +1186,16 @@ static int libavcodec_decompress_get_priority(codec_t compression, struct pixfmt
11981186
return VDEC_PRIO_PREFERRED;
11991187
}
12001188

1201-
unsigned i = 0;
1202-
for ( ; i < sizeof decoders / sizeof decoders[0]; ++i) {
1203-
if (decoders[i].ug_codec == compression) {
1204-
const AVCodec *const decoder =
1205-
avcodec_find_decoder(decoders[i].avcodec_id);
1206-
if (decoder != NULL) {
1207-
break;
1208-
}
1209-
MSG(WARNING,
1210-
"Codec %s supported by lavd but "
1211-
"not compiled in FFmpeg build.\n",
1212-
get_codec_name(compression));
1213-
}
1189+
const enum AVCodecID avcodec_id = get_ug_to_av_codec(compression);
1190+
if (avcodec_id == AV_CODEC_ID_NONE) {
1191+
return VDEC_PRIO_NA;// lavd doesn't handle this compression
12141192
}
1215-
if (i == sizeof decoders / sizeof decoders[0]) { // lavd doesn't handle this compression
1216-
return VDEC_PRIO_NA;
1193+
1194+
if (avcodec_find_decoder(avcodec_id) == NULL) {
1195+
MSG(WARNING,
1196+
"Codec %s supported by lavd but "
1197+
"not compiled in FFmpeg build.\n",
1198+
get_codec_name(compression));
12171199
}
12181200

12191201
if (ugc == VC_NONE) { // probe

0 commit comments

Comments
 (0)