From patchwork Thu Oct 21 03:19:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 31188 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp127216ioa; Wed, 20 Oct 2021 20:20:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJys3bad+Cg5EnblLwuBKoJfFOq87kuv8iXf1Rx2R6qgI1IVjqXApuny12falLqgZ6GiChBv X-Received: by 2002:a05:6402:26c5:: with SMTP id x5mr4043459edd.297.1634786405481; Wed, 20 Oct 2021 20:20:05 -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 b10si6508403ede.76.2021.10.20.20.20.05; Wed, 20 Oct 2021 20:20:05 -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=bgiSZhoA; 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 5ED4068A7C0; Thu, 21 Oct 2021 06:19:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11olkn2034.outbound.protection.outlook.com [40.92.20.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1A4E368A5FC for ; Thu, 21 Oct 2021 06:19:24 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aQ+co/sQcxTJV0KiKzWE9MzycFiaw5XNJ4PGFyEUu5qSbuLF5scrJwkEUqNGc5iBp4iUcQVGYAiaIMarTJmz0DdGkUUv6Im7aXz8AdUluR8qRibLf0hHaoD643BF5JY05LHHnOnOqAf1q7vnvi6/0G3IepHLKR2MlxbAjxI8UJVzyZAOJm9h3RXoNO7WuFP/T561MTDzP/EuHyftK1XYUmE0FKlALse6px1/5W70CuR+scXos41GQVpZoi8FVk2GZqS1IDXFojS2+5R9OMkDw+OPvvykGVHX076MBR1nwdYJ8klZtO3ghnOgFmYho0nBh3R87g3m94a6kMatVAOvrw== 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=UE03tc8hxvDSm/bS1nJjmJxFLCoUuCvqiHNQe7+rTKs=; b=XAE/G11UShjtdC3L4BAlTD83Yno84HnT0CLiPoyxZO2H2jZsQDNJUdUbhvlTnHa684CTI5A/+l+EfhLYmQio1nWmxhexUMYgJIzk1yOx0HkWFPzbbwMIapt8lKNB+zFulbnm6c53/DnVWIOY5XrQ9CU/0TlUpdLm1QOiO9b520VjWt8JUrLoHxJalYLiiVx7v5y++b5keB2QoBSFCoEVxYJxsQk1UuvbpLtVXg9RUEeNp0YAUhTNn7oW7CdGRPnF2CABIoFE2yAXH7ECoHzVVjbfg1F7x26anvpJ6wEa5kWR0rhgTkt5FX3D1ZQkjFaxAKo+ez3TZ3KDvjFmtVLTYA== 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=UE03tc8hxvDSm/bS1nJjmJxFLCoUuCvqiHNQe7+rTKs=; b=bgiSZhoAnndptOfRbgzW42vXZ6cZQrImxsIGsgpFjOc2eSxr/stzU8CsmbirTRys7mOIgrtPA7WQkL2W3DruRoJpkD+VOht+HL8ye+PJYa1dm5B4/HWzwGEvkJiWzBKdew+FsHxMLWrE/hhYzlLS9EYXEfire2dSjbotvRZfRjAZSTv6gQjn+LK+6NMe64ZwZoEKBbrtca4O+QO5AeztCK/JoQZtV167NgnPWR9N8LIQd55E775NtoPVGNp8fGvaS1cBe8pACbMylMN+tCJGVAGAiwzFo8zbMcnfa0s0hFDW7oBnWfHLePZkkFTmeqFKWdL68yKKjpnmtMMsBmWtNQ== Received: from MN2PR04MB5981.namprd04.prod.outlook.com (2603:10b6:208:da::10) by MN2PR04MB6238.namprd04.prod.outlook.com (2603:10b6:208:e4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.18; Thu, 21 Oct 2021 03:19:16 +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.4608.018; Thu, 21 Oct 2021 03:19:15 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v14 04/14] avfilter/subtitles: Add subtitles.c for subtitle frame allocation Thread-Index: AQHXxiptY6/25zLJGUaO67wZ4nGilw== Date: Thu, 21 Oct 2021 03:19:15 +0000 Message-ID: References: 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: [6oBV48q6PbCu5jBDEy4lWX37fjYZ7snJ] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: eb960891-55c3-4afe-2c7f-08d994419009 x-ms-traffictypediagnostic: MN2PR04MB6238: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ZiE06VGyOGlGRzFbyBRoalt4DrWJTxLXnpoNbXdokA1GOZXHzuaj/xWx4sptF4MhEKJVxgxT4NXCq82A77qPm/uNEreySq3uP2RGTQTwtWUpKRH51Zv9z6KHsPE8wQxgQ6dT3S0ShHauY/R7FuCR7qeyGH3Va9IcOS5RXEO7IzuLlcLU+KqGIyJpobVmP+pJ1HufyCw9pCtXJKlkuQsf/x1CVpb9HWw6JhwsxaVlgCC1aJOFkwi6SJisH4KNPfDwvWEw5lmxUh+w30QJPQ64SDl3+aSFORCse9FkmXxDFjW+9kcQt3GaBz/MP5/z1Jy1YBUOSp8LfxsnhhZ74UGo5NDiE/kqfJTXtmsXF+ZyT27M6yuhAqLEtv/opxcnh1bDCeBvLx0rNjCKKsYoM0ykq9Y/ychWzmicjK2aSdsJGgopsHsoxnxO2+c5HHGHVe6B6GhcClEq8D818F92P2cUZHvZ366/MebYIIUCloxkCItKtkzeIDhIAFW1IPbZs1WQDDGS1OaqvAmDx2egEYp+u0oigYaUurEL2YERkrS2Lt4= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: t7fGbHrriDxm+ZBzawoJfX51BzrX1Pn0SzfNYg+fFKcWQMqkbajNzX+3ThZ21bGilHT6ZjZIoUcgRE0qo3CJ3obC/q+nPRsMra+L2NlzxaCwewqVFAjPay84K+8AtoGosBSqwTe723q1hdu35PJQRw5i5kFdDJT/ippNwaggBP6xDM6HN/Gp7D8vTKihQodj/sJtG0eQGvNRYJKz5HjWGINYtNEEbfnTNhSqCIbjx3SJLPwrTsgsqgUuvzM2CLgGsHDaf/HJ+AVzXlE1fzxkH7yucPVQ9gc0seckO0Y0ZSmUwiPhylQpzukzWnCjM3VYqIW8wF37rfeqMyMU3QGiYed8g9mlYc/Vk6peA0zbez9NoD89NmsTZC13nw+0/qmJJiQzz69HfdzbLBsj5QCCWOiEWF6Hm/9HJp2HVI5s3ojWhOdZ/oXODpKbc5UziLrSLEmIFfDmsDGzbJzRmnkoFwRsIcO/+GMUhRF6FHaISXe+QMxzVSIWzHjY7u1+ixegJf7RZvYFJWmSkoaulkyTiizafrextMD8JjMIfMPdl010V8QY+K5RNLdAPeU5GFLxT71gbLUmlwxJ17m+m3+EOLAJZc+YLs4WJ6dLyjQooDJ0/YEUMOsHyAeO88Rv8R9P7SQ6KMLXydHXBC8vj+BYJMvoVQhCRwwAFA5Ys6DSz3tDxeruX1LnslGG99eJHVS1RjM5Gc9WxJ/4x7QAFgkrMA== 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: eb960891-55c3-4afe-2c7f-08d994419009 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Oct 2021 03:19:15.9481 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-userprincipalname: softworkz@hotmail.com X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR04MB6238 Subject: [FFmpeg-devel] [PATCH v14 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: KsGPILSm9Az3 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 94772576b1..5e9a97ae55 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 */