From patchwork Sat May 28 13:25:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 35960 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp1366089pzj; Sat, 28 May 2022 06:26:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPRvh4ni/8rBh3QekNbocQvkHh7JldstlVQkhN8Mye5NQHLm1420yJgMponTKRZAdCcPys X-Received: by 2002:a17:907:9714:b0:6ff:338f:b4d7 with SMTP id jg20-20020a170907971400b006ff338fb4d7mr7573796ejc.718.1653744389726; Sat, 28 May 2022 06:26:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653744389; cv=none; d=google.com; s=arc-20160816; b=c0U4DMdKtx7KVWtmPpgki3qbS+Ix9Zk9RKqEi0r/GmiPIfrWQI2yqYP+C6iq4SnLCm NLNM8RSccJCLqYpLocUodUJ4iQ8ee0i7Vp5T3/7uJfucaX2GiLCskTN1R/B1iN8ohBP8 xFbcHnHqwEjReb124MrdJjPhR5S7ILExgj876nXEJWxdX6gmQuupHaix4kT5l6FsbZNi QLQnFWqzWPd+WoMEmb+Z90TMuPCkC2aBOcuHYMQH3cbiPhohtk2mSzZjB0GE8Dsl4miQ mfMP0UV5awqQ3ThBUCGLKggv/ypJ32HfWJ6LWDD6x+DFraSIJmk1aAVfEms1KCiHmV4a Ojew== 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:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=4hwz+FrrjTq9nLEp/f5U8ktKcLiM8tGH8maZD+d8crE=; b=jsrmlKKhI/5pWaBh5AWUqj/6DdRsMaonjpLbYuw9XVV/vUMNTTKmRCVsPmQeCz8us9 mmJImAR0JQ0jOSgBXq/DNXWqNvjrIGHkkRYB/Z8JXiXnnuWKBh0obFa2FH5XoCRK4jJF Ay+c8fKnr6VrrfxKZxVx9E+9Gc4HsEj12dEUGvrGFB9cv4z1aqL2YLtNeEFMtAehRq3U gq3fy75hI3+zt4PS1yeSLgcBFDUgWZMzvT+rSzvj8dCqzjZaBRZkdYc09J4XIvmJsY0V 3AlZSgwMtdwhYv7lts2ruLzY8Tb7fjI/FV/gb+8hntVA0YUiUmRFViLyjCRDX0ECp/Uo X7Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=SmwF1Po2; 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 kj24-20020a170907765800b006f39e0407e1si6469807ejc.342.2022.05.28.06.26.29; Sat, 28 May 2022 06:26:29 -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=@gmail.com header.s=20210112 header.b=SmwF1Po2; 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 CD56B68B611; Sat, 28 May 2022 16:25:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F3F3968B5A1 for ; Sat, 28 May 2022 16:25:36 +0300 (EEST) Received: by mail-pg1-f181.google.com with SMTP id a63so38491pge.12 for ; Sat, 28 May 2022 06:25:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=wxzzJKpeRGnGC+l6EWLTROQmIRm+MeCE5MMiTQ1xCx8=; b=SmwF1Po2+9WumMK+/j36qe75NXissuKchvKzjSEwXhQZcan+ckGTWVnN9xTPVkQ4a2 5A1NRj4tzIXmjMwq+4e2qaHyKPHxk0u7znrEI3aCVMJvwY+lnl0DjWKBknB3SEWyuCHu R55c7zRLJxE00vdMXxnR8eezn60nvMk+ikEp55/wNSj43NEoAlT/a8HBFiYNVMiu0wfL wJT8yn5ds33t0EJLmpCf7DeIMA1MdAADalNAsvb0LEapYaxJV93ZlCdNNLRY5OZ21j2i ogcuiUtOz75Ciy1IwxxT+3bMcdZuVAPTolJNg9VGshyqdp+eyIx+36VEwe0OJLxr2Ji4 zohA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=wxzzJKpeRGnGC+l6EWLTROQmIRm+MeCE5MMiTQ1xCx8=; b=0qyD0M6NnggFysIbjnfj7Ps32fIbJ9O9LcPY/pYqCMrgsxqOiI3+K+Zx1KrXK8aR5y 8Iw3FzUsCbZ5cyEnK7o9YtPu28foDT5edlE2fdRZHi73RUo8nrx+vrYTTQGLeXTRp9Np HiSqUw1VkVVFUblXk8hNcQ8SLjyyqkpjEZnG4BtebdrXioTeAj9dmR9aZ9cDH7Fj9E0s UEH4Pyrpn7gBzYhHBXQHgB35M4Z005gfArjRNgQ+OMfgEVvlaE82nm1Lz1qupN6erpWn JmToWdnJOjMLLN+VrRuR+MJwVSznTNKdFr7Ba8CE8jUxX8tL92U0LXIZmczzJBW3wWRY nNXQ== X-Gm-Message-State: AOAM532jTyJWo32u4WJd0LACYtVZMjJMm7VRL15mWItT5ufUmd1AXotk ZgeT//ToIxVEokyN0ntjVy3YRGApxPLJKw== X-Received: by 2002:a65:694d:0:b0:3fa:34df:cdc6 with SMTP id w13-20020a65694d000000b003fa34dfcdc6mr26826403pgq.439.1653744335384; Sat, 28 May 2022 06:25:35 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id 10-20020aa7924a000000b00518950bfc82sm1972521pfp.10.2022.05.28.06.25.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 May 2022 06:25:34 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: In-Reply-To: References: Date: Sat, 28 May 2022 13:25:09 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v4 09/23] 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 , Andriy Gelman , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: oMt+rns3DJlU 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 e0e4d0de2c..842068e902 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -20,6 +20,7 @@ OBJS = allfilters.o \ framequeue.o \ graphdump.o \ graphparser.o \ + subtitles.o \ version.o \ video.o \ diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 965f5d0f63..28c5430c3e 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -42,6 +42,7 @@ #include "formats.h" #include "framepool.h" #include "internal.h" +#include "subtitles.h" static void tlog_ref(void *ctx, AVFrame *ref, int end) { @@ -1452,6 +1453,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 0f8da367d0..6c8496879a 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -89,6 +89,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 */