From patchwork Mon Jun 12 22:40:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 3932 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.22.4 with SMTP id 4csp77787vsw; Mon, 12 Jun 2017 15:41:52 -0700 (PDT) X-Received: by 10.28.17.198 with SMTP id 189mr9240907wmr.6.1497307312029; Mon, 12 Jun 2017 15:41:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497307311; cv=none; d=google.com; s=arc-20160816; b=iUkh/FY89JQqq9HfuNxEuo+xCt1VRrOHPRkXVLD5IQhHCrP5x5V3KJvTCDkKxJGOiX MM/XXzRDd9nkrahX2foWXFdSRSPvDvGcwx+HnJGBAQK7RBD49CrMSQG6dYhsksGJvJf7 9BBGRwtGBYMhtwhe5jGK3AG20ALfA4Zd7KPYQo/N0k5zZwjxC10BJBFvoawXriBA3126 phxONJMXMn/pSgbgZyQ36QEOtGvitTCRo9V3isWGIxx3ugaHBlOAT91asMIq6yg7V/nm 8k+iBvrQZcH64euY0YLMAF+K8CxM5/n4/h5yF3OcE3CwxUbyTkMsahQ3iC/n3oqoFzG1 k5wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=2/xmslRK5JJqcGQ5xhcen/dq7RcjXeqwrUqP/Rhn7hc=; b=htuGL3/mYR5BtQaTIEe5jKI3UylydfcwcMnjcsjylfZZJBcNJT1OUdd26npa5h2Q9N iBSSQwCEX9uhUNGv8X0/y2QJc3K/gp+1Jwt+zEyZ97cqJtl0MkQPfZtE3ooX8T0mNtlm CWuFhWR27WcN/OvD99bvZ+ehh8UF14f+br1SvhJoM7UJMU6gU1BcOgxs5eog2sJWmQhI 69wRxUUiX5jne7PW11fuzGDE77QFfaDnUaa0wRSxf8czGGk4RvLTerKoRHVNV8wJFq2E 6wsBHYn10Ol0OAN+3JHoi1IpplCN5O5fVqW74luVDKdorDl1j6cS5+5yCMgq+SxgdkX+ 5QPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com; 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 x130si8557430wmg.27.2017.06.12.15.41.51; Mon, 12 Jun 2017 15:41:51 -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=@jkqxz-net.20150623.gappssmtp.com; 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 A663268A034; Tue, 13 Jun 2017 01:41:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f175.google.com (mail-wr0-f175.google.com [209.85.128.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D44B068091A for ; Tue, 13 Jun 2017 01:41:00 +0300 (EEST) Received: by mail-wr0-f175.google.com with SMTP id v104so113612763wrb.0 for ; Mon, 12 Jun 2017 15:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=2Zlyzj4aM3LOx+rD0ifYbXwe3n8pq9bxh3egpsQJBbo=; b=2K2CpNJvZDkyYe2A0hRSeKt7d6OEu4Zjg1ecP8YiU0n5iLhwQuYhvUI3btpWnSy48h h8J0BvK36UE0Pwq088LOGP4L/28XmYB4ADI/4vlbBdAIUxscxqeffj0Qzx9og9XcHiiC hR9/53YjR2ozbfv1GPx/HaenzA+Nhp8r49xsKNhSbe3Xk0daaY++tk8LJjRUcMDUAWCP i3bVTGaFONYu2oqzcwEtTLLOc6J3eeJp/M0yTK3kYwzJJe7TWElvy6iulo946QO4tOv4 38+/ruaExHwWRGjuUMmbVgXe3mDFLzqvPByakMxn0Gz7Zkceydr2DOdsFo1kMYI6L2VO hImQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=2Zlyzj4aM3LOx+rD0ifYbXwe3n8pq9bxh3egpsQJBbo=; b=QFlL2+1qR45yF37M9Ds70whNyymGL8vWz+b/PiRNOQfFWE9nlA8S02Wu55mzdW1iVW x1/49lNpIVxvPwvcRR7/oHs1UjrxINhWkmVe2x9fvPVLdXVOGGyJHj9frDnjmpQZvEGQ rc0dUixlWAT7myZkP996I3F0HcALc/z1AuaHe2auu4Doun6d4Wiq77m0o3EdGlWlG1Mm ppxZgwefJTqlDRCZmWZ4d03+mToCHcq/6jbql9uaTb/R0S3q8Ys6HQ0qJFYU90U/h61v ID4wiBBVs6csfRpMo9ADitFI83n44vcWY7t+lBdmumAGN3fADEf7DBmqWfFIWDxeAg3E iVjQ== X-Gm-Message-State: AKS2vOy7sOGKbrruZ+Ybz49qXrm12EQ2VMu1NFATc7cjiRZSBT3RWn7/ 28KRIccUVT4u0wnGP8M= X-Received: by 10.223.134.186 with SMTP id 55mr592447wrx.159.1497307262381; Mon, 12 Jun 2017 15:41:02 -0700 (PDT) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id m191sm13098233wmg.30.2017.06.12.15.41.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jun 2017 15:41:01 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Jun 2017 23:40:21 +0100 Message-Id: <20170612224041.6750-5-sw@jkqxz.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170612224041.6750-1-sw@jkqxz.net> References: <20170612224041.6750-1-sw@jkqxz.net> Subject: [FFmpeg-devel] [PATCH 04/24] hwcontext: Make it easier to work with device types X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Adds functions to convert to/from strings and a function to iterate over all supported device types. Also adds a new invalid type AV_HWDEVICE_TYPE_NONE, which acts as a sentinel value. (cherry picked from commit b7487f4f3c39b4b202e1ea7bb2de13902f2dee45) --- doc/APIchanges | 4 ++++ libavutil/hwcontext.c | 42 ++++++++++++++++++++++++++++++++++++++++++ libavutil/hwcontext.h | 28 ++++++++++++++++++++++++++++ libavutil/version.h | 2 +- 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index a6889f3930..5b2203f2b4 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,10 @@ libavutil: 2015-08-28 API changes, most recent first: +2017-06-xx - xxxxxxx - lavu 55.65.100 - hwcontext.h + Add AV_HWDEVICE_TYPE_NONE, av_hwdevice_find_type_by_name(), + av_hwdevice_get_type_name() and av_hwdevice_iterate_types(). + 2017-06-xx - xxxxxxx - lavu 55.64.100 - hwcontext.h Add av_hwdevice_ctx_create_derived(). diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c index 86d290d322..7f9b1d33e3 100644 --- a/libavutil/hwcontext.c +++ b/libavutil/hwcontext.c @@ -50,6 +50,48 @@ static const HWContextType *hw_table[] = { NULL, }; +const char *hw_type_names[] = { + [AV_HWDEVICE_TYPE_CUDA] = "cuda", + [AV_HWDEVICE_TYPE_DXVA2] = "dxva2", + [AV_HWDEVICE_TYPE_QSV] = "qsv", + [AV_HWDEVICE_TYPE_VAAPI] = "vaapi", + [AV_HWDEVICE_TYPE_VDPAU] = "vdpau", + [AV_HWDEVICE_TYPE_VIDEOTOOLBOX] = "videotoolbox", +}; + +enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name) +{ + int type; + for (type = 0; type < FF_ARRAY_ELEMS(hw_type_names); type++) { + if (hw_type_names[type] && !strcmp(hw_type_names[type], name)) + return type; + } + return AV_HWDEVICE_TYPE_NONE; +} + +const char *av_hwdevice_get_type_name(enum AVHWDeviceType type) +{ + if (type >= 0 && type < FF_ARRAY_ELEMS(hw_type_names)) + return hw_type_names[type]; + else + return NULL; +} + +enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev) +{ + enum AVHWDeviceType next; + int i, set = 0; + for (i = 0; hw_table[i]; i++) { + if (prev != AV_HWDEVICE_TYPE_NONE && hw_table[i]->type <= prev) + continue; + if (!set || hw_table[i]->type < next) { + next = hw_table[i]->type; + set = 1; + } + } + return set ? next : AV_HWDEVICE_TYPE_NONE; +} + static const AVClass hwdevice_ctx_class = { .class_name = "AVHWDeviceContext", .item_name = av_default_item_name, diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h index 782dbf22e1..37e8831f6b 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -31,6 +31,7 @@ enum AVHWDeviceType { AV_HWDEVICE_TYPE_DXVA2, AV_HWDEVICE_TYPE_QSV, AV_HWDEVICE_TYPE_VIDEOTOOLBOX, + AV_HWDEVICE_TYPE_NONE, }; typedef struct AVHWDeviceInternal AVHWDeviceInternal; @@ -224,6 +225,33 @@ typedef struct AVHWFramesContext { } AVHWFramesContext; /** + * Look up an AVHWDeviceType by name. + * + * @param name String name of the device type (case-insensitive). + * @return The type from enum AVHWDeviceType, or AV_HWDEVICE_TYPE_NONE if + * not found. + */ +enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name); + +/** Get the string name of an AVHWDeviceType. + * + * @param type Type from enum AVHWDeviceType. + * @return Pointer to a static string containing the name, or NULL if the type + * is not valid. + */ +const char *av_hwdevice_get_type_name(enum AVHWDeviceType type); + +/** + * Iterate over supported device types. + * + * @param type AV_HWDEVICE_TYPE_NONE initially, then the previous type + * returned by this function in subsequent iterations. + * @return The next usable device type from enum AVHWDeviceType, or + * AV_HWDEVICE_TYPE_NONE if there are no more. + */ +enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev); + +/** * Allocate an AVHWDeviceContext for a given hardware type. * * @param type the type of the hardware device to allocate. diff --git a/libavutil/version.h b/libavutil/version.h index dd8d2407da..322b683cf4 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -80,7 +80,7 @@ #define LIBAVUTIL_VERSION_MAJOR 55 -#define LIBAVUTIL_VERSION_MINOR 64 +#define LIBAVUTIL_VERSION_MINOR 65 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \