From patchwork Sat Sep 11 06:48:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 30128 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp2190362iov; Fri, 10 Sep 2021 23:48:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2jeeVhVv8wDgZ02/R2r7eSwBzdQU02FSS8PfBJaK2kxRS/4sZtJlbFM42bZGQhVyv79Ac X-Received: by 2002:a05:6402:48b:: with SMTP id k11mr1921791edv.7.1631342922383; Fri, 10 Sep 2021 23:48:42 -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 da3si962598edb.255.2021.09.10.23.48.41; Fri, 10 Sep 2021 23:48:42 -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=gdtWC3sC; 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 C6504689C28; Sat, 11 Sep 2021 09:48:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12olkn2075.outbound.protection.outlook.com [40.92.23.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42330689C28 for ; Sat, 11 Sep 2021 09:48:30 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GEkpVlDxlL2Lof+lNOTFtWYmfPCT2ZhnF/PRqcGadKevQIcoE8k4x75U8iJIrIjBuNy4y3Z+Ex4QFuCNWDORiberx0Yz/2mcKksOr+Ek/UxURgOSeNjjL/jImjD3UYXPwQLJIjCiBh+16Wvm3qzHTWEcbetEAFUuiY6paD6QFcp2S8fkVwMvbag36L3RR/c52eMjay2KbgsYR/q3DyJZuYmE3zseXzLsmk1YLxNuKrlkL6JSfwGdPdgNsoGhFJ9hBYUEfCApltd7WNZhKPEWFFPmBkPLectgUbGKhcLFXSqBMzHdJol/YzoA3BxixOAdzPHyqRIokkmalJuXZvorUw== 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=QzAsg/ViSvePS6nZHFKYWCYrQmo4Tt6FeYmY3K2x8GqekerpBCDW/+xjmdiL5rw8qbKvgC41VCY9R0Wkt2kkxEskNtfsgb1beOczqAfapsvRhIwz4umBPWLVmyM/5iEzkOHMO2dr74RdJEYySl7A+cbcttBWklCkaFWvQijXbdo8yZDVzN2CA/7QI5kqnQQgJvbF2j4s9A+hotjWk/rVL2TjUQBVRjbiyn4c+P4STseIYNosd60IJ/FQzVKOwigs14R3Gso6fbzrU/LJ6x1WhAR8c6zWAc5gouOho2slFz7Yx9amdp6MNRLoWcRUyM/h2OctxbRuKXMBDuBlGphkdg== 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=gdtWC3sCYbFiOTxvg3MiEGK+v8dVuNqRgd80xehzk3uY7NErCYqQV11Ve6pv1254NeCj8kNsH+i9qAxpxSxdZWt7Ull2kBzOLLYfPzyvLf61Dbup4sYu37mZ3QtfWSFNzxabOytYigfqpFyfZSJ2umS5jOqrOITzGRNHr8vkfYZZrxxhcE+8oPj5partqrloSpK/ahUqWUyRLedNttRRpo064JZwasAJAo91mIqzLhnunUL68nq57QAxP/N340TTXd9XJr4fpV+h7BGrUMu3JnuvEk8Am6yzmFa6cGC7rc3nNAAox2o7Jyj6zS5mLMmeqdQwxWg6yi3ZkErIoaxECA== Received: from MN2PR04MB5981.namprd04.prod.outlook.com (2603:10b6:208:da::10) by MN2PR04MB5502.namprd04.prod.outlook.com (2603:10b6:208:e0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Sat, 11 Sep 2021 06:48:27 +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 06:48:26 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v3 02/18] avutil/subfmt: Move AVSubtitleType, AVSubtitle and AVSubtitleRect to avutil Thread-Index: AdemwRmnOFBsDcMZSfOwOaERame8yA== Date: Sat, 11 Sep 2021 06:48:26 +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: [hsKz9c4Irg0X0Cei8F+QJ7pBkVOiiJsogP2lHOWdi7w=] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 15204766-6b19-4f3b-35d8-08d974f02873 x-ms-traffictypediagnostic: MN2PR04MB5502: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: YBhs3hdQ/iT7wKpe6F8Ir7EiL06pKE9k3DD+W4OGkpRTllx3gDkqq7e2Y3lGvR3WA+ryB9R4q5+veIR2/Cs3nqay5pRBsQxxCsXpMEBA2RFEvYir3XipVd8fD9BaOLFx9qx1Tg9gtL3HTs/VUfQa9y0+16iexzpXIRLJVEUmwxOQCKpttAE9dNw5KgSFqYfobwqIZ3pMEINPRxLZPBYSRYn6SWUk1OfbnCmjNznQbLHraJnekA65uWQBPKmhzGIkfQZGc46uMGfT0yvyn8mRqiPbJJtNC5+fAJlsAJ+R8Yw237YXYZdrfzTDFPrfWgzHYjIIYCsyEWL5pJSo05bJSArsQJTjYMLj1QsHP558uIYCw+86QxQrpKU/ZMSP6tVMxRm7MUPrw7vyJQItAQyqWcg0nDqj5MTwFgvdQgMY5ZMvCy0ub+QZ4egUZd5nStEz x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: XFMlo/y/iYdWFKEjMeXQ6sQ7v3tFbaHoQJM0unoo2joJemqvYvgSWTce1ZknmjHYGJ312RP4VfepJynouQrQmvJSkZMktc2mSNaTEQbsv2kVgVqd22C81w2b59OOlDBrMo28ZThJvHjWASCkO0TDmQ== 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: 15204766-6b19-4f3b-35d8-08d974f02873 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Sep 2021 06:48:26.7458 (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: MN2PR04MB5502 Subject: [FFmpeg-devel] [PATCH v3 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: CciuPLsy5/DR 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 */