From patchwork Sat Sep 11 08:14:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 30132 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp2235284iov; Sat, 11 Sep 2021 01:14:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXzYhvoBd2Pj6OHQ1YMjndf1npiog1hXfdHIgytWJy3pUJXhPU3LCu+gR8Tbtj21S4jI8Z X-Received: by 2002:a05:6402:524f:: with SMTP id t15mr2162677edd.121.1631348062628; Sat, 11 Sep 2021 01:14:22 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d7si1287545edq.7.2021.09.11.01.14.21; Sat, 11 Sep 2021 01:14:22 -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=@hotmail.com header.s=selector1 header.b=Hft8nwbu; 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 98F3D68A5D1; Sat, 11 Sep 2021 11:14:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11olkn2101.outbound.protection.outlook.com [40.92.18.101]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 13A026809C3 for ; Sat, 11 Sep 2021 11:14:12 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cSsocnq554lhWLwxaUisWzaTfciHsXtE/e1eXg4uIWgbE3TF/9vw54v6AwbuFV8iYJ7PEBDRrE6U8+Nz8hpXa1VJ+7ApQgh4Mp8bxAtyMoDhrNvL7/JoidIZPQMBz1fslnETyHh99GcsIvLCuPw68A63nHKwfi25+eDP2DwZUrXcrFkqYRp8/SdB/x8BK6tfEdfGkXVAD5slCzF2YUsO1NuZ3JpVUjhvpzIfIEl9LEac7Xw/pIrj2zO51kKGuNVAIfMZb0JRX7j9ArDcaPwbLmw8t4D7zEG3YDIA7wWc7zwjAIccujSTy3jXHKFMglBJMyaAiKEGaRTegxr118bj9A== 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; bh=L+0hREfX4eUh5Q7rzQiUyM+QqSYqC3DUo5fqX+5qvlY=; b=keP6FovRpQN9iSteDRpiUfbSHUUTHCndK87maxBBe5nCzoZOcQL6wNv+ttNWnh7saDfayjIFLIs+di08qeQZlkjOvjlwEA7klzUOmufJ4ygRWJBvS6j9clb2JI215+MV5EIu11JOjzzUsxE/mwJsbUO5CNdZPneZwqhNGFiWChYM/bJspoBwTcxuD7z+vitykeBV3Knss84Rgxaf9nV0a6WuzBP32G0Mnoct5ZlQ4sFkQf+rhmgg7OY2KZ1wnFLnyiADITSDQ2Prmuu15SS9qn08003l2Dfq38XUQo3YoE7pqNjgLTgwN++XJ9C4sK06ezUVfu3YjBYWpOOBrBJ41w== 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=L+0hREfX4eUh5Q7rzQiUyM+QqSYqC3DUo5fqX+5qvlY=; b=Hft8nwbuHbooXC9s01U5nKYpPswN720PmOOjUrVFQ6Q9egJDN1ZGGfNOElIX6Acs0Tvs0SU5oj/DDvcEza55XuafXKH+l24AKOr6mHdCUsEnG4ag1II1ojmQ6+n8APznzhK5b9Fhef+9o+zpPh7gJYxcH+5r75Wy9LhVA+SEGoV2nJf4Txz/MqmVrMH+Ruw2J3PxU9c2oEHW5vz3Q5V/iIqV96GexOZtlBovJgIcqCGkhWIzk+jB4Zuw9gLn2qPCNgY8t+MjzzhTsM1bhwjEyhMEn8SsvccX2KTDkdfgi0Q8h2cnNJup1yRwJ+tC2NewzBvGWEbYXWTdiU5JEIdXsg== Received: from MN2PR04MB5981.namprd04.prod.outlook.com (2603:10b6:208:da::10) by MN2PR04MB6048.namprd04.prod.outlook.com (2603:10b6:208:e5::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.16; Sat, 11 Sep 2021 08:14:05 +0000 Received: from MN2PR04MB5981.namprd04.prod.outlook.com ([fe80::ecfe:2528:2012:22cb]) by MN2PR04MB5981.namprd04.prod.outlook.com ([fe80::ecfe:2528:2012:22cb%5]) with mapi id 15.20.4500.018; Sat, 11 Sep 2021 08:14:05 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v4 02/18] avutil/subfmt: Move AVSubtitleType, AVSubtitle and AVSubtitleRect to avutil Thread-Index: AdemwRmnL/ThgFsIR+OoKPrLkl6fBw== Date: Sat, 11 Sep 2021 08:14:05 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [YTLciYzkpKn5wH4ADo90VQ/2r2r06QP4MlJRhxIgmJY=] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: df61f9ef-efaf-4307-9129-08d974fc1f5f x-ms-traffictypediagnostic: MN2PR04MB6048: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Qi/YLmZv8fvYi8DUT9akNua/BS1laPvpFpzROoVPJnzQ3tYQx8P56JY2aXALLXK6Rif6CYoCVGR4WwDheB2UdZl+S46WJWLO59Tj4rhBhS0CNk8bH809A3Q89FPQu8zCkym+sizpQn12iPHfSdr29FmSZxMAPdEdjmgfyt2c+qVBmw/eB5BnNkbv6QB2borjI3w4Vp7n9kthgebKZTbc3XFq1/Gu4KWDplNpA7Tbv1XD5ZnENPfCmnhEpIAJSklTuEFmcBzfUhrGpdEmL7N9kSnHuMJeNlzDw7FC4S4oh5r9wKSrbqwjTdBMFgGeTBpVzhtcHaA84EChkzAEXzk5js0WLOP1jheNPXuzsDdgWaVPKmNNEDBguWmjS+I+GT8WpeF33BFuVjCDREcafG+L0eQsN86NTSOFbhnjL68u0DAVkGhTJarpRwBtk2DQohDG x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 3X+YGWU1zJXj/g3wDGCeSG/qrzzoGmrvVjiTZKtIwTZPsfwj2M6ZqabObPtbTiX0WxFO4wXplslkLfp1gZlUybs2BV0bg997WXHc02uOMz10MKknuyLt9QXMmj2gTrour655AA0MRO/5gB8FQ4gh9Q== x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-3174-20-msonline-outlook-529c7.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN2PR04MB5981.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: df61f9ef-efaf-4307-9129-08d974fc1f5f X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Sep 2021 08:14:05.5733 (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: MN2PR04MB6048 Subject: [FFmpeg-devel] [PATCH v4 02/18] avutil/subfmt: Move AVSubtitleType, AVSubtitle and AVSubtitleRect to avutil 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: BRD9KrXvIJqA Moving these type to avutil - analog to e.g. samplefmt, pixfmt Signed-off-by: softworkz --- libavutil/Makefile | 2 + libavutil/subfmt.c | 78 ++++++++++++++++++++++++++++ libavutil/subfmt.h | 125 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 libavutil/subfmt.c create mode 100644 libavutil/subfmt.h diff --git a/libavutil/Makefile b/libavutil/Makefile index 410ac636f7..04e1101bf3 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -74,6 +74,7 @@ HEADERS = adler32.h \ sha512.h \ spherical.h \ stereo3d.h \ + subfmt.h \ threadmessage.h \ time.h \ timecode.h \ @@ -159,6 +160,7 @@ OBJS = adler32.o \ slicethread.o \ spherical.o \ stereo3d.o \ + subfmt.o \ threadmessage.o \ time.o \ timecode.o \ diff --git a/libavutil/subfmt.c b/libavutil/subfmt.c new file mode 100644 index 0000000000..8476c1a15d --- /dev/null +++ b/libavutil/subfmt.c @@ -0,0 +1,78 @@ +/* + * 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 +#include "common.h" +#include "subfmt.h" + +typedef struct SubtitleFmtInfo { + enum AVSubtitleType fmt; + char* name; +} SubtitleFmtInfo; + +static const SubtitleFmtInfo sub_fmt_info[AV_SUBTITLE_FMT_NB] = { + {.fmt = AV_SUBTITLE_FMT_UNKNOWN, .name = "Unknown subtitle format", }, + {.fmt = AV_SUBTITLE_FMT_BITMAP, .name = "Graphical subtitles", }, + {.fmt = AV_SUBTITLE_FMT_TEXT, .name = "Text subtitles (plain)", }, + {.fmt = AV_SUBTITLE_FMT_ASS, .name = "Text subtitles (ass)", }, +}; + +const char *av_get_subtitle_fmt_name(enum AVSubtitleType sub_fmt) +{ + if (sub_fmt < 0 || sub_fmt >= AV_SUBTITLE_FMT_NB) + return NULL; + return sub_fmt_info[sub_fmt].name; +} + +enum AVSubtitleType av_get_subtitle_fmt(const char *name) +{ + int i; + + for (i = 0; i < AV_SUBTITLE_FMT_NB; i++) + if (!strcmp(sub_fmt_info[i].name, name)) + return i; + return AV_SUBTITLE_FMT_NONE; +} + + +void avsubtitle_free(AVSubtitle *sub) +{ + unsigned i; + + for (i = 0; i < sub->num_rects; i++) { + av_freep(&sub->rects[i]->data[0]); + av_freep(&sub->rects[i]->data[1]); + av_freep(&sub->rects[i]->data[2]); + av_freep(&sub->rects[i]->data[3]); + av_freep(&sub->rects[i]->text); + av_freep(&sub->rects[i]->ass); + av_freep(&sub->rects[i]); + } + + av_freep(&sub->rects); + + memset(sub, 0, sizeof(*sub)); +} + +void avsubtitle_free_ref(void *opaque, uint8_t *data) +{ + avsubtitle_free((AVSubtitle *)data); +} + diff --git a/libavutil/subfmt.h b/libavutil/subfmt.h new file mode 100644 index 0000000000..c6544433d0 --- /dev/null +++ b/libavutil/subfmt.h @@ -0,0 +1,125 @@ +/* + * 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 AVUTIL_SUBFMT_H +#define AVUTIL_SUBFMT_H + +#include + +#include "attributes.h" + +enum AVSubtitleType { + + /** + * Subtitle format unknown. + */ + AV_SUBTITLE_FMT_NONE = -1, + + /** + * Subtitle format unknown. + */ + AV_SUBTITLE_FMT_UNKNOWN = 0, + + /** + * Bitmap area in AVSubtitleRect.data, pixfmt AV_PIX_FMT_PAL8. + */ + AV_SUBTITLE_FMT_BITMAP = 1, + + /** + * Plain text in AVSubtitleRect.text. + */ + AV_SUBTITLE_FMT_TEXT = 2, + + /** + * Text Formatted as per ASS specification, contained AVSubtitleRect.ass. + */ + AV_SUBTITLE_FMT_ASS = 3, + + AV_SUBTITLE_FMT_NB, +}; + +typedef struct AVSubtitleRect { + int x; ///< top left corner of pict, undefined when pict is not set + int y; ///< top left corner of pict, undefined when pict is not set + int w; ///< width of pict, undefined when pict is not set + int h; ///< height of pict, undefined when pict is not set + int nb_colors; ///< number of colors in pict, undefined when pict is not set + + /** + * data+linesize for the bitmap of this subtitle. + */ + uint8_t *data[4]; + int linesize[4]; + + enum AVSubtitleType type; + + char *text; ///< 0 terminated plain UTF-8 text + + /** + * 0-terminated ASS/SSA compatible event line. + */ + char *ass; + + int flags; +} AVSubtitleRect; + +typedef struct AVSubtitle { + enum AVSubtitleType format; + uint32_t start_display_time; /* relative to packet pts, in ms */ + uint32_t end_display_time; /* relative to packet pts, in ms */ + unsigned num_rects; + AVSubtitleRect **rects; + int64_t pts; ///< Same as packet pts, in AV_TIME_BASE + + /** + * Header containing style information for text subtitles. + */ + char *header; +} AVSubtitle; + +/** + * Return the name of sub_fmt, or NULL if sub_fmt is not + * recognized. + */ +const char *av_get_subtitle_fmt_name(enum AVSubtitleType sub_fmt); + +/** + * Return a subtitle format corresponding to name, or AV_SUBTITLE_FMT_NONE + * on error. + */ +enum AVSubtitleType av_get_subtitle_fmt(const char *name); + +/** + * Free all allocated data in the given subtitle struct. + * + * @param sub AVSubtitle to free. + */ +void avsubtitle_free(AVSubtitle *sub); + +/** + * Free subtitle (for use with av_buffer) + * + * @param opaque unused + * @param data AVSubtitle to free. + */ +void avsubtitle_free_ref(void *opaque, uint8_t *data); + + +#endif /* AVUTIL_SUBFMT_H */