Commit 6e0e3e1d authored by Mark Thompson's avatar Mark Thompson

hwcontext_vaapi: Do not assume that sw_format is transferable

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.
parent 52a44d50
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment