From patchwork Mon Jul 4 08:09:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Tong1" X-Patchwork-Id: 36640 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp2666189pzh; Mon, 4 Jul 2022 01:11:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ufeIpN7o0/x3FZjSXNeTvkDrLk4ZFo2T33LMiBKBYoewQP18bWIEzWZzdhQfr9Fw4eTlY+ X-Received: by 2002:a17:906:8a58:b0:72a:d029:d92e with SMTP id gx24-20020a1709068a5800b0072ad029d92emr855201ejc.354.1656922278308; Mon, 04 Jul 2022 01:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656922278; cv=none; d=google.com; s=arc-20160816; b=MWBB7uTbMzeG28rliyeM8WSWYYp6uZ4GSa4lWX7NxC16uQITJs6bNjYRnLC7IWL/UP cTVm2xhTSSgAO4zRqRc/jA2WEhHkbm97aJEri3xwUI+/+XcGUIPqUzwuj+zq5EpTQGQS hpYCR5jxSFaEsqpjHPxWkGMPsoFGuhdoqOQPX7VZ7GV+Zo2J5BxKiPWK0JxoleRyjhkK HlNRcHQEI9GWx7nQK1btU54+eCKAGetvuYX399YooXXEenaybw/xJ4NNda+GFKXHe0VZ Dl8KjSqH6v0dqmwG3X+tjGP3GRhJdWSW5NJ9Y57Q8IKHhnzPi1sIUMNZknZWBx6u5Owq 6VrQ== 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=M+H82gMRMl2HLP30tiiRnMHBU5MBf+LmRnlL8zVKIFU=; b=QT2X3ouql8bLtgqDgp95Ozcom49yWYycE6ntLFHkvao0McaFgD1XLe6mOE8s7WKann phi9brLlGocA+suLtN8+G0wuQ0HrT8yYDukIO7CJ1cQ+jFIO2CwmKk/X2iUhrq7949yu +dAvZbQsW/qRlt4cYY7oJ0aXiFf+l4wKQ9bt6ANVodq7AUYaylR7XTL5VDoWrHUfCwCn Q1GDkGSHcfmgmsH359632BIwEMO9pPzOwq8TytpmngZhj18mkQQHzJsQ8dBKOL400RfA pLUXLtTWPuPoPVhVOk36Xs/2akBdNH0l+UFqAjHzQj0G2Go4CN1zTGtDoii6bqBHjhOa O+5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=l9oVwIWJ; 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 m23-20020a17090679d700b00722b1057bfdsi13648440ejo.592.2022.07.04.01.11.17; Mon, 04 Jul 2022 01:11:18 -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=l9oVwIWJ; 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 EE67C68B320; Mon, 4 Jul 2022 11:11:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5606668B844 for ; Mon, 4 Jul 2022 11:11:05 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656922270; x=1688458270; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=X67rUWLColLJTpR48nmyqHn2fB4QpDP+iB34C77FqVs=; b=l9oVwIWJNWGb5WiZanHMxvWx1Vy2d0XwKVUXSJITFFcCJZaWmSs42JaZ aJHzPkjUwEFssVa61fqHF+O2Qz9fYOwYM78hipGkCWi9IgY5nFNrHMhvO jnKUk3oCAUB5/yzf+OYcIN9jSgqkFuUpfROPggoe2qmyitt4lX5EJKUki PJU5A+6/4NyJw2JdrCO7KmSWDzuVuxyBqMJxBqb3mbdgKeHSvxz+ZbCFL 9gbuBIKjIzGTWXL4oFb60SLMZKd1FbDNTrGDWwLGd30OoDW9lJJS5VYsh 8m5+5SxMcTVwpMeIm00pgQcn78e97jXEABMWE0mxpGOwbJgcUngjJIbXj Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10397"; a="262861127" X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="262861127" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jul 2022 01:11:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="660122900" Received: from desktop-qn7n0nf.sh.intel.com (HELO localhost.localdomain) ([10.239.160.39]) by fmsmga004.fm.intel.com with ESMTP; 04 Jul 2022 01:11:02 -0700 From: Tong Wu To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Jul 2022 16:09:53 +0800 Message-Id: <20220704080957.425-1-tong1.wu@intel.com> X-Mailer: git-send-email 2.35.1.windows.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 1/5] avutil/hwcontext: add a function to get the AVHWDeviceType 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: FumgNyrSmAOP Add a function to get the corresponding AVHWDeviceType from a given hardware pixel format. Signed-off-by: Tong Wu --- libavutil/hwcontext.c | 11 +++++++++++ libavutil/hwcontext.h | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c index ab9ad3703e..4d14cb2cb4 100644 --- a/libavutil/hwcontext.c +++ b/libavutil/hwcontext.c @@ -80,6 +80,17 @@ static const char *const hw_type_names[] = { [AV_HWDEVICE_TYPE_VULKAN] = "vulkan", }; +enum AVHWDeviceType av_hwdevice_get_type_by_pix_fmt(enum AVPixelFormat fmt) +{ + for (int i = 0; hw_table[i]; i++) { + for (int j = 0; hw_table[i]->pix_fmts[j] != AV_PIX_FMT_NONE; j++) { + if (hw_table[i]->pix_fmts[j] == fmt) + return hw_table[i]->type; + } + } + return AV_HWDEVICE_TYPE_NONE; +} + enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name) { int type; diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h index c18b7e1e8b..49f3a799ed 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -229,6 +229,18 @@ typedef struct AVHWFramesContext { int width, height; } AVHWFramesContext; +/** + * Get the device type by a given pixel format. + * + * This function only returns a preferred device type which supports the given + * pixel format. There is no guarantee that the device type is unique. + * + * @param fmt Pixel format from enum AVPixelFormat. + * @return The type from enum AVHWDeviceType, or AV_HWDEVICE_TYPE_NONE if + * not found. + */ +enum AVHWDeviceType av_hwdevice_get_type_by_pix_fmt(enum AVPixelFormat fmt); + /** * Look up an AVHWDeviceType by name. * From patchwork Mon Jul 4 08:09:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Tong1" X-Patchwork-Id: 36641 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp2666269pzh; Mon, 4 Jul 2022 01:11:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vA1LC6EaUcyY1BwL2soQ/QVB9Sfa4ItGSf3an5glNZKU2SlgEnQzmGez0WTpYL08dJGEO+ X-Received: by 2002:a05:6402:2741:b0:434:fe8a:1f96 with SMTP id z1-20020a056402274100b00434fe8a1f96mr37930637edd.331.1656922289172; Mon, 04 Jul 2022 01:11:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656922289; cv=none; d=google.com; s=arc-20160816; b=n7VwSh5JQ7MvwHkDlP3sZGEkdLzSbye4he35ix6l6bbWTw5Mgw6FQpST76HYISZBTG JJlrUDyYE0t4Cho0EZyYqZdZ5i8dZ1zdla0aUZGNmGPkeGsgyeFXUi2ZvuZ/3yyXou9G HDS3bIbJE/DxdYdPo0R+NqyG79HpFHTh8grAzTP+rKA1zGyxf0z4JM5JrDyt9r6mPgXd 3ajhgTa0YTenEYG8ITAsaZ65pV9JvsaK9fnfpt1Me3hSwDiUfGYiSRLtoopXo/DH/pkZ dAZzFBudX0B/GZ755bJdSIPAfxdWBoQ9xHUZQ/OdQRFbtFCU9EVO+SBl2EIIRqhtB/xf pPKg== 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=njHaXZf5l/1L6XsThpyr0BRHVMD0iicBBJG2r5JBKJY=; b=gF0wf9uWeFat8PR53goeRkij1GFGUdegOvK5E8IMn4K4GWKLZAUnZtoKYbKNLSIk8F SSCMFT1g+Rm5YGmK6glhVE/kQrsth9eMUkt9OmPSi6uKY18H/jwA0sGJsVD+uWFcwGnZ v/8ZF42+boYY8ykGQtZUVFc3aq13S/KBjn9L4IcIvTSstmPVVQfAtWnWN3PFQehbELJJ Ad+SrISR9nQ9zXu4v18n8oQ05G7brOBNU/T9/V15pbyp5K1nhn7yX2ZHKkcH5/BACCw3 rqgm9d3SplZmLHloGvYs5ebVfZs0Ifa3kY74B2zMjfsZny7kZ1mSSRX4aQawbKNtqxxA VdRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=Rv94aaGp; 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 i24-20020a05640200d800b0042df92502a1si8291173edu.329.2022.07.04.01.11.28; Mon, 04 Jul 2022 01:11:29 -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=Rv94aaGp; 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 3B75B68B9E8; Mon, 4 Jul 2022 11:11:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4149E68B320 for ; Mon, 4 Jul 2022 11:11:07 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656922272; x=1688458272; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fPZ87X4OL+EVQ1rCHSoguqWAsxkiSM5XnwOhtEYcza0=; b=Rv94aaGpwoL0ntVtmcOA2xs7R35/1GhlCBmia18Yj4D4B9xQlThFsYdU eEeh9fHFJpvSa/bA1aHz7G3ftpJjbwDSg4Uim892qiEVPWbxRkhzovqPg 7njoq6DK8br2CobLD+CSVpWnXPrR59ESLo+SrEE1eVXqbQ/W400eDTrrK /YQrfz4Ah/ETNYDu6ClKrX+LNuGj5SCHg0Lb1a/mKVNEeRkb5sUspdlpo QrJqvYgWFLyF1Uf/1T//QcLgEe4m3ewKmgM1ylgvA+qce5Q/mUCmYzhen 5/hedQT1917EPhQr1ZOjPK/h7jJETDDgRMsgMthCVtLMEAr+M4FOV9UZJ g==; X-IronPort-AV: E=McAfee;i="6400,9594,10397"; a="262861131" X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="262861131" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jul 2022 01:11:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="660122906" Received: from desktop-qn7n0nf.sh.intel.com (HELO localhost.localdomain) ([10.239.160.39]) by fmsmga004.fm.intel.com with ESMTP; 04 Jul 2022 01:11:03 -0700 From: Tong Wu To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Jul 2022 16:09:54 +0800 Message-Id: <20220704080957.425-2-tong1.wu@intel.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220704080957.425-1-tong1.wu@intel.com> References: <20220704080957.425-1-tong1.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 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: 6Wevc0LFmdg+ When a derive_device_type is not specified, 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 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_hwmap.c b/libavfilter/vf_hwmap.c index 2e03dfc1fe..328395e352 100644 --- a/libavfilter/vf_hwmap.c +++ b/libavfilter/vf_hwmap.c @@ -70,18 +70,27 @@ 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; - 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; + } + } + if (!device || ctx->derive_device_type) { err = av_hwdevice_ctx_create_derived(&device, type, hwfc->device_ref, 0); if (err < 0) { From patchwork Mon Jul 4 08:09:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Tong1" X-Patchwork-Id: 36642 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp2666337pzh; Mon, 4 Jul 2022 01:11:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u17z1xHwLfEYgwGBKpVNE2kmCUULU+nzSJy9vJe6YF7HuIbZMoV86rr5Ne6Ox8mylRig5i X-Received: by 2002:a17:907:1dc6:b0:72a:5e9a:91be with SMTP id og6-20020a1709071dc600b0072a5e9a91bemr22434740ejc.730.1656922298175; Mon, 04 Jul 2022 01:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656922298; cv=none; d=google.com; s=arc-20160816; b=dipiSDAIHnjhRZhck4RbQbQpGmyFmo/mOw0F/f8sancViwij6Q9AZlZ758Q7VZZX7M fS7MPaUdTwL74DWBHDwURrII1mc65LrPZ6Sar+8joBpc9RqU6uxRgRHoHc87juR3Lxn6 aCRzcS7LlB7MXqEhHHNu2QPhkORP+PLh0eiM/tm7RPVoje6dPXcSWoHq8VX5nyFzUZeR VfBJ8qUgiAvTA6mgn0xteotClcFs232PoQiRC8WBhW0WW4EnuHcuMx1JM9gwu8n/o2EY OyyAf+plk2yTFyLlH/7c7PnCUOheP7WtCJa+RJVS0l/Cgn/CKAmCbm3/tv+36hq0PUhg yj9A== 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=t8PbA2iclTGgx4JAfZQ+DIyIMr1BVPOhIkbzMSp5PEE=; b=QpzqegAPWcrJTL8/rIXs1s70iTatP90d5TavEHYo00TyXsGoAt7CDihze021DNiOmf JbUdhSu/497wjFP+JeQ7bEag4R53j7TBeRFbqps5tLR0zOMf95DWSlT3/EIUaLrVQ4mn IB/5xxzetXJqYShTURK7MIb6AUwRW0RmZk8IeUzz5vbGzjfd/I3vUTNSjuPJNooOzvMx qZ9JgroESrVVzQwnYsIGaqfz1WJtwLdV3MBW0hPE+PH0I4/ZUyWh8wm3zAHtp8u4jXQD VopnEdLbKFsagDLZItYGYnplMMVItEf7U7jTQq9vavK1HKaE/L1wPoxeNcV08JOJ7JMC jllg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=W3FTRfao; 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 dz9-20020a0564021d4900b00437a255e8e9si13672449edb.509.2022.07.04.01.11.37; Mon, 04 Jul 2022 01:11:38 -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=W3FTRfao; 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 02CCE68B951; Mon, 4 Jul 2022 11:11:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6BBED68B9E9 for ; Mon, 4 Jul 2022 11:11:08 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656922273; x=1688458273; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WcUvov7hoTbB6x0Z39U4SYeGYpcM9Zlq6sdhV+cFcIA=; b=W3FTRfaoet7wXJq8lX0xE2M4A2FJiJDL0tPNrqcX4/MAitBtOlo3olQM mViO6GCu7NGvgQ7Xi5N0VUoEjtZtbrpMkp0+ECbersfuXJFApDWX7dFpE q3NDWEvo3kIZqIV4/xPZifZ0KOl6GvPSJWl6ku4n+9MZTtWYzg6pYiU9g 3F9+vcFunHALXM9PuzLhQgnnTwfYL7ZqykILWaGD2On/ZKOtzRZBzTL0Z oJyfYNEFIwOcjXlsNk1dN00L8SykR0KEYPJEL4JDvr4wAIfiENg5pwZL6 RwSdVtO5gkpTKIZAxwpe6OX4tW7/hXr1Q8KMOtTj7btsiWtLmD+LZPSkM g==; X-IronPort-AV: E=McAfee;i="6400,9594,10397"; a="262861135" X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="262861135" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jul 2022 01:11:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="660122915" Received: from desktop-qn7n0nf.sh.intel.com (HELO localhost.localdomain) ([10.239.160.39]) by fmsmga004.fm.intel.com with ESMTP; 04 Jul 2022 01:11:04 -0700 From: Tong Wu To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Jul 2022 16:09:55 +0800 Message-Id: <20220704080957.425-3-tong1.wu@intel.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220704080957.425-1-tong1.wu@intel.com> References: <20220704080957.425-1-tong1.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 3/5] lavfi/avfiltergraph: move convert codes into functions 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: eFUHKju8Edha This patch moves the auto-insert filter codes into two functions. Signed-off-by: Tong Wu --- libavfilter/avfiltergraph.c | 128 ++++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 49 deletions(-) diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index b7dbfc063b..2e6938b049 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -393,6 +393,74 @@ static int formats_declared(AVFilterContext *f) return 1; } +static int insert_auto_filter(AVFilterContext **convert, AVFilterGraph *graph, + AVFilterLink *link, const AVFilterNegotiation *neg, + int *converter_count, void *log_ctx) +{ + int ret; + const AVFilter *filter; + AVFilterContext *ctx; + AVFilterLink *inlink, *outlink; + char inst_name[30]; + const char *opts; + + if (!(filter = avfilter_get_by_name(neg->conversion_filter))) { + av_log(log_ctx, AV_LOG_ERROR, + "'%s' filter not present, cannot convert formats.\n", + neg->conversion_filter); + return AVERROR(EINVAL); + } + snprintf(inst_name, sizeof(inst_name), "auto_%s_%d", + neg->conversion_filter, (*converter_count)++); + opts = FF_FIELD_AT(char *, neg->conversion_opts_offset, *graph); + ret = avfilter_graph_create_filter(&ctx, filter, inst_name, opts, NULL, graph); + if (ret < 0) + return ret; + + if ((ret = avfilter_insert_filter(link, ctx, 0, 0)) < 0) + return ret; + + if ((ret = filter_query_formats(ctx)) < 0) + return ret; + + inlink = ctx->inputs[0]; + outlink = ctx->outputs[0]; + av_assert0( inlink->incfg.formats->refcount > 0); + av_assert0( inlink->outcfg.formats->refcount > 0); + av_assert0(outlink->incfg.formats->refcount > 0); + av_assert0(outlink->outcfg.formats->refcount > 0); + if (outlink->type == AVMEDIA_TYPE_AUDIO) { + av_assert0( inlink-> incfg.samplerates->refcount > 0); + av_assert0( inlink->outcfg.samplerates->refcount > 0); + av_assert0(outlink-> incfg.samplerates->refcount > 0); + av_assert0(outlink->outcfg.samplerates->refcount > 0); + av_assert0( inlink-> incfg.channel_layouts->refcount > 0); + av_assert0( inlink->outcfg.channel_layouts->refcount > 0); + av_assert0(outlink-> incfg.channel_layouts->refcount > 0); + av_assert0(outlink->outcfg.channel_layouts->refcount > 0); + } + + *convert = ctx; + return 0; +} + +static int merge_auto_filter(AVFilterContext *convert, const AVFilterNegotiation *neg) +{ + int ret; + AVFilterLink *inlink = convert->inputs[0]; + AVFilterLink *outlink = convert->outputs[0]; +#define MERGE(merger, link) \ + ((merger)->merge(FF_FIELD_AT(void *, (merger)->offset, (link)->incfg), \ + FF_FIELD_AT(void *, (merger)->offset, (link)->outcfg))) + for (unsigned neg_step = 0; neg_step < neg->nb_mergers; neg_step++) { + const AVFilterFormatsMerger *m = &neg->mergers[neg_step]; + if ((ret = MERGE(m, inlink)) <= 0 || + (ret = MERGE(m, outlink)) <= 0) + break; + } + return ret; +} + /** * Perform one round of query_formats() and merging formats lists on the * filter graph. @@ -470,10 +538,6 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx) if (convert_needed) { AVFilterContext *convert; - const AVFilter *filter; - AVFilterLink *inlink, *outlink; - char inst_name[30]; - const char *opts; if (graph->disable_auto_convert) { av_log(log_ctx, AV_LOG_ERROR, @@ -484,54 +548,20 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx) } /* couldn't merge format lists. auto-insert conversion filter */ - if (!(filter = avfilter_get_by_name(neg->conversion_filter))) { - av_log(log_ctx, AV_LOG_ERROR, - "'%s' filter not present, cannot convert formats.\n", - neg->conversion_filter); - return AVERROR(EINVAL); - } - snprintf(inst_name, sizeof(inst_name), "auto_%s_%d", - neg->conversion_filter, converter_count++); - opts = FF_FIELD_AT(char *, neg->conversion_opts_offset, *graph); - ret = avfilter_graph_create_filter(&convert, filter, inst_name, opts, NULL, graph); - if (ret < 0) - return ret; - if ((ret = avfilter_insert_filter(link, convert, 0, 0)) < 0) + ret = insert_auto_filter(&convert, graph, link, neg, &converter_count, log_ctx); + if (ret < 0) { + av_log(log_ctx, AV_LOG_ERROR, "Failed to insert an auto filter.\n"); return ret; + } - if ((ret = filter_query_formats(convert)) < 0) + ret = merge_auto_filter(convert, neg); + if (ret < 0) return ret; - - inlink = convert->inputs[0]; - outlink = convert->outputs[0]; - av_assert0( inlink->incfg.formats->refcount > 0); - av_assert0( inlink->outcfg.formats->refcount > 0); - av_assert0(outlink->incfg.formats->refcount > 0); - av_assert0(outlink->outcfg.formats->refcount > 0); - if (outlink->type == AVMEDIA_TYPE_AUDIO) { - av_assert0( inlink-> incfg.samplerates->refcount > 0); - av_assert0( inlink->outcfg.samplerates->refcount > 0); - av_assert0(outlink-> incfg.samplerates->refcount > 0); - av_assert0(outlink->outcfg.samplerates->refcount > 0); - av_assert0( inlink-> incfg.channel_layouts->refcount > 0); - av_assert0( inlink->outcfg.channel_layouts->refcount > 0); - av_assert0(outlink-> incfg.channel_layouts->refcount > 0); - av_assert0(outlink->outcfg.channel_layouts->refcount > 0); - } -#define MERGE(merger, link) \ - ((merger)->merge(FF_FIELD_AT(void *, (merger)->offset, (link)->incfg), \ - FF_FIELD_AT(void *, (merger)->offset, (link)->outcfg))) - for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) { - const AVFilterFormatsMerger *m = &neg->mergers[neg_step]; - if ((ret = MERGE(m, inlink)) <= 0 || - (ret = MERGE(m, outlink)) <= 0) { - if (ret < 0) - return ret; - av_log(log_ctx, AV_LOG_ERROR, - "Impossible to convert between the formats supported by the filter " - "'%s' and the filter '%s'\n", link->src->name, link->dst->name); - return AVERROR(ENOSYS); - } + else if (ret == 0) { + av_log(log_ctx, AV_LOG_ERROR, + "Impossible to convert between the formats supported by the filter " + "'%s' and the filter '%s'\n", link->src->name, link->dst->name); + return AVERROR(ENOSYS); } } } From patchwork Mon Jul 4 08:09:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Tong1" X-Patchwork-Id: 36643 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp2666403pzh; Mon, 4 Jul 2022 01:11:47 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t7s85yo8MWuh5oigO4kbJ0vqiLlShtt58l2Z2dgVsL3HDb1I0phlLYOvXOoseUmE4osl7M X-Received: by 2002:a05:6402:280b:b0:437:9efc:a065 with SMTP id h11-20020a056402280b00b004379efca065mr37445797ede.3.1656922307804; Mon, 04 Jul 2022 01:11:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656922307; cv=none; d=google.com; s=arc-20160816; b=RvBQDc8pv9tyTN0YVqXywHh0m/aeaw9YjpLadilzjg1iHkeQjq4i1cIeitMTRRHrvN sPWaUNKFP8DDqb0Mne4kusTaMTGMU2/qqm0qlNr3m195FHtSsQyW+ImFnq5GqrKIDeQE TuoflveXedrAg+Vgea19gQbFGX/xhqhGs74O0+jlfhQ9QS+c5fzt4/n9UUw+k+IS9YHk zdtUU7yzL6vWKcJ2pX9kRz8EV28wMYJPMpFyXb42VVzY610oMQhdEJBXr2Z7dyPg2P42 Do/yzajl7qvlccnoWOa5HS19vFxZIseoOHIZ+K07oZGkNI0pO3QJjbrkVvfbMjIoO9xz aUbg== 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=wh2I06Tuz1Hn3PkREOADR8XG2X/tpdF9FPt2DFr4fCQ=; b=Nz3G+GzoL+6LBbqc0jImeKbRC5TkASMucAWNeG+Km1V3P3teYeQLusyrezNTVnLPpP KVI9IRFRDUcyaYmw8T19/V/tZnJTzcQAA8xiryXpWwYKvnZYqjsjT8v4lWGZ6p0Cv+jq HMxyMuqVPzmoW43qIf5MptkUEh4FGlJRbpUJyL5cCX7trm3hXhEx7d33v8JHQqG1pGNz 06qmP0Ji1IiQcWvYv4UxeAmh9W/Uf0R2UIYMBsmAHZrn89k4QkAorrbpaMDfpDZpXUR4 wZyogGwqT88ECXKp1GStxS9xsmfkyu1lUg/n+PDHhnR57QVTwCl0sCM10QrhDqnbZ1i0 aMDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=Wb+HNs4L; 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 hw9-20020a170907a0c900b0072abb81b5f5si4938857ejc.537.2022.07.04.01.11.47; Mon, 04 Jul 2022 01:11:47 -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=Wb+HNs4L; 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 17F1C68B9F8; Mon, 4 Jul 2022 11:11:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4F42768B9FC for ; Mon, 4 Jul 2022 11:11:11 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656922276; x=1688458276; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=o0E2V7UE8k7IHBeqGT8UrBqVBpqT9Saeivrf2FAsFQk=; b=Wb+HNs4Ll9Wk1oCXMtv2U17OObDD2ZZdEcklQfYg7CV86RJehYsyvBmO lLQecMzjg8ysBIUNEXYlE6ObKj1mpVkIJa+AKCaWN3bASECroEbzOVmKx rHMBs12f3aMoaG4atbK6jYwVxNwzezfXSxxBTwGh0+rXi6Hjq0eVXRSI7 KX63SyCok8HxoiSkqEZp3G17sOMAwYdjO7w+s4riGksDryNTL4qmsNP2u I4Zzw6wRsjIfyvvFRUntF5JH0dvxY5gLrUA2QOrKwjNV2AXcqQX01sjVI Lkz6OYqLrS5Uou9tHERddOnydTGOH9kG/tHp2C+vHPjsV6T9083FXb4O4 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10397"; a="262861138" X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="262861138" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jul 2022 01:11:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="660122919" Received: from desktop-qn7n0nf.sh.intel.com (HELO localhost.localdomain) ([10.239.160.39]) by fmsmga004.fm.intel.com with ESMTP; 04 Jul 2022 01:11:05 -0700 From: Tong Wu To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Jul 2022 16:09:56 +0800 Message-Id: <20220704080957.425-4-tong1.wu@intel.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220704080957.425-1-tong1.wu@intel.com> References: <20220704080957.425-1-tong1.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 4/5] lavfi/format: wrap auto filters into structures 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: dlt9gochIHz3 This patch wraps auto conversion filters into new structures, making it easier to add more auto filters. And it adds a loop to automatically insert every possible conversion filter until merge succeeds. Signed-off-by: Tong Wu --- libavfilter/avfiltergraph.c | 76 +++++++++++++++++++++++++------------ libavfilter/formats.c | 22 +++++++++-- libavfilter/formats.h | 10 ++++- 3 files changed, 78 insertions(+), 30 deletions(-) diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 2e6938b049..102c1f7693 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -395,24 +395,22 @@ static int formats_declared(AVFilterContext *f) static int insert_auto_filter(AVFilterContext **convert, AVFilterGraph *graph, AVFilterLink *link, const AVFilterNegotiation *neg, - int *converter_count, void *log_ctx) + unsigned conv_step, int *converter_count, void *log_ctx) { int ret; const AVFilter *filter; AVFilterContext *ctx; AVFilterLink *inlink, *outlink; char inst_name[30]; - const char *opts; + const char *opts = FF_FIELD_AT(char *, neg->conversion_filters[conv_step].conversion_opts_offset, *graph); + const char *name = neg->conversion_filters[conv_step].conversion_filter; - if (!(filter = avfilter_get_by_name(neg->conversion_filter))) { + if (!(filter = avfilter_get_by_name(name))) { av_log(log_ctx, AV_LOG_ERROR, - "'%s' filter not present, cannot convert formats.\n", - neg->conversion_filter); + "'%s' filter not present, cannot convert formats.\n", name); return AVERROR(EINVAL); } - snprintf(inst_name, sizeof(inst_name), "auto_%s_%d", - neg->conversion_filter, (*converter_count)++); - opts = FF_FIELD_AT(char *, neg->conversion_opts_offset, *graph); + snprintf(inst_name, sizeof(inst_name), "auto_%s_%d", name, (*converter_count)++); ret = avfilter_graph_create_filter(&ctx, filter, inst_name, opts, NULL, graph); if (ret < 0) return ret; @@ -501,7 +499,7 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx) for (j = 0; j < filter->nb_inputs; j++) { AVFilterLink *link = filter->inputs[j]; const AVFilterNegotiation *neg; - unsigned neg_step; + unsigned neg_step, conv_step; int convert_needed = 0; if (!link) @@ -537,8 +535,6 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx) } if (convert_needed) { - AVFilterContext *convert; - if (graph->disable_auto_convert) { av_log(log_ctx, AV_LOG_ERROR, "The filters '%s' and '%s' do not have a common format " @@ -548,20 +544,52 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx) } /* couldn't merge format lists. auto-insert conversion filter */ - ret = insert_auto_filter(&convert, graph, link, neg, &converter_count, log_ctx); - if (ret < 0) { - av_log(log_ctx, AV_LOG_ERROR, "Failed to insert an auto filter.\n"); - return ret; - } + for (conv_step = 0; conv_step < neg->nb_conversion_filters; conv_step++) { + AVFilterContext *convert; + ret = insert_auto_filter(&convert, graph, link, neg, + conv_step, &converter_count, log_ctx); + if (ret < 0) { + av_log(log_ctx, AV_LOG_ERROR, "Failed to insert an auto filter.\n"); + return ret; + } - ret = merge_auto_filter(convert, neg); - if (ret < 0) - return ret; - else if (ret == 0) { - av_log(log_ctx, AV_LOG_ERROR, - "Impossible to convert between the formats supported by the filter " - "'%s' and the filter '%s'\n", link->src->name, link->dst->name); - return AVERROR(ENOSYS); + ret = merge_auto_filter(convert, neg); + if (ret < 0) + return ret; + else if (ret > 0) + break; + else if (conv_step < neg->nb_conversion_filters - 1) { + AVFilterLink *inlink = convert->inputs[0]; + AVFilterLink *outlink = convert->outputs[0]; + av_log(log_ctx, AV_LOG_VERBOSE, + "Impossible to convert between the formats supported by the filter " + "'%s' and the filter '%s', try another conversion filter.\n", + link->src->name, link->dst->name); + unsigned dstpad_idx = outlink->dstpad - outlink->dst->input_pads; + converter_count--; + /* re-hookup the link */ + inlink->dst = outlink->dst; + inlink->dstpad = &outlink->dst->input_pads[dstpad_idx]; + outlink->dst->inputs[dstpad_idx] = inlink; + if (outlink->outcfg.formats) + ff_formats_changeref(&outlink->outcfg.formats, + &inlink->outcfg.formats); + if (outlink->outcfg.samplerates) + ff_formats_changeref(&outlink->outcfg.samplerates, + &inlink->outcfg.samplerates); + if (outlink->outcfg.channel_layouts) + ff_channel_layouts_changeref(&outlink->outcfg.channel_layouts, + &inlink->outcfg.channel_layouts); + /* remove the previous auto filter */ + convert->inputs[0] = NULL; + convert->outputs[0]->dst = NULL; + avfilter_free(convert); + } else { + av_log(log_ctx, AV_LOG_ERROR, + "Impossible to convert between the formats supported by the filter " + "'%s' and the filter '%s'\n", link->src->name, link->dst->name); + return AVERROR(ENOSYS); + } } } } diff --git a/libavfilter/formats.c b/libavfilter/formats.c index e8c2888c0c..c8e20e5b20 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -326,18 +326,32 @@ static const AVFilterFormatsMerger mergers_audio[] = { }, }; +static const AVFilterFormatsFilter filters_video[] = { + { + .conversion_filter = "scale", + .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts), + }, +}; + +static const AVFilterFormatsFilter filters_audio[] = { + { + .conversion_filter = "aresample", + .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts), + } +}; + static const AVFilterNegotiation negotiate_video = { .nb_mergers = FF_ARRAY_ELEMS(mergers_video), .mergers = mergers_video, - .conversion_filter = "scale", - .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts), + .nb_conversion_filters = FF_ARRAY_ELEMS(filters_video), + .conversion_filters = filters_video, }; static const AVFilterNegotiation negotiate_audio = { .nb_mergers = FF_ARRAY_ELEMS(mergers_audio), .mergers = mergers_audio, - .conversion_filter = "aresample", - .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts), + .nb_conversion_filters = FF_ARRAY_ELEMS(filters_audio), + .conversion_filters = filters_audio, }; const AVFilterNegotiation *ff_filter_get_negotiation(AVFilterLink *link) diff --git a/libavfilter/formats.h b/libavfilter/formats.h index 22224dce2d..868cbe98dd 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -330,6 +330,12 @@ typedef struct AVFilterFormatMerger { int (*can_merge)(const void *a, const void *b); } AVFilterFormatsMerger; +typedef struct AVFilterFormatFilter { + const char *conversion_filter; + unsigned conversion_opts_offset; +} AVFilterFormatsFilter; + + /** * Callbacks and properties to describe the steps of a format negotiation. * @@ -418,8 +424,8 @@ typedef struct AVFilterFormatMerger { typedef struct AVFilterNegotiation { unsigned nb_mergers; const AVFilterFormatsMerger *mergers; - const char *conversion_filter; - unsigned conversion_opts_offset; + unsigned nb_conversion_filters; + const AVFilterFormatsFilter *conversion_filters; } AVFilterNegotiation; const AVFilterNegotiation *ff_filter_get_negotiation(AVFilterLink *link); From patchwork Mon Jul 4 08:09:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Tong1" X-Patchwork-Id: 36644 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp2666450pzh; Mon, 4 Jul 2022 01:11:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uKolgQQrxJE7p6ON5+vuFe9V3S5u9DUtXVIzb+mXfbTS4a07KotmiSv8z7iR1Sa+CmfwnE X-Received: by 2002:a17:906:685:b0:6fa:8e17:e9b5 with SMTP id u5-20020a170906068500b006fa8e17e9b5mr26119044ejb.522.1656922316576; Mon, 04 Jul 2022 01:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656922316; cv=none; d=google.com; s=arc-20160816; b=lBWzsXNNN4FwsJXtGPh5Oc70/5H2BiuUOhMEy0HAQBrG/lcEX7lUpwaxy17AozaZNh QM+wjogyf485jfFLHYmDYGwqnKC7NOxWcN1vnqFsdkPFX4sA4P6jzPj1Li5UEfh3A1XF TaDMPrYQl0f2U0y/7GOmCFBZlA6jku6t6uOYpYqbM1zbuC3Xug72/DHsV+vRMVXPRhoh Nh8Zz1iJpLGpV5cJmejBOHU1G7GqZdeRfF9tE4l3g76qxkjGsqr+kppPhGGIJyU3yPVQ t12IEJsEPQhJR6TSoLu+qJqQK5+SI39ZqCUOz5K/XvvsFaLa1i5/+3PJcu0NHlqarQQ3 QcYA== 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=3KcObpMLKIlNB0YEi/gVsrcQ0Fp9LyY5lyrfodmVJNo=; b=E+FEndZ1IjfrDmjaTH9bqBUIg8ej5/fFifNK5HjpBm01kdN7CoPpywzDTFGESYmNGm AKllxRmXW85R6HrjPVjHObqIR0sAHYhJeIXI4bIufpf09FDVPdhUqRKmvvz3Eyt6RKt1 hQNb+RqQv4a+NcCVURm8NTayOia3GbevWyruaztrx91HB2A9YuM5XD5IHgi5SGOtNMqc LpgjBlHyY5pFqX4CL3kVpRoPM0qZdl1rbxaBT+uxievjKcADdvu7m5mTqDzKf19JlP8y fYQ7I0VXqiyjCgAnnVujVJZZZUM3iyWg3x/g3DO/vEUEYoI8VfC4xhihd39smvXjyyP5 R7ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=TmH8Dp5G; 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 f11-20020a056402328b00b0043964f52a6dsi12477158eda.52.2022.07.04.01.11.56; Mon, 04 Jul 2022 01:11:56 -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=TmH8Dp5G; 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 3ED2968B9F0; Mon, 4 Jul 2022 11:11:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3BA7C68B9F8 for ; Mon, 4 Jul 2022 11:11:12 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656922278; x=1688458278; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mqk3s+1LipTmeHO8x4FFjukNqTjNxRisjR2CZKJPAdg=; b=TmH8Dp5GaL/60duf4YimU2q3rsjuArT+GLkz1aCszOfQZSRbovxoJDLQ Obx55q+PR9zTqgSShYbYBluufruP8OBjO/ZjYca/T4fS4wustL1572yfd 9YsC6Hw1rnC0QMl5wTRtonm3Spaa5+5fTqGgZWN29DMe1V1N88dwhH7ez Y5TrpavDzstudLwb1Tcz7HIRpq4eZUefR7gM71QSCPuWhQ3Ocso3ENlU4 rL523GZqmj8t/Sr3vQCPUyuMw+QZlfJYnCWWnpynmsDydmZY5XlniybxD Ix47RNtys8v+V54NQnRbnzhc056dromneyffWN82WRdgpeqVx0iZh4EJb g==; X-IronPort-AV: E=McAfee;i="6400,9594,10397"; a="262861140" X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="262861140" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jul 2022 01:11:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="660122924" Received: from desktop-qn7n0nf.sh.intel.com (HELO localhost.localdomain) ([10.239.160.39]) by fmsmga004.fm.intel.com with ESMTP; 04 Jul 2022 01:11:06 -0700 From: Tong Wu To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Jul 2022 16:09:57 +0800 Message-Id: <20220704080957.425-5-tong1.wu@intel.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220704080957.425-1-tong1.wu@intel.com> References: <20220704080957.425-1-tong1.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 5/5] lavfi/format: add a hwmap auto conversion filter 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: ViCMXURrQmtU When two formats lists cannot be merged, a scale filter is auto-inserted. However, when it comes to hardware map, we have to manually add a hwmap filter to do the conversion. This patch introduces an auto hwmap filter to do the hwmap conversion automatically. Signed-off-by: Tong Wu --- libavfilter/avfiltergraph.c | 3 ++- libavfilter/formats.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 102c1f7693..8e63007cac 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -402,7 +402,8 @@ static int insert_auto_filter(AVFilterContext **convert, AVFilterGraph *graph, AVFilterContext *ctx; AVFilterLink *inlink, *outlink; char inst_name[30]; - const char *opts = FF_FIELD_AT(char *, neg->conversion_filters[conv_step].conversion_opts_offset, *graph); + const char *opts = neg->conversion_filters[conv_step].conversion_opts_offset == 0 ? NULL : + FF_FIELD_AT(char *, neg->conversion_filters[conv_step].conversion_opts_offset, *graph); const char *name = neg->conversion_filters[conv_step].conversion_filter; if (!(filter = avfilter_get_by_name(name))) { diff --git a/libavfilter/formats.c b/libavfilter/formats.c index c8e20e5b20..fee10fa0ee 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -331,6 +331,10 @@ static const AVFilterFormatsFilter filters_video[] = { .conversion_filter = "scale", .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts), }, + { + .conversion_filter = "hwmap", + .conversion_opts_offset = 0, + } }; static const AVFilterFormatsFilter filters_audio[] = {