From patchwork Wed Nov 16 05:56:13 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: 20734 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3112265wru; Tue, 15 Nov 2022 22:05:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ROxTgF2UIT5dn1J/Rk3HGvto9tGh6sYZ5YFyPyYJBAOcNb7F0T/4azPA0QV0H3hiLyHKx X-Received: by 2002:a62:6001:0:b0:571:8549:89c3 with SMTP id u1-20020a626001000000b00571854989c3mr21674259pfb.26.1668578755398; Tue, 15 Nov 2022 22:05:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668578755; cv=none; d=google.com; s=arc-20160816; b=VHpe5Iu+nzKtfANdnIr+DvEYVTjSC47Kk+w/tLG+PWB/6XedO8qfu3qBG8lXoMc73S R51TUcZzuAN2TJXvio8B7zNhirhbHZiSaLXIbEifz9NL7PR0Fw551POLsuco7dEs8Ebp ujtomR0hGkhY55h7Ninuz0kpTuccURQm/YIr2xg8ldQ+Sn/dWvmdl/P6SuwWKy9nXe/n opI8+Mgs6ZhK5nDfyTsEpbjMLdlPiT5bfM5qo3V73+DO5WCFRJUZkfaZT9NyVnJFVVci hG+B1jbpDTMLkhrHeArwIKXCJN01O060dtlU4xe9JhkYdZeM9X2cooXEAS84TopZkt4i KvLQ== 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=q44V2KOaAYcD/N+xk+VWumpglKqAK6Nls/jOUYK03DQ=; b=Q46dbC4tD82+wrMYk6/itoayMSSJ/3joYy18hnt+aFgifL0lTdmbF1RxMxnZIEKG8Q lDI9t3KjlaoJzRDG4QDVzaOzQhWm23qaOflPTNgUoNHNeufZfdaU3zNC1hFyPkpXH1wr HiGrYbDcN0OFUZtm+fo/9iXNMTeL+wuFYc3zWaV0NjxxgwsfkEo3Npke3+5maonkXKcp ivuzz/CqQ5736JsQEHY+5f08Ik7Sjp/j9lGUo3qTRrrZTsisJWhHwHEgT39U0+Vmx9Mp 0AStPfY0ZGU1aYIbbxqvNOewNT2/4Qup/O/pKNSVej4FGmvIM8W1T4FZKl/QiKovlAJC LPsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=vFGnSrW4; 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 y12-20020a17090a644c00b0020db7d975ecsi1074384pjm.176.2022.11.15.22.05.41; Tue, 15 Nov 2022 22:05:55 -0800 (PST) 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=vFGnSrW4; 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 S232473AbiKPF42 (ORCPT + 99 others); Wed, 16 Nov 2022 00:56:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229509AbiKPF41 (ORCPT ); Wed, 16 Nov 2022 00:56:27 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F2E821837; Tue, 15 Nov 2022 21:56:24 -0800 (PST) X-UUID: c6593fea7943441485e5496de840b9cf-20221116 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=q44V2KOaAYcD/N+xk+VWumpglKqAK6Nls/jOUYK03DQ=; b=vFGnSrW4nJV/bfqQNcxabBjTXcTUmPtijIvXK8SG1rLpoCjm6BjEcFKFLLxm5tIaLdBw6OaxVoKZg8Oe4oEQ34G3lVYyODCzYLkGspO1riVmBDx5A3G2H3AbX1qvBFLp+Z2aZUPsMPlaHcwVMUJf1f0lWgQYvTKK3qvgotaBEdE=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.12,REQID:9d3af225-3a5a-427c-a451-6988505c6a19,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:100,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:75 X-CID-INFO: VERSION:1.1.12,REQID:9d3af225-3a5a-427c-a451-6988505c6a19,IP:0,URL :0,TC:0,Content:-25,EDM:0,RT:0,SF:100,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACT ION:quarantine,TS:75 X-CID-META: VersionHash:62cd327,CLOUDID:7af24b28-7328-4d53-af97-37d3ca89e562,B ulkID:2211161356190S8IP0MV,BulkQuantity:0,Recheck:0,SF:38|28|17|19|48,TC:n il,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: c6593fea7943441485e5496de840b9cf-20221116 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1930682219; Wed, 16 Nov 2022 13:56:17 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Wed, 16 Nov 2022 13:56:16 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Wed, 16 Nov 2022 13:56:15 +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 v3] media: mediatek: vcodec: fix h264 cavlc bitstream fail Date: Wed, 16 Nov 2022 13:56:13 +0800 Message-ID: <20221116055613.13991-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?1749631636945682929?= Some cavlc bistream will decode fail when the frame size is smaller 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 Reviewed-by: AngeloGioacchino Del Regno --- changed with v2: - using flag to separate, not compatible name. - replace small with smaller. --- .../vcodec/vdec/vdec_h264_req_multi_if.c | 33 +++++++++++++++++-- 1 file changed, 30 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 2b7576265f48..0e7a70862525 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 @@ -150,6 +150,7 @@ struct vdec_h264_slice_share_info { * @dpb: decoded picture buffer used to store reference * buffer information *@is_field_bitstream: is field bitstream + * @is_need_pending_data: add startcode for cavlc bistream when bs size is smaller than 20 bytes */ struct vdec_h264_slice_inst { unsigned int slice_dec_num; @@ -169,6 +170,7 @@ struct vdec_h264_slice_inst { struct v4l2_h264_dpb_entry dpb[16]; bool is_field_bitstream; + bool is_need_pending_data; }; static int vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst *inst, @@ -395,6 +397,7 @@ static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, static int vdec_h264_slice_init(struct mtk_vcodec_ctx *ctx) { + struct device *dev = &ctx->dev->plat_dev->dev; struct vdec_h264_slice_inst *inst; int err, vsi_size; @@ -423,6 +426,16 @@ static int vdec_h264_slice_init(struct mtk_vcodec_ctx *ctx) inst->resolution_changed = true; inst->realloc_mv_buf = true; + /* 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 (of_device_is_compatible(dev->of_node, "mediatek,mt8192-vcodec-dec") || + of_device_is_compatible(dev->of_node, "mediatek,mt8195-vcodec-dec")) + inst->is_need_pending_data = true; + mtk_vcodec_debug(inst, "lat struct size = %d,%d,%d,%d vsi: %d\n", (int)sizeof(struct mtk_h264_sps_param), (int)sizeof(struct mtk_h264_pps_param), @@ -545,6 +558,19 @@ static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf) return 0; } +static void vdec_h264_insert_startcode(struct vdec_h264_slice_inst *inst, unsigned char *buf, + size_t *bs_size, struct mtk_h264_pps_param *pps) +{ + if (!inst->is_need_pending_data || pps->entropy_coding_mode_flag || *bs_size > 20) + 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) { @@ -588,9 +614,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); @@ -598,6 +621,10 @@ 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, 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 -");