From 7b677a25ac08940b78bf7d24908ae76757c60475 Mon Sep 17 00:00:00 2001 From: Hertz Wang Date: Mon, 29 Oct 2018 11:28:40 +0800 Subject: [PATCH 01/11] find_codec prefer hardware capability Change-Id: Ib885af15b8942ea13cc1e944ab84ecb6b939ac70 Signed-off-by: Hertz Wang --- libavcodec/allcodecs.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 1b8144a..a8fa898 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -853,7 +853,7 @@ static enum AVCodecID remap_deprecated_codec_id(enum AVCodecID id) static AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *)) { - const AVCodec *p, *experimental = NULL; + const AVCodec *p, *experimental = NULL, *first = NULL; void *i = 0; id = remap_deprecated_codec_id(id); @@ -864,12 +864,17 @@ static AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *)) if (p->id == id) { if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && !experimental) { experimental = p; - } else - return (AVCodec*)p; + } else { + if (!first) + first = p; + // prefer hardware + if (p->capabilities & AV_CODEC_CAP_HARDWARE) + return (AVCodec*)p; + } } } - return (AVCodec*)experimental; + return first ? (AVCodec*)first : (AVCodec*)experimental; } AVCodec *avcodec_find_encoder(enum AVCodecID id) -- 2.7.4