From 14427ae2ee1923eeeb5189f6a0a3c9ebf391eff6 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 7 Mar 2013 23:37:06 +0100 Subject: core: make more robust against missing libavcodec AVCodecDescriptor entries Missing entries cause avcodec_descriptor_get() to return NULL, and in turn mp_codec_from_av_codec_id() will return NULL. This shouldn't happen, and avcodec_descriptor_get() returning NULL for a valid codec is clearly a bug. But make it more robust anyway, and use the decoder's name if this happens, because I doubt maintainance of the AVCodecDescriptor table in ffmpeg/Libav will always be perfect and reliable. --- core/av_common.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/core/av_common.c b/core/av_common.c index 68ab461c10..87baf1ac23 100644 --- a/core/av_common.c +++ b/core/av_common.c @@ -90,15 +90,30 @@ void mp_add_lavc_decoders(struct mp_decoder_list *list, enum AVMediaType type) int mp_codec_to_av_codec_id(const char *codec) { - + int id = CODEC_ID_NONE; const AVCodecDescriptor *desc = avcodec_descriptor_get_by_name(codec); - return desc ? desc->id : CODEC_ID_NONE; + if (desc) + id = desc->id; + if (id == CODEC_ID_NONE) { + AVCodec *avcodec = avcodec_find_decoder_by_name(codec); + if (avcodec) + id = avcodec->id; + } + return id; } const char *mp_codec_from_av_codec_id(int codec_id) { + const char *name = NULL; const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id); - return desc ? desc->name : NULL; + if (desc) + name = desc->name; + if (!name) { + AVCodec *avcodec = avcodec_find_decoder(codec_id); + if (avcodec) + name = avcodec->name; + } + return name; } #else -- cgit v1.2.3