From 9f0869cd9aeebaeacfe4ab4ab9c64c163d7887ad Mon Sep 17 00:00:00 2001 From: philippegorley <philippe.gorley@savoirfairelinux.com> Date: Tue, 7 Nov 2017 11:23:23 -0500 Subject: [PATCH] accel: optimize get_format callback Remove the second loop in the getFormatCb function. Ring will no longer check the pixel formats twice in case hardware decoding isn't possible. Change-Id: Ib03deb152394948979249828376bc4280b859424 Reviewed-by: Olivier Soldano <olivier.soldano@savoirfairelinux.com> --- src/media/video/accel.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/media/video/accel.cpp b/src/media/video/accel.cpp index 47876089bd..f14592d329 100644 --- a/src/media/video/accel.cpp +++ b/src/media/video/accel.cpp @@ -54,7 +54,9 @@ getFormatCb(AVCodecContext* codecCtx, const AVPixelFormat* formats) return avcodec_default_get_format(codecCtx, formats); } - for (int i = 0; formats[i] != AV_PIX_FMT_NONE; i++) { + AVPixelFormat fallback = AV_PIX_FMT_NONE; + for (int i = 0; formats[i] != AV_PIX_FMT_NONE; ++i) { + fallback = formats[i]; if (formats[i] == accel->format()) { accel->setWidth(codecCtx->coded_width); accel->setHeight(codecCtx->coded_height); @@ -62,7 +64,6 @@ getFormatCb(AVCodecContext* codecCtx, const AVPixelFormat* formats) accel->setCodecCtx(codecCtx); if (accel->init()) return accel->format(); - break; } } @@ -70,14 +71,7 @@ getFormatCb(AVCodecContext* codecCtx, const AVPixelFormat* formats) RING_WARN("Falling back to software decoding"); codecCtx->get_format = avcodec_default_get_format; codecCtx->get_buffer2 = avcodec_default_get_buffer2; - for (int i = 0; formats[i] != AV_PIX_FMT_NONE; i++) { - auto desc = av_pix_fmt_desc_get(formats[i]); - if (desc && !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) { - return formats[i]; - } - } - - return AV_PIX_FMT_NONE; + return fallback; } static int -- GitLab