From patchwork Fri Dec 3 19:31:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 31941 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp1097814iog; Fri, 3 Dec 2021 11:32:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJyIQ4Xg/48IhEVe5ThIvN3AEGlS2eS1YCA0sx07a/l9Itj9eitDWDFWywfvSh/PyolFUJX6 X-Received: by 2002:a05:6402:12c1:: with SMTP id k1mr28797903edx.355.1638559968188; Fri, 03 Dec 2021 11:32:48 -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 qf24si6500268ejc.430.2021.12.03.11.32.47; Fri, 03 Dec 2021 11:32:48 -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=Sfqdk4qT; 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 5A4E868AED0; Fri, 3 Dec 2021 21:31:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10olkn2103.outbound.protection.outlook.com [40.92.42.103]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5170F68AE9E for ; Fri, 3 Dec 2021 21:31:30 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n6QL0S7WZKVO7Ok+6CJHSGlFUqQyiHn11Ym9iUm6MaOs7QjHQHfNVwKwJTApzIR6mPvsnDKRNBCN0ShhLE3b7NwmnMNfpIS1G1yFpIDXRjzdIoDi7/KvRC05Wt7DFtIBEQP4nXjqNzNeZqK5sCdXLqSP3yQbzeTYyduPcCihfa3Ywxs+Y12oLXjQg3Et+55a3SMndLHUaPDgVSp+5lr4JwHszsCFHDBs5wJw2L/MMcZ4+4mpnfPuUeKM86woDS1ft+LfXgtfeeHq3j0v2eXmt+41/WSndNVrO6qdxn/zSrFE4SlP2iffIAtMWDIKxaLU8n9BmrLDUvALtHX8GBOfcQ== 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=MRY/E5+NIlzJScNIyQUozlVnJtCJhDhtHCVpijJk8uM=; b=KWS9VbsaehYk7EyUZwThIwAjZpEPt3zCVEGNo8v4R+bpSCcH2bq04kqzL20AMdikpseO3e/EpxJFUs7dIdbv+i0Lj5X1h5HrDef24XX0dhjEzmaQ9M5WLTkzFGmZACwCGoWEnG7Ar+Olk4vClPHGNFhLBd2W2OM8vxAxhdfZCq8gfuiUh/cWemxddl7a9FFlSc7m5PWJ2pDCUoyPNsQJXoLBpTfA97zRMzxv/S52fcs5Ss+6D92NOwVEvtjnHkqV0see0iJpYLLV1nRuCvtqeC8Fz20cDrPVOMiExvvMCZy3PqfpF8Er+u3trDJxJ7z2d7hf1iGU0pTf4M5BlReX/g== 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=MRY/E5+NIlzJScNIyQUozlVnJtCJhDhtHCVpijJk8uM=; b=Sfqdk4qTr4Rw5D6XEsnu5qF+UD9CYcc4Au/jmG6chQCMbD1zesIpR7QfcTAZ8Mhd0zYM/iVI4irGxZ3RhAIptqdmN0xwcIvTimZou5iodgzRoEaDeyuVZb6Z5vW6vmYGOgmK6+9Rpqp5j2R2BO0+jrLeU04GS4ghgakJueA+tM507FSbYLCfiD6IvlRpu+HR863wIzv2mjQ42/ddFtb99iuXvZxp8S4r5sXl/m7ZNNCmVWTEBAyn/B9QY36W80gOUT6VCXsGTFEda6n/DH60Zbv7BQnSMn4jGQ4pPuwb8vOgZBBlSIA76LS5VQoKak9gfhTiMQb7sBuMJhtVUaiuMw== Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:b::20) by DM8P223MB0333.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:8::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Fri, 3 Dec 2021 19:31:21 +0000 Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775]) by DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775%8]) with mapi id 15.20.4755.016; Fri, 3 Dec 2021 19:31:21 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v19 09/20] avfilter/subtitles: Add subtitles.c for subtitle frame allocation Thread-Index: AQHX6HxZEGwzhE7q70yJJbQFz4/F3Q== Date: Fri, 3 Dec 2021 19:31:21 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [HAWVqAOMbG5yHcCMrBfgC6xT0/Q+2cy9] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4a89273b-14a5-4260-b4f7-08d9b6937c5e x-ms-traffictypediagnostic: DM8P223MB0333: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: PVEjAhO05UXAYkemkSmAJKHw8mXDAL7Sbwo3ewmWe7nvggknM4NUzUtmkTlIs+i/Xnwpa0PfXARivhJapso0Hg3m/MRW3akJe2C9LIXfhbFarYCdgEcAqKRK1WXMex2qZLH+niYzhMpqFnZcYExHXlwkLsMmwakK8EmWwLLvNxNxZNBqURTGGsQYmMpgrFu6W9xEZcLqgy8/ilObg1PMZAx20Flm6E2a2ifgSdvZrBa3b2A/x18uz3SyGcdSHr3T++24XmVJhUVwHeOgWVDkzVN1ZA7RVUeIXPhHMgeimgAUZsehS5FdOduCpZipTJz8lCbFY6kl4elyA28nFUhmSsNL4HebncukyjfuCcSfKhRo9zmSSH9g9S0TSY2ZHY2IKws0dKXhUPRtHy/Xlvj1MP9/sJXNDaT/Wej71j8jrVS7IjJd9rH8DQNMd4PkHVqVMQfFiEK6c38yqdwA7dDMz5gcEDnQnazId7nkL8gyK4EuKBZLIpp328QvqXept/fIM0x9T7KGCB4wuy9OGeEyIUnBKE3C9FhHF8Jlh3FL1H/ldhWSBR71BeLZ1KBYpWFGUIbedpD6uBSnQdp/al2yVw== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?OpVrDsQZwtLJVK4YurnLd0/l05AI?= =?utf-8?q?uKs6UL4qkdxHWV/uHQ6C+LAzFNlmEX0bvvPqJEMseZgZogC7WmIMZgYR4iBUxPKr+?= =?utf-8?q?nVOWu5VVstgWY0XIWPLppgPQQl28g1+4u/xL8GpBLP7vaRU00NYjv0/kiMyVOZ+FI?= =?utf-8?q?vtmR0bbwTxP6+oEtx95LHzjLF7pJiEL5GcfI3T1t2sQgqE6wZpve0nUUZrz4lygiW?= =?utf-8?q?q71FHt/iVklX3+XWCRhJCwbzfTDFbuujL3v2mX4MgoydE+GvNP2do/Fgj4Ytd5WFC?= =?utf-8?q?ZaNGhOe/PWY5i+NKWcLEXkJbhrr/CQa48K8TfQVXA1bAIHHzfL9bLaWrzT9/9FHSD?= =?utf-8?q?MECqLhQGOHpY8qC71CeA7o+gdXJa7gX+BP4NuFYPhM0+AT8XH1fK78Vjx7hTzpu8I?= =?utf-8?q?BOKwOUTZc42R0e/+wHjIHyu8vHUH5IosBsACUYljRikJANJla6BLdoUgSZJkgZtQS?= =?utf-8?q?j1uZgvY9W3izPza2uRwFy7EurN1PXCoc3IfXoIEbFXKuhGk/1PMCe8Pn0z1QEQDeG?= =?utf-8?q?AyKk85ez7F7WZ1ds0HfcInVHg6XQSNEJYYmgxXuxshZF6tlUJ9R3FCIRvSVcinLpf?= =?utf-8?q?eegVVoHG4MR0nf3B8H4c2TWdDr3/yOxBG58Gpu4zaq5gwJfqkVXpAzP/LD8rqbfTH?= =?utf-8?q?EJrCIW/qmYA9GFUDXEBzgsl/iQoY82mU0u0x01GnuHKwN2KHwzY4vjBvuXmfz9EVO?= =?utf-8?q?TRpuGCzRjEcqL8KUCKL7IxLKLkIhqYabETIlr6wyCv2TXHzq6psuhVMmYkNrCL4ky?= =?utf-8?q?uYRuk47fLoYpD9vO+pqXUHo4ciXqXaYsF9T5+0nVLzOaETt6GVte7AXVJOPWLcWoy?= =?utf-8?q?m5U5hj4vZChW49dNPYwIJSh9iK4ItAoNhX44Qw90p/sKXkY0k/paX1ofhxhd448rm?= =?utf-8?q?gdIBanXhiSddK7w5SW0GByj2R0mu5DVMCowXSfT5dWWQ=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-1ff67.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: 4a89273b-14a5-4260-b4f7-08d9b6937c5e X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Dec 2021 19:31:21.1878 (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: DM8P223MB0333 Subject: [FFmpeg-devel] [PATCH v19 09/20] 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: /lS47nuFs854 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 c8082c4a2f..664566a18a 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 */