From patchwork Fri Jun 7 13:01:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 49644 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:c209:0:b0:460:55fa:d5ed with SMTP id d9csp1009135vqo; Fri, 7 Jun 2024 06:05:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU6kWpecvFwm6M/HUlIpeVpY0s0OkFE7GqryQQ0rRk3WlBsCWXQ8oQmFAwVmQVusFWzqWGN26CVuFh9+2kKi4SG69NF1oYrip69IQ== X-Google-Smtp-Source: AGHT+IGTW5eQsMMUQPBK/asHMJKTg9Nxc3y212gL0IWJ9n98oleMtmn2k1zBUeonaWS6XyHbhcp0 X-Received: by 2002:a17:906:aec4:b0:a68:a811:d18b with SMTP id a640c23a62f3a-a6cdb9dc920mr157845566b.5.1717765504507; Fri, 07 Jun 2024 06:05:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717765504; cv=none; d=google.com; s=arc-20160816; b=bN0wGu6+ANo31NvTWMw9je4tRTp5NqRrFrx6AAsQPy+864V+9sFaiE40lcuRt9HN3D sj72vw2wPNObExPwgkGblldr95NhDS11XJYIcsb3cfgErql5giCoUOzCrin1NtDcM2GH ek+f818VSuwWKVZ14SkhmTH8443kWH8zWvfoXOk0MQagw0Ng3NxIui1q0ESI9eM+e3HJ DRckyW7JnUYYfPLQA/AsoV8NfB5Ll/bXInys5P6eExO02zHsuGijAYr6F4Qtr6weItkS gcsuj7Gd/CPU8NqUMzuCL5oK6Hg8zFkipwvtiGQz/zz65q6QEMFqATjrhj05svvzOc73 nzyg== 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:dkim-signature:delivered-to; bh=EE54r4WtEhok/4/2y9NPGUG2zrIIinM+cyy1YlLVB8U=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Lwdp3qp8Z+dEZZcqn7hNtQh277dgHldA2Kytb2DKrRqNUd+UgMjS9v4w1hzELii5Lu lQemeluYb3q6Sdk0HBmMlrz7BDKMdU7J9FqpgWi9frfvDUBI/QUpqJ7w0SijtWgQRfpE MIceKuUYoZirr2pe/6i+MwRH5svPQpKRPcofqqvpvtMe14uB4IWKAQROhqXADbUj7EDh RcerrpsHV3j2IOPscZZrMj+5i+gMLhTe/vVi1CmXpRhkE0wvKFo5u4XiEiyvthIskUlp zwMEcD3eOJlQTwETwmjEtd0bp8NdRRm/oGuDtHORa6aBS72JWPQ4hDDxSbnEgPKpgYSS /MmA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=T7ysK0u6; 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 a640c23a62f3a-a6c806db07dsi173408466b.446.2024.06.07.06.05.03; Fri, 07 Jun 2024 06:05:04 -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=@khirnov.net header.s=mail header.b=T7ysK0u6; 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 4B72368D70F; Fri, 7 Jun 2024 16:03:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2157068D76E for ; Fri, 7 Jun 2024 16:03:50 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=T7ysK0u6; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 80A6B4DE6 for ; Fri, 7 Jun 2024 15:03:47 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 0f_vR2CQ1prL for ; Fri, 7 Jun 2024 15:03:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1717765422; bh=tBb/a32JZxRSzIW3a02v3Jj5s+4yhB/yzl3JmkhNac8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=T7ysK0u6ty02vo9r/1KMBxoPHcIgDat5yKurBlHq2XrgX/6rYfh3ChsyyhOuOkQQK GC05GDl/AWGQt/4Z9iTond3WGzGzxsbA7zxoVHjvu8uhz0Fmmrf1Dk/RyO8huF8Wdz qUb6ycVhklU/9PytkZ9+b8i1AIFGiDnwSCQkZsMnViaialJx/9YV/7/+396mdW93R9 Kn8Wtwh+3nJYJjUm1oULDz4FUJpeLUs7PKoWhfe4esxiRG1QCnmod+gzmP/owi+a1s QqIPB+NwO3Wn2pL/l3yurEu4nzCdNO/Gur/giR64D1xJ47pHyHyTy6/RNLtNFIlagW sy0nkTJdex1ag== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 063514DF2 for ; Fri, 7 Jun 2024 15:03:41 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 086F83A0DB2 for ; Fri, 07 Jun 2024 15:03:35 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Jun 2024 15:01:11 +0200 Message-ID: <20240607130135.9088-15-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607130135.9088-1-anton@khirnov.net> References: <20240607130135.9088-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/39] lavc/hevcdec: pass SliceHeader explicitly to pred_weight_table() 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: at3eWIlmyXL7 And replace the HEVCContext* parameter by void *logctx. Makes it clear that only SliceHeader is modified by this function. --- libavcodec/hevc/hevcdec.c | 75 ++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index 2c26d397df..6a9de79dcd 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -143,7 +143,8 @@ fail: return AVERROR(ENOMEM); } -static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext *gb) +static int pred_weight_table(SliceHeader *sh, void *logctx, + const HEVCSPS *sps, GetBitContext *gb) { int i = 0; int j = 0; @@ -155,40 +156,40 @@ static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext * luma_log2_weight_denom = get_ue_golomb_long(gb); if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) { - av_log(s->avctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom); + av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom); return AVERROR_INVALIDDATA; } - s->sh.luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3); + sh->luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3); if (sps->chroma_format_idc != 0) { int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb); if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) { - av_log(s->avctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom); + av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom); return AVERROR_INVALIDDATA; } - s->sh.chroma_log2_weight_denom = chroma_log2_weight_denom; + sh->chroma_log2_weight_denom = chroma_log2_weight_denom; } - for (i = 0; i < s->sh.nb_refs[L0]; i++) { + for (i = 0; i < sh->nb_refs[L0]; i++) { luma_weight_l0_flag[i] = get_bits1(gb); if (!luma_weight_l0_flag[i]) { - s->sh.luma_weight_l0[i] = 1 << s->sh.luma_log2_weight_denom; - s->sh.luma_offset_l0[i] = 0; + sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom; + sh->luma_offset_l0[i] = 0; } } if (sps->chroma_format_idc != 0) { - for (i = 0; i < s->sh.nb_refs[L0]; i++) + for (i = 0; i < sh->nb_refs[L0]; i++) chroma_weight_l0_flag[i] = get_bits1(gb); } else { - for (i = 0; i < s->sh.nb_refs[L0]; i++) + for (i = 0; i < sh->nb_refs[L0]; i++) chroma_weight_l0_flag[i] = 0; } - for (i = 0; i < s->sh.nb_refs[L0]; i++) { + for (i = 0; i < sh->nb_refs[L0]; i++) { if (luma_weight_l0_flag[i]) { int delta_luma_weight_l0 = get_se_golomb(gb); if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0) return AVERROR_INVALIDDATA; - s->sh.luma_weight_l0[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l0; - s->sh.luma_offset_l0[i] = get_se_golomb(gb); + sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0; + sh->luma_offset_l0[i] = get_se_golomb(gb); } if (chroma_weight_l0_flag[i]) { for (j = 0; j < 2; j++) { @@ -200,39 +201,39 @@ static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext * return AVERROR_INVALIDDATA; } - s->sh.chroma_weight_l0[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l0; - s->sh.chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * s->sh.chroma_weight_l0[i][j]) - >> s->sh.chroma_log2_weight_denom) + 128), -128, 127); + sh->chroma_weight_l0[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l0; + sh->chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * sh->chroma_weight_l0[i][j]) + >> sh->chroma_log2_weight_denom) + 128), -128, 127); } } else { - s->sh.chroma_weight_l0[i][0] = 1 << s->sh.chroma_log2_weight_denom; - s->sh.chroma_offset_l0[i][0] = 0; - s->sh.chroma_weight_l0[i][1] = 1 << s->sh.chroma_log2_weight_denom; - s->sh.chroma_offset_l0[i][1] = 0; + sh->chroma_weight_l0[i][0] = 1 << sh->chroma_log2_weight_denom; + sh->chroma_offset_l0[i][0] = 0; + sh->chroma_weight_l0[i][1] = 1 << sh->chroma_log2_weight_denom; + sh->chroma_offset_l0[i][1] = 0; } } - if (s->sh.slice_type == HEVC_SLICE_B) { - for (i = 0; i < s->sh.nb_refs[L1]; i++) { + if (sh->slice_type == HEVC_SLICE_B) { + for (i = 0; i < sh->nb_refs[L1]; i++) { luma_weight_l1_flag[i] = get_bits1(gb); if (!luma_weight_l1_flag[i]) { - s->sh.luma_weight_l1[i] = 1 << s->sh.luma_log2_weight_denom; - s->sh.luma_offset_l1[i] = 0; + sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom; + sh->luma_offset_l1[i] = 0; } } if (sps->chroma_format_idc != 0) { - for (i = 0; i < s->sh.nb_refs[L1]; i++) + for (i = 0; i < sh->nb_refs[L1]; i++) chroma_weight_l1_flag[i] = get_bits1(gb); } else { - for (i = 0; i < s->sh.nb_refs[L1]; i++) + for (i = 0; i < sh->nb_refs[L1]; i++) chroma_weight_l1_flag[i] = 0; } - for (i = 0; i < s->sh.nb_refs[L1]; i++) { + for (i = 0; i < sh->nb_refs[L1]; i++) { if (luma_weight_l1_flag[i]) { int delta_luma_weight_l1 = get_se_golomb(gb); if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1) return AVERROR_INVALIDDATA; - s->sh.luma_weight_l1[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l1; - s->sh.luma_offset_l1[i] = get_se_golomb(gb); + sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1; + sh->luma_offset_l1[i] = get_se_golomb(gb); } if (chroma_weight_l1_flag[i]) { for (j = 0; j < 2; j++) { @@ -244,15 +245,15 @@ static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext * return AVERROR_INVALIDDATA; } - s->sh.chroma_weight_l1[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l1; - s->sh.chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * s->sh.chroma_weight_l1[i][j]) - >> s->sh.chroma_log2_weight_denom) + 128), -128, 127); + sh->chroma_weight_l1[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l1; + sh->chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * sh->chroma_weight_l1[i][j]) + >> sh->chroma_log2_weight_denom) + 128), -128, 127); } } else { - s->sh.chroma_weight_l1[i][0] = 1 << s->sh.chroma_log2_weight_denom; - s->sh.chroma_offset_l1[i][0] = 0; - s->sh.chroma_weight_l1[i][1] = 1 << s->sh.chroma_log2_weight_denom; - s->sh.chroma_offset_l1[i][1] = 0; + sh->chroma_weight_l1[i][0] = 1 << sh->chroma_log2_weight_denom; + sh->chroma_offset_l1[i][0] = 0; + sh->chroma_weight_l1[i][1] = 1 << sh->chroma_log2_weight_denom; + sh->chroma_offset_l1[i][1] = 0; } } } @@ -857,7 +858,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb) if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) || (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) { - int ret = pred_weight_table(s, sps, gb); + int ret = pred_weight_table(sh, s->avctx, sps, gb); if (ret < 0) return ret; }