From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 4DD1944BFF for ; Mon, 14 Nov 2022 01:16:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 258A968BCF8; Mon, 14 Nov 2022 03:16:19 +0200 (EET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 66C1A68B797 for ; Mon, 14 Nov 2022 03:16:12 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668388577; x=1699924577; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=MSTwYKjFLqbSW7sRbwewsvMgR6/UibEZU4JwvRlgc/o=; b=Er65d0bzQxnXO6f1GlWRHUfkE+XS9eMEtX7QcU5DKmlh4Uao4RZgxxlV 1JrSTT4g0aTduoKkZsrmUJxAQECKFrLHSjzLb6rkLh01AxHkAynJXg7I0 CbPjdoaM9mPzjfHAGi1RmtX9kbf4yMC2x+P92hXp3UY1tDPK8ye9jYDnq EFN9NzGLyhI7nb2GI3FzrY7PYTgsjQvZYnYSux1k//joKgdNVqjxcs1bs /hiEWG/TVJV/dK6l6uX1eVDFxA3nBK/sZLN2TRfYRTL3srTV3ocxwV0Wk qgY3Wbzip+ht875c61ajYzCIM8AYFzuuKtMJs+C4VIqHamqyCjMH6A8mj w==; X-IronPort-AV: E=McAfee;i="6500,9779,10530"; a="338639933" X-IronPort-AV: E=Sophos;i="5.96,161,1665471600"; d="scan'208";a="338639933" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2022 17:16:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10530"; a="616100165" X-IronPort-AV: E=Sophos;i="5.96,161,1665471600"; d="scan'208";a="616100165" Received: from t.sh.intel.com ([10.239.159.159]) by orsmga006.jf.intel.com with ESMTP; 13 Nov 2022 17:16:08 -0800 From: Fei Wang To: ffmpeg-devel@ffmpeg.org Date: Mon, 14 Nov 2022 09:16:04 +0800 Message-Id: <20221114011605.1157707-1-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 1/2] lavc: add HWACCEL_CAP_RESET_WITHOUT_UNINIT capacity for hwaccel X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Fei Wang Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: The capacity can avoid hwaccel being uninited when do the reset. It provides the method for hwaccel if it still want to use the previous initialized configuration after reset. And the configuration can be updated in AVHWAccel.init() if needed. For example, when use vaapi vp9 decode dynamic resolution clips, need to avoid changing vaContext in avctx->internal->hwaccel_priv_data if current frame resolution change and it reference a pervious frame with different resolution. Otherwise reference frame's information bound in vaContext will be lost, then corrupt current frame. Signed-off-by: Fei Wang --- update: 1. consider the case of va_config/va_context equal to 0. libavcodec/decode.c | 10 ++++++---- libavcodec/hwconfig.h | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 6be2d3d6ed..cfada048e8 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1109,7 +1109,7 @@ static int hwaccel_init(AVCodecContext *avctx, return AVERROR_PATCHWELCOME; } - if (hwaccel->priv_data_size) { + if (hwaccel->priv_data_size && !avctx->internal->hwaccel_priv_data) { avctx->internal->hwaccel_priv_data = av_mallocz(hwaccel->priv_data_size); if (!avctx->internal->hwaccel_priv_data) @@ -1134,10 +1134,12 @@ static int hwaccel_init(AVCodecContext *avctx, static void hwaccel_uninit(AVCodecContext *avctx) { - if (avctx->hwaccel && avctx->hwaccel->uninit) - avctx->hwaccel->uninit(avctx); + if (avctx->hwaccel && !(avctx->hwaccel->caps_internal & HWACCEL_CAP_RESET_WITHOUT_UNINIT)) { + if (avctx->hwaccel->uninit) + avctx->hwaccel->uninit(avctx); - av_freep(&avctx->internal->hwaccel_priv_data); + av_freep(&avctx->internal->hwaccel_priv_data); + } avctx->hwaccel = NULL; diff --git a/libavcodec/hwconfig.h b/libavcodec/hwconfig.h index 721424912c..5fb4e06d5f 100644 --- a/libavcodec/hwconfig.h +++ b/libavcodec/hwconfig.h @@ -25,6 +25,13 @@ #define HWACCEL_CAP_ASYNC_SAFE (1 << 0) +/** + * The hwaccel supports reset without calling back AVHWAccel.uninit() + * and realloc avctx->internal->hwaccel_priv_data. + * + * New configuration can set up through AVHWAccel.init(). + */ +#define HWACCEL_CAP_RESET_WITHOUT_UNINIT (1 << 1) typedef struct AVCodecHWConfigInternal { /** -- 2.25.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".