From patchwork Fri Sep 24 00:30:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 30532 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp987378iob; Thu, 23 Sep 2021 17:31:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHhYeEQYm7WFXA5iqUr8QZr50HM6VJBMhOjSL8mQA+ldwiE8uB9G4R25Wn6RT/FLkHBX03 X-Received: by 2002:a05:6402:1459:: with SMTP id d25mr2027408edx.78.1632443484961; Thu, 23 Sep 2021 17:31:24 -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 f21si8293333edv.204.2021.09.23.17.31.24; Thu, 23 Sep 2021 17:31:24 -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=H7dvOzk8; 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 C239F68A4D2; Fri, 24 Sep 2021 03:30:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11olkn2100.outbound.protection.outlook.com [40.92.18.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 344B068A41C for ; Fri, 24 Sep 2021 03:30:55 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h8TL+bRpsMlpcxvQP5NlnN9F/ks/S/UvU2ZeFKx5Z013o+zWDMwRlGvh/jH7jSn1pX/HTDEvbuaGe3fDfRY8vtFwfEs06E17o+VsxzRr+9L+ol7WMYT2JOUScN511aQymzjX+XnWSqPokjx925YK8TtSVKMBAb2UaY79tNjB7Xf9iiOmGh9C51OZln6bsMBd8ic5+RjW7jGFyGEc36ll/Rosd6RM7872k1o44bw7s7AaWjbz8PzhOmxvOc3EGuDxrUYbPqsluboOFI6auOm8v/Gp03ZYiWMxj9+PgE3iWWXCR6oH+kvk1nCnFAr/cWMrL34i4rWdDwv6AnyaR6UCjQ== 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=IyiujiE8Lg5k0gfDBf7mZY6NH76WxzNc2fYGjmADCwY=; b=XOiFOvFaVyFzTMu04riZoEGJ5OUIwK/EjGgpbs5EoRInBTNplgBsAmkgGKgiAC6OgPXwyWfnflQ1SfjKR/luH0srVJbYGHeOaesITEz9nQjvxUX/tb0qNCfDCpJmbHVqiXg6CFWCsUVsAnyQYb7f7buVUGnSOEEUygSuSTI1DNf7uCRRGpDSlDoKhDgoW+XyhTtQXfNf7irz8oTKGhJUYn7+hkEUl9nQ9oDSipv9W3unQaBO9tQR6ijkuyArsQHLdS38bObHDxdOxBQpfr+I/+2bNrSUgwlFeBpXN47ZojtJnadEKhCz2epPGTxSgXR2GtxUijs0ry36MnEqPneICA== 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=IyiujiE8Lg5k0gfDBf7mZY6NH76WxzNc2fYGjmADCwY=; b=H7dvOzk8fcM0KWpFEBbOxd2A2HRHkNiMUwuh+qDS32//ZLI5xbdqLfDgpdeSqOjqRXoFlLgcPtNCuc0woVqg6YbXNb/84PbS25Lbpefmi3gQ6Yj/YYAs7r/JE6Ko9L8fn0JQMpc6ukMACc5WcL1dhStLP6NgDP71KgiUJAMitIJqrjHMi45s+1vntRN8uevpPYlElMFStUqn+NBAN2R6shI2WEmHAag3aQ+rLwa+NS9BMMTBc/kJUxrbApNUBoC0D4q9RQ4aukuZTwnAj18jgnU62ccdQA7JJbV29sd02p6msBTImrUeHxoY3WtK82WXd35lEiDv9m9R6ho3lVUWgw== Received: from MN2PR04MB5981.namprd04.prod.outlook.com (2603:10b6:208:da::10) by MN2PR04MB5743.namprd04.prod.outlook.com (2603:10b6:208:38::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.14; Fri, 24 Sep 2021 00:30:47 +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.4544.015; Fri, 24 Sep 2021 00:30:47 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v9 04/13] avfilter/subtitles: Add subtitles.c for subtitle frame allocation Thread-Index: AQHXsNtrPDM/NCp3IEut80qW3l1jJQ== Date: Fri, 24 Sep 2021 00:30:47 +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: [UibIe7o7oYj9SrX8unbc9vE+XtZvPDax] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ec7e1eff-685d-4c73-b743-08d97ef28db6 x-ms-traffictypediagnostic: MN2PR04MB5743: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: FI8yWPp5ANFsvyZYu4xS/4vxdcS6XG0EPQ5yVx8kbJZHY2QDLpDjAru6/5a9jQjZSJMKFeHxmWwg+3qnTaLpDu4Gh0rw3T2nzhsdqIW5VkW9HO6Jnb1DDOP4ZZ6xGq9tZ14nAv8YfqaFKSwmRO71XpMuZXnISKK3sXf4L3a7Uvt2Ks6P/eM/kRjiJuTWaEAw3pZPNuVlIwV/Z7aZb+itDjsPJ+Ul0153ymKytKv8Ok/Z88xk3s0bCG3h7Bb9pdhFghXGka6gtqs9Rpl2su67sewYakFdmMfOE00gK3GFuOH/rd/3mCp/epBVND8ttL/1xS3GzaqCkYOCzsEKozpcWmyo4KvCY2SaGvelpIj57PekKRLTpNrQsZH40Hr/vLPVi3Lc77KS2SfWwd1PU1TlihUZ51czf8N/z2nO0zavTMZDK6nHlJe2rOMeasWLynpY x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: pMe0uZqqHjx+ZhKpfkqNNSFXrUBa1UwUDDCG0W+XY6pRTvG3MRC/kEB52EeeDJADAgQbCLzck73OdLySX3LfWXCBPhAdLMiGWz8J9l0Sy4M+WssOJoZfbY32BiWZ0JdAHWNTc2p0SsJnlSuhKXaBCg== 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: ec7e1eff-685d-4c73-b743-08d97ef28db6 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Sep 2021 00:30:47.3303 (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: MN2PR04MB5743 Subject: [FFmpeg-devel] [PATCH v9 04/13] 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: MlXlZBhO8pT7 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 f059f3fef8..041d3c5382 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 f325918021..ef349a67f9 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; @@ -1476,6 +1477,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 e7c154aff0..8977dda2b3 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 */