From patchwork Thu Jan 20 03:25:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 33710 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5432762iog; Wed, 19 Jan 2022 19:27:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJzpHFf6jlNZJh2khllQ2Sk7BC3ZCetZyB5MgQaeRn+B6niSLrFpWRpK2jeEIeC/mZlKFclC X-Received: by 2002:a17:906:8693:: with SMTP id g19mr21669896ejx.579.1642649274917; Wed, 19 Jan 2022 19:27:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642649274; cv=none; d=google.com; s=arc-20160816; b=Guj/v8I6J1M8/Dc2WkWHdKI5jcmDRAZlgP2rZVQgkEiYHTpviVbspJip2AmBSfu0bG LiZbVSSQVK7Qwa4ZfARsrDOg2uuZgeNATojXh4PLV0KPKygcrG82Sjh++uH7rje8UVws PLLjGcr1UOhqgN1eNKQHb+IWjhJvR4h4+jl4BXsA1sJ8dLGj/JW25zMQ/pPUhINjQ+GV JAfs/5xBAO8xHAPDlrcn6G3N99kcLSC6XcMQKcRMmfa7g4f8djXaGrHD38IMfXwoR2Ud TxlqXYsz9vQubCgwyRBfmPaWB7DeAIJjeORBCqS+md1eDYKQ3MI9C8HO1DtrLRy/J3Kd vLoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:from:references :in-reply-to:message-id:dkim-signature:delivered-to; bh=uLZkvCrn2uAzj8khln5/T6YR7szdu31BRs2ibUa5UGs=; b=bG8b5VhTUbg8Z0JHIBWcp5akXhd8f9Dv6DnR3Msm//U9WB6iwd33TSVsC/9Fk4mGSb 3Z6SWR3Ic7RayLiKyHz8Z/KvmAH6K2pxVI3NPhnyl5xbjAbWNmYhCw0Y8CGI6Q7tQIsZ 3zyYe9h0+cxm9WCzOVN2PGhxHgTCIlNwpXN9DVNAwsoUk1AFCe1cY0t+Sb3D9ocT1IU3 Ca+5h0TjjRD5TH+NO1GWILQeReO/jEVhpNdtwI8mVO7K6FzRbjyj4g9tdfklAc0CLg+Z EL1FPHNNFeC/9vdfhYhxbPoS9ZrxPWolqiuNCCkrVenHCp9O4eJPwvM40FRfCqls3qWk bk/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=PY7PmeHl; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i7si1124301edv.86.2022.01.19.19.27.54; Wed, 19 Jan 2022 19:27:54 -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=@gmail.com header.s=20210112 header.b=PY7PmeHl; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C34DD68B2DF; Thu, 20 Jan 2022 05:25:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7DBF468B2A1 for ; Thu, 20 Jan 2022 05:25:45 +0200 (EET) Received: by mail-pl1-f169.google.com with SMTP id c9so4036570plg.11 for ; Wed, 19 Jan 2022 19:25:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Fe3bLSNZewESu8OMEL9Txme3yk6EEiz77C5wfQxNsOY=; b=PY7PmeHlD9kV7fF6LrY599pb32ccyqow0d5Zihe4Yoxmg9Z7zEfRf9F+jZLjboW3JQ rWthy+vv3I55JnfGuS4I6yyhDkLvzttJmI/1h8Ih/Tz4IAgKyOB9u3z6qf69NUzX+Raw 1XKKwOClOphTBxG+6qhVmCg7xRMpOxZ7pr6sAbWCn5prFz/bQT1MYGa/b8LVJbkUFL4c SnPuwF2rIKOnuExD0IfOnOdSL7Lodbb73JvrJR9JJ4F/IL4XOVoWYb68hBF6A3jDX6bt T2o2EnDl8jbI4JMlqjlZa6WyzuMDD+AVKFG2RlFvRomEmhfHc/K8R+dVtn/kGg3igwiN 2tyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Fe3bLSNZewESu8OMEL9Txme3yk6EEiz77C5wfQxNsOY=; b=4BQmeCfWuEU5NhhKwIiPqJjkWJgth06aGhFddnKGTHao5pEugPn4py/6Mxf8/wP0jY QXo4oCnihF7hzsGcWskk7dvIBLMQ63VOguOzmOijBWZGCRVmXSQtxbNvoK1xoF3e/SGW Morhj07dnJPOL/HFU7m2mP0OsNkpvaHRcZOvlzrjpeFwz0+dYd57wZ8QkIPM8MAJhjrG J/AqkhPAnI1WazPCJv4sni2iVT4px6iC2vT8e7G1pBOv/58GxKJKZGopsUP0HegpJZF5 SqjM2uHj+2uL2DFWqaOeCMHOTLslzWvGtDz2fcgHBLBax0PQS3gWHWZLdJUGNO5mwtN7 nl3A== X-Gm-Message-State: AOAM533TkWYV3JWcNx+0KNW82ZESUQipHfn9LDIlAhSQHiZkvC6hP5Yr CkP7SRwxoQpDmxpKuaDgXwQr8B+ZA7k= X-Received: by 2002:a17:902:a9c1:b0:14a:ef78:b728 with SMTP id b1-20020a170902a9c100b0014aef78b728mr7326921plr.83.1642649144042; Wed, 19 Jan 2022 19:25:44 -0800 (PST) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id 69sm843729pgc.61.2022.01.19.19.25.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Jan 2022 19:25:43 -0800 (PST) Message-Id: In-Reply-To: References: From: ffmpegagent Date: Thu, 20 Jan 2022 03:25:16 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v3 08/26] 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 Cc: Michael Niedermayer , softworkz , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 7dHEMwFQla6E From: softworkz 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 282967144b..f1176644c9 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 */