From 56590501f569ab6bed3c5aafe2ca122770474d75 Mon Sep 17 00:00:00 2001 From: nyanmisaka Date: Mon, 20 Jan 2025 19:18:27 +0800 Subject: [PATCH] fixup! lavc/rkmppdec: refactor RKMPP decoders and extend codecs refine hw_device_ctx validation. Signed-off-by: nyanmisaka --- libavcodec/rkmppdec.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libavcodec/rkmppdec.c b/libavcodec/rkmppdec.c index 65fdf46898..6d556c4d44 100644 --- a/libavcodec/rkmppdec.c +++ b/libavcodec/rkmppdec.c @@ -322,13 +322,16 @@ static av_cold int rkmpp_decode_init(AVCodecContext *avctx) } if (avctx->hw_device_ctx) { - r->hwdevice = av_buffer_ref(avctx->hw_device_ctx); - if (!r->hwdevice) { - ret = AVERROR(ENOMEM); - goto fail; + AVBufferRef *device_ref = avctx->hw_device_ctx; + AVHWDeviceContext *device_ctx = (AVHWDeviceContext *)device_ref->data; + + if (device_ctx && device_ctx->type == AV_HWDEVICE_TYPE_RKMPP) { + r->hwdevice = av_buffer_ref(avctx->hw_device_ctx); + if (r->hwdevice) + av_log(avctx, AV_LOG_VERBOSE, "Picked up an existing RKMPP hardware device\n"); } - av_log(avctx, AV_LOG_VERBOSE, "Picked up an existing RKMPP hardware device\n"); - } else { + } + if (!r->hwdevice) { if ((ret = av_hwdevice_ctx_create(&r->hwdevice, AV_HWDEVICE_TYPE_RKMPP, NULL, NULL, 0)) < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to create a RKMPP hardware device: %d\n", ret); goto fail;