From 42e765d48be28562e1d9015c279dfacb64b9f9f8 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Tue, 17 Dec 2024 12:11:00 +0100 Subject: [PATCH] frontends/va: Don't allow Render/EndPicture without BeginPicture It's not valid to call RenderPicture and EndPicture without calling BeginPicture or when BeginPicture fails. FFmpeg will however call EndPicture when BeginPicture fails, so we need to handle this. Use target_id, which is assigned in BeginPicture, as an indication whether we are inside the Begin - End picture sequence. Cc: mesa-stable Reviewed-by: Ruijing Dong Part-of: --- src/gallium/frontends/va/picture.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gallium/frontends/va/picture.c b/src/gallium/frontends/va/picture.c index 9d0d705a711..1be44239c3d 100644 --- a/src/gallium/frontends/va/picture.c +++ b/src/gallium/frontends/va/picture.c @@ -979,6 +979,11 @@ vlVaRenderPicture(VADriverContextP ctx, VAContextID context_id, VABufferID *buff return VA_STATUS_ERROR_INVALID_CONTEXT; } + if (!context->target_id) { + mtx_unlock(&drv->mutex); + return VA_STATUS_ERROR_OPERATION_FAILED; + } + /* Always process VAProtectedSliceDataBufferType first because it changes the state */ for (i = 0; i < num_buffers; ++i) { vlVaBuffer *buf = handle_table_get(drv->htab, buffers[i]); @@ -1127,6 +1132,14 @@ vlVaEndPicture(VADriverContextP ctx, VAContextID context_id) return VA_STATUS_ERROR_INVALID_CONTEXT; } + if (!context->target_id) { + mtx_unlock(&drv->mutex); + return VA_STATUS_ERROR_OPERATION_FAILED; + } + + output_id = context->target_id; + context->target_id = 0; + if (!context->decoder) { if (context->templat.profile != PIPE_VIDEO_PROFILE_UNKNOWN) { mtx_unlock(&drv->mutex); @@ -1138,7 +1151,6 @@ vlVaEndPicture(VADriverContextP ctx, VAContextID context_id) return VA_STATUS_SUCCESS; } - output_id = context->target_id; out_target = &context->target; apply_av1_fg = vlVaQueryApplyFilmGrainAV1(context, &output_id, &out_target);