From patchwork Thu Nov 25 17:52:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 31705 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp1095530iob; Thu, 25 Nov 2021 09:53:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzCWy8sb9P96ajEMjVd4nkWSZXHeafnIr3VacfrJrpinqY4yCxza8eU6AYpU7FD9h4/w/5W X-Received: by 2002:a05:6402:50d4:: with SMTP id h20mr41562172edb.52.1637862812849; Thu, 25 Nov 2021 09:53:32 -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 r14si7668165edy.352.2021.11.25.09.53.32; Thu, 25 Nov 2021 09:53:32 -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=gdpWoz7P; 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 7A25168AC65; Thu, 25 Nov 2021 19:52:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07olkn2051.outbound.protection.outlook.com [40.92.15.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4B7F068AB5E for ; Thu, 25 Nov 2021 19:52:26 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AuDn7W42ek85PNLXKftwAx7qAEWgHxTOb38YH/dSvsxr1sPcVu4McBVzof7RH8dRZTMYrCImk9UGrmhmm2X+0iGGdcE4RtKXS2UVHQhcQEI3autelLm7gfQwzDejB+lO+SMC0NE4k2TXhK1m4BeBVMthOLJukz1Jr3c8CI5SNK18t/czQW8AMZYCPACC0CPlemKbTOSt/utjPlmyUxInaOBvXKMplD6aduc7cx6JCF4irRHY4FzuJxug2SjFK4ijKVq3zNMfxbMCeR9ENFRU3YU6vW50CTFHkF1hSKihY7KMmFVU8UZXSrbLwSTmCGXh/vP9RChqXDLJWnHuYGHDJQ== 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=oaTQurLVPBZuYstGS7ccJd3tGYgDXeZ8/d/+a5wnn7dvBQGHUQJgLpDRpZIC8cJj0uIpLcZAkFyQlR6CxntDqcjYJ8f9grCEOi2k7DEJlqmFWdYbWqMeVWItZudA7YQXHsOg4yUgM2l+wihtZqY8rHQsOpNmfzu0KTHDufoh/z8liP/uROVa9tMbC5oNSnd8qOSDVa4PF4LTRy9nyjwzG/LZsIBPT1CMfQUpbVwgQymdxLDLXgeKIzxZrUB8NjVY3pFTixeutib6zP2QrKb4Z94LHlEJW0SV0wtEfeGMDxR5queUnQpVzarhGLK5xgLQDwYYQiN+mX/4vZMxFDB9ig== 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=gdpWoz7P5JRZW1O+sdxTMcikimVAxkmQZgnN+4Vm50LTFOMOFSUB5IFFD79/4/esYAEtGnbdIhv6XDpzZwwOHOLXTEM8UH8OV8teLAaYoTsO2cFlOg52jdkmxa0hm50XNN8LZSY6q8ULRUVV1QULv7qSWuHNJgwqKcQaSfshVK+MoGXVBX357stZBx2ayJgw8yqw/Xnwf1/a8Gg++Rr2+ruPlUDY7Mwf8CoV4gWt/GgpUBpKrEN5I0TLnibVqzyd6XtL/qFQDPj2Y/NNScXlt9e3IOGAh0j2/crbaHTfC3kDa9LWpq2BS3MRtpogztzF9Ea1H7Fo+HE9ZdvJoZ1V2Q== Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:b::20) by DM8P223MB0287.NAMP223.PROD.OUTLOOK.COM (2603:10b6:5:317::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Thu, 25 Nov 2021 17:52:13 +0000 Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775]) by DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775%5]) with mapi id 15.20.4734.022; Thu, 25 Nov 2021 17:52:13 +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: AQHX4iUtBTM7uubx0U2h03RnAD0B2A== Date: Thu, 25 Nov 2021 17:52:13 +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: [3aDfmGm599OS4zhX6Bapd9+lHy1LqxOV] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6e2cacf9-2239-426e-bbab-08d9b03c4fdb x-ms-traffictypediagnostic: DM8P223MB0287: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: oxnPSpeVmTDHurkpijrqiduhq+Gv1i0egl41Xb3X7zvgr0FMxNJddgUYLdyXGr/6hgaTwVa1c07A1jlYJ3ajcbVFT4mvq5MktvRE5zQaaqNAKXEcv5AoYJrTj7JJLmthxw8k8/L2+Ce9nIn/pNTgtdegbHwIlbt3+KNG9ynX9d24TdSMvl7ew5iJiA7t6HfaSnTW+fWmmjqUJlZMNuyHSr7RbMRh8HpOChmMtAv6Z2IGn/sCmrBO1GI4QhRRc7MXb2DqOAgdKghijUFq5hGY2rAtN/yDdAeS/Cfz8Xv7RfegNKfZtjs6HFsD15S5pyIAZmrEYZH+zCh1jCdnoPv45mf++vUnz8WohLNQqp8Mt/YoAwwnlVEpl6Ulgb3zgIsmwBm4PaciWW6M8rckc6ymFknQg3u3c9PyQ8nk2sCzHyGFBgs9evOHJzTWDP/mUJMYdEgR+kv0LPbjwlHWmDRqHwzK8w5uWH4HyHBG6UIEZtrTODULVQGkb5ScRMvr+mbpYimrTtIev0KHAJ7kPIHZHmiUMhv+tzcMVrvRSQ9AH/xNwoacuYMU3AfMH0/sQjVK+ZL6j5y57A9ZiJUK1zXPgA== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: m6xYn74RQQN6FhxFXjEZdS2P4q/58/lRqNX6x+YXSESg78MfgaGyP8XkDbsc9If3Z9o2E1GNTPkp8ziR5z023XUxW8PaKZ3NQMxiuMYGEx7yAf4dyWE01jFv+oNfi/hWy1kH/cfuJuAenMarQxffyT0N27qwWD44EKY7HG12FVvvZFGy8P8QONuUIfpGzPmfsdc/9yd4LNUcHlqrDLIDr30pQ86lcE3sotht3tDSAQV9QcYYkkH/EHe6KccSMa4It5VS4uvawxjw/aCqcf5aIj4BbY79Drei0/HWfxrYO32eT0ro2kl37yl7G/5xdio+/TUrKcl1JYn+ovbGl8miFP6KRxgY+dZsSJ5g7ImtZhPeRdmZGU7PiUeu+nix90+h2hNDdgpbozSdlfUJhc0XRqt5Xo23uHQurgBdmt2OdoP17mdVt8sO7tyhAo7CedR6Q41xiKGyrNPR1iFXkTutjpWc57LCdJDFo/+WC8goshb25IrJj04Q1KILspE4bF82RoM29Nkeqo0sOnYAvG8tUJ+R9f5C12Ct6Oho4o3igJpfomsdVOwra+W3kCx4Ccn6da/9esV8SFSGYMdw5CVSd3mKNj3P7trc+Djzskm5NcUz2QuhMNINTuaZ2RajXlfj0iUjX0hLYNhIsRZlbRdS7rEFM47fIZddkpA/3DarivAv8jCE3UyEIplwv+ury24KAYgCGWw/ptEr0Jqv8MneSg== 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: 6e2cacf9-2239-426e-bbab-08d9b03c4fdb X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Nov 2021 17:52:13.3474 (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: DM8P223MB0287 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: 4qpeMt3ZbWc5 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 */