From patchwork Tue Nov 8 11:45:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Fei W" X-Patchwork-Id: 39233 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp2771419pzb; Tue, 8 Nov 2022 03:45:04 -0800 (PST) X-Google-Smtp-Source: AMsMyM6IQvmDoteaOn4sI4yCL2P78CyVuaajZl9hVrbaDhAtNn8AocufrYAaB7nDtpcITcjkyX7/ X-Received: by 2002:a17:907:3f19:b0:7a3:2317:4221 with SMTP id hq25-20020a1709073f1900b007a323174221mr51894228ejc.562.1667907904205; Tue, 08 Nov 2022 03:45:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667907904; cv=none; d=google.com; s=arc-20160816; b=NKX/dfM7z8Q6Y3Tr4sQAdpuSfXaQ7rkCnDhYjCpiDc6m3CJiCuc4pO/zZak1yv2sCO EB5mjhGcHspfHeN3yEW3ZWoHxb4Mtt7EDzBWUXMoPnKDqHGanWopmzwHyRRef3w2Ljmn zdYQCK7Nmca1sjB3uldVLN+AtQ3gp8kSwHBxkiT82/ScGvrGJnuTLt2fGPLXjCOe+Apc pVTMO9wAo3hRW0Pu1FZYqQzJZjimJ3fyIh6Rljt7viCG12H/Kufx5qnJ1JegrqamUkQG XKsZ0JSv2HMcN7zLUHT1klY7DSyk55n6+uphbgNvAjOFIRit+tLQyb23hilQXnISOQJY mTWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=uyQ3YXLq1HO3KNbcdW7ZVPFYTblMVSi02CQHY1u40pI=; b=uv4uyIwwakj5CDaqHtLaoI01dPlnVDhAWZCVvTDX/uYpq2kq6L7b6t+dTgrKld20+L OmkGoy/NN74dKpNK9KX5Apo4qhTqn5IrN84VycVBuzfiYN0ixigk2w7EacDEI6LCY2Tf UoaN5UVMjkqBtGJQIC5gqU9DckcwkKkNZofHavftQQiciSisZsznlWpoCuUUfv4kRzpH Xv55iKRz3Jm3zSXIqBXBg9lIM7uNWemo5WM0iYIp9sXp7xADlTXnGCkwYDhqINLYhKqD 28OIyNzIRYhBtNqEywqZW2/DLEj/UHKQaXfeFasZ1qCxPEnON9ak61cQ+Tv2fdqj+Of+ zHgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=iUnlSA6Q; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ga32-20020a1709070c2000b007ade20fc415si13295804ejc.811.2022.11.08.03.45.03; Tue, 08 Nov 2022 03:45:04 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=iUnlSA6Q; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4C2A968B8D0; Tue, 8 Nov 2022 13:45:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: W32AUHedUxMm 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 { /**