From patchwork Mon Oct 11 04:50:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 31029 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp3330232ioa; Sun, 10 Oct 2021 21:51:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzN68zSsbmQkUUnUzPWmJ50xlbz08Tb2bQVf7t3G6iv0GzKPU2LY2+qntSipvPaE1TQlHcy X-Received: by 2002:a17:906:5950:: with SMTP id g16mr23143317ejr.149.1633927914373; Sun, 10 Oct 2021 21:51:54 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id au15si2210278ejc.717.2021.10.10.21.51.54; Sun, 10 Oct 2021 21:51:54 -0700 (PDT) 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=@hotmail.com header.s=selector1 header.b=MeI3kvCV; arc=fail (body hash mismatch); 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=NONE dis=NONE) header.from=hotmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 24F6668A82C; Mon, 11 Oct 2021 07:51:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10olkn2096.outbound.protection.outlook.com [40.92.42.96]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BF64F68A7C8 for ; Mon, 11 Oct 2021 07:51:08 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FhcdvO+Lqm6Xf5+2NCZZI2iFHTc9YoEwp0YrupJwm3a281LMUUwHpE/l7Tp0J0WfvDYEsTm9y4JSooBjDOKJeTJlvhLY1DDNZ68cOFIMH5Dl2k6l4IEfi0+vCKAZs9QrKZcbxEJJwpp2B2IPt8uXCpJk8HZm75GuH+BsurRA78XzsnLCNrLJJ6bmcRwA+36GQhLX2oGLhm8RM6WupNoBDiC3H+AhU+WvYQl4kT1jAO8usvQ62tWa9F6+OJJ24hG4c+k7WS2xne5ZHnn9EUmxthnfya421FMxYVdw084UnLqr4lvMg8tZ0Y8TeONNZbGhjkLkWrv5pHPof+2CjyT8Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lc9/29kqLj9v4GEywKiwh37jL/0d7PyefW1Rv5Vvb8w=; b=TOg6dN6wSbdMXzDJQuGTL6z8m1MjvHZDodX4F1sKIuvfSMNxpK6HmKSvk5mhx5x5TereOvTlwDI9VkjofOTJoq3pdfGo9QG/uFHYQUFzuk3fq75GJhlM4KZwrPi3FeWOt/7Vrw1FKU3DGBHpWDPaFSUuDqakckvjn+10OlbW5fmI7k9ppp8cXcsYKRX1GxmAdgOmUsCd+9SUTarGigaT3L2T+UoTYmXm0raqWcxTpcdtmABUfIiGrIIz8uTRjL5krR8TYhkEZidk0NFQomPOPsUyyu4s6tiOp8tuz4kjUpH2mQNxeRXU2jR5rpgrPfjhJpA3+k5MvqTjcgdt3XotrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lc9/29kqLj9v4GEywKiwh37jL/0d7PyefW1Rv5Vvb8w=; b=MeI3kvCV9QCNKebbunGQgZp6ly1hMHFsAtmRr5GEP9R2Ie+pyDASOGjb/kOufG6o7t/yidxN72VMoQ2sw5tEC2mp40Gjd2GuAOa3cyXysNEw5abVXG62XxmDbXpG/fXqMI11xoXTVA2yB666G98NkrXeyWgDqTIuh2D/TbOvSwYzmn2wFwhPzfbtGUDI8aB7HfxhUTQdzCGtZEcCBCRMamhzApNJK1m1nrEmNFWXLpRr/zb7jHgollvNlDuiFn2gZoRa+XsDjJDxKu81bQbU2BxQZTlDiCxqK+N0/KbHkDmye7z+xDnw+TCzogWAGnmO7TrRzqecG/ny/FK4CW3LuA== Received: from MN2PR04MB5981.namprd04.prod.outlook.com (2603:10b6:208:da::10) by MN2PR04MB6016.namprd04.prod.outlook.com (2603:10b6:208:de::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18; Mon, 11 Oct 2021 04:50:56 +0000 Received: from MN2PR04MB5981.namprd04.prod.outlook.com ([fe80::ecfe:2528:2012:22cb]) by MN2PR04MB5981.namprd04.prod.outlook.com ([fe80::ecfe:2528:2012:22cb%5]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 04:50:56 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v13 04/14] avfilter/subtitles: Add subtitles.c for subtitle frame allocation Thread-Index: AQHXvluTJvfTRvp++EuN1fOwUcz5ZA== Date: Mon, 11 Oct 2021 04:50:56 +0000 Message-ID: References: <41c4d8049ad6a90ab6a8e29955aae8f39d1000ec.1633926637.git.softworkz@hotmail.com> <669100dbb5e7bda1dfc9e8aa8cb7eaf8c6661ec4.1633926637.git.softworkz@hotmail.com> In-Reply-To: <669100dbb5e7bda1dfc9e8aa8cb7eaf8c6661ec4.1633926637.git.softworkz@hotmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [cr8PSnVy+R5LKuOh3jLf3P23TmmnElxA] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 73604604-d091-4bd4-36e4-08d98c72b66e x-ms-traffictypediagnostic: MN2PR04MB6016: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: SNajKvXF/tbfk4QiAAxqWQ27LWjs+zQ66yYwaQWRYYKkgYokPaH8ynQ4DJoz/HKhEkGhGw776iycyrZvX7cjh3TMSLv9w+xWZOWAJWmYwb0gcTTA6m37bX8PFc5L6lbYy9nGf6EMOoBEliNMVOkGeEQ3FvpXI1NtWdVD6Ks26TsNkktYeb99JtCa94s+i1kMcPiTA5Ufz/79vs2ok0JiVtE/iXzjH+NQx0k3IiOqE/vya3fDfrWiRTVIv4EkHVzWeHe2sBN97eQdEu0UCqbbBDPaO7vPmfcph8bmVCTVUfB+88jFWVGabm21T0KOm45iIx4kHm0Licg+fMWLeagxtq8gYeo091quqvaaZmd13s2tJBJpSUyHEi7FCdqhxcLjDEoXPisDpQEZxIEIP+zOuSDjNt04nEoB+Gmxbp5PvzC25JlLydpYWsmEPlBgKvpn x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 6/eLYIG1fsR3ie7yZfYu9wpAmcHUgd8HtcBaEkrDNfT5imJHatpJc4cGBZNohwkfFini9a72+Ri0/ClhD9jtpK+8neH5kE1HFPaaGYBuHCikYfq4PLFccwZS776GxVxC7K1wxqeXpc+2ycGKOazC0w== x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-3174-20-msonline-outlook-529c7.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN2PR04MB5981.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 73604604-d091-4bd4-36e4-08d98c72b66e X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Oct 2021 04:50:56.3593 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR04MB6016 Subject: [FFmpeg-devel] [PATCH v13 04/14] avfilter/subtitles: Add subtitles.c for subtitle frame allocation 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: HDVmw5uJWqXb Analog to avfilter/video.c and avfilter/audio.c Signed-off-by: softworkz --- libavfilter/Makefile | 1 + libavfilter/avfilter.c | 4 +++ libavfilter/internal.h | 1 + libavfilter/subtitles.c | 63 +++++++++++++++++++++++++++++++++++++++++ libavfilter/subtitles.h | 44 ++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 libavfilter/subtitles.c create mode 100644 libavfilter/subtitles.h diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 9ec0963ca8..2ccfebe21d 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -19,6 +19,7 @@ OBJS = allfilters.o \ framequeue.o \ graphdump.o \ graphparser.o \ + subtitles.o \ video.o \ OBJS-$(HAVE_THREADS) += pthread.o diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 7362bcdab5..df5b8f483c 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -43,6 +43,7 @@ #include "formats.h" #include "framepool.h" #include "internal.h" +#include "subtitles.h" #include "libavutil/ffversion.h" const char av_filter_ffversion[] = "FFmpeg version " FFMPEG_VERSION; @@ -1475,6 +1476,9 @@ int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe) case AVMEDIA_TYPE_AUDIO: out = ff_get_audio_buffer(link, frame->nb_samples); break; + case AVMEDIA_TYPE_SUBTITLE: + out = ff_get_subtitles_buffer(link, link->format); + break; default: return AVERROR(EINVAL); } diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 1099b82b4b..fc09ef574c 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -90,6 +90,7 @@ struct AVFilterPad { union { AVFrame *(*video)(AVFilterLink *link, int w, int h); AVFrame *(*audio)(AVFilterLink *link, int nb_samples); + AVFrame *(*subtitle)(AVFilterLink *link, int format); } get_buffer; /** diff --git a/libavfilter/subtitles.c b/libavfilter/subtitles.c new file mode 100644 index 0000000000..951bfd612c --- /dev/null +++ b/libavfilter/subtitles.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2021 softworkz + * + * 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 "libavutil/common.h" + +#include "subtitles.h" +#include "avfilter.h" +#include "internal.h" + + +AVFrame *ff_null_get_subtitles_buffer(AVFilterLink *link, int format) +{ + return ff_get_subtitles_buffer(link->dst->outputs[0], format); +} + +AVFrame *ff_default_get_subtitles_buffer(AVFilterLink *link, int format) +{ + AVFrame *frame; + + frame = av_frame_alloc(); + if (!frame) + return NULL; + + frame->format = format; + frame->type = AVMEDIA_TYPE_SUBTITLE; + + if (av_frame_get_buffer2(frame, 0) < 0) { + av_frame_free(&frame); + return NULL; + } + + return frame; +} + +AVFrame *ff_get_subtitles_buffer(AVFilterLink *link, int format) +{ + AVFrame *ret = NULL; + + if (link->dstpad->get_buffer.subtitle) + ret = link->dstpad->get_buffer.subtitle(link, format); + + if (!ret) + ret = ff_default_get_subtitles_buffer(link, format); + + return ret; +} diff --git a/libavfilter/subtitles.h b/libavfilter/subtitles.h new file mode 100644 index 0000000000..4a9115126e --- /dev/null +++ b/libavfilter/subtitles.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021 softworkz + * + * 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 AVFILTER_SUBTITLES_H +#define AVFILTER_SUBTITLES_H + +#include "avfilter.h" +#include "internal.h" + +/** default handler for get_subtitles_buffer() for subtitle inputs */ +AVFrame *ff_default_get_subtitles_buffer(AVFilterLink *link, int format); + +/** get_subtitles_buffer() handler for filters which simply pass subtitles along */ +AVFrame *ff_null_get_subtitles_buffer(AVFilterLink *link, int format); + +/** + * Request a subtitles frame with a specific set of permissions. + * + * @param link the output link to the filter from which the buffer will + * be requested + * @param format The subtitles format. + * @return A reference to the frame. This must be unreferenced with + * av_frame_free when you are finished with it. +*/ +AVFrame *ff_get_subtitles_buffer(AVFilterLink *link, int format); + +#endif /* AVFILTER_SUBTITLES_H */