From patchwork Sun Jun 9 08:25:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= X-Patchwork-Id: 49726 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:c209:0:b0:460:55fa:d5ed with SMTP id d9csp1911603vqo; Sun, 9 Jun 2024 01:25:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXsjPiWBh3IBj14H2kiZBurho2UFgW7WQKLcT1FqHyGTNw8S2ODgVtqwXNbK0fjUPR96nZ6SUial9P0qMcb9B08c7Z8QC726p25zA== X-Google-Smtp-Source: AGHT+IHRR+g/wzIUkatjNPich2cpKdnmJjvSj4gEGuf+2z2jVvdicpnk7lTedbGb+Upu7ck6k392 X-Received: by 2002:a17:906:8419:b0:a6f:1cf1:f13b with SMTP id a640c23a62f3a-a6f1cf1f395mr25578066b.61.1717921536267; Sun, 09 Jun 2024 01:25:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717921536; cv=none; d=google.com; s=arc-20160816; b=donpKmVUBKJMcrAcTI1dmh9HujReKbo1dMhTfF8v36KF+EuulWtPTHp8K46yIx92Sg NxAUnZsVbbX7OgbCEsq515UkxqPHYdca5Vu8Zq1HBuiv8tVruTxgiul298IvCU15xrv1 7aWwRvvVZzMitvB1//abntGvnlwlqDrjYKe/Sku8mMoyGJQ4BLzgH+hXbV83/kfHM/d9 XFpGMtMtaPxF/B9O2FROcEjvGBPEvPJtLdfoaFQHYHJ5tVLtOCSzl2beWDI8/Zkl69fu 5nR3UxFAzJRq3A95OhOezrUylAXvdiRkgFZO302RtvvVxtedG1QUNJL+MXdXqNn+wJnO zupQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=TpmctuK2MqwkwO2TJZgKy5tC2y/NLmJzFldlyfBv1nk=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=BOMAflGPfJxmM3CsAlX4gUcbA23fU62RqOLGOdSec8gN6UKsa3aec+EuGO2DQQq+GR Y/ELRaRCYFoqPsNbNyyth87pS09lXLl5BqL/lIbhO82x6todTMOP4G+Xn8qiCwYm9PA0 lNyhG3eIm2euJHe1IUP+uIDa3JZ7xQRB26HVjg721EtC90phoYSYn289jn/E40hbuzrl jb/IKDRqLSqUsnazjnOsLmCYYT1MGiwz4SofxVH1s5/cFQvh6T3saYAah0BDlbtmFizy a9wEOtZe1X4J/qja1shxbpDN0hqKfbE2ZwSSECSc8r21J438vKKz5XV1g/4s+FDtjusm QU9Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-57c6b0a4257si1503209a12.169.2024.06.09.01.25.35; Sun, 09 Jun 2024 01:25:36 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 74BC968D757; Sun, 9 Jun 2024 11:25:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ursule.remlab.net (vps-a2bccee9.vps.ovh.net [51.75.19.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1F90168D6C0 for ; Sun, 9 Jun 2024 11:25:16 +0300 (EEST) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id 85638C009A for ; Sun, 9 Jun 2024 11:25:15 +0300 (EEST) From: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Jun 2024 11:25:13 +0300 Message-ID: <20240609082515.1325134-2-remi@remlab.net> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240609082515.1325134-1-remi@remlab.net> References: <20240609082515.1325134-1-remi@remlab.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] lavc/mpvenc: reorder code 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: H9AeO5rxIXz5 No functional changes. --- libavcodec/mpegvideo_enc.c | 166 ++++++++++++++++++------------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 82bab43e14..dd92f0a3af 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -246,6 +246,89 @@ void ff_init_qscale_tab(MpegEncContext *s) } } +int ff_dct_quantize_c(MpegEncContext *s, + int16_t *block, int n, + int qscale, int *overflow) +{ + int i, j, level, last_non_zero, q, start_i; + const int *qmat; + const uint8_t *scantable; + int bias; + int max=0; + unsigned int threshold1, threshold2; + + s->fdsp.fdct(block); + + if(s->dct_error_sum) + s->denoise_dct(s, block); + + if (s->mb_intra) { + scantable= s->intra_scantable.scantable; + if (!s->h263_aic) { + if (n < 4) + q = s->y_dc_scale; + else + q = s->c_dc_scale; + q = q << 3; + } else + /* For AIC we skip quant/dequant of INTRADC */ + q = 1 << 3; + + /* note: block[0] is assumed to be positive */ + block[0] = (block[0] + (q >> 1)) / q; + start_i = 1; + last_non_zero = 0; + qmat = n < 4 ? s->q_intra_matrix[qscale] : s->q_chroma_intra_matrix[qscale]; + bias= s->intra_quant_bias*(1<<(QMAT_SHIFT - QUANT_BIAS_SHIFT)); + } else { + scantable= s->inter_scantable.scantable; + start_i = 0; + last_non_zero = -1; + qmat = s->q_inter_matrix[qscale]; + bias= s->inter_quant_bias*(1<<(QMAT_SHIFT - QUANT_BIAS_SHIFT)); + } + threshold1= (1<=start_i;i--) { + j = scantable[i]; + level = block[j] * qmat[j]; + + if(((unsigned)(level+threshold1))>threshold2){ + last_non_zero = i; + break; + }else{ + block[j]=0; + } + } + for(i=start_i; i<=last_non_zero; i++) { + j = scantable[i]; + level = block[j] * qmat[j]; + +// if( bias+level >= (1<= (1<threshold2){ + if(level>0){ + level= (bias + level)>>QMAT_SHIFT; + block[j]= level; + }else{ + level= (bias - level)>>QMAT_SHIFT; + block[j]= -level; + } + max |=level; + }else{ + block[j]=0; + } + } + *overflow= s->max_qcoeff < max; //overflow might have happened + + /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */ + if (s->idsp.perm_type != FF_IDCT_PERM_NONE) + ff_block_permute(block, s->idsp.idct_permutation, + scantable, last_non_zero); + + return last_non_zero; +} + static void update_duplicate_context_after_me(MpegEncContext *dst, const MpegEncContext *src) { @@ -4565,86 +4648,3 @@ void ff_block_permute(int16_t *block, uint8_t *permutation, block[perm_j] = temp[j]; } } - -int ff_dct_quantize_c(MpegEncContext *s, - int16_t *block, int n, - int qscale, int *overflow) -{ - int i, j, level, last_non_zero, q, start_i; - const int *qmat; - const uint8_t *scantable; - int bias; - int max=0; - unsigned int threshold1, threshold2; - - s->fdsp.fdct(block); - - if(s->dct_error_sum) - s->denoise_dct(s, block); - - if (s->mb_intra) { - scantable= s->intra_scantable.scantable; - if (!s->h263_aic) { - if (n < 4) - q = s->y_dc_scale; - else - q = s->c_dc_scale; - q = q << 3; - } else - /* For AIC we skip quant/dequant of INTRADC */ - q = 1 << 3; - - /* note: block[0] is assumed to be positive */ - block[0] = (block[0] + (q >> 1)) / q; - start_i = 1; - last_non_zero = 0; - qmat = n < 4 ? s->q_intra_matrix[qscale] : s->q_chroma_intra_matrix[qscale]; - bias= s->intra_quant_bias*(1<<(QMAT_SHIFT - QUANT_BIAS_SHIFT)); - } else { - scantable= s->inter_scantable.scantable; - start_i = 0; - last_non_zero = -1; - qmat = s->q_inter_matrix[qscale]; - bias= s->inter_quant_bias*(1<<(QMAT_SHIFT - QUANT_BIAS_SHIFT)); - } - threshold1= (1<=start_i;i--) { - j = scantable[i]; - level = block[j] * qmat[j]; - - if(((unsigned)(level+threshold1))>threshold2){ - last_non_zero = i; - break; - }else{ - block[j]=0; - } - } - for(i=start_i; i<=last_non_zero; i++) { - j = scantable[i]; - level = block[j] * qmat[j]; - -// if( bias+level >= (1<= (1<threshold2){ - if(level>0){ - level= (bias + level)>>QMAT_SHIFT; - block[j]= level; - }else{ - level= (bias - level)>>QMAT_SHIFT; - block[j]= -level; - } - max |=level; - }else{ - block[j]=0; - } - } - *overflow= s->max_qcoeff < max; //overflow might have happened - - /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */ - if (s->idsp.perm_type != FF_IDCT_PERM_NONE) - ff_block_permute(block, s->idsp.idct_permutation, - scantable, last_non_zero); - - return last_non_zero; -}