From patchwork Tue Oct 25 09:13:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 38982 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2684518pzb; Tue, 25 Oct 2022 02:14:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6cCmKJtbGiBzSo7POyY5Gjl9uaTYNAmUCCRdeOqPq6fhDyngL3Lm/eycwaUxNdW2F1OVuP X-Received: by 2002:a05:6402:5207:b0:462:2426:48fc with SMTP id s7-20020a056402520700b00462242648fcmr1402813edd.93.1666689298919; Tue, 25 Oct 2022 02:14:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666689298; cv=none; d=google.com; s=arc-20160816; b=H8Q2rcPaElu0pOl1Ig/6hCuFy8HN9gIjpCVOhdSNgyGEzkHxMUzk2tjX2k1zRAVah/ BxAj0F/ZkDHcF0YJz3ceIsFry/jjEnlVhTZwcgYRi6xxFd+J8Ojj7baxxQn4KoNIHwhb CJK0tqwHvZxQ//zyR55y366WhzMHOebYILrPjBWaqa75Ievac8hBIJ9/BGLG1TecNyVf GX0P1NyN2glGfjItDoAuNjw/wEAr/FAWGerVc+WIt/RIhO32/2FgUHJ4p/Fw2xENvBTm QblC0X+Krpw6kZk/lPmiLXXTO4l300F0pUSLcb6VJuZNmNEEHAMQ+XxDSdspXtJ9bk0x tXRg== 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=OJlsCKMQC4eGamzGa2DyUruCavumRYBWd7KYR+WjXK8=; b=Zl+8B/d0OE0B4zur7CSzhtuCtMwTEzVHz7udNA1hzEMgDab9IyVCwez6PLgdamNVEV 2XrZ60SA/Gtp5eCNRrSgF0Wa/BoEVQ9Fhj9gnXbJfx6sVxjYglO5c/4lsO27O/PMDTLy l7Eaz27quZod+88CaCAhAF4lgoFKsvn3wkSvATP6B3/WGgbc6pOwC0/dWCpiaoVvkQ37 JMCTsGSkLesDojZWJTIN1Mslt1j0vIeoj2uOmW86SSITdbgKIqv1Jzmui3LLDwN8mRhC iLBfvBl2fZvG/nwUxIk8WRGwMoWDmg/ZyBDfqpWnU9h1qMrLE0UTeljVjLJixeLS7TQB 0IPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=VIKWdi5O; 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 gb24-20020a170907961800b007aa3373e802si2214669ejc.660.2022.10.25.02.14.58; Tue, 25 Oct 2022 02:14:58 -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=VIKWdi5O; 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 DF38968BC71; Tue, 25 Oct 2022 12:14:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9134C68BC3E for ; Tue, 25 Oct 2022 12:14:01 +0300 (EEST) Received: by mail-pl1-f180.google.com with SMTP id c2so2447227plz.11 for ; Tue, 25 Oct 2022 02:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:from:to:cc:subject:date :message-id:reply-to; bh=3RMhou2wJmR42zACoesomNs+7Fxvt4YtKlP7MzDsX0E=; b=VIKWdi5OL4MRo6VLS0oxYJJ3wAycm+tDFD72ui02eGd5gzWF4NO49s7F8SdGYEISdE ckC/UYXJYwm25OUyHB+DhnMF0LREHtE7mwI/gWr7H9LJQyGhwQwYYX12FpYG6vpa09xC Gv5jNGdFkMyDOTZk8hfM+1qQ8DGjkxjpbww7vRjAS4IawcR0BKhdtwxkxQForThAMGza maf2nZp3MqqvK76P9/pvk+YiYWy8bVq2qAZVmKLt7Hx7RH4+63I6ehGyQI+21X5LgGA5 y41P9O6/hg56xzgqdyj29jCKIzeErG3Q/Ilauuqf06d8qCM3a9AeUa9akteHKfSdHP2m UKGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=3RMhou2wJmR42zACoesomNs+7Fxvt4YtKlP7MzDsX0E=; b=Nzg7+OHeC2iPH2I4RTv2uvvxObrXkO56oUPkY6HCJIwVMeAler2HIuWV/j/dPLJ4bf x51+JZDhdnKXLbVs4BrctT2dUbXbITEkrCEBQoJ/Z/SnYpypkkaXZmFn6rASHfgmMafu YC8jGVzUCXGhRRItnZE1Q50FUvejx21EffpRZSx0GJZcaZtV1j4pgUPrzoD3HKy0RDAw Zqolsg9Ugl3F7jI3jPipmZiZLlZKzXVR0WRCbX2Nr/JwgfOtEgU/UVzS+NWWRfIIctco KVwMQVDoXmwYtgCPFpL+sjgXAVBeQWpzEdVt8D/UiKx1gI54zT4pDJ019gvFuhAPqnCZ Kd7Q== X-Gm-Message-State: ACrzQf17NfQKpZMiKY3LjlIWVn8Nf7z006Bx+wTY9qqrdYrcID87r32n t9NObO1tkCXUAIdRndqGT6/QVrKQVmo= X-Received: by 2002:a17:902:7b8f:b0:186:a1c4:e648 with SMTP id w15-20020a1709027b8f00b00186a1c4e648mr10521976pll.37.1666689239963; Tue, 25 Oct 2022 02:13:59 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id f1-20020a170902684100b00172fad607b3sm871077pln.207.2022.10.25.02.13.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Oct 2022 02:13:59 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <2ea0e7130348dae1e9982bd9e8737d79a1a708b0.1666689226.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Tue, 25 Oct 2022 09:13:30 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v9 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: softworkz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: YvCLxQzPFcGH 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 ff2a06c262..6db90028e0 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -21,6 +21,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 cc5505e65b..e49d76c14a 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" static void tlog_ref(void *ctx, AVFrame *ref, int end) { @@ -1462,6 +1463,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 aaf2c6c584..1a0752e4ee 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 */