From patchwork Mon Nov 29 19:48:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 31817 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp6642703iob; Mon, 29 Nov 2021 11:49:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDWVaKuHoelIS838tjtCvRvQUWyyHZIoafyQNQyK03SOs/Q9VfbjJH3GR2EPFxE5Ysq4LO X-Received: by 2002:a17:906:b084:: with SMTP id x4mr62009331ejy.214.1638215388358; Mon, 29 Nov 2021 11:49:48 -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 de8si20715438ejc.412.2021.11.29.11.49.47; Mon, 29 Nov 2021 11:49:48 -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=Tcl2GxLI; 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 A756068AE68; Mon, 29 Nov 2021 21:48:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08olkn2058.outbound.protection.outlook.com [40.92.47.58]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B555668A868 for ; Mon, 29 Nov 2021 21:48:13 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XfEgBjPcW0Sysw7YpY73yjDlvTCESEVEBOqqz36YQIeqIWSJNqW7LZNjydWr9cPYIbmrZ+Io0SQ11ujhJXFkdnjPuuEdrVFRNX7lg9jXjnw4DRx1BmZYWy/TDjLEz5ROZuInaqoT0DDnYi5VciBGISfPOCSvluqpBZB8XY9p2C0IUso5VBSasUu7OBrn3XpQg2dVYiuGqt5xm/eCa1GScC74CStDO0vs0mVAct4A5NLErIqwtCBJAMyfFLZtFfQDkrgMUjh3t4AK2NiUH4VnN1LabODOTakMu4yZIb4UY4mHZd6aXonPLv1KeByc1c6DDTYn5Ljb2+P3+ler2H+hQw== 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=oE1SGefma8rjWvtoG9us6qAgGNY4yhNIb7zU+E/8kBU=; b=HZYKrGNE6vrM5GgMCgY455QI/YSKshOzeoPy/uaFyLoPVmc+xLYVLiOecbWCvb53VgGZBtWZTjFNa+F9kuWCCYl8r5WkbGDPYtpw7pStkQXk8eR7iukON6w/GBARJ8l2zq9LA96nFMBgwvaPQkvwahwi95KdjoGh1o6Xt0vRUU+fAVDUCZxPujwKqIS0nsAp/kyNsJpIemDS3phxNRUWYEwsvlTwHcY7t3mfsNOTGmwYNPfRCVV3Y6sywuOm4xZPCg6LzkW1kZm+ZFaLMGalfOj+m+KwU4dxfvtLnec2sFQwi/dD0dlbHVQvXEJJqvL+Hhyook7TnMOeKlF0SyLyDQ== 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=oE1SGefma8rjWvtoG9us6qAgGNY4yhNIb7zU+E/8kBU=; b=Tcl2GxLIVcgexiXzScYPXVSngw5vVaeHxddEs4+gxXqZ4nYqnxrruOxSJg7cBPWx17zmUyDIb+EQ0aP0P9aUecX0tBayqTTQ+vGgG+wH0s7CL1OA9DwTgXkMbknQDNpTMAiXW7LGzUAYH/Z1sHQDeNarhqtFhwtVCRiVE4JgzUgMTn7vN8Lg/j1pT2kXksNjGp/kgEPKVtLn5AQ+3+yuaRoioO1Y1JwpHf3I2FkylKk3HmAu2z9IYDp4PK6bEozSTh9Ru4doNvGCWx1Uo/OHS+2V43ub1HaLPJ+b2g2IGA42H035bxcQaYapDN1p/Lt996Z3z0L2/iZNGC8/yWKlrA== Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:b::20) by DM8P223MB0223.NAMP223.PROD.OUTLOOK.COM (2603:10b6:5:316::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.22; Mon, 29 Nov 2021 19:48:13 +0000 Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775]) by DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775%5]) with mapi id 15.20.4734.024; Mon, 29 Nov 2021 19:48:13 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v18 08/19] avfilter/subtitles: Add subtitles.c for subtitle frame allocation Thread-Index: AQHX5VoLi7hmF5keCE6JsJ8DXx9m8A== Date: Mon, 29 Nov 2021 19:48:13 +0000 Message-ID: References: <01697a451703d7b506c60d75c953dff19bbe05d9.1638214931.git.softworkz@hotmail.com> <3d54150a3bc909d1c4750ed07a00341f5c04ddb5.1638214931.git.softworkz@hotmail.com> <3e076dc07af205e1419f8bda2315bd115c5618cd.1638214931.git.softworkz@hotmail.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [B7/YKFs3SgXHwRX5b0sHjwOgufr7KB6g] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: aa00c758-0feb-46cf-d7dd-08d9b3712df4 x-ms-traffictypediagnostic: DM8P223MB0223: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 1kveSfMomJh5a22reESrxOvSpwC7jhf8NeGZO0WrdwpAxlSulH1857O5RpQWg5gevVYD5hqzc3Oe9hnz2XHwimQJxZHPAeMA5YR25aFoUPmJuO+z7U9j4cmIWgZ6C6QgTUJcf45zq5XBOtVdNYZFNMfvQj+kW75kh3r1VwW/ro+0+QlEqWBSYodMUemwx9YR31e8WTVyTDmmfSAf3U5mY7UAgcSzt3OfIx0OqA3jeoyAr7QwrMEloAMAS+u/WR1hwoJZZpwIqiByJAl7yKgTzgk7K9CkgGNdh88kw96Z5zDn9v1g7B2VCzDNZI7tsGYZTpvwoQtjdr2V9BTLgvEZgwGso+M+wJHR5JA7mN7JvH/Two2dPnEzDzNFoEdVwSG9ITAB76AOTl6yui8HK676ewSJujq82TCUs1xc/VRjelrIuGa9oT9aNhefwXY4nhGa210NQqgpIi3XXHw6R0L5WFe6WYIrf9cq/i9PqOeMv0ndodeEiCnwf3u4l2Y5zgCjKDqgnDLUt6xo3WlcWC8zAOR+ledytXMm9FoXa++exdE2GRtiGcRxQhXTv6S49/n6CQUDlGFYHmANpi8DLgnY0w== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: XWxMLABtjbE4Zn1/YwvTK2T7oec7cLGBsAV6r9oOSM0NfAzbPljeNnIXPPQ2mXLIScUgNi81LztlEL9y9m/Mh6u8NLBKF45mcsnwf8AcNw3wfk0rDTosv66jImc+DUMHJcmCre/Kxot/AmbARw3CPa8fz6FpolxWq4DNpf5m/z7acolMGhshgxVXXHkIzUh/B1wPpKdbtofBl4gKreHwRBjiivLFWiG6rd/SCMFOl6J2K3GBv6NtzsQsWLqOyCbJmrxQSnK+Dk3v+rMAMi9ApM6FPkolqLYirqfvNTyIjT5/1lNeIcXDhCcZMeuDAliEouAtHG40kIxUqW64dkg1+QtQq5BU8vJF7j3FkDfFcCk1DoCOz+Fdbl9usa61iUUXx7qJ972W/YijmN/8IvTiIrPtl2/cdWwXsqyNkEcEhaya0K5LBkZRQDdBSnImrLDgz5KAeEMF6Bd/8+34AQ34ydinPV7jRqKd9Bq6PDJb+MLZPLWJnZ8Y++sQZnV982xVEuS9AUhLzBVuDL2yxwDFZgsWpCWD3Kg15jSD1wuvTcvoX2FZg13Pn3RQ35PCvQCpA+BmHGwN50PH5wxkAzuW/f26vDbjBiRG/j8ZiLEYHqK9AlcDw8ZttyUsm9DoltaX3R92MDvv/FAdjSOOQFMiMOgAQMkvU1X2pfPFv5R36q8eYl6b2ETGdC8p4Xu66MTlDeYn7YpjVYb1vDCgV4AUYw== MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-3912-16-msonline-outlook-1fc6d.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: aa00c758-0feb-46cf-d7dd-08d9b3712df4 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Nov 2021 19:48:13.2377 (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: DM8P223MB0223 Subject: [FFmpeg-devel] [PATCH v18 08/19] 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: F7mOB7W6sKkV 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 0e27aeeff6..99f3047965 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 */