From patchwork Thu Dec 9 12:12:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 32242 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp276126iog; Thu, 9 Dec 2021 04:14:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJzrqrVyMjYmFhlXjvP4P5XkRRX2lx5KMSxYQKwLgysKHRIPY6ToKxhh5S64+SI+7nnW0FNF X-Received: by 2002:a17:907:6d07:: with SMTP id sa7mr15537277ejc.339.1639052077566; Thu, 09 Dec 2021 04:14:37 -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 z16si9903233edm.469.2021.12.09.04.14.33; Thu, 09 Dec 2021 04:14:37 -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=sHPdQsC1; 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 87F5268AF73; Thu, 9 Dec 2021 14:12:54 +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-bn7nam10olkn2041.outbound.protection.outlook.com [40.92.40.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 58DF468AF35 for ; Thu, 9 Dec 2021 14:12:48 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d5JVRQT8KREIm3fhhrLmeQPZ861pYFJ82Z0XvuZ3l2+yumPyxL8P97OOhuxbOpS6U/YKYVDtfiud0MeY2l2CP3djV3gYNcQJHFaxrubeL/HjK1bp2fap+UEKYWPrEPQ4nj3B9fp7jlPIZ9HDhP0zQUTXXxEhq7R1cx1Zf4gnh/Bex9FTlO4j7tL7SfFqnDGKBg9ddsM7sPybOugM6m5q5d8XFx3wQeyCbihcrV7FCcurCeS3TxZBFeWlt3/fjJWiml7tfV1yeYOMyJC4e9w9lzvdiJY2fvMF8Hby1TzMj6aIAPCFKCTNfuvO5cJ95PmV3YfsYdLdrc94MyWQSGv7Ag== 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=hkYDQXII63WnvuyLYTZftA0/5TarXIbhZIcRpSo7PCgdpSaAp54VrfGYGrf+0pG/eijix4fO7d3io4zSuxmDaQFfKvD/BQfH/k7ZrHZPtRpKpcr2oPpvGbksizIELap2fkNShmVwEvst3m3Btt7oVP7E4SHA5ou/2VmR/mSePzM7EYQKrYO3zp0deb3PxvMX7Rq4RuEaGVN8Y0KzKoq9xiIeMMODXeRFViPUuJAMQUO9K8Vf5qK5rvSQ4qOkc9mpKtJ5t5hpOea2dC3CLPpHpXFXyXGOO7toVD3+HawmTezzJf8M2Kv5omuveYU5rcPJq0fBNHCq8nwehk4SGfLCfQ== 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=sHPdQsC1/CS6ybrYj4g/ESHZAgKL4BnB7EVAGsLahSaDQb7q0twvhf6Y90ZDdqzLfPO3UgFJ5JeN4SiwY86n0fUzsFiW2LY5TAu3hc1MXLTaGZpDt8KUQmEr6MNsXjqczOH28Cc8V5C4l8deRcwwQKqx/sAPCjWuSAsYAWm0dSr82qtZoUOzEqDLME31HZYIvhpG4hcku0Fd2kw1cEKxisA7PGsY+ediv487TnfTdak8i8FNvQ/Pi7A1F5GeqAQ8cl2WUJ8L0F070mJ0sSJji9p/cL/wyWsdukMvez2qFVVugoQnHQ8b7kKtcqAFWD2EehmoWBvkenzg0BewV5jq5A== Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:b::20) by DM8P223MB0399.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:8::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Thu, 9 Dec 2021 12:12:43 +0000 Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775]) by DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775%8]) with mapi id 15.20.4755.025; Thu, 9 Dec 2021 12:12:43 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v22 09/23] avfilter/subtitles: Add subtitles.c for subtitle frame allocation Thread-Index: AQHX7PYRjNPsTRwTqUSG7DSvAqpC7w== Date: Thu, 9 Dec 2021 12:12:43 +0000 Message-ID: References: <05fff8a8e41014ff699b57bd805f0411865328af.1639051681.git.softworkz@hotmail.com> <18ca2f636f4ef69cbd1b146fe2b3384e242bc377.1639051681.git.softworkz@hotmail.com> <3f3d922baa2061dc8a4e4243c2fcd9813e59ebc3.1639051681.git.softworkz@hotmail.com> <36b0675ac77e7856359413d13b3c655cd3f32abc.1639051681.git.softworkz@hotmail.com> <3549fd8493f7ddba0a9c8facc7be023f6d8c3d01.1639051681.git.softworkz@hotmail.com> In-Reply-To: <3549fd8493f7ddba0a9c8facc7be023f6d8c3d01.1639051681.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: [K6Pf32fAj5OdVQdXQ7+G4adnbeWLh5Os] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0031a252-4727-4539-9b16-08d9bb0d346b x-ms-traffictypediagnostic: DM8P223MB0399:EE_ x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: MZBV+K0PhS2tvYaqAWcuO++NVVHZPqNGLoGGPhxXUJLbaCxT9g8FZrwUrMyCXmUGAhwYtrjaRzJn9HNZ53tIOBjcrExr+0IhuYNQzY6VUQ6Q/xoSzchHvXZK7pYJe7xl3hVOcxrVTuJtQgsxzdiPOmNZiEFZqvhlPgXZGpJTPmipylKlkq/kGuKwJFLCuQ2HIH8nK3StSDdjcDgJXwFj0IyEHHVYIORhjNwjaLomVyWR9eeQTYTG9wxOXZ/PoEpuptmpTlyVa9AC3c0M5RtSAtOKSBXhzCKY/E9AbdFqwbP8lSE0NiUpbKy1ktsz6hcwXMXCxtkSiq6HbWROYN1gvPwOk4kBuG/eyF+VatBJhWm7XTPn1sXmlnIwv9sivjDP+w+3H25qkwEFXgrNc6RBZl125Vxs90Ak4WrATNsUbmEyu4Q/KpzwUtP61LNGkNhO8RAqL6vBbVTb9LSSR+Xolbk77FIBlVF4JPAFwxr9Gw4/TU9jvksHlwqqw1KN1+sswycBkzdolkdpy1g4X22p0gmKAk0Rm7H5NHg8NK7WMO3ipLaQKZ0jcZgiThhksME6D4aNGiPpGF9hwj6SBRPTDQ== x-ms-exchange-antispam-messagedata-chunkcount: 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AWqGX113kYhBedSCNFMbJy0HjNQnXsotAGlHRsada26R0yIL60KwFq9vsPWP65Kn?= =?utf-8?q?2NZMqdFww08HZm2A5XyoYwTJXW1Ti4G2bapk4hmfLZmA=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: 0031a252-4727-4539-9b16-08d9bb0d346b X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Dec 2021 12:12:43.6927 (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: DM8P223MB0399 Subject: [FFmpeg-devel] [PATCH v22 09/23] 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: OvHYL0Qin52O 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 */