From patchwork Sat Jul 11 08:07:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hanishkvc X-Patchwork-Id: 20957 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id D48AE44BBE6 for ; Sat, 11 Jul 2020 11:13:50 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AA37E6880F7; Sat, 11 Jul 2020 11:13:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f195.google.com (mail-oi1-f195.google.com [209.85.167.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EBC64680B4C for ; Sat, 11 Jul 2020 11:13:43 +0300 (EEST) Received: by mail-oi1-f195.google.com with SMTP id e4so6831418oib.1 for ; Sat, 11 Jul 2020 01:13:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=spbvjp1RgyA4/7Z76L8bkCHA3C7wKsqzM/1MUyVL54k=; b=OQUM9oX40Up+HFSdkYA62JOd4tzLmKIncSSxb4LYfDxgfeGvGMH+hGHksUGLDlWp5k /kraRnGxFM5oJcImvMoGtEAxxlL4YaaPbHglpQBOHwIKIbDtUMJxKn6GxNSH714i1wJI KMIWkgGJXAGDvAP1WhqLf8KPbsXIyklTxz37VggNvn8oH3OBzbwn15jmNuJMWE3Bz9lI 8fXFh54XCBu8NgT+t/gj6oRSg8LEF4raglO9ORwGcNnlAO2M7tXTA5Egv0jquN9uzEIm F1T6E8xkVdo0F1A/3Voycv0iPMVM74JXuBz47nGzFPccaPSOG2rTJ3+HXTQxaU1Ie0Yq K8SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=spbvjp1RgyA4/7Z76L8bkCHA3C7wKsqzM/1MUyVL54k=; b=XGFDtKwJX8ASPvrHDLMXxsNIWamaaP2CoL7zlRbr+9S93+Sgxmmd0uWGR6O4OH/Qw4 gN093u39Udvozc2qtAQ2l5sB7JwzsuUsriVYZNeW3mz+guxsLN+81gj9ebKINOfMo3/N tfGOIBjBi7WONOMdy8ANEAQ2LdOJSIyIFAZEuSqzPy3QNNblLG0qhts3Go5LFo7gbaqc uoBmjU1dPuZ4UVFDh11iy59Ygb2ZXRFyPqTmgDHCCfLCZZrbnHlSVjwhSqeaeejjmL0a SAq58QaiNjHYkXpCooCQTxEo15rwY4JYb9/fC87FpjpIDOmJofSwPDChMdvke0YnmUga EYAQ== X-Gm-Message-State: AOAM531s32MIR1fizRkNvrZ/RKt9A7l5TTofxLbujBqOAJKEwdkmlCRP BMQu4DyEw9Gp84DxEI/j1B4ln3HF X-Google-Smtp-Source: ABdhPJyL7XctaeuMx8pK2p7dhX/vWyP/igtP61enrlT2V9zKixJ+PsCy3EdYlt5FXsiT9cUBE+B4Kg== X-Received: by 2002:a17:90a:de94:: with SMTP id n20mr9845029pjv.125.1594454877824; Sat, 11 Jul 2020 01:07:57 -0700 (PDT) Received: from localhost.localdomain ([122.171.57.136]) by smtp.gmail.com with ESMTPSA id o18sm9298545pfu.138.2020.07.11.01.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jul 2020 01:07:57 -0700 (PDT) From: hanishkvc To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 Jul 2020 13:37:04 +0530 Message-Id: <20200711080704.109581-1-hanishkvc@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v08 1/3] KMSGrab: getfb2 format_modifier if user doesnt specify 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 Cc: hanishkvc Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" If user doesnt specify a format_modifier explicitly, then use GetFB2 to identify the format_modifier of the framebuffer being grabbed. This is supported on newer linux builds, where xf86drmMode.h has added support for GetFB2. --- Changelog | 1 + configure | 5 +++++ libavdevice/kmsgrab.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 1bb9931c0d..ac3f1cf208 100644 --- a/Changelog +++ b/Changelog @@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest within each release, releases are sorted from youngest to oldest. version : +- kmsgrab GetFB2 format_modifier, if user doesnt specify - AudioToolbox output device - MacCaption demuxer - PGX decoder diff --git a/configure b/configure index bdfd731602..3bbc51053c 100755 --- a/configure +++ b/configure @@ -2325,6 +2325,7 @@ HAVE_LIST=" $TYPES_LIST makeinfo makeinfo_html + drm_getfb2 opencl_d3d11 opencl_drm_arm opencl_drm_beignet @@ -6653,6 +6654,10 @@ if enabled vaapi; then check_type "va/va.h va/va_enc_vp9.h" "VAEncPictureParameterBufferVP9" fi +if enabled libdrm; then + check_pkg_config drm_getfb2 libdrm "xf86drm.h xf86drmMode.h" drmModeGetFB2 +fi + if enabled_all opencl libdrm ; then check_type "CL/cl_intel.h" "clCreateImageFromFdINTEL_fn" && enable opencl_drm_beignet diff --git a/libavdevice/kmsgrab.c b/libavdevice/kmsgrab.c index d0de774871..c7fa2343e3 100644 --- a/libavdevice/kmsgrab.c +++ b/libavdevice/kmsgrab.c @@ -239,6 +239,9 @@ static av_cold int kmsgrab_read_header(AVFormatContext *avctx) drmModePlaneRes *plane_res = NULL; drmModePlane *plane = NULL; drmModeFB *fb = NULL; +#if HAVE_DRM_GETFB2 + drmModeFB2 *fb2 = NULL; +#endif AVStream *stream; int err, i; @@ -364,6 +367,28 @@ static av_cold int kmsgrab_read_header(AVFormatContext *avctx) goto fail; } +#if HAVE_DRM_GETFB2 + fb2 = drmModeGetFB2(ctx->hwctx->fd, plane->fb_id); + if (!fb2) { + err = errno; + av_log(avctx, AV_LOG_ERROR, "Failed to get " + "framebuffer2 %"PRIu32": %s.\n", + plane->fb_id, strerror(err)); + err = AVERROR(err); + goto fail; + } + + av_log(avctx, AV_LOG_INFO, "Template framebuffer2 is %"PRIu32": " + "%"PRIu32"x%"PRIu32", pixel_format: 0x%"PRIx32", format_modifier: 0x%"PRIx64".\n", + fb2->fb_id, fb2->width, fb2->height, fb2->pixel_format, fb2->modifier); + + if (ctx->drm_format_modifier == DRM_FORMAT_MOD_INVALID) + ctx->drm_format_modifier = fb2->modifier; +#else + if (ctx->drm_format_modifier == DRM_FORMAT_MOD_INVALID) + ctx->drm_format_modifier = DRM_FORMAT_MOD_NONE; +#endif + stream = avformat_new_stream(avctx, NULL); if (!stream) { err = AVERROR(ENOMEM); @@ -408,6 +433,10 @@ fail: drmModeFreePlane(plane); if (fb) drmModeFreeFB(fb); +#if HAVE_DRM_GETFB2 + if (fb2) + drmModeFreeFB2(fb2); +#endif return err; } @@ -433,7 +462,7 @@ static const AVOption options[] = { { .i64 = AV_PIX_FMT_BGR0 }, 0, UINT32_MAX, FLAGS }, { "format_modifier", "DRM format modifier for framebuffer", OFFSET(drm_format_modifier), AV_OPT_TYPE_INT64, - { .i64 = DRM_FORMAT_MOD_NONE }, 0, INT64_MAX, FLAGS }, + { .i64 = DRM_FORMAT_MOD_INVALID}, 0, INT64_MAX, FLAGS }, { "crtc_id", "CRTC ID to define capture source", OFFSET(source_crtc), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, UINT32_MAX, FLAGS }, From patchwork Sat Jul 11 07:52:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hanishkvc X-Patchwork-Id: 20954 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6AA6244A6CB for ; Sat, 11 Jul 2020 10:54:13 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2CAF86880DC; Sat, 11 Jul 2020 10:54:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A9E0E68807D for ; Sat, 11 Jul 2020 10:54:06 +0300 (EEST) Received: by mail-pl1-f182.google.com with SMTP id 72so3195253ple.0 for ; Sat, 11 Jul 2020 00:54:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=62eDwALf+4WeXgbHTRCbInejubHbD6KbRHMxQxDkFb8=; b=qiku5WQ7TXrifoXLwsoyDbbKVA/EfGWh4f26HUx+xJp8bZWuRX+lYzRlirNR6CXtKM kgWjgROZJDnPJjC6bwirbMCdtwNY7qpYPazcxTvpLl/mtzW3iAfiRvzJMIE0yn2uU9KQ 4GCOweOuLBxj4v1F8vQ5H+LUO33pKQocRlWzmRFPZo4CYXR/mhbzOH+mbByEinrVH6PJ C3//qW0rjLrPtxC3Zf86S4NW1meJ7Zg7G98qNmacHke37/1lCkhQahifOf26A1mQyY+e 9X5pTMxPZLXwEV/YJ7h6IP1gOIBVsFT7zGOpTqgKtaF1aXXAS0B6lQ1wJI8GHs6S9F7F wn8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=62eDwALf+4WeXgbHTRCbInejubHbD6KbRHMxQxDkFb8=; b=PuKNy89/kMvksg3bOI5CO06ydXtn0r6HMR/j09ZMTZS1vh4GNow6G7sqCa5iipZA7a yxvQMIbMEURGU3UmD5RuuZ/GKK5aRKqTmXs9VdPXRUPGnIX8ksXgB024GCiI/O58mo4k fSm13/+seSOAppMkEkf8zJuKtUikhXrnA9Yy+Lew/4a1L+ZO99lysY3jHWG9QXe/JqgH jaVcQ9fdLFjJjlNXApRjUx+sVjGM6191uGVxxv1v9WCztKaYoW6GtQKkj4cT6vZFGIrD Tmt99FbEYhNsUArnZzT5CV7Nr8HOlNEO0/leIgX+V3Usg0n/5th8zJJCh6nZNqE7d+UD uW2A== X-Gm-Message-State: AOAM531X/PQLxN+q4o7YEVFhRm/Pbzv8kWVug35QgqYOs8S+5I0kC/fT JMSB8PS9SPPOB4I/6GS2PbmMJxck X-Google-Smtp-Source: ABdhPJyqNZWlo94FuvjnNqXaMy8gsx2E+gMFAmPglWSLqGy1vxz8MhDubaj+Pxay+LxneiMxXWgtiQ== X-Received: by 2002:a17:90b:142:: with SMTP id em2mr9176503pjb.236.1594454043565; Sat, 11 Jul 2020 00:54:03 -0700 (PDT) Received: from localhost.localdomain ([122.171.57.136]) by smtp.gmail.com with ESMTPSA id i66sm7916339pfc.12.2020.07.11.00.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jul 2020 00:54:02 -0700 (PDT) From: hanishkvc To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 Jul 2020 13:22:38 +0530 Message-Id: <20200711075239.109277-3-hanishkvc@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200711075239.109277-1-hanishkvc@gmail.com> References: <20200711075239.109277-1-hanishkvc@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v08 2/3] fbtile tile/detile, hwcontext_drm detile NonLinear 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 Cc: hanishkvc Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" ** fbtile cpu based framebuffer tile/detile helpers Add helper routines which can be used to tile/detile framebuffer layouts between linear and specified tile layout, using the cpu. Currently it supports Legacy Intel Tile-X, Legacy Intel Tile-Y and Newer Intel Tile-Yf tiled layouts. Currently supported pixel format is 32bit RGB. It also contains fbtile_generic logic, which can be easily configured to support different kinds of tiling layouts, at the expense of some additional processing cycles, compared to developing custom (de)tiling logic. One requires to provide the tile walking parameters for the new tile layout to be supported. Once it is done, both tiling and detiling of the new tile layout can be handled automatically. This is non-public by default. ** hwcontext_drm detile non linear layout, if possible If the framebuffer is a tiled layout, use the fbtile helper routines to try and detile it into linear layout, if supported by fbtile. It uses the format_modifier associated with the framebuffer to decide whether to apply detiling or not and inturn which specific detiling to apply. If user is using kmsgrab, they will have to use -format_modifer option of kmsgrab to force a specific detile logic, in case they dont want to use the original format_modifier related detiling. Or they could even use -format_modifier 0 to make hwcontext_drm bypass this detiling. --- Changelog | 2 + libavutil/Makefile | 2 + libavutil/fbtile.c | 434 ++++++++++++++++++++++++++++++++++++++ libavutil/fbtile.h | 255 ++++++++++++++++++++++ libavutil/hwcontext_drm.c | 36 +++- 5 files changed, 728 insertions(+), 1 deletion(-) create mode 100644 libavutil/fbtile.c create mode 100644 libavutil/fbtile.h diff --git a/Changelog b/Changelog index ac3f1cf208..c25a28a428 100644 --- a/Changelog +++ b/Changelog @@ -2,6 +2,8 @@ Entries are sorted chronologically from oldest to youngest within each release, releases are sorted from youngest to oldest. version : +- hwcontext_drm detiles non linear layouts, if possible +- fbtile cpu based framebuffer tile/detile helpers - kmsgrab GetFB2 format_modifier, if user doesnt specify - AudioToolbox output device - MacCaption demuxer diff --git a/libavutil/Makefile b/libavutil/Makefile index 9b08372eb2..9b58ac5980 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -84,6 +84,7 @@ HEADERS = adler32.h \ xtea.h \ tea.h \ tx.h \ + fbtile.h \ HEADERS-$(CONFIG_LZO) += lzo.h @@ -169,6 +170,7 @@ OBJS = adler32.o \ tx_float.o \ tx_double.o \ tx_int32.o \ + fbtile.o \ video_enc_params.o \ diff --git a/libavutil/fbtile.c b/libavutil/fbtile.c new file mode 100644 index 0000000000..921e5de805 --- /dev/null +++ b/libavutil/fbtile.c @@ -0,0 +1,434 @@ +/* + * CPU based Framebuffer Generic Tile DeTile logic + * Copyright (c) 2020 C Hanish Menon + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "avutil.h" +#include "common.h" +#include "fbtile.h" +#if CONFIG_LIBDRM +#include +#endif + + +SCOPEIN enum FBTileLayout fbtilelayoutid_from_drmformatmodifier(uint64_t formatModifier) +{ + enum FBTileLayout layout = FBTILE_UNKNOWN; + +#if CONFIG_LIBDRM + switch(formatModifier) { + case DRM_FORMAT_MOD_LINEAR: + layout = FBTILE_NONE; + break; + case I915_FORMAT_MOD_X_TILED: + layout = FBTILE_INTEL_XGEN9; + break; + case I915_FORMAT_MOD_Y_TILED: + layout = FBTILE_INTEL_YGEN9; + break; + case I915_FORMAT_MOD_Yf_TILED: + layout = FBTILE_INTEL_YF; + break; + default: + layout = FBTILE_UNKNOWN; + break; + } +#endif +#ifdef DEBUG_FBTILE_FORMATMODIFIER_MAPPING + av_log(NULL, AV_LOG_DEBUG, "fbtile:drmformatmodifier[%lx] mapped to layout[%d]\n", formatModifier, layout); +#endif + return layout; +} + + +/** + * Supported pixel formats + * Currently only RGB based 32bit formats are specified + * TODO: Technically the logic is transparent to 16bit RGB formats also to a great extent + */ +SCOPEIN const enum AVPixelFormat fbtilePixFormats[] = { + AV_PIX_FMT_RGB0, AV_PIX_FMT_0RGB, AV_PIX_FMT_BGR0, AV_PIX_FMT_0BGR, + AV_PIX_FMT_RGBA, AV_PIX_FMT_ARGB, AV_PIX_FMT_BGRA, AV_PIX_FMT_ABGR, + AV_PIX_FMT_NONE}; + +SCOPEIN int fbtile_checkpixformats(const enum AVPixelFormat srcPixFormat, const enum AVPixelFormat dstPixFormat) +{ + int errSrc = 1; + int errDst = 1; + for (int i = 0; fbtilePixFormats[i] != AV_PIX_FMT_NONE; i++) { + if (fbtilePixFormats[i] == srcPixFormat) + errSrc = 0; + if (fbtilePixFormats[i] == dstPixFormat) + errDst = 0; + } + return (errSrc | errDst); +} + + +/* + * Generic tile/detile logic + * The tile layout data is assumed to be tightly packed, with no gaps inbetween. + * However the logic does try to accomodate a src/dst linear layout memory, + * where there is possibly some additional bytes beyond the width in each line + * of pixel data. + */ + +/** + * Settings for Intel Tile-Yf framebuffer layout. + * May need to swap the 4 pixel wide subtile, have to check doc bit more + */ +SCOPEIN struct FBTileWalk tyfTileWalk = { + .bytesPerPixel = 4, + .subTileWidth = 4, .subTileHeight = 8, + .tileWidth = 32, .tileHeight = 32, + .numDirChanges = 6, + .dirChanges = { {8, 4, 0}, {16, -4, 8}, {32, 4, -8}, {64, -12, 8}, {128, 4, -24}, {256, 4, -24} } + }; + +/** + * Setting for Intel Tile-X framebuffer layout + */ +SCOPEIN struct FBTileWalk txTileWalk = { + .bytesPerPixel = 4, + .subTileWidth = 128, .subTileHeight = 8, + .tileWidth = 128, .tileHeight = 8, + .numDirChanges = 1, + .dirChanges = { {8, 128, 0} } + }; + +/** + * Setting for Intel Tile-Y framebuffer layout + * Even thou a simple generic detiling logic doesnt require the + * dummy 256 posOffset entry. The pseudo parallel detiling based + * opti logic requires to know about the Tile boundry. + */ +SCOPEIN struct FBTileWalk tyTileWalk = { + .bytesPerPixel = 4, + .subTileWidth = 4, .subTileHeight = 32, + .tileWidth = 32, .tileHeight = 32, + .numDirChanges = 2, + .dirChanges = { {32, 4, 0}, {256, 4, 0} } + }; + + +/** + * _fbtile_generic_simple tile/detile layout + */ +static int _fbtile_generic_simple(enum FBTileOps op, + const int w, const int h, + uint8_t *dst, const int dstLineSize, + uint8_t *src, const int srcLineSize, + const int bytesPerPixel, + const int subTileWidth, const int subTileHeight, + const int tileWidth, const int tileHeight, + const int numDirChanges, const struct FBTWDirChange *dirChanges) +{ + int tO, lO; + int lX, lY; + int cSTL, nSTLines; + uint8_t *tld, *lin; + int tldLineSize, linLineSize; + const int subTileWidthBytes = subTileWidth*bytesPerPixel; + + if (op == FBTILEOPS_TILE) { + lin = src; + linLineSize = srcLineSize; + tld = dst; + tldLineSize = dstLineSize; + } else { + tld = src; + tldLineSize = srcLineSize; + lin = dst; + linLineSize = dstLineSize; + } + + // To keep things sane and simple tile layout is assumed to be tightly packed, + // so below check is a indirect logical assumption, even thou tldLineSize is not directly mappable at one level + if (w*bytesPerPixel != tldLineSize) { + av_log(NULL, AV_LOG_ERROR, "fbtile:genericsimp: w%dxh%d, dL%d, sL%d\n", w, h, tldLineSize, linLineSize); + av_log(NULL, AV_LOG_ERROR, "fbtile:genericsimp: dont support tldLineSize | Pitch going beyond width\n"); + return FBT_ERR; + } + tO = 0; + lX = 0; + lY = 0; + nSTLines = (w*h)/subTileWidth; // numSubTileLines + cSTL = 0; // curSubTileLine + while (cSTL < nSTLines) { + lO = lY*linLineSize + lX*bytesPerPixel; +#ifdef DEBUG_FBTILE + av_log(NULL, AV_LOG_DEBUG, "fbtile:genericsimp: lX%d lY%d; lO%d, tO%d; %d/%d\n", lX, lY, lO, tO, cSTL, nSTLines); +#endif + + for (int k = 0; k < subTileHeight; k++) { + if (op == FBTILEOPS_TILE) { + memcpy(tld+tO+k*subTileWidthBytes, lin+lO+k*linLineSize, subTileWidthBytes); + } else { + memcpy(lin+lO+k*linLineSize, tld+tO+k*subTileWidthBytes, subTileWidthBytes); + } + } + tO = tO + subTileHeight*subTileWidthBytes; + + cSTL += subTileHeight; + for (int i=numDirChanges-1; i>=0; i--) { + if ((cSTL%dirChanges[i].posOffset) == 0) { + lX += dirChanges[i].xDelta; + lY += dirChanges[i].yDelta; + break; + } + } + if (lX >= w) { + lX = 0; + lY += tileHeight; + } + } + return FBT_OK; +} + + +SCOPEIN int fbtile_generic_simple(enum FBTileOps op, + const int w, const int h, + uint8_t *dst, const int dstLineSize, + uint8_t *src, const int srcLineSize, + const struct FBTileWalk *tw) +{ + return _fbtile_generic_simple(op, w, h, + dst, dstLineSize, src, srcLineSize, + tw->bytesPerPixel, + tw->subTileWidth, tw->subTileHeight, + tw->tileWidth, tw->tileHeight, + tw->numDirChanges, tw->dirChanges); +} + + +static int _fbtile_generic_opti(enum FBTileOps op, + const int w, const int h, + uint8_t *dst, const int dstLineSize, + uint8_t *src, const int srcLineSize, + const int bytesPerPixel, + const int subTileWidth, const int subTileHeight, + const int tileWidth, const int tileHeight, + const int numDirChanges, const struct FBTWDirChange *dirChanges) +{ + int tO, lO, tOPrev; + int lX, lY; + int cSTL, nSTLines; + int curTileInRow, nTilesInARow; + uint8_t *tld, *lin; + int tldLineSize, linLineSize; + const int subTileWidthBytes = subTileWidth*bytesPerPixel; + int parallel = 1; + + if (op == FBTILEOPS_TILE) { + lin = src; + linLineSize = srcLineSize; + tld = dst; + tldLineSize = dstLineSize; + } else { + tld = src; + tldLineSize = srcLineSize; + lin = dst; + linLineSize = dstLineSize; + } + + if (w*bytesPerPixel != tldLineSize) { + av_log(NULL, AV_LOG_ERROR, "fbtile:genericopti: w%dxh%d, dL%d, sL%d\n", w, h, linLineSize, tldLineSize); + av_log(NULL, AV_LOG_ERROR, "fbtile:genericopti: dont support tldLineSize | Pitch going beyond width\n"); + return FBT_ERR; + } + if (w%tileWidth != 0) { + av_log(NULL, AV_LOG_ERROR, "fbtile:genericopti:NotSupported:Width being non-mult Of TileWidth: width%d, tileWidth%d\n", w, tileWidth); + return FBT_ERR; + } + tO = 0; + tOPrev = 0; + lX = 0; + lY = 0; + nTilesInARow = w/tileWidth; + for (parallel=8; parallel>0; parallel--) { + if (nTilesInARow%parallel == 0) + break; + } + nSTLines = (w*h)/subTileWidth; // numSubTileLines + cSTL = 0; // curSubTileLine + curTileInRow = 0; + while (cSTL < nSTLines) { + lO = lY*linLineSize + lX*bytesPerPixel; +#ifdef DEBUG_FBTILE + av_log(NULL, AV_LOG_DEBUG, "fbtile:genericopti: lX%d lY%d; tO%d, lO%d; %d/%d\n", lX, lY, tO, lO, cSTL, nSTLines); +#endif + + // As most tiling layouts have a minimum subtile of 4x4, if I remember correctly, + // so this loop can be unrolled to be multiples of 4, and speed up a bit. + // However tiling involving 3x3 or 2x2 wont be handlable. In which one will have to use + // NON UnRolled version or fbtile_generic_simple for such tile layouts. + // (De)tile parallely to a limited extent. Gain some speed by allowing reuse of calcs and parallelism, + // but still avoid any cache set-associativity and or limited cache based thrashing. Keep it spatially + // and inturn temporaly small at one level. + if (op == FBTILEOPS_DETILE) { +#ifdef FBTILER_OPTI_UNROLL + for (int k = 0; k < subTileHeight; k+=4) { +#else + for (int k = 0; k < subTileHeight; k+=1) { +#endif + for (int p = 0; p < parallel; p++) { + int pTldOffset = p*tileWidth*tileHeight*bytesPerPixel; + int pLinOffset = p*tileWidth*bytesPerPixel; + memcpy(lin+lO+(k+0)*linLineSize+pLinOffset, tld+tO+(k+0)*subTileWidthBytes+pTldOffset, subTileWidthBytes); +#ifdef FBTILER_OPTI_UNROLL + memcpy(lin+lO+(k+1)*linLineSize+pLinOffset, tld+tO+(k+1)*subTileWidthBytes+pTldOffset, subTileWidthBytes); + memcpy(lin+lO+(k+2)*linLineSize+pLinOffset, tld+tO+(k+2)*subTileWidthBytes+pTldOffset, subTileWidthBytes); + memcpy(lin+lO+(k+3)*linLineSize+pLinOffset, tld+tO+(k+3)*subTileWidthBytes+pTldOffset, subTileWidthBytes); +#endif + } + } + } else { +#ifdef FBTILER_OPTI_UNROLL + for (int k = 0; k < subTileHeight; k+=4) { +#else + for (int k = 0; k < subTileHeight; k+=1) { +#endif + for (int p = 0; p < parallel; p++) { + int pTldOffset = p*tileWidth*tileHeight*bytesPerPixel; + int pLinOffset = p*tileWidth*bytesPerPixel; + memcpy(tld+tO+(k+0)*subTileWidthBytes+pTldOffset, lin+lO+(k+0)*linLineSize+pLinOffset, subTileWidthBytes); +#ifdef FBTILER_OPTI_UNROLL + memcpy(tld+tO+(k+1)*subTileWidthBytes+pTldOffset, lin+lO+(k+1)*linLineSize+pLinOffset, subTileWidthBytes); + memcpy(tld+tO+(k+2)*subTileWidthBytes+pTldOffset, lin+lO+(k+2)*linLineSize+pLinOffset, subTileWidthBytes); + memcpy(tld+tO+(k+3)*subTileWidthBytes+pTldOffset, lin+lO+(k+3)*linLineSize+pLinOffset, subTileWidthBytes); +#endif + } + } + } + + tO = tO + subTileHeight*subTileWidthBytes; + cSTL += subTileHeight; + + for (int i=numDirChanges-1; i>=0; i--) { + if ((cSTL%dirChanges[i].posOffset) == 0) { + if (i == numDirChanges-1) { + curTileInRow += parallel; + lX = curTileInRow*tileWidth; + tO = tOPrev + tileWidth*tileHeight*bytesPerPixel*(parallel); + tOPrev = tO; + } else { + lX += dirChanges[i].xDelta; + } + lY += dirChanges[i].yDelta; + break; + } + } + if (lX >= w) { + lX = 0; + curTileInRow = 0; + lY += tileHeight; + if (lY >= h) { + break; + } + } + } + return FBT_OK; +} + + +SCOPEIN int fbtile_generic_opti(enum FBTileOps op, + const int w, const int h, + uint8_t *dst, const int dstLineSize, + uint8_t *src, const int srcLineSize, + const struct FBTileWalk *tw) +{ + return _fbtile_generic_opti(op, w, h, + dst, dstLineSize, src, srcLineSize, + tw->bytesPerPixel, + tw->subTileWidth, tw->subTileHeight, + tw->tileWidth, tw->tileHeight, + tw->numDirChanges, tw->dirChanges); +} + + +SCOPEIN int fbtile_conv(enum FBTileOps op, enum FBTileLayout layout, + int w, int h, + uint8_t *dst, int dstLineSize, + uint8_t *src, int srcLineSize, + int bytesPerPixel) +{ + static int logStateNone = 0; + static int logStateUnknown = 0; + + switch(layout) { + case FBTILE_NONE: + av_log_once(NULL, AV_LOG_WARNING, AV_LOG_VERBOSE, &logStateNone, "fbtile:conv:FBTILE_NONE: not (de)tiling\n"); + return FBT_ERR; + case FBTILE_INTEL_XGEN9: + return fbtile_generic(op, w, h, dst, dstLineSize, src, srcLineSize, &txTileWalk); + case FBTILE_INTEL_YGEN9: + return fbtile_generic(op, w, h, dst, dstLineSize, src, srcLineSize, &tyTileWalk); + case FBTILE_INTEL_YF: + return fbtile_generic(op, w, h, dst, dstLineSize, src, srcLineSize, &tyfTileWalk); + default: + av_log_once(NULL, AV_LOG_WARNING, AV_LOG_VERBOSE, &logStateUnknown, "fbtile:conv: unknown layout [%d] specified, not (de)tiling\n", layout); + return FBT_ERR; + } +} + + +/* + * Copy one AVFrame into the other, tiling or detiling as required, if possible. + * NOTE: Either the Source or the Destination AVFrame (i.e one of them) should be linear. + * NOTE: If the tiling layout is not understood, it will do a simple copy. + */ +SCOPEIN int fbtile_frame_copy(AVFrame *dst, enum FBTileLayout dstTileLayout, AVFrame *src, enum FBTileLayout srcTileLayout, + enum FBTileFrameCopyStatus *status) +{ + int err; + + if (dstTileLayout == FBTILE_NONE) { // i.e DeTile + err = fbtile_checkpixformats(src->format, dst->format); + if (!err) { + err = fbtile_conv(FBTILEOPS_DETILE, srcTileLayout, + dst->width, dst->height, + dst->data[0], dst->linesize[0], + src->data[0], src->linesize[0], 4); + if (!err) { + *status = FBTILE_FRAMECOPY_TILECOPY; + return FBT_OK; + } + } + } else if (srcTileLayout == FBTILE_NONE) { // i.e Tile + err = fbtile_checkpixformats(src->format, dst->format); + if (!err) { + err = fbtile_conv(FBTILEOPS_TILE, dstTileLayout, + src->width, src->height, + dst->data[0], dst->linesize[0], + src->data[0], src->linesize[0], 4); + if (!err) { + *status = FBTILE_FRAMECOPY_TILECOPY; + return FBT_OK; + } + } + } else { + av_log(NULL, AV_LOG_WARNING, "fbtile:framecopy: both src [%d] and dst [%d] layouts cant be tiled\n", srcTileLayout, dstTileLayout); + } + *status = FBTILE_FRAMECOPY_COPYONLY; + return av_frame_copy(dst, src); +} + + +// vim: set expandtab sts=4: // diff --git a/libavutil/fbtile.h b/libavutil/fbtile.h new file mode 100644 index 0000000000..8ac06b6c05 --- /dev/null +++ b/libavutil/fbtile.h @@ -0,0 +1,255 @@ +/* + * CPU based Framebuffer Generic Tile DeTile logic + * Copyright (c) 2020 C Hanish Menon + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_FBTILE_H +#define AVUTIL_FBTILE_H + +#include +#include "libavutil/pixfmt.h" +#include "libavutil/frame.h" + +/** + * @file + * @brief CPU based Framebuffer tiler detiler + * @author C Hanish Menon + * @{ + */ + + +/** + * Set scope of this api to be either public or internal (non-public) + */ +// #define FBTILE_SCOPE_PUBLIC 1 +#ifdef FBTILE_SCOPE_PUBLIC +#define SCOPEIN +#else +#define SCOPEIN static +#endif + + +/** + * Set fbtile_generic to either simple or minimal optimised logic + */ +#define FBTILER_GENERIC_OPTI 1 +#ifdef FBTILER_GENERIC_OPTI +#define fbtile_generic fbtile_generic_opti +#else +#define fbtile_generic fbtile_generic_simple +#endif + + +// Enable printing of the tile walk +//#define DEBUG_FBTILE 1 + + +// Common return values +#define FBT_OK 0 +#define FBT_ERR 1 + +/** + * The FBTile related operations + */ +enum FBTileOps { + FBTILEOPS_NONE, + FBTILEOPS_TILE, + FBTILEOPS_DETILE, + FBTILEOPS_UNKNOWN +}; + + +/** + * The FBTile related Layouts + * This identifies the supported tile layouts + */ +enum FBTileLayout { + FBTILE_NONE, // This also corresponds to linear layout + FBTILE_INTEL_XGEN9, + FBTILE_INTEL_YGEN9, + FBTILE_INTEL_YF, + FBTILE_UNKNOWN, +}; + + +/** + * TileWalk Direction Change Entry + * Used to specify the tile walking of subtiles within a tile. + */ +struct FBTWDirChange { + int posOffset; + int xDelta; + int yDelta; +}; + + +/** + * TileWalk, Contains info required for a given tile walking. + * + * @field bytesPerPixel the bytes per pixel for the image + * @field subTileWidth the width of subtile within the tile, in pixels + * @field subTileHeight the height of subtile within the tile, in pixels + * @field tileWidth the width of the tile, in pixels + * @field tileHeight the height of the tile, in pixels + * @field numDirChanges the number of dir changes involved in tile walk + * @field dirChanges the array of dir changes for the tile walk required + */ +struct FBTileWalk { + int bytesPerPixel; + int subTileWidth, subTileHeight; + int tileWidth, tileHeight; + int numDirChanges; + struct FBTWDirChange dirChanges[]; +}; + + +/** + * FBTile FrameCopy additional status + */ +enum FBTileFrameCopyStatus { + FBTILE_FRAMECOPY_TILECOPY, + FBTILE_FRAMECOPY_COPYONLY +}; + + +#ifdef FBTILE_SCOPE_PUBLIC + + +/** + * Map from formatmodifier to fbtile's internal mode. + * + * @param formatModifier the format_modifier to map + * @return the fbtile's equivalent internal mode + */ +#undef DEBUG_FBTILE_FORMATMODIFIER_MAPPING +enum FBTileLayout fbtilelayoutid_from_drmformatmodifier(uint64_t formatModifier); + + +/** + * Supported pixel formats by the fbtile logics + */ +extern const enum AVPixelFormat fbtilePixFormats[]; +/** + * Check if the given pixel formats are supported by fbtile logic. + * + * @param srcPixFormat pixel format of source image + * @param dstPixFormat pixel format of destination image + * + * @return 0 if supported, 1 if not + */ +int fbtile_checkpixformats(const enum AVPixelFormat srcPixFormat, const enum AVPixelFormat dstPixFormat); + + +/** + * Generic Logic. + */ + + +/** + * Tile Walk parameters for Tile-X, Tile-Y, Tile-Yf + */ +extern struct FBTileWalk tyfTileWalk; +extern struct FBTileWalk txTileWalk; +extern struct FBTileWalk tyTileWalk; + + +/** + * Generic Logic to Tile/Detile between tiled and linear layout. + * + * @param op whether to tile or detile + * @param w width of the image + * @param h height of the image + * @param dst the destination image buffer + * @param dstLineSize the size of each row in dst image, in bytes + * @param src the source image buffer + * @param srcLineSize the size of each row in src image, in bytes + * @param tw the structure which contains the tile walk parameters + * + * @return 0 if detiled, 1 if not + */ + + +/** + * Generic tile/detile simple version. + */ +int fbtile_generic_simple(enum FBTileOps op, + const int w, const int h, + uint8_t *dst, const int dstLineSize, + uint8_t *src, const int srcLineSize, + const struct FBTileWalk *tw); + + +/** + * Generic tile/detile minimal optimised version. + */ +int fbtile_generic_opti(enum FBTileOps op, + const int w, const int h, + uint8_t *dst, const int dstLineSize, + uint8_t *src, const int srcLineSize, + const struct FBTileWalk *tw); + + +/** + * tile/detile demuxer. + * + * @param op todo tiling or todo detiling + * @param layout specify the tile layout of dst/src framebuffer involved + * @param w width of the image + * @param h height of the image + * @param dst the destination image buffer + * @param dstLineSize the size of each row in dst image, in bytes + * @param src the source image buffer + * @param srcLineSize the size of each row in src image, in bytes + * @param bytesPerPixel the bytes per pixel for the image + * + * @return 0 if detiled, 1 if not + */ +int fbtile_conv(enum FBTileOps op, enum FBTileLayout layout, + int w, int h, + uint8_t *dst, int dstLineSize, + uint8_t *src, int srcLineSize, + int bytesPerPixel); + + +/** + * Copy one AVFrame into the other, tiling or detiling as required, if possible. + * NOTE: Either the Source or the Destination AVFrame (i.e one of them) should be linear. + * NOTE: If the tiling layout is not understood, it will do a simple copy. + * + * @param dst the destination avframe + * @param dstTileLayout the framebuffer tiling layout expected for the destination avframe + * @param src the source avframe + * @param srcTileLayout the framebuffer tiling layout of the source avframe + * + * @return 0 if copied. + */ +int fbtile_frame_copy(AVFrame *dst, enum FBTileLayout dstTileLayout, + AVFrame *src, enum FBTileLayout srcTileLayout, + enum FBTileFrameCopyStatus *status); + + +#endif // FBTILE_SCOPE_PUBLIC + + +/** + * @} + */ + +#endif /* AVUTIL_FBTILE_H */ +// vim: set expandtab sts=4: // diff --git a/libavutil/hwcontext_drm.c b/libavutil/hwcontext_drm.c index 32cbde82eb..60058e0f08 100644 --- a/libavutil/hwcontext_drm.c +++ b/libavutil/hwcontext_drm.c @@ -21,6 +21,7 @@ #include #include +#include #include #include "avassert.h" @@ -28,6 +29,10 @@ #include "hwcontext_drm.h" #include "hwcontext_internal.h" #include "imgutils.h" +#include "fbtile.h" +#ifndef FBTILE_SCOPE_PUBLIC +#include "libavutil/fbtile.c" +#endif static void drm_device_free(AVHWDeviceContext *hwdev) @@ -185,6 +190,35 @@ static int drm_transfer_get_formats(AVHWFramesContext *ctx, return 0; } +// Can be overridden during compiling, if required. +#ifndef HWCTXDRM_SYNCRELATED_FORMATMODIFIER +#define HWCTXDRM_SYNCRELATED_FORMATMODIFIER 1 +#endif +static int drm_transfer_with_detile(const AVFrame *hwAVFrame, AVFrame *dst, const AVFrame *src) +{ + int err; + uint64_t formatModifier; + enum FBTileLayout srcFBTileLayout, dstFBTileLayout; + enum FBTileFrameCopyStatus status; + AVDRMFrameDescriptor *drmFrame = NULL; + + srcFBTileLayout = FBTILE_NONE; + dstFBTileLayout = FBTILE_NONE; + if (hwAVFrame->format == AV_PIX_FMT_DRM_PRIME) { + drmFrame = (AVDRMFrameDescriptor*)hwAVFrame->data[0]; + formatModifier = drmFrame->objects[0].format_modifier; + srcFBTileLayout = fbtilelayoutid_from_drmformatmodifier(formatModifier); + } + err = fbtile_frame_copy(dst, dstFBTileLayout, src, srcFBTileLayout, &status); +#if HWCTXDRM_SYNCRELATED_FORMATMODIFIER + if (!err && (status == FBTILE_FRAMECOPY_TILECOPY)) { + if (drmFrame != NULL) + drmFrame->objects[0].format_modifier = DRM_FORMAT_MOD_LINEAR; + } +#endif + return err; +} + static int drm_transfer_data_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src) { @@ -206,7 +240,7 @@ static int drm_transfer_data_from(AVHWFramesContext *hwfc, map->width = dst->width; map->height = dst->height; - err = av_frame_copy(dst, map); + err = drm_transfer_with_detile(src, dst, map); if (err) goto fail; From patchwork Sat Jul 11 07:52:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hanishkvc X-Patchwork-Id: 20955 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3B5F944A6CB for ; Sat, 11 Jul 2020 10:54:19 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 27738688173; Sat, 11 Jul 2020 10:54:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6DB846880EC for ; Sat, 11 Jul 2020 10:54:12 +0300 (EEST) Received: by mail-pl1-f172.google.com with SMTP id m16so1986425pls.5 for ; Sat, 11 Jul 2020 00:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bfuAgNyb80o/k44Br8ArAtDjYyFS4d9rngl4b9J45UI=; b=vSxn+Wy37qkYBiLuUUrRvN1YvJz50S8Ccq2yBDgdc+7BQbNk3hkBrUMLs/ra2XwoyV WDLLcvuNMLmeNcZmkKHSKFjIP1e+WiUxOszwBLgsaDOY354aTsf7sM4EqIHjxBf6+/j7 o8tTnuMRavzOam/pQxmNqdUa0iwHPFqwRiX3dJQyBcDERBnpqlX+jP0bhvUdB92Dn0YF KUlX12EAT5ocL7s2fA/CFvD+l1GVx8noi6VkOdf9AFfppmWFtdsB8nNc/MQN3OHStOzE 3h2Z+QWYyawHgnbL+JR+FHp+wYKb5DY3H9pEGSXxekHrFopxCkCIGtPt/pKGyeuZL32d oUXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bfuAgNyb80o/k44Br8ArAtDjYyFS4d9rngl4b9J45UI=; b=LwMyC5nGjhM5NpKiqcm7nARlSm56+uVSrN3dSRrlusN8mI8XUjUjxmkVg8R2Q8kZU9 Ai8cyRgFknG4Dw5QqJk3stg+Rpdcihf21jQPT0d27YscBrBDp9/k0o2edoaj7M6Yp5/w qRGAflB+1+jNXLuLTHtkVIGu/HqJdbO5K4yY1GHoRfFvaQVsmIfT/mOHovSsDhuBx23F /Ms23vVAHmGfBtdrZzP43SP/3S9eJFwldxg+ga/+udOBE3vlyxcujUX1nL2ul6eT0mzE y6aASdjEOw0RlUUl2UL3i9pcp8Zo5fPmlGJDk6/NHgbfN1XEDq5Wvh5SH1CsVQMDd6LA ubFg== X-Gm-Message-State: AOAM531OU9mHBdQmppjfX814L3WU5qoYy97Q9KrACL2tZjdV6RWlheZw 40iNEXIzxjyaPV96AHDBGhV7TC0I X-Google-Smtp-Source: ABdhPJzWrF8AEQANdSJlPvXqaM9Kqv7OSvOy5pzx7/x2Tz2r7MMVbWnu9Ogpk0Pu9NeDAJ3iiZuElQ== X-Received: by 2002:a17:902:a60d:: with SMTP id u13mr63846451plq.46.1594454049895; Sat, 11 Jul 2020 00:54:09 -0700 (PDT) Received: from localhost.localdomain ([122.171.57.136]) by smtp.gmail.com with ESMTPSA id i66sm7916339pfc.12.2020.07.11.00.54.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jul 2020 00:54:09 -0700 (PDT) From: hanishkvc To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 Jul 2020 13:22:39 +0530 Message-Id: <20200711075239.109277-4-hanishkvc@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200711075239.109277-1-hanishkvc@gmail.com> References: <20200711075239.109277-1-hanishkvc@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v08 3/3] VF fbtiler (tile/detile) and hwdownload (detile) 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 Cc: hanishkvc Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" NOTE: THis is provided for reference, in case someone needs it. fbtiler videofilter cpu based framebuffer tiling/detiling This adds a video filter called fbtiler, which allows the user to tile/detile framebuffer layout between linear and tiled layouts, if required. It uses the fbtile helper routines to achieve its functionality. This is useful, if a) the user doesnt want to apply detiling when capturing some content/framebuffer which is tiled. OR b) the user already has tiled content with them. OR c) a developer wants to experiment with tiled data. OR d) user/developer wants to tile a linear layout. hwdownload detile framebuffer, if requested by user Added logic to support detiling of framebuffer. By default this is disabled. Only if requested by the user, the logic will be triggered. It uses the fbtile helper routines to do the detiling. Currently 32bit RGB pixel format based framebuffers are supported. If the underlying hardware context provides linear layouts, then nothing is done. However if underlying hardware context generates tiled layout, then user can use this to detile, where possible. ./ffmpeg -f kmsgrab -i - -vf hwdownload=1,format=bgr0 out.mp4 --- Changelog | 2 + doc/filters.texi | 103 +++++++++++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_fbtiler.c | 247 ++++++++++++++++++++++++++++++++++++ libavfilter/vf_hwdownload.c | 65 +++++++++- 6 files changed, 417 insertions(+), 2 deletions(-) create mode 100644 libavfilter/vf_fbtiler.c diff --git a/Changelog b/Changelog index c25a28a428..0fde7e27a3 100644 --- a/Changelog +++ b/Changelog @@ -2,6 +2,8 @@ Entries are sorted chronologically from oldest to youngest within each release, releases are sorted from youngest to oldest. version : +- fbtiler cpu based framebuffer layout tile/detile video filter +- hwdownload framebuffer layout detiling (Intel tile-x|y|yf layouts) - hwcontext_drm detiles non linear layouts, if possible - fbtile cpu based framebuffer tile/detile helpers - kmsgrab GetFB2 format_modifier, if user doesnt specify diff --git a/doc/filters.texi b/doc/filters.texi index ad2448acb2..e242304e3d 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -12105,6 +12105,23 @@ Not all formats will be supported on the output - it may be necessary to insert an additional @option{format} filter immediately following in the graph to get the output in a supported format. +It supports the following optional parameters + +@table @option +@item fbdetile +Specify type of CPU based FrameBuffer layout detiling to apply. The supported values are +@table @var +@item 0 +Dont do sw detiling (the default). +@item 1 +intel tile-x to linear conversion. +@item 2 +intel tile-y to linear conversion. +@item 3 +intel tile-yf to linear conversion. +@end table +@end table + @section hwmap Map hardware frames to system memory or to another device. @@ -12218,6 +12235,92 @@ It accepts the following optional parameters: The number of the CUDA device to use @end table +@anchor{fbtiler} +@section fbtiler + +Tile/Detile the Framebuffer between tile layout and linear layout using CPU. + +Currently supports conversion to|from Intel legacy tile-x|tile-y as well as +the newer Intel tile-yf layouts and the linear layout. This is useful if +one is using kmsgrab and hwdownload to capture a screen which is using one +of these non-linear layouts. It can also be used to generate a tiled layout. + +It provides a generic tiling|detiling logic, which can be easily configured +to tile|detile many different tiling schemes if required, in future. One is +only required to specify the tile walk parameters for the new tiling layout. + +Currently it expects the data to be a 32bit RGB based pixel format. However +the logic doesnt do any pixel format conversion or so. Later will be enabling +16bit RGB data also, as the logic is transparent to it at one level. + +One could either insert this into the filter chain while capturing itself, +or else, if it is slowing things down or so, then one could instead insert +it into the filter chain during playback or transcoding or so. + +It supports the following parameters + +@table @option +@item op +Specify whether to apply tiling or detiling. The supported values are +@table @var +@item 0 +Dont do any operation, just pass through. +@item 1 +Apply tiling operation. +@item 2 +Apply detiling operation. +@end table +@item layout +Specify which frame buffer layout to work with for conversion. The supported values are +@table @var +@item 0 +Dont do any tile/detiling. +@item 1 +Between intel tile-x and linear conversion (the default). +@item 2 +Between intel tile-y and linear conversion. +@item 3 +Between intel tile-yf and linear conversion. +@end table +@end table + +If one wants to convert during capture itself, one could do +@example +ffmpeg -f kmsgrab -i - -vf "hwdownload,format=bgr0,fbtiler=op=2:layout=1" OUTPUT +@end example + +However if one wants to convert after the tiled data has been already captured +@example +ffmpeg -i INPUT -vf "fbtiler=op=2" OUTPUT +@end example +@example +ffplay -i INPUT -vf "fbdetile" +@end example + +NOTE: While transcoding a test 1080p h264 stream, with 276 frames, below was +the average times taken by the different detile logics. +@example +rm out.mp4; time ./ffmpeg -i input.mp4 out.mp4 +rm out.mp4; time ./ffmpeg -i input.mp4 -vf fbtiler=op=2:layout=1 out.mp4 +rm out.mp4; time ./ffmpeg -i input.mp4 -vf fbtiler=op=2:layout=2 out.mp4 +rm out.mp4; time ./ffmpeg -i input.mp4 -vf fbtiler=op=2:layout=3 out.mp4 +@end example +@table @option +@item with no filters +it took ~07.28 secs, i5-8th Gen +it took ~09.95 secs, i7-7th Gen +@item with fbtiler=op=0:layout=0 filter, Intel Tile-Yf +it took ~12.70 secs. i7-7th Gen +@item with fbtiler=op=2:layout=1 filter, Intel Tile-X +it took ~08.69 secs, i5-8th Gen +it took ~13.35 secs, i7-7th Gen +@item with fbtiler=op=2:layout=2 filter, Intel Tile-Y +it took ~09.20 secs. i5-8th Gen +it took ~13.65 secs. i7-7th Gen +@item with fbtiler=op=2:layout=3 filter, Intel Tile-Yf +it took ~13.75 secs. i7-7th Gen +@end table + @section hqx Apply a high-quality magnification filter designed for pixel art. This filter diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 5123540653..e9ac9b1c28 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -280,6 +280,7 @@ OBJS-$(CONFIG_HWDOWNLOAD_FILTER) += vf_hwdownload.o OBJS-$(CONFIG_HWMAP_FILTER) += vf_hwmap.o OBJS-$(CONFIG_HWUPLOAD_CUDA_FILTER) += vf_hwupload_cuda.o OBJS-$(CONFIG_HWUPLOAD_FILTER) += vf_hwupload.o +OBJS-$(CONFIG_FBTILER_FILTER) += vf_fbtiler.o OBJS-$(CONFIG_HYSTERESIS_FILTER) += vf_hysteresis.o framesync.o OBJS-$(CONFIG_IDET_FILTER) += vf_idet.o OBJS-$(CONFIG_IL_FILTER) += vf_il.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 1183e40267..4ec80e77f1 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -265,6 +265,7 @@ extern AVFilter ff_vf_hwdownload; extern AVFilter ff_vf_hwmap; extern AVFilter ff_vf_hwupload; extern AVFilter ff_vf_hwupload_cuda; +extern AVFilter ff_vf_fbtiler; extern AVFilter ff_vf_hysteresis; extern AVFilter ff_vf_idet; extern AVFilter ff_vf_il; diff --git a/libavfilter/vf_fbtiler.c b/libavfilter/vf_fbtiler.c new file mode 100644 index 0000000000..ece920c673 --- /dev/null +++ b/libavfilter/vf_fbtiler.c @@ -0,0 +1,247 @@ +/* + * Copyright (c) 2020 HanishKVC + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Tile or Detile the Frame buffer using cpu + * Currently it supports the following layouts + * legacy Intel Tile-X + * legacy Intel Tile-Y + * newer Intel Tile-Yf + * It uses the fbtile helper library to do its job. + * More tiling layouts can be easily supported by adding configuration data + * for tile walking into fbtile library or its tile|detile_generic function. + * + */ + +/* + * ToThink|Check: Optimisations + * + * Does gcc setting used by ffmpeg allows memcpy | stringops inlining, + * loop unrolling, better native matching instructions, additional + * optimisations, ... + * + * Does gcc map to optimal memcpy logic, based on the situation it is + * used in i.e like + * based on size of transfer, alignment, architecture, etc + * a suitable combination of inlining and or rep movsb and or + * simd load/store and or unrolling and or ... + * + * If not, may be look at vector_size or intrinsics or appropriate arch + * and cpu specific inline asm or ... + * + */ + +/* + * Performance check results on i7-7500u + * + * Run Type : Layout : Seconds Min, Max : TSCCnt Min, Max + * Non filter run: : 10.04s, 09.97s : 00.00M, 00.00M + * fbdetile=0 run: PasThro: 12.70s, 13.20s : 00.00M, 00.00M + * fbdetile=1 run: TileX : 13.34s, 13.52s : 06.13M, 06.20M ; Opti generic + * fbdetile=2 run: TileY : 13.59s, 13.68s : 08.60M, 08.97M ; Opti generic + * fbdetile=3 run: TileYf : 13.73s, 13.83s : 09.82M, 09.92M ; Opti generic + * The Older logics + * fbdetile=2 run: TileX : 12.45s, 13.41s : 05.95M, 06.05M ; prev custom + * fbdetile=3 run: TileY : 13.47s, 13.89s : 06.31M, 06.38M ; prev custom + * fbdetile=4 run: TileYf : 13.73s, 13.83s : 11.41M, 11.83M ; Simple generic + */ + +#include "libavutil/avassert.h" +#include "libavutil/imgutils.h" +#include "libavutil/opt.h" +#include "libavutil/fbtile.h" +#ifndef FBTILE_SCOPE_PUBLIC +#include "libavutil/fbtile.c" +#endif +#include "avfilter.h" +#include "formats.h" +#include "internal.h" +#include "video.h" + + +// Print time taken by tile/detile using performance counter +#if ARCH_X86 +#define DEBUG_PERF 1 +#else +#undef DEBUG_PERF +#endif + +#ifdef DEBUG_PERF +#include +uint64_t perfTime = 0; +int perfCnt = 0; +#endif + +typedef struct FBTilerContext { + const AVClass *class; + int width, height; + int layout; + int op; +} FBTilerContext; + +#define OFFSET(x) offsetof(FBTilerContext, x) +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM +static const AVOption fbtiler_options[] = { + { "layout", "set framebuffer tile|format_modifier layout", OFFSET(layout), AV_OPT_TYPE_INT, {.i64=FBTILE_INTEL_XGEN9}, 0, FBTILE_UNKNOWN-1, FLAGS, "layout" }, + { "None", "Linear layout", 0, AV_OPT_TYPE_CONST, {.i64=FBTILE_NONE}, INT_MIN, INT_MAX, FLAGS, "layout" }, + { "intelx", "Intel Tile-X layout", 0, AV_OPT_TYPE_CONST, {.i64=FBTILE_INTEL_XGEN9}, INT_MIN, INT_MAX, FLAGS, "layout" }, + { "intely", "Intel Tile-Y layout", 0, AV_OPT_TYPE_CONST, {.i64=FBTILE_INTEL_YGEN9}, INT_MIN, INT_MAX, FLAGS, "layout" }, + { "intelyf", "Intel Tile-Yf layout", 0, AV_OPT_TYPE_CONST, {.i64=FBTILE_INTEL_YF}, INT_MIN, INT_MAX, FLAGS, "layout" }, + { "op", "select framebuffer tiling operations i.e tile or detile", OFFSET(op), AV_OPT_TYPE_INT, {.i64=FBTILEOPS_NONE}, 0, FBTILEOPS_UNKNOWN-1, FLAGS, "op" }, + { "None", "Nop", 0, AV_OPT_TYPE_CONST, {.i64=FBTILEOPS_NONE}, INT_MIN, INT_MAX, FLAGS, "op" }, + { "tile", "Apply tiling operation", 0, AV_OPT_TYPE_CONST, {.i64=FBTILEOPS_TILE}, INT_MIN, INT_MAX, FLAGS, "op" }, + { "detile", "Apply detiling operation", 0, AV_OPT_TYPE_CONST, {.i64=FBTILEOPS_DETILE}, INT_MIN, INT_MAX, FLAGS, "op" }, + { NULL } +}; + +AVFILTER_DEFINE_CLASS(fbtiler); + +static av_cold int init(AVFilterContext *ctx) +{ + FBTilerContext *fbtiler = ctx->priv; + + if (fbtiler->op == FBTILEOPS_NONE) { + av_log(ctx, AV_LOG_INFO, "init:Op: None, Pass through\n"); + } else if (fbtiler->op == FBTILEOPS_TILE) { + av_log(ctx, AV_LOG_INFO, "init:Op: Apply tiling\n"); + } else if (fbtiler->op == FBTILEOPS_DETILE) { + av_log(ctx, AV_LOG_INFO, "init:Op: Apply detiling\n"); + } else { + av_log(ctx, AV_LOG_ERROR, "init:Op: Unknown, shouldnt reach here\n"); + } + + if (fbtiler->layout == FBTILE_NONE) { + av_log(ctx, AV_LOG_INFO, "init:Layout: pass through\n"); + } else if (fbtiler->layout == FBTILE_INTEL_XGEN9) { + av_log(ctx, AV_LOG_INFO, "init:Layout: Intel tile-x\n"); + } else if (fbtiler->layout == FBTILE_INTEL_YGEN9) { + av_log(ctx, AV_LOG_INFO, "init:Layout: Intel tile-y\n"); + } else if (fbtiler->layout == FBTILE_INTEL_YF) { + av_log(ctx, AV_LOG_INFO, "init:Layout: Intel tile-yf\n"); + } else { + av_log(ctx, AV_LOG_ERROR, "init: Unknown Tile format specified, shouldnt reach here\n"); + } + fbtiler->width = 1920; + fbtiler->height = 1088; + return 0; +} + +static int query_formats(AVFilterContext *ctx) +{ + AVFilterFormats *fmts_list; + + fmts_list = ff_make_format_list(fbtilePixFormats); + if (!fmts_list) + return AVERROR(ENOMEM); + return ff_set_common_formats(ctx, fmts_list); +} + +static int config_props(AVFilterLink *inlink) +{ + AVFilterContext *ctx = inlink->dst; + FBTilerContext *fbtiler = ctx->priv; + + fbtiler->width = inlink->w; + fbtiler->height = inlink->h; + av_log(ctx, AV_LOG_INFO, "config_props: %d x %d\n", fbtiler->width, fbtiler->height); + + return 0; +} + + +static int filter_frame(AVFilterLink *inlink, AVFrame *in) +{ + AVFilterContext *ctx = inlink->dst; + FBTilerContext *fbtiler = ctx->priv; + AVFilterLink *outlink = ctx->outputs[0]; + AVFrame *out; + + if ((fbtiler->op == FBTILEOPS_NONE) || (fbtiler->layout == FBTILE_NONE)) + return ff_filter_frame(outlink, in); + + out = ff_get_video_buffer(outlink, outlink->w, outlink->h); + if (!out) { + av_frame_free(&in); + return AVERROR(ENOMEM); + } + av_frame_copy_props(out, in); + +#ifdef DEBUG_PERF + unsigned int tscArg; + uint64_t perfStart = __rdtscp(&tscArg); +#endif + + fbtile_conv(fbtiler->op, fbtiler->layout, + fbtiler->width, fbtiler->height, + out->data[0], out->linesize[0], + in->data[0], in->linesize[0], 4); + +#ifdef DEBUG_PERF + uint64_t perfEnd = __rdtscp(&tscArg); + perfTime += (perfEnd - perfStart); + perfCnt += 1; +#endif + + av_frame_free(&in); + return ff_filter_frame(outlink, out); +} + +static av_cold void uninit(AVFilterContext *ctx) +{ +#ifdef DEBUG_PERF + if (perfCnt == 0) + perfCnt = 1; + av_log(ctx, AV_LOG_INFO, "uninit:perf: AvgTSCCnt %ld\n", perfTime/perfCnt); +#endif +} + +static const AVFilterPad fbtiler_inputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_props, + .filter_frame = filter_frame, + }, + { NULL } +}; + +static const AVFilterPad fbtiler_outputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + }, + { NULL } +}; + +AVFilter ff_vf_fbtiler = { + .name = "fbtiler", + .description = NULL_IF_CONFIG_SMALL("Tile|Detile Framebuffer using CPU"), + .priv_size = sizeof(FBTilerContext), + .init = init, + .uninit = uninit, + .query_formats = query_formats, + .inputs = fbtiler_inputs, + .outputs = fbtiler_outputs, + .priv_class = &fbtiler_class, + .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, +}; + +// vim: set expandtab sts=4: // diff --git a/libavfilter/vf_hwdownload.c b/libavfilter/vf_hwdownload.c index 33af30cf40..310ed11056 100644 --- a/libavfilter/vf_hwdownload.c +++ b/libavfilter/vf_hwdownload.c @@ -22,6 +22,10 @@ #include "libavutil/mem.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" +#include "libavutil/fbtile.h" +#ifndef FBTILE_SCOPE_PUBLIC +#include "libavutil/fbtile.c" +#endif #include "avfilter.h" #include "formats.h" @@ -33,8 +37,20 @@ typedef struct HWDownloadContext { AVBufferRef *hwframes_ref; AVHWFramesContext *hwframes; + int fbdetile; } HWDownloadContext; +#define OFFSET(x) offsetof(HWDownloadContext, x) +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM +static const AVOption hwdownload_options[] = { + { "fbdetile", "set framebuffer detile layout info", OFFSET(fbdetile), AV_OPT_TYPE_INT, {.i64=FBTILE_NONE}, 0, FBTILE_UNKNOWN-1, FLAGS, "fbdetile" }, + { "none", "Pass through", 0, AV_OPT_TYPE_CONST, {.i64=FBTILE_NONE}, INT_MIN, INT_MAX, FLAGS, "fbdetile" }, + { "intelx", "Intel Tile-X layout", 0, AV_OPT_TYPE_CONST, {.i64=FBTILE_INTEL_XGEN9}, INT_MIN, INT_MAX, FLAGS, "fbdetile" }, + { "intely", "Intel Tile-Y layout", 0, AV_OPT_TYPE_CONST, {.i64=FBTILE_INTEL_YGEN9}, INT_MIN, INT_MAX, FLAGS, "fbdetile" }, + { "intelyf", "Intel Tile-Yf layout", 0, AV_OPT_TYPE_CONST, {.i64=FBTILE_INTEL_YF}, INT_MIN, INT_MAX, FLAGS, "fbdetile" }, + { NULL } +}; + static int hwdownload_query_formats(AVFilterContext *avctx) { AVFilterFormats *infmts = NULL; @@ -64,6 +80,7 @@ static int hwdownload_query_formats(AVFilterContext *avctx) static int hwdownload_config_input(AVFilterLink *inlink) { + int err; AVFilterContext *avctx = inlink->dst; HWDownloadContext *ctx = avctx->priv; @@ -81,6 +98,15 @@ static int hwdownload_config_input(AVFilterLink *inlink) ctx->hwframes = (AVHWFramesContext*)ctx->hwframes_ref->data; + if (ctx->fbdetile != 0) { + err = fbtile_checkpixformats(ctx->hwframes->sw_format, fbtilePixFormats[0]); + if (err) { + av_log(ctx, AV_LOG_ERROR, "Invalid input format %s for fbdetile.\n", + av_get_pix_fmt_name(ctx->hwframes->sw_format)); + return AVERROR(EINVAL); + } + } + return 0; } @@ -116,6 +142,15 @@ static int hwdownload_config_output(AVFilterLink *outlink) return AVERROR(EINVAL); } + if (ctx->fbdetile != 0) { + err = fbtile_checkpixformats(outlink->format, fbtilePixFormats[0]); + if (err) { + av_log(ctx, AV_LOG_ERROR, "Invalid output format %s for fbdetile.\n", + av_get_pix_fmt_name(outlink->format)); + return AVERROR(EINVAL); + } + } + outlink->w = inlink->w; outlink->h = inlink->h; @@ -128,6 +163,7 @@ static int hwdownload_filter_frame(AVFilterLink *link, AVFrame *input) AVFilterLink *outlink = avctx->outputs[0]; HWDownloadContext *ctx = avctx->priv; AVFrame *output = NULL; + AVFrame *output2 = NULL; int err; if (!ctx->hwframes_ref || !input->hw_frames_ctx) { @@ -162,13 +198,38 @@ static int hwdownload_filter_frame(AVFilterLink *link, AVFrame *input) if (err < 0) goto fail; + if (ctx->fbdetile == 0) { + av_frame_free(&input); + return ff_filter_frame(avctx->outputs[0], output); + } + + output2 = ff_get_video_buffer(outlink, ctx->hwframes->width, + ctx->hwframes->height); + if (!output2) { + err = AVERROR(ENOMEM); + goto fail; + } + + output2->width = outlink->w; + output2->height = outlink->h; + fbtile_conv(FBTILEOPS_DETILE, ctx->fbdetile, + output2->width, output2->height, + output2->data[0], output2->linesize[0], + output->data[0], output->linesize[0], 4); + + err = av_frame_copy_props(output2, input); + if (err < 0) + goto fail; + av_frame_free(&input); + av_frame_free(&output); - return ff_filter_frame(avctx->outputs[0], output); + return ff_filter_frame(avctx->outputs[0], output2); fail: av_frame_free(&input); av_frame_free(&output); + av_frame_free(&output2); return err; } @@ -182,7 +243,7 @@ static av_cold void hwdownload_uninit(AVFilterContext *avctx) static const AVClass hwdownload_class = { .class_name = "hwdownload", .item_name = av_default_item_name, - .option = NULL, + .option = hwdownload_options, .version = LIBAVUTIL_VERSION_INT, };