From patchwork Wed Jan 17 20:41:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 45643 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1896:b0:199:de12:6fa6 with SMTP id bm22csp101169pzb; Wed, 17 Jan 2024 12:41:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJvyiK5bZYfzNNVGBva66+LnvTpy5ShGBgxz0MFTHQZuv5O0ivNzjSf4Nrj4JZP62NAY0P X-Received: by 2002:a5d:644a:0:b0:337:b38d:69c1 with SMTP id d10-20020a5d644a000000b00337b38d69c1mr1168139wrw.120.1705524119171; Wed, 17 Jan 2024 12:41:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705524119; cv=none; d=google.com; s=arc-20160816; b=04PlB7YJtX295pNzD7S1vTjj0g+si3tyTnGz0G+kagsBtv6UXiqnjMXKvDE5YOXQhP XkGTiDqneu3o7ysjBcPDLGNi/pJ8N3ShI2W1lfpotdsx6Bue0NK5jDx7qPImRE6+lwHv VLhlyHzSnMXOYSzkR0GJWqF71nnBQcQwB8M8AZT+oxwOsEv5xBwSzx7FLm6eJH/FulrL BH+hsSSyupxQ2Fp0QZnQ61C8iaCPNQpQZgRc6mGflppCwr2xXBEsvGMVUsgslvdW+YLx y5+qX4CUEDP3Z/OdxbUvwU/9DVnLMtTJ/fIADmnp5c7dVjvXsTNzyuQyxPbfpMcAM3Qp zAfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=IqUXqcqtnzKts9PgTXbh51YQaoH/tjsVHvBikBImJps=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=MpiKxIqa9BkGIJ2KKTUVHLuzGJFRkaJ8df781IDriw3iDJ1VSYb/Xds5CMIg85wt96 2J4oet7rGmrxTVGgJowaU3HTaxN8nhwHeGHYiyF8n+1nTklNRSX/trFpHQA6+pMlgyvo Lh5PsJKy1QuCNwCKb7vE06omZSN1tlYoF+0RyVE3FVghP/VWeezjowRAH+MKxs1PJW9/ bbISxMa0BxKKlFlQPqiVnMq/jzCZfv/S8GRvultg9hkK9Eyk27WsH+o75XJ4aIFRKqJO CAdWjoQEE6c/jKfbcELveVcOd2XDpMPy/BFfLZFm5l1SKxWnJel8+tRaoqGwNY2RiAly tfhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=dxhDc2sU; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j7-20020a170906278700b00a2ae479d391si6180619ejc.479.2024.01.17.12.41.58; Wed, 17 Jan 2024 12:41:59 -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=@gmail.com header.s=20230601 header.b=dxhDc2sU; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7A8BC68D029; Wed, 17 Jan 2024 22:41:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 264C468AC25 for ; Wed, 17 Jan 2024 22:41:50 +0200 (EET) Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1d5f1e0e32eso13418925ad.3 for ; Wed, 17 Jan 2024 12:41:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705524107; x=1706128907; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=NTGV7THJCLrp1w92v2KrDxzc+JWKCmFFYhN07Q8+F/8=; b=dxhDc2sUjEqLyzIfiOkW76d7Uhz/y7+1iLlp7HMYy7fL9plL0IzDpaPuFolzU7A8Gh Eu5B+ol8SGeJr3Qii+7ib/iZfmxX/JvmIoHljtmN2biMTrMdOZ94HHnaqWfY25v8sxAR MjdJFQE7WRE3VtCSTylIl6HVkRID0wWJzx2bY5tYPB6XiuKSMNCi1etPrv27iCpeQjlU nJLKs3KdqidmlymZ/AFfrlVNju+O+CZzcDicm2RvXs3Rr2j71cLUEnRCBcm2cNzDaXQT bB1EKmNJd6AxB3AlSKIcx1F+hUddHWhSreObyrPruOxIdcOgKp5Vi0W2rFEHDzMIsfI+ AbAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705524107; x=1706128907; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NTGV7THJCLrp1w92v2KrDxzc+JWKCmFFYhN07Q8+F/8=; b=qLPqQf8yEjcXQ1BFLTXSlhQ9BZvsMsSNKkH2fWG3Mrgliddz2GuBGDIi6kZ8vg3UUN JA4QFFWC/31uM4WghlZu5klt9TVeceNbCIv8EzDV0CO6ulRNY78lo2BehNYeZ1ptQpMz ISdplL1W77XFkJMUqFOzqT821AsCoVl9hEFbmjIJGdgo/lzA4LZPkOvhz/Bwy3+QwA8w RVSTnua+OKB+zpUFNcp5tX0UD6k3f9+hDUgCUHmPXAKMLMLmPOVtrtFjUlXrcZtAFl5i nv0dCvRUPHXPDOD5QwDK9su/K1ti/NjOzM0Un7BT3O93BNA2BuoskYqAchQJpTNKmQJe dYqg== X-Gm-Message-State: AOJu0Yzcuygd/3OwtFjNZ0bc1Biu4r6WNAPVZJ7GmNMgum/t187383dR ZClMJJqNXXe4RBYU51WTtvKlrd2fOBY= X-Received: by 2002:a17:902:e812:b0:1d3:f5a6:7d4f with SMTP id u18-20020a170902e81200b001d3f5a67d4fmr6748392plg.110.1705524107366; Wed, 17 Jan 2024 12:41:47 -0800 (PST) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id o13-20020a170902778d00b001d50ca466e5sm70353pll.133.2024.01.17.12.41.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 12:41:47 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 Jan 2024 17:41:32 -0300 Message-ID: <20240117204133.11142-1-jamrial@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avutil: add a Tile Grid API X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: G1YEM1cSmx2O This includes a struct and helpers. It will be used to support container level tiled image formats like HEIF, but should be generic enough for general usage. Signed-off-by: James Almer --- libavutil/Makefile | 2 + libavutil/tile.c | 72 +++++++++++++++++++++++++ libavutil/tile.h | 132 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 libavutil/tile.c create mode 100644 libavutil/tile.h diff --git a/libavutil/Makefile b/libavutil/Makefile index e7709b97d0..380d706cfe 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -82,6 +82,7 @@ HEADERS = adler32.h \ spherical.h \ stereo3d.h \ threadmessage.h \ + tile.h \ time.h \ timecode.h \ timestamp.h \ @@ -172,6 +173,7 @@ OBJS = adler32.o \ spherical.o \ stereo3d.o \ threadmessage.o \ + tile.o \ time.o \ timecode.o \ tree.o \ diff --git a/libavutil/tile.c b/libavutil/tile.c new file mode 100644 index 0000000000..d6a95d85ed --- /dev/null +++ b/libavutil/tile.c @@ -0,0 +1,72 @@ +/* + * 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 +#include + +#include "log.h" +#include "mem.h" +#include "opt.h" +#include "tile.h" + +#define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM +#define OFFSET(x) offsetof(AVTileGrid, x) +static const AVOption tile_grid_options[] = { + { "type", NULL, OFFSET(type), AV_OPT_TYPE_INT, + { .i64 = AV_TILE_DIMENSION_TYPE_UNIFORM }, + AV_TILE_DIMENSION_TYPE_UNIFORM, AV_TILE_DIMENSION_TYPE_VARIABLE, FLAGS, "type" }, + { "uniform", NULL, 0, AV_OPT_TYPE_CONST, + { .i64 = AV_TILE_DIMENSION_TYPE_UNIFORM }, .unit = "type" }, + { "variable", NULL, 0, AV_OPT_TYPE_CONST, + { .i64 = AV_TILE_DIMENSION_TYPE_VARIABLE }, .unit = "type" }, + { "tile_rows", NULL, OFFSET(tile_rows), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, UINT_MAX, FLAGS }, + { "tile_cols", NULL, OFFSET(tile_cols), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, UINT_MAX, FLAGS }, + { "output_size", "size of the output image", OFFSET(output_width), AV_OPT_TYPE_IMAGE_SIZE, + { .str = NULL }, 0, INT_MAX, FLAGS }, + { NULL }, +}; + +static const AVClass tile_grid_class = { + .class_name = "AVTileGrid", + .version = LIBAVUTIL_VERSION_INT, + .option = tile_grid_options, +}; + +const AVClass *av_tile_grid_get_class(void) +{ + return &tile_grid_class; +} + +AVTileGrid *av_tile_grid_alloc(void) +{ + return av_mallocz(sizeof(AVTileGrid)); +} + +void av_tile_grid_free(AVTileGrid **ptile_grid) +{ + AVTileGrid *tile_grid = *ptile_grid; + + if (!tile_grid) + return; + + if (tile_grid->type == AV_TILE_DIMENSION_TYPE_VARIABLE) { + av_freep(&tile_grid->w.tile_widths); + av_freep(&tile_grid->h.tile_heights); + } + av_freep(ptile_grid); +} diff --git a/libavutil/tile.h b/libavutil/tile.h new file mode 100644 index 0000000000..fb8af0d56f --- /dev/null +++ b/libavutil/tile.h @@ -0,0 +1,132 @@ +/* + * 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_TILE_H +#define AVUTIL_TILE_H + +#include + +#include "log.h" + +/** + * @defgroup lavu_tile_grid Tile grid paremeters + * @{ + */ + +enum AVTileGridType { + AV_TILE_DIMENSION_TYPE_UNIFORM, ///< All tiles have the same size + AV_TILE_DIMENSION_TYPE_VARIABLE, ///< Tiles may have variable size +}; + +typedef struct AVTileGrid { + const AVClass *av_class; + + int tile_rows; ///< rows in the final grid + int tile_cols; ///< cols in the final grid + + enum AVTileGridType type; + + union { + /** + * Height of every tile. + * This member must be used when the type is AV_TILE_DIMENSION_TYPE_UNIFORM. + */ + int tile_height; + /** + * A @ref tile_rows * @ref tile_cols sized array of height values for each + * tile in the grid, in row major order. + * This member must be used when the type is AV_TILE_DIMENSION_TYPE_VARIABLE + * + * Must be allocated with the av_malloc() family of functions, and will be + * freed by av_tile_grid_free(). + */ + int *tile_heights; + } h; + + union { + /** + * Width of every tile. + * This member must be used when the type is AV_TILE_DIMENSION_TYPE_UNIFORM. + */ + int tile_width; + /** + * A @ref tile_rows * @ref tile_cols sized array of width values for each + * tile in the grid, in row major order. + * This member must be used when the type is AV_TILE_DIMENSION_TYPE_VARIABLE + * + * Must be allocated with the av_malloc() family of functions, and will be + * freed by av_tile_grid_free(). + */ + int *tile_widths; + } w; + + /** + * Width of the final image for presentation. + * + * When @ref type is AV_TILE_DIMENSION_TYPE_UNIFORM, this field must be > 0 + * and <= tile_width * tile_cols. + * When it's not equal to tile_width * tile_cols, the result of + * (tile_width * tile_cols) - output_width is the amount of pixels to be + * cropped from the right edge of the final image before presentation. + * + * When @ref type is AV_TILE_DIMENSION_TYPE_VARIABLE, this field must be > 0 + * and <= the sum of all values in the tile_widths array. + * When it's not equal to the sum of all values in the tile_widths array, + * the result of said sum minus output_width is the amount of pixels to be + * cropped from the right edge of the final image before presentation. + */ + int output_width; + /** + * Height of the final image for presentation. + * + * When @ref type is AV_TILE_DIMENSION_TYPE_UNIFORM, this field must be > 0 + * and <= tile_height * tile_rows. + * When it's not equal to tile_height * tile_rows, the result of + * (tile_height * tile_rows) - output_width is the amount of pixels to be + * cropped from the bottom edge of the final image before presentation. + * + * When @ref type is AV_TILE_DIMENSION_TYPE_VARIABLE, this field must be > 0 + * and <= the sum of all values in the tile_heights array. + * When it's not equal to the sum of all values in the tile_heights array, + * the result of said sum minus output_height is the amount of pixels to be + * cropped from the bottom edge of the final image before presentation. + */ + int output_height; +} AVTileGrid; + +const AVClass *av_tile_grid_get_class(void); + +/** + * Allocates a AVTileGrid, and initializes its fields with default values. + * Must be freed with av_tile_grid_free(). + */ +AVTileGrid *av_tile_grid_alloc(void); + +/** + * Free an AVTileGrid and all its contents. + * + * @param tile_grid pointer to pointer to an allocated AVTileGrid. + * upon return, *tile_grid will be set to NULL. + */ +void av_tile_grid_free(AVTileGrid **tile_grid); + +/** + * @} + */ + +#endif /* AVUTIL_TILE_H */ From patchwork Wed Jan 17 20:41:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 45644 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1896:b0:199:de12:6fa6 with SMTP id bm22csp101290pzb; Wed, 17 Jan 2024 12:42:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IFts0fHj4UZA/Po1JWSg7kcGpqrIGfF3Tv5zX0/tnpAmFCtODdd9M5fEevcmLqY5GlADu5U X-Received: by 2002:a17:906:22c6:b0:a26:d98d:74d7 with SMTP id q6-20020a17090622c600b00a26d98d74d7mr1403310eja.33.1705524132486; Wed, 17 Jan 2024 12:42:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705524132; cv=none; d=google.com; s=arc-20160816; b=lo4Xd68tDXeuWre5aXrm8QPn26AIokFbUPXub8DnW8sTbxfU9/b2o2mBb6QSWgb9BH Fp+GOpp+FVcYTvSVmg2wByDuZ5sIhPbPesmTYWZaWlNQctUfMblw+klLcwVW52WHcLgY M5zufasP6EiDzsxgJdPuo/AfHu27N8Ng5tVra8jt79sTrg3vGM2dPyI04swSWxfQNBlW i6qmPXKA7N24Mz6DiVKoZkxOYHDhMAHSQi6UK0qcGnHzCu48/p2rWyaZVq8GZCbuC+PX 7zVPPlGwCGSfqk2ttR96puZ43GRhsW/whS2rVVtelOMpCqswhcDKtkQCsrsxtcJSCwec sMSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=ZmFw29wuNfUkF1B6fx5BGwFSohZASRQV+5JS3Wc+rNA=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=b2Zj2b+USthz0WwXlDItRv+z6fIIWEfOCQ7cJvItw8Xk5PnjTHNlmD3PgNh3VCm/BG u8X/XpCXVJxiKCSE02ezpVC1JnP2SAeYRUKyFLx8323fZ5mxjjerijVqzBruW7EEIsY6 XDEGPed9UyqWLKkr17mSUjHftK3QZlXzcZmYQuzBk3MYytn+/XgTbl9KtKzzWDal6Ypd KVf1m2GNhFe8x6aGvD2CbhnYrnx1Hl76hHgfvsEYwl94WCo0ihzhLPMt/4ipDQKF2DQe zcOuIqWi2Vu6/PhXsvngRiSRKbffX5qdEn6qiZQz6MvLLnI+Y0GQwVwP9FQOKdAr64gH PM2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=Q1ll6DrG; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h2-20020a1709063c0200b00a2ed24c42d0si921614ejg.390.2024.01.17.12.42.07; Wed, 17 Jan 2024 12:42:12 -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=@gmail.com header.s=20230601 header.b=Q1ll6DrG; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8864D68D053; Wed, 17 Jan 2024 22:41:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 598C168D029 for ; Wed, 17 Jan 2024 22:41:51 +0200 (EET) Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1d5db9eb0e7so19295395ad.2 for ; Wed, 17 Jan 2024 12:41:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705524109; x=1706128909; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=R1Hx05/L9dGn+BdkUBXxBUdxdWv9LDs5NWWssC60Fd8=; b=Q1ll6DrGFtFPtV0wn+X/0y87WweFtmWYf7slzbORmOrCZeywpKsBk87p0GwxIXqjZL 3tmlXeEF6fc53yMxk3aGY2STE9lN7FAM5dzcD3l8bQ2ZITyLKpC1C69Qonhj70lJucG3 /0J07Fqp7QQG7PF358g0F57kEIlK8MtnSMVQ5iZzA6GHjReLmYtCGFmMrVQOF1hCRURe gY/RhP5glPWPXJwDPK+ajHuMWHEc65Gs0W6Y8iv+OJVP6FQ+mitqGmaK2Y0dR73cz9ik 9siDim8QTAsqX55bm+arnQBD/+qFL2Yk/NfyI1MvJpLrYKJ2t63FJdIYMeKv1OtbcTH7 rUwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705524109; x=1706128909; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R1Hx05/L9dGn+BdkUBXxBUdxdWv9LDs5NWWssC60Fd8=; b=sP55T+3xbGrGpkJOHLf3UMJJ7GcVSeXPcpTnGpHgjlN/n/vdz6KJdb/qUJtx10pQC1 SRSJumhzueEn4AsFNlTx3eMg0woiL9kkcCie9inRGSSPRW229SsDsg9FMjZOA7z7u8EC Qx4PwM+MojSWxTK1DZSvWuO+0Wsgf3H1TJQeapBqgChffD2fsLg4Z28nCHt5B3JpMOo5 OU7WY2FvnfR2Wcf+9kYFP9UmLy0U1msyfnaVrsACh+5sPTLJBVEYgBfH6TUW6b3aGC3v 8RzQqfhFt8Fpw452HmNWFLYnUge53GxKpxiDDJ1GDmWg/7OH/ILSR/bSQgxrft9AXqXq 7Ppg== X-Gm-Message-State: AOJu0YzvLOgxk4omyp2OkfuAMlke23zbmmkXF3vzK/WGuOSL82s9scHF GulWzmbcp1CnkqA+hR0apiTa4OkzgGw= X-Received: by 2002:a17:902:8345:b0:1d4:4482:83c7 with SMTP id z5-20020a170902834500b001d4448283c7mr4821699pln.117.1705524108798; Wed, 17 Jan 2024 12:41:48 -0800 (PST) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id o13-20020a170902778d00b001d50ca466e5sm70353pll.133.2024.01.17.12.41.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 12:41:48 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 Jan 2024 17:41:33 -0300 Message-ID: <20240117204133.11142-2-jamrial@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240117204133.11142-1-jamrial@gmail.com> References: <20240117204133.11142-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avformat: add a Tile Grid stream group type X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: uDpK/gVWtFIc This will be used to support tiled image formats like HEIF. Signed-off-by: James Almer --- libavformat/avformat.c | 5 +++++ libavformat/avformat.h | 3 +++ libavformat/dump.c | 36 ++++++++++++++++++++++++++++++++++++ libavformat/options.c | 9 +++++++++ 4 files changed, 53 insertions(+) diff --git a/libavformat/avformat.c b/libavformat/avformat.c index 882927f7b1..a7bd959db5 100644 --- a/libavformat/avformat.c +++ b/libavformat/avformat.c @@ -30,6 +30,7 @@ #include "libavutil/opt.h" #include "libavutil/pixfmt.h" #include "libavutil/samplefmt.h" +#include "libavutil/tile.h" #include "libavcodec/avcodec.h" #include "libavcodec/codec.h" #include "libavcodec/bsf.h" @@ -100,6 +101,10 @@ void ff_free_stream_group(AVStreamGroup **pstg) av_iamf_mix_presentation_free(&stg->params.iamf_mix_presentation); break; } + case AV_STREAM_GROUP_PARAMS_TILE_GRID: { + av_tile_grid_free(&stg->params.tile_grid); + break; + } default: break; } diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 5d0fe82250..f259ad1367 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1022,10 +1022,12 @@ enum AVStreamGroupParamsType { AV_STREAM_GROUP_PARAMS_NONE, AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT, AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION, + AV_STREAM_GROUP_PARAMS_TILE_GRID, }; struct AVIAMFAudioElement; struct AVIAMFMixPresentation; +struct AVTileGrid; typedef struct AVStreamGroup { /** @@ -1062,6 +1064,7 @@ typedef struct AVStreamGroup { union { struct AVIAMFAudioElement *iamf_audio_element; struct AVIAMFMixPresentation *iamf_mix_presentation; + struct AVTileGrid *tile_grid; } params; /** diff --git a/libavformat/dump.c b/libavformat/dump.c index aff51b43f6..84884121a1 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -22,6 +22,7 @@ #include #include +#include "libavutil/avstring.h" #include "libavutil/channel_layout.h" #include "libavutil/display.h" #include "libavutil/iamf.h" @@ -35,6 +36,7 @@ #include "libavutil/spherical.h" #include "libavutil/stereo3d.h" #include "libavutil/timecode.h" +#include "libavutil/tile.h" #include "libavcodec/avcodec.h" @@ -720,6 +722,40 @@ static void dump_stream_group(const AVFormatContext *ic, uint8_t *printed, } } break; + case AV_STREAM_GROUP_PARAMS_TILE_GRID: { + const AVTileGrid *tile_grid = stg->params.tile_grid; + AVCodecContext *avctx = avcodec_alloc_context3(NULL); + const char *ptr = NULL; + av_log(NULL, AV_LOG_INFO, " Tile Grid:"); + dump_metadata(NULL, stg->metadata, " ", AV_LOG_INFO); + if (avctx && stg->nb_streams && !avcodec_parameters_to_context(avctx, ic->streams[0]->codecpar)) { + avctx->width = tile_grid->output_width; + avctx->height = tile_grid->output_height; + avctx->coded_width = FFALIGN(tile_grid->output_width, tile_grid->w.tile_width); + avctx->coded_height = FFALIGN(tile_grid->output_height, tile_grid->h.tile_height); + if (ic->dump_separator) + av_opt_set(avctx, "dump_separator", ic->dump_separator, 0); + buf[0] = 0; + avcodec_string(buf, sizeof(buf), avctx, is_output); + ptr = av_stristr(buf, " "); + } + avcodec_free_context(&avctx); + if (ptr) { + ptr++; + av_log(NULL, AV_LOG_INFO, " %s", ptr); + av_log(NULL, AV_LOG_VERBOSE, ","); + } + av_log(NULL, AV_LOG_VERBOSE, " %d rows, %d columns, tile size %dx%d", + tile_grid->tile_rows, tile_grid->tile_cols, + tile_grid->w.tile_width, tile_grid->h.tile_height); + av_log(NULL, AV_LOG_INFO, "\n"); + for (int i = 0; i < stg->nb_streams; i++) { + const AVStream *st = stg->streams[i]; + dump_stream_format(ic, st->index, i, index, is_output, AV_LOG_VERBOSE); + printed[st->index] = 1; + } + break; + } } default: break; diff --git a/libavformat/options.c b/libavformat/options.c index e79ae221d9..dd33ea3470 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -30,6 +30,7 @@ #include "libavutil/internal.h" #include "libavutil/intmath.h" #include "libavutil/opt.h" +#include "libavutil/tile.h" /** * @file @@ -367,6 +368,9 @@ static const AVClass *stream_group_child_iterate(void **opaque) case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: ret = av_iamf_mix_presentation_get_class(); break; + case AV_STREAM_GROUP_PARAMS_TILE_GRID: + ret = av_tile_grid_get_class(); + break; default: break; } @@ -427,6 +431,11 @@ AVStreamGroup *avformat_stream_group_create(AVFormatContext *s, if (!stg->params.iamf_mix_presentation) goto fail; break; + case AV_STREAM_GROUP_PARAMS_TILE_GRID: + stg->params.tile_grid = av_tile_grid_alloc(); + if (!stg->params.tile_grid) + goto fail; + break; default: goto fail; }