From patchwork Fri Dec 10 21:37:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 32272 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp2373548iog; Fri, 10 Dec 2021 13:38:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7HNvhTctNWjT0OPqxItH1aIoHWJwvz3bkH5v65MVChaA8QCqWtLBjjMJcjzGqsS+jQsMB X-Received: by 2002:a17:906:eb8a:: with SMTP id mh10mr25800478ejb.198.1639172337913; Fri, 10 Dec 2021 13:38:57 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id sb42si7493425ejc.480.2021.12.10.13.38.57; Fri, 10 Dec 2021 13:38:57 -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=@hotmail.com header.s=selector1 header.b=IjBzYHcq; 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 0E4A568AF2D; Fri, 10 Dec 2021 23:37:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12olkn2011.outbound.protection.outlook.com [40.92.21.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1251768AF3A for ; Fri, 10 Dec 2021 23:37:33 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JbGhLvlq5RpRlGrLIwre32A4KRm0ddej/GLVZFSQ6EWhPioLWMV0L9CGvJnzadLW9CJ16l2VLKPNWKgupAfJfIc7FTabrbuF3QI+9gL/CYX5a1mz93w667GX37nUuR+l4Ma2IlrEyRdv7VPHBUI1s5+2EwtvPFIW1Oamy+sXAb6M+v9TnFn+Dw6sBqF/YufIZH3wSZGDiRBIFmv3WWf6cbcfIbkwJ4FUKBSyaSET1j4ijgd/xlPiJZjlMBtSodBL7cYTfVkGo3waKX7xdBS3ogeRPPhSH/Qv7ZjBOyC6e5OERyA2l/YLWgUqW1eLm0O8Hn9ZVxdHBrBicCydGAGWtw== 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=MRY/E5+NIlzJScNIyQUozlVnJtCJhDhtHCVpijJk8uM=; b=MeSEAEJ1oOzdQLPao86lmxW/YZbKFJ/YwdZSk1gFqdDcVUvfwMPMRr6QUaT5CRNPXGRO4W8WEpAitzIRENDMb+s2UzMOCDMfu3wY12t8vtB6X9K4zjJgRSpDtfai7R6bGRP2KRofuV0WRWfA8hpw1pWjI2hxexg+9NXOsBq3z/ZzEl1tCxlO1wCnt/weqglmH9cuVidqU8+/3PmhKaBzWQr3Xqev1YzqsQMHm6CQfwizNMblxdpfpm1b2hhVCGxpfZ89LUSvZU93wxw5Sa5fUnVBkWuUyTHEyAZQ48I9fjIKYimWqdDQy14iWrDuDXKtmGYFHdpAqQTvymP2bu58EQ== 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=MRY/E5+NIlzJScNIyQUozlVnJtCJhDhtHCVpijJk8uM=; b=IjBzYHcqfvpBbJ9VhxH5JTQ9UbQJBuB2q7/RutzSyNXFWdJ0Kq9UpIoedrOxVwZsDqcVRAe4f4fAkB2QFYzibs8WCoyNT7vXZ9LJAy/AzX4b56SKSmIhm9JSghZegaZrSOb94o9cT/6fDswTjkp1HakfS+1r8WQ4mpkGTvoA4peZkxgfJTr1JKF1zliKnULBke8GY50aKfaTFUcsIe3IzYiB1mxqmUju6MjDK71nwy8wi8GerSVu6PGTOEKvC83yqhkymhlaWxi9u6YFIjqryrX9wbDcGXXWE2iMOv1LwGeJ7ejsjSeEjNMR7bR4z9g8ja1C3RUL8SWbYhzGGitN3w== Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:b::20) by DM8P223MB0397.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:b::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.20; Fri, 10 Dec 2021 21:37:31 +0000 Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775]) by DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775%7]) with mapi id 15.20.4778.015; Fri, 10 Dec 2021 21:37:31 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v23 09/21] avfilter/subtitles: Add subtitles.c for subtitle frame allocation Thread-Index: AQHX7g4iiGzA5lq7Dku29RpPb/MJTw== Date: Fri, 10 Dec 2021 21:37:31 +0000 Message-ID: References: <84c6ba3b99bf387e818d59f2161009ead8fb5767.1639172095.git.softworkz@hotmail.com> <0b41271ed30b530c1d55a9b824fc8bbbbd14fe5e.1639172095.git.softworkz@hotmail.com> <9f2875d043147119351f59b6410d718d170574e1.1639172095.git.softworkz@hotmail.com> <62a926e2d86310039653324bdf2a856f09a0fb46.1639172095.git.softworkz@hotmail.com> <75bb9ceffef9e8e2d05ffce8a51c1991d5d3a973.1639172095.git.softworkz@hotmail.com> In-Reply-To: <75bb9ceffef9e8e2d05ffce8a51c1991d5d3a973.1639172095.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: [/0TjQrLdZS4o3XAstQv6FRdx2htRb/ub] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4271f08f-bed2-4e6c-dcc9-08d9bc25456e x-ms-traffictypediagnostic: DM8P223MB0397:EE_ x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Kyz+82qESiHy/oopYAhr7oaxBzssVFGRDa71HsUyGqwKXttbRYECIXWgvtsoVKdb2pt4Bns3XoN3IfE5Acq+KyeSWtBXYstKTHgEk9QTOG+wKod9C+CsqZ+fv7U7uZ4pZE1lrQKBtbRX5s+F1asV9slVuNI2dr24uXnNmxLCTnCsW1Ute8N+3ZAPtsCUGwoKCtzm+rf+XOsTQtRT7QFZ5pFaU5AgZ2n8n8hi2g24mrEt8BrVRPdZEDJ5/Z29Ar/SpjuPr2NrRLJ4wJ237QsQvn7t4Klr3lmCPJzH7ew16Y9LjssRIlUYxrAYCZnbgs2LH1iKJ1bP/vXiuJ29p7CeSL9zhycQ8UvuJqe0c/ibqj7mc5dnpYwf5UT0gbNuFr9a3aOZOo3N13BhXfbOuA5OQa1rGT1dJuW58klmeng1hOCTB8e4b1BF8oGIJlLBD9l5gkWF1OEcRp1EM2Dl0gHftL8IEUfEHtv9/flUbt+zwFC2IqERYFfGLLtaBmD9rAYUXgSxvaUhBBgfHPFJaLn5OkBi4BmYOT5eD1Ez4yqS9gm2EKnKATOfMz1SajqDWZQ9575kAoyrVKWkQcoOMSS+qQ== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?oX7hOCZ0HFACOeQKE97fpTIlaBeo?= =?utf-8?q?Ew46pt67DbZirNst1E6VVqPWvcqrrLJ0X98c5vWfZ6FvXYkHI20mNZqcBv6imZsdb?= =?utf-8?q?pcdpjW86JRPrSqvNe7i3YYmQpvjXj8hYMcWC1XZV6dmekNu2KYs8qTD9R+nxUT9y/?= =?utf-8?q?hOWHBMri1ICtFBMHr/MPFVDKm6k02bDU55mBE6TP1qfqFLTdY8VtrRB97qOsI0bsX?= =?utf-8?q?YLN/Zl3IVPBZFCzKJFVH2KSJlgiGkfCUqg4YlmghrwGTcus3MAcSMQilgofQrXg60?= =?utf-8?q?55T96zG6T/ISD1rpsG7Maa71Yt8nkbSqtzQfdb8bi4JGb20g7A/ctMijdusZxVHsx?= =?utf-8?q?bBQcwDo/UYUlxTPGUhpboGQ5pgcXjJe2hRYl/jF1aYA57bSjX065KF15khWhcQtVc?= =?utf-8?q?8SVIB0op2pzl7kYY2U7EeiDxzBAMAfKFMhPtjLWxtsYsNL/ZckI7TiR4CZytSzJXu?= =?utf-8?q?kVEQldVKyrGow9l60XdgmIwRrMCDKUMPYA0seeaE/EaOk+FPm/cPuSsDtDmdSGEaE?= =?utf-8?q?eOfUtSdPuGbvp62LCYNcTy5pcgIsVN/OFO4o4UuT4QjOKLnl7rAho4XLBeKny7WBa?= =?utf-8?q?lFASRiOaCClHMGEyVHCYQSmwQirMVGWw4jpOMY/sYtIPm3gPKbfgauDIaZH74noHp?= =?utf-8?q?ESHthXJbGRSNk2LRXWD9LdboERexXq9AwMB9/ahus9ZROt49pm36pBFnbv/Bg+k5J?= =?utf-8?q?WkNXiwETwQanWXVV42T/4vZQ0kyuAKq5BGDfufiY8rqBCD8alvp1rBqve5b6zANDU?= =?utf-8?q?a4oaor3VvwjEOlAOLeWKN5gMoDd7o1A3nGoCa5q4er9wjHcFtLg9idMuijThNEI9L?= =?utf-8?q?27AXtvkV058+eo1a1S+bFacTVhe+ZrufA+NbqBb+fZwOSfVmQHrzsVkLZrFewukla?= =?utf-8?q?2SEjqPetpTlwKdUwi6GrOroLhY0sG/RjdckevERMMkpA=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-1ff67.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 4271f08f-bed2-4e6c-dcc9-08d9bc25456e X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Dec 2021 21:37:31.3156 (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: DM8P223MB0397 Subject: [FFmpeg-devel] [PATCH v23 09/21] 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: BNg+blDLpSIC 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 c8082c4a2f..664566a18a 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 */