diff options
author | wm4 <wm4@nowhere> | 2013-03-07 23:37:06 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-03-07 23:42:58 +0100 |
commit | 14427ae2ee1923eeeb5189f6a0a3c9ebf391eff6 (patch) | |
tree | dcd9f65dfbdb6e8443b2d3fa92e6a1359bb5f676 /core | |
parent | fe4213b164ad19bd94273cb179ee7c61f6094b59 (diff) | |
download | mpv-14427ae2ee1923eeeb5189f6a0a3c9ebf391eff6.tar.bz2 mpv-14427ae2ee1923eeeb5189f6a0a3c9ebf391eff6.tar.xz |
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.
Diffstat (limited to 'core')
-rw-r--r-- | core/av_common.c | 21 |
1 files 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 |