From 62919ef9d0802c2bfb59a236dc97bd9d40905d6b Mon Sep 17 00:00:00 2001 From: David Rosca Date: Tue, 21 Jan 2025 10:39:23 +0100 Subject: [PATCH] frontends/va: Require protected context for VAProtectedSliceDataBuffer Instead of switching the protected playback flag on when processing first VAProtectedSliceDataBuffer, require the context to be created as protected. Reviewed-by: David (Ming Qiang) Wu Part-of: --- src/gallium/frontends/va/picture.c | 46 +++++++++++++----------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/src/gallium/frontends/va/picture.c b/src/gallium/frontends/va/picture.c index 75d5a02b113..54f4003c71f 100644 --- a/src/gallium/frontends/va/picture.c +++ b/src/gallium/frontends/va/picture.c @@ -387,22 +387,25 @@ bufHasStartcode(vlVaBuffer *buf, unsigned int code, unsigned int bits) return 0; } -static void +static VAStatus handleVAProtectedSliceDataBufferType(vlVaContext *context, vlVaBuffer *buf) { - uint8_t* encrypted_data = (uint8_t*) buf->data; - uint8_t* drm_key; + uint8_t *encrypted_data = (uint8_t*)buf->data; + uint8_t *drm_key; + unsigned int drm_key_size = buf->size; - unsigned int drm_key_size = buf->size; + if (!context->desc.base.protected_playback) + return VA_STATUS_ERROR_INVALID_CONTEXT; - drm_key = REALLOC(context->desc.base.decrypt_key, - context->desc.base.key_size, drm_key_size); - if (!drm_key) - return; - context->desc.base.decrypt_key = drm_key; - memcpy(context->desc.base.decrypt_key, encrypted_data, drm_key_size); - context->desc.base.key_size = drm_key_size; - context->desc.base.protected_playback = true; + drm_key = REALLOC(context->desc.base.decrypt_key, + context->desc.base.key_size, drm_key_size); + if (!drm_key) + return VA_STATUS_ERROR_ALLOCATION_FAILED; + context->desc.base.decrypt_key = drm_key; + memcpy(context->desc.base.decrypt_key, encrypted_data, drm_key_size); + context->desc.base.key_size = drm_key_size; + + return VA_STATUS_SUCCESS; } static VAStatus @@ -479,8 +482,7 @@ handleVASliceDataBufferType(vlVaContext *context, vlVaBuffer *buf) context->bs.sizes[context->bs.num_buffers++] = context->mjpeg.slice_header_size; break; case PIPE_VIDEO_FORMAT_VP9: - if (false == context->desc.base.protected_playback) - vlVaDecoderVP9BitstreamHeader(context, buf); + vlVaDecoderVP9BitstreamHeader(context, buf); break; case PIPE_VIDEO_FORMAT_AV1: break; @@ -994,18 +996,6 @@ vlVaRenderPicture(VADriverContextP ctx, VAContextID context_id, VABufferID *buff 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]); - if (!buf) { - mtx_unlock(&drv->mutex); - return VA_STATUS_ERROR_INVALID_BUFFER; - } - - if (buf->type == VAProtectedSliceDataBufferType) - handleVAProtectedSliceDataBufferType(context, buf); - } - for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; ++i) { vlVaBuffer *buf = handle_table_get(drv->htab, buffers[i]); if (!buf) { @@ -1070,6 +1060,10 @@ vlVaRenderPicture(VADriverContextP ctx, VAContextID context_id, VABufferID *buff handleVAStatsStatisticsBufferType(ctx, context, buf); break; + case VAProtectedSliceDataBufferType: + vaStatus = handleVAProtectedSliceDataBufferType(context, buf); + break; + default: break; }