Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5558269pxb; Mon, 28 Mar 2022 14:12:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOecMQvljvVRKNxNnY3Hso2toIsD4ADiytsC07PeLx57D1wuz+dg9Lsqndl6RAxL4gVDxs X-Received: by 2002:a05:622a:446:b0:2e1:deef:79d with SMTP id o6-20020a05622a044600b002e1deef079dmr24132174qtx.6.1648501930229; Mon, 28 Mar 2022 14:12:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648501930; cv=none; d=google.com; s=arc-20160816; b=ZUAEZ3vIIHSamrDItEJos5UCj8ALabjhTU0EpDO3oWcnKtOa0XWXnA7Y0/+Xofayl4 B4BMv4TKL6NxJqLfBUWex4BJ8gOa3/FW/mJVc6WkHcbj/WybdXsp4v1gUmNKAzhMbCls Golyze4UOJRDijJqxjG67ZYDc4lJrCTzda6Gnm2YYi+O1eQ91Nb8QRLIKd1D7vVzZvAO WHR3+hD3UVDLKVIsXwwhOC4CG/tnpcicZ4ywIVwtO8lcJTjLj9J2clxAjFMUd3PgUBs1 jOxEzaeyemOFBUE/046ypzeegDDBrZ2jr82LHoun0QF41uXnJXlzBtIad6STgEEVXId5 eTTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+nWkVcNHF4eMPHS4+WQPPGCQbjzbbKMTaw6r34pvYho=; b=iwwYxzp6zZZt47Keof8vORjCWPcjNSV1DcaTARn0HyoTpzmSna3x6Gng5B38W4rrTJ h0uCjZ+/GL0a+kXvmM4oZGrhwtFfYofBISwhsz0hdAWIKkEYE4iA8BWJLAU5zxf3Z0oX UFSJNuukUZ769G9u1e9fEu3xA2EZALY8TqFyDDm4r00bnESNcdh5DBX2Ie377FaxV9p0 2h9v5r1T8ZfIHgqJCOf77gpjdB1xNh0INc2M/9nO8vjn0EQpz1G0gyRi6JFRQ0k9EF3B M7D/pwH+KeuN81xVgtDeGjnK9r1y9/cHXYPUljVsOTChLEgH1U6kvt4afT024kUtnA0x 9pVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=nmQHtGgp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n10-20020a67e04a000000b0032547c90e5fsi2968395vsl.106.2022.03.28.14.12.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 14:12:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=nmQHtGgp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4019134B8E; Mon, 28 Mar 2022 14:03:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344243AbiC1UC0 (ORCPT + 99 others); Mon, 28 Mar 2022 16:02:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344262AbiC1UCC (ORCPT ); Mon, 28 Mar 2022 16:02:02 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EC7B3BFBF; Mon, 28 Mar 2022 13:00:10 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: nicolas) with ESMTPSA id 26A8D1F43887 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1648497609; bh=Ddp9raQj8UeMQfeTi2igopokBtztJ648lvZgYhxyu0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nmQHtGgp4cTLxB5/7cfkka6D2p/R8j+k0fG5AE62PwiZjhbYMp+XBvVXYf6MAMBEF gtpf/XPG0eQ/TtjkZL9Ws602REUe23MVKQFmYJQSxE9ePgeVbWbPZwSxBjhmsTccES c7o+P2K5q4AemDt88R8TIu+24NG68zJHoZ79An5i+i5bSTtKKBCa0jiaOtK9Heh881 nEfYfD26TdGGbbmfNgAweFFT7Cn0x4w6/h5hX5KrcScaXoi5f0oA9n1JlFpEMQqGA0 FsXccF9DGL8xmsN7T43zZyGFix0+NnOZuAqXyn/tF1jKwoegVlHYVTn+8ry+cZREsP AfOu/ePtN/hlg== From: Nicolas Dufresne To: Ezequiel Garcia , Mauro Carvalho Chehab , Greg Kroah-Hartman Cc: kernel@collabora.com, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v1 14/24] media: rkvdec: h264: Fix dpb_valid implementation Date: Mon, 28 Mar 2022 15:59:26 -0400 Message-Id: <20220328195936.82552-15-nicolas.dufresne@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220328195936.82552-1-nicolas.dufresne@collabora.com> References: <20220328195936.82552-1-nicolas.dufresne@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ref builder only provided reference that are marked as valid in the dpb. Thus the current implementation of dpb_valid would always set the flag to 1. This is not representing missing frames (this is called 'non-existing' pictures in the spec). In some context, these non-existing pictures still need occupy a slot in the reference list according to the spec. Signed-off-by: Nicolas Dufresne --- drivers/staging/media/rkvdec/rkvdec-h264.c | 33 ++++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c index 842d8cd80e90..db1e762baee5 100644 --- a/drivers/staging/media/rkvdec/rkvdec-h264.c +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c @@ -112,6 +112,7 @@ struct rkvdec_h264_run { const struct v4l2_ctrl_h264_sps *sps; const struct v4l2_ctrl_h264_pps *pps; const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix; + int ref_buf_idx[V4L2_H264_NUM_DPB_ENTRIES]; }; struct rkvdec_h264_ctx { @@ -725,6 +726,26 @@ static void assemble_hw_pps(struct rkvdec_ctx *ctx, } } +static void lookup_ref_buf_idx(struct rkvdec_ctx *ctx, + struct rkvdec_h264_run *run) +{ + const struct v4l2_ctrl_h264_decode_params *dec_params = run->decode_params; + u32 i; + + for (i = 0; i < ARRAY_SIZE(dec_params->dpb); i++) { + struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx; + const struct v4l2_h264_dpb_entry *dpb = run->decode_params->dpb; + struct vb2_queue *cap_q = &m2m_ctx->cap_q_ctx.q; + int buf_idx = -1; + + if (dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE) + buf_idx = vb2_find_timestamp(cap_q, + dpb[i].reference_ts, 0); + + run->ref_buf_idx[i] = buf_idx; + } +} + static void assemble_hw_rps(struct rkvdec_ctx *ctx, struct rkvdec_h264_run *run) { @@ -762,7 +783,7 @@ static void assemble_hw_rps(struct rkvdec_ctx *ctx, for (j = 0; j < RKVDEC_NUM_REFLIST; j++) { for (i = 0; i < h264_ctx->reflists.num_valid; i++) { - u8 dpb_valid = 0; + u8 dpb_valid = run->ref_buf_idx[i] >= 0; u8 idx = 0; switch (j) { @@ -779,8 +800,6 @@ static void assemble_hw_rps(struct rkvdec_ctx *ctx, if (idx >= ARRAY_SIZE(dec_params->dpb)) continue; - dpb_valid = !!(dpb[idx].flags & - V4L2_H264_DPB_ENTRY_FLAG_ACTIVE); set_ps_field(hw_rps, DPB_INFO(i, j), idx | dpb_valid << 4); @@ -859,13 +878,8 @@ get_ref_buf(struct rkvdec_ctx *ctx, struct rkvdec_h264_run *run, unsigned int dpb_idx) { struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx; - const struct v4l2_h264_dpb_entry *dpb = run->decode_params->dpb; struct vb2_queue *cap_q = &m2m_ctx->cap_q_ctx.q; - int buf_idx = -1; - - if (dpb[dpb_idx].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE) - buf_idx = vb2_find_timestamp(cap_q, - dpb[dpb_idx].reference_ts, 0); + int buf_idx = run->ref_buf_idx[dpb_idx]; /* * If a DPB entry is unused or invalid, address of current destination @@ -1102,6 +1116,7 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) assemble_hw_scaling_list(ctx, &run); assemble_hw_pps(ctx, &run); + lookup_ref_buf_idx(ctx, &run); assemble_hw_rps(ctx, &run); config_registers(ctx, &run); -- 2.34.1