From patchwork Mon Dec 13 23:40:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 32460 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp6140062iog; Mon, 13 Dec 2021 15:42:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJyAvZ6/uCuHYjjdDP0Jcx9PXEDRdNWP3JEFIin36Ldz12C/m6gl+/B/X5eDgnX+HMesND/l X-Received: by 2002:aa7:c946:: with SMTP id h6mr2784552edt.190.1639438925450; Mon, 13 Dec 2021 15:42:05 -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 qf36si25901852ejc.35.2021.12.13.15.42.05; Mon, 13 Dec 2021 15:42:05 -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=eiCxdCGI; 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 71ACB68B094; Tue, 14 Dec 2021 01:40:46 +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-bn8nam12olkn2082.outbound.protection.outlook.com [40.92.21.82]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 37AE068B097 for ; Tue, 14 Dec 2021 01:40:41 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HSn+bUo6I9n37NhSYPi3cdDTRNDFH8GMn7w65kwStHXyPi6lmu5pzEUQtVNkRtRSiVICTHu1Dat964bXodkLjYC3OKnptYrw9eyjxNax7Pg4kwVuUxLg+oh5whLijaBqB+EPW4aZZMaRSvtcmtEPx3awyarfgLlTcFQ5KexdwPbNWUNnK2BgfPOVDDZZBLj7tY46o7pmoYgBfQKsPlRxNnBFZZRmoK7/cLO44A7Nqgk3WEi7PPdM22DJgvhLGxab7ZeLLK5DuzJSc68r+a1xMjZeP/FFHfwQXyrP421FkYTt8ruylfOUxIoxL0HZ4bo6rOEZhedhJ5QbcOuZW9cmWQ== 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=OFPGP6c/q3W5r6K7OtjtiKLBZ7YZwwGUi/mkkxikzZM=; b=b28i5hL4wRB6L11GpqGPsC185cZbaBTw0MZXL8NrWISNZraQK+ipyvj/SNwrAnlhj1vKLyZ35rv3e0EtsrnMWIUcNUS9+GApNEkwfE/mGCc5PbeDh11zfOVS4Xm1T6I5IEjwibTQH5UbSN4vQMbiJuA0QAFawEKbWjg1EyJJgnuZD+PXRmr8cxBq3iH+M6snJxyZElCvZo9jVpxTW6y2SZ05y7fqftbEPYwBPSTgR0EuAge2TAHNqgdgZHVD8GW8vNgr1WIEzIMS4GRX998+n6dfQzp3NRtZcg43wJGoS4OI9y3W0VayaS21hADt9Uqfab9EkOXLO0d3AZGxmERliw== 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=OFPGP6c/q3W5r6K7OtjtiKLBZ7YZwwGUi/mkkxikzZM=; b=eiCxdCGIg5tm3zqWPC+rl74e9QrdedCmU8hJVLiEapTxJvuaiQXBsmat0T67A0wE71+WA8qVbW4AJ78mytqH9v/PN4t10Lil1n4BnavltHT38rVABXlPLg7YxZqU+nF3qZLCI1JOQTwKYYRVed589sWUSOLZXvUrEAM/5MZbncUit3UgxIQrOA6Q6lrhwJiiVeqRh3P3w8+L13Vj3RTuFe7rcExeOwIOLM05G3YQ+f61gY2EzK+wLzktUB4YaHbB+FCsfiPPds0pAc3I/DpmKmvY6wYXjrPJ3bE2KDzpLJ1LcOY6aW7xKh5124vHymlEbWWYtUDU3EVSD+oLftWxNA== 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.4778.17; Mon, 13 Dec 2021 23:40:37 +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.018; Mon, 13 Dec 2021 23:40:37 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v24 09/21] avfilter/subtitles: Add subtitles.c for subtitle frame allocation Thread-Index: AQHX8HrUp3GaD0y7bkeWVrmfrkT1rw== Date: Mon, 13 Dec 2021 23:40:37 +0000 Message-ID: References: <1ef42eb01b3627bbad539abd46206f320bb39697.1639438462.git.softworkz@hotmail.com> <4148d77a82d4b7e229fc81ce9bc1bc06904533f1.1639438462.git.softworkz@hotmail.com> <2ac798924ee984010d2e85f00bc992d9aa106171.1639438462.git.softworkz@hotmail.com> <300ea7188b331ca5e00dd7e04c03df8aba2a99c0.1639438462.git.softworkz@hotmail.com> <9474726b26f0d3e8f353d07caed2fbd33cdf473a.1639438462.git.softworkz@hotmail.com> <424522c96b5cdf6b03faa6bdceb1d25449463429.1639438462.git.softworkz@hotmail.com> In-Reply-To: <424522c96b5cdf6b03faa6bdceb1d25449463429.1639438462.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: [u9JThvXlugyYMTt9JjlQrJUz1Qo7/w/p] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b3a16f15-b06f-4949-0b64-08d9be91f73f x-ms-traffictypediagnostic: DM8P223MB0397:EE_ x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: umvNPp3WNtDbNmmiMuxTa8T7sru6IZoGBuECJT59zlr8mVXv7d4qiob9EyhYjhT4P9Cr7XeJO5v1QiVX7tY63zuGVESlif8BZdDlQ2JP4VQhIDFwxlTw04Elch0eg9C77L42JqnP3MbWW4RiwjXiRUtDEfmm19AoXtZPq/5Xbsaq8B+DZPw6yUFxJDUmf17cxHIp9pQyTzIJQq1pIsPUxvnVgYGjpL9nstsXd6SSureYXYuCmSJh9DRbkO1BID1GGHANp90lwiTExlc5Q2qMuOMYLEUUt6xdFksq8tvPwXE795HS/kru0hp7ONGwZ6HEZeUfKXjx88/E9IuDnSeniy1wMvstu+a1TXgIuSjSg7AosUKrE9yEwQ4Q708zUwelAklRYSs5tsaP7iUVM3GI1qt5q1DpN3mJWaF5uBqfnS9lEHBk3QVNpvPbzGBWOi/c9iYv2clMmqxnBxgn7F57N3gfHT9qPEIzaHKpsn5Rs21fzWEm0UeAJaITqJ7EjMPCrhtWY5D+prBthcR61ixdMnhYgdHMz4+JFQeasGkZlWqSy7MwVFX1LQXBv18t1a+cAYgst5H/XrDJXecyoaxB5Q== x-ms-exchange-antispam-messagedata-chunk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rlJWXHiyWnFO8FGV0afqMaRlMJp7vJwcwyaBymOe6x/CE3JqRtQKtYM?= =?utf-8?q?/vCfyysXR2cgBZZXEESMxuF2f6HsSVelW5XE/nz0BZiQ=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: b3a16f15-b06f-4949-0b64-08d9be91f73f X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Dec 2021 23:40:37.6657 (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 v24 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: QDRzodTMu6T4 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 2fe495df28..a2f61d39f0 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 */