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 2971448ADC for ; Mon, 1 Jan 2024 17:35:12 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5336668CFCC; Mon, 1 Jan 2024 19:35:10 +0200 (EET) Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 31E0668CE3D for ; Mon, 1 Jan 2024 19:35:04 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 6185FE0002 for ; Mon, 1 Jan 2024 17:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1704130503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=WdLJ2T5Xc9euJZe+CzNCaK4KQqL9UAvMdv+54Ca1reQ=; b=GulHLUw9TRhnc+gzEUMCV4y7ncvLxqDklm442TcnCKtRaVH+a7A6+2DzAQjQBMYqva/BGT GlijOS83LJcSNtcmCdupU9pzBulaACpYJZjHJj1nPIbVYp6VyzeG1Kd8GjHMqeFpte1eRj 83mrXY3wPJntei2aoAS2JMNR0Z6De0sbJm5MZ91dI5nCn+Y1R5nsptDntgjc1iS5EVEI9A Mu6BgaPGGKaU7ECNYOac2tUYbfp5VP20d0Z+Cj1PG6NQEZefSJEaKk0JnPR+XBx0cZkQ/E ZN3wKSLMh3w9GY1D0+T/pWGPOz36Bo+4QMFV108BQByosoiGBii0KM0FkD8u+A== Date: Mon, 1 Jan 2024 18:34:59 +0100 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20240101173459.GV6420@pb2> References: <20240101141239.6623-1-nuomi2021@gmail.com> MIME-Version: 1.0 In-Reply-To: X-GND-Sasl: michael@niedermayer.cc Subject: Re: [FFmpeg-devel] [PATCH v9 03/13] vvcdec: add cabac 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 Content-Type: multipart/mixed; boundary="===============8893059089724564043==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============8893059089724564043== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="vPUQSeIDJYHeNf1K" Content-Disposition: inline --vPUQSeIDJYHeNf1K Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jan 01, 2024 at 10:12:29PM +0800, Nuo Mi wrote: > add Context-based Adaptive Binary Arithmetic Coding (CABAC) decoder >=20 > Co-authored-by: Xu Mu > Co-authored-by: Frank Plowman > Co-authored-by: Shaun Loo > Co-authored-by: Wu Jianhua > --- > libavcodec/vvc/Makefile | 4 +- > libavcodec/vvc/vvc_cabac.c | 2478 ++++++++++++++++++++++++++++++++++++ > libavcodec/vvc/vvc_cabac.h | 126 ++ > libavcodec/vvc/vvc_ctu.c | 32 + > libavcodec/vvc/vvc_ctu.h | 464 +++++++ > libavcodec/vvc/vvcdec.h | 7 + > 6 files changed, 3110 insertions(+), 1 deletion(-) > create mode 100644 libavcodec/vvc/vvc_cabac.c > create mode 100644 libavcodec/vvc/vvc_cabac.h > create mode 100644 libavcodec/vvc/vvc_ctu.c > create mode 100644 libavcodec/vvc/vvc_ctu.h [...] > +static int residual_ts_coding_subblock(VVCLocalContext *lc, ResidualCodi= ng* rc, const int i) > +{ > + const CodingUnit *cu =3D lc->cu; > + TransformBlock *tb =3D rc->tb; > + const int bdpcm_flag =3D cu->bdpcm_flag[tb->c_idx]; > + const int xs =3D rc->sb_scan_x_off[i]; > + const int ys =3D rc->sb_scan_y_off[i]; > + uint8_t *sb_coded_flag =3D rc->sb_coded_flag + ys * rc->width_in_sbs= + xs; > + int infer_sb_sig_coeff_flag =3D 1; > + int last_scan_pos_pass1 =3D -1, last_scan_pos_pass2 =3D -1, n; > + int abs_level_gtx_flag[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE]; > + int abs_level_pass2[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE]; = ///< AbsLevelPass2 > + > + if (i !=3D rc->last_sub_block || !rc->infer_sb_cbf) > + *sb_coded_flag =3D sb_coded_flag_decode(lc, sb_coded_flag, rc, x= s, ys); > + else > + *sb_coded_flag =3D 1; > + if (*sb_coded_flag && i < rc->last_sub_block) > + rc->infer_sb_cbf =3D 0; > + > + //first scan pass > + for (n =3D 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >=3D 4; n++= ) { > + const int xc =3D (xs << rc->log2_sb_w) + rc->scan_x_off[n]; > + const int yc =3D (ys << rc->log2_sb_h) + rc->scan_y_off[n]; > + const int off =3D yc * tb->tb_width + xc; > + int *sig_coeff_flag =3D rc->sig_coeff_flag + off; > + int *abs_level_pass1 =3D rc->abs_level_pass1 + off; > + int *coeff_sign_level =3D rc->coeff_sign_level + off; > + int par_level_flag =3D 0; > + > + abs_level_gtx_flag[n] =3D 0; > + last_scan_pos_pass1 =3D n; > + if (*sb_coded_flag && (n !=3D rc->num_sb_coeff - 1 || !infer_sb_= sig_coeff_flag)) { > + *sig_coeff_flag =3D sig_coeff_flag_decode(lc, rc, xc, yc); > + rc->rem_bins_pass1--; > + if (*sig_coeff_flag) > + infer_sb_sig_coeff_flag =3D 0; > + } else { > + *sig_coeff_flag =3D (n =3D=3D rc->num_sb_coeff - 1) && infer= _sb_sig_coeff_flag && *sb_coded_flag; > + } > + *coeff_sign_level =3D 0; > + if (*sig_coeff_flag) { > + *coeff_sign_level =3D 1 - 2 * coeff_sign_flag_ts_decode(lc, = cu, rc, xc, yc); > + abs_level_gtx_flag[n] =3D abs_level_gt1_flag_ts_decode(lc, c= u, rc, xc, yc); > + rc->rem_bins_pass1 -=3D 2; > + if (abs_level_gtx_flag[n]) { > + par_level_flag =3D par_level_flag_ts_decode(lc); > + rc->rem_bins_pass1--; > + } > + } > + *abs_level_pass1 =3D *sig_coeff_flag + par_level_flag + abs_leve= l_gtx_flag[n]; > + } > + > + //greater than x scan pass > + for (n =3D 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >=3D 4; n++= ) { > + const int xc =3D (xs << rc->log2_sb_w) + rc->scan_x_off[n]; > + const int yc =3D (ys << rc->log2_sb_h) + rc->scan_y_off[n]; > + const int off =3D yc * tb->tb_width + xc; > + > + abs_level_pass2[n] =3D rc->abs_level_pass1[off]; > + for (int j =3D 1; j < 5 && abs_level_gtx_flag[n]; j++) { > + abs_level_gtx_flag[n] =3D abs_level_gtx_flag_ts_decode(lc, j= ); > + abs_level_pass2[n] +=3D abs_level_gtx_flag[n] << 1; > + rc->rem_bins_pass1--; > + } > + last_scan_pos_pass2 =3D n; > + } > + > + /* remainder scan pass */ > + for (n =3D 0; n < rc->num_sb_coeff; n++) { > + const int xc =3D (xs << rc->log2_sb_w) + rc->scan_x_off[n]; > + const int yc =3D (ys << rc->log2_sb_h) + rc->scan_y_off[n]; > + const int off =3D yc * tb->tb_width + xc; > + const int *abs_level_pass1 =3D rc->abs_level_pass1 + off; > + int *abs_level =3D rc->abs_level + off; > + int *coeff_sign_level =3D rc->coeff_sign_level + off; > + int abs_remainder =3D 0; > + > + if ((n <=3D last_scan_pos_pass2 && abs_level_pass2[n] >=3D 10) || > + (n > last_scan_pos_pass2 && n <=3D last_scan_pos_pass1 && > + *abs_level_pass1 >=3D 2) || > + (n > last_scan_pos_pass1 && *sb_coded_flag)) > + abs_remainder =3D abs_remainder_ts_decode(lc, rc, xc, yc); > + if (n <=3D last_scan_pos_pass2) { > + *abs_level =3D abs_level_pass2[n] + 2 * abs_remainder; > + } else if (n <=3D last_scan_pos_pass1) { > + *abs_level =3D *abs_level_pass1 + 2 * abs_remainder; > + } else { > + *abs_level =3D abs_remainder; > + if (abs_remainder) { > + //n > lastScanPosPass1 > + *coeff_sign_level =3D 1 - 2 * coeff_sign_flag_decode(lc); > + } > + } > + if (!bdpcm_flag && n <=3D last_scan_pos_pass1) { > + const int left =3D xc > 0 ? abs_level[-1] : 0; > + const int above =3D yc > 0 ? abs_level[-tb->tb_width] : 0; > + const int pred =3D FFMAX(left, above); > + > + if (*abs_level =3D=3D 1 && pred > 0) > + *abs_level =3D pred; > + else if (*abs_level > 0 && *abs_level <=3D pred) > + (*abs_level)--; > + } > + if (*abs_level) { > + tb->coeffs[off] =3D *coeff_sign_level * *abs_level; > + tb->max_scan_x =3D FFMAX(xc, tb->max_scan_x); > + tb->max_scan_y =3D FFMAX(yc, tb->max_scan_y); > + tb->min_scan_x =3D FFMIN(xc, tb->min_scan_x); > + tb->min_scan_y =3D FFMIN(yc, tb->min_scan_y); > + } else { > + tb->coeffs[off] =3D 0; > + } Is this just for optimization ? computing the max/min x/y indexes of non zero coeffs to later only process them is likely more expensive than to just do the dequantization here where= its known what is non zero, also probably the non zero coeffs do not cluster we= ll in a rectangle so there will likely still be alot of 0 in that If this is just for optimization, its a strange direction at such an early = stage dequantization can be done directly here when we already have a seperate br= anch for non zero coefficients. and for transform it knowing for example that rows 1 and 3 are all 0 is pro= bably more usefull than knowing that all non zero elements are in rows 0-2 thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Many things microsoft did are stupid, but not doing something just because microsoft did it is even more stupid. If everything ms did were stupid they would be bankrupt already. --vPUQSeIDJYHeNf1K Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZZL3vwAKCRBhHseHBAsP q22IAKCOIHy3rEvT8bsSYiplldEr/tHzkgCgidjxATmZ2tbEvK3zHsUvotpeUIM= =jnQ0 -----END PGP SIGNATURE----- --vPUQSeIDJYHeNf1K-- --===============8893059089724564043== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============8893059089724564043==--