From patchwork Sat Sep 11 08:25:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 30136 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp2241327iov; Sat, 11 Sep 2021 01:25:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmkbxzYLGRuhwnh3VXaipa3JEUKkCLB2sF7Lg5bGGPVK1kvDim65vSqNRxJ+DfyMnGSBHQ X-Received: by 2002:a17:906:2c0b:: with SMTP id e11mr1887932ejh.284.1631348747361; Sat, 11 Sep 2021 01:25:47 -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 o5si1096395edq.513.2021.09.11.01.25.47; Sat, 11 Sep 2021 01:25:47 -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=TVZIopM0; 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 EC0AB68A787; Sat, 11 Sep 2021 11:25:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10olkn2028.outbound.protection.outlook.com [40.92.40.28]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4931068A761 for ; Sat, 11 Sep 2021 11:25:38 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PbdBr/tdLMU5g4Z9TPriqrFX7ECjMS/zen9e++ayuqT6Yk96OUpXcAtxJgO424FwTe74EPh7RsIJPe7vmFVuOhST4yh21tZLlnFeau03vo6MDxfafd1X0LJJ8gR9yEae9OQR/7mpsAVG5XzAl1Theo4jvs6W41qEltt1NLOr697w81O77MAtxQJA+KJN7g0nuyiEDRUZQIgwb5k+h7bu43WHkpwakvoxpqtGucDYmbQEqErrKQMmb4vG9yHvXVH9/oC1gvcwc0FP/wt8pTKyDf7qiB4i1jyLoiXnTCphcxzZHQdeJMsBwrjHVr+hocOimxz6MM12Q77D5PnqMhURUQ== 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; bh=CKO00Z+wopx5s6Ftnr5+qcftpkI9g52J5OuXpmEgG7A=; b=AifsIPyfWGn9zy/wFlscYVQKXmDrN1QtsL/wFF5e7yNOxI/04vSkd4SWNsVHt7Osf9pv0LTBbOe6TIV4e5l4jSR/rKZ0hHoqBFAtYw3Sv4zF1SauKlv1KDs2cS9LggbkW9eElDBl7d177dSJ3P5+ldlD4avKgsT/jy/v/Q7Lc+2ClTw6PQxA+fmKPLQ9y/1+mJH9EfW/YW+8LfIvmg0eIO5Fc/iSrbUtC9/urb7UeMEx+6jtg/rgp9pJOMnsLNLQ51YBaIC0oGP0jqER9GS/Q7T36l0Gsu4ej2YkSiqbXlxaSMuSsLWXaY6LT9Fc0iG31wbbX+Qgua46hy84tEsgKA== 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=CKO00Z+wopx5s6Ftnr5+qcftpkI9g52J5OuXpmEgG7A=; b=TVZIopM0586eTfRoC3cY+YU/Mlrl2gF41qMFvjA/3chQquEual4AvRrDPYj7r/sVDmZKxgfSOQTllgaFxf4k6dNUu5IbpXm3RAxJRxrtZxX74bC2qNOKuys87FwtWRdhXWvVymSORiVU7FYOTXhkhJDH+8Rfvb3R4BHPRS5e8qFW5eNOX/hoshHr7JkHpSDgJLB3F0fkXhd7BNiqDzOaTo//WFxbPbjvXcVuP5ERtSjfKgsilPJoHpYJm5pyGbBrxOtutBGZEsuAQr17QQa7DXxiDWeb/sN5DCoEZrY6qc5QCFsCdBmjhumGm9saW6R3YLfrtJskJgV9BXf0FKfiBQ== Received: from MN2PR04MB5981.namprd04.prod.outlook.com (2603:10b6:208:da::10) by MN2PR04MB5549.namprd04.prod.outlook.com (2603:10b6:208:db::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Sat, 11 Sep 2021 08:25:36 +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.4500.018; Sat, 11 Sep 2021 08:25:36 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v4 09/18] avfilter/subtitles: Add subtitles.c Thread-Index: AdedcjHq1z+8uqoHRIuC40GiFCQD4A== Date: Sat, 11 Sep 2021 08:25:36 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [bFUHMOfuKZXj11Sw2WPRYorvU6KNPRnZqrp6S4dOiQc=] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 73f4f146-2b54-42d5-2c5a-08d974fdbafc x-ms-traffictypediagnostic: MN2PR04MB5549: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 70BR8EKSx8w3ageHUtnwm7at9e66igVbjz9UKtcqhzqVhyuaBQjYYA9IpcvlHTDpgvVt+mXhHcss+hzTg52DyJmtqtQotEx9EbKvRqTH4HtmcJxxDjp0m8MukrIwyJ1wssQr3uen/ZrQUWbQ0ifyvjHYqL4OlzxSfyRXrBEPGjOXYR9J+itH6B47jXLiRw0ZQtxt5yShi2wCgU/GyQqwPs9ohY511DAvW0WCe6lk5g18u3hOB/jiTG+p9Ez1Sc4ARHPe+ySCB9broDBkSrk8IZQG2bK6Yt+YWoVg/8qJObq+WyjfFqvDBEWdw5uh27iSMrzKGTiB6xX28nTK2J9bG+1gxuQio+KSu5SS2EkiWfUAp0Pj5mhnCBGegCGdjW2Lz9HJ+ZyiYRsn3UxY0fe3l2wb098ntSbauNR1pg98ucCUZ7h1X23BauW9860l6uZ6 x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 6AYSBdEw6AEWD6oWu9CH/TwIuDKcxXeauXDtP/gRZcoSLBT9ROZwuUQO+7acAp8fff1HZRT4vhfWJbL7pHW+N6dw66MhEc56jQj/4R+O8uyRYuD+g/Gs1IHO0txuzfw1INMuFf8SY7RFUuVYX/uM7A== x-ms-exchange-transport-forked: True 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: 73f4f146-2b54-42d5-2c5a-08d974fdbafc X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Sep 2021 08:25:36.1632 (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: MN2PR04MB5549 Subject: [FFmpeg-devel] [PATCH v4 09/18] avfilter/subtitles: Add subtitles.c 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: ZO9v1j1dlrIB Signed-off-by: softworkz --- libavfilter/Makefile | 1 + libavfilter/f_interleave.c | 3 ++ libavfilter/internal.h | 1 + libavfilter/subtitles.c | 61 ++++++++++++++++++++++++++++++++++++++ libavfilter/subtitles.h | 44 +++++++++++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 libavfilter/subtitles.c create mode 100644 libavfilter/subtitles.h diff --git a/libavfilter/Makefile b/libavfilter/Makefile index af957a5ac0..a510dd12b4 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/f_interleave.c b/libavfilter/f_interleave.c index b60e89762f..e8821dceba 100644 --- a/libavfilter/f_interleave.c +++ b/libavfilter/f_interleave.c @@ -32,6 +32,7 @@ #include "filters.h" #include "internal.h" #include "audio.h" +#include "subtitles.h" #include "video.h" typedef struct InterleaveContext { @@ -170,6 +171,8 @@ static av_cold int init(AVFilterContext *ctx) inpad.get_buffer.video = ff_null_get_video_buffer; break; case AVMEDIA_TYPE_AUDIO: inpad.get_buffer.audio = ff_null_get_audio_buffer; break; + case AVMEDIA_TYPE_SUBTITLE: + inpad.get_buffer.subtitle = ff_null_get_subtitles_buffer; break; default: av_assert0(0); } diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 6ddf024d93..8a9951d20e 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..90ec479e51 --- /dev/null +++ b/libavfilter/subtitles.c @@ -0,0 +1,61 @@ +/* + * 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 = NULL; + + // TODO: + //frame = ff_frame_pool_get(link->frame_pool); + + frame = av_frame_alloc(); + if (!frame) + return NULL; + + frame->format = format; + frame->type = AVMEDIA_TYPE_SUBTITLE; + + 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..d3d5491652 --- /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 buffer 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 subtitles. This must be unreferenced with + * avfilter_unref_buffer when you are finished with it. +*/ +AVFrame *ff_get_subtitles_buffer(AVFilterLink *link, int format); + +#endif /* AVFILTER_SUBTITLES_H */