From patchwork Mon Mar 27 10:46:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawid Kozinski X-Patchwork-Id: 40860 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp1220007pzh; Mon, 27 Mar 2023 03:46:55 -0700 (PDT) X-Google-Smtp-Source: AKy350aYIK3R2w5EpSH/qV0s4UB4NiWL85Xtyc1BcuqPtLbF+pbfiTi26RocwVB0uRHy/qtXhSom X-Received: by 2002:aa7:c516:0:b0:502:2395:c3c5 with SMTP id o22-20020aa7c516000000b005022395c3c5mr9886567edq.37.1679914015414; Mon, 27 Mar 2023 03:46:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679914015; cv=none; d=google.com; s=arc-20160816; b=jWSTaXGVtI/D3Fi39ACoqzsAX9aunZGrHzCrSvo5ewyZ6fzYvuROcC/POSnY8cp8mK AykljqZRajQkT9Z04XCKKoPUNo5BhC1evfWdz4KChuDkZ7sx1OeVagrjhJ4UNm2oomyV RegMEldevLcBVmoLd6Hp4u1wkcx/0V4XUeokg7alzSTk2Nef1KItrSS8+hfEtmzjS8Ho SNDXDEa9ufTe5httPdBfGMbUwDRW4DqzuZbLkD3Yue0XltMkDsNozon/XLsY2MAFsNzw DyP1nekrkME8qMmkFErlmGoR4J6TXvfiK3vJ9jlE6JxTSv7XWkhRdcmUGYbwF59kK9qP +SSA== 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=KBFKsnKl2uaLIjhlCXZBH7r3/enf1+ISdah6x1WpoRU=; b=TlCD2H0t/+1doD11dTvjx2F6hzmAqb6NuU1gBcRg9MrY2mlt8wBTdDlr4dkl5elWQ3 g2/bMk8svsz64BsU0j0uVwA482rKR4RJYVo6aEvgDPQlFDt3iETU8YqOTTEYXTx8+4u3 KgN5qhOnarn6C3KGnuKZf2992UaU7crsHaouJDQ9AYgyflasC0I9hFtdRYIKysD9LKlZ ULJfWFu5fj5V9o4PMQfVQJ+IZBCDhiQu4rUM6/JUWJwRkamY92ql8AtIeBLbrd7yYjuk MQiZVZXPRqtXKM0HqOzSze1BJjdUxzcA1qo58HEwFX5vl2XdmbrtpjSZWxcQix8O/cpA dRIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=g5j5QBi8; 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 u12-20020a05640207cc00b0050202fbb587si12525370edy.352.2023.03.27.03.46.54; Mon, 27 Mar 2023 03:46:55 -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=@samsung.com header.s=mail20170921 header.b=g5j5QBi8; 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 3D83568C9ED; Mon, 27 Mar 2023 13:46:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A0D7368C99A for ; Mon, 27 Mar 2023 13:46:44 +0300 (EEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230327104642euoutp01ab98ccbdeed29deb79f004453c3f1f88~QQOKR69OB0851108511euoutp01d for ; Mon, 27 Mar 2023 10:46:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230327104642euoutp01ab98ccbdeed29deb79f004453c3f1f88~QQOKR69OB0851108511euoutp01d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1679914002; bh=VTwYPTRkkgawvEtZWW38nu2ClnnPBGkBUTTUDOAyxtA=; h=From:To:Cc:Subject:Date:References:From; b=g5j5QBi89hKylqK3w37SD3YfDVFzCxU64mJk+DKgnuzk4/Ziu7K6JYWAOeLY3kVuN 4RoEkErwPhwlbeqjH7eb/ggeoLfTxJ49yBBdmUWG10/7nzDDfxZNgMpC0PZlmY1rNa INdU2Bh804X4SuwIamPdlM3+nvrARDdMwCkfleAw= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230327104642eucas1p2efc8bf1d9d183f80512619597b448558~QQOKF-9jN0315503155eucas1p2l; Mon, 27 Mar 2023 10:46:42 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 18.32.10014.21471246; Mon, 27 Mar 2023 11:46:42 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230327104642eucas1p18807289552c0824846334b0061303dd3~QQOJw3F-30556505565eucas1p1w; Mon, 27 Mar 2023 10:46:42 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230327104642eusmtrp2538af038d4e9b1555726043ab06735cc~QQOJwW9Z30071800718eusmtrp2Q; Mon, 27 Mar 2023 10:46:42 +0000 (GMT) X-AuditID: cbfec7f5-b8bff7000000271e-a0-6421741252f4 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 81.8A.08862.21471246; Mon, 27 Mar 2023 11:46:42 +0100 (BST) Received: from AMDN5164.EU.corp.samsungelectronics.net (unknown [106.210.132.171]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230327104642eusmtip129d7351caa49718dce4d9a4f6b0f3316~QQOJfh1Yp1039710397eusmtip1d; Mon, 27 Mar 2023 10:46:41 +0000 (GMT) From: Dawid Kozinski To: d.frankiewic@samsung.com, ffmpeg-devel@ffmpeg.org Date: Mon, 27 Mar 2023 12:46:30 +0200 Message-Id: <20230327104630.1709-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+NgFnrJIsWRmVeSWpSXmKPExsWy7djP87pCJYopBl87lC2+XPvCbLHy228W i2+fzjA7MHv8WbSZxaNvyyrGAKYoLpuU1JzMstQifbsErozt31YyFTyRrjj54hlTA+NB0S5G Tg4JAROJR/9/MncxcnEICaxglOh6cJERwvnCKPH8+hpGkCohgc+MEpOOycJ07F7yix2iaDmj xLdrx1kgitqZJObM4gOx2QR0JV5+eMQEYosImEqcbN7LBmIzC2hLrLv7HcwWFnCW2LD0IzOI zSKgKvH40h2wel4BK4mjH94wQizTlJiwZQ5UXFDi5MwnLBBxbol1sy6xQsyUl2jeOhvsBQmB n+wSj/e3QzW7SGx//J0ZwhaWeHV8CzuELSPxf+d8oKEcQHaxxKF+BwizRuLQj3SICmuJt43H GUHCzEAnrN+lD1HhKPHuBj+EySdx460gxH4+iUnbpjNDhHklOtqEIEwVib5OMYhxUhJPl82B OsRDouXoHrYJjIqzkDw1C8kjsxC2LmBkXsUonlpanJueWmycl1quV5yYW1yal66XnJ+7iRGY Gk7/O/51B+OKVx/1DjEycTAeYpTgYFYS4d3srZgixJuSWFmVWpQfX1Sak1p8iFGag0VJnFfb 9mSykEB6YklqdmpqQWoRTJaJg1OqgSnzERsza4qPazVLnJu80bGOK8cT3M335P58d/yX1qkF t7fVhotHzD7Ty7totsoz3WffNhZbhRfG7Zb8ZXDv/44PHC2LX4lFrM6Z5/Lc+iibcY7RsfrZ x45KHNb10o8WiX/r+J5t5d7M58fun9vyQ9Tr48mOvBVHYgz+5/3q5uvzndr/c/qNJp2X/9gs Z+hsE5GcYmCglX3Pd8ZbE1u5FNel/HUJlzbtlT900l7R8P6cloq/fJ2rP940vP2x/F7hnrWM LnwGq/fXbA959+D4z8saW+fkB3YpRZ5/4t325sDGbsmdz7SdDRe19Dc3uWQpRe/qcVrUwV1R aNwUHNp7aP5Bq0VnlBZu0JEL75d8rqrEUpyRaKjFXFScCAAXSUnxfAMAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrELMWRmVeSWpSXmKPExsVy+t/xu7pCJYopBo+/C1h8ufaF2WLlt98s Ft8+nWF2YPb4s2gzi0ffllWMAUxRejZF+aUlqQoZ+cUltkrRhhZGeoaWFnpGJpZ6hsbmsVZG pkr6djYpqTmZZalF+nYJehnbv61kKngiXXHyxTOmBsaDol2MnBwSAiYSu5f8Yu9i5OIQEljK KPGt6zcrREJKYunSRYwQtrDEn2tdbBBFrUwSZ94uACtiE9CVePnhEROILSJgLnFx3S2wBmYB bYl1d7+zgdjCAs4SG5Z+ZAaxWQRUJR5fugNWzytgJXH0wxuoBZoSE7bMgYoLSpyc+YQFIs4t sW7WJVaImfISzVtnM09g5J+FpGwWktQCRqZVjCKppcW56bnFhnrFibnFpXnpesn5uZsYgYG7 7djPzTsY5736qHeIkYmD8RCjBAezkgjvZm/FFCHelMTKqtSi/Pii0pzU4kOMpkC3TmSWEk3O B8ZOXkm8oZmBqaGJmaWBqaWZsZI4r2dBR6KQQHpiSWp2ampBahFMHxMHp1QDk8ztZ/dfzLk+ Zb1l4+2HZ7/658Ym6u+x/SD+bOv6bdPiNJt3+b7RnVYmnxmxtmjO1hdP42xdjnTPV/yl4bui 8sv/Ze5X/r1aFnR3pg3vxo1nrl023eGbd/jIJb+tiQn7A7M//FQ0f7kvXUBk/1ON60416Q84 1IXeBgZ6hOg6KrxO3i9voPz1W1ncgep/2bd1bqYHz3I6F7PlUObn/N8PNO27C39bvL5XdjlQ ua2960Zf34trxoFB1gK/tx5+cW0x49aqTA27aF/1G8FcqdzW5qf0Fs4V7yl6xW5V0nWUNbKO 9Ufitgqu28uWNR1wFrOZED7vd8SUDSw6HKWPZjz47nre/ZtB2Jb4lI1cciVbPymxFGckGmox FxUnAgCgXO8o5QIAAA== X-CMS-MailID: 20230327104642eucas1p18807289552c0824846334b0061303dd3 X-Msg-Generator: CA X-RootMTR: 20230327104642eucas1p18807289552c0824846334b0061303dd3 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230327104642eucas1p18807289552c0824846334b0061303dd3 References: Subject: [FFmpeg-devel] [PATCH v17 1/9] avcodec/evc: MPEG-5 EVC codec registration 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: MskvlBfUGdMW Added prerequisites that must be met before providing support for the MPEG-5 EVC codec - Added new entry to codec IDs list - Added new entry to the codec descriptor list - Bumped libavcodec minor version - Added profiles for EVC codec --- libavcodec/avcodec.h | 3 +++ libavcodec/codec_desc.c | 8 ++++++++ libavcodec/codec_id.h | 1 + libavcodec/profiles.c | 6 ++++++ libavcodec/profiles.h | 1 + libavcodec/version.h | 2 +- 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 30f1d312f4..be2a8a1a65 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1695,6 +1695,9 @@ typedef struct AVCodecContext { #define FF_PROFILE_KLVA_SYNC 0 #define FF_PROFILE_KLVA_ASYNC 1 +#define FF_PROFILE_EVC_BASELINE 0 +#define FF_PROFILE_EVC_MAIN 1 + /** * level * - encoding: Set by user. diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index d912704891..e59a1a30ff 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -1923,6 +1923,14 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("ViewQuest VQC"), .props = AV_CODEC_PROP_LOSSY, }, + { + .id = AV_CODEC_ID_EVC, + .type = AVMEDIA_TYPE_VIDEO, + .name = "evc", + .long_name = NULL_IF_CONFIG_SMALL("MPEG-5 EVC (Essential Video Coding)"), + .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER, + .profiles = NULL_IF_CONFIG_SMALL(ff_evc_profiles), + }, /* various PCM "codecs" */ { diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h index 64df9699f4..c6c07bd18c 100644 --- a/libavcodec/codec_id.h +++ b/libavcodec/codec_id.h @@ -320,6 +320,7 @@ enum AVCodecID { AV_CODEC_ID_WBMP, AV_CODEC_ID_MEDIA100, AV_CODEC_ID_VQC, + AV_CODEC_ID_EVC, /* various PCM "codecs" */ AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs diff --git a/libavcodec/profiles.c b/libavcodec/profiles.c index 545626337c..c646a3f54d 100644 --- a/libavcodec/profiles.c +++ b/libavcodec/profiles.c @@ -194,4 +194,10 @@ const AVProfile ff_arib_caption_profiles[] = { { FF_PROFILE_UNKNOWN } }; +const AVProfile ff_evc_profiles[] = { + { FF_PROFILE_EVC_BASELINE, "Baseline" }, + { FF_PROFILE_EVC_MAIN, "Main" }, + { FF_PROFILE_UNKNOWN }, +}; + #endif /* !CONFIG_SMALL */ diff --git a/libavcodec/profiles.h b/libavcodec/profiles.h index 1d523992fc..c0eacae5c1 100644 --- a/libavcodec/profiles.h +++ b/libavcodec/profiles.h @@ -74,5 +74,6 @@ extern const AVProfile ff_sbc_profiles[]; extern const AVProfile ff_prores_profiles[]; extern const AVProfile ff_mjpeg_profiles[]; extern const AVProfile ff_arib_caption_profiles[]; +extern const AVProfile ff_evc_profiles[]; #endif /* AVCODEC_PROFILES_H */ diff --git a/libavcodec/version.h b/libavcodec/version.h index 7acb261bb3..ecb096f38b 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -30,7 +30,7 @@ #include "version_major.h" #define LIBAVCODEC_VERSION_MINOR 7 -#define LIBAVCODEC_VERSION_MICRO 100 +#define LIBAVCODEC_VERSION_MICRO 101 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ From patchwork Mon Mar 27 10:47:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawid Kozinski X-Patchwork-Id: 40861 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp1220299pzh; Mon, 27 Mar 2023 03:47:29 -0700 (PDT) X-Google-Smtp-Source: AKy350ZWDSGTak6khnav4SVQ4P78J5gJvnfOymHe5e7+f8c8ji+7E1R9hmQIJ0ucw5AvRBwWom1t X-Received: by 2002:a50:fb11:0:b0:502:62:78 with SMTP id d17-20020a50fb11000000b0050200620078mr13928438edq.28.1679914049226; Mon, 27 Mar 2023 03:47:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679914049; cv=none; d=google.com; s=arc-20160816; b=aZtDdqYzJaEBsynt1Ac06MK/4aP8QvxN8Ll2BmzbAWk9yeV1Eq4MT7nbLoj8pTkRdg iVB+Q8p8fuuaMMGM4ZTF8X2tT9jZSLUbUC7w4IHtxdVHXBbXk2a4R7vDydqu4VPtRHsu e7/lfnqq6jHB/oIsWR3cZcsEENwAd307wQeNHVGM0sW6kIMPCjo9BBP9u/TSsRnqIoix 7uDPRbdPNd02l5r7k57t6clGS6O+aU4M8jpyJdjDDq5XjfZmwFRR9c8Zxf1/9jBhXijm gNd9yU+Z6aQ3DDUKxWF4gera8GTaqu3OH8nTe4J/jK6KutDks8dUK5XbDqPSVJ7QoQA3 sjyQ== 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=gweoucjXe2YQnGtHrRfi0VzJ6FHqBZjwIrzgLA/DlJI=; b=ulCfuHpxPTjxrVo5GucJqoNqLfbjSOsRgJU4fqUtHRZAaqb9FlvlMwV3p+uXHx4Y/V D9fbvKrpo+BCHNkyg1uQuTEAIGzMGolBQQDVy+YDOSJLPfmqWwC/f+RqbFIKlG4jcpSl zP4qfTLu2BnLt6CnZ1M2k0JiRfvVUOT+a7uacF7DzIL/VxSThFecn+Y4/Yf3TkfCGcWh ueqAjxi2/yuJWrL0cEGnha2kK7e3/1uTRjiwZyM8A5KhJmcmgDKttaDyh461UEzWiPsc HZvFWtBCHHQUu9K46Uq/nBWjHW9cBoIU44uIfPbFB6tqJJDPDthLCETOcyM1ilxJvZdA nvag== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=u8dp583U; 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 w15-20020a056402070f00b004bff4ce5ec3si26819179edx.371.2023.03.27.03.47.28; Mon, 27 Mar 2023 03:47:29 -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=@samsung.com header.s=mail20170921 header.b=u8dp583U; 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 67ED968CA2D; Mon, 27 Mar 2023 13:47:26 +0300 (EEST) 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 CAE8968C921 for ; Mon, 27 Mar 2023 13:47:18 +0300 (EEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230327104717euoutp02f7fa43a9632dbce04cbe3a347d7075b5~QQOqmuEsn0465504655euoutp02P for ; Mon, 27 Mar 2023 10:47:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230327104717euoutp02f7fa43a9632dbce04cbe3a347d7075b5~QQOqmuEsn0465504655euoutp02P DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1679914037; bh=xonSU42ahjA9ObCXpiH1Z3gSz86hoF0qj5CNq9Qp3C8=; h=From:To:Cc:Subject:Date:References:From; b=u8dp583UAYKJdHgs9r1GuzGU7iBPjhl6QuIS7xGp/3CV/5IeCfON+8h61aHU0rIRG TovA+p21VLO3HtcTGp9Jo3gMqcMalmhoGSKMH3o+NIQLJ3bgiHaHkNjnOiZ6hn+enR 9rLIEJiYNaeq9qjtZolf8kdONqWllyD+cBtlPBco= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230327104717eucas1p24086f565a382b5f5843e4b8747085577~QQOqYJiRy0085600856eucas1p2L; Mon, 27 Mar 2023 10:47:17 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 87.52.10014.53471246; Mon, 27 Mar 2023 11:47:17 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230327104716eucas1p180d59a4d3b6035914b66dc7a4ba85747~QQOp7F_Zv3004030040eucas1p1S; Mon, 27 Mar 2023 10:47:16 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230327104716eusmtrp2899bd2dbc56f24299e111c50dc5bdec5~QQOp6g5rf0125701257eusmtrp2h; Mon, 27 Mar 2023 10:47:16 +0000 (GMT) X-AuditID: cbfec7f5-ba1ff7000000271e-1f-642174357fe3 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 8A.9A.08862.43471246; Mon, 27 Mar 2023 11:47:16 +0100 (BST) Received: from AMDN5164.EU.corp.samsungelectronics.net (unknown [106.210.132.171]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230327104716eusmtip12cc369d3b63e4900a2fe948a70ac2e49~QQOpc5BJ22144321443eusmtip1y; Mon, 27 Mar 2023 10:47:16 +0000 (GMT) From: Dawid Kozinski To: d.frankiewic@samsung.com, ffmpeg-devel@ffmpeg.org Date: Mon, 27 Mar 2023 12:47:05 +0200 Message-Id: <20230327104705.62-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+NgFnrFIsWRmVeSWpSXmKPExsWy7djPc7qmJYopBm+3clt8ufaF2WLlt98s Ft8+nWF2YPb4s2gzi0ffllWMAUxRXDYpqTmZZalF+nYJXBmzficVvL/KXPFyaQtLA+PiY0xd jJwcEgImEr/ad7J0MXJxCAmsYJR4f3QJI4TzhVHietskqMxnRolNd6eyw7TsPPqNDcQWEljO KPF6UixEUTuTxM9Jh8GK2AR0JV5+eAS2Q0TAVOJk816wBmYBbYl1d78D2RwcwgKREme+SYGE WQRUJV68XMAKEuYVsJBob4iGWKUpMWHLHLApvAKCEidnPmGBiHNLrJt1iRViorxE89bZzCAn SAj8ZJc4+HkrM0SRi8TT7w1QbwpLvDq+Bep+GYn/O+czgeySECiWONTvAGHWSBz6kQ5RYS3x tvE4I0iYGeiE9bv0IcKOEmsam9ghqvkkbrwVhDiAT2LStunMEGFeiY42IQhTRaKvUwyiUUri 6bI5UFd5SBxf8IJ5AqPiLCRfzULyySyEtQsYmVcxiqeWFuempxYb56WW6xUn5haX5qXrJefn bmIEJofT/45/3cG44tVHvUOMTByMhxglOJiVRHg3eyumCPGmJFZWpRblxxeV5qQWH2KU5mBR EufVtj2ZLCSQnliSmp2aWpBaBJNl4uCUamCyYr46lWfH69boedeyZ507v9d4htydb6qM6abi x2+cLP2VIx9Rv/7IrBsWfK8VtR8nmdy0PF0hFbPzzBOBZXkTb+zumB0Tfacj47V4vOCBLjPN a2eckg7/OO1iq1Pt97eq1Usset0sVSsrAfcLhqputo2CXxTnPHs66fWRBxc2b+X+XOlbaTix dM335MarOa9/ddbv3qsw10Rt101OnrkOk1gkxZ6LBTxLz910fXHs+zfSTg7/vpn+5r54wYQz 6eHM01dSxX9uCgqucQ1+zVheZNL8kHHzq16uZMv5QjmNW8SEMwVWyf/eH/782GantTm3DyQ9 VZw5IWUpW43Zfd0v9yJuvFzrc27SzB7Wb3q1SizFGYmGWsxFxYkAzkedYX0DAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrELMWRmVeSWpSXmKPExsVy+t/xu7omJYopBvMu61h8ufaF2WLlt98s Ft8+nWF2YPb4s2gzi0ffllWMAUxRejZF+aUlqQoZ+cUltkrRhhZGeoaWFnpGJpZ6hsbmsVZG pkr6djYpqTmZZalF+nYJehmzficVvL/KXPFyaQtLA+PiY0xdjJwcEgImEjuPfmPrYuTiEBJY yiix5NZmFoiElMTSpYsYIWxhiT/XuqCKWpkkHm28yAqSYBPQlXj54RHYJBEBc4mL626BNTAL aEusu/udDcQWFgiXePDoKDuIzSKgKvHi5QKgXg4OXgELifaGaIj5mhITtswBG8MrIChxcuYT qBu4JdbNusQKMVJeonnrbOYJjPyzkJTNQpJawMi0ilEktbQ4Nz232FCvODG3uDQvXS85P3cT IzBwtx37uXkH47xXH/UOMTJxMB5ilOBgVhLh3eytmCLEm5JYWZValB9fVJqTWnyI0RTo1InM UqLJ+cDYySuJNzQzMDU0MbM0MLU0M1YS5/Us6EgUEkhPLEnNTk0tSC2C6WPi4JRqYOIWfLF+ sUqlT9D+BwnzQpvvtVz/ulTxWeO1QNU7D2dOa5siM8fS3CmrNGnpl1VWh2ekR9ReNv3EmxxU LSRVmRG88dyEU8d6lILcf0oVFdnLTkl9OfVVn6v1mug0TjaJp9e7t91y4dhg+un36rS+GVyO af9NLexD68WOBoaa1zUpXdZbUjT9t6aT2vPfwu8vdGnefD4vr+a3UIx9oE/DrRk1WiHKdy/7 rfkR1u4Y9PvcV2fHnvrkJxd2Tb/4mXvyL72v6h2ZXybkbedoOpXXu/1/Z98+roiM1MfZ4e6m ++4m6i3by3OlYcukQx1f75u5/Y90D/+2d//aaTwcr1foHPi4K48n6IRFcSxDzvfCi0osxRmJ hlrMRcWJAHomVG/lAgAA X-CMS-MailID: 20230327104716eucas1p180d59a4d3b6035914b66dc7a4ba85747 X-Msg-Generator: CA X-RootMTR: 20230327104716eucas1p180d59a4d3b6035914b66dc7a4ba85747 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230327104716eucas1p180d59a4d3b6035914b66dc7a4ba85747 References: Subject: [FFmpeg-devel] [PATCH v17 2/9] avcodec/evc_parser: Added parser implementation for EVC format 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: qKUJQ5NITzs8 - Added constants definitions for EVC parser - Provided NAL units parsing following ISO_IEC_23094-1 - EVC parser registration --- libavcodec/Makefile | 1 + libavcodec/evc.h | 155 +++++ libavcodec/evc_parser.c | 1270 +++++++++++++++++++++++++++++++++++++++ libavcodec/parsers.c | 1 + 4 files changed, 1427 insertions(+) create mode 100644 libavcodec/evc.h create mode 100644 libavcodec/evc_parser.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 408ecd1e31..635b936cac 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1157,6 +1157,7 @@ OBJS-$(CONFIG_DVAUDIO_PARSER) += dvaudio_parser.o OBJS-$(CONFIG_DVBSUB_PARSER) += dvbsub_parser.o OBJS-$(CONFIG_DVD_NAV_PARSER) += dvd_nav_parser.o OBJS-$(CONFIG_DVDSUB_PARSER) += dvdsub_parser.o +OBJS-$(CONFIG_EVC_PARSER) += evc_parser.o OBJS-$(CONFIG_FLAC_PARSER) += flac_parser.o flacdata.o flac.o OBJS-$(CONFIG_FTR_PARSER) += ftr_parser.o OBJS-$(CONFIG_G723_1_PARSER) += g723_1_parser.o diff --git a/libavcodec/evc.h b/libavcodec/evc.h new file mode 100644 index 0000000000..d1fdb4fac6 --- /dev/null +++ b/libavcodec/evc.h @@ -0,0 +1,155 @@ +/* + * EVC definitions and enums + * Copyright (c) 2022 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 + */ + +#ifndef AVCODEC_EVC_H +#define AVCODEC_EVC_H + +// The length field that indicates the length in bytes of the following NAL unit is configured to be of 4 bytes +#define EVC_NALU_LENGTH_PREFIX_SIZE (4) /* byte */ +#define EVC_NALU_HEADER_SIZE (2) /* byte */ + +/** + * @see ISO_IEC_23094-1_2020, 7.4.2.2 NAL unit header semantic + * Table 4 - NAL unit type codes and NAL unit type classes + */ +enum EVCNALUnitType { + EVC_NOIDR_NUT = 0, /* Coded slice of a non-IDR picture */ + EVC_IDR_NUT = 1, /* Coded slice of an IDR picture */ + EVC_RSV_VCL_NUT02 = 2, + EVC_RSV_VCL_NUT03 = 3, + EVC_RSV_VCL_NUT04 = 4, + EVC_RSV_VCL_NUT05 = 5, + EVC_RSV_VCL_NUT06 = 6, + EVC_RSV_VCL_NUT07 = 7, + EVC_RSV_VCL_NUT08 = 8, + EVC_RSV_VCL_NUT09 = 9, + EVC_RSV_VCL_NUT10 = 10, + EVC_RSV_VCL_NUT11 = 11, + EVC_RSV_VCL_NUT12 = 12, + EVC_RSV_VCL_NUT13 = 13, + EVC_RSV_VCL_NUT14 = 14, + EVC_RSV_VCL_NUT15 = 15, + EVC_RSV_VCL_NUT16 = 16, + EVC_RSV_VCL_NUT17 = 17, + EVC_RSV_VCL_NUT18 = 18, + EVC_RSV_VCL_NUT19 = 19, + EVC_RSV_VCL_NUT20 = 20, + EVC_RSV_VCL_NUT21 = 21, + EVC_RSV_VCL_NUT22 = 22, + EVC_RSV_VCL_NUT23 = 23, + EVC_SPS_NUT = 24, /* Sequence parameter set */ + EVC_PPS_NUT = 25, /* Picture paremeter set */ + EVC_APS_NUT = 26, /* Adaptation parameter set */ + EVC_FD_NUT = 27, /* Filler data */ + EVC_SEI_NUT = 28, /* Supplemental enhancement information */ + EVC_RSV_NONVCL29 = 29, + EVC_RSV_NONVCL30 = 30, + EVC_RSV_NONVCL31 = 31, + EVC_RSV_NONVCL32 = 32, + EVC_RSV_NONVCL33 = 33, + EVC_RSV_NONVCL34 = 34, + EVC_RSV_NONVCL35 = 35, + EVC_RSV_NONVCL36 = 36, + EVC_RSV_NONVCL37 = 37, + EVC_RSV_NONVCL38 = 38, + EVC_RSV_NONVCL39 = 39, + EVC_RSV_NONVCL40 = 40, + EVC_RSV_NONVCL41 = 41, + EVC_RSV_NONVCL42 = 42, + EVC_RSV_NONVCL43 = 43, + EVC_RSV_NONVCL44 = 44, + EVC_RSV_NONVCL45 = 45, + EVC_RSV_NONVCL46 = 46, + EVC_RSV_NONVCL47 = 47, + EVC_RSV_NONVCL48 = 48, + EVC_RSV_NONVCL49 = 49, + EVC_RSV_NONVCL50 = 50, + EVC_RSV_NONVCL51 = 51, + EVC_RSV_NONVCL52 = 52, + EVC_RSV_NONVCL53 = 53, + EVC_RSV_NONVCL54 = 54, + EVC_RSV_NONVCL55 = 55, + EVC_UNSPEC_NUT56 = 56, + EVC_UNSPEC_NUT57 = 57, + EVC_UNSPEC_NUT58 = 58, + EVC_UNSPEC_NUT59 = 59, + EVC_UNSPEC_NUT60 = 60, + EVC_UNSPEC_NUT61 = 61, + EVC_UNSPEC_NUT62 = 62 +}; + +// slice type +// @see ISO_IEC_23094-1_2020 7.4.5 Slice header semantics +// +enum EVCSliceType { + EVC_SLICE_TYPE_B = 0, + EVC_SLICE_TYPE_P = 1, + EVC_SLICE_TYPE_I = 2 +}; + +enum { + // 7.4.3.2: aps_video_parameter_set_id is u(4). + EVC_MAX_APS_COUNT = 32, + + // 7.4.3.1: sps_seq_parameter_set_id is in [0, 15]. + EVC_MAX_SPS_COUNT = 16, + + // 7.4.3.2: pps_pic_parameter_set_id is in [0, 63]. + EVC_MAX_PPS_COUNT = 64, + + // 7.4.5: slice header slice_pic_parameter_set_id in [0, 63] + EVC_MAX_SH_COUNT = 64, + + // E.3.2: cpb_cnt_minus1[i] is in [0, 31]. + EVC_MAX_CPB_CNT = 32, + + // A.4.1: in table A.1 the highest level allows a MaxLumaPs of 35 651 584. + EVC_MAX_LUMA_PS = 35651584, + + EVC_MAX_NUM_REF_PICS = 21, + + EVC_MAX_NUM_RPLS = 32, + + // A.4.1: pic_width_in_luma_samples and pic_height_in_luma_samples are + // constrained to be not greater than sqrt(MaxLumaPs * 8). Hence height/ + // width are bounded above by sqrt(8 * 35651584) = 16888.2 samples. + EVC_MAX_WIDTH = 16888, + EVC_MAX_HEIGHT = 16888, + + // A.4.1: table A.1 allows at most 22 tile rows for any level. + EVC_MAX_TILE_ROWS = 22, + // A.4.1: table A.1 allows at most 20 tile columns for any level. + EVC_MAX_TILE_COLUMNS = 20, + + // A.4.1: table A.1 allows at most 600 slice segments for any level. + EVC_MAX_SLICE_SEGMENTS = 600, + + // 7.4.7.1: in the worst case (tiles_enabled_flag and + // entropy_coding_sync_enabled_flag are both set), entry points can be + // placed at the beginning of every Ctb row in every tile, giving an + // upper bound of (num_tile_columns_minus1 + 1) * PicHeightInCtbsY - 1. + // Only a stream with very high resolution and perverse parameters could + // get near that, though, so set a lower limit here with the maximum + // possible value for 4K video (at most 135 16x16 Ctb rows). + HEVC_MAX_ENTRY_POINT_OFFSETS = EVC_MAX_TILE_COLUMNS * 135, +}; + +#endif // AVCODEC_EVC_H diff --git a/libavcodec/evc_parser.c b/libavcodec/evc_parser.c new file mode 100644 index 0000000000..d27f33a637 --- /dev/null +++ b/libavcodec/evc_parser.c @@ -0,0 +1,1270 @@ +/* + * EVC format parser + * + * 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 + +#include "libavutil/common.h" +#include "parser.h" +#include "golomb.h" +#include "evc.h" + +#define EVC_MAX_QP_TABLE_SIZE 58 + +#define EXTENDED_SAR 255 +#define NUM_CPB 32 + +// rpl structure +typedef struct RefPicListStruct { + int poc; + int tid; + int ref_pic_num; + int ref_pic_active_num; + int ref_pics[EVC_MAX_NUM_REF_PICS]; + char pic_type; + +} RefPicListStruct; + +// chromaQP table structure to be signalled in SPS +typedef struct ChromaQpTable { + int chroma_qp_table_present_flag; // u(1) + int same_qp_table_for_chroma; // u(1) + int global_offset_flag; // u(1) + int num_points_in_qp_table_minus1[2]; // ue(v) + int delta_qp_in_val_minus1[2][EVC_MAX_QP_TABLE_SIZE]; // u(6) + int delta_qp_out_val[2][EVC_MAX_QP_TABLE_SIZE]; // se(v) +} ChromaQpTable; + +// Hypothetical Reference Decoder (HRD) parameters, part of VUI +typedef struct HRDParameters { + int cpb_cnt_minus1; // ue(v) + int bit_rate_scale; // u(4) + int cpb_size_scale; // u(4) + int bit_rate_value_minus1[NUM_CPB]; // ue(v) + int cpb_size_value_minus1[NUM_CPB]; // ue(v) + int cbr_flag[NUM_CPB]; // u(1) + int initial_cpb_removal_delay_length_minus1; // u(5) + int cpb_removal_delay_length_minus1; // u(5) + int dpb_output_delay_length_minus1; // u(5) + int time_offset_length; // u(5) +} HRDParameters; + +// video usability information (VUI) part of SPS +typedef struct VUIParameters { + int aspect_ratio_info_present_flag; // u(1) + int aspect_ratio_idc; // u(8) + int sar_width; // u(16) + int sar_height; // u(16) + int overscan_info_present_flag; // u(1) + int overscan_appropriate_flag; // u(1) + int video_signal_type_present_flag; // u(1) + int video_format; // u(3) + int video_full_range_flag; // u(1) + int colour_description_present_flag; // u(1) + int colour_primaries; // u(8) + int transfer_characteristics; // u(8) + int matrix_coefficients; // u(8) + int chroma_loc_info_present_flag; // u(1) + int chroma_sample_loc_type_top_field; // ue(v) + int chroma_sample_loc_type_bottom_field; // ue(v) + int neutral_chroma_indication_flag; // u(1) + int field_seq_flag; // u(1) + int timing_info_present_flag; // u(1) + int num_units_in_tick; // u(32) + int time_scale; // u(32) + int fixed_pic_rate_flag; // u(1) + int nal_hrd_parameters_present_flag; // u(1) + int vcl_hrd_parameters_present_flag; // u(1) + int low_delay_hrd_flag; // u(1) + int pic_struct_present_flag; // u(1) + int bitstream_restriction_flag; // u(1) + int motion_vectors_over_pic_boundaries_flag; // u(1) + int max_bytes_per_pic_denom; // ue(v) + int max_bits_per_mb_denom; // ue(v) + int log2_max_mv_length_horizontal; // ue(v) + int log2_max_mv_length_vertical; // ue(v) + int num_reorder_pics; // ue(v) + int max_dec_pic_buffering; // ue(v) + + HRDParameters hrd_parameters; +} VUIParameters; + +// The sturcture reflects SPS RBSP(raw byte sequence payload) layout +// @see ISO_IEC_23094-1 section 7.3.2.1 +// +// The following descriptors specify the parsing process of each element +// u(n) - unsigned integer using n bits +// ue(v) - unsigned integer 0-th order Exp_Golomb-coded syntax element with the left bit first +typedef struct EVCParserSPS { + int sps_seq_parameter_set_id; // ue(v) + int profile_idc; // u(8) + int level_idc; // u(8) + int toolset_idc_h; // u(32) + int toolset_idc_l; // u(32) + int chroma_format_idc; // ue(v) + int pic_width_in_luma_samples; // ue(v) + int pic_height_in_luma_samples; // ue(v) + int bit_depth_luma_minus8; // ue(v) + int bit_depth_chroma_minus8; // ue(v) + + int sps_btt_flag; // u(1) + int log2_ctu_size_minus5; // ue(v) + int log2_min_cb_size_minus2; // ue(v) + int log2_diff_ctu_max_14_cb_size; // ue(v) + int log2_diff_ctu_max_tt_cb_size; // ue(v) + int log2_diff_min_cb_min_tt_cb_size_minus2; // ue(v) + + int sps_suco_flag; // u(1) + int log2_diff_ctu_size_max_suco_cb_size; // ue(v) + int log2_diff_max_suco_min_suco_cb_size; // ue(v) + + int sps_admvp_flag; // u(1) + int sps_affine_flag; // u(1) + int sps_amvr_flag; // u(1) + int sps_dmvr_flag; // u(1) + int sps_mmvd_flag; // u(1) + int sps_hmvp_flag; // u(1) + + int sps_eipd_flag; // u(1) + int sps_ibc_flag; // u(1) + int log2_max_ibc_cand_size_minus2; // ue(v) + + int sps_cm_init_flag; // u(1) + int sps_adcc_flag; // u(1) + + int sps_iqt_flag; // u(1) + int sps_ats_flag; // u(1) + + int sps_addb_flag; // u(1) + int sps_alf_flag; // u(1) + int sps_htdf_flag; // u(1) + int sps_rpl_flag; // u(1) + int sps_pocs_flag; // u(1) + int sps_dquant_flag; // u(1) + int sps_dra_flag; // u(1) + + int log2_max_pic_order_cnt_lsb_minus4; // ue(v) + int log2_sub_gop_length; // ue(v) + int log2_ref_pic_gap_length; // ue(v) + + int max_num_tid0_ref_pics; // ue(v) + + int sps_max_dec_pic_buffering_minus1; // ue(v) + int long_term_ref_pic_flag; // u(1) + int rpl1_same_as_rpl0_flag; // u(1) + int num_ref_pic_list_in_sps[2]; // ue(v) + struct RefPicListStruct rpls[2][EVC_MAX_NUM_RPLS]; + + int picture_cropping_flag; // u(1) + int picture_crop_left_offset; // ue(v) + int picture_crop_right_offset; // ue(v) + int picture_crop_top_offset; // ue(v) + int picture_crop_bottom_offset; // ue(v) + + struct ChromaQpTable chroma_qp_table_struct; + + int vui_parameters_present_flag; // u(1) + + struct VUIParameters vui_parameters; + +} EVCParserSPS; + +typedef struct EVCParserPPS { + int pps_pic_parameter_set_id; // ue(v) + int pps_seq_parameter_set_id; // ue(v) + int num_ref_idx_default_active_minus1[2]; // ue(v) + int additional_lt_poc_lsb_len; // ue(v) + int rpl1_idx_present_flag; // u(1) + int single_tile_in_pic_flag; // u(1) + int num_tile_columns_minus1; // ue(v) + int num_tile_rows_minus1; // ue(v) + int uniform_tile_spacing_flag; // u(1) + int tile_column_width_minus1[EVC_MAX_TILE_ROWS]; // ue(v) + int tile_row_height_minus1[EVC_MAX_TILE_COLUMNS]; // ue(v) + int loop_filter_across_tiles_enabled_flag; // u(1) + int tile_offset_len_minus1; // ue(v) + int tile_id_len_minus1; // ue(v) + int explicit_tile_id_flag; // u(1) + int tile_id_val[EVC_MAX_TILE_ROWS][EVC_MAX_TILE_COLUMNS]; // u(v) + int pic_dra_enabled_flag; // u(1) + int pic_dra_aps_id; // u(5) + int arbitrary_slice_present_flag; // u(1) + int constrained_intra_pred_flag; // u(1) + int cu_qp_delta_enabled_flag; // u(1) + int log2_cu_qp_delta_area_minus6; // ue(v) + +} EVCParserPPS; + +// The sturcture reflects Slice Header RBSP(raw byte sequence payload) layout +// @see ISO_IEC_23094-1 section 7.3.2.6 +// +// The following descriptors specify the parsing process of each element +// u(n) - unsigned integer using n bits +// ue(v) - unsigned integer 0-th order Exp_Golomb-coded syntax element with the left bit first +// u(n) - unsigned integer using n bits. +// When n is "v" in the syntax table, the number of bits varies in a manner dependent on the value of other syntax elements. +typedef struct EVCParserSliceHeader { + int slice_pic_parameter_set_id; // ue(v) + int single_tile_in_slice_flag; // u(1) + int first_tile_id; // u(v) + int arbitrary_slice_flag; // u(1) + int last_tile_id; // u(v) + int num_remaining_tiles_in_slice_minus1; // ue(v) + int delta_tile_id_minus1[EVC_MAX_TILE_ROWS * EVC_MAX_TILE_COLUMNS]; // ue(v) + + int slice_type; // ue(v) + int no_output_of_prior_pics_flag; // u(1) + int mmvd_group_enable_flag; // u(1) + int slice_alf_enabled_flag; // u(1) + + int slice_alf_luma_aps_id; // u(5) + int slice_alf_map_flag; // u(1) + int slice_alf_chroma_idc; // u(2) + int slice_alf_chroma_aps_id; // u(5) + int slice_alf_chroma_map_flag; // u(1) + int slice_alf_chroma2_aps_id; // u(5) + int slice_alf_chroma2_map_flag; // u(1) + int slice_pic_order_cnt_lsb; // u(v) + + // @note + // Currently the structure does not reflect the entire Slice Header RBSP layout. + // It contains only the fields that are necessary to read from the NAL unit all the values + // necessary for the correct initialization of the AVCodecContext structure. + + // @note + // If necessary, add the missing fields to the structure to reflect + // the contents of the entire NAL unit of the SPS type + +} EVCParserSliceHeader; + +// picture order count of the current picture +typedef struct EVCParserPoc { + int PicOrderCntVal; // current picture order count value + int prevPicOrderCntVal; // the picture order count of the previous Tid0 picture + int DocOffset; // the decoding order count of the previous picture +} EVCParserPoc; + +typedef struct EVCParserContext { + ParseContext pc; + EVCParserSPS sps[EVC_MAX_SPS_COUNT]; + EVCParserPPS pps[EVC_MAX_PPS_COUNT]; + EVCParserSliceHeader slice_header[EVC_MAX_PPS_COUNT]; + + int to_read; // number of bytes of NAL Unit that do not fit into the current input data chunk and must be read from the new chunk(s) + int bytes_read; // number of bytes of the current Access Unit that already has been read + + int incomplete_nalu_prefix_read; // the flag is set to 1 when the current input data chunk contains an incomplete NAL unit prefix + int incomplete_nalu_read; // the flag is set to 1 when the current input data chunk contains an incomplete NAL unit (more input data is needed to read complete NAL unit) + + int nuh_temporal_id; // the value of TemporalId (shall be the same for all VCL NAL units of an Access Unit) + + int nalu_prefix_assembled; // the flag is set to when NALU prefix has been assembled from last chunk and current chunk of incoming data + int nalu_type; // the current NALU type + int nalu_size; // the current NALU size + int time_base; + + EVCParserPoc poc; + + int parsed_extradata; + +} EVCParserContext; + +static int get_nalu_type(const uint8_t *bits, int bits_size, AVCodecContext *avctx) +{ + 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) + 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, AVCodecContext *avctx) +{ + 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; i < EVC_NALU_LENGTH_PREFIX_SIZE; i++) + t = (t << 8) | p[i]; + + nalu_len = t; + if (nalu_len == 0) + return 0; + } + + return nalu_len; +} + +// nuh_temporal_id specifies a temporal identifier for the NAL unit +static int get_temporal_id(const uint8_t *bits, int bits_size, AVCodecContext *avctx) +{ + int temporal_id = 0; + short t = 0; + + if (bits_size >= EVC_NALU_HEADER_SIZE) { + unsigned char *p = (unsigned char *)bits; + // forbidden_zero_bit + if ((p[0] & 0x80) != 0) + return -1; + + for (int i = 0; i < EVC_NALU_HEADER_SIZE; i++) + t = (t << 8) | p[i]; + + temporal_id = (t >> 6) & 0x0007; + } + + return temporal_id; +} + +// @see ISO_IEC_23094-1 (7.3.7 Reference picture list structure syntax) +static int ref_pic_list_struct(GetBitContext *gb, RefPicListStruct *rpl) +{ + uint32_t delta_poc_st, strp_entry_sign_flag = 0; + rpl->ref_pic_num = get_ue_golomb(gb); + if (rpl->ref_pic_num > 0) { + delta_poc_st = get_ue_golomb(gb); + + rpl->ref_pics[0] = delta_poc_st; + if (rpl->ref_pics[0] != 0) { + strp_entry_sign_flag = get_bits(gb, 1); + + rpl->ref_pics[0] *= 1 - (strp_entry_sign_flag << 1); + } + } + + for (int i = 1; i < rpl->ref_pic_num; ++i) { + delta_poc_st = get_ue_golomb(gb); + if (delta_poc_st != 0) + strp_entry_sign_flag = get_bits(gb, 1); + rpl->ref_pics[i] = rpl->ref_pics[i - 1] + delta_poc_st * (1 - (strp_entry_sign_flag << 1)); + } + + return 0; +} + +// @see ISO_IEC_23094-1 (E.2.2 HRD parameters syntax) +static int hrd_parameters(GetBitContext *gb, HRDParameters *hrd) +{ + hrd->cpb_cnt_minus1 = get_ue_golomb(gb); + hrd->bit_rate_scale = get_bits(gb, 4); + hrd->cpb_size_scale = get_bits(gb, 4); + for (int SchedSelIdx = 0; SchedSelIdx <= hrd->cpb_cnt_minus1; SchedSelIdx++) { + hrd->bit_rate_value_minus1[SchedSelIdx] = get_ue_golomb(gb); + hrd->cpb_size_value_minus1[SchedSelIdx] = get_ue_golomb(gb); + hrd->cbr_flag[SchedSelIdx] = get_bits(gb, 1); + } + hrd->initial_cpb_removal_delay_length_minus1 = get_bits(gb, 5); + hrd->cpb_removal_delay_length_minus1 = get_bits(gb, 5); + hrd->cpb_removal_delay_length_minus1 = get_bits(gb, 5); + hrd->time_offset_length = get_bits(gb, 5); + + return 0; +} + +// @see ISO_IEC_23094-1 (E.2.1 VUI parameters syntax) +static int vui_parameters(GetBitContext *gb, VUIParameters *vui) +{ + vui->aspect_ratio_info_present_flag = get_bits(gb, 1); + if (vui->aspect_ratio_info_present_flag) { + vui->aspect_ratio_idc = get_bits(gb, 8); + if (vui->aspect_ratio_idc == EXTENDED_SAR) { + vui->sar_width = get_bits(gb, 16); + vui->sar_height = get_bits(gb, 16); + } + } + vui->overscan_info_present_flag = get_bits(gb, 1); + if (vui->overscan_info_present_flag) + vui->overscan_appropriate_flag = get_bits(gb, 1); + vui->video_signal_type_present_flag = get_bits(gb, 1); + if (vui->video_signal_type_present_flag) { + vui->video_format = get_bits(gb, 3); + vui->video_full_range_flag = get_bits(gb, 1); + vui->colour_description_present_flag = get_bits(gb, 1); + if (vui->colour_description_present_flag) { + vui->colour_primaries = get_bits(gb, 8); + vui->transfer_characteristics = get_bits(gb, 8); + vui->matrix_coefficients = get_bits(gb, 8); + } + } + vui->chroma_loc_info_present_flag = get_bits(gb, 1); + if (vui->chroma_loc_info_present_flag) { + vui->chroma_sample_loc_type_top_field = get_ue_golomb(gb); + vui->chroma_sample_loc_type_bottom_field = get_ue_golomb(gb); + } + vui->neutral_chroma_indication_flag = get_bits(gb, 1); + + vui->field_seq_flag = get_bits(gb, 1); + + vui->timing_info_present_flag = get_bits(gb, 1); + if (vui->timing_info_present_flag) { + vui->num_units_in_tick = get_bits(gb, 32); + vui->time_scale = get_bits(gb, 32); + vui->fixed_pic_rate_flag = get_bits(gb, 1); + } + vui->nal_hrd_parameters_present_flag = get_bits(gb, 1); + if (vui->nal_hrd_parameters_present_flag) + hrd_parameters(gb, &vui->hrd_parameters); + vui->vcl_hrd_parameters_present_flag = get_bits(gb, 1); + if (vui->vcl_hrd_parameters_present_flag) + hrd_parameters(gb, &vui->hrd_parameters); + if (vui->nal_hrd_parameters_present_flag || vui->vcl_hrd_parameters_present_flag) + vui->low_delay_hrd_flag = get_bits(gb, 1); + vui->pic_struct_present_flag = get_bits(gb, 1); + vui->bitstream_restriction_flag = get_bits(gb, 1); + if (vui->bitstream_restriction_flag) { + vui->motion_vectors_over_pic_boundaries_flag = get_bits(gb, 1); + vui->max_bytes_per_pic_denom = get_ue_golomb(gb); + vui->max_bits_per_mb_denom = get_ue_golomb(gb); + vui->log2_max_mv_length_horizontal = get_ue_golomb(gb); + vui->log2_max_mv_length_vertical = get_ue_golomb(gb); + vui->num_reorder_pics = get_ue_golomb(gb); + vui->max_dec_pic_buffering = get_ue_golomb(gb); + } + + return 0; +} + +// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax) +static EVCParserSPS *parse_sps(const uint8_t *bs, int bs_size, EVCParserContext *ev) +{ + GetBitContext gb; + EVCParserSPS *sps; + int sps_seq_parameter_set_id; + + if (init_get_bits8(&gb, bs, bs_size) < 0) + return NULL; + + sps_seq_parameter_set_id = get_ue_golomb(&gb); + + if (sps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT) + return NULL; + + sps = &ev->sps[sps_seq_parameter_set_id]; + sps->sps_seq_parameter_set_id = sps_seq_parameter_set_id; + + // the Baseline profile is indicated by profile_idc eqal to 0 + // the Main profile is indicated by profile_idc eqal to 1 + sps->profile_idc = get_bits(&gb, 8); + + sps->level_idc = get_bits(&gb, 8); + + skip_bits_long(&gb, 32); /* skip toolset_idc_h */ + skip_bits_long(&gb, 32); /* skip toolset_idc_l */ + + // 0 - monochrome + // 1 - 4:2:0 + // 2 - 4:2:2 + // 3 - 4:4:4 + sps->chroma_format_idc = get_ue_golomb(&gb); + + sps->pic_width_in_luma_samples = get_ue_golomb(&gb); + sps->pic_height_in_luma_samples = get_ue_golomb(&gb); + + sps->bit_depth_luma_minus8 = get_ue_golomb(&gb); + sps->bit_depth_chroma_minus8 = get_ue_golomb(&gb); + + sps->sps_btt_flag = get_bits(&gb, 1); + if (sps->sps_btt_flag) { + sps->log2_ctu_size_minus5 = get_ue_golomb(&gb); + sps->log2_min_cb_size_minus2 = get_ue_golomb(&gb); + sps->log2_diff_ctu_max_14_cb_size = get_ue_golomb(&gb); + sps->log2_diff_ctu_max_tt_cb_size = get_ue_golomb(&gb); + sps->log2_diff_min_cb_min_tt_cb_size_minus2 = get_ue_golomb(&gb); + } + + sps->sps_suco_flag = get_bits(&gb, 1); + if (sps->sps_suco_flag) { + sps->log2_diff_ctu_size_max_suco_cb_size = get_ue_golomb(&gb); + sps->log2_diff_max_suco_min_suco_cb_size = get_ue_golomb(&gb); + } + + sps->sps_admvp_flag = get_bits(&gb, 1); + if (sps->sps_admvp_flag) { + sps->sps_affine_flag = get_bits(&gb, 1); + sps->sps_amvr_flag = get_bits(&gb, 1); + sps->sps_dmvr_flag = get_bits(&gb, 1); + sps->sps_mmvd_flag = get_bits(&gb, 1); + sps->sps_hmvp_flag = get_bits(&gb, 1); + } + + sps->sps_eipd_flag = get_bits(&gb, 1); + if (sps->sps_eipd_flag) { + sps->sps_ibc_flag = get_bits(&gb, 1); + if (sps->sps_ibc_flag) + sps->log2_max_ibc_cand_size_minus2 = get_ue_golomb(&gb); + } + + sps->sps_cm_init_flag = get_bits(&gb, 1); + if (sps->sps_cm_init_flag) + sps->sps_adcc_flag = get_bits(&gb, 1); + + sps->sps_iqt_flag = get_bits(&gb, 1); + if (sps->sps_iqt_flag) + sps->sps_ats_flag = get_bits(&gb, 1); + + sps->sps_addb_flag = get_bits(&gb, 1); + sps->sps_alf_flag = get_bits(&gb, 1); + sps->sps_htdf_flag = get_bits(&gb, 1); + sps->sps_rpl_flag = get_bits(&gb, 1); + sps->sps_pocs_flag = get_bits(&gb, 1); + sps->sps_dquant_flag = get_bits(&gb, 1); + sps->sps_dra_flag = get_bits(&gb, 1); + + if (sps->sps_pocs_flag) + sps->log2_max_pic_order_cnt_lsb_minus4 = get_ue_golomb(&gb); + + if (!sps->sps_pocs_flag || !sps->sps_rpl_flag) { + sps->log2_sub_gop_length = get_ue_golomb(&gb); + if (sps->log2_sub_gop_length == 0) + sps->log2_ref_pic_gap_length = get_ue_golomb(&gb); + } + + if (!sps->sps_rpl_flag) + sps->max_num_tid0_ref_pics = get_ue_golomb(&gb); + else { + sps->sps_max_dec_pic_buffering_minus1 = get_ue_golomb(&gb); + sps->long_term_ref_pic_flag = get_bits(&gb, 1); + sps->rpl1_same_as_rpl0_flag = get_bits(&gb, 1); + sps->num_ref_pic_list_in_sps[0] = get_ue_golomb(&gb); + + for (int i = 0; i < sps->num_ref_pic_list_in_sps[0]; ++i) + ref_pic_list_struct(&gb, &sps->rpls[0][i]); + + if (!sps->rpl1_same_as_rpl0_flag) { + sps->num_ref_pic_list_in_sps[1] = get_ue_golomb(&gb); + for (int i = 0; i < sps->num_ref_pic_list_in_sps[1]; ++i) + ref_pic_list_struct(&gb, &sps->rpls[1][i]); + } + } + + sps->picture_cropping_flag = get_bits(&gb, 1); + + if (sps->picture_cropping_flag) { + sps->picture_crop_left_offset = get_ue_golomb(&gb); + sps->picture_crop_right_offset = get_ue_golomb(&gb); + sps->picture_crop_top_offset = get_ue_golomb(&gb); + sps->picture_crop_bottom_offset = get_ue_golomb(&gb); + } + + if (sps->chroma_format_idc != 0) { + sps->chroma_qp_table_struct.chroma_qp_table_present_flag = get_bits(&gb, 1); + + if (sps->chroma_qp_table_struct.chroma_qp_table_present_flag) { + sps->chroma_qp_table_struct.same_qp_table_for_chroma = get_bits(&gb, 1); + sps->chroma_qp_table_struct.global_offset_flag = get_bits(&gb, 1); + for (int i = 0; i < (sps->chroma_qp_table_struct.same_qp_table_for_chroma ? 1 : 2); i++) { + sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i] = get_ue_golomb(&gb);; + for (int j = 0; j <= sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i]; j++) { + sps->chroma_qp_table_struct.delta_qp_in_val_minus1[i][j] = get_bits(&gb, 6); + sps->chroma_qp_table_struct.delta_qp_out_val[i][j] = get_se_golomb(&gb); + } + } + } + } + + sps->vui_parameters_present_flag = get_bits(&gb, 1); + if (sps->vui_parameters_present_flag) + vui_parameters(&gb, &(sps->vui_parameters)); + + // @note + // If necessary, add the missing fields to the EVCParserSPS structure + // and then extend parser implementation + + return sps; +} + +// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax) +// +// @note +// The current implementation of parse_sps function doesn't handle VUI parameters parsing. +// If it will be needed, parse_sps function could be extended to handle VUI parameters parsing +// to initialize fields of the AVCodecContex i.e. color_primaries, color_trc,color_range +// +static EVCParserPPS *parse_pps(const uint8_t *bs, int bs_size, EVCParserContext *ev) +{ + GetBitContext gb; + EVCParserPPS *pps; + + int pps_pic_parameter_set_id; + + if (init_get_bits8(&gb, bs, bs_size) < 0) + return NULL; + + pps_pic_parameter_set_id = get_ue_golomb(&gb); + if (pps_pic_parameter_set_id > EVC_MAX_PPS_COUNT) + return NULL; + + pps = &ev->pps[pps_pic_parameter_set_id]; + + pps->pps_pic_parameter_set_id = pps_pic_parameter_set_id; + + pps->pps_seq_parameter_set_id = get_ue_golomb(&gb); + if (pps->pps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT) + return NULL; + + pps->num_ref_idx_default_active_minus1[0] = get_ue_golomb(&gb); + pps->num_ref_idx_default_active_minus1[1] = get_ue_golomb(&gb); + pps->additional_lt_poc_lsb_len = get_ue_golomb(&gb); + pps->rpl1_idx_present_flag = get_bits(&gb, 1); + pps->single_tile_in_pic_flag = get_bits(&gb, 1); + + if (!pps->single_tile_in_pic_flag) { + pps->num_tile_columns_minus1 = get_ue_golomb(&gb); + pps->num_tile_rows_minus1 = get_ue_golomb(&gb); + pps->uniform_tile_spacing_flag = get_bits(&gb, 1); + + if (!pps->uniform_tile_spacing_flag) { + for (int i = 0; i < pps->num_tile_columns_minus1; i++) + pps->tile_column_width_minus1[i] = get_ue_golomb(&gb); + + for (int i = 0; i < pps->num_tile_rows_minus1; i++) + pps->tile_row_height_minus1[i] = get_ue_golomb(&gb); + } + pps->loop_filter_across_tiles_enabled_flag = get_bits(&gb, 1); + pps->tile_offset_len_minus1 = get_ue_golomb(&gb); + } + + pps->tile_id_len_minus1 = get_ue_golomb(&gb); + pps->explicit_tile_id_flag = get_bits(&gb, 1); + + if (pps->explicit_tile_id_flag) { + for (int i = 0; i <= pps->num_tile_rows_minus1; i++) { + for (int j = 0; j <= pps->num_tile_columns_minus1; j++) + pps->tile_id_val[i][j] = get_bits(&gb, pps->tile_id_len_minus1 + 1); + } + } + + pps->pic_dra_enabled_flag = 0; + pps->pic_dra_enabled_flag = get_bits(&gb, 1); + + if (pps->pic_dra_enabled_flag) + pps->pic_dra_aps_id = get_bits(&gb, 5); + + pps->arbitrary_slice_present_flag = get_bits(&gb, 1); + pps->constrained_intra_pred_flag = get_bits(&gb, 1); + pps->cu_qp_delta_enabled_flag = get_bits(&gb, 1); + + if (pps->cu_qp_delta_enabled_flag) + pps->log2_cu_qp_delta_area_minus6 = get_ue_golomb(&gb); + + return pps; +} + +// @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax) +static EVCParserSliceHeader *parse_slice_header(const uint8_t *bs, int bs_size, EVCParserContext *ev) +{ + GetBitContext gb; + EVCParserSliceHeader *sh; + EVCParserPPS *pps; + EVCParserSPS *sps; + + int num_tiles_in_slice = 0; + int slice_pic_parameter_set_id; + + if (init_get_bits8(&gb, bs, bs_size) < 0) + return NULL; + + slice_pic_parameter_set_id = get_ue_golomb(&gb); + + if (slice_pic_parameter_set_id < 0 || slice_pic_parameter_set_id >= EVC_MAX_PPS_COUNT) + return NULL; + + sh = &ev->slice_header[slice_pic_parameter_set_id]; + pps = &ev->pps[slice_pic_parameter_set_id]; + sps = &ev->sps[slice_pic_parameter_set_id]; + + sh->slice_pic_parameter_set_id = slice_pic_parameter_set_id; + + if (!pps->single_tile_in_pic_flag) { + sh->single_tile_in_slice_flag = get_bits(&gb, 1); + sh->first_tile_id = get_bits(&gb, pps->tile_id_len_minus1 + 1); + } else + sh->single_tile_in_slice_flag = 1; + + if (!sh->single_tile_in_slice_flag) { + if (pps->arbitrary_slice_present_flag) + sh->arbitrary_slice_flag = get_bits(&gb, 1); + + if (!sh->arbitrary_slice_flag) + sh->last_tile_id = get_bits(&gb, pps->tile_id_len_minus1 + 1); + else { + sh->num_remaining_tiles_in_slice_minus1 = get_ue_golomb(&gb); + num_tiles_in_slice = sh->num_remaining_tiles_in_slice_minus1 + 2; + for (int i = 0; i < num_tiles_in_slice - 1; ++i) + sh->delta_tile_id_minus1[i] = get_ue_golomb(&gb); + } + } + + sh->slice_type = get_ue_golomb(&gb); + + if (ev->nalu_type == EVC_IDR_NUT) + sh->no_output_of_prior_pics_flag = get_bits(&gb, 1); + + if (sps->sps_mmvd_flag && ((sh->slice_type == EVC_SLICE_TYPE_B) || (sh->slice_type == EVC_SLICE_TYPE_P))) + sh->mmvd_group_enable_flag = get_bits(&gb, 1); + else + sh->mmvd_group_enable_flag = 0; + + if (sps->sps_alf_flag) { + int ChromaArrayType = sps->chroma_format_idc; + + sh->slice_alf_enabled_flag = get_bits(&gb, 1); + + if (sh->slice_alf_enabled_flag) { + sh->slice_alf_luma_aps_id = get_bits(&gb, 5); + sh->slice_alf_map_flag = get_bits(&gb, 1); + sh->slice_alf_chroma_idc = get_bits(&gb, 2); + + if ((ChromaArrayType == 1 || ChromaArrayType == 2) && sh->slice_alf_chroma_idc > 0) + sh->slice_alf_chroma_aps_id = get_bits(&gb, 5); + } + if (ChromaArrayType == 3) { + int sliceChromaAlfEnabledFlag = 0; + int sliceChroma2AlfEnabledFlag = 0; + + if (sh->slice_alf_chroma_idc == 1) { // @see ISO_IEC_23094-1 (7.4.5) + sliceChromaAlfEnabledFlag = 1; + sliceChroma2AlfEnabledFlag = 0; + } else if (sh->slice_alf_chroma_idc == 2) { + sliceChromaAlfEnabledFlag = 0; + sliceChroma2AlfEnabledFlag = 1; + } else if (sh->slice_alf_chroma_idc == 3) { + sliceChromaAlfEnabledFlag = 1; + sliceChroma2AlfEnabledFlag = 1; + } else { + sliceChromaAlfEnabledFlag = 0; + sliceChroma2AlfEnabledFlag = 0; + } + + if (!sh->slice_alf_enabled_flag) + sh->slice_alf_chroma_idc = get_bits(&gb, 2); + + if (sliceChromaAlfEnabledFlag) { + sh->slice_alf_chroma_aps_id = get_bits(&gb, 5); + sh->slice_alf_chroma_map_flag = get_bits(&gb, 1); + } + + if (sliceChroma2AlfEnabledFlag) { + sh->slice_alf_chroma2_aps_id = get_bits(&gb, 5); + sh->slice_alf_chroma2_map_flag = get_bits(&gb, 1); + } + } + } + + if (ev->nalu_type != EVC_IDR_NUT) { + if (sps->sps_pocs_flag) + sh->slice_pic_order_cnt_lsb = get_bits(&gb, sps->log2_max_pic_order_cnt_lsb_minus4 + 4); + } + + // @note + // If necessary, add the missing fields to the EVCParserSliceHeader structure + // and then extend parser implementation + + return sh; +} + +static int parse_nal_unit(AVCodecParserContext *s, const uint8_t *buf, + int buf_size, AVCodecContext *avctx) +{ + EVCParserContext *ev = s->priv_data; + int nalu_type, nalu_size; + int tid; + const uint8_t *data = buf; + int data_size = buf_size; + + s->picture_structure = AV_PICTURE_STRUCTURE_FRAME; + s->key_frame = -1; + + + nalu_size = buf_size; + if (nalu_size <= 0) { + av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit size: (%d)\n", nalu_size); + return AVERROR_INVALIDDATA; + } + + // @see ISO_IEC_23094-1_2020, 7.4.2.2 NAL unit header semantic (Table 4 - NAL unit type codes and NAL unit type classes) + // @see enum EVCNALUnitType in evc.h + nalu_type = get_nalu_type(data, data_size, avctx); + if (nalu_type < EVC_NOIDR_NUT || nalu_type > EVC_UNSPEC_NUT62) { + av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit type: (%d)\n", nalu_type); + return AVERROR_INVALIDDATA; + } + ev->nalu_type = nalu_type; + + tid = get_temporal_id(data, data_size, avctx); + if (tid < 0) { + av_log(avctx, AV_LOG_ERROR, "Invalid temporial id: (%d)\n", tid); + return AVERROR_INVALIDDATA; + } + ev->nuh_temporal_id = tid; + + if (data_size < nalu_size) { + av_log(avctx, AV_LOG_ERROR, "NAL unit does not fit in the data buffer\n"); + return AVERROR_INVALIDDATA; + } + + data += EVC_NALU_HEADER_SIZE; + data_size -= EVC_NALU_HEADER_SIZE; + + if (nalu_type == EVC_SPS_NUT) { + EVCParserSPS *sps; + int SubGopLength; + + sps = parse_sps(data, nalu_size, ev); + if (!sps) { + av_log(avctx, AV_LOG_ERROR, "SPS parsing error\n"); + return AVERROR_INVALIDDATA; + } + + s->coded_width = sps->pic_width_in_luma_samples; + s->coded_height = sps->pic_height_in_luma_samples; + s->width = sps->pic_width_in_luma_samples - sps->picture_crop_left_offset - sps->picture_crop_right_offset; + s->height = sps->pic_height_in_luma_samples - sps->picture_crop_top_offset - sps->picture_crop_bottom_offset; + + SubGopLength = (int)pow(2.0, sps->log2_sub_gop_length); + avctx->gop_size = SubGopLength; + + avctx->delay = (sps->sps_max_dec_pic_buffering_minus1) ? sps->sps_max_dec_pic_buffering_minus1 - 1 : SubGopLength + sps->max_num_tid0_ref_pics - 1; + + if (sps->profile_idc == 1) avctx->profile = FF_PROFILE_EVC_MAIN; + else avctx->profile = FF_PROFILE_EVC_BASELINE; + + ev->time_base = avctx->time_base.den; + + switch (sps->chroma_format_idc) { + case 0: /* YCBCR400_10LE */ + av_log(avctx, AV_LOG_ERROR, "YCBCR400_10LE: Not supported chroma format\n"); + s->format = AV_PIX_FMT_GRAY10LE; + return -1; + case 1: /* YCBCR420_10LE */ + s->format = AV_PIX_FMT_YUV420P10LE; + break; + case 2: /* YCBCR422_10LE */ + av_log(avctx, AV_LOG_ERROR, "YCBCR422_10LE: Not supported chroma format\n"); + s->format = AV_PIX_FMT_YUV422P10LE; + return -1; + case 3: /* YCBCR444_10LE */ + av_log(avctx, AV_LOG_ERROR, "YCBCR444_10LE: Not supported chroma format\n"); + s->format = AV_PIX_FMT_YUV444P10LE; + return -1; + default: + s->format = AV_PIX_FMT_NONE; + av_log(avctx, AV_LOG_ERROR, "Unknown supported chroma format\n"); + return -1; + } + } else if (nalu_type == EVC_PPS_NUT) { + EVCParserPPS *pps; + + pps = parse_pps(data, nalu_size, ev); + if (!pps) { + av_log(avctx, AV_LOG_ERROR, "PPS parsing error\n"); + return AVERROR_INVALIDDATA; + } + } else if (nalu_type == EVC_SEI_NUT) // Supplemental Enhancement Information + return 0; + else if (nalu_type == EVC_APS_NUT) // Adaptation parameter set + return 0; + else if (nalu_type == EVC_FD_NUT) /* Filler data */ + return 0; + else if (nalu_type == EVC_IDR_NUT || nalu_type == EVC_NOIDR_NUT) { // Coded slice of a IDR or non-IDR picture + EVCParserSliceHeader *sh; + EVCParserSPS *sps; + int slice_pic_parameter_set_id; + + sh = parse_slice_header(data, nalu_size, ev); + if (!sh) { + av_log(avctx, AV_LOG_ERROR, "Slice header parsing error\n"); + return AVERROR_INVALIDDATA; + } + + switch (sh->slice_type) { + case EVC_SLICE_TYPE_B: { + s->pict_type = AV_PICTURE_TYPE_B; + break; + } + case EVC_SLICE_TYPE_P: { + s->pict_type = AV_PICTURE_TYPE_P; + break; + } + case EVC_SLICE_TYPE_I: { + s->pict_type = AV_PICTURE_TYPE_I; + break; + } + default: { + s->pict_type = AV_PICTURE_TYPE_NONE; + } + } + + s->key_frame = (nalu_type == EVC_IDR_NUT) ? 1 : 0; + + // POC (picture order count of the current picture) derivation + // @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count + slice_pic_parameter_set_id = sh->slice_pic_parameter_set_id; + sps = &ev->sps[slice_pic_parameter_set_id]; + + if (sps->sps_pocs_flag) { + + int PicOrderCntMsb = 0; + ev->poc.prevPicOrderCntVal = ev->poc.PicOrderCntVal; + + if (nalu_type == EVC_IDR_NUT) + PicOrderCntMsb = 0; + else { + int MaxPicOrderCntLsb = 1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4); + + int prevPicOrderCntLsb = ev->poc.PicOrderCntVal & (MaxPicOrderCntLsb - 1); + int prevPicOrderCntMsb = ev->poc.PicOrderCntVal - prevPicOrderCntLsb; + + + if ((sh->slice_pic_order_cnt_lsb < prevPicOrderCntLsb) && + ((prevPicOrderCntLsb - sh->slice_pic_order_cnt_lsb) >= (MaxPicOrderCntLsb / 2))) + + PicOrderCntMsb = prevPicOrderCntMsb + MaxPicOrderCntLsb; + + else if ((sh->slice_pic_order_cnt_lsb > prevPicOrderCntLsb) && + ((sh->slice_pic_order_cnt_lsb - prevPicOrderCntLsb) > (MaxPicOrderCntLsb / 2))) + + PicOrderCntMsb = prevPicOrderCntMsb - MaxPicOrderCntLsb; + + else + PicOrderCntMsb = prevPicOrderCntMsb; + } + ev->poc.PicOrderCntVal = PicOrderCntMsb + sh->slice_pic_order_cnt_lsb; + + } else { + if (nalu_type == EVC_IDR_NUT) { + ev->poc.PicOrderCntVal = 0; + ev->poc.DocOffset = -1; + } else { + int SubGopLength = (int)pow(2.0, sps->log2_sub_gop_length); + if (tid == 0) { + ev->poc.PicOrderCntVal = ev->poc.prevPicOrderCntVal + SubGopLength; + ev->poc.DocOffset = 0; + ev->poc.prevPicOrderCntVal = ev->poc.PicOrderCntVal; + } else { + int ExpectedTemporalId; + int PocOffset; + int prevDocOffset = ev->poc.DocOffset; + + ev->poc.DocOffset = (prevDocOffset + 1) % SubGopLength; + if (ev->poc.DocOffset == 0) { + ev->poc.prevPicOrderCntVal += SubGopLength; + ExpectedTemporalId = 0; + } else + ExpectedTemporalId = 1 + (int)log2(ev->poc.DocOffset); + while (tid != ExpectedTemporalId) { + ev->poc.DocOffset = (ev->poc.DocOffset + 1) % SubGopLength; + if (ev->poc.DocOffset == 0) + ExpectedTemporalId = 0; + else + ExpectedTemporalId = 1 + (int)log2(ev->poc.DocOffset); + } + PocOffset = (int)(SubGopLength * ((2.0 * ev->poc.DocOffset + 1) / (int)pow(2.0, tid) - 2)); + ev->poc.PicOrderCntVal = ev->poc.prevPicOrderCntVal + PocOffset; + } + } + } + + s->output_picture_number = ev->poc.PicOrderCntVal; + s->key_frame = (nalu_type == EVC_IDR_NUT) ? 1 : 0; + + return 0; + } + data += (nalu_size - EVC_NALU_HEADER_SIZE); + data_size -= (nalu_size - EVC_NALU_HEADER_SIZE); + + return 0; +} + +// Reconstruct NAL Unit from incomplete data +// +// Assemble the NALU prefix storing NALU length if it has been split between 2 subsequent buffers (input chunks) incoming to the parser. +// This is the case when the buffer size is not enough for the buffer to store the whole NAL unit prefix. +// In this case, we have to get part of the prefix from the previous buffer and assemble it with the rest from the current buffer. +// Then we'll be able to read NAL unit size. +static int evc_assemble_nalu_prefix(AVCodecParserContext *s, const uint8_t *data, int data_size, + uint8_t *nalu_prefix, AVCodecContext *avctx) +{ + EVCParserContext *ctx = s->priv_data; + ParseContext *pc = &ctx->pc; + + // 1. pc->buffer contains previously read bytes of NALU prefix + // 2. buf contains the rest of NAL unit prefix bytes + + for (int i = 0; i < EVC_NALU_LENGTH_PREFIX_SIZE; i++) { + if (i < pc->index) + nalu_prefix[i] = pc->buffer[i]; + else + nalu_prefix[i] = data[i - pc->index]; + } + + return 0; +} + +// Reconstruct NALU from incomplete data +// Assemble NALU if it is split between multiple buffers +// +// This is the case when the buffer size is not enough to store the entire NAL unit. +// In this scenario, we must retrieve parts of the NALU from the previous buffers stored in pc->buffer and assemble them with the remainder from the current buffer. +static int evc_assemble_nalu(AVCodecParserContext *s, const uint8_t *data, int data_size, + uint8_t *nalu, int nalu_size, + AVCodecContext *avctx) +{ + EVCParserContext *ctx = s->priv_data; + ParseContext *pc = &ctx->pc; + + // 1. pc->buffer contains previously read bytes of the current NALU and previous NALUs that belong to the current Access Unit. + // + // - previously read bytes are data that came with the previous incoming data chunks. + // + // - pc->buffer contains bytes of the current NALU that have already been read while processing previous chunks of incoming data, + // as well as already read bytes of previous NALUs belonging to the same Access Unit. + // + // - ctx->bytes_read is the index of the the first element of the current NALU int the pc->buffer. + // - The pc->index is the index of the element located right next to the last element of the current NALU in the pc->buffer. + // - The elements of pc->buffer located before ctx->bytes_read index contain previously read NALUs of the current Access Unit. + // + // 2. buf contains the rest of the NAL unit bytestime_base + // + // - ctx->to_read number of bytes to read from buf (the index of the element right next to the last element to read) + + uint8_t *prev_data = pc->buffer + ctx->bytes_read; + int prev_data_size = pc->index - ctx->bytes_read; + + memcpy(nalu, prev_data, prev_data_size); + memcpy(nalu + prev_data_size, data, data_size); + + return 0; +} + +static int end_of_access_unit_found(AVCodecParserContext *s, AVCodecContext *avctx) +{ + EVCParserContext *ctx = s->priv_data; + + if (avctx->profile == 0) { // BASELINE profile + if (ctx->nalu_type == EVC_NOIDR_NUT || ctx->nalu_type == EVC_IDR_NUT) + return 1; + } else { // MAIN profile + EVCParserContext *ev = s->priv_data; + if (ctx->nalu_type == EVC_NOIDR_NUT) { + if (ev->poc.PicOrderCntVal != ev->poc.prevPicOrderCntVal) + return 1; + } else if (ctx->nalu_type == EVC_IDR_NUT) + return 1; + } + return 0; +} + +// Find the end of the current frame in the bitstream. +// The end of frame is the end of Access Unit. +// Function returns the position of the first byte of the next frame, or END_NOT_FOUND +static int evc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf, + int buf_size, AVCodecContext *avctx) +{ + EVCParserContext *ctx = s->priv_data; + + const uint8_t *data = buf; + int data_size = buf_size; + + while (data_size > 0) { + + if (ctx->to_read == 0) { + // Nothing must be read and appended to the data from previous chunks. + // The previous chunk of data provided the complete NALU prefix or provided the complete NALU. + + if (ctx->nalu_prefix_assembled) // NALU prefix has been assembled from previous and current chunks of incoming data + ctx->nalu_prefix_assembled = 0; + else { // Buffer size is not enough for buffer to store NAL unit 4-bytes prefix (length) + if (data_size < EVC_NALU_LENGTH_PREFIX_SIZE) { + ctx->to_read = EVC_NALU_LENGTH_PREFIX_SIZE - data_size; + ctx->incomplete_nalu_prefix_read = 1; + return END_NOT_FOUND; + } + + ctx->nalu_size = read_nal_unit_length(data, data_size, avctx); + ctx->bytes_read += EVC_NALU_LENGTH_PREFIX_SIZE; + + data += EVC_NALU_LENGTH_PREFIX_SIZE; + data_size -= EVC_NALU_LENGTH_PREFIX_SIZE; + } + + if (data_size < ctx->nalu_size) { + + ctx->to_read = ctx->nalu_size - data_size; + ctx->incomplete_nalu_read = 1; + return END_NOT_FOUND; + } + + // the entire NALU can be read + if (parse_nal_unit(s, data, ctx->nalu_size, avctx) != 0) { + av_log(avctx, AV_LOG_ERROR, "Parsing of NAL unit failed\n"); + return AVERROR_INVALIDDATA; + } + + data += ctx->nalu_size; + data_size -= ctx->nalu_size; + + ctx->bytes_read += ctx->nalu_size; + + if (end_of_access_unit_found(s, avctx)) { + + // parser should return buffer that contains complete AU + int read_bytes = ctx->bytes_read; + ctx->bytes_read = 0; + return read_bytes; + } + + // go to the next iteration + continue; + + } else { + // The previous chunk of input data did not contain the complete valid NALU prefix or did not contain the complete NALU. + // + // Missing data must be read from the current data chunk and merged with the data from the previous data chunk + // to assemble a complete NALU or complete NALU prefix. + // + // The data from the previous data chunk are stored in pc->buf + + if (ctx->to_read < data_size) { + + if (ctx->incomplete_nalu_prefix_read == 1) { + + uint8_t nalu_prefix[EVC_NALU_LENGTH_PREFIX_SIZE]; + evc_assemble_nalu_prefix(s, data, data_size, nalu_prefix, avctx); + + ctx->nalu_size = read_nal_unit_length(nalu_prefix, EVC_NALU_LENGTH_PREFIX_SIZE, avctx); + + // update variable storing amout of read bytes for teh current AU + ctx->bytes_read += ctx->to_read; + + // update data pointer and data size + data += ctx->to_read; + data_size -= ctx->to_read; + + // reset variable storing amount of bytes to read from the new data chunk + ctx->to_read = 0; + + ctx->incomplete_nalu_prefix_read = 0; + ctx->nalu_prefix_assembled = 1; + + continue; + } + if (ctx->incomplete_nalu_read == 1) { + + uint8_t *nalu = (uint8_t *)av_malloc(ctx->nalu_size); + + // assemble NAL unit using data from previous data chunks (pc->buffer) and the current one (data) + evc_assemble_nalu(s, data, ctx->to_read, nalu, ctx->nalu_size, avctx); + + if (parse_nal_unit(s, nalu, ctx->nalu_size, avctx) != 0) { + av_log(avctx, AV_LOG_ERROR, "Parsing of NAL unit failed\n"); + return AVERROR_INVALIDDATA; + } + av_free(nalu); + + // update variable storing amout of read bytes for teh current AU + ctx->bytes_read += ctx->nalu_size; + + // update data pointer and data size + data += ctx->to_read; + data_size -= ctx->to_read; + + ctx->incomplete_nalu_read = 0; + + if (end_of_access_unit_found(s, avctx)) { + + // parser should return buffer that contains complete AU + int read_bytes = ctx->to_read; + + ctx->to_read = 0; + ctx->bytes_read = 0; + + return read_bytes; + } + + // reset variable storing amount of bytes to read from the new data chunk + ctx->to_read = 0; + + continue; + } + } else { + // needed more input data to assemble complete valid NAL Unit + ctx->to_read = ctx->to_read - data_size; + return END_NOT_FOUND; + } + } + } + + return END_NOT_FOUND; +} + +static int evc_parse(AVCodecParserContext *s, AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + int next; + EVCParserContext *ev = s->priv_data; + ParseContext *pc = &ev->pc; + + if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) + next = buf_size; + else { + next = evc_find_frame_end(s, buf, buf_size, avctx); + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + } + + // poutbuf contains just one Access Unit + *poutbuf = buf; + *poutbuf_size = buf_size; + + return next; +} + +static int evc_parser_init(AVCodecParserContext *s) +{ + EVCParserContext *ev = s->priv_data; + ev->incomplete_nalu_prefix_read = 0; + + return 0; +} + +const AVCodecParser ff_evc_parser = { + .codec_ids = { AV_CODEC_ID_EVC }, + .priv_data_size = sizeof(EVCParserContext), + .parser_init = evc_parser_init, + .parser_parse = evc_parse, + .parser_close = ff_parse_close, +}; diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c index d355808018..2c077ec3ae 100644 --- a/libavcodec/parsers.c +++ b/libavcodec/parsers.c @@ -41,6 +41,7 @@ extern const AVCodecParser ff_dvaudio_parser; extern const AVCodecParser ff_dvbsub_parser; extern const AVCodecParser ff_dvdsub_parser; extern const AVCodecParser ff_dvd_nav_parser; +extern const AVCodecParser ff_evc_parser; extern const AVCodecParser ff_flac_parser; extern const AVCodecParser ff_ftr_parser; extern const AVCodecParser ff_g723_1_parser; From patchwork Mon Mar 27 10:47:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawid Kozinski X-Patchwork-Id: 40862 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp1220505pzh; Mon, 27 Mar 2023 03:47:56 -0700 (PDT) X-Google-Smtp-Source: AKy350ZGlkpGTHGUucrEeql7K4QyDZpLLd5RYhoOCqAiayC+QKS+Atqs2NVoL1KK/nKgwLOOwZC9 X-Received: by 2002:a17:906:6882:b0:930:6ead:f81 with SMTP id n2-20020a170906688200b009306ead0f81mr10416018ejr.71.1679914076014; Mon, 27 Mar 2023 03:47:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679914076; cv=none; d=google.com; s=arc-20160816; b=lnTe6+t8DQ+j1xbYjADx3ZLq24AaNzwETqrG04Voy+QOQ5nJOU3a/6J9rcd1huiBdY v1XOALJVL/rwnRxwmSuY6eclS6JL6OYZKA9NXBW228AfqSEw11z+Zm+9GdQH13JWbGbF o1GCQxKX82AbDMBKYtPKkfN3UflC5FwLHd171M9DzCwIULg8yrE3PN6iy2Utnm+kNmXA 5hu+dzMmRiXU8RA73PmpReO0Ja/9JnO4EZ+RNQLW9h+lrM3wFkM08fXyqu8X1h5iJtuL EBztUvVjoxO3Njq4zO5Tci8ETlnoUZfvqTXIHI2C2JZzJ5OvzD4dPUFwLlkiNe8/8aui IkpQ== 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=jNlSKr+VYOmAY/hgGRmeILenQECtnz2xarsJvMo6j4U=; b=XBRkJHXJmMJ9qt8kN4Qf488bpie/Y1NAWGaijbBY8NIvlGuiquFhquiopVU/pCJAyv 8Q9Ee+R8DpRzFDh3TE99xduJC8G/5skm1Dd8cSBoIyabfCLNqeZuurxHPd8+4zqkoVOB C3H6NPzVOnEtJJrFKDwjSB5BfnqwoW0xQIOZ3b42mQCloextx8q3IXJzF8B0gvYHrPQp CjUZn6PYBpL6yZazlXVUd4OgDmDmQ3bkcL51HzTw21XS+gbDx2IHNAqSkl+9DVtF3RX/ PkVcZ5QH0CFQ7R5o5jFEFXWYACXz17v2Knz8752XYc8g6cKL5snvpZe1qG7nSCHF8rrS mCTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=pfcbShdB; 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 di19-20020a170906731300b00932f1463036si30919262ejc.283.2023.03.27.03.47.55; Mon, 27 Mar 2023 03:47:55 -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=@samsung.com header.s=mail20170921 header.b=pfcbShdB; 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 9D10F68CA6B; Mon, 27 Mar 2023 13:47:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E032668CA0B for ; Mon, 27 Mar 2023 13:47:47 +0300 (EEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230327104747euoutp014472ed61cd3132d0423892db614f358e~QQPGbjbwC1013710137euoutp01g for ; Mon, 27 Mar 2023 10:47:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230327104747euoutp014472ed61cd3132d0423892db614f358e~QQPGbjbwC1013710137euoutp01g DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1679914067; bh=aVDN2ck0KSVxBzBwyHLU1iN2s6AWYnFv3yMzgWuCF0Y=; h=From:To:Cc:Subject:Date:References:From; b=pfcbShdB/a3qIg9WrAl8rIP4nCe7QmY20F+SMIEbpyCL7hKju1aTwVRuhCSoJfBU9 WSHi+RNczZAvziq7D0T1BZkZl+oMvivV3ttuFN3XrYdtcVkd2SPHq5VMaTPhmyUg79 s5jjGgCXgzoVr08hv3Z1FZYvAFA8i+fIKWwzco5E= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230327104747eucas1p2fa9b079ce7ceea0f52a743cdf9e04559~QQPGP73Y_0697906979eucas1p2e; Mon, 27 Mar 2023 10:47:47 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 47.72.10014.35471246; Mon, 27 Mar 2023 11:47:47 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230327104746eucas1p1ba5652d3167ad13429122b22d1f2191d~QQPF-rYKc1095210952eucas1p1V; Mon, 27 Mar 2023 10:47:46 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230327104746eusmtrp1841b35a0a534b3c54d869ee2a3c8dc7a~QQPF-JcoD1184611846eusmtrp1G; Mon, 27 Mar 2023 10:47:46 +0000 (GMT) X-AuditID: cbfec7f5-b8bff7000000271e-8a-64217453e146 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 7F.AA.08862.25471246; Mon, 27 Mar 2023 11:47:46 +0100 (BST) Received: from AMDN5164.EU.corp.samsungelectronics.net (unknown [106.210.132.171]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230327104746eusmtip23a562d4124ff756c4dd3df3ec69611ae~QQPFphd3T1799817998eusmtip2u; Mon, 27 Mar 2023 10:47:46 +0000 (GMT) From: Dawid Kozinski To: d.frankiewic@samsung.com, ffmpeg-devel@ffmpeg.org Date: Mon, 27 Mar 2023 12:47:30 +0200 Message-Id: <20230327104730.1215-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+NgFnrDIsWRmVeSWpSXmKPExsWy7djP87rBJYopBnPf8Fh8ufaF2WLlt98s Ft8+nWF2YPb4s2gzi0ffllWMAUxRXDYpqTmZZalF+nYJXBkbNtxhLNgmWrH421T2BsbLAl2M nBwSAiYSa/ouM3cxcnEICaxglFg65xUbhPOFUaJv9g12COczo8Suj7NYYVr2N+2GqlrOKLF7 31+oqnYmiZ7dr5lAqtgEdCVefngEZosImEqcbN7LBmIzC2hLrLv7HcwWFqiRuHF6NpjNIqAq sX3jTGYQm1fASuL+Poh6CQFNiQlb5jBBxAUlTs58wgIR55ZYN+sSK8RMeYnmrbPBnpAQ+Msu cbBxDxNEkYvE1P4GqEHCEq+Ob2GHsGUkTk/uARrEAWQXSxzqd4AwayQO/UiHqLCWeNt4nBEk zAx0wvpd+hBhR4ktHzcyQlTzSdx4KwhxAJ/EpG3TmSHCvBIdbUIQpopEX6cYRKOUxNNlc5gh bA+JwztnMk9gVJyF5KtZSD6ZhbB2ASPzKkbx1NLi3PTUYuO81HK94sTc4tK8dL3k/NxNjMAE cfrf8a87GFe8+qh3iJGJg/EQowQHs5II72ZvxRQh3pTEyqrUovz4otKc1OJDjNIcLErivNq2 J5OFBNITS1KzU1MLUotgskwcnFINTBaBOfeC3yXGPX8ZfPRKKn/1EueFfxaenr1015H352TZ Z/4QUPK8M19o8YwpTF7akoWLZD9Jn/BoeL2gKGnyTk5mq5f3LWzaXfsUQ1qyOvd9CFFtvvPo avKfZ6VifFJXWc3UJtvP9hBm2hywbWtWrIDR1qObVt8KWRC9VzimynbS93O37px986fb5+se 5+d3IpwzbJ1Pblg3q+vxqztMYXNkj9g+cdkhYeBc5XN51+pKi4S9CU/3vmj8osN7+cDcfilF 5v2hrbxVjb5fFk83218QXHRttY/08lf/5zGs5Th5W+N72TfVX4u7bl/wKT6nHSW59LXkixiZ +H0/Jl7fekdj/onwbR+iPljku4TGf41SYinOSDTUYi4qTgQAKFWUHX8DAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrILMWRmVeSWpSXmKPExsVy+t/xe7pBJYopBm9fm1h8ufaF2WLlt98s Ft8+nWF2YPb4s2gzi0ffllWMAUxRejZF+aUlqQoZ+cUltkrRhhZGeoaWFnpGJpZ6hsbmsVZG pkr6djYpqTmZZalF+nYJehkbNtxhLNgmWrH421T2BsbLAl2MnBwSAiYS+5t2s3UxcnEICSxl lPh44RY7REJKYunSRYwQtrDEn2tdUEWtTBJnb95jAUmwCehKvPzwiAnEFhEwl7i47hZYA7OA tsS6u9+BGjg4hAWqJLafFgUJswioSmzfOJMZxOYVsJK4v28vG8R8TYkJW+YwQcQFJU7OfMIC EeeWWDfrEivESHmJ5q2zmScw8s9CUjYLSWoBI9MqRpHU0uLc9NxiQ73ixNzi0rx0veT83E2M wLDdduzn5h2M81591DvEyMTBeIhRgoNZSYR3s7diihBvSmJlVWpRfnxRaU5q8SFGU6BbJzJL iSbnAyMnryTe0MzA1NDEzNLA1NLMWEmc17OgI1FIID2xJDU7NbUgtQimj4mDU6qBycotKPPO 3Ij/LNJZckskt4f+PPz3qPwdxi2avWsnLHuq+Hj9swcSN/mW3n59f+ukC2KPN20P+e7x+pOW tk/XhcetCReeVzHzWacnprzYcPd5e+GRTboX7nFtyWAQWWMfu2jbpcndKy/ZNV3yDW35bHVH Ylv+t9Zjm8447Lzmc0c4YeWp5ksLnDL1tE2jb/9Wcd7E27TqzM53i8IeTNxaZ8EmufHM6siN GTfv/jdaGvOwaJPvA/8nX2fNONBky95vsmldzvo53oalhy+drNY4+sZMICjYVGmWzgkGxTrm 2FJXKc2c5a9Ffv4Wnn/vlrDqmTTxYutvOl8S17j9yJy47LOHHM/rVgM/haI1h/wXpigpsRRn JBpqMRcVJwIANRxii+QCAAA= X-CMS-MailID: 20230327104746eucas1p1ba5652d3167ad13429122b22d1f2191d X-Msg-Generator: CA X-RootMTR: 20230327104746eucas1p1ba5652d3167ad13429122b22d1f2191d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230327104746eucas1p1ba5652d3167ad13429122b22d1f2191d References: Subject: [FFmpeg-devel] [PATCH v17 3/9] avformat/evc_muxer: Added muxer to handle writing EVC encoded data into file or output bytestream 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: YAjdPGK9Rp0n - Provided AVOutputFormat structure describing EVC output format (ff_evc_muxer) - Added documentation for EVC muxer --- doc/muxers.texi | 6 ++++++ libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/rawenc.c | 13 +++++++++++++ 4 files changed, 21 insertions(+) diff --git a/doc/muxers.texi b/doc/muxers.texi index 79dd864182..eee3e7c526 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -2120,6 +2120,12 @@ DTS Coherent Acoustics (DCA) audio. Dolby Digital Plus, also known as Enhanced AC-3, audio. +@subsection evc + +MPEG-5 Essential Video Coding (EVC) / EVC / MPEG-5 Part 1 EVC video. + +Extensions: evc + @subsection g722 ITU-T G.722 audio. diff --git a/libavformat/Makefile b/libavformat/Makefile index 048649689b..fafed6d129 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_MUXER) += rawenc.o OBJS-$(CONFIG_HLS_DEMUXER) += hls.o hls_sample_encryption.o OBJS-$(CONFIG_HLS_MUXER) += hlsenc.o hlsplaylist.o avc.o OBJS-$(CONFIG_HNM_DEMUXER) += hnm.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index cb5b69e9cd..203188cb27 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -154,6 +154,7 @@ extern const AVInputFormat ff_ea_cdata_demuxer; extern const AVInputFormat ff_eac3_demuxer; extern const FFOutputFormat ff_eac3_muxer; extern const AVInputFormat ff_epaf_demuxer; +extern const FFOutputFormat ff_evc_muxer; extern const FFOutputFormat ff_f4v_muxer; extern const AVInputFormat ff_ffmetadata_demuxer; extern const FFOutputFormat ff_ffmetadata_muxer; diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c index 78fadda967..70d6322c53 100644 --- a/libavformat/rawenc.c +++ b/libavformat/rawenc.c @@ -401,6 +401,19 @@ const FFOutputFormat ff_hevc_muxer = { }; #endif +#if CONFIG_EVC_MUXER +const FFOutputFormat ff_evc_muxer = { + .p.name = "evc", + .p.long_name = NULL_IF_CONFIG_SMALL("raw EVC video"), + .p.extensions = "evc", + .p.audio_codec = AV_CODEC_ID_NONE, + .p.video_codec = AV_CODEC_ID_EVC, + .init = force_one_stream, + .write_packet = ff_raw_write_packet, + .p.flags = AVFMT_NOTIMESTAMPS, +}; +#endif + #if CONFIG_M4V_MUXER const FFOutputFormat ff_m4v_muxer = { .p.name = "m4v", From patchwork Mon Mar 27 10:47:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawid Kozinski X-Patchwork-Id: 40863 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp1220698pzh; Mon, 27 Mar 2023 03:48:19 -0700 (PDT) X-Google-Smtp-Source: AKy350bcbIcP0/0U6vaaAok1OH1xJ3K1HjSGFYB8zIzJDeLGERVETavVpAYBY6WVbpuPonBkFaVy X-Received: by 2002:a05:6402:c4:b0:502:4875:721 with SMTP id i4-20020a05640200c400b0050248750721mr1068629edu.15.1679914099168; Mon, 27 Mar 2023 03:48:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679914099; cv=none; d=google.com; s=arc-20160816; b=Q9TC46xKgTE0MtjITj3+HiCM3drPzrGPynrfyC3wrEiBQTtjOKbmiQs7gyt/7haXhO a9OzwX6BqtSrkB07lOs75+ez3pa2tdfiK99kiITG6dAS7Xcklai+kVLIaSpX6IkdMlbv fB5JvYnxzt2L++YMl9fTqdPiKZj1RpCLuaok9Ntf14ZidiiqkaWWlm0X9VSOIlTMmdZ+ CckkTLYY/nqlbZ3lG24KKcnMW9kYh8tlukJtBpUHsIEvxugM+503NZt/PutlEZRsS+pa G2JiIVC5CYuIJPne1sQcZpEE4xDBixz9nBogq3BizUY88w22zbfw7QqGltTToO78r82J dmgA== 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=qtnvfHe+RoBEj3uigv9SRrP6dTNktv+x7ajtsbwo4Jk=; b=AXnXdEvqdkp0K11zEN81kSSWNhJmvr4pQqP1IqNArH8L1i3HAAmlNtkhWxH8BI92VW ywU60Z+kWXMocgWstjqc6Jd4yYXOuvGgZs1EHvzxK1ipoLSJr9x3QccECN/Bqw6+MOdc WFIaYajTB3iI2ifhv2LwmnWzlSh4qzyIBfYXE4ThMh5UkMTIGhDoHTcoJVErvWSOQX8w 4jSLdL1Q+cZkH2kCBhmukZSpiszUZeTAtyYFffBLTnQqUx2UcC2r7dF4HzwohSOiXbe6 Qgy3voiGMXt4zc3npY3iSBrPLOnTuOsrEjtGZMSf+IHMeMyCYaRhOOlNsaBCvvv7ShVG zf1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=kaHI55ZZ; 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 tg4-20020a1709078dc400b0093e6f0395c1si7090054ejc.687.2023.03.27.03.48.18; Mon, 27 Mar 2023 03:48:19 -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=@samsung.com header.s=mail20170921 header.b=kaHI55ZZ; 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 AB22768CAA2; Mon, 27 Mar 2023 13:48:16 +0300 (EEST) 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 0208168C9B0 for ; Mon, 27 Mar 2023 13:48:10 +0300 (EEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230327104810euoutp0213bba1659fb73199da97a118158c3a59~QQPb1q97y1105311053euoutp02P for ; Mon, 27 Mar 2023 10:48:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230327104810euoutp0213bba1659fb73199da97a118158c3a59~QQPb1q97y1105311053euoutp02P DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1679914090; bh=cRZiWB8DVu9BxmCHAZJvCcYP24RzllcU/8TR+QU89I0=; h=From:To:Cc:Subject:Date:References:From; b=kaHI55ZZ22Vbm+T1QgY4+y/bxzFzYpPoBkQ8YfDua0xBmjvQuPoWCNgpdRG4xHgwX 6EzzmAgpKeztLH2BTX28xjRcVuSvonEB9MQ8ty+6tCQpDzdTCD55D0EjG4Q81YB57t ctPtIN74u1NloiZem2DvNd0q6KaWXNzzGjKuwVQk= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230327104810eucas1p2b0bd94f7c18d6924b34edea676a9b4ea~QQPbj5Tut0699606996eucas1p2f; Mon, 27 Mar 2023 10:48:10 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 49.82.10014.A6471246; Mon, 27 Mar 2023 11:48:10 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230327104809eucas1p238296974019037dcfb16061ec38eabd8~QQPbXDBRt0697806978eucas1p2d; Mon, 27 Mar 2023 10:48:09 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230327104809eusmtrp116a46935506c9f68f3c69d09c1839417~QQPbWY4q71184611846eusmtrp14; Mon, 27 Mar 2023 10:48:09 +0000 (GMT) X-AuditID: cbfec7f5-b8bff7000000271e-d8-6421746a2197 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id B2.A4.09583.96471246; Mon, 27 Mar 2023 11:48:09 +0100 (BST) Received: from AMDN5164.EU.corp.samsungelectronics.net (unknown [106.210.132.171]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230327104809eusmtip2f408ec668cef56d19cdb5be3f2a1d024~QQPbDJlKE2414724147eusmtip2T; Mon, 27 Mar 2023 10:48:09 +0000 (GMT) From: Dawid Kozinski To: d.frankiewic@samsung.com, ffmpeg-devel@ffmpeg.org Date: Mon, 27 Mar 2023 12:47:58 +0200 Message-Id: <20230327104758.1538-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+NgFnrDIsWRmVeSWpSXmKPExsWy7djP87pZJYopBjunsFl8ufaF2WLlt98s Ft8+nWF2YPb4s2gzi0ffllWMAUxRXDYpqTmZZalF+nYJXBl7v5xnLLipWXHgQg97A+MJ+S5G Tg4JAROJ/4/Ps3cxcnEICaxglPhw/h8LhPOFUWLKo4dMEM5nRomvH08wwbTMOX6VFSKxnFFi 2bknjBBOO5PEj76zjCBVbAK6Ei8/PALrEBEwlTjZvJcNxGYW0JZYd/c7mC0skCCx7NZudhCb RUBVYt+bKywgNq+AlcT81gPMENs0JSZsmcMEEReUODnzCQtEnFti3axLrBAz5SWat85mBjlC QuAru8SHDYugTnWRaO1eywhhC0u8Or6FHcKWkTg9uQdoEAeQXSxxqN8BwqyROPQjHaLCWuJt 43FGkDAz0Anrd+lDhB0lrv1cCtXIJ3HjrSDEAXwSk7ZNZ4YI80p0tAlBmCoSfZ1iEI1SEk+X zYF6yUPi5PXXjBMYFWch+WoWkk9mIaxdwMi8ilE8tbQ4Nz212DgvtVyvODG3uDQvXS85P3cT IzBBnP53/OsOxhWvPuodYmTiYDzEKMHBrCTCu9lbMUWINyWxsiq1KD++qDQntfgQozQHi5I4 r7btyWQhgfTEktTs1NSC1CKYLBMHp1QDU8rGkOlhxuGRE3yWfNkSFyH5K7ZHe6LnRLaU3gcN jQ71Uw60TnQSufy4fs2TyGfNKb4Rxn3SswQXr6ywbZt+ukCAx+Xpp9dJMw77P7h4zO9OXOvx ax8/rK59+uEzd9XsI9JMbj9sijsvb7KKjNKyO+Lz9/9UvtKs/NX1gjythikLmhI/bLpV5Cvh +aFcJ+Gaw5kzW1VOtd9UWNY7tfyvhMt65a1nj05/2z/D8aD5oY/Xj72eG/bdgnHDlyMf/V+m 31c5k+3TyMcVbMXvdveQ517HtgmFi7uP2F7+yVp683dzj+9ln0tRR1bMu6hwvNZTO/aoTUtE xXoJ7kOca6skVQyyV0T3XntgwKfSXFQmpsRSnJFoqMVcVJwIAFd17DB/AwAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrELMWRmVeSWpSXmKPExsVy+t/xe7qZJYopBq+eGVt8ufaF2WLlt98s Ft8+nWF2YPb4s2gzi0ffllWMAUxRejZF+aUlqQoZ+cUltkrRhhZGeoaWFnpGJpZ6hsbmsVZG pkr6djYpqTmZZalF+nYJehl7v5xnLLipWXHgQg97A+MJ+S5GTg4JAROJOcevsnYxcnEICSxl lDg4fTYjREJKYunSRVC2sMSfa11sEEWtTBITl7QwgSTYBHQlXn54BGaLCJhLXFx3C6yBWUBb Yt3d72wgtrBAnMSHmYtZQGwWAVWJfW+ugNm8AlYS81sPMEMs0JSYsGUOE0RcUOLkzCcsEHFu iXWzLrFCzJSXaN46m3kCI/8sJGWzkKQWMDKtYhRJLS3OTc8tNtIrTswtLs1L10vOz93ECAzc bcd+btnBuPLVR71DjEwcjIcYJTiYlUR4N3srpgjxpiRWVqUW5ccXleakFh9iNAW6dSKzlGhy PjB28kriDc0MTA1NzCwNTC3NjJXEeT0LOhKFBNITS1KzU1MLUotg+pg4OKUamHxU1zWLcO9J 1Jlo0hk2wXiO0S821z6bzvz9ZdEpOTkJp6fJCQv4+2UoTe/8/OSosd4V9nnHt12vnny+5K2u 0uU3Lt/Sc1Z4a/k0JjeuLfn5xW0j8/bQWXHVz6QOMkz52/jOgpH/ga9YR78qd3/vwkUCgdPV Sn3cfJfpS53tjjrAp3lh+r9jp8I3qAUdnfdg2raAo+amDy5LR6TLX856a7ZsV+m3rYZrvTYk 8nxsOTM/jb9cuqxjz8TDV5+f99Lb+Pv6UgV/FyabSY+Ou52ecjWl8LB66wfuihvP+EsWhbY+ 8dkYfidye2FJzxOnR0U/u/SeagWx88vFPdvedlRU7/ZVq4RbYQnTVu+NOhZepsRSnJFoqMVc VJwIANOXRaXlAgAA X-CMS-MailID: 20230327104809eucas1p238296974019037dcfb16061ec38eabd8 X-Msg-Generator: CA X-RootMTR: 20230327104809eucas1p238296974019037dcfb16061ec38eabd8 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230327104809eucas1p238296974019037dcfb16061ec38eabd8 References: Subject: [FFmpeg-devel] [PATCH v17 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: lt0N3e9xMd2t - Provided AVInputFormat structure describing EVC input format (ff_evc_demuxer) --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/evcdec.c | 121 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 libavformat/evcdec.c diff --git a/libavformat/Makefile b/libavformat/Makefile index fafed6d129..d80e5dc6b3 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 203188cb27..9d7d6a37a1 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -154,6 +154,7 @@ extern const AVInputFormat ff_ea_cdata_demuxer; extern const AVInputFormat ff_eac3_demuxer; extern const FFOutputFormat ff_eac3_muxer; extern const AVInputFormat ff_epaf_demuxer; +extern const AVInputFormat ff_evc_demuxer; extern const FFOutputFormat ff_evc_muxer; extern const FFOutputFormat 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..f73eeb4417 --- /dev/null +++ b/libavformat/evcdec.c @@ -0,0 +1,121 @@ +/* + * 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; i < EVC_NALU_LENGTH_PREFIX_SIZE; i++) + t = (t << 8) | p[i]; + + nalu_len = t; + if (nalu_len == 0) // Invalid bitstream size + return 0; + } + + return nalu_len; +} + +static int parse_nal_units(const AVProbeData *p, EVCParserContext *ev) +{ + int nalu_type; + size_t nalu_size; + unsigned char *bits = (unsigned char *)p->buf; + 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) From patchwork Mon Mar 27 10:48:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawid Kozinski X-Patchwork-Id: 40864 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp1220893pzh; Mon, 27 Mar 2023 03:48:43 -0700 (PDT) X-Google-Smtp-Source: AKy350aKamT1vGKk94Z76Cn/+k6cFp5bUNpZ2lSIjTJt+cuRf/czrXNYiWvihJ2MfxLCCsKGUIjG X-Received: by 2002:aa7:c557:0:b0:4fa:39a6:af25 with SMTP id s23-20020aa7c557000000b004fa39a6af25mr13379984edr.16.1679914123382; Mon, 27 Mar 2023 03:48:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679914123; cv=none; d=google.com; s=arc-20160816; b=zQlRhEZZrAN9qGzcGtcWIaXw0H0GzZAEFCd1XtastWKzdiMqFUfPpaf0vxCF+Utsmv W6r4PdkpvSKFwoE6r2szAUgHtPiGmFCMkyFDyMDBjBiPwIRyxJ2eJDAlLwQfyAKO5/sb 5vbeRhnUrOi1eRjevgB0nWzIJHlz9fcig5b7Xgp3HBMlEj3pViC+TDVoR7/odD8yHVdZ jKoWAZoHgzxHfRPgM/11Xrq7VDJc6ppIRB/hoRO76zm1G5nGIW7u1crtbuvZsX+Hi4f6 Z9ixYMC6XnT1gpTC31pE45vj5UCc4QicawyLsyTifvSb/EKPXSdkHmj8sK//xcFEjj8t jn9A== 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=KyvG+m7Hz/h5PLV6Ccob6t2smBKso0/bRSzGmpo6cpA=; b=VjYomz6A3uKvMRSxK+AxRRLR2BEos07t0wTCJA45NHiPyqemf0XdOAXqYsXdJDlNIA fXcn///kKgVe8fTnnVKe1PqRjnuRHeffQx8MKT0wlPt32iwjEwlhubsS3JzA7bKu+F9w KhAN2uwJmjqB8a2Zyp6w2dBQWEgFaJYkNWD1t1xLh+XB+qqdKP8YiUxaHxK3stBCiU91 DTeg//EE5m6Y7jgpAfiIGGSBFamrjrqhfyyHsvSYjGmKS63Se5cX0vvoy3bg2t/RZXnl XmVt5jNQ6VafnjaBbDKE8BahkFFfzuNdU4UqoKQoesjsuIQE20K7qMNdZLtNy/iaIHgy PBdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=I8AhgxUp; 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 d4-20020a50fb04000000b004fef30e1027si25732675edq.621.2023.03.27.03.48.43; Mon, 27 Mar 2023 03:48:43 -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=@samsung.com header.s=mail20170921 header.b=I8AhgxUp; 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 E0EAB68CAAE; Mon, 27 Mar 2023 13:48:40 +0300 (EEST) 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 4917368C483 for ; Mon, 27 Mar 2023 13:48:34 +0300 (EEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230327104833euoutp02c61dbc755b5b91190f43bafa8ca3fa93~QQPxqRQsB1105311053euoutp02g for ; Mon, 27 Mar 2023 10:48:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230327104833euoutp02c61dbc755b5b91190f43bafa8ca3fa93~QQPxqRQsB1105311053euoutp02g DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1679914113; bh=qaeRplXlWi5xZrM/gnM+d11uNv+igA+uNgpcSQPMhHs=; h=From:To:Cc:Subject:Date:References:From; b=I8AhgxUpFpICtx+eOtbNf5er7XBsocryJnqHAqmHgyLDpYLgA/BQ7DihoXbD0U0O1 Q/Z+LnEYOT1bScOUhYf0doQx7oNONOI41sXVU33hmLWLjx5Q0H2v2HQIJFKCngDAZb b+77OwAcHpS901YAX0bpaPw2t4t4+0Pwx9+UiPMw= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230327104833eucas1p14d32d79767d73642f1817d606ddfec71~QQPxYk6Rb1824818248eucas1p11; Mon, 27 Mar 2023 10:48:33 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id BE.6D.09966.18471246; Mon, 27 Mar 2023 11:48:33 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230327104833eucas1p2defc66560ce0fdd5ffe9261ff35fcd81~QQPxBI2vh2861128611eucas1p2B; Mon, 27 Mar 2023 10:48:33 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230327104833eusmtrp1b3ce9ced38c5a7d272e97d98b1c3253a~QQPw-8CTH1227712277eusmtrp1X; Mon, 27 Mar 2023 10:48:33 +0000 (GMT) X-AuditID: cbfec7f4-d4fff700000026ee-32-642174811feb Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 72.DA.08862.08471246; Mon, 27 Mar 2023 11:48:33 +0100 (BST) Received: from AMDN5164.EU.corp.samsungelectronics.net (unknown [106.210.132.171]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230327104832eusmtip25af944def1e3d085a648d0ea32cb73d5~QQPwlfYtk1211012110eusmtip2B; Mon, 27 Mar 2023 10:48:32 +0000 (GMT) From: Dawid Kozinski To: d.frankiewic@samsung.com, ffmpeg-devel@ffmpeg.org Date: Mon, 27 Mar 2023 12:48:22 +0200 Message-Id: <20230327104822.1191-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+NgFnrNIsWRmVeSWpSXmKPExsWy7djPc7qNJYopButnylh8ufaF2WLlt98s Ft8+nWF2YPb4s2gzi0ffllWMAUxRXDYpqTmZZalF+nYJXBmLj51jLpj9m7Fi+tdLTA2Mu/Yy djFyckgImEjsbjsJZHNxCAmsYJT42djIBuF8YZSYtrabFaRKSOAzo8SFVnOYjp4r86E6ljNK 3JjxCsppZ5LYsXQpG0gVm4CuxMsPj5hAbBEBU4mTzXvB4swC2hLr7n4Hs4UFAiT2NR8Hu4NF QFXiY8d3FhCbV8BKou/ufiaIbZoSE7bMYYKIC0qcnPmEBSLOLbFu1iVWiJnyEs1bZzNDxH+y S2w6Hwdhu0g8O/Ibao6wxKvjW9ghbBmJ05N7gOZwANnFEof6HSDMGolDP9IhKqwl3jaCXMYB NF1TYv0ufYiwo8Sm/7/ZIar5JG68FYTYzycxadt0Zogwr0RHmxCEqSLR1ykG0Sgl8XTZHKgK D4kzL0MmMCrOQvLTLCR/zELYuoCReRWjeGppcW56arFRXmq5XnFibnFpXrpecn7uJkZgejj9 7/iXHYzLX33UO8TIxMF4iFGCg1lJhHezt2KKEG9KYmVValF+fFFpTmrxIUZpDhYlcV5t25PJ QgLpiSWp2ampBalFMFkmDk6pBiaNP9um1Kzx7+J/LRrTs6hgccXb/nWqX7y6kjX5Gpv0Tt/z zk68Yhj59oU168H/3JNV2qQ0baoVltspdqXskJsczLQvUTnxtzGzPpthdMhXYSHX+2lrg6sK JtpZnA/mOHrT/6D9r/9P5R4q+V7l3TGDa7nT0uOn/+85+HPGH+nVHfUPHu3+VLr8X0D52f9X EyMSY96+UJO9/+VLqkGjMrelRMm719q719zlK9sZb12b/XTihEV7Hn40acvULwvSXLpexuu4 5o7Dtz1KhBSePC1UWnLi4lVB1zNmz8NdfAvuMgRcqRXLMP2k9+lLrW6F1i1H6T+nNJxVQ/4/ /Hoz5g1z15Sw6M6qeYcF5W9Pt1diKc5INNRiLipOBAAAgI5dfgMAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrMLMWRmVeSWpSXmKPExsVy+t/xe7qNJYopBkdmMVl8ufaF2WLlt98s Ft8+nWF2YPb4s2gzi0ffllWMAUxRejZF+aUlqQoZ+cUltkrRhhZGeoaWFnpGJpZ6hsbmsVZG pkr6djYpqTmZZalF+nYJehmLj51jLpj9m7Fi+tdLTA2Mu/YydjFyckgImEj0XJkPZHNxCAks ZZRYPrGLHSIhJbF06SKoImGJP9e62EBsIYFWJolzS1hBbDYBXYmXHx4xgdgiAuYSF9fdAqtn FtCWWHf3O1i9sICfxNMDL1hAbBYBVYmPHd/BbF4BK4m+u/uZIOZrSkzYMocJIi4ocXLmExaI OLfEulmXWCFmyks0b53NPIGRfxaSsllIUgsYmVYxiqSWFuem5xYb6hUn5haX5qXrJefnbmIE hu62Yz8372Cc9+qj3iFGJg7GQ4wSHMxKIrybvRVThHhTEiurUovy44tKc1KLDzGaAt06kVlK NDkfGD15JfGGZgamhiZmlgamlmbGSuK8ngUdiUIC6YklqdmpqQWpRTB9TBycUg1M63fYzbJ6 GPdittXO3XL7Mzx5pKP/eFbNCDznyNc+t/RsrOCVcIf/buw3F/g41s85daL95CztaZ+lkycy +03NnW9aO+XqqwOLl4Ts+uM6vSN6kw7ju8NHWoPaDNl3Fp6/vPvCNjcdrbjK20pPw4SmnVp7 3aVrh5/Yu/TwH5df9Lidvt///8KEnDR+8TvN8d72VlK3RfpfVi1992yT/rGHe+LNZO7dOZ3V qOPMzpUx1cWY96rGwcdBtfekt0ftfS1o892rzFkiI0/J4+9cYysBBaPWrXHWx18UnXzi4eNy WmhOsoybmMKzbXwLTtV8XyrIaXq+apqBpM/+qVXHWrpmncgv3LjPi+v11l+/vHe+U2Ipzkg0 1GIuKk4EALoeJUjmAgAA X-CMS-MailID: 20230327104833eucas1p2defc66560ce0fdd5ffe9261ff35fcd81 X-Msg-Generator: CA X-RootMTR: 20230327104833eucas1p2defc66560ce0fdd5ffe9261ff35fcd81 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230327104833eucas1p2defc66560ce0fdd5ffe9261ff35fcd81 References: Subject: [FFmpeg-devel] [PATCH v17 5/9] avcodec/evc_encoder: Provided support for EVC encoder 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: hfa6NLYIW2/C - Added EVC encoder wrapper - Changes in project configuration file and libavcodec Makefile - Added documentation for xeve wrapper --- configure | 4 + doc/encoders.texi | 69 +++++ doc/general_contents.texi | 11 + libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/libxeve.c | 616 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 702 insertions(+) create mode 100644 libavcodec/libxeve.c diff --git a/configure b/configure index cec001fb16..176e42d131 100755 --- a/configure +++ b/configure @@ -291,6 +291,7 @@ External library support: --enable-libwebp enable WebP encoding via libwebp [no] --enable-libx264 enable H.264 encoding via x264 [no] --enable-libx265 enable HEVC encoding via x265 [no] + --enable-libxeve enable EVC encoding via libxeve [no] --enable-libxavs enable AVS encoding via xavs [no] --enable-libxavs2 enable AVS2 encoding via xavs2 [no] --enable-libxcb enable X11 grabbing using XCB [autodetect] @@ -1862,6 +1863,7 @@ EXTERNAL_LIBRARY_LIST=" libvorbis libvpx libwebp + libxeve libxml2 libzimg libzmq @@ -3397,6 +3399,7 @@ libx265_encoder_deps="libx265" libx265_encoder_select="atsc_a53" libxavs_encoder_deps="libxavs" libxavs2_encoder_deps="libxavs2" +libxeve_encoder_deps="libxeve" libxvid_encoder_deps="libxvid" libzvbi_teletext_decoder_deps="libzvbi" vapoursynth_demuxer_deps="vapoursynth" @@ -6735,6 +6738,7 @@ enabled libx265 && require_pkg_config libx265 x265 x265.h x265_api_get require_cpp_condition libx265 x265.h "X265_BUILD >= 89" enabled libxavs && require libxavs "stdint.h xavs.h" xavs_encoder_encode "-lxavs $pthreads_extralibs $libm_extralibs" enabled libxavs2 && require_pkg_config libxavs2 "xavs2 >= 1.3.0" "stdint.h xavs2.h" xavs2_api_get +enabled libxeve && require_pkg_config libxeve "xeve >= 0.4.3" "xeve.h" xeve_encode enabled libxvid && require libxvid xvid.h xvid_global -lxvidcore enabled libzimg && require_pkg_config libzimg "zimg >= 2.7.0" zimg.h zimg_get_api_version enabled libzmq && require_pkg_config libzmq "libzmq >= 4.2.1" zmq.h zmq_ctx_new diff --git a/doc/encoders.texi b/doc/encoders.texi index af3bd43cbe..45ae61b3fb 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -2878,6 +2878,75 @@ ffmpeg -i input -c:v libxavs2 -xavs2-params RdoqLevel=0 output.avs2 @end example @end table +@section libxeve + +eXtra-fast Essential Video Encoder (XEVE) MPEG-5 EVC encoder wrapper. +The xeve-equivalent options or values are listed in parentheses for easy migration. + +This encoder requires the presence of the libxeve headers and library +during configuration. You need to explicitly configure the build with +@option{--enable-libxeve}. + +@float NOTE +Many libxeve encoder options are mapped to FFmpeg global codec options, +while unique encoder options are provided through private options. +Additionally the xeve-params private options allows one to pass a list +of key=value tuples as accepted by the libxeve @code{parse_xeve_params} function. +@end float + +The xeve project website is at @url{https://github.com/mpeg5/xeve}. + +@subsection Options + +The following options are supported by the libxeve wrapper. +The xeve-equivalent options or values are listed in parentheses for easy migration. + +@float NOTE +To reduce the duplication of documentation, only the private options +and some others requiring special attention are documented here. For +the documentation of the undocumented generic options, see +@ref{codec-options,,the Codec Options chapter}. +@end float + +@float NOTE +To get a more accurate and extensive documentation of the libxeve options, +invoke the command @code{xeve_app --help} or consult the libxeve documentation. +@end float + +@table @option +@item b (@emph{bitrate}) +Set target video bitrate in bits/s. +Note that FFmpeg's b option is expressed in bits/s, while xeve's bitrate is in kilobits/s. + +@item bf (@emph{bframes}) +Set the maximum number of B frames (1,3,7,15). + +@item g (@emph{keyint}) +Set the GOP size (I-picture period). + +@item preset (@emph{preset}) +Set the xeve preset. +Set the encoder preset value to determine encoding speed [fast, medium, slow, placebo] + +@item tune (@emph{tune}) +Set the encoder tune parameter [psnr, zerolatency] + +@item profile (@emph{profile}) +Set the encoder profile [0: baselie; 1: main] + +@item crf (@emph{crf}) +Set the quality for constant quality mode. +Constant rate factor <10..49> [default: 32] + +@item qp (@emph{qp}) +Set constant quantization rate control method parameter. +Quantization parameter qp <0..51> [default: 32] + +@item threads (@emph{threads}) +Force to use a specific number of threads + +@end table + @section libxvid Xvid MPEG-4 Part 2 encoder wrapper. diff --git a/doc/general_contents.texi b/doc/general_contents.texi index 2eeebd847d..c6a997bfd6 100644 --- a/doc/general_contents.texi +++ b/doc/general_contents.texi @@ -343,6 +343,14 @@ libxavs2 is under the GNU Public License Version 2 or later details), you must upgrade FFmpeg's license to GPL in order to use it. @end float +@section eXtra-fast Essential Video Encoder (XEVE) + +FFmpeg can make use of the XEVE library for EVC video encoding. + +Go to @url{https://github.com/mpeg5/xeve} and follow the instructions for +installing the XEVE library. Then pass @code{--enable-libxeve} to configure to +enable it. + @section ZVBI ZVBI is a VBI decoding library which can be used by FFmpeg to decode DVB @@ -598,6 +606,7 @@ library: @item raw DTS @tab X @tab X @item raw DTS-HD @tab @tab X @item raw E-AC-3 @tab X @tab X +@item raw EVC @tab X @tab X @item raw FLAC @tab X @tab X @item raw GSM @tab @tab X @item raw H.261 @tab X @tab X @@ -943,6 +952,8 @@ following image formats are supported: @item Electronic Arts TQI video @tab @tab X @item Escape 124 @tab @tab X @item Escape 130 @tab @tab X +@item EVC / MPEG-5 Part 1 @tab X @tab X + @tab encoding and decoding supported through external library libxeve @item FFmpeg video codec #1 @tab X @tab X @tab lossless codec (fourcc: FFV1) @item Flash Screen Video v1 @tab X @tab X diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 635b936cac..53ffdc5bbe 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1130,6 +1130,7 @@ OBJS-$(CONFIG_LIBX264_ENCODER) += libx264.o OBJS-$(CONFIG_LIBX265_ENCODER) += libx265.o OBJS-$(CONFIG_LIBXAVS_ENCODER) += libxavs.o OBJS-$(CONFIG_LIBXAVS2_ENCODER) += libxavs2.o +OBJS-$(CONFIG_LIBXEVE_ENCODER) += libxeve.o OBJS-$(CONFIG_LIBXVID_ENCODER) += libxvid.o OBJS-$(CONFIG_LIBZVBI_TELETEXT_DECODER) += libzvbi-teletextdec.o ass.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 385ee34803..acfade1893 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -814,6 +814,7 @@ extern LIBX264_CONST FFCodec ff_libx264_encoder; #endif extern const FFCodec ff_libx264rgb_encoder; extern FFCodec ff_libx265_encoder; +extern const FFCodec ff_libxeve_encoder; extern const FFCodec ff_libxavs_encoder; extern const FFCodec ff_libxavs2_encoder; extern const FFCodec ff_libxvid_encoder; diff --git a/libavcodec/libxeve.c b/libavcodec/libxeve.c new file mode 100644 index 0000000000..c10b7de023 --- /dev/null +++ b/libavcodec/libxeve.c @@ -0,0 +1,616 @@ +/* + * libxeve encoder + * EVC (MPEG-5 Essential Video Coding) encoding using XEVE MPEG-5 EVC encoder library + * + * 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 +#include + +#include + +#include "libavutil/internal.h" +#include "libavutil/common.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" +#include "libavutil/pixfmt.h" +#include "libavutil/time.h" +#include "libavutil/cpu.h" +#include "libavutil/avstring.h" + +#include "avcodec.h" +#include "internal.h" +#include "packet_internal.h" +#include "codec_internal.h" +#include "profiles.h" +#include "encode.h" + +#define MAX_BS_BUF (16*1024*1024) + +/** + * Error codes + */ +#define XEVE_PARAM_BAD_NAME -100 +#define XEVE_PARAM_BAD_VALUE -200 + +/** + * Encoder states + * + * STATE_ENCODING - the encoder receives and processes input frames + * STATE_BUMPING - there are no more input frames, however the encoder still processes previously received data + */ +typedef enum State { + STATE_ENCODING, + STATE_BUMPING, +} State; + +/** + * The structure stores all the states associated with the instance of Xeve MPEG-5 EVC encoder + */ +typedef struct XeveContext { + const AVClass *class; + + XEVE id; // XEVE instance identifier + XEVE_CDSC cdsc; // coding parameters i.e profile, width & height of input frame, num of therads, frame rate ... + XEVE_BITB bitb; // bitstream buffer (output) + XEVE_STAT stat; // encoding status (output) + XEVE_IMGB imgb; // image buffer (input) + + State state; // encoder state (skipping, encoding, bumping) + + int profile_id; // encoder profile (main, baseline) + int preset_id; // preset of xeve ( fast, medium, slow, placebo) + int tune_id; // tune of xeve (psnr, zerolatency) + + // variables for rate control modes + int rc_mode; // Rate control mode [ 0(CQP) / 1(ABR) / 2(CRF) ] + int qp; // quantization parameter (QP) [0,51] + int crf; // constant rate factor (CRF) [10,49] + + int hash; // embed picture signature (HASH) for conformance checking in decoding + int sei_info; // embed Supplemental enhancement information while encoding + + int color_format; // input data color format: currently only XEVE_CF_YCBCR420 is supported + + AVDictionary *xeve_params; +} XeveContext; + +/** + * Convert FFmpeg pixel format (AVPixelFormat) to XEVE pre-defined color format + * + * @param[in] av_pix_fmt pixel format (@see https://ffmpeg.org/doxygen/trunk/pixfmt_8h.html#a9a8e335cf3be472042bc9f0cf80cd4c5) + * @param[out] xeve_col_fmt XEVE pre-defined color format (@see xeve.h) + * + * @return 0 on success, negative value on failure + */ +static int libxeve_color_fmt(enum AVPixelFormat av_pix_fmt, int *xeve_col_fmt) +{ + switch (av_pix_fmt) { + case AV_PIX_FMT_YUV420P: + *xeve_col_fmt = XEVE_CF_YCBCR420; + break; + case AV_PIX_FMT_YUV420P10: + *xeve_col_fmt = XEVE_CF_YCBCR420; + break; + default: + *xeve_col_fmt = XEVE_CF_UNKNOWN; + return AVERROR_INVALIDDATA; + } + + return 0; +} + +/** + * Convert FFmpeg pixel format (AVPixelFormat) into XEVE pre-defined color space + * + * @param[in] px_fmt pixel format (@see https://ffmpeg.org/doxygen/trunk/pixfmt_8h.html#a9a8e335cf3be472042bc9f0cf80cd4c5) + * + * @return XEVE pre-defined color space (@see xeve.h) on success, XEVE_CF_UNKNOWN on failure + */ +static int libxeve_color_space(enum AVPixelFormat av_pix_fmt) +{ + /* color space of input image */ + int cs = XEVE_CF_UNKNOWN; + + switch (av_pix_fmt) { + case AV_PIX_FMT_YUV420P: + cs = XEVE_CS_YCBCR420; + break; + case AV_PIX_FMT_YUV420P10: +#if AV_HAVE_BIGENDIAN + cs = XEVE_CS_SET(XEVE_CF_YCBCR420, 10, 1); +#else + cs = XEVE_CS_YCBCR420_10LE; +#endif + + break; + default: + cs = XEVE_CF_UNKNOWN; + break; + } + + return cs; +} + +/** + * The function returns a pointer to the object of the XEVE_CDSC type. + * XEVE_CDSC contains all encoder parameters that should be initialized before the encoder is used. + * + * The field values of the XEVE_CDSC structure are populated based on: + * - the corresponding field values of the AvCodecConetxt structure, + * - the xeve encoder specific option values, + * (the full list of options available for xeve encoder is displayed after executing the command ./ffmpeg --help encoder = libxeve) + * + * The order of processing input data and populating the XEVE_CDSC structure + * 1) first, the fields of the AVCodecContext structure corresponding to the provided input options are processed, + * (i.e -pix_fmt yuv420p -s:v 1920x1080 -r 30 -profile:v 0) + * 2) then xeve-specific options added as AVOption to the xeve AVCodec implementation + * (i.e -preset 0) + * + * Keep in mind that, there are options that can be set in different ways. + * In this case, please follow the above-mentioned order of processing. + * The most recent assignments overwrite the previous values. + * + * @param[in] avctx codec context (AVCodecContext) + * @param[out] cdsc contains all Xeve MPEG-5 EVC encoder encoder parameters that should be initialized before the encoder is use + * + * @return 0 on success, negative error code on failure + */ +static int get_conf(AVCodecContext *avctx, XEVE_CDSC *cdsc) +{ + XeveContext *xectx = NULL; + int ret; + + xectx = avctx->priv_data; + + /* initialize xeve_param struct with default values */ + ret = xeve_param_default(&cdsc->param); + if (XEVE_FAILED(ret)) { + av_log(avctx, AV_LOG_ERROR, "Cannot set_default parameter\n"); + return AVERROR_EXTERNAL; + } + + /* read options from AVCodecContext */ + if (avctx->width > 0) + cdsc->param.w = avctx->width; + + if (avctx->height > 0) + cdsc->param.h = avctx->height; + + if (avctx->framerate.num > 0) { + // fps can be float number, but xeve API doesn't support it + cdsc->param.fps = lrintf(av_q2d(avctx->framerate)); + } + + // GOP size (key-frame interval, I-picture period) + cdsc->param.keyint = avctx->gop_size; // 0: only one I-frame at the first time; 1: every frame is coded in I-frame + + if (avctx->max_b_frames == 0 || avctx->max_b_frames == 1 || avctx->max_b_frames == 3 || + avctx->max_b_frames == 7 || avctx->max_b_frames == 15) // number of b-frames + cdsc->param.bframes = avctx->max_b_frames; + else { + av_log(avctx, AV_LOG_ERROR, "Incorrect value for maximum number of B frames: (%d) \n" + "Acceptable values for bf option (maximum number of B frames) are 0,1,3,7 or 15\n", avctx->max_b_frames); + return AVERROR_INVALIDDATA; + } + + cdsc->param.level_idc = avctx->level; + + if (avctx->rc_buffer_size) // VBV buf size + cdsc->param.vbv_bufsize = (int)(avctx->rc_buffer_size / 1000); + + cdsc->param.rc_type = xectx->rc_mode; + + if (xectx->rc_mode == XEVE_RC_CQP) + cdsc->param.qp = xectx->qp; + else if (xectx->rc_mode == XEVE_RC_ABR) { + if (avctx->bit_rate / 1000 > INT_MAX || avctx->rc_max_rate / 1000 > INT_MAX) { + av_log(avctx, AV_LOG_ERROR, "Not supported bitrate bit_rate and rc_max_rate > %d000\n", INT_MAX); + return AVERROR_INVALIDDATA; + } + cdsc->param.bitrate = (int)(avctx->bit_rate / 1000); + } else if (xectx->rc_mode == XEVE_RC_CRF) + cdsc->param.crf = xectx->crf; + else { + av_log(avctx, AV_LOG_ERROR, "Not supported rate control type: %d\n", xectx->rc_mode); + return AVERROR_INVALIDDATA; + } + + if (avctx->thread_count <= 0) { + int cpu_count = av_cpu_count(); + cdsc->param.threads = (cpu_count < XEVE_MAX_THREADS) ? cpu_count : XEVE_MAX_THREADS; + } else if (avctx->thread_count > XEVE_MAX_THREADS) + cdsc->param.threads = XEVE_MAX_THREADS; + else + cdsc->param.threads = avctx->thread_count; + + + libxeve_color_fmt(avctx->pix_fmt, &xectx->color_format); + + cdsc->param.cs = XEVE_CS_SET(xectx->color_format, cdsc->param.codec_bit_depth, AV_HAVE_BIGENDIAN); + + cdsc->max_bs_buf_size = MAX_BS_BUF; + + ret = xeve_param_ppt(&cdsc->param, xectx->profile_id, xectx->preset_id, xectx->tune_id); + if (XEVE_FAILED(ret)) { + av_log(avctx, AV_LOG_ERROR, "Cannot set profile(%d), preset(%d), tune(%d)\n", xectx->profile_id, xectx->preset_id, xectx->tune_id); + return AVERROR_EXTERNAL; + } + + return 0; +} + +/** + * Set XEVE_CFG_SET_USE_PIC_SIGNATURE for encoder + * + * @param[in] logger context + * @param[in] id XEVE encodec instance identifier + * @param[in] ctx the structure stores all the states associated with the instance of Xeve MPEG-5 EVC encoder + * + * @return 0 on success, negative error code on failure + */ +static int set_extra_config(AVCodecContext *avctx, XEVE id, XeveContext *ctx) +{ + int ret, size; + size = 4; + + // embed SEI messages identifying encoder parameters and command line arguments + // - 0: off\n" + // - 1: emit sei info" + // + // SEI - Supplemental enhancement information contains information + // that is not necessary to decode the samples of coded pictures from VCL NAL units. + // Some SEI message information is required to check bitstream conformance + // and for output timing decoder conformance. + // @see ISO_IEC_23094-1_2020 7.4.3.5 + // @see ISO_IEC_23094-1_2020 Annex D + ret = xeve_config(id, XEVE_CFG_SET_SEI_CMD, &ctx->sei_info, &size); // sei_cmd_info + if (XEVE_FAILED(ret)) { + av_log(avctx, AV_LOG_ERROR, "Failed to set config for sei command info messages\n"); + return AVERROR_EXTERNAL; + } + + ret = xeve_config(id, XEVE_CFG_SET_USE_PIC_SIGNATURE, &ctx->hash, &size); + if (XEVE_FAILED(ret)) { + av_log(avctx, AV_LOG_ERROR, "Failed to set config for picture signature\n"); + return AVERROR_EXTERNAL; + } + + return 0; +} + +/** + * @brief Switch encoder to bumping mode + * + * @param id XEVE encodec instance identifier + * @return 0 on success, negative error code on failure + */ +static int setup_bumping(XEVE id) +{ + int val = 1; + int size = sizeof(int); + if (XEVE_FAILED(xeve_config(id, XEVE_CFG_SET_FORCE_OUT, (void *)(&val), &size))) + return AVERROR_EXTERNAL; + + return 0; +} + +/** + * @brief Initialize eXtra-fast Essential Video Encoder codec + * Create an encoder instance and allocate all the needed resources + * + * @param avctx codec context + * @return 0 on success, negative error code on failure + */ +static av_cold int libxeve_init(AVCodecContext *avctx) +{ + XeveContext *xectx = avctx->priv_data; + unsigned char *bs_buf = NULL; + int i; + int shift_h = 0; + int shift_v = 0; + int width_chroma = 0; + int height_chroma = 0; + XEVE_IMGB *imgb = NULL; + int ret = 0; + + XEVE_CDSC *cdsc = &(xectx->cdsc); + + /* allocate bitstream buffer */ + bs_buf = av_malloc(MAX_BS_BUF); + if (bs_buf == NULL) { + av_log(avctx, AV_LOG_ERROR, "Cannot allocate bitstream buffer\n"); + return AVERROR(ENOMEM); + } + xectx->bitb.addr = bs_buf; + xectx->bitb.bsize = MAX_BS_BUF; + + /* read configurations and set values for created descriptor (XEVE_CDSC) */ + if ((ret = get_conf(avctx, cdsc)) != 0) { + av_log(avctx, AV_LOG_ERROR, "Cannot get configuration\n"); + return AVERROR(EINVAL); + } + + if ((ret = xeve_param_check(&cdsc->param)) != 0) { + av_log(avctx, AV_LOG_ERROR, "Invalid configuration\n"); + return AVERROR(EINVAL); + } + + { + AVDictionaryEntry *en = NULL; + while (en = av_dict_get(xectx->xeve_params, "", en, AV_DICT_IGNORE_SUFFIX)) { + if ((ret = xeve_param_parse(&cdsc->param, en->key, en->value)) < 0) { + av_log(avctx, AV_LOG_WARNING, + "Error parsing option '%s = %s'.\n", + en->key, en->value); + } + } + } + + /* create encoder */ + xectx->id = xeve_create(cdsc, NULL); + if (xectx->id == NULL) { + av_log(avctx, AV_LOG_ERROR, "Cannot create XEVE encoder\n"); + return AVERROR_EXTERNAL; + } + + if ((ret = set_extra_config(avctx, xectx->id, xectx)) != 0) { + av_log(avctx, AV_LOG_ERROR, "Cannot set extra configuration\n"); + return AVERROR(EINVAL); + } + + if ((ret = av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &shift_h, &shift_v)) != 0) { + av_log(avctx, AV_LOG_ERROR, "Failed to get chroma shift\n"); + return AVERROR(EINVAL); + } + + // Chroma subsampling + // + // YUV format explanation + // shift_h == 1 && shift_v == 1 : YUV420 + // shift_h == 1 && shift_v == 0 : YUV422 + // shift_h == 0 && shift_v == 0 : YUV444 + // + width_chroma = AV_CEIL_RSHIFT(avctx->width, shift_h); + height_chroma = AV_CEIL_RSHIFT(avctx->height, shift_v); + + /* set default values for input image buffer */ + imgb = &xectx->imgb; + imgb->cs = libxeve_color_space(avctx->pix_fmt); + imgb->np = 3; /* only for yuv420p, yuv420ple */ + + for (i = 0; i < imgb->np; i++) + imgb->x[i] = imgb->y[i] = 0; + + imgb->w[0] = imgb->aw[0] = avctx->width; // width luma + imgb->w[1] = imgb->w[2] = imgb->aw[1] = imgb->aw[2] = width_chroma; + imgb->h[0] = imgb->ah[0] = avctx->height; // height luma + imgb->h[1] = imgb->h[2] = imgb->ah[1] = imgb->ah[2] = height_chroma; + + xectx->state = STATE_ENCODING; + + return 0; +} + +/** + * Encode raw data frame into EVC packet + * + * @param[in] avctx codec context + * @param[out] avpkt output AVPacket containing encoded data + * @param[in] frame AVFrame containing the raw data to be encoded + * @param[out] got_packet encoder sets to 0 or 1 to indicate that a + * non-empty packet was returned in pkt + * + * @return 0 on success, negative error code on failure + */ +static int libxeve_encode(AVCodecContext *avctx, AVPacket *avpkt, + const AVFrame *frame, int *got_packet) +{ + XeveContext *xectx = avctx->priv_data; + int ret = -1; + + // No more input frames are available but encoder still can have some data in its internal buffer to process + // and some frames to dump. + if (xectx->state == STATE_ENCODING && frame == NULL) { + if (setup_bumping(xectx->id) == 0) + xectx->state = STATE_BUMPING; // Entering bumping process + else { + av_log(avctx, AV_LOG_ERROR, "Failed to setup bumping\n"); + return 0; + } + } + + if (xectx->state == STATE_ENCODING) { + int i; + XEVE_IMGB *imgb = NULL; + + imgb = &xectx->imgb; + + for (i = 0; i < imgb->np; i++) { + imgb->a[i] = frame->data[i]; + imgb->s[i] = frame->linesize[i]; + } + + imgb->ts[XEVE_TS_PTS] = frame->pts; + + /* push image to encoder */ + ret = xeve_push(xectx->id, imgb); + if (XEVE_FAILED(ret)) { + av_log(avctx, AV_LOG_ERROR, "xeve_push() failed\n"); + return AVERROR_EXTERNAL; + } + } + if (xectx->state == STATE_ENCODING || xectx->state == STATE_BUMPING) { + /* encoding */ + ret = xeve_encode(xectx->id, &(xectx->bitb), &(xectx->stat)); + if (XEVE_FAILED(ret)) { + av_log(avctx, AV_LOG_ERROR, "xeve_encode() failed\n"); + return AVERROR_EXTERNAL; + } + + /* store bitstream */ + if (ret == XEVE_OK_OUT_NOT_AVAILABLE) { // Return OK but picture is not available yet + *got_packet = 0; + return 0; + } else if (ret == XEVE_OK) { + int av_pic_type; + + if (xectx->stat.write > 0) { + + ret = ff_get_encode_buffer(avctx, avpkt, xectx->stat.write, 0); + if (ret < 0) + return ret; + + memcpy(avpkt->data, xectx->bitb.addr, xectx->stat.write); + + avpkt->time_base.num = 1; + avpkt->time_base.den = xectx->cdsc.param.fps; + + avpkt->pts = xectx->bitb.ts[XEVE_TS_PTS]; + avpkt->dts = xectx->bitb.ts[XEVE_TS_DTS]; + + switch(xectx->stat.stype) { + case XEVE_ST_I: + av_pic_type = AV_PICTURE_TYPE_I; + avpkt->flags |= AV_PKT_FLAG_KEY; + break; + case XEVE_ST_P: + av_pic_type = AV_PICTURE_TYPE_P; + break; + case XEVE_ST_B: + av_pic_type = AV_PICTURE_TYPE_B; + break; + case XEVE_ST_UNKNOWN: + av_log(avctx, AV_LOG_ERROR, "Unknown slice type\n"); + return AVERROR_INVALIDDATA; + } + + ff_side_data_set_encoder_stats(avpkt, xectx->stat.qp * FF_QP2LAMBDA, NULL, 0, av_pic_type); + + *got_packet = 1; + } + } else if (ret == XEVE_OK_NO_MORE_FRM) { + // Return OK but no more frames + return 0; + } else { + av_log(avctx, AV_LOG_ERROR, "Invalid return value: %d\n", ret); + return AVERROR_EXTERNAL; + } + } else { + av_log(avctx, AV_LOG_ERROR, "Udefined encoder state\n"); + return AVERROR_INVALIDDATA; + } + + return 0; +} + +/** + * Destroy the encoder and release all the allocated resources + * + * @param avctx codec context + * @return 0 on success, negative error code on failure + */ +static av_cold int libxeve_close(AVCodecContext *avctx) +{ + XeveContext *xectx = avctx->priv_data; + + if (xectx->id) { + xeve_delete(xectx->id); + xectx->id = NULL; + } + + av_free(xectx->bitb.addr); /* release bitstream buffer */ + + return 0; +} + +#define OFFSET(x) offsetof(XeveContext, x) +#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM + +static const enum AVPixelFormat supported_pixel_formats[] = { + AV_PIX_FMT_YUV420P, + AV_PIX_FMT_YUV420P10, + AV_PIX_FMT_NONE +}; + +// Consider using following options (./ffmpeg --help encoder=libxeve) +// +static const AVOption libxeve_options[] = { + { "preset", "Encoding preset for setting encoding speed", OFFSET(preset_id), AV_OPT_TYPE_INT, { .i64 = XEVE_PRESET_MEDIUM }, XEVE_PRESET_DEFAULT, XEVE_PRESET_PLACEBO, VE, "preset" }, + { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_PRESET_DEFAULT }, INT_MIN, INT_MAX, VE, "preset" }, + { "fast", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_PRESET_FAST }, INT_MIN, INT_MAX, VE, "preset" }, + { "medium", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_PRESET_MEDIUM }, INT_MIN, INT_MAX, VE, "preset" }, + { "slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_PRESET_SLOW }, INT_MIN, INT_MAX, VE, "preset" }, + { "placebo", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_PRESET_PLACEBO }, INT_MIN, INT_MAX, VE, "preset" }, + { "tune", "Tuning parameter for special purpose operation", OFFSET(tune_id), AV_OPT_TYPE_INT, { .i64 = XEVE_TUNE_NONE }, XEVE_TUNE_NONE, XEVE_TUNE_PSNR, VE, "tune"}, + { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_TUNE_NONE }, INT_MIN, INT_MAX, VE, "tune" }, + { "zerolatency", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_TUNE_ZEROLATENCY }, INT_MIN, INT_MAX, VE, "tune" }, + { "psnr", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_TUNE_PSNR }, INT_MIN, INT_MAX, VE, "tune" }, + { "profile", "Encoding profile", OFFSET(profile_id), AV_OPT_TYPE_INT, { .i64 = XEVE_PROFILE_BASELINE }, XEVE_PROFILE_BASELINE, XEVE_PROFILE_MAIN, VE, "profile" }, + { "baseline", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_PROFILE_BASELINE }, INT_MIN, INT_MAX, VE, "profile" }, + { "main", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_PROFILE_MAIN }, INT_MIN, INT_MAX, VE, "profile" }, + { "rc_mode", "Rate control mode", OFFSET(rc_mode), AV_OPT_TYPE_INT, { .i64 = XEVE_RC_CQP }, XEVE_RC_CQP, XEVE_RC_CRF, VE, "rc_mode" }, + { "CQP", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_RC_CQP }, INT_MIN, INT_MAX, VE, "rc_mode" }, + { "ABR", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_RC_ABR }, INT_MIN, INT_MAX, VE, "rc_mode" }, + { "CRF", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_RC_CRF }, INT_MIN, INT_MAX, VE, "rc_mode" }, + { "qp", "Quantization parameter value for CQP rate control mode", OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 32 }, 0, 51, VE }, + { "crf", "Constant rate factor value for CRF rate control mode", OFFSET(crf), AV_OPT_TYPE_INT, { .i64 = 32 }, 10, 49, VE }, + { "hash", "Embed picture signature (HASH) for conformance checking in decoding", OFFSET(hash), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, + { "sei_info", "Embed SEI messages identifying encoder parameters and command line arguments", OFFSET(sei_info), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, + { "xeve-params", "Override the xeve configuration using a :-separated list of key=value parameters", OFFSET(xeve_params), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE }, + { NULL } +}; + +static const AVClass libxeve_class = { + .class_name = "libxeve", + .item_name = av_default_item_name, + .option = libxeve_options, + .version = LIBAVUTIL_VERSION_INT, +}; + +/** + * libavcodec generic global options, which can be set on all the encoders and decoders + * @see https://www.ffmpeg.org/ffmpeg-codecs.html#Codec-Options + */ +static const FFCodecDefault libxeve_defaults[] = { + { "b", "0" }, // bitrate in terms of kilo-bits per second + { "g", "0" }, // gop_size (key-frame interval 0: only one I-frame at the first time; 1: every frame is coded in I-frame) + { "bf", "15"}, // maximum number of B frames (0: no B-frames, 1,3,7,15) + { "threads", "0"}, // number of threads to be used (0: automatically select the number of threads to set) + { NULL }, +}; + +const FFCodec ff_libxeve_encoder = { + .p.name = "libxeve", + .p.long_name = NULL_IF_CONFIG_SMALL("libxeve MPEG-5 EVC"), + .p.type = AVMEDIA_TYPE_VIDEO, + .p.id = AV_CODEC_ID_EVC, + .init = libxeve_init, + FF_CODEC_ENCODE_CB(libxeve_encode), + .close = libxeve_close, + .priv_data_size = sizeof(XeveContext), + .p.priv_class = &libxeve_class, + .defaults = libxeve_defaults, + .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS | AV_CODEC_CAP_DR1, + .p.profiles = NULL_IF_CONFIG_SMALL(ff_evc_profiles), + .p.wrapper_name = "libxeve", + .p.pix_fmts = supported_pixel_formats, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_NOT_INIT_THREADSAFE, +}; From patchwork Mon Mar 27 10:48:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawid Kozinski X-Patchwork-Id: 40866 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp1221054pzh; Mon, 27 Mar 2023 03:49:06 -0700 (PDT) X-Google-Smtp-Source: AK7set/XWqfeXseKUoZ6CI/lR485GFtz98cfKtG9MTtjT2mRzSvdTp/OJqrNqojEvzinGLnpsQjl X-Received: by 2002:a05:6402:a53:b0:4bf:b2b1:84d8 with SMTP id bt19-20020a0564020a5300b004bfb2b184d8mr19195371edb.19.1679914146648; Mon, 27 Mar 2023 03:49:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679914146; cv=none; d=google.com; s=arc-20160816; b=P/IbeXtAQr/yo54XdiCgxx8XV5EpfD1+i8VeRsgg6l6FZ2VvXVYr8XpIU+MscklDpE 1NenJ1muiitv6q8yWsH9w98u0W3EjpUutTcuY7tyU2rOwkYtsPsnZUEZ0njwDmmPYK09 2qHgzri240bwPM1xL8QaxR7RNU5Je2aQcn4INrLZ/g7cfwMWU5oKQQiugDa8Sore+kPl foLEqJGO0ZtPNNR8EqyGghtaPhF6vKXLXXmkIYy5AyiTPRgKBxMUP0LKKvs4xse2Nw18 PrFQ5E7Ular87GCyiZtz66CDckpylqOB3Yc1j9BheYhSQS4yVUW4D1+9J8GOMSXGXoXF 1maQ== 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=Kzr54QttK3gAkRWzA6/6OO8dkPeIwMHz1fUAC4goe14=; b=TbuEnVUY8l5orG352hz3WgjlGwMubMcSstWYZQk2/4c+c2LEcHihNqzY/6FkScjKQc 9Uo4k0n/JKF81xaapKFj9HN8fuTgxAUk3NMVoP2CI/ptWCrTo9CHcKaekp5Q0xPBI1fG GQjfiwYUPt3BwjW+PBtAmXbf0JwyK0UyuEqy8B13UQqDplp10fZBFtNzUqxLX+z3Xv82 EVQDQEFtzgi1GMuov9Rk3EaOWo66DpF5gylvTKSGfVs0z3YXSBH8b7PCyFGKpvWYXqAf ZfWfym+hUbmOk/KQG+DZmAWTZO3qfynb/Dnx/FnmxUUjWKkMjSr7IKvMnml22wNI12gF 4GGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=T19aciA5; 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 q23-20020a056402033700b004c10381668csi28085269edw.286.2023.03.27.03.49.06; Mon, 27 Mar 2023 03:49:06 -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=@samsung.com header.s=mail20170921 header.b=T19aciA5; 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 260CE68CABA; Mon, 27 Mar 2023 13:49:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 35ECD68C906 for ; Mon, 27 Mar 2023 13:48:58 +0300 (EEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230327104857euoutp01cda762cb466de9ffe5aa43c4d1334adc~QQQH5-W4X1389013890euoutp01H for ; Mon, 27 Mar 2023 10:48:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230327104857euoutp01cda762cb466de9ffe5aa43c4d1334adc~QQQH5-W4X1389013890euoutp01H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1679914137; bh=KY3pNh6KS1HaM2LHnsKQkiOCViPBlKeZncL5bwEw7ww=; h=From:To:Cc:Subject:Date:References:From; b=T19aciA5sq6Gn1+bmq9DtJEIN41Qi74rB5t6y/RDKzltA1gWiztg6UUWeNM2zeWj3 CPOaKZIue5tNwWI+qSZo7kfxXu8l8PXhpyvPmYA//GEnczDMVAIreml3a5nUP6ErNj rpRtW6r0hobaVxMa+sboFyOj5Zy8V34DsnsYhs34= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230327104857eucas1p158c7b1085ab12bf0af9df115fa5c65ff~QQQHrprTs1096010960eucas1p1j; Mon, 27 Mar 2023 10:48:57 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 5F.7D.09966.99471246; Mon, 27 Mar 2023 11:48:57 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230327104857eucas1p2ed1e1549d1cc373ae22dc5ec8bcb3580~QQQHWSPtB0085000850eucas1p2W; Mon, 27 Mar 2023 10:48:57 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230327104857eusmtrp1575cea6a8a59f040b0376ebb9bc050db~QQQHVwioI1227712277eusmtrp1N; Mon, 27 Mar 2023 10:48:57 +0000 (GMT) X-AuditID: cbfec7f4-d4fff700000026ee-90-6421749960e5 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 19.C4.09583.89471246; Mon, 27 Mar 2023 11:48:57 +0100 (BST) Received: from AMDN5164.EU.corp.samsungelectronics.net (unknown [106.210.132.171]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230327104856eusmtip29edbdc08f2be5392eb8cea363c370b65~QQQG8x-041799717997eusmtip2k; Mon, 27 Mar 2023 10:48:56 +0000 (GMT) From: Dawid Kozinski To: d.frankiewic@samsung.com, ffmpeg-devel@ffmpeg.org Date: Mon, 27 Mar 2023 12:48:45 +0200 Message-Id: <20230327104845.1651-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+NgFnrDIsWRmVeSWpSXmKPExsWy7djPc7ozSxRTDCaflLL4cu0Ls8XKb79Z LL59OsPswOzxZ9FmFo++LasYA5iiuGxSUnMyy1KL9O0SuDKWdDazFrzezFix+tEn1gbGbXVd jJwcEgImEj8mH2XvYuTiEBJYwSjxdvEyKOcLo8SsN71sEM5nRokTUy6xwLTc3zQDKrGcUWJa +3VmCKedSWJv53xmkCo2AV2Jlx8eMYHYIgKmEieb97KB2MwC2hLr7n4Hs4UFAiR+Hb4JVs8i oCqx5cZ8dhCbV8BK4t/Wo4wQ2zQlJmyZwwQRF5Q4OfMJ1BXcEutmXWKFmCkv0bx1NtgREgI/ 2SXmXJzLBFHkInF+/1I2CFtY4tXxLewQtozE6ck9QIM4gOxiiUP9DhBmjcShH+kQFdYSbxuP M4KEmYFOWL9LH6LCUeLnSncIk0/ixltBiP18EpO2TWeGCPNKdLQJQZgqEn2dYhDjpCSeLpvD DGF7SJy5co1lAqPiLCRPzULyyCyErQsYmVcxiqeWFuempxYb5aWW6xUn5haX5qXrJefnbmIE JojT/45/2cG4/NVHvUOMTByMhxglOJiVRHg3eyumCPGmJFZWpRblxxeV5qQWH2KU5mBREufV tj2ZLCSQnliSmp2aWpBaBJNl4uCUamAS0kiZtHwh0/5pm07O/buy6MxOu8LCQzt+Tsm2KWCf OFO6a83uRctuJuhOKt15x89xE4vrbKWDQTJ/j8x8nn1bkvfs0ZXTXqkc59lg0C1WxBygYhb1 9dkH+x61RWIPQyzDls+VTbLIV9lW2yb7IL5Wyeh3zM/mtun5xpfWK32yvjrFvub53G89/QUx 3wrfFhx/lHZdYkboUYHLgaWBk2T1ck7aP68TPLl+1YY1FUrWb/1Fdp4KmKe0k8crsXTTtS1v w6aIzeAPuGEQuurXSgvrL++cfjeKb77qdWxBae3ytx6Ct7/9X2VeZqWQxRXc1Jgmx7oh89el C77sUQe3dMmY2XgUH5rCZSxb7vaJsaFKiaU4I9FQi7moOBEAhyi++38DAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrELMWRmVeSWpSXmKPExsVy+t/xe7ozSxRTDN7dZLT4cu0Ls8XKb79Z LL59OsPswOzxZ9FmFo++LasYA5ii9GyK8ktLUhUy8otLbJWiDS2M9AwtLfSMTCz1DI3NY62M TJX07WxSUnMyy1KL9O0S9DKWdDazFrzezFix+tEn1gbGbXVdjJwcEgImEvc3zWDrYuTiEBJY yigxac13JoiElMTSpYsYIWxhiT/XuthAbCGBViaJY+e8QGw2AV2Jlx8egdWLCJhLXFx3C6ye WUBbYt3d72D1wgJ+EpM+nweLswioSmy5MZ8dxOYVsJL4t/Uo1HxNiQlb5jBBxAUlTs58wgIR 55ZYN+sSK8RMeYnmrbOZJzDyz0JSNgtJagEj0ypGkdTS4tz03GIjveLE3OLSvHS95PzcTYzA wN127OeWHYwrX33UO8TIxMF4iFGCg1lJhHezt2KKEG9KYmVValF+fFFpTmrxIUZToFsnMkuJ JucDYyevJN7QzMDU0MTM0sDU0sxYSZzXs6AjUUggPbEkNTs1tSC1CKaPiYNTqoGpf8daaQOb auGnc0ocbFj3H5UV2BOzp3FzNEOMeu96i8U79vQVbHh4yIGbsWX+vcTjG/bEbVVsuiXo+Zlp 37nF1jOiTh/4EPj2Louo3O7FgiLvXlVfWjyxOX4J7+bwxgmpb8uPXXH8dZIt6Jj8ZZ9l3wPe CadFBLyScBRsf1naWCnbcf/rnG+FPwz5Z1U8DPZYE7zZxO/GnsiK1KqbnryRQq1Wakvu7cqM rHLzPCBxouN1qLPD5Df5LuaB01c5JV408r8XM6er5d7foHPS/z/mLZfLkdfVOqZq2rJ592KB Kqtz7/oYNjy8pRzOf/OT98OjNU3NUj9OZFZXpJuv6pr7h/t66qaT89NuLF98q/6/EktxRqKh FnNRcSIAl7lnHeUCAAA= X-CMS-MailID: 20230327104857eucas1p2ed1e1549d1cc373ae22dc5ec8bcb3580 X-Msg-Generator: CA X-RootMTR: 20230327104857eucas1p2ed1e1549d1cc373ae22dc5ec8bcb3580 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230327104857eucas1p2ed1e1549d1cc373ae22dc5ec8bcb3580 References: Subject: [FFmpeg-devel] [PATCH v17 6/9] avcodec/evc_decoder: Provided support for EVC decoder 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: DJhquTyPV5F+ - Added EVC decoder wrapper - Changes in project configuration file and libavcodec Makefile - Added documentation for xevd wrapper --- configure | 4 + doc/decoders.texi | 24 ++ doc/general_contents.texi | 10 +- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/libxevd.c | 488 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 527 insertions(+), 1 deletion(-) create mode 100644 libavcodec/libxevd.c diff --git a/configure b/configure index 176e42d131..d5e48c2c7f 100755 --- a/configure +++ b/configure @@ -292,6 +292,7 @@ External library support: --enable-libx264 enable H.264 encoding via x264 [no] --enable-libx265 enable HEVC encoding via x265 [no] --enable-libxeve enable EVC encoding via libxeve [no] + --enable-libxevd enable EVC decoding via libxevd [no] --enable-libxavs enable AVS encoding via xavs [no] --enable-libxavs2 enable AVS2 encoding via xavs2 [no] --enable-libxcb enable X11 grabbing using XCB [autodetect] @@ -1863,6 +1864,7 @@ EXTERNAL_LIBRARY_LIST=" libvorbis libvpx libwebp + libxevd libxeve libxml2 libzimg @@ -3399,6 +3401,7 @@ libx265_encoder_deps="libx265" libx265_encoder_select="atsc_a53" libxavs_encoder_deps="libxavs" libxavs2_encoder_deps="libxavs2" +libxevd_decoder_deps="libxevd" libxeve_encoder_deps="libxeve" libxvid_encoder_deps="libxvid" libzvbi_teletext_decoder_deps="libzvbi" @@ -6738,6 +6741,7 @@ enabled libx265 && require_pkg_config libx265 x265 x265.h x265_api_get require_cpp_condition libx265 x265.h "X265_BUILD >= 89" enabled libxavs && require libxavs "stdint.h xavs.h" xavs_encoder_encode "-lxavs $pthreads_extralibs $libm_extralibs" enabled libxavs2 && require_pkg_config libxavs2 "xavs2 >= 1.3.0" "stdint.h xavs2.h" xavs2_api_get +enabled libxevd && require_pkg_config libxevd "xevd >= 0.4.1" "xevd.h" xevd_decode enabled libxeve && require_pkg_config libxeve "xeve >= 0.4.3" "xeve.h" xeve_encode enabled libxvid && require libxvid xvid.h xvid_global -lxvidcore enabled libzimg && require_pkg_config libzimg "zimg >= 2.7.0" zimg.h zimg_get_api_version diff --git a/doc/decoders.texi b/doc/decoders.texi index 5ba85cf9b1..54720ee8b4 100644 --- a/doc/decoders.texi +++ b/doc/decoders.texi @@ -130,6 +130,30 @@ Set amount of frame threads to use during decoding. The default value is 0 (auto @end table +@section libxevd + +eXtra-fast Essential Video Decoder (XEVD) MPEG-5 EVC decoder wrapper. + +This decoder requires the presence of the libxevd headers and library +during configuration. You need to explicitly configure the build with +@option{--enable-libxevd}. + +The xevd project website is at @url{https://github.com/mpeg5/xevd}. + +@subsection Options + +The following options are supported by the libxevd wrapper. +The xevd-equivalent options or values are listed in parentheses for easy migration. + +To get a more accurate and extensive documentation of the libxevd options, +invoke the command @code{xevd_app --help} or consult the libxevd documentation. + +@table @option +@item threads (@emph{threads}) +Force to use a specific number of threads + +@end table + @section QSV Decoders The family of Intel QuickSync Video decoders (VC1, MPEG-2, H.264, HEVC, diff --git a/doc/general_contents.texi b/doc/general_contents.texi index c6a997bfd6..8e08f5ebc3 100644 --- a/doc/general_contents.texi +++ b/doc/general_contents.texi @@ -351,6 +351,14 @@ Go to @url{https://github.com/mpeg5/xeve} and follow the instructions for installing the XEVE library. Then pass @code{--enable-libxeve} to configure to enable it. +@section eXtra-fast Essential Video Decoder (XEVD) + +FFmpeg can make use of the XEVD library for EVC video decoding. + +Go to @url{https://github.com/mpeg5/xevd} and follow the instructions for +installing the XEVD library. Then pass @code{--enable-libxevd} to configure to +enable it. + @section ZVBI ZVBI is a VBI decoding library which can be used by FFmpeg to decode DVB @@ -953,7 +961,7 @@ following image formats are supported: @item Escape 124 @tab @tab X @item Escape 130 @tab @tab X @item EVC / MPEG-5 Part 1 @tab X @tab X - @tab encoding and decoding supported through external library libxeve + @tab encoding and decoding supported through external libraries libxeve and libxevd @item FFmpeg video codec #1 @tab X @tab X @tab lossless codec (fourcc: FFV1) @item Flash Screen Video v1 @tab X @tab X diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 53ffdc5bbe..1c473f3beb 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1130,6 +1130,7 @@ OBJS-$(CONFIG_LIBX264_ENCODER) += libx264.o OBJS-$(CONFIG_LIBX265_ENCODER) += libx265.o OBJS-$(CONFIG_LIBXAVS_ENCODER) += libxavs.o OBJS-$(CONFIG_LIBXAVS2_ENCODER) += libxavs2.o +OBJS-$(CONFIG_LIBXEVD_DECODER) += libxevd.o OBJS-$(CONFIG_LIBXEVE_ENCODER) += libxeve.o OBJS-$(CONFIG_LIBXVID_ENCODER) += libxvid.o OBJS-$(CONFIG_LIBZVBI_TELETEXT_DECODER) += libzvbi-teletextdec.o ass.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index acfade1893..a55a06023e 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -815,6 +815,7 @@ extern LIBX264_CONST FFCodec ff_libx264_encoder; extern const FFCodec ff_libx264rgb_encoder; extern FFCodec ff_libx265_encoder; extern const FFCodec ff_libxeve_encoder; +extern const FFCodec ff_libxevd_decoder; extern const FFCodec ff_libxavs_encoder; extern const FFCodec ff_libxavs2_encoder; extern const FFCodec ff_libxvid_encoder; diff --git a/libavcodec/libxevd.c b/libavcodec/libxevd.c new file mode 100644 index 0000000000..2e02176606 --- /dev/null +++ b/libavcodec/libxevd.c @@ -0,0 +1,488 @@ +/* + * libxevd decoder + * EVC (MPEG-5 Essential Video Coding) decoding using XEVD MPEG-5 EVC decoder library + * + * 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 +#include + +#include + +#include "libavutil/internal.h" +#include "libavutil/common.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" +#include "libavutil/pixfmt.h" +#include "libavutil/imgutils.h" +#include "libavutil/cpu.h" + +#include "avcodec.h" +#include "internal.h" +#include "packet_internal.h" +#include "codec_internal.h" +#include "profiles.h" +#include "decode.h" + +#define XEVD_PARAM_BAD_NAME -1 +#define XEVD_PARAM_BAD_VALUE -2 + +#define EVC_NAL_HEADER_SIZE 2 /* byte */ + +/** + * The structure stores all the states associated with the instance of Xeve MPEG-5 EVC decoder + */ +typedef struct XevdContext { + const AVClass *class; + + XEVD id; // XEVD instance identifier @see xevd.h + XEVD_CDSC cdsc; // decoding parameters @see xevd.h + + // If end of stream occurs it is required "flushing" (aka draining) the codec, + // as the codec might buffer multiple frames or packets internally. + int draining_mode; // The flag is set if codec enters draining mode. +} XevdContext; + +/** + * The function populates the XEVD_CDSC structure. + * XEVD_CDSC contains all decoder parameters that should be initialized before its use. + * + * @param[in] avctx codec context + * @param[out] cdsc contains all decoder parameters that should be initialized before its use + * + */ +static void get_conf(AVCodecContext *avctx, XEVD_CDSC *cdsc) +{ + int cpu_count = av_cpu_count(); + + /* clear XEVS_CDSC structure */ + memset(cdsc, 0, sizeof(XEVD_CDSC)); + + /* init XEVD_CDSC */ + if (avctx->thread_count <= 0) + cdsc->threads = (cpu_count < XEVD_MAX_TASK_CNT) ? cpu_count : XEVD_MAX_TASK_CNT; + else if (avctx->thread_count > XEVD_MAX_TASK_CNT) + cdsc->threads = XEVD_MAX_TASK_CNT; + else + cdsc->threads = avctx->thread_count; +} + +/** + * Read NAL unit length + * @param bs input data (bitstream) + * @return the length of NAL unit on success, 0 value on failure + */ +static uint32_t read_nal_unit_length(const uint8_t *bs, int bs_size, AVCodecContext *avctx) +{ + uint32_t len = 0; + XEVD_INFO info; + int ret; + + if (bs_size == XEVD_NAL_UNIT_LENGTH_BYTE) { + ret = xevd_info((void *)bs, XEVD_NAL_UNIT_LENGTH_BYTE, 1, &info); + if (XEVD_FAILED(ret)) { + av_log(avctx, AV_LOG_ERROR, "Cannot get bitstream information\n"); + return 0; + } + len = info.nalu_len; + if (len == 0) { + av_log(avctx, AV_LOG_ERROR, "Invalid bitstream size! [%d]\n", bs_size); + return 0; + } + } + + return len; +} + +/** + * @param[in] xectx the structure that stores all the state associated with the instance of Xeve MPEG-5 EVC decoder + * @param[out] avctx codec context + * @return 0 on success, negative value on failure + */ +static int export_stream_params(const XevdContext *xectx, AVCodecContext *avctx) +{ + int ret; + int size; + int color_space; + + avctx->pix_fmt = AV_PIX_FMT_YUV420P10; + + size = 4; + ret = xevd_config(xectx->id, XEVD_CFG_GET_CODED_WIDTH, &avctx->coded_width, &size); + if (XEVD_FAILED(ret)) { + av_log(avctx, AV_LOG_ERROR, "Failed to get coded_width\n"); + return AVERROR_EXTERNAL; + } + + ret = xevd_config(xectx->id, XEVD_CFG_GET_CODED_HEIGHT, &avctx->coded_height, &size); + if (XEVD_FAILED(ret)) { + av_log(avctx, AV_LOG_ERROR, "Failed to get coded_height\n"); + return AVERROR_EXTERNAL; + } + + ret = xevd_config(xectx->id, XEVD_CFG_GET_WIDTH, &avctx->width, &size); + if (XEVD_FAILED(ret)) { + av_log(avctx, AV_LOG_ERROR, "Failed to get width\n"); + return AVERROR_EXTERNAL; + } + + ret = xevd_config(xectx->id, XEVD_CFG_GET_HEIGHT, &avctx->height, &size); + if (XEVD_FAILED(ret)) { + av_log(avctx, AV_LOG_ERROR, "Failed to get height\n"); + return AVERROR_EXTERNAL; + } + + ret = xevd_config(xectx->id, XEVD_CFG_GET_COLOR_SPACE, &color_space, &size); + if (XEVD_FAILED(ret)) { + av_log(avctx, AV_LOG_ERROR, "Failed to get color_space\n"); + return AVERROR_EXTERNAL; + } + switch(color_space) { + case XEVD_CS_YCBCR400_10LE: + avctx->pix_fmt = AV_PIX_FMT_GRAY10LE; + break; + case XEVD_CS_YCBCR420_10LE: + avctx->pix_fmt = AV_PIX_FMT_YUV420P10LE; + break; + case XEVD_CS_YCBCR422_10LE: + avctx->pix_fmt = AV_PIX_FMT_YUV422P10LE; + break; + case XEVD_CS_YCBCR444_10LE: + avctx->pix_fmt = AV_PIX_FMT_YUV444P10LE; + break; + default: + av_log(avctx, AV_LOG_ERROR, "Unknown color space\n"); + avctx->pix_fmt = AV_PIX_FMT_NONE; + return AVERROR_INVALIDDATA; + } + + // the function returns sps->num_reorder_pics + ret = xevd_config(xectx->id, XEVD_CFG_GET_MAX_CODING_DELAY, &avctx->max_b_frames, &size); + if (XEVD_FAILED(ret)) { + av_log(avctx, AV_LOG_ERROR, "Failed to get max_coding_delay\n"); + return AVERROR_EXTERNAL; + } + + avctx->has_b_frames = (avctx->max_b_frames) ? 1 : 0; + + return 0; +} + +/** + * @brief Copy image in imgb to frame. + * + * @param avctx codec context + * @param[in] imgb + * @param[out] frame + * @return 0 on success, negative value on failure + */ +static int libxevd_image_copy(struct AVCodecContext *avctx, XEVD_IMGB *imgb, struct AVFrame *frame) +{ + int ret; + if (imgb->cs != XEVD_CS_YCBCR420_10LE) { + av_log(avctx, AV_LOG_ERROR, "Not supported pixel format: %s\n", av_get_pix_fmt_name(avctx->pix_fmt)); + return AVERROR_INVALIDDATA; + } + + if (imgb->w[0] != avctx->width || imgb->h[0] != avctx->height) { // stream resolution changed + if (ff_set_dimensions(avctx, imgb->w[0], imgb->h[0]) < 0) { + av_log(avctx, AV_LOG_ERROR, "Cannot set new dimension\n"); + return AVERROR_INVALIDDATA; + } + } + + if (ret = ff_get_buffer(avctx, frame, 0) < 0) + return ret; + + av_image_copy(frame->data, frame->linesize, (const uint8_t **)imgb->a, + imgb->s, avctx->pix_fmt, + imgb->w[0], imgb->h[0]); + + return 0; +} + +/** + * Initialize decoder + * Create a decoder instance and allocate all the needed resources + * + * @param avctx codec context + * @return 0 on success, negative error code on failure + */ +static av_cold int libxevd_init(AVCodecContext *avctx) +{ + XevdContext *xectx = avctx->priv_data; + XEVD_CDSC *cdsc = &(xectx->cdsc); + + /* read configurations and set values for created descriptor (XEVD_CDSC) */ + get_conf(avctx, cdsc); + + /* create decoder */ + xectx->id = xevd_create(&(xectx->cdsc), NULL); + if (xectx->id == NULL) { + av_log(avctx, AV_LOG_ERROR, "Cannot create XEVD encoder\n"); + return AVERROR_EXTERNAL; + } + + xectx->draining_mode = 0; + + return 0; +} + +/** + * Decode frame with decoupled packet/frame dataflow + * + * @param avctx codec context + * @param[out] frame decoded frame + * + * @return 0 on success, negative error code on failure + */ +static int libxevd_receive_frame(AVCodecContext *avctx, AVFrame *frame) +{ + XevdContext *xectx = NULL; + AVPacket *pkt = NULL; + XEVD_IMGB *imgb = NULL; + + int xevd_ret = 0; + int ret = 0; + + xectx = avctx->priv_data; + + pkt = av_packet_alloc(); + if (!pkt) + return AVERROR(ENOMEM); + + // obtain input data + ret = ff_decode_get_packet(avctx, pkt); + if (ret < 0 && ret != AVERROR_EOF) { + av_packet_free(&pkt); + return ret; + } else if(ret == AVERROR_EOF && xectx->draining_mode == 0) { // End of stream situations. Enter draining mode + + frame = NULL; + xectx->draining_mode = 1; + + av_packet_free(&pkt); + + return AVERROR_EOF; + } + + if (pkt->size > 0) { + int bs_read_pos = 0; + XEVD_STAT stat; + XEVD_BITB bitb; + int nalu_size; + + imgb = NULL; + + while(pkt->size > (bs_read_pos + XEVD_NAL_UNIT_LENGTH_BYTE)) { + memset(&stat, 0, sizeof(XEVD_STAT)); + + nalu_size = read_nal_unit_length(pkt->data + bs_read_pos, XEVD_NAL_UNIT_LENGTH_BYTE, avctx); + if (nalu_size == 0) { + av_log(avctx, AV_LOG_ERROR, "Invalid bitstream\n"); + av_packet_free(&pkt); + ret = AVERROR_INVALIDDATA; + return ret; + } + bs_read_pos += XEVD_NAL_UNIT_LENGTH_BYTE; + + bitb.addr = pkt->data + bs_read_pos; + bitb.ssize = nalu_size; + + /* main decoding block */ + xevd_ret = xevd_decode(xectx->id, &bitb, &stat); + if (XEVD_FAILED(xevd_ret)) { + av_log(avctx, AV_LOG_ERROR, "Failed to decode bitstream\n"); + av_packet_free(&pkt); + ret = AVERROR_EXTERNAL; + return ret; + } + + bs_read_pos += nalu_size; + + if (stat.nalu_type == XEVD_NUT_SPS) { // EVC stream parameters changed + if ((ret = export_stream_params(xectx, avctx)) != 0) { + av_log(avctx, AV_LOG_ERROR, "Failed to export stream params\n"); + av_packet_free(&pkt); + return ret; + } + } + if (stat.read != nalu_size) + av_log(avctx, AV_LOG_INFO, "Different reading of bitstream (in:%d, read:%d)\n,", nalu_size, stat.read); + if (stat.fnum >= 0) { + // already has a decoded image + if (imgb) { + // xevd_pull uses pool of objects of type XEVD_IMGB. + // The pool size is equal MAX_PB_SIZE (26), so release object when it is no more needed + imgb->release(imgb); + imgb = NULL; + } + xevd_ret = xevd_pull(xectx->id, &imgb); + if (XEVD_FAILED(xevd_ret)) { + av_log(avctx, AV_LOG_ERROR, "Failed to pull the decoded image (xevd error code: %d, frame#=%d)\n", xevd_ret, stat.fnum); + ret = AVERROR_EXTERNAL; + av_packet_free(&pkt); + + return ret; + } else if (xevd_ret == XEVD_OK_FRM_DELAYED) { + if (imgb) { + // xevd_pull uses pool of objects of type XEVD_IMGB. + // The pool size is equal MAX_PB_SIZE (26), so release object when it is no more needed + imgb->release(imgb); + imgb = NULL; + } + av_packet_free(&pkt); + + return AVERROR(EAGAIN); + } + if (imgb) { // got frame + int ret = libxevd_image_copy(avctx, imgb, frame); + if(ret < 0) { + av_log(avctx, AV_LOG_ERROR, "Image copying error\n"); + if (imgb) { + imgb->release(imgb); + imgb = NULL; + } + av_packet_free(&pkt); + + return ret; + } + + // use ff_decode_frame_props() to fill frame properties + ret = ff_decode_frame_props(avctx, frame); + if (ret < 0) { + if (imgb) { + imgb->release(imgb); + imgb = NULL; + } + av_packet_free(&pkt); + av_frame_unref(frame); + + return ret; + } + // match timestamps and packet size + ret = ff_decode_frame_props_from_pkt(avctx, frame, pkt); + pkt->opaque = NULL; + if (ret < 0) { + if (imgb) { + imgb->release(imgb); + imgb = NULL; + } + av_packet_free(&pkt); + av_frame_unref(frame); + + return ret; + } + + frame->pkt_dts = pkt->dts; + + // xevd_pull uses pool of objects of type XEVD_IMGB. + // The pool size is equal MAX_PB_SIZE (26), so release object when it is no more needed + imgb->release(imgb); + imgb = NULL; + + return 0; + } else + return AVERROR(EAGAIN); + } + } + } else { // decoder draining mode handling + xevd_ret = xevd_pull(xectx->id, &imgb); + if (xevd_ret == XEVD_ERR_UNEXPECTED) // draining process completed + return AVERROR_EOF; + else if (XEVD_FAILED(xevd_ret)) { + av_log(avctx, AV_LOG_ERROR, "Failed to pull the decoded image (xevd error code: %d)\n", xevd_ret); + + if (imgb) { + imgb->release(imgb); + imgb = NULL; + } + + av_packet_free(&pkt); + + return AVERROR_EXTERNAL; + } + if (imgb) { // got frame + int ret = libxevd_image_copy(avctx, imgb, frame); + if(ret < 0) { + if (imgb) { + imgb->release(imgb); + imgb = NULL; + } + av_packet_free(&pkt); + } + + frame->pkt_dts = pkt->dts; + + // xevd_pull uses pool of objects of type XEVD_IMGB. + // The pool size is equal MAX_PB_SIZE (26), so release object when it is no more needed + imgb->release(imgb); + imgb = NULL; + + return 0; + } + return AVERROR_EOF; + } + return ret; +} + +/** + * Destroy decoder + * + * @param avctx codec context + * @return 0 on success + */ +static av_cold int libxevd_close(AVCodecContext *avctx) +{ + XevdContext *xectx = avctx->priv_data; + if (xectx->id) { + xevd_delete(xectx->id); + xectx->id = NULL; + } + + xectx->draining_mode = 0; + + return 0; +} + +#define OFFSET(x) offsetof(XevdContext, x) +#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM + +static const AVClass libxevd_class = { + .class_name = "libxevd", + .item_name = av_default_item_name, + .version = LIBAVUTIL_VERSION_INT, +}; + +const FFCodec ff_libxevd_decoder = { + .p.name = "evc", + .p.long_name = NULL_IF_CONFIG_SMALL("EVC / MPEG-5 Essential Video Coding (EVC)"), + .p.type = AVMEDIA_TYPE_VIDEO, + .p.id = AV_CODEC_ID_EVC, + .init = libxevd_init, + FF_CODEC_RECEIVE_FRAME_CB(libxevd_receive_frame), + .close = libxevd_close, + .priv_data_size = sizeof(XevdContext), + .p.priv_class = &libxevd_class, + .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS | AV_CODEC_CAP_AVOID_PROBING, + .p.profiles = NULL_IF_CONFIG_SMALL(ff_evc_profiles), + .p.wrapper_name = "libxevd", + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_NOT_INIT_THREADSAFE | FF_CODEC_CAP_SETS_PKT_DTS | FF_CODEC_CAP_SETS_FRAME_PROPS +}; From patchwork Mon Mar 27 10:49:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawid Kozinski X-Patchwork-Id: 40867 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp1221242pzh; Mon, 27 Mar 2023 03:49:32 -0700 (PDT) X-Google-Smtp-Source: AKy350bS51SstlPY4WWHDqjg40D+31th2yU4nbwthX6wIt7+BnDhKQkcXvDZTo4pgW7VztG7AY6O X-Received: by 2002:a17:907:1628:b0:88f:8a5:b4cd with SMTP id hb40-20020a170907162800b0088f08a5b4cdmr15457289ejc.1.1679914171796; Mon, 27 Mar 2023 03:49:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679914171; cv=none; d=google.com; s=arc-20160816; b=zE0WwaTOiSipJ+ND7XV14XjmEUnlBuVricthfI/XN4m0EDX1qn+qo6u2mr7E5kRF8K Y4WdbIN5YQBa83v+p9J08UfJEo5jYFsqvb1uIBIQ67gm7wa4D2OZL5ggKSnW2Z/3mMBh yZxP2lU+rGXLgWbCIRGI0znlaTnCXpduhLaRj7/cJJgLIqzVmoqYBLBi5bmcDfYPdz30 BDM2jHUMKt1KGWBnOWjShJiDAjxh56HWI1oyJcYsrIKQwkR5W3Gu1P+TV8f8m0FNCPE0 HC1cgDLyNpAArrTATH2tER91Wg+eUjb/MjKwpdLDxLSncL/z36/fL2l7/F3WC8Ke1WJR IUgQ== 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=ClxnDQHgOBhPAZpcnLLoHi5TcJ0FydwQiIFbqZUHqqU=; b=rikxC/6B6ti83vm+RMW2ObQzprCG4hLZ5t3WbF8x6Uwhjh2dp2d+NwWdlZfMtvR2Tg 06EcbpLaSi01nuGH0pQ38X/mSjQkSo53Y59savJuRNeh9OOR44hYVP/vyEGdCdK0MxIX uY8h2/SrIrzbeKX0/oEslFCLVjM1sK2yRp/nyiOCu3NI9Aspbb7PAsODVgeUvH96cQML j1QFY8aR9/94luNfEV3lZXFruBY/ZXxmFQ+lpls/zSD2nCkP0ErLQXblWnlhTzdYRYbw yQ2J7Hhi1uuJRphbmsHnGQr+F0hv4wYQ2hfLllg/JGDyJDQZ9YyvnEhf3sbC9Ub3/JNi Mt7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b="TZyM0/hH"; 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 cr2-20020a170906d54200b008d6d20d1920si27597807ejc.35.2023.03.27.03.49.31; Mon, 27 Mar 2023 03:49:31 -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=@samsung.com header.s=mail20170921 header.b="TZyM0/hH"; 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 5749A68CAC6; Mon, 27 Mar 2023 13:49:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3647468C927 for ; Mon, 27 Mar 2023 13:49:24 +0300 (EEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230327104923euoutp01122187c2216394545ad12460e3933ebb~QQQgByGoE1420014200euoutp01E for ; Mon, 27 Mar 2023 10:49:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230327104923euoutp01122187c2216394545ad12460e3933ebb~QQQgByGoE1420014200euoutp01E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1679914163; bh=IJ+kLxkOh8G0JeMTfZBlq+LjJ2JeKkTICULSpS9/Nv4=; h=From:To:Cc:Subject:Date:References:From; b=TZyM0/hHORVPSAP8DoFTEzzOVNrxrrWGhX5mjOuPzUHjdYnyNBY3tkguyeBy6yVHA NWkTO6NSdt9B5oqjisAPWrV1Vpcwbcv0Ez1XxG8E5mJCLEaa109oPjSKjcSW1cNGVZ nQZV4mGNVqnfPSEpm0usz23P4Salth1lBMoo5IGA= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230327104923eucas1p173dc683331eac42f748b2a7f9341c842~QQQfxkzKv1871518715eucas1p11; Mon, 27 Mar 2023 10:49:23 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id E4.9D.09966.3B471246; Mon, 27 Mar 2023 11:49:23 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230327104922eucas1p27670846a9a9cd8d7482db4bc9499baf1~QQQfWwWTJ0085000850eucas1p2f; Mon, 27 Mar 2023 10:49:22 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230327104922eusmtrp1bbe527b8c24323afedc1bed9a247e675~QQQfV9pd11273712737eusmtrp1A; Mon, 27 Mar 2023 10:49:22 +0000 (GMT) X-AuditID: cbfec7f4-d4fff700000026ee-f2-642174b39063 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 4B.EA.08862.2B471246; Mon, 27 Mar 2023 11:49:22 +0100 (BST) Received: from AMDN5164.EU.corp.samsungelectronics.net (unknown [106.210.132.171]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230327104922eusmtip27669e60ea88b1066d19df60af37734d0~QQQe9ao-K1211012110eusmtip2S; Mon, 27 Mar 2023 10:49:22 +0000 (GMT) From: Dawid Kozinski To: d.frankiewic@samsung.com, ffmpeg-devel@ffmpeg.org Date: Mon, 27 Mar 2023 12:49:11 +0200 Message-Id: <20230327104911.190-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+NgFnrHIsWRmVeSWpSXmKPExsWy7djPc7qbSxRTDP6vFrT4cu0Ls8XKb79Z LL59OsPswOzxZ9FmFo++LasYA5iiuGxSUnMyy1KL9O0SuDLO/NjKXnB8F2PFgu+72RsYJ3Yw djFyckgImEgs33afuYuRi0NIYAWjxOqt0xghnC+MEu/nnmGBcD4zSvT+2cEG0/Lz5VVWiMRy RolHv44yQTjtTBKf1jwGG8wmoCvx8sMjJhBbRMBU4mTzXrBuZgFtiXV3v4PZwgKxEuc3nGMG sVkEVCWmHesAi/MKWEpcOPKJFWKbpsSELXOYIOKCEidnPmGBiHNLrJt1iRViprxE89bZYE9I CPxll1jX/Y0ZoshF4uuMB1CfCku8Or6FHcKWkTg9uQdoEAeQXSxxqN8BwqyROPQjHaLCWuJt 43FGkDAz0Anrd+lDhB0lLrV1MUNU80nceCsIcQCfxKRt06HCvBIdbUIQpopEX6cYRKOUxNNl c6Cu8pD4NW0l6wRGxVlIvpqF5JNZCGsXMDKvYhRPLS3OTU8tNspLLdcrTswtLs1L10vOz93E CEwSp/8d/7KDcfmrj3qHGJk4GA8xSnAwK4nwbvZWTBHiTUmsrEotyo8vKs1JLT7EKM3BoiTO q217MllIID2xJDU7NbUgtQgmy8TBKdXAFK2wZsVOW64zynvE/l74ffb03O8ufrGTU75LhC45 vJ4l8iND+Te7Aq6u8PT0nSVFJccWJ8y7O+mdgcq5zT6hUr3uLyLl2lKvXLzDrVF9ZXa70K6F B35zT3h6yUAjtbCdUXaqfnH+ybf//6Qvqhd+yt18wWDRgyvfl91Qy9haFvd/Tt2eHf6VLZmZ 1vcWrEhwZdj6sDQ6VOqb41xbv5KAKSG/VE7FFC/eyd7QIswUqajBum/r+pXJlldKnyQui7ua LsZUJjdnkWyoQqCfUmi3bcuiA1NSHXudcmI3vfxh3XGzqLtyNmuLhKbRtQ9CvSza59ObQnnf /dqW1W8/Y5u8IGehcK6DZPAhqQdr3G8osRRnJBpqMRcVJwIAEMa2BIEDAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrCLMWRmVeSWpSXmKPExsVy+t/xe7qbShRTDHo3GFp8ufaF2WLlt98s Ft8+nWF2YPb4s2gzi0ffllWMAUxRejZF+aUlqQoZ+cUltkrRhhZGeoaWFnpGJpZ6hsbmsVZG pkr6djYpqTmZZalF+nYJehlnfmxlLzi+i7Fiwffd7A2MEzsYuxg5OSQETCR+vrzK2sXIxSEk sJRRYn/HXRaIhJTE0qWLoIqEJf5c62KDKGplkjh64AobSIJNQFfi5YdHTCC2iIC5xMV1t8Aa mAW0Jdbd/Q5WIywQLXHy9hdWEJtFQFVi2rEOsDivgKXEhSOfWCEWaEpM2DKHCSIuKHFy5hOo I7gl1s26xAoxU16ieets5gmM/LOQlM1CklrAyLSKUSS1tDg3PbfYUK84Mbe4NC9dLzk/dxMj MHi3Hfu5eQfjvFcf9Q4xMnEwHmKU4GBWEuHd7K2YIsSbklhZlVqUH19UmpNafIjRFOjWicxS osn5wPjJK4k3NDMwNTQxszQwtTQzVhLn9SzoSBQSSE8sSc1OTS1ILYLpY+LglGpgkujjEPxw Wn55wLkGiStsR3U9Bbd3Om3VKxPyuL/z18dT9zc/CFnnLzbFjOfR1f+3RZo2Xwy+xKSwsVzU yWh6kli6JZvo1PYrR248azx+6+pdt3PbXjwqTay8H/UgeEtWQtennUmf997ftPa1z+S1tzZc f8Vd1BI/08YxSFVugtehNcK/1aZmlN1fU146K2J6W/j+vsaw+vwHsybIenZu/xBh0VrJt9Q4 N9EgfNef07uvP2+7vuwcQ+aHlxenuR997Vgxb7GA4JvKfalpPH8yZadVBN6Pj9746viX1vvh a54tP/31r3D5DoO3Ir+z+UR8T9W9q+sLPO+tUs4iMVOT/dyDeJtTTAsrbgba3lvtvlWJpTgj 0VCLuag4EQDF19Yu5wIAAA== X-CMS-MailID: 20230327104922eucas1p27670846a9a9cd8d7482db4bc9499baf1 X-Msg-Generator: CA X-RootMTR: 20230327104922eucas1p27670846a9a9cd8d7482db4bc9499baf1 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230327104922eucas1p27670846a9a9cd8d7482db4bc9499baf1 References: Subject: [FFmpeg-devel] [PATCH v17 7/9] avformat/mov_muxer: Extended MOV muxer to handle EVC video content 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: y0dbbFxP7vcm - Changes in mov_write_video_tag function to handle EVC elementary stream - Provided structure EVCDecoderConfigurationRecord that specifies the decoder configuration information for ISO/IEC 23094-1 video content --- libavformat/Makefile | 2 +- libavformat/evc.c | 455 ++++++++++++++++++++++++++++++++++++++++ libavformat/evc.h | 44 ++++ libavformat/isom_tags.c | 2 + libavformat/movenc.c | 33 +++ 5 files changed, 535 insertions(+), 1 deletion(-) create mode 100644 libavformat/evc.c create mode 100644 libavformat/evc.h diff --git a/libavformat/Makefile b/libavformat/Makefile index d80e5dc6b3..77e11aef84 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -363,7 +363,7 @@ OBJS-$(CONFIG_MOV_DEMUXER) += mov.o mov_chan.o mov_esds.o \ OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o vpcc.o \ movenchint.o mov_chan.o rtp.o \ movenccenc.o movenc_ttml.o rawutils.o \ - dovi_isom.o + dovi_isom.o evc.o OBJS-$(CONFIG_MP2_MUXER) += rawenc.o OBJS-$(CONFIG_MP3_DEMUXER) += mp3dec.o replaygain.o OBJS-$(CONFIG_MP3_MUXER) += mp3enc.o rawenc.o id3v2enc.o diff --git a/libavformat/evc.c b/libavformat/evc.c new file mode 100644 index 0000000000..9a3daba04a --- /dev/null +++ b/libavformat/evc.c @@ -0,0 +1,455 @@ +/* + * EVC helper functions for muxers + * Copyright (c) 2022 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 "libavutil/intreadwrite.h" +#include "libavcodec/get_bits.h" +#include "libavcodec/golomb.h" +#include "libavcodec/evc.h" +#include "avformat.h" +#include "avio.h" +#include "evc.h" +#include "avio_internal.h" + +// The length field that indicates the length in bytes of the following NAL unit is configured to be of 4 bytes +#define EVC_NALU_LENGTH_PREFIX_SIZE (4) /* byte */ +#define EVC_NALU_HEADER_SIZE (2) /* byte */ + +// @see ISO/IEC 14496-15:2021 Coding of audio-visual objects - Part 15: section 12.3.3.1 +enum { + SPS_INDEX, + PPS_INDEX, + APS_INDEX, + SEI_INDEX, + NB_ARRAYS +}; + +// rpl structure +typedef struct RefPicListStruct { + int poc; + int tid; + int ref_pic_num; + int ref_pic_active_num; + int ref_pics[EVC_MAX_NUM_REF_PICS]; + char pic_type; + +} RefPicListStruct; + +// The sturcture reflects SPS RBSP(raw byte sequence payload) layout +// @see ISO_IEC_23094-1 section 7.3.2.1 +// +// The following descriptors specify the parsing process of each element +// u(n) - unsigned integer using n bits +// ue(v) - unsigned integer 0-th order Exp_Golomb-coded syntax element with the left bit first +typedef struct EVCSPS { + int sps_seq_parameter_set_id; // ue(v) + int profile_idc; // u(8) + int level_idc; // u(8) + int toolset_idc_h; // u(32) + int toolset_idc_l; // u(32) + int chroma_format_idc; // ue(v) + int pic_width_in_luma_samples; // ue(v) + int pic_height_in_luma_samples; // ue(v) + int bit_depth_luma_minus8; // ue(v) + int bit_depth_chroma_minus8; // ue(v) + + // @note + // Currently the structure does not reflect the entire SPS RBSP layout. + // It contains only the fields that are necessary to read from the NAL unit all the values + // necessary for the correct initialization of EVCDecoderConfigurationRecord + + // @note + // If necessary, add the missing fields to the structure to reflect + // the contents of the entire NAL unit of the SPS type + +} EVCSPS; + +// @see ISO/IEC 14496-15:2021 Coding of audio-visual objects - Part 15: section 12.3.3.3 +typedef struct EVCNALUnitArray { + uint8_t array_completeness; // when equal to 1 indicates that all NAL units of the given type are in the following array + uint8_t NAL_unit_type; // indicates the type of the NAL units in the following array + uint16_t numNalus; // indicates the number of NAL units of the indicated type + uint16_t *nalUnitLength; // indicates the length in bytes of the NAL unit + uint8_t **nalUnit; // contains an SPS, PPS, APS or a SEI NAL unit, as specified in ISO/IEC 23094-1 +} EVCNALUnitArray; + +/** + * @brief Specifies the decoder configuration information for ISO/IEC 23094-1 video content. + * @see ISO/IEC 14496-15:2021 Coding of audio-visual objects - Part 15: section 12.3.3.2 + * Carriage of network abstraction layer (NAL) unit structured video in the ISO base media file format + */ +typedef struct EVCDecoderConfigurationRecord { + uint8_t configurationVersion; // 8 bits + uint8_t profile_idc; // 8 bits + uint8_t level_idc; // 8 bits + uint32_t toolset_idc_h; // 32 bits + uint32_t toolset_idc_l; // 32 bits + uint8_t chroma_format_idc; // 2 bits + uint8_t bit_depth_luma_minus8; // 3 bits + uint8_t bit_depth_chroma_minus8; // 3 bits + uint16_t pic_width_in_luma_samples; // 16 bits + uint16_t pic_height_in_luma_samples; // 16 bits + uint8_t reserved; // 6 bits '000000'b + uint8_t lengthSizeMinusOne; // 2 bits + uint8_t num_of_arrays; // 8 bits + EVCNALUnitArray arrays[NB_ARRAYS]; +} EVCDecoderConfigurationRecord; + +typedef struct NALU { + int offset; + uint32_t size; +} NALU; + +typedef struct NALUList { + NALU *nalus; + unsigned nalus_array_size; + unsigned nb_nalus; ///< valid entries in nalus +} NALUList; + +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) + 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; + for (int i = 0; i < EVC_NALU_LENGTH_PREFIX_SIZE; i++) + t = (t << 8) | bits[i]; + + nalu_len = t; + if (nalu_len == 0) + return 0; + } + + return nalu_len; +} + +// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax) +static int evcc_parse_sps(const uint8_t *bs, int bs_size, EVCDecoderConfigurationRecord *evcc) +{ + GetBitContext gb; + int sps_seq_parameter_set_id; + EVCSPS sps; + + if (init_get_bits8(&gb, bs, bs_size) < 0) + return 0; + + sps.sps_seq_parameter_set_id = get_ue_golomb(&gb); + + if (sps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT) + return 0; + + // the Baseline profile is indicated by profile_idc eqal to 0 + // the Main profile is indicated by profile_idc eqal to 1 + sps.profile_idc = get_bits(&gb, 8); + + sps.level_idc = get_bits(&gb, 8); + + sps.toolset_idc_h = get_bits(&gb, 32); + sps.toolset_idc_l = get_bits(&gb, 32); + + // 0 - monochrome + // 1 - 4:2:0 + // 2 - 4:2:2 + // 3 - 4:4:4 + sps.chroma_format_idc = get_ue_golomb(&gb); + + sps.pic_width_in_luma_samples = get_ue_golomb(&gb); + sps.pic_height_in_luma_samples = get_ue_golomb(&gb); + + sps.bit_depth_luma_minus8 = get_ue_golomb(&gb); + sps.bit_depth_chroma_minus8 = get_ue_golomb(&gb); + + evcc->profile_idc = sps.profile_idc; + evcc->level_idc = sps.level_idc; + evcc->toolset_idc_h = sps.toolset_idc_h; + evcc->toolset_idc_l = sps.toolset_idc_l; + evcc->chroma_format_idc = sps.chroma_format_idc; + evcc->bit_depth_luma_minus8 = sps.bit_depth_luma_minus8; + evcc->bit_depth_chroma_minus8 = sps.bit_depth_chroma_minus8; + evcc->pic_width_in_luma_samples = sps.pic_width_in_luma_samples; + evcc->pic_height_in_luma_samples = sps.pic_height_in_luma_samples; + + return 0; +} + +// @see ISO/IEC 14496-15:2021 Coding of audio-visual objects - Part 15: section 12.3.3.3 +static int evcc_array_add_nal_unit(const uint8_t *nal_buf, uint32_t nal_size, + uint8_t nal_type, int ps_array_completeness, + EVCNALUnitArray *array) +{ + int ret; + uint16_t numNalus = array->numNalus; + + ret = av_reallocp_array(&array->nalUnit, numNalus + 1, sizeof(uint8_t *)); + if (ret < 0) + return ret; + + ret = av_reallocp_array(&array->nalUnitLength, numNalus + 1, sizeof(uint16_t)); + if (ret < 0) + return ret; + + array->nalUnit [numNalus] = (uint8_t *)nal_buf; + array->nalUnitLength[numNalus] = nal_size; + array->NAL_unit_type = nal_type; + array->numNalus++; + + /* + * When the sample entry name is 'evc1', the default and mandatory value of + * array_completeness is 1 for arrays of all types of parameter sets, and 0 + * for all other arrays. + */ + if (nal_type == EVC_SPS_NUT || nal_type == EVC_PPS_NUT || nal_type == EVC_APS_NUT) + array->array_completeness = ps_array_completeness; + + return 0; +} + +static void evcc_init(EVCDecoderConfigurationRecord *evcc) +{ + memset(evcc, 0, sizeof(EVCDecoderConfigurationRecord)); + evcc->configurationVersion = 1; + evcc->lengthSizeMinusOne = 3; // 4 bytes +} + +static void evcc_close(EVCDecoderConfigurationRecord *evcc) +{ + for (unsigned i = 0; i < FF_ARRAY_ELEMS(evcc->arrays); i++) { + EVCNALUnitArray *const array = &evcc->arrays[i]; + array->numNalus = 0; + av_freep(&array->nalUnit); + av_freep(&array->nalUnitLength); + } +} + +static int evcc_write(AVIOContext *pb, EVCDecoderConfigurationRecord *evcc) +{ + uint16_t sps_count; + + av_log(NULL, AV_LOG_TRACE, "configurationVersion: %"PRIu8"\n", + evcc->configurationVersion); + av_log(NULL, AV_LOG_TRACE, "profile_idc: %"PRIu8"\n", + evcc->profile_idc); + av_log(NULL, AV_LOG_TRACE, "level_idc: %"PRIu8"\n", + evcc->level_idc); + av_log(NULL, AV_LOG_TRACE, "toolset_idc_h: %"PRIu32"\n", + evcc->toolset_idc_h); + av_log(NULL, AV_LOG_TRACE, "toolset_idc_l: %"PRIu32"\n", + evcc->toolset_idc_l); + av_log(NULL, AV_LOG_TRACE, "chroma_format_idc: %"PRIu8"\n", + evcc->chroma_format_idc); + av_log(NULL, AV_LOG_TRACE, "bit_depth_luma_minus8: %"PRIu8"\n", + evcc->bit_depth_luma_minus8); + av_log(NULL, AV_LOG_TRACE, "bit_depth_chroma_minus8: %"PRIu8"\n", + evcc->bit_depth_chroma_minus8); + av_log(NULL, AV_LOG_TRACE, "pic_width_in_luma_samples: %"PRIu16"\n", + evcc->pic_width_in_luma_samples); + av_log(NULL, AV_LOG_TRACE, "pic_height_in_luma_samples: %"PRIu16"\n", + evcc->pic_height_in_luma_samples); + av_log(NULL, AV_LOG_TRACE, "lengthSizeMinusOne: %"PRIu8"\n", + evcc->lengthSizeMinusOne); + av_log(NULL, AV_LOG_TRACE, "num_of_arrays: %"PRIu8"\n", + evcc->num_of_arrays); + for (unsigned i = 0; i < FF_ARRAY_ELEMS(evcc->arrays); i++) { + const EVCNALUnitArray *const array = &evcc->arrays[i]; + + if(array->numNalus == 0) + continue; + + av_log(NULL, AV_LOG_TRACE, "array_completeness[%"PRIu8"]: %"PRIu8"\n", + i, array->array_completeness); + av_log(NULL, AV_LOG_TRACE, "NAL_unit_type[%"PRIu8"]: %"PRIu8"\n", + i, array->NAL_unit_type); + av_log(NULL, AV_LOG_TRACE, "numNalus[%"PRIu8"]: %"PRIu16"\n", + i, array->numNalus); + for ( unsigned j = 0; j < array->numNalus; j++) + av_log(NULL, AV_LOG_TRACE, + "nalUnitLength[%"PRIu8"][%"PRIu16"]: %"PRIu16"\n", + i, j, array->nalUnitLength[j]); + } + + /* + * We need at least one SPS. + */ + sps_count = evcc->arrays[SPS_INDEX].numNalus; + if (!sps_count || sps_count > EVC_MAX_SPS_COUNT) + return AVERROR_INVALIDDATA; + + if (!sps_count || sps_count > EVC_MAX_SPS_COUNT) + return AVERROR_INVALIDDATA; + + /* unsigned int(8) configurationVersion = 1; */ + avio_w8(pb, evcc->configurationVersion); + + /* unsigned int(8) profile_idc */ + avio_w8(pb, evcc->profile_idc); + + /* unsigned int(8) profile_idc */ + avio_w8(pb, evcc->level_idc); + + /* unsigned int(32) toolset_idc_h */ + avio_wb32(pb, evcc->toolset_idc_h); + + /* unsigned int(32) toolset_idc_l */ + avio_wb32(pb, evcc->toolset_idc_l); + + /* + * unsigned int(2) chroma_format_idc; + * unsigned int(3) bit_depth_luma_minus8; + * unsigned int(3) bit_depth_chroma_minus8; + */ + avio_w8(pb, evcc->chroma_format_idc << 6 | + evcc->bit_depth_luma_minus8 << 3 | + evcc->bit_depth_chroma_minus8); + + /* unsigned int(16) pic_width_in_luma_samples; */ + avio_wb16(pb, evcc->pic_width_in_luma_samples); + + /* unsigned int(16) pic_width_in_luma_samples; */ + avio_wb16(pb, evcc->pic_height_in_luma_samples); + + /* + * bit(6) reserved = '111111'b; + * unsigned int(2) chromaFormat; + */ + avio_w8(pb, evcc->lengthSizeMinusOne | 0xfc); + + /* unsigned int(8) numOfArrays; */ + avio_w8(pb, evcc->num_of_arrays); + + for (unsigned i = 0; i < FF_ARRAY_ELEMS(evcc->arrays); i++) { + const EVCNALUnitArray *const array = &evcc->arrays[i]; + + if (!array->numNalus) + continue; + + /* + * bit(1) array_completeness; + * unsigned int(1) reserved = 0; + * unsigned int(6) NAL_unit_type; + */ + avio_w8(pb, array->array_completeness << 7 | + array->NAL_unit_type & 0x3f); + + /* unsigned int(16) numNalus; */ + avio_wb16(pb, array->numNalus); + + for (unsigned j = 0; j < array->numNalus; j++) { + /* unsigned int(16) nalUnitLength; */ + avio_wb16(pb, array->nalUnitLength[j]); + + /* bit(8*nalUnitLength) nalUnit; */ + avio_write(pb, array->nalUnit[j], + array->nalUnitLength[j]); + } + } + + return 0; +} + +int ff_isom_write_evcc(AVIOContext *pb, const uint8_t *data, + int size, int ps_array_completeness) +{ + EVCDecoderConfigurationRecord evcc; + int nalu_type; + size_t nalu_size; + int bytes_to_read = size; + unsigned array_index; + + int ret = 0; + + if (size < 8) { + /* We can't write a valid evcC from the provided data */ + return AVERROR_INVALIDDATA; + } else if (*data == 1) { + /* Data is already evcC-formatted */ + avio_write(pb, data, size); + return 0; + } + + evcc_init(&evcc); + + while (bytes_to_read > EVC_NALU_LENGTH_PREFIX_SIZE) { + nalu_size = read_nal_unit_length(data, EVC_NALU_LENGTH_PREFIX_SIZE); + if (nalu_size == 0) break; + + data += 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(data, bytes_to_read); + + switch (nalu_type) { + case EVC_SPS_NUT: + array_index = SPS_INDEX; + break; + case EVC_PPS_NUT: + array_index = PPS_INDEX; + break; + case EVC_APS_NUT: + array_index = APS_INDEX; + break; + case EVC_SEI_NUT: + array_index = SEI_INDEX; + break; + default: + break; + } + + ret = evcc_array_add_nal_unit(data, nalu_size, nalu_type, ps_array_completeness, &(evcc.arrays[array_index])); + if (ret < 0) + goto end; + if (evcc.arrays[array_index].numNalus == 1) + evcc.num_of_arrays++; + + if(nalu_type == EVC_SPS_NUT) { + ret = evcc_parse_sps(data, nalu_size, &evcc); + if (ret < 0) + goto end; + } + + data += nalu_size; + bytes_to_read -= nalu_size; + } + + ret = evcc_write(pb, &evcc); + +end: + evcc_close(&evcc); + return ret; +} diff --git a/libavformat/evc.h b/libavformat/evc.h new file mode 100644 index 0000000000..db56275fd8 --- /dev/null +++ b/libavformat/evc.h @@ -0,0 +1,44 @@ +/* + * EVC helper functions for muxers + * Copyright (c) 2022 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 + */ + +#ifndef AVFORMAT_EVC_H +#define AVFORMAT_EVC_H + +#include +#include "libavutil/rational.h" +#include "avio.h" + + + +/** + * Writes EVC sample metadata to the provided AVIOContext. + * + * @param pb pointer to the AVIOContext where the evc sample metadata shall be written + * @param buf input data buffer + * @param size size in bytes of the input data buffer + * @param ps_array_completeness @see ISO/IEC 14496-15:2021 Coding of audio-visual objects - Part 15: section 12.3.3.3 + * + * @return 0 in case of success, a negative error code in case of failure + */ +int ff_isom_write_evcc(AVIOContext *pb, const uint8_t *data, + int size, int ps_array_completeness); + +#endif // AVFORMAT_EVC_H diff --git a/libavformat/isom_tags.c b/libavformat/isom_tags.c index 86c7272525..2a29823b2e 100644 --- a/libavformat/isom_tags.c +++ b/libavformat/isom_tags.c @@ -147,6 +147,8 @@ const AVCodecTag ff_codec_movvideo_tags[] = { { AV_CODEC_ID_H264, MKTAG('d', 'v', 'a', '1') }, /* AVC-based Dolby Vision derived from avc1 */ { AV_CODEC_ID_H264, MKTAG('d', 'v', 'a', 'v') }, /* AVC-based Dolby Vision derived from avc3 */ + { AV_CODEC_ID_EVC, MKTAG('e', 'v', 'c', '1') }, /* EVC/MPEG-5 */ + { AV_CODEC_ID_VP8, MKTAG('v', 'p', '0', '8') }, /* VP8 */ { AV_CODEC_ID_VP9, MKTAG('v', 'p', '0', '9') }, /* VP9 */ { AV_CODEC_ID_AV1, MKTAG('a', 'v', '0', '1') }, /* AV1 */ diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 68e7f8222b..94510a4670 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -35,6 +35,7 @@ #include "isom.h" #include "av1.h" #include "avc.h" +#include "evc.h" #include "libavcodec/ac3_parser_internal.h" #include "libavcodec/dnxhddata.h" #include "libavcodec/flac.h" @@ -1455,6 +1456,21 @@ static int mov_write_hvcc_tag(AVIOContext *pb, MOVTrack *track) return update_size(pb, pos); } +static int mov_write_evcc_tag(AVIOContext *pb, MOVTrack *track) +{ + int64_t pos = avio_tell(pb); + + avio_wb32(pb, 0); + ffio_wfourcc(pb, "evcC"); + + if (track->tag == MKTAG('e','v','c','1')) + ff_isom_write_evcc(pb, track->vos_data, track->vos_len, 1); + else + ff_isom_write_evcc(pb, track->vos_data, track->vos_len, 0); + + return update_size(pb, pos); +} + /* also used by all avid codecs (dv, imx, meridien) and their variants */ static int mov_write_avid_tag(AVIOContext *pb, MOVTrack *track) { @@ -1704,6 +1720,16 @@ static int mov_get_h264_codec_tag(AVFormatContext *s, MOVTrack *track) return tag; } +static int mov_get_evc_codec_tag(AVFormatContext *s, MOVTrack *track) +{ + int tag = track->par->codec_tag; + + if (!tag) + tag = MKTAG('e', 'v', 'c', 'i'); + + return tag; +} + static const struct { enum AVPixelFormat pix_fmt; uint32_t tag; @@ -1785,6 +1811,8 @@ static unsigned int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track) tag = mov_get_mpeg2_xdcam_codec_tag(s, track); else if (track->par->codec_id == AV_CODEC_ID_H264) tag = mov_get_h264_codec_tag(s, track); + else if (track->par->codec_id == AV_CODEC_ID_EVC) + tag = mov_get_evc_codec_tag(s, track); else if (track->par->codec_id == AV_CODEC_ID_DNXHD) tag = mov_get_dnxhd_codec_tag(s, track); else if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) { @@ -2352,6 +2380,9 @@ static int mov_write_video_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex mov_write_avcc_tag(pb, track); if (track->mode == MODE_IPOD) mov_write_uuid_tag_ipod(pb); + } + else if (track->par->codec_id ==AV_CODEC_ID_EVC) { + mov_write_evcc_tag(pb, track); } else if (track->par->codec_id == AV_CODEC_ID_VP9) { mov_write_vpcc_tag(mov->fc, pb, track); } else if (track->par->codec_id == AV_CODEC_ID_AV1) { @@ -6123,6 +6154,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_HEVC || par->codec_id == AV_CODEC_ID_VP9 || + par->codec_id == AV_CODEC_ID_EVC || par->codec_id == AV_CODEC_ID_TRUEHD) && !trk->vos_len && !TAG_IS_AVCI(trk->tag)) { /* copy frame to create needed atoms */ @@ -7782,6 +7814,7 @@ static const AVCodecTag codec_mp4_tags[] = { { AV_CODEC_ID_H264, MKTAG('a', 'v', 'c', '3') }, { AV_CODEC_ID_HEVC, MKTAG('h', 'e', 'v', '1') }, { AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1') }, + { AV_CODEC_ID_EVC, MKTAG('e', 'v', 'c', '1') }, { AV_CODEC_ID_MPEG2VIDEO, MKTAG('m', 'p', '4', 'v') }, { AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', '4', 'v') }, { AV_CODEC_ID_MJPEG, MKTAG('m', 'p', '4', 'v') }, From patchwork Mon Mar 27 10:49:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawid Kozinski X-Patchwork-Id: 40865 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp1221425pzh; Mon, 27 Mar 2023 03:49:55 -0700 (PDT) X-Google-Smtp-Source: AKy350YZpxiusZ5LwhcIohCFCYyBkO9SaDpLLAbEu4vjJYJmRvZeC8upZmP3wmPk3lQ8tLaBjM8L X-Received: by 2002:aa7:c98b:0:b0:4fe:9374:30d0 with SMTP id c11-20020aa7c98b000000b004fe937430d0mr10681350edt.39.1679914195508; Mon, 27 Mar 2023 03:49:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679914195; cv=none; d=google.com; s=arc-20160816; b=MVNSgWgoXoPT7J5hil0+SQmpw8k9RSld7eva4frY/cIla3M4Lb7/4SUcwK278nGO6s DYvtfGsg+ldU/9gSJ60HGcPsENfSL7sUFF9d6LfbjYhXyr9d92Jbs+tFi/zNgQdK/E8s +o/j2hEeGEYy+QNqI4IE59Qh1ay/XhJdAHFeuOMAzRcAMsT0UII8RCbc3Gu4weByIke0 MCSBIdi67P40S0kh19IWBIIk5aVRPZOA7AhttReSrJvjDCyK89i2hZWxnE8uwiKb0+4a bqZH4R+zMRfGG5VIRyB9vRpIWQwjQ7yhXKfRtreU3KL3aL3mEK16Io2PoSRkFlmJTU4v OLEA== 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=bFFAdHE12XPRw7vqksyrItcadROyyB12DTxjkQKWxxQ=; b=cpdeOvOMwjLO9G+QQjQEH41k7ZU4CbXub0AahN4NjbGb5GFJ5dx8dIR53Yic/TZqLM gZ3VNmr4lP8ey9GHjMrjHde8ulfZbEAS4QmtXUzfTtFNgnUXF477BcgRHeETRob+7mvl L/hZzLtYBz/JzrYz0vPlyGbusmXptxZKSP1dpXslnQHywsvMrdIBF5XvdChfHAYBFMn+ rcxwLmQW0VYo+9cSWHNBmYLPCrKfnR6KcHXexnd2LSnDVh5jcML4o0cL/o180LQULdks GeAYAc06ceqBY9WelxQShfSH/p6KSN+r4VftynMSm62VW6c8xOAgiUSJBp4J1821WtSg LU2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=DamRiakt; 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 g18-20020a50ee12000000b004fd2a8b4962si27306423eds.132.2023.03.27.03.49.55; Mon, 27 Mar 2023 03:49:55 -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=@samsung.com header.s=mail20170921 header.b=DamRiakt; 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 61CBE68CACA; Mon, 27 Mar 2023 13:49:53 +0300 (EEST) 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 59F3368CACB for ; Mon, 27 Mar 2023 13:49:47 +0300 (EEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230327104946euoutp02b2a3cfd8e1576d9ef2997cd719ab1dbd~QQQ1ovtu01182911829euoutp02t for ; Mon, 27 Mar 2023 10:49:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230327104946euoutp02b2a3cfd8e1576d9ef2997cd719ab1dbd~QQQ1ovtu01182911829euoutp02t DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1679914186; bh=mhGVWwUJJILmpkzXaJ1bYgU4uSVaZc0U+49QAUDhUC0=; h=From:To:Cc:Subject:Date:References:From; b=DamRiaktciGrMVhVYKCUP5oBxwDa+uZleGcFSk3JGESxjUQgV03oPLmL9XlUQ91rj JLGg2S9xIXPFOF7V1Qz5rkqpnILl38El1jlgU7PodxR9kNLIAyFTC9nhDzu66XHK29 24jA+V6ok5BASCN7BTP3F4JTk/1NorHnB/rGEHIA= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230327104946eucas1p2513c657f3e42351e2274a0a5d3a851b2~QQQ1fbtug0783307833eucas1p2-; Mon, 27 Mar 2023 10:49:46 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id DE.E2.10014.AC471246; Mon, 27 Mar 2023 11:49:46 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230327104946eucas1p1778bce4f0ecd557255a7be7c04f3bcaf~QQQ1K1Pr21526915269eucas1p1_; Mon, 27 Mar 2023 10:49:46 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230327104946eusmtrp2198083e8ab46a4d133084e1f027b26d7~QQQ1KTna90291602916eusmtrp2I; Mon, 27 Mar 2023 10:49:46 +0000 (GMT) X-AuditID: cbfec7f5-b8bff7000000271e-59-642174cab503 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 27.E4.09583.AC471246; Mon, 27 Mar 2023 11:49:46 +0100 (BST) Received: from AMDN5164.EU.corp.samsungelectronics.net (unknown [106.210.132.171]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230327104945eusmtip1540b70f460b1f727c48005bd8cbdaa29~QQQ01oTq62483624836eusmtip1W; Mon, 27 Mar 2023 10:49:45 +0000 (GMT) From: Dawid Kozinski To: d.frankiewic@samsung.com, ffmpeg-devel@ffmpeg.org Date: Mon, 27 Mar 2023 12:49:35 +0200 Message-Id: <20230327104935.730-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+NgFnrFIsWRmVeSWpSXmKPExsWy7djPc7qnShRTDBrmqlp8ufaF2WLlt98s Ft8+nWF2YPb4s2gzi0ffllWMAUxRXDYpqTmZZalF+nYJXBkNNysK7vBWTPx4h7WBcTtXFyMn h4SAicTdO21sILaQwApGial9BV2MXED2F0aJB72TWCCcz4wS7V/mssJ0PLjfygaRWM4o8W3l ZFYIp51JYvvXWywgVWwCuhIvPzxiArFFBEwlTjbvBdvBLKAtse7udzBbWCBRYvffR2BTWQRU Jf5fWsYOYvMKWErMv/CRBWKbpsSELXOYIOKCEidnPoGKc0usm3WJFWKmvETz1tnMIEdICPxk l2h/O5kRoshFYuXmWVANwhKvjm9hh7BlJP7vnA80lAPILpY41O8AYdZIHPqRDlFhLfG28Tgj SJgZ6IT1u/Qhwo4Sn08fYYOo5pO48VYQ4gA+iUnbpjNDhHklOtqEIEwVib5OMYhGKYmny+Yw Q9geElvmt7BMYFScheSrWUg+mYWwdgEj8ypG8dTS4tz01GLjvNRyveLE3OLSvHS95PzcTYzA 5HD63/GvOxhXvPqod4iRiYPxEKMEB7OSCO9mb8UUId6UxMqq1KL8+KLSnNTiQ4zSHCxK4rza tieThQTSE0tSs1NTC1KLYLJMHJxSDUzqu84qv5656ALLjgTGVhehXImHLwp530/ICa4NElK9 VS7xOThyRe5L7tez32vuFaq5c+Rj/vxlK24t8Ps8W+7Vlqf7NHKqPu37I7xl0yw7o0WTn/Ve v7/hw42VjsLqppudqmX7vtt382y7xrrBQlnjZ6BTQI/a0lsP32jMuM59WItrTYCwxrvDS07L nOKdpHYlM8/qx7KPPU/zdm/foWTeZXOS+z630DX/PcdlXvH0GG5eG/Tv6vqoEqGwrONKgUci NgrN+mTt83X5jm+rNnufYMyckfnSxT0tyuyncG7KBQPB4J6CRWadn5lSWsKvuuk3uTxq+53j fOvUJf6yU7rNeUHGtWnftn2eEPvn+e73SizFGYmGWsxFxYkARIa1pX0DAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrILMWRmVeSWpSXmKPExsVy+t/xu7qnShRTDDbd5Lf4cu0Ls8XKb79Z LL59OsPswOzxZ9FmFo++LasYA5ii9GyK8ktLUhUy8otLbJWiDS2M9AwtLfSMTCz1DI3NY62M TJX07WxSUnMyy1KL9O0S9DIablYU3OGtmPjxDmsD43auLkZODgkBE4kH91vZuhi5OIQEljJK 3Fr0lBkiISWxdOkiRghbWOLPtS6oolYmiaW969hBEmwCuhIvPzxiArFFBMwlLq67BdbALKAt se7udzYQW1ggXmLJsgmsIDaLgKrE/0vLwHp5BSwl5l/4yAKxQFNiwpY5TBBxQYmTM59Axbkl 1s26xAoxU16ieets5gmM/LOQlM1CklrAyLSKUSS1tDg3PbfYSK84Mbe4NC9dLzk/dxMjMGy3 Hfu5ZQfjylcf9Q4xMnEwHmKU4GBWEuHd7K2YIsSbklhZlVqUH19UmpNafIjRFOjWicxSosn5 wMjJK4k3NDMwNTQxszQwtTQzVhLn9SzoSBQSSE8sSc1OTS1ILYLpY+LglGpgCrnS7TAx6nrc YneTiI3Rgcf7ou4sXvf18o5Vx54Fc7jV9a/Vml1yvuyah8/6lj3Lju+x/MfwlDHciqdv8bRH uzoN06Ywzbkbe7g38Mm1kGZ1Zy2z2VV7Z/39ufTKwoLb/X0PxZo//uW7H/hwycSkOM7DwgEz 1qjq/Ft+MnPajmdLxdmOn1BL/rz3scCB+W+sKsV33Jryd9P3bT7B21jcNua7Sc/OOf7Na/WX vzKvVpcevxN8Y9a9c9W/l6ybtaij+pTgkbovX0MXfpBwui7yMuqM3JwrO5bsVW89/07PZe6z t7d/9Dmd9zBjSr9kY1e0IKJkgQ33oxqWmHlNr298mtfv+eHrA/kp0jM/M5b+WCXeoMRSnJFo qMVcVJwIAAXs7RTkAgAA X-CMS-MailID: 20230327104946eucas1p1778bce4f0ecd557255a7be7c04f3bcaf X-Msg-Generator: CA X-RootMTR: 20230327104946eucas1p1778bce4f0ecd557255a7be7c04f3bcaf X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230327104946eucas1p1778bce4f0ecd557255a7be7c04f3bcaf References: Subject: [FFmpeg-devel] [PATCH v17 8/9] avformat/mov_demuxer: Extended MOV demuxer to handle EVC video content 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: Ked2fwSk0dCg - Added evc extension to the list of extensions for ff_mov_demuxer --- libavformat/demux.c | 1 + libavformat/mov.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libavformat/demux.c b/libavformat/demux.c index b19ab86d08..031d17dab8 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -120,6 +120,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, { "mp3", AV_CODEC_ID_MP3, AVMEDIA_TYPE_AUDIO }, { "mpegvideo", AV_CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO }, { "truehd", AV_CODEC_ID_TRUEHD, AVMEDIA_TYPE_AUDIO }, + { "evc", AV_CODEC_ID_EVC, AVMEDIA_TYPE_VIDEO }, { 0 } }; int score; diff --git a/libavformat/mov.c b/libavformat/mov.c index 057fd872b1..3d5c432697 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -2647,6 +2647,7 @@ static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb, case AV_CODEC_ID_VP9: sti->need_parsing = AVSTREAM_PARSE_FULL; break; + case AV_CODEC_ID_EVC: case AV_CODEC_ID_AV1: /* field_order detection of H264 requires parsing */ case AV_CODEC_ID_H264: @@ -9305,7 +9306,7 @@ const AVInputFormat ff_mov_demuxer = { .long_name = NULL_IF_CONFIG_SMALL("QuickTime / MOV"), .priv_class = &mov_class, .priv_data_size = sizeof(MOVContext), - .extensions = "mov,mp4,m4a,3gp,3g2,mj2,psp,m4b,ism,ismv,isma,f4v,avif", + .extensions = "mov,mp4,m4a,3gp,3g2,mj2,psp,m4b,ism,ismv,isma,f4v,avif,evc", .flags_internal = FF_FMT_INIT_CLEANUP, .read_probe = mov_probe, .read_header = mov_read_header, From patchwork Mon Mar 27 10:49:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawid Kozinski X-Patchwork-Id: 40868 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp1221622pzh; Mon, 27 Mar 2023 03:50:20 -0700 (PDT) X-Google-Smtp-Source: AKy350Y6eeWFgeXJv+ekgFa+s273RwJmxDDxpc+MqfEA1OsuYwjqSx9guKBDESQ9LfK0Jcx7x+pD X-Received: by 2002:aa7:c950:0:b0:500:2c4f:3f5 with SMTP id h16-20020aa7c950000000b005002c4f03f5mr10425447edt.12.1679914220761; Mon, 27 Mar 2023 03:50:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679914220; cv=none; d=google.com; s=arc-20160816; b=WYUsr41GYvPcWe75C5+Jl1zW8i8ZuBla0VvDcS52qw6njKhmSUVj9wZDHBJv+WhryI FudaYf7zUg3NjMS0w1B75xJKGElYNnKv/ysYvIu6LUIkIbOUUUecSxqwYwaeSd8uWoDF jx2MNTMAsSJyaa9EX0xkK2y6bPKQLix18RvwG+hvCikU6F/PtDprp2ZxSiuMJADPgFsZ ECiAz8ufb0PFhrj7nrOb2W1DsT5a+k5BOIOFAxJvOxA3AYkjoEcHKX1H65DpkLig3T3o 23BHQdAVdAJHv5zNCebG22O0f0h9BvURr2Pn6b2rY37o18CI+bcmoVB9IqGPq8fk4CNX k2Nw== 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=cHnYjmo+plqOohTbQpXQWu4Z0fa8MtaufTpCkVvZKtg=; b=QgRP+9wM38Q3wFbc+iGpzcD/kx3lprgtSlslBhl9jusHSLaVBDQKiLu9SWhLyPoHIx oWJAPTP7yDtqxHALbEfPWnM5qlizDurYp/M8pviOe1sGCBX3e4vz92I3ovmod/dJtwHx NleiIM++b2DEhHHr2r+7bhDUt/lviOC7kD2ZME7y4lJGwNmN8536K7H3sLL9wek00Ff1 D/47v3wZJk9quko911Hj14CljqCzbPZQ60TGLmxyCWviPGFk5sOoC11F15KCEBed48gb WTFYtfCSpr7mUkXtoaFkKzfviuhCe286vgaR4/yiXZyBKxemteo0owssLrgHed1Fhw1P GQ3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=BrigW9i5; 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 tk9-20020a170907c28900b0093e6f40ea12si7234073ejc.111.2023.03.27.03.50.20; Mon, 27 Mar 2023 03:50:20 -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=@samsung.com header.s=mail20170921 header.b=BrigW9i5; 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 8D40568CADE; Mon, 27 Mar 2023 13:50:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C0BC968C463 for ; Mon, 27 Mar 2023 13:50:11 +0300 (EEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230327105011euoutp011d505f002b9282d57afd27174e7cf650~QQRMdZ-NN1572115721euoutp01D for ; Mon, 27 Mar 2023 10:50:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230327105011euoutp011d505f002b9282d57afd27174e7cf650~QQRMdZ-NN1572115721euoutp01D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1679914211; bh=AhY2XzmLYhXY5GmYBKpyJ/QFePxX6juhdN8bnsBy/7k=; h=From:To:Cc:Subject:Date:References:From; b=BrigW9i50xjiQDieOSS/iliWgAa6cm49ShYIdPMJP3NprCsdtXXcwdvlaT9deFN/3 aJNGBYp5ElzNfv+POrxsh7T5ntmE2cuyz0Y9/aLTNjApKPvvFf3rjRAhJrDeOey5vO CjrRAS+P9lhj/ASimH44BRe0DP2O7QhMO8XDOKfg= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230327105011eucas1p29fa4e978591c920eb84f095f99b1d544~QQRMLXgyX2859928599eucas1p2j; Mon, 27 Mar 2023 10:50:11 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 02.FF.09503.2E471246; Mon, 27 Mar 2023 11:50:11 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230327105010eucas1p27c1aaf3c28c350755ad26f06c3c63bf7~QQRL0KLGt0700807008eucas1p2C; Mon, 27 Mar 2023 10:50:10 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230327105010eusmtrp19c1ccc5953b3907f06bedc4f55ae90f3~QQRLzo1hS1277712777eusmtrp1f; Mon, 27 Mar 2023 10:50:10 +0000 (GMT) X-AuditID: cbfec7f2-e8fff7000000251f-c4-642174e244ce Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 6D.0B.08862.2E471246; Mon, 27 Mar 2023 11:50:10 +0100 (BST) Received: from AMDN5164.EU.corp.samsungelectronics.net (unknown [106.210.132.171]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230327105010eusmtip1655d10a069140bb162f2b8aadf70ba96~QQRLf-KGZ1282112821eusmtip1Q; Mon, 27 Mar 2023 10:50:10 +0000 (GMT) From: Dawid Kozinski To: d.frankiewic@samsung.com, ffmpeg-devel@ffmpeg.org Date: Mon, 27 Mar 2023 12:49:58 +0200 Message-Id: <20230327104958.1160-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+NgFnrFIsWRmVeSWpSXmKPExsWy7djPc7qPSxRTDF6ZW3y59oXZYuW33ywW 3z6dYXZg9vizaDOLR9+WVYwBTFFcNimpOZllqUX6dglcGc+u7GQqeMZScePzV/YGxkfMXYyc HBICJhJPL7ewgNhCAisYJS40ZnQxcgHZXxglXh2fzALhfGaUeHj8OjtMx+T+9+wQieWMEvOm tkI57UwST/7OB5vLJqAr8fLDIyYQW0TAVOJk8142EJtZQFti3d3vYLawgL3EifcHwHazCKhK THj1B2wDr4CVxL1v79kgtmlKTNgyhwkiLihxcuYTFog4t8S6WZdYIWbKSzRvnc0McoSEwE92 ialXm6Cec5F48+4iK4QtDPTPFqgXZCROT+4BGsQBZBdLHOp3gDBrJA79SIeosJZ423icESTM DHTC+l36EGFHifmTPzJDVPNJ3HgrCHEAn8SkbdOhwrwSHW1CEKaKRF+nGESjlMTTZXOgrvKQ WPpzE9MERsVZSL6aheSTWQhrFzAyr2IUTy0tzk1PLTbMSy3XK07MLS7NS9dLzs/dxAhMDqf/ Hf+0g3Huq496hxiZOBgPMUpwMCuJ8G72VkwR4k1JrKxKLcqPLyrNSS0+xCjNwaIkzqttezJZ SCA9sSQ1OzW1ILUIJsvEwSnVwMQ3e9XL7v+b/x7d//7brp7O+T/O8n0vtpNoT3hqaJX25ncD 3w2GRzbFJYy6FQG5hece31WLe7B+ve2a2vn8Tp+7/z15eU/Md97x2+uFnPmX3VrWKNL5yj91 fu+Dd3KmYqILnZJDd1b7qi286Nl9f1L824A7YXUqCf3zjMKfFnyT6L2ivsHYV9zZjDetbZtJ ndFHO5YT/vzHjHbvqnGq94249KiL73oO0+fXKgwWG01T9fpklI2zK/g1383WPO++9ZpH5iOb dec6/nJVxr11y1IuX50qwZS4f8sjY39Dy5d7d9h+LVsruNQuQqZuwq3wn0ZvxC6uXygeyL9N KPxD08SVT9T0D6nOS9ifbLUqWImlOCPRUIu5qDgRALQvtwh9AwAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrELMWRmVeSWpSXmKPExsVy+t/xu7qPShRTDC7NUrP4cu0Ls8XKb79Z LL59OsPswOzxZ9FmFo++LasYA5ii9GyK8ktLUhUy8otLbJWiDS2M9AwtLfSMTCz1DI3NY62M TJX07WxSUnMyy1KL9O0S9DKeXdnJVPCMpeLG56/sDYyPmLsYOTkkBEwkJve/Z+9i5OIQEljK KNHc0MYEkZCSWLp0ESOELSzx51oXG0RRK5PEq0PP2EASbAK6Ei8/PAJrEBEwl7i47hZYA7OA tsS6u9/BaoQF7CVOvD/AAmKzCKhKTHj1hx3E5hWwkrj37T0bxAJNiQlb5jBBxAUlTs58wgIR 55ZYN+sSK8RMeYnmrbOZJzDyz0JSNgtJagEj0ypGkdTS4tz03GJDveLE3OLSvHS95PzcTYzA wN127OfmHYzzXn3UO8TIxMF4iFGCg1lJhHezt2KKEG9KYmVValF+fFFpTmrxIUZToFsnMkuJ JucDYyevJN7QzMDU0MTM0sDU0sxYSZzXs6AjUUggPbEkNTs1tSC1CKaPiYNTqoGpbueRqK1m V1wrTvzeudd2B++xD4+v2z7Xrn4v+X5zVYpPqsITwdkfvr3m+PJny/n/zRPDjL5OFlQ4Uv7b rPrN4x2myqF1Hmy/E2/uFK6vuPpLep/83Ks7RT1elER7Ltvk+sI5SFFu68aNVxc0HXd8ti1p zWXhQ1u4PYP3O0kKSyhbKq1zk2WeqcAafndF/7JdR6oXLk28GfmUZdHnxgq1ZMvwo0F2Uxwk fq8RsCw8GbL2/9MUM6Yl77wSpJ5c/MngV1r8QIFB69X9hXEvXx59MkNbPmaLmRPbXcUUKdeY q+HqspPu31oseGPZxw9ZL46/7U/My2sq5z9zpdYk54qy7k//ZcoWza5/H6/r3rmwRomlOCPR UIu5qDgRANFFM63lAgAA X-CMS-MailID: 20230327105010eucas1p27c1aaf3c28c350755ad26f06c3c63bf7 X-Msg-Generator: CA X-RootMTR: 20230327105010eucas1p27c1aaf3c28c350755ad26f06c3c63bf7 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230327105010eucas1p27c1aaf3c28c350755ad26f06c3c63bf7 References: Subject: [FFmpeg-devel] [PATCH v17 9/9] avcodec/evc: Changes in Changelog file 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: VP9awmfRbFxl - Changelog update --- Changelog | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index b357f428ab..0cf4c8f461 100644 --- a/Changelog +++ b/Changelog @@ -74,6 +74,8 @@ version 5.1: - remap_opencl filter - added chromakey_cuda filter - added bilateral_cuda filter +- eXtra-fast Essential Video Encoder (XEVE) +- eXtra-fast Essential Video Decoder (XEVD) version 5.0: @@ -121,7 +123,6 @@ version 5.0: - anlmf audio filter - IMF demuxer (experimental) - version 4.4: - AudioToolbox output device - MacCaption demuxer