From patchwork Wed Dec 14 12:00:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawid Kozinski X-Patchwork-Id: 39697 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp250264pzb; Wed, 14 Dec 2022 04:00:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf4sumiTb4EWYR/qyi2vAhiE5AOBFGas8Pict6huS1MBqmLXqDIeOgGj9vm0ybZZ0sHqJj9X X-Received: by 2002:a17:907:d40f:b0:7c4:f402:9769 with SMTP id vi15-20020a170907d40f00b007c4f4029769mr1144764ejc.76.1671019239116; Wed, 14 Dec 2022 04:00:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671019239; cv=none; d=google.com; s=arc-20160816; b=aqedTpD3TWUBq5brYG8lfHL56TNAFKyb6Xs1w1XAzskW2mDpMx8evHlLdqeoImHH1y PoDfX3qOALFlslJHFI68oJKuCZ+DkaCx7l2E8N7ZzcZNjxvxIggpZn+mIDH5SbVvbNoO WoIPMxKymfhmdYl1hS5sWrZiaUkgPGr5Y6BdUHIi6blZbZFFx+/0RDClyzNb9anHvofx GapRYY5w80Yb7rIhfPNnmOl4PmUH5V4LWbTOeCQ7xC8SN2uPqEssgRvSnBN8CfB1p7Y2 ooNBP1XHXaAnww5/4Qfy6VkNSFPOcO7rsuKQsLkRMxOE+QJwuLWlS2TQtMAWoJi31eRM aGNA== 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:references:cms-type:mime-version :message-id:date:to:from:dkim-signature:dkim-filter:delivered-to; bh=0FhYCcwwOFsqxbSfY2NovJDpy9Dpxfde0tXUvVo9WKc=; b=fKnzTIVVIcGsRAkyYunLj1sn1qtoe4IRpBOvylv0eMwF9J3pEeJmjC25K/Q3Ll79M6 cci69LLy5ANE2M18hDxCqdfT4mdPvv8GCkTMHU5BpGVODqKeUwseClxfyj8zBDMgaZHS K9KZAY3hq7Av3M2+87ox5y6VJQGSNHWxmtznYu0vi4/8AV5wswXnv54w31aXFSKdUb+9 CNu7eAZ0cltEV41D2i7upA1RO+Xr3sfZEC48YC1qeB+Vv9A7WiTuD90ECpppWas3rFNX JuA/+/MMaMHBeHTJZ6955zAQ4KRc+T/0cLSNb0Me9BJAunc3Pa+69jIyT9w+8l6/C0Om h53A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=qX60vZVK; 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=samsung.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id kf17-20020a17090776d100b0078d4b605b71si8424601ejc.338.2022.12.14.04.00.38; Wed, 14 Dec 2022 04:00:39 -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=@samsung.com header.s=mail20170921 header.b=qX60vZVK; 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=samsung.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5A00268BAE4; Wed, 14 Dec 2022 14:00:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DC07768BAE4 for ; Wed, 14 Dec 2022 14:00:28 +0200 (EET) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20221214120028euoutp02e46f4f143d533919be0ab4a858f9d84d~wpyKEk-cy1295412954euoutp024 for ; Wed, 14 Dec 2022 12:00:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20221214120028euoutp02e46f4f143d533919be0ab4a858f9d84d~wpyKEk-cy1295412954euoutp024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1671019228; bh=x0Ebh6ZM1zpyzS4o9hU7BTaPVofVI0IiwKMLOmUN7yQ=; h=From:To:Cc:Subject:Date:References:From; b=qX60vZVKsGOSCJ5Ff0b2/tlSto6N2tNDOEu9rDU486kYY4Mq6P03ddcvb0e24ivS4 Ci1d3z50LVZAVQszEqR+yHhTPxEGCq2onXSjKvHmYU95tcGmBfoLykrc40NTEOLjnm nl0DMSPL7bG/CvyDtYOolIBad7m1xeTVEEF924K8= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20221214120028eucas1p2e42fc6196cabf9f63227146df60b6078~wpyJ1T8b00033100331eucas1p2Y; Wed, 14 Dec 2022 12:00:28 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id EF.26.10112.CDAB9936; Wed, 14 Dec 2022 12:00:28 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20221214120027eucas1p20b8703a0b0cc9e087001e45577662628~wpyJjhF-s0400004000eucas1p2X; Wed, 14 Dec 2022 12:00:27 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20221214120027eusmtrp228ac923d6bc885dc0caeca9f5488bfe6~wpyJi8sTm1992819928eusmtrp28; Wed, 14 Dec 2022 12:00:27 +0000 (GMT) X-AuditID: cbfec7f4-d09ff70000002780-68-6399badc303a Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id A5.2B.09026.BDAB9936; Wed, 14 Dec 2022 12:00:27 +0000 (GMT) Received: from AMDN5164.EU.corp.samsungelectronics.net (unknown [106.210.132.171]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20221214120027eusmtip1ae6dd6a655a7b23cdaea089300e93c15~wpyJJjrRi2276422764eusmtip15; Wed, 14 Dec 2022 12:00:27 +0000 (GMT) From: Dawid Kozinski To: d.frankiewic@samsung.com, ffmpeg-devel@ffmpeg.org Date: Wed, 14 Dec 2022 13:00:08 +0100 Message-Id: <20221214120008.1291-1-d.kozinski@samsung.com> X-Mailer: git-send-email 2.37.3.windows.1 MIME-Version: 1.0 X-Unsent: 1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrFIsWRmVeSWpSXmKPExsWy7djP87p3ds1MNui5wG7x5doXZouV336z WHz7dIbZgdnjz6LNLB59W1YxBjBFcdmkpOZklqUW6dslcGW8vGNdsFWrYsPjK4wNjC0KXYyc HBICJhInuj+ydDFycQgJrGCU2LLlKSOE84VRYv/dQ6wQzmdGia3XPrDAtJxb9pAdIrGcUeLA 4R9QTjuTROf9+0wgVWwCuhIvPzwCs0UETCVONu9lA7GZBbQl1t39DmYLCyRInD58mR3EZhFQ lTg5cR/QOg4OXgEriSnfGSGWaUpM2DIHbAyvgKDEyZlPoI7gllg36xIrxEh5ieats5lBbpAQ +Msu8WX9Y6giF4nW9pvsELawxKvjW6BsGYn/O+czgeySECiWONTvAGHWSBz6kQ5RYS3xtvE4 I0iYGeiE9bv0Ic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FGJg7GQ4wSHMxKIryqGtOShXhTEiurUovy44tKc1KLDzGaAp06kVlK NDkfGDd5JfGGZgamhiZmlgamlmbGSuK8ngUdiUIC6YklqdmpqQWpRTB9TBycUg1Mm56c3H9m ffjcR6vntAj06Rmv9Xu2yj9Bjkt8T+Rixblav5fV+XbtDmfqbvo3tSMi9wrLqwMdztMmm0yw npC5zWjXC7WwDUI7jhbfY/E9dFVv04nb96bbJKrN+85fcPb4ubxshbJS/kPtk75bq3z9IFLt eur2hSyV7Pm+U1+Z8sxqE/Conv3goJyrazWzlNjjJ1ceT5VaYhe0cYmyf59ZoeueCMtJR76o pH8Kf3b67Ip+hkvH2kp3vxDSnuvAc/Ws5fai+pfMb/rk31wUajxWX7zp+gzPSKd1O+J5Jzoo rJuU+eNI0tQ1J3o4H75O2WZvof3p5d1TFzjnCS5Udp3G/OraqoklDsxXlnI+WWW84JgSS3FG oqEWc1FxIgD+B0oO4wIAAA== X-CMS-MailID: 20221214120027eucas1p20b8703a0b0cc9e087001e45577662628 X-Msg-Generator: CA X-RootMTR: 20221214120027eucas1p20b8703a0b0cc9e087001e45577662628 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20221214120027eucas1p20b8703a0b0cc9e087001e45577662628 References: Subject: [FFmpeg-devel] [PATCH v15 4/9] avformat/evc_demuxer: Added demuxer to handle reading EVC video files 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: Dawid Kozinski Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: v9iPJDz5eNq/ - Provided AVInputFormat structure describing EVC input format (ff_evc_demuxer) Signed-off-by: Dawid Kozinski --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/evcdec.c | 124 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 libavformat/evcdec.c diff --git a/libavformat/Makefile b/libavformat/Makefile index a14a759c1f..af175d2097 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -251,6 +251,7 @@ OBJS-$(CONFIG_HCOM_DEMUXER) += hcom.o pcm.o OBJS-$(CONFIG_HDS_MUXER) += hdsenc.o OBJS-$(CONFIG_HEVC_DEMUXER) += hevcdec.o rawdec.o OBJS-$(CONFIG_HEVC_MUXER) += rawenc.o +OBJS-$(CONFIG_EVC_DEMUXER) += evcdec.o rawdec.o OBJS-$(CONFIG_EVC_MUXER) += rawenc.o OBJS-$(CONFIG_HLS_DEMUXER) += hls.o hls_sample_encryption.o OBJS-$(CONFIG_HLS_MUXER) += hlsenc.o hlsplaylist.o avc.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index aabc9b5f99..a963c0223d 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -153,6 +153,7 @@ extern const AVInputFormat ff_ea_cdata_demuxer; extern const AVInputFormat ff_eac3_demuxer; extern const AVOutputFormat ff_eac3_muxer; extern const AVInputFormat ff_epaf_demuxer; +extern const AVInputFormat ff_evc_demuxer; extern const AVOutputFormat ff_evc_muxer; extern const AVOutputFormat ff_f4v_muxer; extern const AVInputFormat ff_ffmetadata_demuxer; diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c new file mode 100644 index 0000000000..7887f0b591 --- /dev/null +++ b/libavformat/evcdec.c @@ -0,0 +1,124 @@ +/* + * RAW EVC video demuxer + * + * Copyright (c) 2021 Dawid Kozinski + * + * 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 "libavcodec/get_bits.h" +#include "libavcodec/golomb.h" +#include "libavcodec/internal.h" +#include "libavcodec/evc.h" + +#include "rawdec.h" +#include "avformat.h" + +typedef struct EVCParserContext { + int got_sps; + int got_pps; + int got_idr; + int got_nonidr; +} EVCParserContext; + +static int get_nalu_type(const uint8_t *bits, int bits_size) +{ + int unit_type_plus1 = 0; + + if (bits_size >= EVC_NALU_HEADER_SIZE) { + unsigned char *p = (unsigned char *)bits; + // forbidden_zero_bit + if ((p[0] & 0x80) != 0) { // Cannot get bitstream information. Malformed bitstream. + return -1; + } + + // nal_unit_type + unit_type_plus1 = (p[0] >> 1) & 0x3F; + } + + return unit_type_plus1 - 1; +} + +static uint32_t read_nal_unit_length(const uint8_t *bits, int bits_size) +{ + uint32_t nalu_len = 0; + + if (bits_size >= EVC_NALU_LENGTH_PREFIX_SIZE) { + + int t = 0; + unsigned char *p = (unsigned char *)bits; + + for (int i=0; ibuf; + int bytes_to_read = p->buf_size; + + while (bytes_to_read > EVC_NALU_LENGTH_PREFIX_SIZE) { + + nalu_size = read_nal_unit_length(bits, EVC_NALU_LENGTH_PREFIX_SIZE); + if (nalu_size == 0) break; + + bits += EVC_NALU_LENGTH_PREFIX_SIZE; + bytes_to_read -= EVC_NALU_LENGTH_PREFIX_SIZE; + + if(bytes_to_read < nalu_size) break; + + nalu_type = get_nalu_type(bits, bytes_to_read); + + bits += nalu_size; + bytes_to_read -= nalu_size; + + if (nalu_type == EVC_SPS_NUT) + ev->got_sps++; + else if (nalu_type == EVC_PPS_NUT) + ev->got_pps++; + else if (nalu_type == EVC_IDR_NUT ) + ev->got_idr++; + else if (nalu_type == EVC_NOIDR_NUT) + ev->got_nonidr++; + } + + return 0; +} + +static int evc_probe(const AVProbeData *p) +{ + EVCParserContext ev = {0}; + int ret = parse_nal_units(p, &ev); + + if (ret == 0 && ev.got_sps && ev.got_pps && (ev.got_idr || ev.got_nonidr > 3)) + return AVPROBE_SCORE_EXTENSION + 1; // 1 more than .mpg + + return 0; +} + +FF_DEF_RAWVIDEO_DEMUXER(evc, "raw EVC video", evc_probe, "evc", AV_CODEC_ID_EVC)