From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 3E08146F79 for ; Fri, 25 Aug 2023 03:17:40 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 97E9B68C6AF; Fri, 25 Aug 2023 06:17:37 +0300 (EEST) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 991AB68C50B for ; Fri, 25 Aug 2023 06:17:30 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692933455; x=1724469455; h=from:to:subject:date:message-id:references:in-reply-to: content-transfer-encoding:mime-version; bh=qFIxNACUD7jQFMYWmwl+3VHtSeEpnWu3NRW/sywKbKQ=; b=SL4Xli1w5l4xD/JEt47WkDuSRAsJU1ZdDb/If3CT5o5l2JCBnZCMF5FZ 7o+196tN580YldSWVR/Ez7EKvXfU0EGUxR/9HHTIJ+IipkbfvvZi+xSXq 68aV2IovlVg/H5YdbcbuWtasrbb6sVpUrIDvE8QWnmX0BKL2EMedeNN/c QIfJFNOEnh29alCcppqd64vCWCMlyoDuzIArRAcX0xFNNMsJ6U/GCHYC4 BbDJwGd7Pis4A+6cd+L7CmliJevl4oWpqBZo8rXXQv4ECxYhfOe2oPGb1 9Z7mGBweIVLDLFUZCxyLmA3ZUyfRFbcJEPvvx0G9CEXCC18qZlGPiFDfI A==; X-IronPort-AV: E=McAfee;i="6600,9927,10812"; a="374592954" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="374592954" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 20:17:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10812"; a="714197180" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="714197180" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orsmga006.jf.intel.com with ESMTP; 24 Aug 2023 20:17:21 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 24 Aug 2023 20:17:20 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Thu, 24 Aug 2023 20:17:20 -0700 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.43) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.27; Thu, 24 Aug 2023 20:17:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZtcPVo6gbFkd2LXrEAKmw4TJrMF/7ReAgblJGFXZYartronjo05GS93obistOnkXr5c0WK3t+7jtcWqPg/29lRdkYjTDPu+UTnT/7ZyaHX2d/I6rsfRDXTCiZvMeQSrm6ktlyvNKKCjtPQYBA+2cULHI1CuFV1UbM0qEqyf9JTI5fPRLIYFsDUKBKNY/9P0W8q/jAVgc43LYSwJDU6QrxSoE/nAakCrtQVo4wv/3GCxbdViVErIZQA4qci126I408+PbYmLFP7fIvRU0BsREIP+EMMq5OUzmaOAqD3Q+IdB6dtTNFdMKFGHlemiMQiL3er6wn3fZ0Bp9ogOMa8iEVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lfxiPPRj578fypq5BDsp+MHdQ9WyRQws2uKSg4VU0is=; b=kPHtTEYlfqjHbSxR3MHdwTuWSleObfAgzkjYorONCWXS4+XieqW4u+bJWDgzzpI7POhsMXzhofkeWRcm8WilZR+KT6t1+8TsP5H3kp7veZpb2Y9HAaF5H30/K+p6fJg0Mhaq69KL2NGdDUq9Y/w7oyh/xADFGNUeWCflkph8epcQaaFqHiG9rdviLKYZr23kT+6UJZrS3dMbIiD7TggV5Cl3uW1tZ1mvadwLPo1emPobkDVQveFmmfeC3XdmzsfxxbgjYBQc/PxD748b36QxDPoGETs4jq/cSjpC+UmAI8DG8tyjG6qb9puzBJIAg7S0IZnJu0dMzNq2JUbA/SfFiA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from DM6PR11MB2681.namprd11.prod.outlook.com (2603:10b6:5:bd::33) by SN7PR11MB6655.namprd11.prod.outlook.com (2603:10b6:806:26d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 03:17:17 +0000 Received: from DM6PR11MB2681.namprd11.prod.outlook.com ([fe80::3549:fc64:19cc:c591]) by DM6PR11MB2681.namprd11.prod.outlook.com ([fe80::3549:fc64:19cc:c591%5]) with mapi id 15.20.6699.027; Fri, 25 Aug 2023 03:17:17 +0000 From: "Dai, Jianhui J" To: FFmpeg development discussions and patches Thread-Topic: [PATCH v4] avcodec/cbs_vp8: Add support for VP8 codec bitstream Thread-Index: AdmG0tDkoKIoNj/tTiydglUry7bYTxQL4jag Date: Fri, 25 Aug 2023 03:17:16 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM6PR11MB2681:EE_|SN7PR11MB6655:EE_ x-ms-office365-filtering-correlation-id: 48c8e2a5-01c0-4d54-cbdd-08dba519c924 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: mpcPHl6ea8z/a9f8PmhUe1LWhrErdLYtEQh4ERF53Cz/mqNyGhjWYjHM4XU2q/mu+SaJ8s+QmwqwnVz4QdVLQ6Fpv+oe3ESX9Vu9dVa1GmDkMagLcjf8jylHt7zFgG1BPaEgQTQM2qoF1Pu/xMHzBsqgMF3nfB00pYrv9MjohR1sP085vxqOYhJKBNF46ofcqQutqoWSgGHM+peHKdIfkoumJG+J6Otpw9OuzYNlQyFgUFpnamK/Rtu2p5rIqwxlK5zkvIX+mtEz+kpWGJD85EAWWwrxjZ+s803N7gG2lee/YYPbaYcHkz99aT1HKhPIhAxkz14wLrbBHLSO3rqZkwLk840Q6MzSP3B5rKnSF+Vz/gSNRFw8wkDetm4EczuFvBqC1RYC/bVVqsTdcxsZxSRKeOso8oB20Ld2esejjcD2cyDmqjEvbwCuvzwassrLoqKu0CNQjRQkPYi/L2lzidhQKyHuMs2GJgluSC5w0jAXAWXpmIDITSK70/n9gXO0iEAolqAAKvUcXVojJYksHkiCqkJSXMgjfkpj4B4JFIVJmTon554G/d6qMGlZRccx4339tZmhiXSLaelZmgFxX1u7JXh4nt+iABQiXPowRet5Gs14pvD5z5NXzjLiz+2n x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR11MB2681.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(346002)(366004)(39860400002)(396003)(376002)(136003)(186009)(1800799009)(451199024)(66899024)(66946007)(26005)(2940100002)(83380400001)(53546011)(9686003)(41300700001)(66556008)(30864003)(66446008)(66476007)(2906002)(6916009)(316002)(76116006)(52536014)(5660300002)(8936002)(8676002)(478600001)(6506007)(71200400001)(7696005)(19627235002)(966005)(55016003)(64756008)(82960400001)(33656002)(86362001)(122000001)(38070700005)(38100700002)(2004002)(559001)(579004); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?VxO7c3YvFCg1WIFPyx4Fx37G6xVOeyAHmFwtio7EpzuQstjcwqFL5qIxW5h2?= =?us-ascii?Q?OfCBdzZu10JByW82JpFqIUEtfacQC1GkWFrKSxkM29u3/m+Dke8RAQiDgBN8?= =?us-ascii?Q?hD8oEQJMB7UaZOY71ga9c51fcR6mBZARYkM84UVUmWOgGK4BtgOy6HqGcAY/?= =?us-ascii?Q?TSTDlfxig5DNFZ6zJjSAgW0s0NnPmqqoMPQKGqeLN9PmnZuVinyHu+2iAWTe?= =?us-ascii?Q?cBztzwihKKSgOHFfaYNx+nnfpbxEuOGvUIL4GwOvCTHGsCNxt8fV/uJhYgrp?= =?us-ascii?Q?WIEK7ujy3H1b+ylPCF0kGExHYaka2tWbpukEIY99hXFxKJEmOXHO/yoaZcYU?= =?us-ascii?Q?sSAsFHtoQLKC24RRJAyW/XzocmkFQIL08/a9Gp7dG8UHRu1iAaVtQN2mQSYt?= =?us-ascii?Q?XaOID06cmmv8NrgyRc4ktQo8uvyKEQ9rOwx6F8BEvqa7fwsZuH4Ac2JBsiGZ?= =?us-ascii?Q?3XRQH3uYm4cS+dgzmEAHk0mY8dkOg8IupZjV2WEVeAAvyxvsn7fXr29eG1uR?= =?us-ascii?Q?G6kuhCbDhBxM0ivrdL8ohyZVTFgapePp2CPfgJarZowOT61/Wy2fZqm3bcpk?= =?us-ascii?Q?womVxEhAXZfWZMdlx4MWOZc4Q0QWE/xUieFrtPQJ63qNpSRPmyWml0qOvuzn?= =?us-ascii?Q?9mhbN+8pogOZdZlftba0tOczJ0EkrAGrFAJdUvPzv96c1pIH7yZK8bwk66Xh?= =?us-ascii?Q?LrfZB58NIH/e1DqwegbF5BvVRRj/g5OQ3+jQ9ud554KILsWqAPcYLStUnUAj?= =?us-ascii?Q?aSWwBd96Pu3uJtRwL1x5H6/H//UywIScBi5zfZTvPLbv/C37xj02+pt5s7wO?= =?us-ascii?Q?TKxe70yF9ihiWU3bYq7ihuvuyKjUdgr0uoF3JcddmDPkYUlLPsWRotqKIK1T?= =?us-ascii?Q?HTKLcjZTcDzkNGEjeoMZzbVmS9TyDiuYRkVBFtqhVSBXBEvGBzdvfX+H408W?= =?us-ascii?Q?4HfVP5N91Jx1K9DwdEY+YXqBbuLJNmSwRZVqZYjBRVYTmPCA2XRjf4fBBUWU?= =?us-ascii?Q?RjaVBOJab+92Y96NGMGiIqTFlfNILalRjibFZY0YNVF1TQMGlIQoCEuZaHfz?= =?us-ascii?Q?Lm9HsiQnKXri85S2juF4n+KN3InS0fn4bJBbQwCNAGZlLgnuk8UrqjE8r7ID?= =?us-ascii?Q?as/lCKU+5XgdGV/xa0TuborY7twSykUYo6VUAUPWB+OsEWnvJBsgN0oKfMJ9?= =?us-ascii?Q?XKUoRHB8IaRtDeLP3jE4CeCGZuEeEVrhQDMLaIE3Ci4yygeP743d2rwMkgfR?= =?us-ascii?Q?wdUkEXQEUh/FAfmdAx8VsDWvoqpJW6sNwwl5IsMod3ulRzb1xrj4h1gJRXZ0?= =?us-ascii?Q?PwKeIdWhpyC3e6LM/6rtU6GVpYn1Le/sPwCU0L+TEks0znQUIMg8e+S0Uqwm?= =?us-ascii?Q?rJupgmNjyCtrrwDxwVP1C9kEpJNMThuc9/3GBdaTqJOZT9MzTzhBXUP7F4ne?= =?us-ascii?Q?e6DqmaP+1snP3ry4gusmWDrrIyIEqiGU0KxWqKhRbtQUa1PBGLFNe0v3dXIc?= =?us-ascii?Q?bB0b34OmiAi9FNKHnKFRZJpDTadF1I2djUsNcKiiMHMNAYeGESf5LxMbeJ0H?= =?us-ascii?Q?0a1dPBp5UBK3xXAuMnmy0xpgkLkHLSlPK01yZfLd?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB2681.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 48c8e2a5-01c0-4d54-cbdd-08dba519c924 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Aug 2023 03:17:16.9951 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: KubADZzn6yKckBB9CAknrcJcTxrFvmDzijw+0etkubBvbEgK5ImAkq69jd6cGxKJ6k5x46NamrDigvUqopzkHQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR11MB6655 X-OriginatorOrg: intel.com Subject: Re: [FFmpeg-devel] [PATCH v4] avcodec/cbs_vp8: Add support for VP8 codec bitstream 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: > -----Original Message----- > From: ffmpeg-devel On Behalf Of Dai, > Jianhui J > Sent: Friday, August 25, 2023 10:40 AM > To: ffmpeg-devel@ffmpeg.org > Subject: [FFmpeg-devel] [PATCH v4] avcodec/cbs_vp8: Add support for VP8 > codec bitstream > > This commit adds support for VP8 bitstream read methods to the cbs codec. > This enables the trace_headers bitstream filter to support VP8, in addition to > AV1, H.264, H.265, and VP9. This can be useful for debugging VP8 stream > issues. > > The CBS VP8 implements a simple VP8 boolean decoder with bounds > checking to prevent overreads. > > Only the read methods `read_unit` and `split_fragment` are implemented. > The write methods `write_unit` and `assemble_fragment` return the error > code AVERROR_PATCHWELCOME. This is because CBS VP8 write is unlikely to > be used by any applications at the moment. The write methods can be added > later if there is a real need for them. > > TESTS: ffmpeg -i fate-suite/vp8/frame_size_change.webm -vcodec copy -bsf:v > trace_headers -f null - > > Signed-off-by: Jianhui Dai > --- > configure | 4 +- > libavcodec/Makefile | 1 + > libavcodec/cbs.c | 6 + > libavcodec/cbs_internal.h | 1 + > libavcodec/cbs_vp8.c | 591 +++++++++++++++++++++++++++ > libavcodec/cbs_vp8.h | 137 +++++++ > libavcodec/cbs_vp8_syntax_template.c | 248 +++++++++++ > 7 files changed, 987 insertions(+), 1 deletion(-) create mode 100644 > libavcodec/cbs_vp8.c create mode 100644 libavcodec/cbs_vp8.h create > mode 100644 libavcodec/cbs_vp8_syntax_template.c > > diff --git a/configure b/configure > index 932998b8d6..2424ee61ad 100755 > --- a/configure > +++ b/configure > @@ -2479,6 +2479,7 @@ CONFIG_EXTRA=" > cbs_h266 > cbs_jpeg > cbs_mpeg2 > + cbs_vp8 > cbs_vp9 > deflate_wrapper > dirac_parse > @@ -2764,6 +2765,7 @@ cbs_h265_select="cbs" > cbs_h266_select="cbs" > cbs_jpeg_select="cbs" > cbs_mpeg2_select="cbs" > +cbs_vp8_select="cbs" > cbs_vp9_select="cbs" > dct_select="rdft" > deflate_wrapper_deps="zlib" > @@ -3349,7 +3351,7 @@ h264_redundant_pps_bsf_select="cbs_h264" > hevc_metadata_bsf_select="cbs_h265" > mjpeg2jpeg_bsf_select="jpegtables" > mpeg2_metadata_bsf_select="cbs_mpeg2" > -trace_headers_bsf_select="cbs" > +trace_headers_bsf_select="cbs cbs_vp8" > vp9_metadata_bsf_select="cbs_vp9" > vvc_metadata_bsf_select="cbs_h266" > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile index > 3c16b51462..04f735f45e 100644 > --- a/libavcodec/Makefile > +++ b/libavcodec/Makefile > @@ -79,6 +79,7 @@ OBJS-$(CONFIG_CBS_H265) += cbs_h2645.o > cbs_sei.o h2645_parse.o > OBJS-$(CONFIG_CBS_H266) += cbs_h2645.o cbs_sei.o h2645_parse.o > OBJS-$(CONFIG_CBS_JPEG) += cbs_jpeg.o > OBJS-$(CONFIG_CBS_MPEG2) += cbs_mpeg2.o > +OBJS-$(CONFIG_CBS_VP8) += cbs_vp8.o > OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o > OBJS-$(CONFIG_CRYSTALHD) += crystalhd.o > OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o > diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 3ec8285e21..f891e7247f > 100644 > --- a/libavcodec/cbs.c > +++ b/libavcodec/cbs.c > @@ -49,6 +49,9 @@ static const CodedBitstreamType *const > cbs_type_table[] = { #if CONFIG_CBS_MPEG2 > &ff_cbs_type_mpeg2, > #endif > +#if CONFIG_CBS_VP8 > + &ff_cbs_type_vp8, > +#endif > #if CONFIG_CBS_VP9 > &ff_cbs_type_vp9, > #endif > @@ -73,6 +76,9 @@ const enum AVCodecID ff_cbs_all_codec_ids[] = { #if > CONFIG_CBS_MPEG2 > AV_CODEC_ID_MPEG2VIDEO, > #endif > +#if CONFIG_CBS_VP8 > + AV_CODEC_ID_VP8, > +#endif > #if CONFIG_CBS_VP9 > AV_CODEC_ID_VP9, > #endif > diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h index > da84697a29..7ae7e477d6 100644 > --- a/libavcodec/cbs_internal.h > +++ b/libavcodec/cbs_internal.h > @@ -263,6 +263,7 @@ extern const CodedBitstreamType ff_cbs_type_h265; > extern const CodedBitstreamType ff_cbs_type_h266; extern const > CodedBitstreamType ff_cbs_type_jpeg; extern const CodedBitstreamType > ff_cbs_type_mpeg2; > +extern const CodedBitstreamType ff_cbs_type_vp8; > extern const CodedBitstreamType ff_cbs_type_vp9; > > > diff --git a/libavcodec/cbs_vp8.c b/libavcodec/cbs_vp8.c new file mode > 100644 index 0000000000..6db295ce08 > --- /dev/null > +++ b/libavcodec/cbs_vp8.c > @@ -0,0 +1,591 @@ > +/* > + * 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/avassert.h" > + > +#include "cbs.h" > +#include "cbs_internal.h" > +#include "cbs_vp8.h" > + > +#include > + > +#define DEFAULT_PROB 0x80 > + > +static const uint8_t vp8_token_update_probs[4][8][3][11] = { > + { > + { > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {176, 246, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {223, 241, 252, 255, 255, 255, 255, 255, 255, 255, 255}, > + {249, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 244, 252, 255, 255, 255, 255, 255, 255, 255, 255}, > + {234, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 246, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {239, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {251, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {251, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 254, 253, 255, 254, 255, 255, 255, 255, 255, 255}, > + {250, 255, 254, 255, 254, 255, 255, 255, 255, 255, 255}, > + {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + }, > + { > + { > + {217, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {225, 252, 241, 253, 255, 255, 254, 255, 255, 255, 255}, > + {234, 250, 241, 250, 253, 255, 253, 254, 255, 255, 255}, > + }, > + { > + {255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {223, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {238, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {249, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {247, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {252, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255}, > + {250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + }, > + { > + { > + {186, 251, 250, 255, 255, 255, 255, 255, 255, 255, 255}, > + {234, 251, 244, 254, 255, 255, 255, 255, 255, 255, 255}, > + {251, 251, 243, 253, 254, 255, 254, 255, 255, 255, 255}, > + }, > + { > + {255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {236, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {251, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + }, > + { > + { > + {248, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {250, 254, 252, 254, 255, 255, 255, 255, 255, 255, 255}, > + {248, 254, 249, 253, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255}, > + {246, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255}, > + {252, 254, 251, 254, 254, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 254, 252, 255, 255, 255, 255, 255, 255, 255, 255}, > + {248, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255}, > + {253, 255, 254, 254, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {245, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {253, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 251, 253, 255, 255, 255, 255, 255, 255, 255, 255}, > + {252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 252, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {249, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 255, 253, 255, 255, 255, 255, 255, 255, 255, 255}, > + {250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + { > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, > + }, > + }, > +}; > + > +typedef struct CBSVP8BoolDecoder { > + const uint8_t *buffer; > + int buffer_size; > + int buffer_pos; > + > + uint16_t value; > + uint8_t range; > + > + int count; // Store the number of bits in the `value` buffer. > +} CBSVP8BoolDecoder; > + > +static int cbs_vp8_bool_decoder_init(CBSVP8BoolDecoder *decoder, > + const uint8_t *buffer, const int > +size) { > + av_assert0(decoder); > + > + if (decoder->buffer == NULL || decoder->buffer <= 0) { > + return AVERROR_INVALIDDATA; > + } > + > + decoder->buffer = buffer; > + decoder->buffer_size = size; > + decoder->buffer_pos = 0; > + > + decoder->value = 0; > + decoder->range = 255; > + > + decoder->count = 0; > + > + return 0; > +} > + > +static bool cbs_vp8_bool_decoder_fill_value(CBSVP8BoolDecoder *decoder) > +{ > + int shift = 8 - decoder->count; > + > + av_assert0(decoder->count < 8); > + > + // End of buffer. > + if (decoder->buffer_pos >= decoder->buffer_size) { > + return false; > + } > + > + while (shift >= 0 && decoder->buffer_pos < decoder->buffer_size) { > + decoder->value |= *(decoder->buffer + decoder->buffer_pos++) << > + shift; > + > + decoder->count += 8; > + shift -= 8; > + } > + > + return (decoder->count >= 8); > +} > + > +static int cbs_vp8_bool_decoder_read_bool(CBSVP8BoolDecoder *decoder, > + const uint8_t prob, uint8_t > +*output) { > + uint8_t split = 1 + (((decoder->range - 1) * prob) >> 8); > + uint16_t big_split = split << 8; > + > + if (decoder->count < 8 && !cbs_vp8_bool_decoder_fill_value(decoder)) { > + return AVERROR_INVALIDDATA; > + } > + > + av_assert0(decoder->count >= 8); > + if (decoder->value >= big_split) { > + *output = 1; > + decoder->range -= split; > + decoder->value -= big_split; > + } else { > + *output = 0; > + decoder->range = split; > + } > + > + while (decoder->range < 128) { > + decoder->value <<= 1; > + decoder->range <<= 1; > + --decoder->count; > + } > + > + return 0; > +} > + > +static int cbs_vp8_bool_decoder_read_literal(CBSVP8BoolDecoder *decoder, > + const uint8_t prob, > + uint32_t num_bits, > + uint32_t *output) { > + int ret = 0; > + > + av_assert0(num_bits <= 32); > + > + *output = 0; > + for (; num_bits > 0; --num_bits) { > + uint8_t bit_output = 0; > + if ((ret = cbs_vp8_bool_decoder_read_bool(decoder, prob, > + &bit_output)) != 0) { > + return ret; > + } > + > + *output = (*output << 1) | bit_output; > + } > + > + return 0; > +} > + > +static int cbs_vp8_bool_decoder_bit_count(CBSVP8BoolDecoder > +*bool_decoder) { > + return (bool_decoder->buffer_pos * 8 - bool_decoder->count); } > + > +static int cbs_vp8_bool_decoder_read_unsigned( > + CodedBitstreamContext *ctx, CBSVP8BoolDecoder *bool_decoder, int > width, > + uint8_t prob, const char *name, const int *subscripts, uint32_t *write_to, > + bool trace_enable) > +{ > + int ret = 0; > + CodedBitstreamVP8Context *vp8 = ctx->priv_data; > + uint32_t value; > + int pos; > + > + av_assert0(width >= 0 && width <= 8); > + > + pos = vp8->uncompressed_header_size * 8; > + pos += cbs_vp8_bool_decoder_bit_count(bool_decoder); > + > + ret = cbs_vp8_bool_decoder_read_literal(bool_decoder, prob, width, > &value); > + if (ret != 0) { > + return ret; > + } > + > + if (ctx->trace_enable && trace_enable) { > + char bits[33] = "-"; > + ff_cbs_trace_syntax_element(ctx, pos, name, subscripts, bits, value); > + } > + > + *write_to = value; > + return 0; > +} > + > +static int cbs_vp8_bool_decoder_read_signed( > + CodedBitstreamContext *ctx, CBSVP8BoolDecoder *bool_decoder, int > width, > + uint8_t prob, const char *name, const int *subscripts, int32_t > +*write_to) { > + int ret = 0; > + CodedBitstreamVP8Context *vp8 = ctx->priv_data; > + int32_t value; > + uint8_t sign = 0; > + int pos; > + > + av_assert0(width >= 0 && width <= 8); > + > + pos = vp8->uncompressed_header_size * 8; > + pos += cbs_vp8_bool_decoder_bit_count(bool_decoder); > + > + ret = cbs_vp8_bool_decoder_read_literal(bool_decoder, prob, width, > &value); > + if (ret != 0) { > + return ret; > + } > + > + ret = cbs_vp8_bool_decoder_read_bool(bool_decoder, prob, &sign); > + if (ret != 0) { > + return ret; > + } > + > + if (sign) { > + value = -value; > + } > + > + if (ctx->trace_enable) { > + char bits[33] = "-"; > + ff_cbs_trace_syntax_element(ctx, pos, name, subscripts, bits, value); > + } > + > + *write_to = value; > + return 0; > +} > + > +static int cbs_vp8_read_unsigned(CodedBitstreamContext *ctx, > GetBitContext *gbc, > + int width, const char *name, > + const int *subscripts, uint32_t > +*write_to) { > + int pos; > + uint32_t value; > + > + av_assert0(width > 0 && width <= 24); > + > + if (get_bits_left(gbc) < width) { > + av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value: bitstream > ended.\n"); > + return AVERROR_INVALIDDATA; > + } > + > + pos = get_bits_count(gbc); > + value = get_bits_le(gbc, width); > + > + if (ctx->trace_enable) { > + int i; > + char bits[33]; > + for (i = 0; i < width; i++) > + bits[i] = value >> (width - i - 1) & 1 ? '1' : '0'; > + bits[i] = 0; > + > + ff_cbs_trace_syntax_element(ctx, pos, name, subscripts, bits, value); > + } > + > + *write_to = value; > + return 0; > +} > + > +#define HEADER(name) \ > + do { \ > + ff_cbs_trace_header(ctx, name); \ > + } while (0) > + > +#define CHECK(call) \ > + do { \ > + int err = (call); \ > + if (err < 0) \ > + return err; \ > + } while (0) > + > +#define FUNC_NAME(rw, codec, name) cbs_##codec##_##rw##_##name > #define > +FUNC_VP8(rw, name) FUNC_NAME(rw, vp8, name) #define FUNC(name) > +FUNC_VP8(READWRITE, name) > + > +#define SUBSCRIPTS(subs, ...) \ > + (subs > 0 ? ((int[subs + 1]){subs, __VA_ARGS__}) : NULL) > + > +#define f(width, name) xf(width, name, 0) > + > +// bool [de|en]coder methods. > +#define bc_f(width, name) bc_unsigned_subs(width, DEFAULT_PROB, true, > +name, 0) #define bc_s(width, name) bc_signed_subs(width, DEFAULT_PROB, > +name, 0) #define bc_fs(width, name, subs, ...) \ > + bc_unsigned_subs(width, DEFAULT_PROB, true, name, subs, > +__VA_ARGS__) #define bc_ss(width, name, subs, ...) \ > + bc_signed_subs(width, DEFAULT_PROB, name, subs, __VA_ARGS__) > + > +// bool [de|en]coder methods for boolean value and disable tracing. > +#define bc_b(name) bc_unsigned_subs(1, DEFAULT_PROB, false, name, 0) > +#define bc_b_prob(prob, name) bc_unsigned_subs(1, prob, false, name, 0) > + > +#define READ > +#define READWRITE read > +#define RWContext GetBitContext > +#define CBSVP8BoolCodingRW CBSVP8BoolDecoder > + > +#define xf(width, name, subs, ...) \ > + do { \ > + uint32_t value; \ > + CHECK(cbs_vp8_read_unsigned(ctx, rw, width, #name, \ > + SUBSCRIPTS(subs, __VA_ARGS__), &value)); \ > + current->name = value; \ > + } while (0) > + > +#define fixed(width, name, value) \ > + do { \ > + uint32_t fixed_value; \ > + CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, 0, &fixed_value, \ > + value, value)); \ > + } while (0) > + > +#define bc_unsigned_subs(width, prob, enable_trace, name, subs, ...) \ > + do { \ > + uint32_t value; \ > + CHECK(cbs_vp8_bool_decoder_read_unsigned( \ > + ctx, bool_coding_rw, width, prob, #name, \ > + SUBSCRIPTS(subs, __VA_ARGS__), &value, enable_trace)); \ > + current->name = value; \ > + } while (0) > + > +#define bc_signed_subs(width, prob, name, subs, ...) \ > + do { \ > + int32_t value; \ > + CHECK(cbs_vp8_bool_decoder_read_signed( \ > + ctx, bool_coding_rw, width, prob, #name, \ > + SUBSCRIPTS(subs, __VA_ARGS__), &value)); \ > + current->name = value; \ > + } while (0) > + > +#include "cbs_vp8_syntax_template.c" > + > +static int cbs_vp8_split_fragment(CodedBitstreamContext *ctx, > + CodedBitstreamFragment *frag, int > +header) { > + int err; > + > + if (frag->data_size == 0) > + return AVERROR_INVALIDDATA; > + > + err = ff_cbs_append_unit_data(frag, 0, frag->data, frag->data_size, > + frag->data_ref); > + if (err < 0) > + return err; > + > + return 0; > +} > + > +static int cbs_vp8_read_unit(CodedBitstreamContext *ctx, > + CodedBitstreamUnit *unit) { > + CodedBitstreamVP8Context *vp8 = ctx->priv_data; > + VP8RawFrame *frame; > + GetBitContext gbc; > + CBSVP8BoolDecoder bool_decoder; > + int err, pos; > + > + err = ff_cbs_alloc_unit_content(ctx, unit); > + if (err < 0) > + return err; > + frame = unit->content; > + > + // Create GetBitContext for uncompressed header. > + err = init_get_bits8_le(&gbc, unit->data, 8 * unit->data_size); > + if (err < 0) > + return err; > + > + err = cbs_vp8_read_uncompressed_header(ctx, &gbc, frame); > + if (err < 0) > + return err; > + > + pos = get_bits_count(&gbc); > + av_assert0(pos % 8 == 0); > + pos /= 8; > + av_assert0(pos <= unit->data_size); > + > + if (pos == unit->data_size) > + return AVERROR_INVALIDDATA; > + > + vp8->uncompressed_header_size = pos; > + > + // Create bool decoder for compressed header. > + err = cbs_vp8_bool_decoder_init( > + &bool_decoder, unit->data + pos, > + frame->header.first_partition_length_in_bytes); > + if (err < 0) > + return err; > + > + err = cbs_vp8_read_compressed_header(ctx, &bool_decoder, frame); > + if (err < 0) > + return err; > + > + pos = cbs_vp8_bool_decoder_bit_count(&bool_decoder); > + if (pos > bool_decoder.buffer_size * 8) > + return AVERROR_INVALIDDATA; > + > + frame->data_ref = av_buffer_ref(unit->data_ref); > + if (!frame->data_ref) > + return AVERROR(ENOMEM); > + > + frame->data = unit->data + pos; > + frame->data_size = unit->data_size - pos; > + > + return 0; > +} > + > +static int cbs_vp8_write_unit(CodedBitstreamContext *ctx, > + CodedBitstreamUnit *unit, PutBitContext > +*pbc) { > + return AVERROR_PATCHWELCOME; > +} > + > +static int cbs_vp8_assemble_fragment(CodedBitstreamContext *ctx, > + CodedBitstreamFragment *frag) { > + return AVERROR_PATCHWELCOME; > +} > + > +static void cbs_vp8_flush(CodedBitstreamContext *ctx) { > + // Do nothing. > +} > + > +static const CodedBitstreamUnitTypeDescriptor cbs_vp8_unit_types[] = { > + CBS_UNIT_TYPE_INTERNAL_REF(0, VP8RawFrame, data), > + CBS_UNIT_TYPE_END_OF_LIST, > +}; > + > +const CodedBitstreamType ff_cbs_type_vp8 = { > + .codec_id = AV_CODEC_ID_VP8, > + > + .priv_data_size = sizeof(CodedBitstreamVP8Context), > + > + .unit_types = cbs_vp8_unit_types, > + > + .split_fragment = &cbs_vp8_split_fragment, > + .read_unit = &cbs_vp8_read_unit, > + .write_unit = &cbs_vp8_write_unit, > + > + .flush = &cbs_vp8_flush, > + > + .assemble_fragment = &cbs_vp8_assemble_fragment, }; > diff --git a/libavcodec/cbs_vp8.h b/libavcodec/cbs_vp8.h new file mode > 100644 index 0000000000..4434251c09 > --- /dev/null > +++ b/libavcodec/cbs_vp8.h > @@ -0,0 +1,137 @@ > +/* > + * 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_CBS_VP8_H > +#define AVCODEC_CBS_VP8_H > + > +#include > +#include > + > +#include "cbs.h" > + > +enum { > + VP8_START_CODE_0 = 0x9D, > + VP8_START_CODE_1 = 0x01, > + VP8_START_CODE_2 = 0x2A, > +}; > + > +enum { > + VP8_KEY_FRAME = 0, > + VP8_NON_KEY_FRAME = 1, > +}; > + > +typedef struct VP8RawFrameHeader { > + // frame tag > + uint8_t frame_type; > + uint8_t profile; > + uint8_t show_frame; > + uint32_t first_partition_length_in_bytes; > + > + uint16_t width; > + uint8_t horizontal_scale; > + uint16_t height; > + uint8_t vertical_scale; > + > + // frame header > + uint8_t color_space; > + uint8_t clamping_type; > + > + // segmentation > + uint8_t segmentation_enable; > + uint8_t update_segment_map; > + uint8_t update_segment_feature_data; > + uint8_t segment_feature_mode; > + uint8_t segment_qp_update[4]; > + int8_t segment_qp[4]; > + uint8_t segment_loop_filter_level_update[4]; > + int8_t segment_loop_filter_level[4]; > + uint8_t segment_probs_update[3]; > + uint8_t segment_probs[3]; > + > + // loop filter > + uint8_t loop_filter_type; > + uint8_t loop_filter_level; > + uint8_t loop_filter_sharpness; > + uint8_t mode_ref_lf_delta_enable; > + uint8_t mode_ref_lf_delta_update; > + uint8_t ref_lf_deltas_update[4]; > + int8_t ref_lf_deltas[4]; > + uint8_t mode_lf_deltas_update[4]; > + int8_t mode_lf_deltas[4]; > + > + uint8_t log2_token_partitions; > + > + // qp > + uint8_t base_qindex; > + uint8_t y1dc_delta_q_present; > + int8_t y1dc_delta_q; > + uint8_t y2dc_delta_q_present; > + int8_t y2dc_delta_q; > + uint8_t y2ac_delta_q_present; > + int8_t y2ac_delta_q; > + uint8_t uvdc_delta_q_present; > + int8_t uvdc_delta_q; > + uint8_t uvac_delta_q_present; > + int8_t uvac_delta_q; > + > + // ref > + uint8_t refresh_golden_frame; > + uint8_t refresh_alternate_frame; > + uint8_t copy_buffer_to_golden; > + uint8_t copy_buffer_to_alternate; > + uint8_t ref_frame_sign_bias_golden; > + uint8_t ref_frame_sign_bias_alternate; > + uint8_t refresh_last_frame; > + > + uint8_t refresh_entropy_probs; > + > + // token probs > + uint8_t coeff_prob_update[4][8][3][11]; > + uint8_t coeff_prob[4][8][3][11]; > + > + uint8_t mb_no_skip_coeff; > + uint8_t prob_skip_false; > + > + uint8_t prob_intra; > + uint8_t prob_last; > + uint8_t prob_golden; > + > + uint8_t intra_16x16_prob_update; > + uint8_t intra_16x16_prob[4]; > + > + uint8_t intra_chrome_prob_update; > + uint8_t intra_chrome_prob[3]; > + > + // mv probs > + uint8_t mv_prob_update[2][19]; > + uint8_t mv_prob[2][19]; > +} VP8RawFrameHeader; > + > +typedef struct VP8RawFrame { > + VP8RawFrameHeader header; > + > + uint8_t *data; > + AVBufferRef *data_ref; > + size_t data_size; > +} VP8RawFrame; > + > +typedef struct CodedBitstreamVP8Context { > + uint32_t uncompressed_header_size; > +} CodedBitstreamVP8Context; > + > +#endif /* AVCODEC_CBS_VP8_H */ > diff --git a/libavcodec/cbs_vp8_syntax_template.c > b/libavcodec/cbs_vp8_syntax_template.c > new file mode 100644 > index 0000000000..0bdf699f39 > --- /dev/null > +++ b/libavcodec/cbs_vp8_syntax_template.c > @@ -0,0 +1,248 @@ > +/* > + * 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 */ > + > +static int FUNC(update_segmentation)(CodedBitstreamContext *ctx, > + CBSVP8BoolCodingRW *bool_coding_rw, > + VP8RawFrameHeader *current) { > + bc_f(1, update_segment_map); > + bc_f(1, update_segment_feature_data); > + > + if (current->update_segment_feature_data) { > + bc_f(1, segment_feature_mode); > + // quantizer > + for (int i = 0; i < 4; i++) { > + bc_b(segment_qp_update[i]); > + if (current->segment_qp_update[i]) > + bc_ss(7, segment_qp[i], 1, i); > + } > + // loop filter > + for (int i = 0; i < 4; i++) { > + bc_b(segment_loop_filter_level_update[i]); > + if (current->segment_loop_filter_level_update[i]) > + bc_ss(6, segment_loop_filter_level[i], 1, i); > + } > + } > + > + if (current->update_segment_map) { > + for (int i = 0; i < 3; i++) { > + bc_b(segment_probs_update[i]); > + if (current->segment_probs_update[i]) > + bc_fs(8, segment_probs[i], 1, i); > + } > + } > + > + return 0; > +} > + > +static int FUNC(mode_ref_lf_deltas)(CodedBitstreamContext *ctx, > + CBSVP8BoolCodingRW *bool_coding_rw, > + VP8RawFrameHeader *current) { > + bc_f(1, mode_ref_lf_delta_enable); > + if (current->mode_ref_lf_delta_enable) { > + bc_b(mode_ref_lf_delta_update); > + if (current->mode_ref_lf_delta_update) { > + // ref_lf_deltas > + for (int i = 0; i < 4; i++) { > + bc_b(ref_lf_deltas_update[i]); > + if (current->ref_lf_deltas_update[i]) > + bc_ss(6, ref_lf_deltas[i], 1, i); > + } > + // mode_lf_deltas > + for (int i = 0; i < 4; i++) { > + bc_b(mode_lf_deltas_update[i]); > + if (current->mode_lf_deltas_update[i]) > + bc_ss(6, mode_lf_deltas[i], 1, i); > + } > + } > + } > + > + return 0; > +} > + > +static int FUNC(quantization_params)(CodedBitstreamContext *ctx, > + CBSVP8BoolCodingRW *bool_coding_rw, > + VP8RawFrameHeader *current) { > + bc_f(7, base_qindex); > + > + bc_b(y1dc_delta_q_present); > + if (current->y1dc_delta_q_present) > + bc_s(4, y1dc_delta_q); > + > + bc_b(y2dc_delta_q_present); > + if (current->y2dc_delta_q_present) > + bc_s(4, y2dc_delta_q); > + > + bc_b(y2ac_delta_q_present); > + if (current->y2ac_delta_q_present) > + bc_s(4, y2ac_delta_q); > + > + bc_b(uvdc_delta_q_present); > + if (current->uvdc_delta_q_present) > + bc_s(4, uvdc_delta_q); > + > + bc_b(uvac_delta_q_present); > + if (current->uvac_delta_q_present) > + bc_s(4, uvac_delta_q); > + > + return 0; > +} > + > +static int FUNC(update_token_probs)(CodedBitstreamContext *ctx, > + CBSVP8BoolCodingRW *bool_coding_rw, > + VP8RawFrameHeader *current) { > + for (int i = 0; i < 4; ++i) { > + for (int j = 0; j < 8; ++j) { > + for (int k = 0; k < 3; ++k) { > + for (int l = 0; l < 11; ++l) { > + bc_b_prob(vp8_token_update_probs[i][j][k][l], > + coeff_prob_update[i][j][k][l]); > + if (current->coeff_prob_update[i][j][k][l]) > + bc_fs(8, coeff_prob[i][j][k][l], 4, i, j, k, l); > + } > + } > + } > + } > + > + return 0; > +} > + > +static int FUNC(update_mv_probs)(CodedBitstreamContext *ctx, > + CBSVP8BoolCodingRW *bool_coding_rw, > + VP8RawFrameHeader *current) { > + for (int i = 0; i < 2; ++i) { > + for (int j = 0; j < 19; ++j) { > + bc_b(mv_prob_update[i][j]); > + if (current->mv_prob_update[i][j]) > + bc_fs(7, mv_prob[i][j], 2, i, j); > + } > + } > + > + return 0; > +} > + > +static int FUNC(frame_tag)(CodedBitstreamContext *ctx, RWContext *rw, > + VP8RawFrameHeader *current) { > + f(1, frame_type); > + f(3, profile); > + f(1, show_frame); > + f(19, first_partition_length_in_bytes); > + > + if (current->frame_type == VP8_KEY_FRAME) { > + fixed(8, start_code_0, VP8_START_CODE_0); > + fixed(8, start_code_1, VP8_START_CODE_1); > + fixed(8, start_code_2, VP8_START_CODE_2); > + > + f(14, width); > + f(2, horizontal_scale); > + f(14, height); > + f(2, vertical_scale); > + } > + > + return 0; > +} > + > +static int FUNC(frame_header)(CodedBitstreamContext *ctx, > + CBSVP8BoolCodingRW *bool_coding_rw, > + VP8RawFrameHeader *current) { > + if (current->frame_type == VP8_KEY_FRAME) { > + bc_f(1, color_space); > + bc_f(1, clamping_type); > + } > + > + bc_f(1, segmentation_enable); > + if (current->segmentation_enable) > + CHECK(FUNC(update_segmentation)(ctx, bool_coding_rw, current)); > + > + bc_f(1, loop_filter_type); > + bc_f(6, loop_filter_level); > + bc_f(3, loop_filter_sharpness); > + > + CHECK(FUNC(mode_ref_lf_deltas)(ctx, bool_coding_rw, current)); > + > + bc_f(2, log2_token_partitions); > + > + CHECK(FUNC(quantization_params)(ctx, bool_coding_rw, current)); > + > + if (current->frame_type != VP8_KEY_FRAME) { > + bc_f(1, refresh_golden_frame); > + bc_f(1, refresh_alternate_frame); > + if (!current->refresh_golden_frame) > + bc_f(2, copy_buffer_to_golden); > + if (!current->refresh_alternate_frame) > + bc_f(2, copy_buffer_to_alternate); > + bc_f(1, ref_frame_sign_bias_golden); > + bc_f(1, ref_frame_sign_bias_alternate); > + } > + bc_f(1, refresh_entropy_probs); > + if (current->frame_type != VP8_KEY_FRAME) > + bc_f(1, refresh_last_frame); > + > + CHECK(FUNC(update_token_probs)(ctx, bool_coding_rw, current)); > + > + bc_f(1, mb_no_skip_coeff); > + if (current->mb_no_skip_coeff) > + bc_f(8, prob_skip_false); > + > + if (current->frame_type != VP8_KEY_FRAME) { > + bc_f(8, prob_intra); > + bc_f(8, prob_last); > + bc_f(8, prob_golden); > + > + // intra_16x16_prob > + bc_b(intra_16x16_prob_update); > + if (current->intra_16x16_prob_update) > + for (int i = 0; i < 4; i++) > + bc_fs(8, intra_16x16_prob[i], 1, i); > + > + // intra_chroma_prob > + bc_b(intra_chrome_prob_update); > + if (current->intra_chrome_prob_update) > + for (int i = 0; i < 3; i++) > + bc_fs(8, intra_chrome_prob[i], 1, i); > + > + CHECK(FUNC(update_mv_probs)(ctx, bool_coding_rw, current)); > + } > + > + return 0; > +} > + > +static int FUNC(uncompressed_header)(CodedBitstreamContext *ctx, > RWContext *rw, > + VP8RawFrame *current) { > + HEADER("Frame"); > + > + CHECK(FUNC(frame_tag)(ctx, rw, ¤t->header)); > + > + return 0; > +} > + > +static int FUNC(compressed_header)(CodedBitstreamContext *ctx, > + CBSVP8BoolCodingRW *bool_coding_rw, > + VP8RawFrame *current) { > + CHECK(FUNC(frame_header)(ctx, bool_coding_rw, ¤t->header)); > + > + return 0; > +} @Andreas Rheinhardt Fixed all the commentary of PATCH v3, please take a look. Thanks. > -- > 2.25.1 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org > with subject "unsubscribe". _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".