From patchwork Tue Oct 18 11:41:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?WXVuZmVpIERvbmcgKOiRo+S6kemjnik=?= X-Patchwork-Id: 4126 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1912400wrs; Tue, 18 Oct 2022 04:45:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4VQ3LKH1Z9MWPmE7RQyxA1PJwQygKPH1nhtUvP4BcMvqrJg4KKPge8ItPof9jYx0hKncCK X-Received: by 2002:a17:907:7632:b0:78d:b5ba:87db with SMTP id jy18-20020a170907763200b0078db5ba87dbmr2023738ejc.661.1666093521241; Tue, 18 Oct 2022 04:45:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666093521; cv=none; d=google.com; s=arc-20160816; b=uqEDW/QfA6D3bZnFwnoKDIomFfOG0RPHadValAYwdZeV3g2fbF8k0Tx8dK7M6GWbe7 +tWNJZMwiAM+Q6WzcBMCsBVJbPNIY68ijrxk81iI18UJFVyI22UQtZs1UPsljMdbfI6V ToJ+iqEFjCb8Iabcclo9OULP5SNwb65S5sig4ni5FpGlFvC8uk+2BNNiPOKf1r4RsI15 r4CVsXwFVgR/Eqn6i6YcUPDccpByvF9Ns6nKizPyNWjJhlNmH+dMJ4KyrAGhC7C9vaOk iwg6y/er8Ltsncb2v3JOzdtMsdxpjNR5ddb6EMPVouCFEDJPtnaYYcfO6NzsI3GQerBN 07gw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=tG0N5Imt8sQtSGLzlkEksopxM01mlREtCjpaw9PTrAk=; b=IxhgpYRf+W7u6wiEmji8QvjzC0g3K9L3mNGRxJTu1zebxNg6SFa68tSqi2EuI0NRgJ 5jLVrIFLtwxbjmBV3sMqKQsSUtjEONQBBZ/rCDUCKU3KV5pbNZnJxAY3O1HlCkWWQdTn /3iFtXnVcIWqzwyVwnKgqLvdDpPqCIUpMyLHVfS/hBTLt+R4RbWu3sDy7v8pqJUABK38 b5H5LR2EpHSnzQrioEaMBaLiw3bDsEjlRdP7mZZleKVonthUgMlLyZ85/RpJ2whCwt0E cnGFEBnxP6aluhtiUtEuLccrd20OOLFA0wZOlm8Xu8ZZm2IFCFa0DUi6b7K5Zsrot0EN UWLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=LwlGOjgz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs17-20020a1709072d1100b0078d27c1b499si14829806ejc.500.2022.10.18.04.44.56; Tue, 18 Oct 2022 04:45:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=LwlGOjgz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230152AbiJRLnJ (ORCPT + 99 others); Tue, 18 Oct 2022 07:43:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbiJRLnG (ORCPT ); Tue, 18 Oct 2022 07:43:06 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9E11222A9; Tue, 18 Oct 2022 04:42:47 -0700 (PDT) X-UUID: ed1989fdbe9f44c5b4338f426a986e10-20221018 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=tG0N5Imt8sQtSGLzlkEksopxM01mlREtCjpaw9PTrAk=; b=LwlGOjgzWt+p0aWyDjlZkmBIVdfgx3E33QT//bQokGi27m1M8WDPlKPkSGQUd0edjy3jZ8+1vixUA9EHmeGUYHHuuGyouSwGcrqxxcPDzab4uQxs+Vfwc4aHChh5zPZT2ea5/JfWBAoP9CxcaqiyvkQffTZn3Hi1oPyRDxdSLkc=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.11,REQID:e9c60308-a294-4c3a-991c-2775c6befb14,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:39a5ff1,CLOUDID:4f652aa3-73e4-48dd-a911-57b5d5484f14,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: ed1989fdbe9f44c5b4338f426a986e10-20221018 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 606959868; Tue, 18 Oct 2022 19:41:26 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Tue, 18 Oct 2022 19:41:25 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 18 Oct 2022 19:41:24 +0800 From: Yunfei Dong To: Yunfei Dong , Chen-Yu Tsai , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Tiffany Lin CC: Mauro Carvalho Chehab , Matthias Brugger , George Sun , Xiaoyong Lu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , , , , , , Subject: [PATCH v2] media: mediatek: vcodec: fix h264 cavlc bitstream fail Date: Tue, 18 Oct 2022 19:41:22 +0800 Message-ID: <20221018114122.26785-1-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747025679810374120?= X-GMAIL-MSGID: =?utf-8?q?1747025679810374120?= Some cavlc bistream will decode fail when the frame size is small than 20 bytes. Need to add pending data at the end of the bitstream. For the minimum size of mapped memory is 256 bytes(16x16), adding four bytes data won't lead to access unknown virtual memory. Fixes: 59fba9eed5a7 ("media: mediatek: vcodec: support stateless H.264 decoding for mt8192") Signed-off-by: Yunfei Dong Reviewed-by: Chen-Yu Tsai --- compared with v1: - add detail comments for function: vdec_h264_insert_startcode. - re-write commit message. --- .../vcodec/vdec/vdec_h264_req_multi_if.c | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c index 4cc92700692b..18e048755d11 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c +++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c @@ -539,6 +539,29 @@ static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf) return 0; } +static void vdec_h264_insert_startcode(struct mtk_vcodec_dev *vcodec_dev, unsigned char *buf, + size_t *bs_size, struct mtk_h264_pps_param *pps) +{ + struct device *dev = &vcodec_dev->plat_dev->dev; + + /* Need to add pending data at the end of bitstream when bs_sz is small than + * 20 bytes for cavlc bitstream, or lat will decode fail. This pending data is + * useful for mt8192 and mt8195 platform. + * + * cavlc bitstream when entropy_coding_mode_flag is false. + */ + if (pps->entropy_coding_mode_flag || *bs_size > 20 || + !(of_device_is_compatible(dev->of_node, "mediatek,mt8192-vcodec-dec") || + of_device_is_compatible(dev->of_node, "mediatek,mt8195-vcodec-dec"))) + return; + + buf[*bs_size] = 0; + buf[*bs_size + 1] = 0; + buf[*bs_size + 2] = 1; + buf[*bs_size + 3] = 0xff; + (*bs_size) += 4; +} + static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, struct vdec_fb *fb, bool *res_chg) { @@ -582,9 +605,6 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, } inst->vsi->dec.nal_info = buf[nal_start_idx]; - inst->vsi->dec.bs_buf_addr = (u64)bs->dma_addr; - inst->vsi->dec.bs_buf_size = bs->size; - lat_buf->src_buf_req = src_buf_info->m2m_buf.vb.vb2_buf.req_obj.req; v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb, &lat_buf->ts_info, true); @@ -592,6 +612,12 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, if (err) goto err_free_fb_out; + vdec_h264_insert_startcode(inst->ctx->dev, buf, &bs->size, + &share_info->h264_slice_params.pps); + + inst->vsi->dec.bs_buf_addr = (uint64_t)bs->dma_addr; + inst->vsi->dec.bs_buf_size = bs->size; + *res_chg = inst->resolution_changed; if (inst->resolution_changed) { mtk_vcodec_debug(inst, "- resolution changed -");