From patchwork Fri Nov 24 00:51:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 6305 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp1463816jah; Thu, 23 Nov 2017 16:51:48 -0800 (PST) X-Google-Smtp-Source: AGs4zMYun9AuebIrtCjyl4Dcp6sUooAHrRn3hOlhaYPllmwXz6ia6e5bIa5iqpoRhbM9cdP9nlzN X-Received: by 10.223.169.135 with SMTP id b7mr21697284wrd.171.1511484708083; Thu, 23 Nov 2017 16:51:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511484708; cv=none; d=google.com; s=arc-20160816; b=qDAyXOQen2LW3Iw5mF2QxjtsFtj6rJ7MLJmgDBmXt7vEqFcRbSwmyzQe5soaCm0Y89 LeNqJelDcrU8lmWoks8gXK05hCueTVOfgLttNE7UEpeu/RPa0hHNgJJWZHZeSIR22uFN rmNagTXKiz2YIgYG+ayhq0M95cA57NEz4mkRo5P4MdekMyYoTEFOC51nwC5n3N6Q4+Lp 8TX9OY3jhiXcKtXrBWgjIsov04Dd61ENYxoxACE6BUZX0etF1AFewYatGJj701tMsaUI Onx5NYNjgpNEV43QVycbT6qXK+R2A1ckeTnuW0uI3AOGC2y/H9KOvYMXsuQoqknvPz6/ 1oqA== 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:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=NmY1eGIIWdi9CQgeqtWp65jIFavAxfegT2zmgNEc1ek=; b=oIfZJ2ACSzL188Fy1wztoeFd1ZWikONXnvwoq7ANS8DN30X8AcQ/lJF1lHL/Gh2kks OjQW4zdmHq8fiVm3TgarHATIAaGIzF56WjJ6pUco+6/4hJ7r7o3OScMdzMJSkP0mTQYy JW0hUdwYx5T2evORVzpQhgoetUYQppsfRxQSyALT7/De04h03uM5agNSb9nsuel2KObE 8oUWPIJqhbAvlW3axEthyTWZJg0PrCAmFcoSn5X/k18oxyKB+mO3tIkWyGyp4jsrqvff RZm2EVon9wkPkGyhilHGvvNGvGvArPLe1kjzkDrqq8wun0L2gdvtxAkDlMGtLwaGZR3h tDKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=AIabIL+F; 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 k7si16458880wrg.112.2017.11.23.16.51.47; Thu, 23 Nov 2017 16:51:48 -0800 (PST) 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 header.s=20150623 header.b=AIabIL+F; 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 9853068A16A; Fri, 24 Nov 2017 02:51:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 06E71689FC9 for ; Fri, 24 Nov 2017 02:51:38 +0200 (EET) Received: by mail-wr0-f196.google.com with SMTP id 11so15592201wrb.6 for ; Thu, 23 Nov 2017 16:51:39 -0800 (PST) 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; bh=NzbdvTqZPbsI701bR7cFY+R/P1nI17Gq9cbtrdYbzhc=; b=AIabIL+F3+BXxewkFJMrXxXOSrseP2tHyQdFNvOfA0dI/fPwwAnfkrn8ISl41urclP aEzwNJV7zFWRH/qBuAq/u5JwM4Rg87CqwjoMj6EZbCrbOofMAce3s832RUIl8c0NS0Le 1oIfNQxh5eTYHwR8A3+0PzePKfOCl3lnhps7tnCUI9HWkNsZQJwRm5W8lf7AgOjmCYNL gX5a/zBf6Y2aawB/Oi9rDTMVWIfdhqNt+wVDkDgS+OaVhOl9MujKi3RjtmbbO1Cbp9hu DtoBPJIhSZihzSJXA13PGrTpJuVGlOFbNeHV0R/UHIzCzLwhT0UTAEpnA4QFfkbJ5mHu SBow== 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; bh=NzbdvTqZPbsI701bR7cFY+R/P1nI17Gq9cbtrdYbzhc=; b=TcYYtE8KQ0qK8vw41Wwdle6fjVuUYT5GNnNvv8yzXkgnkDrIis7OG0LzfibLuVgCuA inBMYOLqGd/oSk93uwk2YM+32XtxOPXaVkxtby+g39PLpRii763+uVeL+zidfHCqhT7P pkVauhdzYRWccllquacENRYshmHJl7w7HGCnYCId4C2AugriDnXp88cxDThyf9AuuRbk JWx4XQA9euZzt6ZCTvIYDCmm6/KRk9vQDplWabbfbrVOL8L++ZqagWI57uoGsiYTH1oM mIqP/5te6oEWoub7ToujyPT3ePOQQdnbUw5PjC1el2UyGvlz1rlntj86249je3B7C5kZ FYoQ== X-Gm-Message-State: AJaThX5wyTmYpX7GNu4j3wqil9wEk4a+DKG84Sx6/mw0AdwHpd47Y3Cn K0d9GanoQM/c1f2GtxjHQboZO1kK X-Received: by 10.223.156.201 with SMTP id h9mr16540463wre.143.1511484698494; Thu, 23 Nov 2017 16:51:38 -0800 (PST) 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 h7sm4489655wrb.35.2017.11.23.16.51.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Nov 2017 16:51:37 -0800 (PST) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Nov 2017 00:51:18 +0000 Message-Id: <20171124005134.5683-1-sw@jkqxz.net> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH 01/17] lavc: Add codec metadata to indicate hardware support 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" --- doc/APIchanges | 3 +++ libavcodec/avcodec.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ libavcodec/hwaccel.h | 18 +++++++++++++ libavcodec/utils.c | 12 +++++++++ 4 files changed, 107 insertions(+) diff --git a/doc/APIchanges b/doc/APIchanges index 45276f734c..704efe1719 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2017-10-21 API changes, most recent first: +2017-xx-xx - xxxxxxx - lavc 58.x+1.0 - avcodec.h + Add AVCodecHWConfig and avcodec_get_hw_config(). + 2017-11-xx - xxxxxxx - lavu 55.3.0 - opencl.h Remove experiental OpenCL API (av_opencl_*). diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 4cd72b5961..e2dc97d62f 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -36,6 +36,7 @@ #include "libavutil/channel_layout.h" #include "libavutil/dict.h" #include "libavutil/frame.h" +#include "libavutil/hwcontext.h" #include "libavutil/log.h" #include "libavutil/pixfmt.h" #include "libavutil/rational.h" @@ -3279,6 +3280,61 @@ typedef struct AVProfile { const char *name; ///< short name for the profile } AVProfile; +enum { + /** + * The codec supports this format via the hw_device_ctx interface. + * + * When selecting this format, AVCodecContext.hw_device_ctx should + * have been set to a device of the specified type before calling + * avcodec_open2(). + */ + AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX = 0x01, + /** + * The codec supports this format via the hw_frames_ctx interface. + * + * When selecting this format for a decoder, + * AVCodecContext.hw_frames_ctx should be set to a suitable frames + * context inside the get_format() callback. The frames context + * must have been created on a device of the specified type. + */ + AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX = 0x02, + /** + * The codec supports this format by some internal method. + * + * This format can be selected without any additional configuration - + * no device or frames context is required. + */ + AV_CODEC_HW_CONFIG_METHOD_INTERNAL = 0x04, + /** + * The codec supports this format by some ad-hoc method. + * + * Additional settings and/or function calls are required. See the + * codec-specific documentation for details. (Methods requiring + * this sort of configuration are deprecated and others should be + * used in preference.) + */ + AV_CODEC_HW_CONFIG_METHOD_AD_HOC = 0x08, +}; + +typedef struct AVCodecHWConfig { + /** + * A hardware pixel format which the codec can use. + */ + enum AVPixelFormat pix_fmt; + /** + * Bit set of AV_CODEC_HW_CONFIG_METHOD_* flags, describing the possible + * setup methods which can be used with this configuration. + */ + int methods; + /** + * The device type associated with the configuration. + * + * Must be set for AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX and + * AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, otherwise unused. + */ + enum AVHWDeviceType device_type; +} AVCodecHWConfig; + typedef struct AVCodecDefault AVCodecDefault; struct AVSubtitle; @@ -3404,6 +3460,15 @@ typedef struct AVCodec { * packets before decoding. */ const char *bsfs; + + /** + * Array of pointers to hardware configurations supported by the codec, + * or NULL if no hardware supported. The array is terminated by a NULL + * pointer. + * + * The user can only access this field via avcodec_get_hw_config(). + */ + const struct AVCodecHWConfigInternal **hw_configs; } AVCodec; #if FF_API_CODEC_GET_SET @@ -3414,6 +3479,15 @@ int av_codec_get_max_lowres(const AVCodec *codec); struct MpegEncContext; /** + * Retrieve supported hardware configurations for a codec. + * + * Values of index from zero to some maximum return the indexed configuration + * descriptor; all other values return NULL. If the codec does not support + * any hardware configurations then it will always return NULL. + */ +const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *codec, int index); + +/** * @defgroup lavc_hwaccel AVHWAccel * @{ */ diff --git a/libavcodec/hwaccel.h b/libavcodec/hwaccel.h index 124fbbf1fd..0198c7f858 100644 --- a/libavcodec/hwaccel.h +++ b/libavcodec/hwaccel.h @@ -19,6 +19,24 @@ #ifndef AVCODEC_HWACCEL_H #define AVCODEC_HWACCEL_H +#include "avcodec.h" + + #define HWACCEL_CAP_ASYNC_SAFE (1 << 0) + +typedef struct AVCodecHWConfigInternal { + /** + * This is the structure which will be returned to the user by + * avcodec_get_hw_config(). + */ + AVCodecHWConfig public; + /** + * If this configuration uses a hwaccel, a pointer to it. + * If not, NULL. + */ + const AVHWAccel *hwaccel; +} AVCodecHWConfigInternal; + + #endif /* AVCODEC_HWACCEL_H */ diff --git a/libavcodec/utils.c b/libavcodec/utils.c index e50de6e89b..01bf7556f7 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -45,6 +45,7 @@ #include "libavutil/thread.h" #include "avcodec.h" #include "decode.h" +#include "hwaccel.h" #include "libavutil/opt.h" #include "me_cmp.h" #include "mpegvideo.h" @@ -1885,6 +1886,17 @@ int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b) return i; } +const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *codec, int index) +{ + int i; + if (!codec->hw_configs || index < 0) + return NULL; + for (i = 0; i < index; i++) + if (!codec->hw_configs[i]) + return NULL; + return &codec->hw_configs[index]->public; +} + static AVHWAccel *first_hwaccel = NULL; static AVHWAccel **last_hwaccel = &first_hwaccel;