From patchwork Wed Mar 23 09:05:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 12789582 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A468AC433F5 for ; Wed, 23 Mar 2022 09:07:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+LleYKRloxus7oQL8p3RB28ljQTboZHHVAK3j0835Mo=; b=mBFuL/KD5XzhES Y+kNwZkDOoL87oDOra9DOE59PZZLhcN6AcaF+EbiZOp0/0RqCfyKXQTOjomz6KiujSw/oGok78Dt0 Zxp5wyPBO2Kyx+JuFCMFuSlRDHuMwvHRO8oQnwK2Q2Q5ewmesvQ24aGhEUx6LZ/VBXVmPIenbFF/y LlqimhSpk0b+wpQr7Hir16Wgm6TR8mna0u8Qj6xWFzNuA9sXz6LLQnT+ciV3HmJuhGTqKETJvSXG7 LW5S1UALJ3i7kdS6b9jWd7lq3HXzI1UdBIp5JXJ/YDyz/UBOjKUIfJdWkd9SKIejYm2K6SA5OavIw 74qSw0pmV/xYxdSZjNpw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWwwt-00DBCB-E7; Wed, 23 Mar 2022 09:06:35 +0000 Received: from mail-he1eur04on061c.outbound.protection.outlook.com ([2a01:111:f400:fe0d::61c] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWwwg-00DB7p-JF for linux-arm-kernel@lists.infradead.org; Wed, 23 Mar 2022 09:06:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dh/QtLEXij8ODAO8pn3P0su8WYR0tIHCxeN5cuO/33mPP63/5nRQZxmT4khg7VJLAa5KdHQgx2Dtr6cViQ73/HflDVh9h9VtkiShPgPEUdWyrPgaEu7u1CzliNlOy9EoAzAjYYQQVYH5jcT0SU0FgXCDKnee12oxpc4aMFonayr+HU6M0n2c/ViF4Zgc98gSTJbQhOhkQcy7nmBuu9Aqq5a5o7gH3H19MLOlWimWIqLVhCCdrSeWjqh4YBD1UY5xm4BnO1TSeGlzQnTTj12mfgXFhsObc8+FbGVZiKN7HpNDflpsM+BQkDxJZgD+K7ijEpi8GOhd9R1Vjqmxk+rugA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nV+4+ggQij4sZAFQbBSSvSn62mz5psI8ZHje06+CNwc=; b=YAaQVp9aiCz3G8WAui6U1N1n7QTGul/GPXtyCAHIlBnsfAZEx2+ZszctkUzj812HRQYRI2NCDvXIlocAW8LSiGoRavnho3gW4ujhVGf2lHbBWN/FNZJloynokKRNri48mLiKQnhS2v/XoPXpVNCBzR3zAxCOh4uXBnI/KJWcmEHVlBkGZ/xyecNLZYn1NOgi/6oWFKDeXb2mSu5555e9BmOG21CK3fYD44zWA9WZhecUdmzwaQAd/8mRd++9DQfCX0E32YfFQMqpfr8fv9Fr3lD2lXU5VaI+IkID9c6exWT0F+D6AvvOUcgM/+7aH8+6fjcp+X5tJE0V3MJE33Tn1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nV+4+ggQij4sZAFQbBSSvSn62mz5psI8ZHje06+CNwc=; b=KtiOONj2iapUFXpzQCBhltiPVpMwPb/gawExTS7lJYTdwsqA6bx8uA2xedpOQDi8iGjFH6WWhBEaoWa9tKvkEgVpk2L05qMCzCmi72s2ud3XAlvLtJecpBU00pMXXVMPke6LfHQ0qy7VA32KsU/hG3GsuD/6PajsCb2XA7Son0Y= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) by AM6PR04MB4901.eurprd04.prod.outlook.com (2603:10a6:20b:1::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.23; Wed, 23 Mar 2022 09:06:18 +0000 Received: from AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::c39:69cf:c4ea:967]) by AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::c39:69cf:c4ea:967%5]) with mapi id 15.20.5102.017; Wed, 23 Mar 2022 09:06:18 +0000 From: Ming Qian To: mchehab@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, mirela.rabulea@oss.nxp.com Cc: hverkuil-cisco@xs4all.nl, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 1/5] media: imx-jpeg: Refactor function mxc_jpeg_parse Date: Wed, 23 Mar 2022 17:05:54 +0800 Message-Id: <9f67125ccbab5d36f985c783990ac2767df50f36.1648023273.git.ming.qian@nxp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SG2PR0401CA0014.apcprd04.prod.outlook.com (2603:1096:3:1::24) To AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0046c55c-68b5-4fc6-03fc-08da0cac6438 X-MS-TrafficTypeDiagnostic: AM6PR04MB4901:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: flrJmAd6lUceAqs/sS26ZJWhXoEMbCU+cKtXdD1Q+OiOsaA7B5qLU1x5VAqLf/FLUnqUgVtzzS3aAwL4eHufNi+2V3tUmQYGoPn50zeaqTZng1jJtEwTT5GbLBI/hv/XqPqSY5W+NChdTXMEgD6RosKMH7GMw4d9wAohe/B30a/uJLTW0xr4251ceskW1Bl2veKTHk/uyMHgFvQ0i2Inx3dm/577PviM6yM+4DAuwZoX0UNAFFOpxhsbB6NG5sYdsLTspMN3MaeBSh45Oit8kGnNnBV94RLYnbAeC4/OJEZzXl3ma8QUEX7aHoraRtHe91Wclvdv24J9dmTwGgv9baTbg0TgssVQzhWM6qljllixnqlaEdbnhZb5brcQPX1lsL/Pu7WdaRohJ/ewEkPGnTfynAL1H3JL8o42f3UkZLdolKty4O6h4O3bU1BVlwVA7zNLZNXqUicjIhdp25qO2WHCUgQB1SiR7MCk9yYDLoxMQj795fgmoN3xHRhJkGvqert6JsiizkLjpqEj06KD039rFfLIVrRA638JFKkglGfzu07qp/omMvwbnZ6ehwsaVlrf1So0s2o+xUMMghOzju2As+LaWanjtCO36hdIT/ILnKWXMGp8Eiwf53vOcrSGZs+WBXyj217OH5BtuROIUhq91lUcpWpUwy2FqorsZ2dbibGP4KUamQiefE0IhekbDV5Nh+cLZVuSMbTKgxcWcg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR04MB6341.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(2906002)(38100700002)(38350700002)(316002)(8676002)(4326008)(66946007)(66556008)(66476007)(6486002)(6506007)(86362001)(508600001)(8936002)(83380400001)(7416002)(52116002)(6666004)(44832011)(5660300002)(26005)(186003)(2616005)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 49iIVbEeBSdDIF42GMc4hJrwBgGs/Ndvz3pGgEjWQ5JUIUHj0bmCTAQYhJ3Nt5NYdMRcbwhUPdQIxUYJ4p+D4cjVZBpZLMXQ6Os0p636frpgb7Ul0ycdlOu5WvBkHbL5qCzRhZFu3JOmQMikhZJXXZ3N2w4/agzK8tM5r85rvWhuAorsHLWkB8GRkvELMOkUwBizLkrgrdxP9OXZPjHK39pt/s08JYD2p85fMc9+T34Nr6YAXN+KST4+gIZCZhDJfb9N0PjRjXj7HJnEat6LtSrQZKsDQFdx5NG09uGyqX9Har66WAFO3PWOW7OpJGDL3zACWFlM4Kl+RQNqiCbelJfe5j+VLOQrebIFhoKVzjLNzxAogDPlF30+4yvdICkyL5ktOqhtrUiSkPN1CQxSY7OBO56VNTZ5+xHy7qPRE0ViBN/2ruglz1QEb60OFlxl3uMywcjp/yYLB7Md9zh3a98WpRhozrAOHJoixXTla1+bACUO5EpuBxGUEqKsUQ4IUu91L9OTjwu5Xl8KVNlOVqy/XHysA6KC8Qpd89wBrVvcwgbyEmvc8kIywRUKou74/KONh3ev3gHLYGgkADvinKpmuzHCoKfbLmdBbFdYQUXI5BSoZVNKL2SYrC+B8oIO+ZtsmD+RxaBkuWgMAtw/r6sFnEGXz/Hvfd31xM+GhW24SGpr9gc/HPJUhwmQro8/a5+r/c5m0Jji4BydldtaFArwS87/y7NoTVOIPBMr4rbumRjZFm/7fNQN+omQYCuXPEq/stgkFluwuaxxSN6cF/0nX8oRelX9rqfG5pwrb6hCS0dgzJ28LG1QwItl9TLbFTK5LqB/3m+qNzqzVp1DdQjrCgJM6uBcyAl32ayY8+UGM1ck3Rk4dG6PdY8UJgAm3oJGlu6utk1OwmHTxg31iUSdnhlJrMvpR+p9CbtzAg5wNHlfvzJcUPGqxjDr/vUkqrcNwrmU87Qi3eVrwwsEBwLYhUzqBw1ujgzHAbXA/ewmU+ThebVjCBgDhFlikB5bQCpepEpuJ5jvNFzfzN0Wt8y8BUJx+5LuzKejcz6IkluZ8bFOB8ixjEz8i4bMGmwOXogPHxOK7PtQnVHxQH5LPse56B7OP2UwvmSDhgRXmKa1ujRMhA+6LO4KmAd+icbEPewtxgW+nPMEnLqdE1l2llYuP0gENsSs7PPrS3dtSvHiFsjX2v6TlF+NF6nU2/riaoVQ57r9eCjyWsmT11C3TUjpFe4oRGqPJgGczc8AuJwfhCF1qGoQxklkQ9vuCVU7beHVKfION6RTZwXyUhH4McITKaFWLBDk30y5m1ZxcpwPxy376e/4ve5/SKUfXpO42UwRPZgkN1tMLEO2HCpC0I0EEW8SgotzCskZAE5gI8lF5A9RMjRNfTB7Pb8px8fQ01pRTnruxT700Jt9pixdVAXNmvd0TEeUghQT38/7t6DHQmyR2VpQduOyhX1bfWcm X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0046c55c-68b5-4fc6-03fc-08da0cac6438 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2022 09:06:18.3522 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Bs3Mt+Qeo7rLiW8ocve2CI4bYJOT/H/NiZttdPhP2n03O8KlgWFeydDwhlb7NHB6FoLrKh25Z2s4ZpdwMckk4Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4901 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220323_020622_673876_63F9997B X-CRM114-Status: GOOD ( 10.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Refine code to support dynamic resolution change Signed-off-by: Ming Qian --- drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c index d1ec1f4b506b..48e496cec04d 100644 --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c @@ -1245,8 +1245,7 @@ static void mxc_jpeg_sizeimage(struct mxc_jpeg_q_data *q) } } -static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, - u8 *src_addr, u32 size, bool *dht_needed) +static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, struct vb2_buffer *vb) { struct device *dev = ctx->mxc_jpeg->dev; struct mxc_jpeg_q_data *q_data_out, *q_data_cap; @@ -1256,6 +1255,9 @@ static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, struct v4l2_jpeg_header header; struct mxc_jpeg_sof *psof = NULL; struct mxc_jpeg_sos *psos = NULL; + struct mxc_jpeg_src_buf *jpeg_src_buf = vb2_to_mxc_buf(vb); + u8 *src_addr = (u8 *)vb2_plane_vaddr(vb, 0); + u32 size = vb2_get_plane_payload(vb, 0); int ret; memset(&header, 0, sizeof(header)); @@ -1266,7 +1268,7 @@ static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, } /* if DHT marker present, no need to inject default one */ - *dht_needed = (header.num_dht == 0); + jpeg_src_buf->dht_needed = (header.num_dht == 0); q_data_out = mxc_jpeg_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); @@ -1381,10 +1383,7 @@ static void mxc_jpeg_buf_queue(struct vb2_buffer *vb) jpeg_src_buf = vb2_to_mxc_buf(vb); jpeg_src_buf->jpeg_parse_error = false; - ret = mxc_jpeg_parse(ctx, - (u8 *)vb2_plane_vaddr(vb, 0), - vb2_get_plane_payload(vb, 0), - &jpeg_src_buf->dht_needed); + ret = mxc_jpeg_parse(ctx, vb); if (ret) jpeg_src_buf->jpeg_parse_error = true; From patchwork Wed Mar 23 09:05:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 12789583 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 81BE3C433F5 for ; Wed, 23 Mar 2022 09:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=a6z7JwdtWEjin8anN7G1TqX9WTFH+hB3tbqZ1HBxhSY=; b=U25TXymQ96G02y 2MYKSN+KjOHoKmbu+CxWVUC52fK+R7SIRtKgQwayVOfZZ9GD0NJbUcP7/zpcIWX3rwwRLjblkaU8q cED6IV6LuSzsPxIWINclc/mwGKOxsI037fAMdsfhsjIQNQ41Jdr7QaE9qWorK+a9vS4LPaFHG21rp Gak3JPWYEsLGvX9VMqR/5xbofUQJt4RxdhZYb8IVmrO4D8/p/wU1azCOv/bhhNkhTavfMy9RaK4t6 BDT8um3PGC5ANhV3y5uNqqLLgOPDQ/EOpbY7/a31Oqwm62Bfgq+2tHSfb/cjKfv0zWWvF6hlxG0j0 3TlVo3v0oJc/Co/XS3Xw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWwx4-00DBEE-3d; Wed, 23 Mar 2022 09:06:46 +0000 Received: from mail-he1eur04on061c.outbound.protection.outlook.com ([2a01:111:f400:fe0d::61c] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWwwj-00DB7p-IN for linux-arm-kernel@lists.infradead.org; Wed, 23 Mar 2022 09:06:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eygwDMnzzpq2uq5sw21KruqilrLktgmZuI5CkLpkdcUfEQMWwtmnpikDen0UiaT/1mNr8Gu6M/1LwZ945A4XLwBAAXHSVohQhM5pl3FXyNQTRuZsuR2Wqn2phgz0fx+GaJhHLWdMDXdSxs3EAv1UwM4rblrRPxF0LycOQLX8riMRkGgZXBAxVVk/BWAlVbvbMGhmRy/Q8yzPtka9ALUMf/2wrU5PMiMOK9S8x5SHxcaZGGJ3tOkdGA8G3+9XjLhJhIw0UNY3Jm6XoZAXLNnTl5WooL7F6zKEc5ae2CZlut7Pm46d0pQ+Wb9Lom17u6jYgJwIvaXdpQYpQ9cbDnKCeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/g+690WIg+MYXNJQ5zJOBqx/MdkSYyzOmm7jmQ4tgPE=; b=Mz7dCxNNUltUAeVkhKFYEnbwV27gdjFVF+gYJpbktrs8KIOq7K/Jt4FctlrgF05yqNJEGGlCP07O+YD/FZqa3tdi8NBfXumqPGlJ9r5EQJp9QtipDsgmUkM+8NVO5OQIYl+yWgRh58SgN5uPlBiRi082ej7+gq+3lJIZ+Lji/EVPqGb71fpyPrrj6z+KcTergn5vISSimV8R6fd2bT6FveeEYefNYZrb2oEvUndT/BSe4i6KhGaIbPxQCjL5NnyaipSpS/q/txHPxYU3Sc789ZjCl88fT3ai68Xi+NNtLTNPzXXSoIZxWexR6/E2mhDbxiFMt2jwtnoVNSUkVPQXhg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/g+690WIg+MYXNJQ5zJOBqx/MdkSYyzOmm7jmQ4tgPE=; b=kIVQOumrK8U+sWzmbdhVCP9aOTiXkuNJYPDJL4LNp64bTvlq6WL4+MBi5+peQKCdFEc7S2AjiWMHAGnhv0Qp/G8ZoiHLFyea3IkN88cvnkK9DIgeLUnTAc7tiEsyNj5uuqhAuJU+xsvxHtlj8ZHHWIkgV1StqS9STQPzeZQrwEA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) by AM6PR04MB4901.eurprd04.prod.outlook.com (2603:10a6:20b:1::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.23; Wed, 23 Mar 2022 09:06:22 +0000 Received: from AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::c39:69cf:c4ea:967]) by AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::c39:69cf:c4ea:967%5]) with mapi id 15.20.5102.017; Wed, 23 Mar 2022 09:06:22 +0000 From: Ming Qian To: mchehab@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, mirela.rabulea@oss.nxp.com Cc: hverkuil-cisco@xs4all.nl, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 2/5] media: imx-jpeg: Identify and handle precision correctly Date: Wed, 23 Mar 2022 17:05:55 +0800 Message-Id: <629549f287c71d78b726fecdd2a3eea35982ffe9.1648023273.git.ming.qian@nxp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SG2PR0401CA0014.apcprd04.prod.outlook.com (2603:1096:3:1::24) To AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f918bef6-8490-42e0-a4f9-08da0cac6689 X-MS-TrafficTypeDiagnostic: AM6PR04MB4901:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vYCsTyYHKzsXAHVvtcpzYxw1ftuTPPjfiHGPYWJxpUU9F1DNcik3seqVc9XAJo6vUmWZm0x0KWSkGLEBiA80TR17n+4jaaUI7qg6xhdoroJEB3Mva1pAfy0u+LePffFKDH7OEhOV7a3Jvf5deXYU44MqAOzaJb4hDhFl/lOpSFmy6WVpW6GHMrZ+HItuF2KbWOHWgtisY1zStEjD8V0RJSMzsjR9iWXT/gHvbP6ABxZs8KJXtNR4+dzkCHEpISmdoImUxAse4iz3iJoa20a8Mw+zMicpGYI4y3xDbv/C0Pm/dCxeTlDxFEROsmRDPsXSzupndj3Ek7yiGPjqi3NadWVn9ZeKCWqYyInSZKdPGsQ06op4xz00og2qIgApZzGyV6TTM7A0HuFTMXxQPHyYMFKMANY38a2rcaWYJ0JLiSAqu18K9KHhc8UrPDTMKu3QEd0vUuo+X/ltvfOZ1O9FlEi98ssn/DZYq6dgCq3T2Nqd/7rswoarhxQh5ob3bxsWoW4/AG6XDCIkyc1IZYaXqCEqmedKV+I9WeACEP4k8lgRoSSW2LbMUbhz0HdtWG5MHz5jmaFwfPZYqrR22eiLXp2xfwegAtGZQQc8wO/JX/Q7Nt1pW4nxPx06jYYvI7YIm29C6vW0MZt9ovHiu2tJ9kTpOQDyc0c7RQ2Cc4VBBQprkO1RDFq4j5LZOA4RZDCoOve5+cDNsof32U7rdgtwxg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR04MB6341.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(2906002)(38100700002)(38350700002)(316002)(8676002)(4326008)(66946007)(66556008)(66476007)(6486002)(6506007)(86362001)(508600001)(8936002)(83380400001)(7416002)(52116002)(6666004)(44832011)(5660300002)(26005)(186003)(2616005)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OrrQ6/xLkM3ydwb+pHKbE9aC9xgHZSN+1Ai1a4blBdRtJvU9u+3ZlTbawc1WK1sVqW4bm+A0A7n2MmMKZwAHkCwtrV7FapMgCEgjRqhFaalay89pbNIRjONKLVGqPEoHkno0tkKq5zTTMJQJhsHKjGKl1f30a1Wnz2RIAoQqunl/3nvGMIuzWvbUEAbWcFHvHqVauD3RatRCj87BK092j7SSRR97tdkp6h+Hf8Nnut74sIxU9wo1+0w4nSlidzF2h1O7204NliReIfQhXamh3tmabbMHR1qxMRuPJ6LxnzWph/d7sJeiRp4rlp4NrPiRU0RRwBpW78truCCF9DrJ1idCFM6lNF/o52JT5OTxGXDAKfjXaPmCmr2Fzgc+8cEHcVvo4S7JRC30VX/EkdjQND044DXbDwvO4lBZqVayQp5C6FQvsXv3r087VkXT+Y6MsgYDay3pLXZRW24NdzW0BCYSsWe6FAxXsK0s73JGTIOHxqNZVmbibxFwpihH3R+eZGxVaT53FjQnALDvea9XuPkzV+6it76eJ889xvodHUtfC73o98QyRy70aBvG9wp9adafIBJ9gzW0+7IndIsZPfTF2eIvedtademg+6EUmBbR9Rpfx45ninU5Ye7zqwNqpb3zHGj8Ups2DlVKE+WwPT+WTKeQmoD0XRa3v3euIU0rDuYhmDwe+fbS0FwG5j1sbrtS76er1URUdBoJ5tXfHa7VQcnhC6fEqT2nyftXc0L2AvVAZqRXbxDJA34EwKrha2tVufELSys/bB47NOh9cxCC770Qfx48hq6cWHdCWOyCYdhE27mJLh+IrL/wibNOf8tzon0GHj49ItIf6M0vfGMoNKo8mHjfSTrHJ88EGwW5fJ0HZcpsxAWCzbtJOs/irPnKaLTFrvuBLLDCWXP7MaKjB4gSKnH15HCdarF0aEf1ZP0myMW7utSRBCPeXZshEapDa22WFvocaVA+a7H/Eg17Og7rIym9n962mUYtJ1MeGHF+WfWSqM6zQhmgLAsL9FngKl9H3rCaiNGyqcnz5QE+M8gV7WeReuGEFd21amOYcB//rt/rL9lPh16HT/sHJFE77Rtuyns2EunT0llnwSLyzysTGssP5TZQ8y9KvjmZYbJqe6dypcCYWCAnGRS5vr1B5knxbMAQtEEd/aiHkFBGz//PN1QZ8JDaa9gh9ivKhwYZDOAvAhvKHhV42M9vY1UAh0kNGxZOukWbkKIA1lrZVM6BIQ2sH7fTbJPvhsp0+BCIsGlQtUxtuRMZdIyuOCu6dSRdEaa7GP+rwJVCCp4JYcmEfdvIdwXVewZNbTXH8UvIl6l3rB5imUTPBGVJjGMfOxBEDasE3V3rR4g/2sHAzNG8XqJaA4ufu3ApBYUJYGpcliUdsMLDjxZQ+yz35MfsiNmn/9j2BZ20N0KJl7kc2TA1yXVYcxt+HBqWleOmTQAlmyFtwo9efHRnaPL7 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f918bef6-8490-42e0-a4f9-08da0cac6689 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2022 09:06:22.2738 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: J+aJSKS+/9rfEVSQuSZ9zHtvkOe9aJCNnEXyVoRZvpJDd4esWkUSJRJtmMNDtnjZaScWR2qDQ+DUTbmqa/Zs/A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4901 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220323_020625_648040_B6D1C587 X-CRM114-Status: GOOD ( 20.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The decoder will save the precision that was detected from jpeg header and use it later, when choosing the pixel format and also calculate bytesperline according to precision. The 12bit jpeg is not supported yet, but driver shouldn't led to serious problem if user enqueue a 12 bit jpeg. And the 12bit jpeg is supported by hardware, driver may support it later. Signed-off-by: Ming Qian --- .../media/platform/nxp/imx-jpeg/mxc-jpeg.c | 37 +++++++++++++------ .../media/platform/nxp/imx-jpeg/mxc-jpeg.h | 1 + 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c index 48e496cec04d..a95305639dd9 100644 --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c @@ -82,6 +82,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 3, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "ARGB", /* ARGBARGB packed format */ @@ -93,6 +94,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 3, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "YUV420", /* 1st plane = Y, 2nd plane = UV */ @@ -104,6 +106,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 4, .v_align = 4, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "YUV422", /* YUYV */ @@ -115,6 +118,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 4, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "YUV444", /* YUVYUV */ @@ -126,6 +130,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 3, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "Gray", /* Gray (Y8/Y12) or Single Comp */ @@ -137,6 +142,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 3, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, }; @@ -1175,14 +1181,17 @@ static u32 mxc_jpeg_get_image_format(struct device *dev, for (i = 0; i < MXC_JPEG_NUM_FORMATS; i++) if (mxc_formats[i].subsampling == header->frame.subsampling && - mxc_formats[i].nc == header->frame.num_components) { + mxc_formats[i].nc == header->frame.num_components && + mxc_formats[i].precision == header->frame.precision) { fourcc = mxc_formats[i].fourcc; break; } if (fourcc == 0) { - dev_err(dev, "Could not identify image format nc=%d, subsampling=%d\n", + dev_err(dev, + "Could not identify image format nc=%d, subsampling=%d, precision=%d\n", header->frame.num_components, - header->frame.subsampling); + header->frame.subsampling, + header->frame.precision); return fourcc; } /* @@ -1208,18 +1217,22 @@ static void mxc_jpeg_bytesperline(struct mxc_jpeg_q_data *q, /* bytesperline unused for compressed formats */ q->bytesperline[0] = 0; q->bytesperline[1] = 0; - } else if (q->fmt->fourcc == V4L2_PIX_FMT_NV12M) { + } else if (q->fmt->subsampling == V4L2_JPEG_CHROMA_SUBSAMPLING_420) { /* When the image format is planar the bytesperline value * applies to the first plane and is divided by the same factor * as the width field for the other planes */ - q->bytesperline[0] = q->w * (precision / 8) * - (q->fmt->depth / 8); + q->bytesperline[0] = q->w * DIV_ROUND_UP(precision, 8); q->bytesperline[1] = q->bytesperline[0]; + } else if (q->fmt->subsampling == V4L2_JPEG_CHROMA_SUBSAMPLING_422) { + q->bytesperline[0] = q->w * DIV_ROUND_UP(precision, 8) * 2; + q->bytesperline[1] = 0; + } else if (q->fmt->subsampling == V4L2_JPEG_CHROMA_SUBSAMPLING_444) { + q->bytesperline[0] = q->w * DIV_ROUND_UP(precision, 8) * q->fmt->nc; + q->bytesperline[1] = 0; } else { - /* single plane formats */ - q->bytesperline[0] = q->w * (precision / 8) * - (q->fmt->depth / 8); + /* grayscale */ + q->bytesperline[0] = q->w * DIV_ROUND_UP(precision, 8); q->bytesperline[1] = 0; } } @@ -1353,7 +1366,7 @@ static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, struct vb2_buffer *vb) (fourcc >> 24) & 0xff); /* setup bytesperline/sizeimage for capture queue */ - mxc_jpeg_bytesperline(q_data_cap, header.frame.precision); + mxc_jpeg_bytesperline(q_data_cap, q_data_cap->fmt->precision); mxc_jpeg_sizeimage(q_data_cap); /* @@ -1509,7 +1522,7 @@ static void mxc_jpeg_set_default_params(struct mxc_jpeg_ctx *ctx) q[i]->h = MXC_JPEG_DEFAULT_HEIGHT; q[i]->w_adjusted = MXC_JPEG_DEFAULT_WIDTH; q[i]->h_adjusted = MXC_JPEG_DEFAULT_HEIGHT; - mxc_jpeg_bytesperline(q[i], 8); + mxc_jpeg_bytesperline(q[i], q[i]->fmt->precision); mxc_jpeg_sizeimage(q[i]); } } @@ -1651,7 +1664,7 @@ static int mxc_jpeg_try_fmt(struct v4l2_format *f, const struct mxc_jpeg_fmt *fm } /* calculate bytesperline & sizeimage into the tmp_q */ - mxc_jpeg_bytesperline(&tmp_q, 8); + mxc_jpeg_bytesperline(&tmp_q, fmt->precision); mxc_jpeg_sizeimage(&tmp_q); /* adjust user format according to our calculations */ diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h index f53f004ba851..82b38cc2dfab 100644 --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h @@ -60,6 +60,7 @@ struct mxc_jpeg_fmt { int h_align; int v_align; u32 flags; + u8 precision; }; struct mxc_jpeg_desc { From patchwork Wed Mar 23 09:05:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 12789584 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1FF26C433EF for ; Wed, 23 Mar 2022 09:08:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FP2OylUwgMWLrnAz9iM1Cknq0FOYZ5Ajn/JzOIg57nI=; b=E68E2PJePfzfLr OvLDQErrybrhklo/RlsvMcj2RgZZbS9SJHIhglpdhuGRs4TpC2ye08iDSdS/W1tItgZ7T7C3/AJSN gpjwOtdEJYUmfEe7zr5JihIcJms0vT9XYaJhfFh5k+ti0lZmnrio0H/jgWs4Bl4JUSNA2j/OD/e6t W3bqOkbz1xJ3yGS7vmfSJdotqkHsaOU2MrPcI62dbgY+Howc66cxOAxwfmq5Z5ugSnUDjlZPkuXUF rgNvarX3M5QU44wUDMYeCfdw9vWjiJEjEMGOdOhfhMh+IwP+4sTKxaRmfFlB/ZtqDxxR8lEG2+P8k Is4tFPcDz/4q3xgMVObQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWwxF-00DBIk-Gw; Wed, 23 Mar 2022 09:06:57 +0000 Received: from mail-he1eur04on061c.outbound.protection.outlook.com ([2a01:111:f400:fe0d::61c] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWwwl-00DB7p-TF for linux-arm-kernel@lists.infradead.org; Wed, 23 Mar 2022 09:06:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AQhesWiQCFGvhk7cv6H9MNE6fvqqsbdHqK/PozS5AKdYfgdBg0y7N2mBV8VBrt4TdaLACRDsyxpBE2L0PUpK5LwnAMFcVjdPCd4HlVnP94plJFrv6+GCuZdYgKy5tNXKRHF/EeONIBx57o375c7fBO6rB/lTXg76BES7ypigMVRfv0WnMCQoFha6ZqQVB+3Sx44lOmQeONqlvlf34oTQr1lM6r4ZqkifCBriZxvChNnOigMcxf7pQzxtwcuPSQQyHCLxUUoZ3ZKU8fbl0gb8KQRzYxTescuL7AJ24NCghXApFx4BLzxjX7DFlrvAhjqmJFq3eldk5qGfpZq86R9slg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TxbkxqO1O3BFIRbYDJPwW5bmJEorFPJX8Y9qkO5XWMQ=; b=hCPKmT8DuULRDCLtqwV6o6yJz66p+lT2BB4z1JCuYmIIraAT230NMaQG9pg6m8Cv+XOg/CLnwfRk4hUkQij45JTXejJ3DN5I2yjBT1rK+y3pjv1uNfDF8HnSDJ6wHKsEVIJYzo58IIc4M38E3775ovWY75DS6svDNSnUVtGbbJ5a6k3PlyqJNCvbT9Ez89fpjZQzOz9KiQAUMIW40vt7/NxXzrPbtw9ya49EXE4KEiQnEYgoCl/KtMKlj1tXWw5UN9Rrg8/LdAs/6rudbx9dYWuF/yaPY19A36n2O9MGKZZT+5TXyH3zyw9thnyX+oElUSovaSuo46r1Zukqsd2sNA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TxbkxqO1O3BFIRbYDJPwW5bmJEorFPJX8Y9qkO5XWMQ=; b=SlnicDMGkoFa+Jc5eOmzU5APuaXdIy3JBc2OCDPVFT8+KOnbR3uLPdemyRQWGaWgfTtRvUzRWy70b8KogQB3ORje/NFi2oDPYL0H/0rQt1bRA17a5czs+5YfclBRC1u8pcrpJgn+41ASJX5aFt4SHOhJ0oaiNc1oO0Lq3FMQtlU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) by AM6PR04MB4901.eurprd04.prod.outlook.com (2603:10a6:20b:1::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.23; Wed, 23 Mar 2022 09:06:26 +0000 Received: from AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::c39:69cf:c4ea:967]) by AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::c39:69cf:c4ea:967%5]) with mapi id 15.20.5102.017; Wed, 23 Mar 2022 09:06:26 +0000 From: Ming Qian To: mchehab@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, mirela.rabulea@oss.nxp.com Cc: hverkuil-cisco@xs4all.nl, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 3/5] media: imx-jpeg: Propagate the output frame size to the capture side Date: Wed, 23 Mar 2022 17:05:56 +0800 Message-Id: <473edd5666b24a659f651ca003add12ac9a0c2d2.1648023273.git.ming.qian@nxp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SG2PR0401CA0014.apcprd04.prod.outlook.com (2603:1096:3:1::24) To AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fea22ca5-aa25-4975-8106-08da0cac68d6 X-MS-TrafficTypeDiagnostic: AM6PR04MB4901:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: htxEOoc4VFHSeJUDQZe9ry+LIQ30O+kdYq4oCihljX7zuX/1+SmieOtjq3BTs+s09T+gAETShyuJOT0vuAi20Il89nklKDXOEthssyGloqOMEwO3yRFWlolY6hueRcJTaIl/skQo+4k9Zu8HuAZ2d1/+WQOhse0hN3ct4UBT/Xu0DiKrbZlpCAeuLKVSVALLpee70xTHNNezKgoO8J4qmxth/7nkIsiHHz+HJyu1lh+x0FhZy2+z5eLM1EhgCHYerwJgOd5u4zVdLsKFjHmcjeFXxhkMn6MqIbfXuJBiLRkscZKFs+4653TGw/r7R9mk4qKFnhEiGJoHHN5gBTxZwqZIcEX7IRZFEFTIcq7JMIvmpMHE55MDQ843QFBFNOolVNmqNpYJxAAL+n1yNWn/bZxDlNQP8mWKWqBZFJRd249XiX+NGcik179i3ned4ly9KnKSDpcNuonquoeYAjhOtUiXLcIut4+zH2O7xSY5peC3IeOVG0BqQXeQ2/m31O1RxTzj4Eft/DteskidBRQh5j+0UagSK4OQzP5jQT+E+v2wQrl4JODULO2LP3ihKoNqEoz5gZ7kM2w8wzWFVbuMXm7E9D4QIb/Ia+Ebmh75w+zNsJjj+DKMHO2sZk2kjTl5aG/aoRQ6hh3YIcDr1xAER4KcHUT6d//cNEkl2djaFZwKNhAryp/LNffIIFDzzbK2BJ3MIyGOmvEYBkL/ssQmpg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR04MB6341.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(2906002)(38100700002)(38350700002)(316002)(8676002)(4326008)(66946007)(66556008)(66476007)(6486002)(6506007)(86362001)(508600001)(8936002)(83380400001)(7416002)(52116002)(6666004)(44832011)(5660300002)(26005)(186003)(2616005)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aI8nEhFAfQ/W1YZ0g5EbG+KI7WoliO4cT6nHRF6dgod0KmidmDVxSkk8jefx42gCzS9bAlh8yKs/JoW2IPtwNT1qNkgAx5+5QwXQzjvt4P9Q9G0s3R02MZdJ4p1e849aIHCHx13WiAV7DEemxXk7/K/0Bf7LHTpZYWYSyBHQ4BZjHVatDyeUZnghubQe7GLZHWL1E7ocPoGidD/k9f4VATqpAxncLESGZQ51ssfolu3M3NYVIWpU1bABDbFceHsJgSXJ/4ttWg1IEphn/NA5rgyu8olEz1Djc0bXQY+XkeTsOMudX5+2oH59ao5cHXJa/AijzsLBKGHjtXuBZk2agnCKsX8JPS2NVMCHwlLkPhSIO2csjaamRLz24Bzd2xkZExYY592ELiQzXLLSqNbDsM20hJX9ZQ3U84qsT/y9ooR6cZmcyP4AMS8cg4vu6cbulQ3FZTj9XdawNBqZomrmNqqQBtN15YoFivznBseVMFLLaEPHGHydGqRmzZLUbHEcHldSATZYo7MmwF/WhgOT8/7lsYnxN8u4eGOvP965M7Hdw7joLljB5H0rLUv20heGPSHsOSBam7WvVbQwAP+k3OKsdmpv+bHqDB9LTFGWJl5A92uuRU2iFXDxWvPTBHZRtSThHQrEfbTzSpnhNHSgrVYvOjo/nhsutBLCFyP3Ksvcc8pGoTOvdr2eDu+RVxwS5lYlcBvMmxRgO66FCQfEd1Wn1w7GEiBkdQt0X26xjEADhK6QNKtALPDITs+L9hA/ZvtPCFK8hKEo6VpC+jZ06hPJUtoPve1VzOgvSDbHkh9FhQchlDwU58KN9DV79pCn7z7w5f5Gtgxuq2tup/dZuIl4yHwA/sC51EhrA+j5G2AuQCO9zoneOT+MVf2vuiQ1a5rv/Gk9nI4oosiFfi+vU0gHQEIw3WfkwG+9K5zCYTeTgH/GR1Idvm4HWxKVMCDpC6wY2ODAdkk6ywh17TMINgQ82xJytfQI23jgnyPewba1VOwfVy2Zqqsn0kbHJiOjans49pMe6Ru1MJXNhoJDoEtX5mx0iEcctt2BfN9F2t/C7G3qTj0/zfrGJ3TjPRUsDyWSYmSk5OlyPiDp/6U913W2P63R7T9CGLCAFbErSWI4XJDRufletzHB4RhPlDZL9cbHCV4KQjwiDRtr7Wc9KXYUkPu3hOrTAoJSi/LwuIRtxcXLqOW3TlYiuf6IJXZj98XgyLs9LT68A8Zf84Fr1jfXAiLfzx+Iz09NFgN/U9654T1LZv6O2qdTldO0J4beNwjYNexJypjEwvdbSyIU6b7xskrv+IQ16uI9vipRD5cW99Q+e7ube3MY7K2eGhJ6DumJUQ1VhzGRI2HS11fLXczocsbTikjuqioL15RGwSVOEdY0iU3+FReMPPaCxw60/WVv1Pn7Zxa6Y29IgQZ0THVgmlqt49oiwfwg2rn12/0RtIB2j13cNmQTHOJOynQU X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fea22ca5-aa25-4975-8106-08da0cac68d6 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2022 09:06:26.0705 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ck0kitYGFm74Vhdl3w1LUzIFzGsRttvNusUI+YlEXYjB+p0TJ3WlH8HTUfpTJ+QuXoA+FwJaxWAlna9PG81d6g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4901 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220323_020627_973014_5555AEBE X-CRM114-Status: GOOD ( 12.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The GStreamer v4l2videodec only ever calls S_FMT on the output side and then expects G_FMT on the capture side to return a valid format. Signed-off-by: Ming Qian --- .../media/platform/nxp/imx-jpeg/mxc-jpeg.c | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c index a95305639dd9..5dfa6f87871e 100644 --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c @@ -1831,12 +1831,40 @@ static int mxc_jpeg_s_fmt_vid_out(struct file *file, void *priv, struct v4l2_format *f) { int ret; + struct mxc_jpeg_ctx *ctx = mxc_jpeg_fh_to_ctx(priv); + struct vb2_queue *dst_vq; + struct mxc_jpeg_q_data *q_data_cap; + enum v4l2_buf_type cap_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; + struct v4l2_format fc; ret = mxc_jpeg_try_fmt_vid_out(file, priv, f); if (ret) return ret; - return mxc_jpeg_s_fmt(mxc_jpeg_fh_to_ctx(priv), f); + ret = mxc_jpeg_s_fmt(mxc_jpeg_fh_to_ctx(priv), f); + if (ret) + return ret; + + if (ctx->mxc_jpeg->mode != MXC_JPEG_DECODE) + return 0; + + dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, cap_type); + if (!dst_vq) + return -EINVAL; + + if (vb2_is_busy(dst_vq)) + return 0; + + q_data_cap = mxc_jpeg_get_q_data(ctx, cap_type); + if (q_data_cap->w == f->fmt.pix_mp.width && q_data_cap->h == f->fmt.pix_mp.height) + return 0; + memset(&fc, 0, sizeof(fc)); + fc.type = cap_type; + fc.fmt.pix_mp.pixelformat = q_data_cap->fmt->fourcc; + fc.fmt.pix_mp.width = f->fmt.pix_mp.width; + fc.fmt.pix_mp.height = f->fmt.pix_mp.height; + + return mxc_jpeg_s_fmt_vid_cap(file, priv, &fc); } static int mxc_jpeg_g_fmt_vid(struct file *file, void *priv, From patchwork Wed Mar 23 09:05:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 12789614 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40027C433EF for ; Wed, 23 Mar 2022 09:22:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1zSJ+33xgTZ0NrNZ7+iWhMIXjxDGrTGtpdU7X761Ohg=; b=U3IMnDVfgm7s61 ad4sf+usJ9A7nAQJb38l0wu2jwgeawHDe88c+j34T8HGPWEeJCRp8IWJ6hUb+9GEitAR5zibyIGVT wKjObxb7+7qyvTx1r8WUp143Qa1NWSYGeVzj4Pm4l8+QLQVIsugfPxD4QzsPpeZi75RUhefG7Nq8O fBkMvfmSYQoJx3lKxstDd2HAD/QIYKtMNhdO3Bu2OHoUhWo9GmJlbKdeAPm72lDzz/CSa1+zPsoQV cghvLlahRWhM2Mf1zL1FSCUAkxnotAhHec5NrlxV9L71wyUi+XKrEcw2JgETF/GfZ8HPCj2o6WzFc 7pekVX6Vp8Iq7kUgYu7Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWxBU-00DE5P-F4; Wed, 23 Mar 2022 09:21:40 +0000 Received: from mail-vi1eur05on20631.outbound.protection.outlook.com ([2a01:111:f400:7d00::631] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWxBQ-00DE3X-Iq for linux-arm-kernel@lists.infradead.org; Wed, 23 Mar 2022 09:21:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BegJH0dzxoxW8P5nK9ICZN8pb5QGR0PkZOPOLCSKjeEH8HttkYXnzO/E/cRKMT3ve620AnwDvXhXWGmpXqkrAf/BkmoW98Ds8BTYOe/1rkkDzjR2MDtKMh8Wj/8ZlfhSxM1KUVd+jkFBrhIb5Ciaa2eea31piBBnMs3m0d4OshXNr6ojVNOgBWNQnuMoZ7RZrKj1LXUELpo37DTsHPyT5KdofPufnoaphctDuyY3OP0T/aArm2j9MS7zL6+5c2GlsfVGQ8cPoa/UfcBVts/F2QNJ9vfGPnXWLvVZfqjgBFERwoWxBqVebc9e+ENYEXvUI8KJsGjRfiLM3kigYuup2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zxnJbqncKEweF+paty/0EbSShq4QeW2vvkPTLwpQZRM=; b=hafWvuFOEhOhFS6Hr2fvL1cmxol40ZkIOeoATPaqCnrQNbb+wY4GfxvUbzwwHczsIEyepsGNi8AOAFaAjBOHWYe9vCpnwEN9Me0b9/14QmSLhFHf5dRwX1o1emwpewQIxJijnCpmlEWQOrJwXGCmQFTGgo7vT8GHEh3Keevij/9mzIIhdhavGweF7nb4XGJdEJHX3LZgwlsdIwigiV5Kg+cB9U4SD8loNKZm0V40iKAK12CR7DmSAZu5YsUg0yz+DQJfBi+IDvzO43FsxarQqSnwL7d6hlFcZ72upXtvk5JIjbY6NCHIbAavbixd/PwTQqVkt7aDu1Dev/qXv3wJog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zxnJbqncKEweF+paty/0EbSShq4QeW2vvkPTLwpQZRM=; b=JYv60Lr6R3II4bmiszl0VTpurBeyioMR6KgADEY0cKJmbX0fDz/Z5kIMaSjhleoEUC14+rxQMNmV1OOU6ALw+yVjNJ7lrVC92BtUE9cLvbadGlthHpF5Wj0J5KnNLjznHlsRDNZcRv5A3PHJ6NdId8ikJ56qmhrdUI+BfJFe5XM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) by DBAPR04MB7317.eurprd04.prod.outlook.com (2603:10a6:10:1b3::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.16; Wed, 23 Mar 2022 09:06:30 +0000 Received: from AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::c39:69cf:c4ea:967]) by AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::c39:69cf:c4ea:967%5]) with mapi id 15.20.5102.017; Wed, 23 Mar 2022 09:06:29 +0000 From: Ming Qian To: mchehab@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, mirela.rabulea@oss.nxp.com Cc: hverkuil-cisco@xs4all.nl, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 4/5] media: imx-jpeg: Handle source change in a function Date: Wed, 23 Mar 2022 17:05:57 +0800 Message-Id: <3f3be7bac34c43b38ac77bcdccf93e1a364534a2.1648023273.git.ming.qian@nxp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SG2PR0401CA0014.apcprd04.prod.outlook.com (2603:1096:3:1::24) To AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7e8fa2d5-9a55-49b9-98d0-08da0cac6b1e X-MS-TrafficTypeDiagnostic: DBAPR04MB7317:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DtZ1h5/EvTqQQSvpCmnGSp9YbINGbV/Lz3NX6gtPInjmrmRn5TwFlS21QyThiCyBJ21ASBioEByZB69lzxB6fksLA0f6tlgmuipLK6tpG40crJZj2vsKdblk1EyPYih4EM/+foYa0oHLVqHIr7lkh442yinPFvNKSgUwftlxnaioPMOP6JEF2zjpoodJS7z6gc3vtI03t2m2CVIxxJiV4ySR7INJU5JyNc8+dZvd6lmFsY3fGjLd6ipGkhmE6rmqUtE0GEZ+CTgyhlhZK+Pi90raT/GQisGOlKPqBDTWu1KOzTQZqgBrsEs/erkJm5HqRz6+/EN9kxqgoIoBOml9isCieJwiK1dTWGY2QWEv5P5s3k9n7wV+zmy3UinZhC/QvGUXNk8X6AGdkyn/uLrl9brEJiU5hiIYr75eHY9ZYs2EvGjtesDCdOh5Si8g2xxPr1pGkU7RNEE3n01Uak50bS/ovtnarb58tcnjmMtoKjCjKpb+Y72RxzN50KPyXge7iUD8fsOkdUyrtk5Qq0+C1dt2E1KFxh+IbDszjS15dFkou++T7noQtXEM0iRU0Ad7kuwN+7lnb7FZMRL3aXjRF3/vCMOf55GzpBkxwmKKjDjJQ+TucuM1+++zozBaNjOkM0zQmsXloOzGhpnN2aBWoet2WDL1QV0pU86u1J05kgafmvUnQBYraW8kI1iw4XlWU9K9qCf4js8e0PnlUGK2tA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR04MB6341.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(66476007)(5660300002)(38350700002)(38100700002)(83380400001)(2906002)(66556008)(66946007)(6486002)(7416002)(508600001)(4326008)(8676002)(44832011)(8936002)(316002)(26005)(52116002)(36756003)(86362001)(6666004)(6512007)(6506007)(186003)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6AskAJLj1C8gnGtte/orF88XigBIfuSz+ynWmPs+eoNGw3W66cOoX8kIM6q4wMnSG8/JIBD5wQkJr9BmFtO9htpQENJNHCZH3Kiqv0OVtX+Y37cSG/KBUitxM+BBM6cPPXitsv6kYD8g+UzPLEKl5+juvK2A70ZLGDy+BcDijcMmBDAgWw22RDfGIL0yIBBTx8liYu9JU3fdYsCRLqSTojnwMbioah5O0KM8DG5Az1lcsV8EQ6yzVFVVinf33dNJldhHoXsrzh4IJykWAuIK15EWF8zpKDh2xGUzwzuIWXWkJagPyXB/Gjl5m1XrRDpPUfU/KTr3ckWJXas/D0mePj9Pz/5x4VqGLgjXz09wRQM88yPnF3nY0U3OXQz7RIK98fmoMcuB8b92CkaITaOtVe99InAFxP5zAsXI132FhM47XqjjjVVpVFYac1Mfw2QwGFUgH3inD9j5NTNUTH+S+vVKkum3fBwhZH0RzB5dor9RwB5alxmfkEXOUGYfOtAsN8pOGAswHLM+peHbTSHlaFKAiIpOsi6gyh6PbeLIP+XUIbfZiKlYfCR5Sf4sw4kBEKOBuVNM5vl8JMck6H3k1nophlEO/nIenMsHpFJMzrZiAy7pJ6s0b6ZQDdk5TmjejxGVTqQXCQVspv/OsO8K1owVCRu9/YdXJYqhPCfmRvQxO2VkBUNMx2/q21DHFKYePOdAEwuL7iUq+IpyNkPnU3iqPCgra2XmjkyO+NQ3xZYv5xW4uMyyu32SB/x8JTr2xAoA8vGwNUiByzOYJ1jxbcb4JHAexCNmi/561ZlL4vytMzsUOJVYe8SouSkFx7T5JRpOqrBMmYGOAiJVwO7Qw8Z3p9dKvPMAhTbyaxYFgWov/tqwwBrge716k2EKYombIcDuJxvr6GhuiuIaILRFrDLUWMFo1TgAwPTtBIpYZ/3t4x11DC8Vl7F7DkTj1dUZ6xJ/i9UdBE9qwO32XOp07n2NmW/tA7vvTG1emJURnzepEaREJzVO/NOF5d0fQbNIpIGogD9vWNEjy0+v50difeMB918bt4Rkxkr5KH4HniBOPHP0Fmxh5Atq+EDbU3MH04JGlKMGXIsRUyO6E+6fad9/pVhrkVvDbIpvm63bzbrhJ9+nVHYNfA+MeIN4Wn29MT1TFj3a/a1tc7/Mwovv/NKWo6J7kjY+SYjRJEv64Cnrrqw6Of23a41H0ISUizCiz8fMOxE4Z44lh5y60ajCSW5S2kR1PiahgfulEJeMWePgANWWSpRxmf+9m5bTNslOddyahNuOvFRNJha0XYiHdJLRHF7NQSwyFcoBVu3Yy9GPdN/MH6tJtt+Inal/MTh6y9u61vbE/ZY6XzTUCHyER4DlMG+5SMG82T6CvWHbxzPGX9Yx5GyUjVAds6jE+ofgib9Ts+1mdsUXEHmqFJV2M/Q/h2DKjA3LB5AY6aNKYqaMkIgS7tCDB0eZHPWdK/1U X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7e8fa2d5-9a55-49b9-98d0-08da0cac6b1e X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2022 09:06:29.8828 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: frFg1VXFRUsw93qENf/oTk4JKoD+xkov4KlG7EAtjotottOd6U5nGSw4tsYm0iRRFlG9zeaMyTaHvy9KtJa44g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR04MB7317 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220323_022136_635727_D1C0532E X-CRM114-Status: GOOD ( 20.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Refine code to support dynamic resolution change Signed-off-by: Ming Qian --- .../media/platform/nxp/imx-jpeg/mxc-jpeg.c | 114 ++++++++++-------- 1 file changed, 65 insertions(+), 49 deletions(-) diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c index 5dfa6f87871e..30289f2be3dd 100644 --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c @@ -315,6 +315,9 @@ struct mxc_jpeg_src_buf { /* mxc-jpeg specific */ bool dht_needed; bool jpeg_parse_error; + const struct mxc_jpeg_fmt *fmt; + int w; + int h; }; static inline struct mxc_jpeg_src_buf *vb2_to_mxc_buf(struct vb2_buffer *vb) @@ -327,6 +330,9 @@ static unsigned int debug; module_param(debug, int, 0644); MODULE_PARM_DESC(debug, "Debug level (0-3)"); +static void mxc_jpeg_bytesperline(struct mxc_jpeg_q_data *q, u32 precision); +static void mxc_jpeg_sizeimage(struct mxc_jpeg_q_data *q); + static void _bswap16(u16 *a) { *a = ((*a & 0x00FF) << 8) | ((*a & 0xFF00) >> 8); @@ -922,6 +928,59 @@ static void mxc_jpeg_config_enc_desc(struct vb2_buffer *out_buf, mxc_jpeg_set_desc(cfg_desc_handle, reg, slot); } +static bool mxc_jpeg_source_change(struct mxc_jpeg_ctx *ctx, + struct mxc_jpeg_src_buf *jpeg_src_buf) +{ + struct device *dev = ctx->mxc_jpeg->dev; + struct mxc_jpeg_q_data *q_data_cap; + bool src_chg = false; + + if (!jpeg_src_buf->fmt) + return src_chg; + + q_data_cap = mxc_jpeg_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); + if (q_data_cap->w != jpeg_src_buf->w || q_data_cap->h != jpeg_src_buf->h) { + dev_dbg(dev, "Detected jpeg res=(%dx%d)->(%dx%d), pixfmt=%c%c%c%c\n", + q_data_cap->w, q_data_cap->h, + jpeg_src_buf->w, jpeg_src_buf->h, + (jpeg_src_buf->fmt->fourcc & 0xff), + (jpeg_src_buf->fmt->fourcc >> 8) & 0xff, + (jpeg_src_buf->fmt->fourcc >> 16) & 0xff, + (jpeg_src_buf->fmt->fourcc >> 24) & 0xff); + + /* + * set-up the capture queue with the pixelformat and resolution + * detected from the jpeg output stream + */ + q_data_cap->w = jpeg_src_buf->w; + q_data_cap->h = jpeg_src_buf->h; + q_data_cap->fmt = jpeg_src_buf->fmt; + q_data_cap->w_adjusted = q_data_cap->w; + q_data_cap->h_adjusted = q_data_cap->h; + + /* + * align up the resolution for CAST IP, + * but leave the buffer resolution unchanged + */ + v4l_bound_align_image(&q_data_cap->w_adjusted, + q_data_cap->w_adjusted, /* adjust up */ + MXC_JPEG_MAX_WIDTH, + q_data_cap->fmt->h_align, + &q_data_cap->h_adjusted, + q_data_cap->h_adjusted, /* adjust up */ + MXC_JPEG_MAX_HEIGHT, + q_data_cap->fmt->v_align, + 0); + + /* setup bytesperline/sizeimage for capture queue */ + mxc_jpeg_bytesperline(q_data_cap, jpeg_src_buf->fmt->precision); + mxc_jpeg_sizeimage(q_data_cap); + notify_src_chg(ctx); + src_chg = true; + } + return src_chg; +} + static void mxc_jpeg_device_run(void *priv) { struct mxc_jpeg_ctx *ctx = priv; @@ -1209,8 +1268,7 @@ static u32 mxc_jpeg_get_image_format(struct device *dev, return fourcc; } -static void mxc_jpeg_bytesperline(struct mxc_jpeg_q_data *q, - u32 precision) +static void mxc_jpeg_bytesperline(struct mxc_jpeg_q_data *q, u32 precision) { /* Bytes distance between the leftmost pixels in two adjacent lines */ if (q->fmt->fourcc == V4L2_PIX_FMT_JPEG) { @@ -1261,9 +1319,7 @@ static void mxc_jpeg_sizeimage(struct mxc_jpeg_q_data *q) static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, struct vb2_buffer *vb) { struct device *dev = ctx->mxc_jpeg->dev; - struct mxc_jpeg_q_data *q_data_out, *q_data_cap; - enum v4l2_buf_type cap_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; - bool src_chg = false; + struct mxc_jpeg_q_data *q_data_out; u32 fourcc; struct v4l2_jpeg_header header; struct mxc_jpeg_sof *psof = NULL; @@ -1331,51 +1387,11 @@ static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, struct vb2_buffer *vb) if (fourcc == 0) return -EINVAL; - /* - * set-up the capture queue with the pixelformat and resolution - * detected from the jpeg output stream - */ - q_data_cap = mxc_jpeg_get_q_data(ctx, cap_type); - if (q_data_cap->w != header.frame.width || - q_data_cap->h != header.frame.height) - src_chg = true; - q_data_cap->w = header.frame.width; - q_data_cap->h = header.frame.height; - q_data_cap->fmt = mxc_jpeg_find_format(ctx, fourcc); - q_data_cap->w_adjusted = q_data_cap->w; - q_data_cap->h_adjusted = q_data_cap->h; - /* - * align up the resolution for CAST IP, - * but leave the buffer resolution unchanged - */ - v4l_bound_align_image(&q_data_cap->w_adjusted, - q_data_cap->w_adjusted, /* adjust up */ - MXC_JPEG_MAX_WIDTH, - q_data_cap->fmt->h_align, - &q_data_cap->h_adjusted, - q_data_cap->h_adjusted, /* adjust up */ - MXC_JPEG_MAX_HEIGHT, - q_data_cap->fmt->v_align, - 0); - dev_dbg(dev, "Detected jpeg res=(%dx%d)->(%dx%d), pixfmt=%c%c%c%c\n", - q_data_cap->w, q_data_cap->h, - q_data_cap->w_adjusted, q_data_cap->h_adjusted, - (fourcc & 0xff), - (fourcc >> 8) & 0xff, - (fourcc >> 16) & 0xff, - (fourcc >> 24) & 0xff); - - /* setup bytesperline/sizeimage for capture queue */ - mxc_jpeg_bytesperline(q_data_cap, q_data_cap->fmt->precision); - mxc_jpeg_sizeimage(q_data_cap); + jpeg_src_buf->fmt = mxc_jpeg_find_format(ctx, fourcc); + jpeg_src_buf->w = header.frame.width; + jpeg_src_buf->h = header.frame.height; - /* - * if the CAPTURE format was updated with new values, regardless of - * whether they match the values set by the client or not, signal - * a source change event - */ - if (src_chg) - notify_src_chg(ctx); + mxc_jpeg_source_change(ctx, jpeg_src_buf); return 0; } From patchwork Wed Mar 23 09:05:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 12789615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E8AA8C433F5 for ; Wed, 23 Mar 2022 09:24:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EisuID1oPxC3qM7Y19YGTnl9LVPO6fSijRp3LphCeQg=; b=QVtTKimZVea9Gs tTsCQDBnRfe+Zm2MYVPWanEzKcZsHOnBkr+niJJS3rePlSUOMycKgHXStVc+uOL4JCB6V5UWInqu2 w7000QO4JF+r22LaUCAPod3zbGbWGCRO+RGniKXWNLSXEHNP8sQoyYnF8QQtS5xcZlHNcyhOl8uOG sD8HQkUQnrtk4JEPCrvFxy62PHNf9CUHP8tNwce946QtNY/KTQBlZ2tJyQqCvqd1eVLwwYafOXTt2 NsWmm7IQ5I9zodffkl2YDMHWKqoIyO/5LzfSrXmwtVHpxFhgB9yuGdEciZw4apsO9xmyEFnGQt6rn YR6Q8BdDLNwgsECZLfog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWxCW-00DEJn-5D; Wed, 23 Mar 2022 09:22:44 +0000 Received: from mail-vi1eur04on0608.outbound.protection.outlook.com ([2a01:111:f400:fe0e::608] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWxCS-00DEIy-VB for linux-arm-kernel@lists.infradead.org; Wed, 23 Mar 2022 09:22:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aeXuiyq4prF2Qj/JVZI108nNsZMj0nyGWf3Kd3Ws459wrXbgmWNJmO+LVRYq3dxmqCwKc7hVjmigNo1n2LtnxHRThOOMrJs+cD9h/W4O+wdwAtjv6SdB6M9uyoXxcp3toLSudzuIv9bbxIcZdzB/3IX1juYDXtkQ15EH77EkjWedR1oZu36Gnwc1o5ipogiMaDN9lCUS+dW/qwFWTCZlJl/F7V9JMi9BDylcUZi6W7q5QUyJXeagiA4X1wpcDCzF0jg+x6U3z32UbxCtItCAMlNpAGfozvOkjEjSvvqoSkXDntmw2VSpN/yus60XEqOU67gq13bgQrRBNVCLmgVZsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SgI6WfVd45h4vDMCaKFbnqdkIhyPrO10ugn9R9MRfSw=; b=bXMqyT1f2L7XPRXdj3OI6cNHRQuGEM6xNttnzWy9KAeFtUYOwoMVziL9E5f+Hchm8Z3io13t0j30rQL5i6Pb1Bmnxz2nIB2HdvwHRjAxgkeqPn5ucLuyIhC/63anvXuiE9bfyUGm1k0MrUSvpP+Gq2Q1N5wn2kN4Q7QOfEQ9Gq8xxv/T3sKyKhdLkxevjIYkf2phNq4TBfQhgaoADivTw0hKrv/Vz1xLOYPXCMG3vfaZI1A31CansaalAf6YpI4U15wtM5H9JJZMvpRCE9e59hkHlYzH988udPbHlqjReLrubZgVkXXaIY0DTr6B5Nvl0jqf5PQjIH50KQX+vAwn9A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SgI6WfVd45h4vDMCaKFbnqdkIhyPrO10ugn9R9MRfSw=; b=HZU8pL4pTTFn2VIWa9XoJo9QYITPftk2BC9D9gyEDB1rrJsFL9R87LwOJ922K8rndjXJbNz6Z3q6zlkcmRkE/FlCl0nty2Xd57Y8ouNFLciT5LGs059g8qWDxVbaLZAVIXc/n0ntLNAmh+W0aQbOImL6OXc+09BKkZQHmEFnwsU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) by DBAPR04MB7317.eurprd04.prod.outlook.com (2603:10a6:10:1b3::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.16; Wed, 23 Mar 2022 09:06:33 +0000 Received: from AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::c39:69cf:c4ea:967]) by AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::c39:69cf:c4ea:967%5]) with mapi id 15.20.5102.017; Wed, 23 Mar 2022 09:06:33 +0000 From: Ming Qian To: mchehab@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, mirela.rabulea@oss.nxp.com Cc: hverkuil-cisco@xs4all.nl, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 5/5] media: imx-jpeg: Support dynamic resolution change Date: Wed, 23 Mar 2022 17:05:58 +0800 Message-Id: <93dd8b6a487a4f228984debb7a255d7ddde8f490.1648023273.git.ming.qian@nxp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SG2PR0401CA0014.apcprd04.prod.outlook.com (2603:1096:3:1::24) To AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 899d3802-8a78-48b4-eb91-08da0cac6d61 X-MS-TrafficTypeDiagnostic: DBAPR04MB7317:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HTO4qQoT08U52nOo3eCm3j8DgnJNIVOq42dpPP+tcw9SoVB1I7h7vryU31Twwm2khm+5jTnBEBzJq1PbRZ5uiULtH+22WeGv3sJQ8PR35Hrm60Rdxd5gL0wTslyZzJy6KotOVNFxrQe5563YDMbxb4t5IpNbt1wx7VSZfqGpcaEIt7L3QCbMflmXVsC2kWoxJ0NHgHGXdar/KJPIHYQl+uTtXsOqNLAHkf+8XRf2rYK9xrfBdBT8b8FlyNiSJn9Kz3Z95LzxlIVH38ZEoAm44v2bpis+8dwU6VtDbNmWDUh1Gyut1xMlfPYLMNA/xDp3ZAj3enw8x6W08Dna/G5zvXsodIgsYfkSCDW5mxq6+tuKB0YwvbHzQUZYvSh/IijR02iBZPRNcpZH0RSrxwHrsganPkxzeK98WoSicLWZNGmkmUKZUMBj2bDB3OIboPhvDl3W0IWnic+3UlvTXcLLQ/CwGKbdbG5o009nMCqYVaLLeytdK0Vmyp45JqcsCX1tL73tgs4TfQN2xAdPd9sL/AoCAq0NhMM2kn4mKf86Wq7mwVKLE1RoFkMEaXCqLXItddD0ESjNzRuevGoPbq/lloy84Hk7eFE1q/cUoLX0Y6N7BKyoYRGi+pBKeiAjR11ncwF9JF4B4tDC9tSb1HuEiwCKEnTtKW6x+npktLgCqPnIiRk010xOY53gDHYE3F2BFhZob8K0ZUIPODgMbKbkNg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR04MB6341.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(66476007)(5660300002)(38350700002)(38100700002)(83380400001)(2906002)(66556008)(66946007)(6486002)(7416002)(508600001)(4326008)(8676002)(44832011)(8936002)(316002)(26005)(52116002)(36756003)(86362001)(6666004)(6512007)(6506007)(186003)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5zqcujfl4D3opzlaA7hOlLr8WkemqD1D+6UWxDF6sXeP240Xg9fdUdDEpVPeJvTM37LBPULosQgUOT1B310U85CMpLaYG+0ntgdUBCim0L999IqzdBYuWi4R7r21qL3B9k6/DMn610PmuzeRsmp2rljMgoBKpKDP0BSCx05Y3YPLht4G5oTvFjpRg2AW48D4dYCNkDd5JmtV9M5bNudpHWpQQDUie0ClC+LfflMYkc5uj3OofWd41iHlyaluCxNLs3EfaLAdZNCgB+trWsTehv0l4BFNzPScfKppBUGJjAKkGTUI3Tg3kpIbe4p6xGFZIf6BiNVhToZ3p8/DycxardInevtewarWdWo6IY2Dth9usxxz6yGUM3TBWuiXW/e5D0i21EMS6Ssb5rFmFcgz+ij5xM7dUJHbqF31RdnrhY8i/Z7ruVmsKh/2HCDXkq5LFvW8hI4qmf3IxnlZ/Dve8tsaqf0V3MK6U43JGiVyzpzvtakXRLmoRX4LlwcwIqvZf61FNk++/lDpyk/e5wUkEcR7gzfn3D7B93IjF5nxGYte8ScLNIp9UPWIdcbMm6vXcz2VDrWTANq28QE62V/HhtWVSeT18pJym+7S2nVISDnvweOstZrMavlvuFzwuMGUMOLcpzQsE1X0jAhTQ1KGHhauVQoOOshdUW6+kRN8X2xohqKTrBC5xx2sMm1dJ22sAJVdlEF1WM9lbwOfTgxVq9CPVamNB7L4sEPgf6CK/DI2zhUBpgRjvK2yt+uP1uOYuGmaUMRmFPjGzrGcmvZMOITkeh4IN6RuHsEV+OqjXLqADKg1Q48t5VTrJmyG182fpcxy4qT/lsQM4QOOP6QzC9psZl+S4IxGp2YAKFrZd1RvoGuOxV/AuWNgiczPfqvpou8PRoM7PQPnWFHm+dGtjm9RTG4t5YEjkCVpyqDiwwftOdOCQ+hOoMCMoQzedFxdkbq8cybEn4JLuBh9j8jYzJMm5TgeBzzUVFakto7xAcAWzKs3xeqgD27syf1hCVO8qpd5+HZbdRNfXtmJAfqBZJpFfgAQlSWQRMGEUE0BkNp5Fp8IlO7IGRrfnkKbwSta+XNFCkAuwo6Mq93AE3Rb1PzdcVAhzqfwAHw/HaxpF/6kyYYKI7NWXUK0aef+W8+Nn0otLrJzEbsV2Aq9Vpu/RMFTLTiMywbp2+glPwXrUasEJTgkgWU3q9VqzO7A6BKHCF7kGGe/HodridvaTGU0ABPQ8juZeK7E6OZBlmNhugRwgUt8sgvr4sod18TjTgv7KdBEZd8G1dHLVGirKEa6e1ICbew/8khmjgEMVFSR6it7SH9rCMe9C0NHcmInh9GpSnsWkuxUUdHgyC4/5ztSH3VaA3X5lcD7RkoGdnM1woL5mMU6h3gydE8elZZUbQxVSnhKTCeTRqbvAyje8JPPMg18I9RZ9DtFkbeYFKDcjPIi5vJ/H3PpendGs8BAzhwS X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 899d3802-8a78-48b4-eb91-08da0cac6d61 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2022 09:06:33.6951 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Y7HMsNOsewwkYXGdqLP3bbVLwkzJdyef2AA6d8p6G6OqCX43TB9UJv+O/kLvbCQYk7H23wykYAtQCU8TiRkRxw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR04MB7317 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220323_022241_020157_D2B438DE X-CRM114-Status: GOOD ( 19.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org To support dynamic resolution change, driver should meet the following conditions: 1. the previous pictures are all decoded before source change event. 2. prevent decoding new resolution pictures with incorrect capture buffer, until user handle source change event and setup capture. 3. report correct fmt and resolution during source change. Signed-off-by: Ming Qian --- .../media/platform/nxp/imx-jpeg/mxc-jpeg.c | 69 ++++++++++++++----- .../media/platform/nxp/imx-jpeg/mxc-jpeg.h | 2 + 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c index 30289f2be3dd..0c3a1efbeae7 100644 --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c @@ -933,13 +933,14 @@ static bool mxc_jpeg_source_change(struct mxc_jpeg_ctx *ctx, { struct device *dev = ctx->mxc_jpeg->dev; struct mxc_jpeg_q_data *q_data_cap; - bool src_chg = false; if (!jpeg_src_buf->fmt) - return src_chg; + return false; q_data_cap = mxc_jpeg_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); - if (q_data_cap->w != jpeg_src_buf->w || q_data_cap->h != jpeg_src_buf->h) { + if (q_data_cap->fmt != jpeg_src_buf->fmt || + q_data_cap->w != jpeg_src_buf->w || + q_data_cap->h != jpeg_src_buf->h) { dev_dbg(dev, "Detected jpeg res=(%dx%d)->(%dx%d), pixfmt=%c%c%c%c\n", q_data_cap->w, q_data_cap->h, jpeg_src_buf->w, jpeg_src_buf->h, @@ -976,9 +977,16 @@ static bool mxc_jpeg_source_change(struct mxc_jpeg_ctx *ctx, mxc_jpeg_bytesperline(q_data_cap, jpeg_src_buf->fmt->precision); mxc_jpeg_sizeimage(q_data_cap); notify_src_chg(ctx); - src_chg = true; + ctx->source_change = 1; } - return src_chg; + return ctx->source_change ? true : false; +} + +static int mxc_jpeg_job_ready(void *priv) +{ + struct mxc_jpeg_ctx *ctx = priv; + + return ctx->source_change ? 0 : 1; } static void mxc_jpeg_device_run(void *priv) @@ -1028,6 +1036,13 @@ static void mxc_jpeg_device_run(void *priv) return; } + if (ctx->mxc_jpeg->mode == MXC_JPEG_DECODE) { + if (ctx->source_change || mxc_jpeg_source_change(ctx, jpeg_src_buf)) { + spin_unlock_irqrestore(&ctx->mxc_jpeg->hw_lock, flags); + v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); + return; + } + } mxc_jpeg_enable(reg); mxc_jpeg_set_l_endian(reg, 1); @@ -1074,6 +1089,7 @@ static void mxc_jpeg_set_last_buffer_dequeued(struct mxc_jpeg_ctx *ctx) q->last_buffer_dequeued = true; wake_up(&q->done_wq); ctx->stopped = 0; + ctx->header_parsed = false; } static int mxc_jpeg_decoder_cmd(struct file *file, void *priv, @@ -1167,6 +1183,8 @@ static int mxc_jpeg_start_streaming(struct vb2_queue *q, unsigned int count) struct mxc_jpeg_q_data *q_data = mxc_jpeg_get_q_data(ctx, q->type); int ret; + if (ctx->mxc_jpeg->mode == MXC_JPEG_DECODE && V4L2_TYPE_IS_CAPTURE(q->type)) + ctx->source_change = 0; dev_dbg(ctx->mxc_jpeg->dev, "Start streaming ctx=%p", ctx); q_data->sequence = 0; @@ -1345,16 +1363,15 @@ static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, struct vb2_buffer *vb) dev_warn(dev, "Invalid user resolution 0x0"); dev_warn(dev, "Keeping resolution from JPEG: %dx%d", header.frame.width, header.frame.height); - q_data_out->w = header.frame.width; - q_data_out->h = header.frame.height; } else if (header.frame.width != q_data_out->w || header.frame.height != q_data_out->h) { dev_err(dev, "Resolution mismatch: %dx%d (JPEG) versus %dx%d(user)", header.frame.width, header.frame.height, q_data_out->w, q_data_out->h); - return -EINVAL; } + q_data_out->w = header.frame.width; + q_data_out->h = header.frame.height; if (header.frame.width % 8 != 0 || header.frame.height % 8 != 0) { dev_err(dev, "JPEG width or height not multiple of 8: %dx%d\n", header.frame.width, header.frame.height); @@ -1390,8 +1407,10 @@ static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, struct vb2_buffer *vb) jpeg_src_buf->fmt = mxc_jpeg_find_format(ctx, fourcc); jpeg_src_buf->w = header.frame.width; jpeg_src_buf->h = header.frame.height; + ctx->header_parsed = true; - mxc_jpeg_source_change(ctx, jpeg_src_buf); + if (!v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx)) + mxc_jpeg_source_change(ctx, jpeg_src_buf); return 0; } @@ -1468,6 +1487,7 @@ static void mxc_jpeg_buf_finish(struct vb2_buffer *vb) if (list_empty(&q->done_list)) { vbuf->flags |= V4L2_BUF_FLAG_LAST; ctx->stopped = 0; + ctx->header_parsed = false; } } @@ -1613,26 +1633,42 @@ static int mxc_jpeg_enum_fmt_vid_cap(struct file *file, void *priv, struct v4l2_fmtdesc *f) { struct mxc_jpeg_ctx *ctx = mxc_jpeg_fh_to_ctx(priv); + struct mxc_jpeg_q_data *q_data = mxc_jpeg_get_q_data(ctx, f->type); - if (ctx->mxc_jpeg->mode == MXC_JPEG_ENCODE) + if (ctx->mxc_jpeg->mode == MXC_JPEG_ENCODE) { return enum_fmt(mxc_formats, MXC_JPEG_NUM_FORMATS, f, MXC_JPEG_FMT_TYPE_ENC); - else + } else if (!ctx->header_parsed) { return enum_fmt(mxc_formats, MXC_JPEG_NUM_FORMATS, f, MXC_JPEG_FMT_TYPE_RAW); + } else { + /* For the decoder CAPTURE queue, only enumerate the raw formats + * supported for the format currently active on OUTPUT + * (more precisely what was propagated on capture queue + * after jpeg parse on the output buffer) + */ + if (f->index) + return -EINVAL; + f->pixelformat = q_data->fmt->fourcc; + strscpy(f->description, q_data->fmt->name, sizeof(f->description)); + return 0; + } } static int mxc_jpeg_enum_fmt_vid_out(struct file *file, void *priv, struct v4l2_fmtdesc *f) { struct mxc_jpeg_ctx *ctx = mxc_jpeg_fh_to_ctx(priv); + u32 type = ctx->mxc_jpeg->mode == MXC_JPEG_DECODE ? MXC_JPEG_FMT_TYPE_ENC : + MXC_JPEG_FMT_TYPE_RAW; + int ret; + ret = enum_fmt(mxc_formats, MXC_JPEG_NUM_FORMATS, f, type); + if (ret) + return ret; if (ctx->mxc_jpeg->mode == MXC_JPEG_DECODE) - return enum_fmt(mxc_formats, MXC_JPEG_NUM_FORMATS, f, - MXC_JPEG_FMT_TYPE_ENC); - else - return enum_fmt(mxc_formats, MXC_JPEG_NUM_FORMATS, f, - MXC_JPEG_FMT_TYPE_RAW); + f->flags = V4L2_FMT_FLAG_DYN_RESOLUTION; + return 0; } static int mxc_jpeg_try_fmt(struct v4l2_format *f, const struct mxc_jpeg_fmt *fmt, @@ -2018,6 +2054,7 @@ static const struct v4l2_file_operations mxc_jpeg_fops = { }; static const struct v4l2_m2m_ops mxc_jpeg_m2m_ops = { + .job_ready = mxc_jpeg_job_ready, .device_run = mxc_jpeg_device_run, }; diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h index 82b38cc2dfab..9ae56e6e0fbe 100644 --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h @@ -94,6 +94,8 @@ struct mxc_jpeg_ctx { unsigned int stopping; unsigned int stopped; unsigned int slot; + unsigned int source_change; + bool header_parsed; }; struct mxc_jpeg_slot_data {