From patchwork Sun Jun 26 16:35:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 36460 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp1539841pzh; Sun, 26 Jun 2022 09:36:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u4p09qJv5Up3dn4VQVvNCYYB0EuGWI9XkfI004OSKFZwm8Y++XkMqbmFSoDM7AxbeVqsl+ X-Received: by 2002:a17:907:7202:b0:722:e4d6:2e17 with SMTP id dr2-20020a170907720200b00722e4d62e17mr8795127ejc.434.1656261384771; Sun, 26 Jun 2022 09:36:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656261384; cv=none; d=google.com; s=arc-20160816; b=wXjovgHGkqgYqqpNT88Wkdvr5lY7zni4IpWBg4fKh+8lxU6NddWkFMU4ZQnQIfOOsm Ra2H9eGhODvUzG6a90ef/zdMj5vCM9wJp6zaPi8fiVhVUJL9VSNHIlitSnulIW4tPDKG AtwTJZWsWcV8w4Sa+ai4RVhHDe/9wzMZA1hnW8lL59h3H0rOluNOHQ0+Pd7BA0/H0Nt3 XwJ5x7kXFu+ZairTtp8KwV69H2Wxq93hfjSv/m65BzAUYCqWBtUE2Vc72q5DqnxdBsUA 8TCbIvczRBCNEtGp1S8OsD+xtl5xbRBKPFj+5w51XirTvYhOsi5/LM2LcMZ42lf86r3f +T4w== 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=ArgArcddnW6CEjs+l93gVDuxxjwgCYReD9AZQavuJB4=; b=xn9eH+JFoxXama3541Wox9KlS3Ec9z+bL5nLvmbEJrXNEgVfPoQgYqy6vgBL3Tlb0s fcbf157ud32iQ/CvmUvxoTbXtwZM7Bn4bhs2j3uZKp9SsHdgT0f+j9FluPQD8flucQxg tsZOETmPOtp77hRcXN5gQoNJMIl1dphSt6hTjjT2iFicKtbDQX8Nc0xfo+7HeOOf6D+F xIT5sUSF6TwAVzsNJr5/rJa2VPxwmSdZiaHGZyztceiPZkc0A/QVZiCVjlxCVu8jyiUS zdH/qhmRHNgG/YI7bIa5XCbOk1NGjgT0QNTEjrPTmt4xH7LJz3pTHVPkMVsnfs4XsBGA 65fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=FzQOPn6r; 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 ha1-20020a170906a88100b006f3be13d016si8717373ejb.37.2022.06.26.09.36.23; Sun, 26 Jun 2022 09:36: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=@gmail.com header.s=20210112 header.b=FzQOPn6r; 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 83A8368B81D; Sun, 26 Jun 2022 19:35:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 134EB68B7DF for ; Sun, 26 Jun 2022 19:35:34 +0300 (EEST) Received: by mail-pj1-f46.google.com with SMTP id k12-20020a17090a404c00b001eaabc1fe5dso10173574pjg.1 for ; Sun, 26 Jun 2022 09:35:34 -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=oYfoR8RImfUhwn1dzHYY1AxSOuEjRY43nJnB6xnih24=; b=FzQOPn6rHobEt4HwGcTN2U7XdbriMZvY+x8Z9O4lEoJ3UyR6lXkUEY/QY/Z7tAEoZt h2GEcyeTCn1LcFZ4DEbrcldrEP8D7tABBJsieH5623q3X947G1NjjWKiGLvP/xmBCEUl Fs+ygGyW3qNkmzju41bHciGLhBnd7bIOXH9/RbabQ4BQFVi5CCn48HXx4rmv0vkJfLkm M4DyOrccenxmv/49JkfO0+RivXA0eG1rdlCsyCLcwzHOr8ML8k92A+j7AXYOjEEyKbwF gGaxLXKpaXslzwunO752gfEEPLCf3NSZVcWxv35g987OzGMvFak7TZmw0xmEZAm+tn+F B5fw== 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=oYfoR8RImfUhwn1dzHYY1AxSOuEjRY43nJnB6xnih24=; b=wE5TZVJ4uzkSqvmBRoBjSxviJR/62/OYV/tJ+1Jt11i9FEwcSnio8NkWSpZrnBQuvJ IDvRVPNuMSTRs9hqw39XJoA1Cps7RXkQZrYj045XYcyn7rMLhiHmdCClR9AQYaCoO0XN O3SHD8VnezFn40B6beNLoxAoLA47ztmcB2qwkL/+1yXJiU1Eym/pxMOXRyaCVx3xB/DE TP4f0elJqY8XBu2B2dNtAYoGB7qi3s3rKpgrmSyPY5Crv1pbSUP5+pNs45afMbfNW83s KHipoNiSn3jnfOf7HFITjH+qc0/gnW7KKpeFKG1MMn+PacEUrR5ETkvqnRy8lEb3Es/O rBRg== X-Gm-Message-State: AJIora9QO1FTdprCf3INQ/fckjJqm0JlkKr3eJtuuzdcbMXN/3vWSlxp zKcb2r62NJyJObCAxVzDkTXAk1kjbl/Llg== X-Received: by 2002:a17:902:f34a:b0:16a:e2d:3e9 with SMTP id q10-20020a170902f34a00b0016a0e2d03e9mr10190365ple.95.1656261333150; Sun, 26 Jun 2022 09:35:33 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id d10-20020a170902e14a00b0016196bd15f4sm5427794pla.15.2022.06.26.09.35.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jun 2022 09:35:32 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <2e55dbe180301e658249b4737b80995af2f6f93d.1656261322.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Sun, 26 Jun 2022 16:35:06 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v6 09/25] 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: tGWgT+kUjGvW 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 7ba1c8a861..af52a77ebc 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 */