Message ID | 20221018114122.26785-1-yunfei.dong@mediatek.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> 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 <rfc822;carlos.wei.hk@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <yunfei.dong@mediatek.com>) (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 <yunfei.dong@mediatek.com> To: Yunfei Dong <yunfei.dong@mediatek.com>, Chen-Yu Tsai <wenst@chromium.org>, Nicolas Dufresne <nicolas@ndufresne.ca>, Hans Verkuil <hverkuil-cisco@xs4all.nl>, AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>, Benjamin Gaignard <benjamin.gaignard@collabora.com>, Tiffany Lin <tiffany.lin@mediatek.com> CC: Mauro Carvalho Chehab <mchehab@kernel.org>, Matthias Brugger <matthias.bgg@gmail.com>, George Sun <george.sun@mediatek.com>, Xiaoyong Lu <xiaoyong.lu@mediatek.com>, Hsin-Yi Wang <hsinyi@chromium.org>, Fritz Koenig <frkoenig@chromium.org>, Daniel Vetter <daniel@ffwll.ch>, Steve Cho <stevecho@chromium.org>, <linux-media@vger.kernel.org>, <devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <linux-mediatek@lists.infradead.org>, <Project_Global_Chrome_Upstream_Group@mediatek.com> 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: <linux-kernel.vger.kernel.org> 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?= |
Series |
[v2] media: mediatek: vcodec: fix h264 cavlc bitstream fail
|
|
Commit Message
Yunfei Dong (董云飞)
Oct. 18, 2022, 11:41 a.m. UTC
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 <yunfei.dong@mediatek.com>
---
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(-)
Comments
On Tue, Oct 18, 2022 at 7:41 PM Yunfei Dong <yunfei.dong@mediatek.com> wrote: > > 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 <yunfei.dong@mediatek.com> Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Il 18/10/22 13:41, Yunfei Dong ha scritto: > Some cavlc bistream will decode fail when the frame size is small than s/small/smaller/g > 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 <yunfei.dong@mediatek.com> > --- > 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. What is the reason why other SoCs don't need this? > + * > + * 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"))) I'm not comfortable seeing of_device_is_compatible... this list will grow whenever a new SoC needing this appears. Please think about a good name for a flag/quirk, or a bool, in the platform data for these two SoCs and use it. Regards, Angelo
Hi AngeloGioacchino, Thanks for your detail suggestion. On Mon, 2022-11-14 at 12:08 +0100, AngeloGioacchino Del Regno wrote: > Il 18/10/22 13:41, Yunfei Dong ha scritto: > > Some cavlc bistream will decode fail when the frame size is small > > than > > s/small/smaller/g Will fix in next patch. > > > 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 <yunfei.dong@mediatek.com> > > --- > > 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_i > > f.c > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i > > f.c > > index 4cc92700692b..18e048755d11 100644 > > --- > > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i > > f.c > > +++ > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i > > f.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. > > What is the reason why other SoCs don't need this? > For the hardware not add this feature, and will add in the future Soc. > > + * > > + * 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"))) > > I'm not comfortable seeing of_device_is_compatible... this list will > grow whenever > a new SoC needing this appears. > Please think about a good name for a flag/quirk, or a bool, in the > platform data > for these two SoCs and use it. > For this feature only need to add in these two Socs, and won't grow anymore. So just want to use compatible to separate, not add one flags. So you think that using one flag to separate much better? Best Regards, Yunfei Dong > Regards, > Angelo > >
Il 15/11/22 03:00, Yunfei Dong (董云飞) ha scritto: > Hi AngeloGioacchino, > > Thanks for your detail suggestion. > On Mon, 2022-11-14 at 12:08 +0100, AngeloGioacchino Del Regno wrote: >> Il 18/10/22 13:41, Yunfei Dong ha scritto: >>> Some cavlc bistream will decode fail when the frame size is small >>> than >> >> s/small/smaller/g > > Will fix in next patch. >> >>> 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 <yunfei.dong@mediatek.com> >>> --- >>> 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_i >>> f.c >>> b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i >>> f.c >>> index 4cc92700692b..18e048755d11 100644 >>> --- >>> a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i >>> f.c >>> +++ >>> b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i >>> f.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. >> >> What is the reason why other SoCs don't need this? >> > For the hardware not add this feature, and will add in the future Soc. >>> + * >>> + * 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"))) >> >> I'm not comfortable seeing of_device_is_compatible... this list will >> grow whenever >> a new SoC needing this appears. >> Please think about a good name for a flag/quirk, or a bool, in the >> platform data >> for these two SoCs and use it. >> > For this feature only need to add in these two Socs, and won't grow > anymore. So just want to use compatible to separate, not add one flags. > > So you think that using one flag to separate much better? > A flag is better: please remember that calls to of_device_is_compatible() will perform a string comparison which, as you know, as much optimized as it can be, it's always going to be slower than a simple integer/bool/flag check. This means that even for functional (not just cosmetic) reasons we should not use of_device_is_compatible() here :-) Cheers, Angelo
Hi AngeloGioacchino, Thanks for your suggestion. Fixed in patch v3, could you please help to review it again. For this flag only be used in H264, add the flag in H264 instance. Best Regards, Yunfei Dong On Mon, 2022-11-14 at 12:08 +0100, AngeloGioacchino Del Regno wrote: > Il 18/10/22 13:41, Yunfei Dong ha scritto: > > Some cavlc bistream will decode fail when the frame size is small > > than > > s/small/smaller/g > > > 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 <yunfei.dong@mediatek.com> > > --- > > 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_i > > f.c > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i > > f.c > > index 4cc92700692b..18e048755d11 100644 > > --- > > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i > > f.c > > +++ > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i > > f.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. > > What is the reason why other SoCs don't need this? > > > + * > > + * 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"))) > > I'm not comfortable seeing of_device_is_compatible... this list will > grow whenever > a new SoC needing this appears. > Please think about a good name for a flag/quirk, or a bool, in the > platform data > for these two SoCs and use it. > > Regards, > Angelo > >
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 -");