From patchwork Thu Nov 25 00:48:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 31638 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp11414878iob; Wed, 24 Nov 2021 16:49:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJy0Uy6EjjrPl6B4KjKdpWTWMflF3Xvg/OAlnkn05DpxcdCINqxJkTaYKVrrmr1E/wI3eZ7z X-Received: by 2002:a50:d492:: with SMTP id s18mr33647086edi.145.1637801339856; Wed, 24 Nov 2021 16:48:59 -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 r27si2998221eda.484.2021.11.24.16.48.59; Wed, 24 Nov 2021 16:48:59 -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="bIaAL/i2"; 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 3BD7268AC65; Thu, 25 Nov 2021 02:48:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10olkn2043.outbound.protection.outlook.com [40.92.40.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D6CDF68ABD1 for ; Thu, 25 Nov 2021 02:48:30 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FhtrQt0AWegwNEFUKhiEOBHEYYa4dr/K7bWzfelkd4pMLC7eWBNOjrOxmMCtlM6VuKhr0LeVIFEax6xDJu3b1jNsNT8lNj5zl1UwbjY9XGn4/BW0LWM+uk3NrtMNZlUsclMArzEOXDgskyM6KCKtc/t27C3QeNK1CPVx2/nzR2LvyEVQhYCwCoBstf5JxyGGSrITCdzkNx69Fwzt35BySWUtGTdrlXXDWTuMCKLBgv7f6pIpVZ0nbe6DP04qG9g6L0lhpgbsBGnjKyZc1qBCXW+XIcQgu6MX3qaHleTsobL6YZ+mHaRsulIyaKZIlv+XJejU5QYfT5bqOwoFgVxCUQ== 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=VpxkwamvwCx+uSagYpcVM5oWp9LwG50LV2xdPP3BPxm38rTgAL1B1IlttEMyMrnRgfrGZtGccqrX3/UyK9VGQ3qZiPactnf07GNaHvyJXQ4Rbw0kM621zwwsF9s6lrOt4zaBPUJMMEHV0wvEwptgY6VhUkj7jQ551w2wAIKsT32IE+PHThJ8uNIXK3lCfBhFMee5VW/pLv/aZCDhL+k6zIZz+zGqb8348JT+TZfs9ZCFToNzkktVnkSPTHDRlvDp3B1AtxXDC+N4RFZ5CLITXwMi3EHTgFwPJ3c2b0T9KkM+iAmT52UJsszmkCmioGQHCFwZmz5zkzl2+r6YIlmvTw== 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=bIaAL/i2NOtLE98zEkJhAEWkqdHBWUUlXtpRiUEL5/X+H1LSTpFMSY/3FTaR0nkt4nGlEbJli6ejj7eNkfa2Pkw5zDXeknOWfmIY2WKU/6WXo3mYSK3ykSyQ5OxTkUYo308dHLVT5WmtQvbTOnUJ6p/7BCJjv68Hk72alwoIwbbB4lw/W+XepGUR2acrkTBn5RCSpsit0CRs5sJ5zl2dnGqHrqCL2EcxLpmCIEC9zhPb6gl7PsQ2LxQo91a50JU4cx7tq1eMsD8LzSlDjXkQyMSCuENrFsIodmNYLown1vzg+fCtCfIsdrI8r1en3X/SgMjG0qfi9c4KbIeM5IiFRQ== Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:b::20) by DM8P223MB0063.NAMP223.PROD.OUTLOOK.COM (2603:10b6:5:316::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19; Thu, 25 Nov 2021 00:48:18 +0000 Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::8c05:4078:21a:53fb]) by DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::8c05:4078:21a:53fb%5]) with mapi id 15.20.4734.020; Thu, 25 Nov 2021 00:48:18 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v15 04/16] avfilter/subtitles: Add subtitles.c for subtitle frame allocation Thread-Index: AQHX4ZYjFozSuH4BDU2s/Dly0lr7VA== Date: Thu, 25 Nov 2021 00:48:18 +0000 Message-ID: References: <3815d024795f567ed6215bfcd4faae23dc1b7ecf.1637801132.git.softworkz@hotmail.com> <7c5e4813b96e3517e377b2d3d8031b9e083adfac.1637801132.git.softworkz@hotmail.com> <7ab9f75e090bd6e9155fd773714781d28af68049.1637801132.git.softworkz@hotmail.com> In-Reply-To: <7ab9f75e090bd6e9155fd773714781d28af68049.1637801132.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: [NCNyTyCiC2ucbu+LdzWN3kwC0DUqRhGh] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 74194659-43ab-4884-e013-08d9afad45b9 x-ms-traffictypediagnostic: DM8P223MB0063: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: rxW3QblpRw7k4Zlyp7PV1H68wUFQrZlgf7LotPT4BVgoI/6Q7/jNOjtZNTiMrxMoeBjXBtSCoLT6YRm4/AEGateOqVqHbbCk/+cRBkZ9H0GND604VXWwNh0f6rFYfo4vcWJQHztFrhg2Iq07vEBCG6ER1qJhMO+mSfberZbi+OdrK2llMl68x6A5pCJwed3Sz5KbfMm4vWywKS358+Gv022cuutXJsFv1/w0zeO9+8R9mMd2K2oDIvTDUY5bYF6WsPzCZIwKrOMtfoAQlRCkB1QOzqZRDcrcuVeEFtAVBpIp8BIObaDZwUHjVnLU+cL3Qp3+rJGTTd+MAv0rAYfWANqoHf/NcYdfk+Gh+xkmTc0g4yR84BhVYq2FmVYrhCd+f37OVfvILHtTJhHkqqqPONMyM2uX6VvPdj5T/cnWFdOAk8U6MXTNCwv0xTMFwabGmFzmts1pzwazzZbAryBuZW6WkGHJ1jyYxjchQrs3YO70tpjilgTRnL7gJJPm1ke3dRGizmtdhEGjF9+OYVxV3vATI1FQ7phJAYSk7lNKDHmxZ6xAIXcNUYe93+h2BmCIdJEsOkSXqujBd3QFWZ00bg== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: tdotzpvqjpsOLPeO5d05e8qoI00PZHalYhmcs3GJR5vgCkfcbbNVrLg/044DpJLoB0LddFpK3kA9Y4ku8uftwb8oOqzlKVRTNaZZZJjOucX8SvEfkuYF7nUSfn5kt4qzR8XwplD2mj2fGEp0+2P+ifln4wIxmw40jm+dcSgNd98spxuJWZ+p8cldMKgO7GlONZSL9VhW041cEY7CC//XxgYFO/wnxALiAdaqqroiYI5gBm8jhe1+51VdhForEaCtFZ4y9MbiG9SXsHckp4rGlV2A2VZJExqCjgdG8Kakvpn4msTcUlfXMzlNmiubxLAkfF7sYLUbpDkv0V8N30Vwcckocggd2PINAKGVRJn9cqKHjnotau22QSqbrmNxLkUvujsm7eJyd1ZKTCT9OPFsaiIHuXvRkV0RsgnS17/u7cbHxFXBTBMMAYGXkd7WPOr4q4XvySMcT9dQwUTutOy2D6ngh/7bel08NQdTeSdfbhyUPTQYtMR1G5FhwC2U6ARhT8Tgh24ZWNSr22sru/JB30iEWuwwNowWoobVV85CiucZDYreSggxT3vW+bMRhrQ1zJ4AdNlwSjWmyv0VuaBOrBLxWRAZaaRYwsKCTuXR0E6rqCH6VaUYe+i5O0A2hs/o7xcyBwTLRD2Z+KJeAMiuWNbSVhbzvXRp9VTG+qY/Szj5S0rfIAgo8buqNBpFJxa+ICibipZ66123kFRtrWprQA== 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: 74194659-43ab-4884-e013-08d9afad45b9 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Nov 2021 00:48:18.2732 (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: DM8P223MB0063 Subject: [FFmpeg-devel] [PATCH v15 04/16] 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: 94PglZRin8F1 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 */