From patchwork Wed Jul 26 09:27:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hung kuishing X-Patchwork-Id: 42991 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7528:b0:130:ccc6:6c4b with SMTP id r40csp394814pzd; Wed, 26 Jul 2023 02:27:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlEVtDL4Irqww88/bTH2FPUkDyFvXHhQplIv+JMjrhFFDUibiWgBrkWMMu059MPF0sbXb2uD X-Received: by 2002:aa7:c544:0:b0:522:37fc:71fb with SMTP id s4-20020aa7c544000000b0052237fc71fbmr1206935edr.37.1690363668256; Wed, 26 Jul 2023 02:27:48 -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 f10-20020a50ee8a000000b005222ab8744bsi4592691edr.332.2023.07.26.02.27.47; Wed, 26 Jul 2023 02:27:48 -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=@outlook.com header.s=selector1 header.b=SoTc05Of; 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=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9782F68C931; Wed, 26 Jul 2023 12:27:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10olkn2046.outbound.protection.outlook.com [40.92.42.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D032A68BF90 for ; Wed, 26 Jul 2023 12:27:36 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EjOMwLte3l5IFkxj8ycP+awDJv6kFDJjd+VoGlpZTeysWIOoKeX3KHdnre6YpOexnd48yHwpLT2yY5CDK1GedkL1wYRifZsAvdsP8ZuirC3wm22ELiRZHzNF1K5gz9VnLSGCWgutDpTEDGuGMxvmLFqBn2+IvCL5aSQmrEo7pC+rgAE6wkGjQDgPX6GPuBl/nEmNLLxiodJL8W9sWSm36jlp79FrAFav/Lt7RYnrHZzclhi1V/DQmzefSYYKiawk/MG+5eq0KI45AOM8NWPXE9j9qDAR9wo4ziu4DK/jjBknTiqMPdY0EYrkNC48OSRoZ67agPh+Xuc4JfxdQxiMoQ== 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=PzpeP5s7kWjpkdno6ng0JxC3lX9RWs8FAcXkFiqeZuM=; b=d4s7aV488fnrl7nUXkFFyCthlqKPsnKVvVLFrmWp6ZWB5dlBO5+mqIWqo5j+aTMviARaTj8e01tPx9VzW6UZbpOff0mcTUvn9m5tyHa/r9gjdRJUJ/gND6OfSjCdQWXOgRGhfEp15sYvblBrBwra7GBiKVZFnnIqQ7jgX6U421mschOErWGPKOueCZp2WEeuAxQbrIl8wKV8f7KXUhVQYe8vmEmUTMypPESozfY91V3iTFtweBZFbwBTyCYZ4O8feIVOUZ7fnyS1tReIaxuCMXAI7ZuPbLGm2kqUJX5u1585lmzF8uDQsuGcuKv2bA1SbGesmRlN8Q14p8U3VrRdJA== 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=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PzpeP5s7kWjpkdno6ng0JxC3lX9RWs8FAcXkFiqeZuM=; b=SoTc05Of/tYfpgAnhj+n+vn4qn/x90FxznVmmbPtBSmLbIEekhvyHxHGY6uOZxPuC6koobneZ91SP+fp/PB6ZGO5aY1/GvaH4rOB7Ykz3iPPJ4LnfRlwN4a2nwVXZv520Lidi0cwQbj0EeCl4pTbHJ61oj8+aR5MVeNj/mQlKv1Cnp0k2Subu6YyZk1EDGMLvC9EIN3+Dwn4NblXxVfAKpDyJRiEfWsninq/iLe+vh+9DWmri+cZlgtOODERHU9IDY16QxsdGckHGyj0rH9HsHlYZgb1unWT3iEzl46yuoNOWmXipLjt4DqWMBugfQ9m1AlLfOSRpqzShzB+b5t59g== Received: from PH7PR11MB7430.namprd11.prod.outlook.com (2603:10b6:510:274::20) by PH7PR11MB7431.namprd11.prod.outlook.com (2603:10b6:510:273::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Wed, 26 Jul 2023 09:27:33 +0000 Received: from PH7PR11MB7430.namprd11.prod.outlook.com ([fe80::6216:b3a7:a5b2:bd43]) by PH7PR11MB7430.namprd11.prod.outlook.com ([fe80::6216:b3a7:a5b2:bd43%4]) with mapi id 15.20.6609.032; Wed, 26 Jul 2023 09:27:33 +0000 From: hung kuishing To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v3 1/2] lavc: add prores bitstream parser Thread-Index: Adm/oR9ORkqO1RQ5TMqZviRF/8FgLA== Date: Wed, 26 Jul 2023 09:27:33 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [+jmUB7PM9f+WXa98yRs+AwnNAbkkdKd4eYHHYMwizmQ=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PH7PR11MB7430:EE_|PH7PR11MB7431:EE_ x-ms-office365-filtering-correlation-id: bcd866d8-2e2e-4432-4d8e-08db8dba8aac x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: +iVIt4Z5R1G6R4A8FwrWfpelMJYzHXe6HpUO9kBYpgqQ7/ZlD3n0mOEiSiCDYSyBsWfKXJO/Q7uQBi5gC7xxjodwuJIHwLzqBhqpv3mWJjm6+gotA7yoUHQy/bQXIBGfmvK58gQR/8z+/lNhYbHKvNDxKmKCrhM7GnXyIPotYfIj5vp7Fk5qdn4leKY2uAif8z3G40HUlTkXzoT+TIumtYYQQ9HaIM5k92se8soGQfcWbnQO6mfxICvdqlAhHChqlmzoGf25ye21JZopkvMQ0Zq/QjkgNATzPFvCKqYmxRiWndUwGltHizWfa7JOIoTtnLcnbdVznW7P3PN/FYFbqYj5835QDUek5ihDjjgNrb3D8xJnp7Xhut5vkAMSfWyJE4P5oyLs7ZZscyJuLmDQqJvsxi9muXHXVK29ADihDSXwiQ9wBGMpNFo9P5ZIQGhuMTwiEhpuGu+ZeOE1HYudbYA3O0G9XaOMYdjYfA+ORQ+fK0hqScWNR1a1elAFCsPFTpE0JuuNYL13fUS9dYc0xBPQhWT8u9iBSPWXHGJM35e5k6NcLHU3oagawISs6TMz x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?cMG8trbEqR81itxiVzObOCekTaWl?= =?utf-8?q?17fAX407/BtBM3nEkUhcqd6Ane3z7mMOtvHutjyzcwBIhWovH/qQ+2KIknO8vmiPQ?= =?utf-8?q?MdrDN5zNIyyIbWkj3ZllVGsm05lza1ti2va2lUS54h2hF1N2Of2ZjAccP7JfsRdhQ?= =?utf-8?q?JFBu8E2fE9cf6bKyxjBhlWL4ZAAGp41wHTBvj+UmDydYhLI91uF6oDWM4QPc8gfUm?= =?utf-8?q?U437jh3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5dADGXHoB9GLZZifueIfka5X6xEAa80Eri45063PE/busFIj2KiwGoJOo?= =?utf-8?q?hDsRn2xbxVsjl3EH4pku3psMJebMq0Wib/YUnhfw=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH7PR11MB7430.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: bcd866d8-2e2e-4432-4d8e-08db8dba8aac X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Jul 2023 09:27:33.2685 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB7431 Subject: [FFmpeg-devel] [PATCH v3 1/2] lavc: add prores bitstream parser 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: uxA1nu2o9x4A Signed-off-by: clarkh --- libavcodec/Makefile | 1 + libavcodec/parsers.c | 1 + libavcodec/prores_parser.c | 107 +++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 libavcodec/prores_parser.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 1b0226c089..21cd28c9ac 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1198,6 +1198,7 @@ OBJS-$(CONFIG_OPUS_PARSER) += opus_parser.o opus_parse.o \ vorbis_data.o OBJS-$(CONFIG_PNG_PARSER) += png_parser.o OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o +OBJS-$(CONFIG_PRORES_PARSER) += prores_parser.o OBJS-$(CONFIG_QOI_PARSER) += qoi_parser.o OBJS-$(CONFIG_RV30_PARSER) += rv34_parser.o OBJS-$(CONFIG_RV40_PARSER) += rv34_parser.o diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c index 285f81a901..131867686a 100644 --- a/libavcodec/parsers.c +++ b/libavcodec/parsers.c @@ -64,6 +64,7 @@ extern const AVCodecParser ff_mpegvideo_parser; extern const AVCodecParser ff_opus_parser; extern const AVCodecParser ff_png_parser; extern const AVCodecParser ff_pnm_parser; +extern const AVCodecParser ff_prores_parser; extern const AVCodecParser ff_qoi_parser; extern const AVCodecParser ff_rv30_parser; extern const AVCodecParser ff_rv40_parser; diff --git a/libavcodec/prores_parser.c b/libavcodec/prores_parser.c new file mode 100644 index 0000000000..1299c7b642 --- /dev/null +++ b/libavcodec/prores_parser.c @@ -0,0 +1,107 @@ +/* + * ProRes bitstream parser + * Copyright (c) 2023 clarkh + * + * 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 "parser.h" +#include "libavutil/intreadwrite.h" +#include "libavcodec/proresdata.h" + +typedef struct { + ParseContext pc; + int remaining; + int overwrite; +} ProResParserContext; + +static int prores_find_frame_end(ProResParserContext *pctx, const uint8_t *buf, int buf_size) +{ + ParseContext *pc = &pctx->pc; + uint64_t state64 = pc->state64; + int pic_found = pc->frame_start_found; + int i = 0; + + if (!pic_found) { + for (i = 0; i < buf_size; i++) { + state64 = (state64 << 8) | buf[i]; + if ((state64 & 0xFFFFFFFF) == FRAME_ID) { + i++; + pic_found = 1; + pctx->remaining = state64 >> 32; + pctx->remaining -= pctx->overwrite; + break; + } + } + } + + if (pic_found) { + if (!buf_size) + return END_NOT_FOUND; + + if (pctx->remaining > buf_size) { + pctx->remaining -= buf_size; + } else { + int remaining = pctx->remaining; + + pc->frame_start_found = 0; + pc->state64 = -1; + pctx->remaining = 0; + pctx->overwrite = 0; + return remaining; + } + } else { + pctx->overwrite += buf_size; + } + + pc->frame_start_found = pic_found; + pc->state64 = state64; + + return END_NOT_FOUND; +} + +static int prores_parse(AVCodecParserContext *s, AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ProResParserContext *pctx = s->priv_data; + ParseContext *pc = &pctx->pc; + int next; + + if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { + next = buf_size; + } else { + next = prores_find_frame_end(pctx, buf, buf_size); + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + } + + *poutbuf = buf; + *poutbuf_size = buf_size; + + return next; +} + +const AVCodecParser ff_prores_parser = { + .codec_ids = { AV_CODEC_ID_PRORES }, + .priv_data_size = sizeof(ProResParserContext), + .parser_parse = prores_parse, + .parser_close = ff_parse_close +};