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 A596A44BC5 for ; Tue, 8 Nov 2022 11:45:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1A98468BBA4; Tue, 8 Nov 2022 13:45:00 +0200 (EET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A401468B8D0 for ; Tue, 8 Nov 2022 13:44:52 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667907897; x=1699443897; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=47t/eYDIaWGJO2VyCuzFj4W/2x1XKt4km12k3L9RGP4=; b=iUnlSA6QLsvwrK8OJybJ9hp84xxEk8riKQft/kUOIkxIEN78mVMJ9cA2 uX3Te4WgSLndhwg6V43Tjy+3FBM3LvILcbXhr+Ya2L7HHRBhPZQ5NfT/g ZQZMp6dflRaXuRTb6aqWDdDXomYhlT4M0QBOSzDPtUtcDR2O5jdKKesAz mpWORpQxkoNOOobhEinnbDCVK6urir+3/bo3W2lVh8CplyDZkXGgBGnRV paJTtRgk3r9CqugQ4PzYSIHAGUgs5BjhAETcCA/WqBrRb15ZZ/9MBQteP /zm1QqA0jPmm5EgD9B1N9ByTR4CxDoe9Q4rkvEecsB+TExV2dHjUE9gMk A==; X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="309382923" X-IronPort-AV: E=Sophos;i="5.96,147,1665471600"; d="scan'208";a="309382923" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2022 03:44:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="699896194" X-IronPort-AV: E=Sophos;i="5.96,147,1665471600"; d="scan'208";a="699896194" Received: from t.sh.intel.com ([10.239.159.159]) by fmsmga008.fm.intel.com with ESMTP; 08 Nov 2022 03:44:50 -0800 From: Fei Wang To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Nov 2022 19:45:00 +0800 Message-Id: <20221108114501.570349-1-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 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 --- 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".