[FFmpeg-devel] [PATCH 17/17] hwcontext_vaapi: Do not assume that sw_format is transferable
Mark Thompson
sw at jkqxz.net
Fri Nov 24 02:51:34 EET 2017
Drivers can support a format for surfaces without also supporting it for
images, so we can't assume that sw_format is usable for transfer. This
would previously hit an assert in cases where it isn't.
---
libavutil/hwcontext_vaapi.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 2f47162a0d..7ec18db56b 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -627,24 +627,31 @@ static int vaapi_transfer_get_formats(AVHWFramesContext *hwfc,
enum AVPixelFormat **formats)
{
VAAPIDeviceContext *ctx = hwfc->device_ctx->internal->priv;
- enum AVPixelFormat *pix_fmts, preferred_format;
- int i, k;
+ enum AVPixelFormat *pix_fmts;
+ int i, k, sw_format_available;
- preferred_format = hwfc->sw_format;
+ sw_format_available = 0;
+ for (i = 0; i < ctx->nb_formats; i++) {
+ if (ctx->formats[i].pix_fmt == hwfc->sw_format)
+ sw_format_available = 1;
+ }
pix_fmts = av_malloc((ctx->nb_formats + 1) * sizeof(*pix_fmts));
if (!pix_fmts)
return AVERROR(ENOMEM);
- pix_fmts[0] = preferred_format;
- k = 1;
+ if (sw_format_available) {
+ pix_fmts[0] = hwfc->sw_format;
+ k = 1;
+ } else {
+ k = 0;
+ }
for (i = 0; i < ctx->nb_formats; i++) {
- if (ctx->formats[i].pix_fmt == preferred_format)
+ if (ctx->formats[i].pix_fmt == hwfc->sw_format)
continue;
av_assert0(k < ctx->nb_formats);
pix_fmts[k++] = ctx->formats[i].pix_fmt;
}
- av_assert0(k == ctx->nb_formats);
pix_fmts[k] = AV_PIX_FMT_NONE;
*formats = pix_fmts;
--
2.11.0
More information about the ffmpeg-devel
mailing list