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, };