From patchwork Tue Apr 25 07:26:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Tong1" X-Patchwork-Id: 41319 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a17:907:3203:b0:94c:9d7a:e065 with SMTP id xg3csp3293719ejb; Tue, 25 Apr 2023 00:30:24 -0700 (PDT) X-Google-Smtp-Source: AKy350ZFQRH/RwAhCrbsrVwOr0voiBlDkiH+OjjiE1MYZ588JqywMbZsQt1LqX4URYpabkklBI8g X-Received: by 2002:a17:907:8a25:b0:957:1789:c38c with SMTP id sc37-20020a1709078a2500b009571789c38cmr14441408ejc.38.1682407823962; Tue, 25 Apr 2023 00:30:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682407823; cv=none; d=google.com; s=arc-20160816; b=y8F8DS2IOMJSH5dghqMQ4kAApm1vLoCDtgYPtImti8RPkCkp4uv055d+RTz8QmIsVb VGK1KCERrEjWjHjclb2yyn+//zrZy3MJlDKX86PPmnXnEL2yw1JT2jWGvlX3tg6iWUtR tzRca0M2RQLj2TY5rY5Bn3LGs4C03R+YjHZxVe2JshVs366FKZL3scLt9rYexhgg//0o gw/lTQCYHw2hkCK7wRxMJ+c5AslGtjpBlK2OuwHsPvYg3bg7dWA4pKnLrqEOp6XjGtbf YKKeoEj5p4sYPVkhJd7/iapy9TEycFlyPZ1XA3GthBP9FAA9nrmHjgTpUMoMghdC2B1y nM6g== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=Fi0gkS8UHqDIfiAqyex6pcdcXo+pd45oMQKe2iqPHRE=; b=BqiGsoet0RUHDGV745PGEYOM5zSzKp2X3dKdu8eNWvgtNRQ5uTiDMNcuoh9bJiHeeU tq033Y0JDMYfYOJpETEXF2I4PFVuEEmUX91yT+q3ykLhY/7EMNY3SPCpbMeQ9o/C9aKD pgELbjzwprcr+yIUk3b+0ADH8pCGlRKSqdCL8Uh/BsylJnFIuBdOz0JxIz1R0EJRuAzx Da+Usx6V4qFBCf6ld1vFSfDeSKTu8mHDCUU83BBlSksHD7kFfd9SyieuP4hR1L63D2bP kIgpdmmCK44qIKFYybX4xnZjqDYnO1JA2TyOPRXi9nuOIZmC3QaD6cypRS7tpUifKNUi 0nQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=TIvAq8Hc; 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 w22-20020a1709060a1600b0094e017ff484si9388378ejf.882.2023.04.25.00.30.23; Tue, 25 Apr 2023 00:30:23 -0700 (PDT) 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=TIvAq8Hc; 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 B45BC68BF05; Tue, 25 Apr 2023 10:30:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0D58268B9FC for ; Tue, 25 Apr 2023 10:30:06 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1682407812; x=1713943812; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CeS1ec12Z0+g3baTXuNnAQrHLQiSVFoTpN0hGl193qg=; b=TIvAq8Hc+Xt3vb4x/PBiR+zKOuI6i/sHLzStkdUQfEDH5BJwXQA8d4Rn pmGd4KyBl5+WxrkUJhkDuiAoUttOProPnI+E8Rjvq+eY3/eO+ty5Olc6m IxmT2Om3UJV0alk8cu7Z9RO2J8Vtryw5NsiQz/Ix324RF6NTdgumPMAnB MwL9QDVfOBZFL8fdq26t43rPZECj43zxxWvyA30pcSuxmJtJ+7uXWBJnT CBGmilQ9c1lJRE/3ELBYo0aZGXiHud8R4fH6nMkIy09cUGjKmGls/MDJN 1yyaymbZDN2CubFhaHn00Yx7VMSLuq7Xd9C4LS1PfI4bF2g1pGU9bLebO A==; X-IronPort-AV: E=McAfee;i="6600,9927,10690"; a="374630975" X-IronPort-AV: E=Sophos;i="5.99,224,1677571200"; d="scan'208";a="374630975" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2023 00:29:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10690"; a="867798312" X-IronPort-AV: E=Sophos;i="5.99,224,1677571200"; d="scan'208";a="867798312" Received: from desktop-qn7n0nf.sh.intel.com (HELO localhost.localdomain) ([10.239.160.59]) by orsmga005.jf.intel.com with ESMTP; 25 Apr 2023 00:29:57 -0700 From: Tong Wu To: ffmpeg-devel@ffmpeg.org Date: Tue, 25 Apr 2023 15:26:17 +0800 Message-Id: <20230425072620.512-2-tong1.wu@intel.com> X-Mailer: git-send-email 2.39.1.windows.1 In-Reply-To: <20230425072620.512-1-tong1.wu@intel.com> References: <20230425072620.512-1-tong1.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 2/5] avfilter/vf_hwmap: get the AVHWDeviceType from outlink format 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: Tong Wu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: lENG/xaMnBY5 When both derive_device_type and device context are not presented during hw->hw map, the hwmap filter should be able to retrieve AVHWDeviceType from outlink->format and create corresponding hwdevice context. Signed-off-by: Tong Wu --- libavfilter/vf_hwmap.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/libavfilter/vf_hwmap.c b/libavfilter/vf_hwmap.c index e246b22603..e5b40233b2 100644 --- a/libavfilter/vf_hwmap.c +++ b/libavfilter/vf_hwmap.c @@ -70,16 +70,31 @@ static int hwmap_config_output(AVFilterLink *outlink) device_is_derived = 0; if (inlink->hw_frames_ctx) { + enum AVHWDeviceType type; hwfc = (AVHWFramesContext*)inlink->hw_frames_ctx->data; - if (ctx->derive_device_type) { - enum AVHWDeviceType type; + desc = av_pix_fmt_desc_get(outlink->format); + if (!desc) { + err = AVERROR(EINVAL); + goto fail; + } - type = av_hwdevice_find_type_by_name(ctx->derive_device_type); - if (type == AV_HWDEVICE_TYPE_NONE) { - av_log(avctx, AV_LOG_ERROR, "Invalid device type.\n"); - err = AVERROR(EINVAL); - goto fail; + if (ctx->derive_device_type || (!device && (desc->flags & AV_PIX_FMT_FLAG_HWACCEL))) { + if (ctx->derive_device_type) { + type = av_hwdevice_find_type_by_name(ctx->derive_device_type); + if (type == AV_HWDEVICE_TYPE_NONE) { + av_log(avctx, AV_LOG_ERROR, "Invalid device type.\n"); + err = AVERROR(EINVAL); + goto fail; + } + } else { + type = av_hwdevice_get_type_by_pix_fmt(outlink->format); + if (type == AV_HWDEVICE_TYPE_NONE) { + av_log(avctx, AV_LOG_ERROR, "Could not get device type from " + "format %s.\n", av_get_pix_fmt_name(outlink->format)); + err = AVERROR(EINVAL); + goto fail; + } } err = av_hwdevice_ctx_create_derived(&device, type, @@ -92,12 +107,6 @@ static int hwmap_config_output(AVFilterLink *outlink) device_is_derived = 1; } - desc = av_pix_fmt_desc_get(outlink->format); - if (!desc) { - err = AVERROR(EINVAL); - goto fail; - } - if (inlink->format == hwfc->format && (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) && !ctx->reverse) {