From b14e0e8c0fde976581fca7dc9975970c884d352a Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Wed, 4 Jan 2017 21:19:40 +0100 Subject: avcodec: configure h264 decoder by name patch was written by @hargut fixes https://github.com/alfredh/baresip/pull/198 --- modules/avcodec/avcodec.c | 22 ++++++++++++++++++++-- modules/avcodec/avcodec.h | 1 + modules/avcodec/decode.c | 19 ++++++++++++++++--- 3 files changed, 37 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/avcodec/avcodec.c b/modules/avcodec/avcodec.c index b5b46f0..307b774 100644 --- a/modules/avcodec/avcodec.c +++ b/modules/avcodec/avcodec.c @@ -32,7 +32,8 @@ * Config options: * \verbatim - avcodec_h264enc ; e.g. nvenc_h264, h264_videotoolbox + avcodec_h264enc ; e.g. h264_nvenc, h264_videotoolbox + avcodec_h264dec ; e.g. h264_cuvid, h264_vda, h264_qsv \endverbatim * * References: @@ -48,6 +49,7 @@ const uint8_t h264_level_idc = 0x0c; AVCodec *avcodec_h264enc; /* optinal; specified H.264 encoder */ +AVCodec *avcodec_h264dec; /* optinal; specified H.264 decoder */ int avcodec_resolve_codecid(const char *s) @@ -182,6 +184,7 @@ static struct vidcodec mpg4 = { static int module_init(void) { char h264enc[64]; + char h264dec[64]; #ifdef USE_X264 debug("avcodec: x264 build %d\n", X264_BUILD); @@ -195,8 +198,23 @@ static int module_init(void) avcodec_register_all(); - if (avcodec_find_decoder(AV_CODEC_ID_H264)) + if (0 == conf_get_str(conf_cur(), "avcodec_h264dec", + h264dec, sizeof(h264dec))) { + + info("avcodec: using h264 decoder by name (%s)\n", h264dec); + + avcodec_h264dec = avcodec_find_decoder_by_name(h264dec); + if (!avcodec_h264dec) { + warning("avcodec: h264 decoder not found (%s)\n", + h264dec); + return ENOENT; + } vidcodec_register(&h264); + } + else { + if (avcodec_find_decoder(AV_CODEC_ID_H264)) + vidcodec_register(&h264); + } if (avcodec_find_decoder(AV_CODEC_ID_H263)) vidcodec_register(&h263); diff --git a/modules/avcodec/avcodec.h b/modules/avcodec/avcodec.h index 601a402..f3a2b70 100644 --- a/modules/avcodec/avcodec.h +++ b/modules/avcodec/avcodec.h @@ -18,6 +18,7 @@ extern const uint8_t h264_level_idc; extern AVCodec *avcodec_h264enc; +extern AVCodec *avcodec_h264dec; /* diff --git a/modules/avcodec/decode.c b/modules/avcodec/decode.c index 9b24586..6416662 100644 --- a/modules/avcodec/decode.c +++ b/modules/avcodec/decode.c @@ -57,9 +57,18 @@ static int init_decoder(struct viddec_state *st, const char *name) if (codec_id == AV_CODEC_ID_NONE) return EINVAL; - st->codec = avcodec_find_decoder(codec_id); - if (!st->codec) - return ENOENT; + /* + * Special handling of H.264 decoder + */ + if (codec_id == AV_CODEC_ID_H264 && avcodec_h264dec) { + st->codec = avcodec_h264dec; + info("avcodec: h264 decoder activated\n"); + } + else { + st->codec = avcodec_find_decoder(codec_id); + if (!st->codec) + return ENOENT; + } #if LIBAVCODEC_VERSION_INT >= ((52<<16)+(92<<8)+0) st->ctx = avcodec_alloc_context3(st->codec); @@ -212,6 +221,10 @@ static int ffdecode(struct viddec_state *st, struct vidframe *frame, frame->fmt = VID_FMT_YUV420P; break; + case AV_PIX_FMT_NV12: + frame->fmt = VID_FMT_NV12; + break; + default: warning("avcodec: decode: bad pixel format" " (%i) (%s)\n", -- cgit v1.2.3