From patchwork Tue Sep 21 23:54:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 30437 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp2919086iob; Tue, 21 Sep 2021 16:55:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5brdqqTjny+XI7F5uCNCSgDZ57vAHRSgLlDrWyBY6v1zTHQMoGuKwx0xotuKfIji1it3Q X-Received: by 2002:aa7:ca45:: with SMTP id j5mr39552022edt.6.1632268514425; Tue, 21 Sep 2021 16:55:14 -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 e5si623511ejy.324.2021.09.21.16.55.14; Tue, 21 Sep 2021 16:55:14 -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="fk5Pfz/m"; 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 0D4A468B08A; Wed, 22 Sep 2021 02:54:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12olkn2108.outbound.protection.outlook.com [40.92.22.108]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ED6D968B08A for ; Wed, 22 Sep 2021 02:54:41 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CEt/3lZU0+9tmJAgKCbr7pMgXAlp6d7e46IphNHSUob528wVgr0rof8oK/oAI/5+E8IokjErMPaZbBmZrwgk4tRHsgU94Rjw9/zXekNf0UKSVTeg5PmlYQHb5SKyJO7DR9RdT9zHLMYQTSzhMNNKzySGkq4wUzG65VHkXUbM9y+jrDaTbS2slG9m0Zt0+jcGz+PFR9skJQ80pHaPLW6OnTBAMUqMY9fd1A1X0C7HmVrqafttbrpMAJF9fAy+e061rOYOf+ErgsLoYc+/rJBr43Ts+IRfOsdBkGorm8ZPKcnBAUn8sULXHuIRMJYPE67nRzxeO6kD9+9/nJtDOLeDBg== 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=H02vlvdEgRm2pOfQFT3Eg1sKz2VDyh9N8ur8A+qTiNo=; b=nDJx7N/3TtrmfFPYO0bA6az+pEOBJPME2OiZFNEKjJm48p6nKRL4tFcuyr1n8eZKwtY1PCREFsLh/Cvj9C4HNNKyAlwXhACXULV3TvPLbXRcsfWU2iXVqL9NmN+6d7sOuMYp7cf4aVuUnlc4ZCj4lMXcJUdP9ZNgJCpzNg/ydjDfes7oeYxzjRDowJ+WTeBbtQ+05XZcyyUH7Oujr65+sffrtDY6dacjlDalFzjbxwh2KdyyZ2FJPOagfFRmZ4g32BECuOLlfG6/lbKPSfcn3bo3Cej7Xpoe1eVdE572DgH8pWYmwBeLv9FzPgCyQ5jtLazPiwABSAm6hmneHELfBg== 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=H02vlvdEgRm2pOfQFT3Eg1sKz2VDyh9N8ur8A+qTiNo=; b=fk5Pfz/mZ2TaeYdWIyPH3gA3ec6fxd2RVD11mV/BR8aIOrx/6tmhIgz0lQNzrImY30T4l55BqFjJo/a/GekqA8DbKzK4En/wVzGpwUc2k9Vyatu6kCUF4MN6fKPOAxC+jVLnGbGKQR0HkQycnEdBOD1yhZvNKPlMuxRmqjVEDkI/crOf820d3X7sC53ctSW6uSp2rL99vN3Wd9iCH4sc1JysPrOgrSPouMmM4m9rJGpmAnM4Mqf9j+Gc8BrOhMPB+D6Ul+5KjsvTwEhHsaUmCZfNPufQvFKyJ7Us2e+IDwgRbHW2oDN+5JQsAJo8MyRbXCZ2jCpdy2D0zTwWPT6ETA== Received: from MN2PR04MB5981.namprd04.prod.outlook.com (2603:10b6:208:da::10) by MN2PR04MB5808.namprd04.prod.outlook.com (2603:10b6:208:a3::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.18; Tue, 21 Sep 2021 23:54:34 +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.4523.019; Tue, 21 Sep 2021 23:54:34 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v8 03/13] avfilter/subtitles: Add subtitles.c for subtitle frame allocation Thread-Index: AQHXr0QFTeQKPQh/u0Wa6qkxJ2wANg== Date: Tue, 21 Sep 2021 23:54:32 +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: [ERJObGr5xhuqnhpBbkoPtv2xKB1B4fsA] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8cf88535-7535-4600-cc2b-08d97d5b29e9 x-ms-traffictypediagnostic: MN2PR04MB5808: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 1n1J890/OuTe+HcnUJZgWUoFlq+feXqZA11FhM7ZN9dapvA1IkJPSAmEUUtHWkMw9pYC12uwGMPKck2ydI1Yt8lHzfrbucX3hiNAZsUZkKEjxOuRJpM9ySBVyl6fTX974QVYAMnq6O2GIA3QyL8zLBNnmdS2lVlgnKP+mr4tz1x+BhCcq3VuNUjT/NqwDOJVHaTUox9rZGPmyCVCwTp+o/0ZMIflfTa4GwZ9QKXDBo2N3hGie+L022P3K21m/2QdEAAcD7x1zRdVx+8i1Vtu4MF2HRXyyGOxr1/wkYwkhOECfCFrgmvDSniEz42ESwVgWGRdaRR4oOgGtek7UWn6EF7cBpIUErhAtcGbIqzECjToGIyQ/ORuqhSnnz28MuR3QCacTTIjxzrbiigyoa8qCdp/gYJzlgJfJaZnDwUHtMj6XIB8+g1WBmLioiIyvtsN x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 7Qpu6KTRGzL9TB9r2urvIKuJjqDEnSRMMivXAR8TgfoCUhFqtZ19FnoMI0+3kv/9hDrC/iH2vyiFrShzpcXQA7rp1kX/aaJrl52dthXahgiJTzwh2P74r1fZMZpTL2neVCaXX4ewhOzDStnnJqn5mQ== 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: 8cf88535-7535-4600-cc2b-08d97d5b29e9 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Sep 2021 23:54:32.3343 (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: MN2PR04MB5808 Subject: [FFmpeg-devel] [PATCH v8 03/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: FbS6DCvNAx12 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 | 61 +++++++++++++++++++++++++++++++++++++++++ libavfilter/subtitles.h | 44 +++++++++++++++++++++++++++++ 5 files changed, 111 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..fd2e7c3c0f --- /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; + + frame = av_frame_alloc(); + if (!frame) + return NULL; + + frame->format = format; + frame->type = AVMEDIA_TYPE_SUBTITLE; + + if (av_frame_get_buffer2(frame, 0) < 0) + 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..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 */