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 E48ED43938 for ; Sun, 3 Jul 2022 12:58:30 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2958768B9B9; Sun, 3 Jul 2022 15:58:28 +0300 (EEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 212DF68B971 for ; Sun, 3 Jul 2022 15:58:20 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656853106; x=1688389106; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=X67rUWLColLJTpR48nmyqHn2fB4QpDP+iB34C77FqVs=; b=X6KNkdMjLAdGt5PBzxYXgy6kDaH4w4v3LYRzkrSxdJe7i1VjbcWwNasH sfMwnh7ASmqoOQwq3ZHmJ6CysywcS1RwaVCC9qllokeYcr3vrtElEd5qM FpPvxme0w3gZjkfSTN+O/aK0v81oX3+iA9TlkC4eJ0fQCiZXUrLMz2Oxh KyHZ5DivnTkuyQhIxQoDnsXvjukHmb4MmzCKwIGX+vtSELedcS7Pk7sWE oST3rxF69Yz20chIGuw+hF2t+HG0vWMijBEZLwJ8Bhjna4lEFp7pmtpf0 NYJVDYEO7xAU2Os3dsMGR0cqzPMVP2EOnI8ZKAnAhFx0aaTSJ+buaGj3L Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10396"; a="280500544" X-IronPort-AV: E=Sophos;i="5.92,241,1650956400"; d="scan'208";a="280500544" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jul 2022 05:58:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,241,1650956400"; d="scan'208";a="542206167" Received: from desktop-qn7n0nf.sh.intel.com (HELO localhost.localdomain) ([10.239.160.39]) by orsmga003.jf.intel.com with ESMTP; 03 Jul 2022 05:58:17 -0700 From: Tong Wu To: ffmpeg-devel@ffmpeg.org Date: Sun, 3 Jul 2022 20:57:12 +0800 Message-Id: <20220703125714.1230-1-tong1.wu@intel.com> X-Mailer: git-send-email 2.35.1.windows.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 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 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: 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. * -- 2.35.1.windows.2 _______________________________________________ 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".