Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH v9 03/13] vvcdec: add cabac decoder
Date: Mon, 1 Jan 2024 18:34:59 +0100
Message-ID: <20240101173459.GV6420@pb2> (raw)
In-Reply-To: <TYSPR06MB64337C13ECE97978A56C1152AA62A@TYSPR06MB6433.apcprd06.prod.outlook.com>


[-- Attachment #1.1: Type: text/plain, Size: 7343 bytes --]

On Mon, Jan 01, 2024 at 10:12:29PM +0800, Nuo Mi wrote:
> add Context-based Adaptive Binary Arithmetic Coding (CABAC) decoder
> 
> Co-authored-by: Xu Mu <toxumu@outlook.com>
> Co-authored-by: Frank Plowman <post@frankplowman.com>
> Co-authored-by: Shaun Loo <shaunloo10@gmail.com>
> Co-authored-by: Wu Jianhua <toqsxw@outlook.com>
> ---
>  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, ResidualCoding* rc, const int i)
> +{
> +    const CodingUnit *cu   = lc->cu;
> +    TransformBlock *tb     = rc->tb;
> +    const int bdpcm_flag   = cu->bdpcm_flag[tb->c_idx];
> +    const int xs           = rc->sb_scan_x_off[i];
> +    const int ys           = rc->sb_scan_y_off[i];
> +    uint8_t *sb_coded_flag = rc->sb_coded_flag + ys * rc->width_in_sbs + xs;
> +    int infer_sb_sig_coeff_flag = 1;
> +    int last_scan_pos_pass1 = -1, last_scan_pos_pass2 = -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 != rc->last_sub_block || !rc->infer_sb_cbf)
> +        *sb_coded_flag = sb_coded_flag_decode(lc, sb_coded_flag, rc, xs, ys);
> +    else
> +        *sb_coded_flag = 1;
> +    if (*sb_coded_flag && i < rc->last_sub_block)
> +        rc->infer_sb_cbf = 0;
> +
> +    //first scan pass
> +    for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) {
> +        const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
> +        const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
> +        const int off = yc * tb->tb_width + xc;
> +        int *sig_coeff_flag   = rc->sig_coeff_flag + off;
> +        int *abs_level_pass1  = rc->abs_level_pass1 + off;
> +        int *coeff_sign_level = rc->coeff_sign_level + off;
> +        int par_level_flag    = 0;
> +
> +        abs_level_gtx_flag[n] = 0;
> +        last_scan_pos_pass1 = n;
> +        if (*sb_coded_flag && (n != rc->num_sb_coeff - 1 || !infer_sb_sig_coeff_flag)) {
> +            *sig_coeff_flag = sig_coeff_flag_decode(lc, rc, xc, yc);
> +            rc->rem_bins_pass1--;
> +            if (*sig_coeff_flag)
> +                infer_sb_sig_coeff_flag = 0;
> +        } else {
> +            *sig_coeff_flag = (n == rc->num_sb_coeff - 1) && infer_sb_sig_coeff_flag && *sb_coded_flag;
> +        }
> +        *coeff_sign_level = 0;
> +        if (*sig_coeff_flag) {
> +            *coeff_sign_level = 1 - 2 * coeff_sign_flag_ts_decode(lc, cu, rc, xc, yc);
> +            abs_level_gtx_flag[n] = abs_level_gt1_flag_ts_decode(lc, cu, rc, xc, yc);
> +            rc->rem_bins_pass1 -= 2;
> +            if (abs_level_gtx_flag[n]) {
> +                par_level_flag = par_level_flag_ts_decode(lc);
> +                rc->rem_bins_pass1--;
> +            }
> +        }
> +        *abs_level_pass1 = *sig_coeff_flag + par_level_flag + abs_level_gtx_flag[n];
> +    }
> +
> +    //greater than x scan pass
> +    for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) {
> +        const int xc  = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
> +        const int yc  = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
> +        const int off = yc * tb->tb_width + xc;
> +
> +        abs_level_pass2[n] = rc->abs_level_pass1[off];
> +        for (int j = 1; j < 5 && abs_level_gtx_flag[n]; j++) {
> +            abs_level_gtx_flag[n] = abs_level_gtx_flag_ts_decode(lc, j);
> +            abs_level_pass2[n] += abs_level_gtx_flag[n] << 1;
> +            rc->rem_bins_pass1--;
> +        }
> +        last_scan_pos_pass2 = n;
> +    }
> +
> +    /* remainder scan pass */
> +    for (n = 0; n < rc->num_sb_coeff; n++) {
> +        const int xc  = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
> +        const int yc  = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
> +        const int off = yc * tb->tb_width + xc;
> +        const int *abs_level_pass1 = rc->abs_level_pass1 + off;
> +        int *abs_level             = rc->abs_level + off;
> +        int *coeff_sign_level      = rc->coeff_sign_level + off;
> +        int abs_remainder          = 0;
> +
> +        if ((n <= last_scan_pos_pass2 && abs_level_pass2[n] >= 10) ||
> +            (n > last_scan_pos_pass2 && n <= last_scan_pos_pass1 &&
> +            *abs_level_pass1 >= 2) ||
> +            (n > last_scan_pos_pass1 &&  *sb_coded_flag))
> +            abs_remainder = abs_remainder_ts_decode(lc, rc, xc, yc);
> +        if (n <= last_scan_pos_pass2) {
> +            *abs_level = abs_level_pass2[n] + 2 * abs_remainder;
> +        } else if (n <= last_scan_pos_pass1) {
> +            *abs_level = *abs_level_pass1 + 2 * abs_remainder;
> +        } else {
> +            *abs_level = abs_remainder;
> +            if (abs_remainder) {
> +                //n > lastScanPosPass1
> +                *coeff_sign_level = 1 - 2 * coeff_sign_flag_decode(lc);
> +            }
> +        }
> +        if (!bdpcm_flag && n <= last_scan_pos_pass1) {
> +            const int left  = xc > 0 ? abs_level[-1] : 0;
> +            const int above = yc > 0 ? abs_level[-tb->tb_width] : 0;
> +            const int pred  = FFMAX(left, above);
> +
> +            if (*abs_level == 1 && pred > 0)
> +                *abs_level = pred;
> +            else if (*abs_level > 0 && *abs_level <= pred)
> +                (*abs_level)--;
> +        }

> +        if (*abs_level) {
> +            tb->coeffs[off] = *coeff_sign_level * *abs_level;
> +            tb->max_scan_x = FFMAX(xc, tb->max_scan_x);
> +            tb->max_scan_y = FFMAX(yc, tb->max_scan_y);
> +            tb->min_scan_x = FFMIN(xc, tb->min_scan_x);
> +            tb->min_scan_y = FFMIN(yc, tb->min_scan_y);
> +        } else {
> +            tb->coeffs[off] = 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 well
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 branch for
non zero coefficients.

and for transform it knowing for example that rows 1 and 3 are all 0 is probably
more usefull than knowing that all non zero elements are in rows 0-2

thx

[...]
-- 
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.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

  parent reply	other threads:[~2024-01-01 17:35 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240101141239.6623-1-nuomi2021@gmail.com>
2024-01-01 14:12 ` [FFmpeg-devel] [PATCH v9 01/13] vvcdec: add vvc_data Nuo Mi
2024-01-01 14:12 ` [FFmpeg-devel] [PATCH v9 02/13] vvcdec: add parameter parser for sps, pps, ph, sh Nuo Mi
2024-01-01 14:12 ` [FFmpeg-devel] [PATCH v9 03/13] vvcdec: add cabac decoder Nuo Mi
2024-01-01 15:13   ` Lynne
2024-01-02 13:21     ` Nuo Mi
2024-01-02 15:57       ` Lynne
2024-01-03  1:38         ` Nuo Mi
2024-01-01 17:34   ` Michael Niedermayer [this message]
2024-01-02 13:44     ` Nuo Mi
2024-01-01 14:12 ` [FFmpeg-devel] [PATCH v9 04/13] vvcdec: add reference management Nuo Mi
2024-01-01 14:12 ` [FFmpeg-devel] [PATCH v9 05/13] vvcdec: add motion vector decoder Nuo Mi
2024-01-01 14:12 ` [FFmpeg-devel] [PATCH v9 06/13] vvcdec: add inter prediction Nuo Mi
2024-01-01 15:04   ` Lynne
2024-01-02 14:16     ` Nuo Mi
2024-01-02 14:30       ` Kieran Kunhya
2024-01-02 15:59       ` Lynne
2024-01-01 14:12 ` [FFmpeg-devel] [PATCH v9 07/13] vvcdec: add inv transform 1d Nuo Mi
2024-01-01 14:50   ` Lynne
2024-01-02 13:01     ` Nuo Mi
2024-01-02 15:55       ` Lynne
2024-01-03 12:04         ` Nuo Mi
2024-01-01 14:12 ` [FFmpeg-devel] [PATCH v9 08/13] vvcdec: add intra prediction Nuo Mi
2024-01-01 14:12 ` [FFmpeg-devel] [PATCH v9 09/13] vvcdec: add LMCS, Deblocking, SAO, and ALF filters Nuo Mi
2024-01-01 15:17   ` Lynne
2024-01-02  9:47     ` Nuo Mi
2024-01-02 11:38       ` Jean-Baptiste Kempf
2024-01-02 15:51       ` Lynne
2024-01-03  1:14         ` Nuo Mi
2024-01-03 18:38       ` Michael Niedermayer
2024-01-04 11:45         ` Nuo Mi
2024-01-04 12:06           ` Martin Storsjö
2024-01-04 13:57             ` Nuo Mi
2024-01-04 14:53               ` James Almer
2024-01-05  0:02                 ` Nuo Mi
2024-01-05 11:55                 ` Martin Storsjö
2024-01-05 20:47                   ` Michael Niedermayer
2024-01-01 14:12 ` [FFmpeg-devel] [PATCH v9 10/13] vvcdec: add dsp init and inv transform Nuo Mi
2024-01-01 14:12 ` [FFmpeg-devel] [PATCH v9 11/13] vvcdec: add CTU parser Nuo Mi
2024-01-01 14:12 ` [FFmpeg-devel] [PATCH v9 12/13] vvcdec: add CTU thread logical Nuo Mi
2024-01-01 14:12 ` [FFmpeg-devel] [PATCH v9 13/13] vvcdec: add vvc decoder Nuo Mi
2024-01-01 14:53   ` Lynne
2024-01-01 15:14     ` Hendrik Leppkes
2024-01-01 15:22       ` Lynne
2024-01-02  9:38         ` Nuo Mi
2024-01-02 11:41           ` Jean-Baptiste Kempf
2024-01-02 16:00           ` Lynne
2024-01-05 20:48   ` James Almer
2024-01-06 17:47   ` James Almer
2024-01-07  5:31     ` Nuo Mi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240101173459.GV6420@pb2 \
    --to=michael@niedermayer.cc \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git