From patchwork Thu Jun 30 02:45: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: 36536 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp13838pzh; Wed, 29 Jun 2022 19:47:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s6c9a065YfFG5jRKjW2yKBBYj4g9Y8a7EMdtFdlu9m1z0ueCfQQSRXwjjbfnxh8OQljMRE X-Received: by 2002:a05:6402:b34:b0:435:d064:8762 with SMTP id bo20-20020a0564020b3400b00435d0648762mr8500101edb.238.1656557246999; Wed, 29 Jun 2022 19:47:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656557246; cv=none; d=google.com; s=arc-20160816; b=u6Z8D2zcqV0AegXT7b4WI5Dm5wWBA+IzirFlZ25cYaHm36vgIHS5oLZpJe/NiFiQZa gIaRzKAv07FDVSVk53lJzkrEEAqjjL+bE61Ufe7EbCDlJAMsXqd0yANZSfXLoy8jCHwK Xi7ZRI9EJmC4yyzzA73n+FtBsI545td8tB/7fRnmbhlyJ14Yr0RhLEEGjB+XzyRyaTtb n00yrL5y0EPcwYSOlwQxLM8efIk/fjEyJdQbTyiA0mr+CD8GENpKVkORJ8hmSu5YWZYv YHaavUrcDsSnL8Si5vJ/r9+aDkCehZ/MWkOgHT8NRtHNp4ilAKBK1mgCBpXNQ7Up+6A6 xxRg== 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=DtrJWgp+Rdbbx0lt6b6x0YWh+NhSdURFwvrvaIxuQR4=; b=mvSr900SUNtP5Bo8i89+QCNT2oDOrqU4oW6Y9KK4zdbKkNmOLby3dS+JrHm2K2gY5Q CELE5OlIaXhdTe3z+P4hmfw2SAsc21UkQxzm/3Bhlcd9dP2AU8aaEtcNT8MXIW2rmKEt 6DXiWApTzIsHqOhXvjFWW0lZJgA+lQcWUQ0ORGymSOTMVzPMU6Rj51x0GqoqPKext2Eh Dv++gRowPVRj9XbZoJobLlQbcTB7xxMJemUfLTg+9jz/NBj4VKkTc+KTlDnsvl9wV6X9 +olWb0VSfg7+UfxotnzW5Uqg27RqlqJQdiWxrS1PGHi2VFQR7gw2I2JP16cz0sQNni6w ATbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=Gom+RJDf; 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 mp37-20020a1709071b2500b00711d89b831esi25786143ejc.721.2022.06.29.19.47.26; Wed, 29 Jun 2022 19:47:26 -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=Gom+RJDf; 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 D7FA868B78C; Thu, 30 Jun 2022 05:47:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2A6D468B3B1 for ; Thu, 30 Jun 2022 05:47:15 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656557241; x=1688093241; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=IYR8XUwKlj+wHdhMoBWYkmfNO1QamE/XcqsEP+Vc2eA=; b=Gom+RJDfJrTEaj49sliarSDwFndi45mPanhfSXJ+XSMaTOv6vrA3hAAD tiodc+C6ySbzWV5EbaQFKWjhVMf+PjIMnCWOhHCGCuibj2oRCrCsbO0xr 4QfJNwSgArYyefrMvcwY3pW4EP2BMV5qYeC7/pC6Uz3lQnkr9uBg5SRyp n585jZWDYMDJT3zkeqckYtn6Re77j3KwtYqKObTYw35gJ+uYgH58fMpD7 CrCIma8fMRoOkq8xFqk0VnVhEmpEfz6CTJi8eTL7kZib7keErof8pXKiH fkTpxpmNiUaUjyUu03qPCKpeSUru3GjdrP3UhodJo5c2hipr/L2vmT2eD A==; X-IronPort-AV: E=McAfee;i="6400,9594,10393"; a="265257537" X-IronPort-AV: E=Sophos;i="5.92,232,1650956400"; d="scan'208";a="265257537" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 19:47:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,232,1650956400"; d="scan'208";a="837387130" Received: from desktop-qn7n0nf.sh.intel.com (HELO localhost.localdomain) ([10.239.160.39]) by fmsmga006.fm.intel.com with ESMTP; 29 Jun 2022 19:47:12 -0700 From: Tong Wu To: ffmpeg-devel@ffmpeg.org Date: Thu, 30 Jun 2022 10:45:56 +0800 Message-Id: <20220630024558.1444-1-tong1.wu@intel.com> X-Mailer: git-send-email 2.35.1.windows.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/3] 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: 0K9oAjAUL6/E Add a function to get the corresponding AVHWDeviceType from a given hardware pixel format. Signed-off-by: Tong Wu --- libavutil/hwcontext.c | 12 ++++++++++++ libavutil/hwcontext.h | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c index ab9ad3703e..3521ed34f4 100644 --- a/libavutil/hwcontext.c +++ b/libavutil/hwcontext.c @@ -80,6 +80,18 @@ static const char *const hw_type_names[] = { [AV_HWDEVICE_TYPE_VULKAN] = "vulkan", }; +enum AVHWDeviceType av_hwdevice_get_type_by_pix_fmt(enum AVPixelFormat fmt) +{ + int i, j; + for (i = 0; hw_table[i]; i++) { + for (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..97f94403e2 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -229,6 +229,15 @@ typedef struct AVHWFramesContext { int width, height; } AVHWFramesContext; +/** + * Get the device type by a given pixel format. + * + * @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. *