From patchwork Sat Jul 4 13:17:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hanishkvc X-Patchwork-Id: 20800 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 3C6914498AB for ; Sat, 4 Jul 2020 16:19:22 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1AB6968B4DF; Sat, 4 Jul 2020 16:19:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C457E68B490 for ; Sat, 4 Jul 2020 16:19:19 +0300 (EEST) Received: by mail-pf1-f173.google.com with SMTP id 207so14876123pfu.3 for ; Sat, 04 Jul 2020 06:19:19 -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=QDZMz80FcmqrcFdzvu5UD2WrCNCtjJ352jbHJosKPcg=; b=AUSTYg9OGzoGYkg7onPVxUy3s8nlUSuI79r7kZJRQ9LbbgiGgJug19YGtuOLt/iqSa I6SSu+HvztCK3MCbRtfu2SFWWmSS0zCWgedc2Vd3kYUAMidCRViOFRCYk8/FZw3dhoJN ld0TvAgJWv7dGIPkUJeHwBbgOORc4ynm+2V+GI+SQdb6Ka/eC9DrN2V0R02hVO+lU3wb FEao2eAx7ASlCHdeHyXGN3/WdoLB416t1BnxIaLwNIUmL8rNan/EdblfLSjsMW5NYn+o pPSFFt2oa1B/qwcbWk1lGukyG9IJIUVf/VG9OoYnoUF3A3LdAfd1Jn4wiua7Rj3bK0VX XxRg== 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=QDZMz80FcmqrcFdzvu5UD2WrCNCtjJ352jbHJosKPcg=; b=MuQGw/yhU6AnJ53eiFWoEJhzqQi1WBI2aGA0SESECiNPgr1/tvXizXhea5irUVziw2 oqGW2Kd9RsVNR9rB3TH1VE4akZn/52W7DxjAgud4w9iwdmDTJ4clO/Z9llg2G/T/Bd3E HmKcmsCKJTus5EKxQPZBFr37mT+Xke626AjzcQVEbhte2eabwm04+51b4ufJUaX7aRyP D/fU+5Fzqp7pk9FPVCthHSF9MaO6DY+JkA7wnohoersZzktqtDRV8pG2UUVzKy69559z fQ6DkXCbFgb6F46Ab4Kmsq4sxQ1Dq8By/vNPcHiD5fBKJSAbQlVQ3QOh1kJHj48IxJsg 3f0g== X-Gm-Message-State: AOAM5326EH+u3u1R0/i3GvmfCgsjPX+CSA7d/oJxzI/JMfitl2KKlSw+ DzS8Wn8Z9RGjdxbLrONVbQDqrxQk X-Google-Smtp-Source: ABdhPJy9q0quqV+AII/GsoObv+kfDt7R1uYWHVmDq/TN7KQMMPz2bFQA0JmUkfvtHD3NrIlTf2rsBw== X-Received: by 2002:a63:9246:: with SMTP id s6mr32185547pgn.22.1593868757470; Sat, 04 Jul 2020 06:19:17 -0700 (PDT) Received: from localhost.localdomain ([122.179.70.80]) by smtp.gmail.com with ESMTPSA id b191sm14657507pga.13.2020.07.04.06.19.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jul 2020 06:19:16 -0700 (PDT) From: hanishkvc To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Jul 2020 18:47:16 +0530 Message-Id: <20200704131717.49428-5-hanishkvc@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200704131717.49428-1-hanishkvc@gmail.com> References: <20200704131717.49428-1-hanishkvc@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v06 4/5] hwdownload detile framebuffer, if requested by user 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" 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. Only if the 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 | 1 + doc/filters.texi | 19 ++++++++++ libavfilter/vf_hwdownload.c | 74 ++++++++++++++++++++++++++++++++++++- 3 files changed, 92 insertions(+), 2 deletions(-) diff --git a/Changelog b/Changelog index b6a4ad1b34..6174770ce1 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 : +- hwdownload framebuffer layout detiling (Intel tile-x|y|yf layouts) - hwcontext_drm detiles non linear layouts, if possible - kmsgrab GetFB2 format_modifier, if user doesnt specify - AudioToolbox output device diff --git a/doc/filters.texi b/doc/filters.texi index 67892e0afb..c783e059c2 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -12097,6 +12097,25 @@ 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 +Auto detect detile logic to apply (for hwcontext_drm). +@item 2 +intel tile-x to linear conversion. +@item 3 +intel tile-y to linear conversion. +@item 4 +intel tile-yf to linear conversion. +@end table +@end table + @section hwmap Map hardware frames to system memory or to another device. diff --git a/libavfilter/vf_hwdownload.c b/libavfilter/vf_hwdownload.c index 33af30cf40..5413ff104d 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" +#if CONFIG_LIBDRM +#include "libavutil/hwcontext_drm.h" +#endif #include "avfilter.h" #include "formats.h" @@ -33,8 +37,23 @@ 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 mode", OFFSET(fbdetile), AV_OPT_TYPE_INT, {.i64=TILE_NONE}, 0, TILE_NONE_END-1, FLAGS, "fbdetile" }, + { "none", "No SW detiling", 0, AV_OPT_TYPE_CONST, {.i64=TILE_NONE}, INT_MIN, INT_MAX, FLAGS, "fbdetile" }, + { "auto", "auto select based on format_modifier", 0, AV_OPT_TYPE_CONST, {.i64=TILE_AUTO}, INT_MIN, INT_MAX, FLAGS, "fbdetile" }, + { "intelx", "Intel Tile-X layout", 0, AV_OPT_TYPE_CONST, {.i64=TILE_INTELX}, INT_MIN, INT_MAX, FLAGS, "fbdetile" }, + { "intely", "Intel Tile-Y layout", 0, AV_OPT_TYPE_CONST, {.i64=TILE_INTELY}, INT_MIN, INT_MAX, FLAGS, "fbdetile" }, + { "intelyf", "Intel Tile-Yf layout", 0, AV_OPT_TYPE_CONST, {.i64=TILE_INTELYF}, INT_MIN, INT_MAX, FLAGS, "fbdetile" }, + { "intelgx", "Intel Tile-X layout, GenericDetile", 0, AV_OPT_TYPE_CONST, {.i64=TILE_INTELGX}, INT_MIN, INT_MAX, FLAGS, "fbdetile" }, + { "intelgy", "Intel Tile-Y layout, GenericDetile", 0, AV_OPT_TYPE_CONST, {.i64=TILE_INTELGY}, INT_MIN, INT_MAX, FLAGS, "fbdetile" }, + { NULL } +}; + static int hwdownload_query_formats(AVFilterContext *avctx) { AVFilterFormats *infmts = NULL; @@ -81,6 +100,16 @@ static int hwdownload_config_input(AVFilterLink *inlink) ctx->hwframes = (AVHWFramesContext*)ctx->hwframes_ref->data; + int found = 0; + if (ctx->fbdetile != 0) { + found = fbtile_checkpixformats(ctx->hwframes->sw_format, fbtilePixFormats[0]); + if (!found) { + 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 +145,15 @@ static int hwdownload_config_output(AVFilterLink *outlink) return AVERROR(EINVAL); } + if (ctx->fbdetile != 0) { + found = fbtile_checkpixformats(outlink->format, fbtilePixFormats[0]); + if (!found) { + 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 +166,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 +201,44 @@ 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; + uint64_t formatModifier = 0; +#if CONFIG_LIBDRM + if (input->format == AV_PIX_FMT_DRM_PRIME) { + AVDRMFrameDescriptor *drmFrame = input->data[0]; + formatModifier = drmFrame->objects[0].format_modifier; + } +#endif + detile_this(ctx->fbdetile, formatModifier, 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 +252,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, };