From 6d33b742b039075975fd510d5d01b3f8b9089574 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 (cherry picked from commit 42e765d48be28562e1d9015c279dfacb64b9f9f8) Part-of: --- .pick_status.json | 2 +- src/gallium/frontends/va/picture.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index c9d75b93813..fcaca36af54 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2214,7 +2214,7 @@ "description": "frontends/va: Don't allow Render/EndPicture without BeginPicture", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/gallium/frontends/va/picture.c b/src/gallium/frontends/va/picture.c index 25d45c59d5a..783d219d331 100644 --- a/src/gallium/frontends/va/picture.c +++ b/src/gallium/frontends/va/picture.c @@ -1005,6 +1005,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]); @@ -1155,6 +1160,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); @@ -1166,7 +1179,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);