From patchwork Fri Mar 11 07:51:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 12777579 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 4CF6AC433EF for ; Fri, 11 Mar 2022 07:54:20 +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=DkK4PcMDrjXIjgMoT4bN1Qxb5/yoDueLPOHLIm7qCa8=; b=obEbW3VZwqWyvh PExnpwtPzOqnsVEyJXpJhfpfXojDjvRbeJxtsx+eCNgWZONPQ5jRJaHZlZFD1LjlwkuLJU5wwriKU EFvGW9wQdS9QRFfQJjpxLVraMcPr5G8tfk0wEJLb+cWX9Yusbbrh8cjD9bGKqn42jB6F8bDdhkeir Z4T6HYo7L2xGhwlbGLeZXZvJ02sJWl/n2vQiGG3EY/aWbmeYfuv8/BxS6AJC4Ub3G9Lj5rVrJE0uL MoILm/5ECCbTgMPnu7ISvu6BQYdMrjQRMkMKdU6HgLp/j9y8r6Mbc7gfZcdpyPE3wkS3y0y5rc1tK W6hYo7LezV98j0y/MPjw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSa4s-00FOmr-7H; Fri, 11 Mar 2022 07:52:46 +0000 Received: from mail-am6eur05on20609.outbound.protection.outlook.com ([2a01:111:f400:7e1b::609] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSa4e-00FOgY-T9 for linux-arm-kernel@lists.infradead.org; Fri, 11 Mar 2022 07:52:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gnPQI+UEJhdh/tb0KBuRqmyVB6EaGk5oKGCpqrUwHW47I8FlVqB8A1IoEU8At3i8Y9s6fI/qSiprWbaBalrvx8ZlPc/CoLIYI+rzCEB/DzTEYNAoNgbeC34koXSzgtIXfI2/i5WQuGtHEbMvYYXAypbUh2knGCdY7PB/EnipBSdDBk2atB3+zmHtR4tElNFUh+CWh/ZoKesAYSS/UoIvpMVzNjbcFXeFTp90gkgkBmI6/4M5U19e71cVmWCXrT2VkXzdi5goJH6c6OcQx9fl9xxWTqcTBV/XudX1Qd+zBvroX/L7CYG2nFQ/vfNBjLeQJMaPGjZGTEA90iuNN+f5mw== 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=X7hcNMneOC9xJkl/Wtf0wJPxGaqpQjEMuKLCGvH/sRI=; b=aY9dfsMqi/5MR/u/ITqMj2Zsu1frkUVbowJBJowRTkYPBWwrEHGsoZvP7uLThBuuRfNk5FHlKActle2l6SrfApt/4Mbk5ZBzcQU+TinXCAfLKeyMZschY3QybwbB1nn0qNGvT/8XKZLgY7g2NC6CQlaeogjd69Xjm2YG7EUFzAmf75qURkR6cQM8xb3SrV3cCQ0ziVX8j4iWHubFkNLX/yftqbCevEOPRG09yY3Q0ON0RMPvEOCDQrpOKN8h4M8mr06SVJJszpxntX9NPfSyuIt345fRoR2f/UYbAEnm1MVQWXPj33ws6edaMH886hfRMqCPnib/bggKU13PPwtzpQ== 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=X7hcNMneOC9xJkl/Wtf0wJPxGaqpQjEMuKLCGvH/sRI=; b=Q2+4PeiRSRH2bYQPFCNMDbQ0PS8ns36SndqN6SyXYGfATMtoFk7SP7TFuXkjVZ2mpvou2xJzDpMirlvWKzfs4/5Xv4QtKvVMAGougui2vsKZfhgCkCM9eCiyBup1xnldgAHrusY7wJFYu+a3nOKL3Is9S2cya2O5ikcl42ClkPo= 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 DB7PR04MB4443.eurprd04.prod.outlook.com (2603:10a6:5:32::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Fri, 11 Mar 2022 07:52:27 +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.5061.022; Fri, 11 Mar 2022 07:52:27 +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 1/5] media: imx-jpeg: Refactor function mxc_jpeg_parse Date: Fri, 11 Mar 2022 15:51:43 +0800 Message-Id: <73ea0dba34b5bf02104517fce3f66ef2e6d96a16.1646983646.git.ming.qian@nxp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SGXP274CA0015.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::27) 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: 11317b55-abf6-4ba8-9740-08da0334166b X-MS-TrafficTypeDiagnostic: DB7PR04MB4443: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: eWIIn3dVgvz5oQ0aAQoCZcEJyS4KgMWIGx4WYIPRKhkUBRAJ5zifsQerjuaaix0BjMMN4m/UP91xIdR/1qFWh7fgYYWO5eGty7FDQRhPOsTXaWJUY3Kf7d1hnP+6f8mlEHzwMyL8fkds+4JjEhaZV6qKe+vfQH4xgFVtSmFHShHkISSliHBY9zocftSESdMFrdFwX1W5b099RAOrBAruSXk7JvdkoaCjFM+7MLBG+/7dnyl9qqEJEFhae/XwoZgA3J9DcAfqaZPTJFGPdAOodngeq+KDU/gp4Eslx6e6daK2txzGq9xmYeoxx3QZaT9nAfJAeVwesAv3OwZZn4E0BxRRmmHxq6X41vMRxC0l4PUT4IwKeCvalCUgIkQcaotu7gsZnbQNMErWkMrC7Xna4Jh6bxLn31/7JGXRKrnFVqIFFpWbvw1xj7Sp4vUKUoM6pMZnjZD4taWJeVlvUhyApFui4RwQsAHRxsQPLZn4OxJhSqyC79b1SNq/mVT9abEb+AHyQ04fLVezIfZL2pdkTqxr5o/Hucw8aLfzMb4dL7cxDAHY0DNf1KpkGq9RE0BmL+thG5pmB1TzykXBYXt+kRSfFe2gzNLTNjMaMruTdKNllRk8HJg1JJu9dSXWWap8WJtA0JF7vFnoeFjYCXnlOF2tlwrValN1EXgUQRdbj+la+67eaing5YVsAExjcnXqpB0bobWG8jXGCeSWm/MBAg== 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)(7416002)(8936002)(26005)(52116002)(44832011)(2906002)(8676002)(6486002)(2616005)(508600001)(86362001)(4326008)(186003)(66946007)(6512007)(6506007)(5660300002)(66556008)(38350700002)(6666004)(38100700002)(66476007)(316002)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0hiZ06YDnZHHvWPuVouM+ZobIAQ7MjSakku7dDO1p94aBd8NHPbO4IA2rbqngJ/qO2ZxAVllJfiEJvps+Y/TC7o9Bvu/qZm4pfdCBmHXdLIzxuV2kz9XBqc/0iq4Fx7PDbMw8QKuVdm21jsYcMvfSNxowLlEr8hfCkRZD3hrkRMrJtHj1tLQc8TYR8Qee8Io0j2TTnzQ7CVbby5Z/qS5hepG9YvVzH3/4HAMHomEVkyucW4woh1CDn9GUntJuWlD/PbS3cop9byCHvxQojPIShMQvnD+AHnTUO4Oohxw8rdDUHpWJnRRuON2Wh1Sr2wV3e52+AglBu2Q9MCQWrvcR6lL2zNnPebfHtDMy7Lf8pcCCU3SJTE/SB5gI7H3VU+DvQ0SV7ZTbFBX8NIBimlouQPGEAf+Ob/O7EbSTvfwOkEnaJRs/sNfOh6jGXlWLe+7X/BtuhTm8Cx8OWrlKhuc09rz3sImMUqoU3b2AmUBWDbVjtd2+cR1kSPMoXk/AaKYsnMPdx6741Mdy5CNzX6H46q6xoQNg6NK2De9NDntCj/rZY7+WQT/zgcd7LUmXwYajIHN8DSXj2ZaS4UKortclPKablZeFQFuoCz6eklhdrvfd8nE4PYt7FYV1lT6nPF0blAO+1+3qJcF9wpgHplZ7RJe4LjUc+iZx0dXyJSUL1ea8uqkBjHJ0YRoBtWcHdfUAJoZbCpX4WXVLEoo9K2KzRKUoajaH1AOh93JcaJW2mNYWLsoStEi7HsU6wKs7/tafP3tHk5LYkOWbG0ojWNGM6X/NwEjDLdmwQD62TmwQ91adjqKimkSpHczq1UUOTikei9NUyvrGuJN5oWIeyb9yrzxXqieLCVwVFMmtSU7nThdD+dB5twPaT3c04nS0BwfGP02e0sSMhkGKWDVYwYk96t31wdU1fyeimEHVVK6MYZvS35bkGBVutbGaFLNxc7Al3keqxN6Vlya7IiOQGUKXp8SLK0ag3XWSxpSzfxsGm9aFlUJ059NbOOXmodiyp+CQ+xYQUxjwFm70VeUCIs5TZ2MfYjxkwdcvItXBn8nnNSDOowfR0M6RYz/oKSUuQ8XEXzovWRlkx8SuMkN+CpUSCyNRvm/YQbIZBXf6mFsPGlrPGHOuDzJz3DKU84IiMRaAsGLQxKg4KO0kt5YHeUEY9nsL5KEGJKp0wVXhlP0N2ban94GZTu6b+4m3fjZU/HCaxn0Yd9v3NplUX5n3LXQ4jEfR5b+LPx0IlBAAHZMZ8AVaW9uQ5uuSg8/ljgL88rxKV9ujNtzcX3qmcYpRVl6v94X+n8FH/Lme7sfbu2u6/0GKPpusKUh6Olp6MZPAmFJjSw241M4UaSde3FIq0tSWNHxgy1flOEr49GZOziEmXNMgJGKyIxULjCoLPVexoa0UDJ/AdHS3dHuj8nK1Q5ebKyCljrOU9tqF5uWykVyh688VPJBE5WDuoNJUQuxJAa1R3Ecm4nVG+DMcFyzduae3l/8QKWbkE7Xre3b10PUDjGz4JsxX3l56mRw1eXDtMCYRK6HmG2UJal9G89wsVDI9OBqN4jS4SdNswJdh8x0BjnBdCKodZlyNHLGB2z7IenHw5g4sJI/Gfe+l1THO06m4rPGZd+KWbdFLe6Y/cQdvzY= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 11317b55-abf6-4ba8-9740-08da0334166b X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 07:52:27.7710 (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: JId3ZNfD/y2qNkYRfh5r4cp+UJRWv3TQ+4Wfp1wAeNOOyurgL4daSrSG4FjZkPqV+kJ8+ht8R7W/zZjEPVblCQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4443 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220310_235232_953320_41D38088 X-CRM114-Status: GOOD ( 10.85 ) 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/imx-jpeg/mxc-jpeg.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/imx-jpeg/mxc-jpeg.c index 1de0400750aa..d8d24c19f423 100644 --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/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 Fri Mar 11 07:51:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 12777580 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 CF486C433EF for ; Fri, 11 Mar 2022 07:54:35 +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=TRMDnML9vq5+Qo7J4gVoi7GHKOT/SL0UjBJNvRwkXDU=; b=b1ZmWDvm9T4bzG e2l556yHVNzxa2kHkR+oitygDjjc8rpBswt5Z6lrbU/vnFNVMZITx5Mx9ZuFq69iYEKNWXwrsp3Ll rXsvZ6TpxXjD07lVxM+nv2BXP22OlKY2MfrU17KotCIyUYOo4sn+Ir6G0QrpvDRsSaeBvanOKEide iQyw51ET6GdlBa5mOEgrmhIzPMb9qWJ6Lf+EmDKVXagIl6G26bF5iOsBuZt458cYD4R3y8Kvgsnvz 45veIk5om9oVIC9mHzW95wQHUEiIDi2HIgkAiTJcPd+DmQ6u+Jz6ohM+g1UOWBm0Fwz2xBl+s+6IH xXm1whREyglHMS+5Kp9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSa54-00FOrr-6k; Fri, 11 Mar 2022 07:52:58 +0000 Received: from mail-am6eur05on20609.outbound.protection.outlook.com ([2a01:111:f400:7e1b::609] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSa4g-00FOgY-Gh for linux-arm-kernel@lists.infradead.org; Fri, 11 Mar 2022 07:52:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GqqsjVK28CfMfzRUQh86mLAsRHATIVXXSPsDZmYiZFf0fRYohIp9eVBnTC2eSZTpWBvMRq7ub+1WoAMYgkwOjLqzhl/pcVA5HojLdZPDKZq0/jtvaILXaPgcydbK26AinVA2VFZDZao73AOCj95pCR6NojCApMGzSwiqPOSzbAxiq99k7ur02S4HCsCgIIczbzY7fz3HlIO/3lIEfmGgPYakydAJtF7hWODZosQNFewW9yXQlcRHt+EEATsQeOHQvnz3cu1vShEX2DBAqG2BoUwOuxVUIeXxZ1mxmDIFu/NnRUf7ynR9GksjhNLKMXkfzM9l8PqoABEBGgJKHCEfqA== 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=VE9QcKGDoUZhfJe4o47yAi9yM9BKIcAXhlDwk+vQ/74=; b=hc4kelUFIYgdcRIeCXyCkNNdmUwnkIJCoWSf/vbMDv+UVxw9knVwHXf3LOg2zYq+afi0IhbQF9SSObQ46aMg3lGOXtq2AeXvHNsABsuLX6tUHynOhbUhYt06ucxrxcJY/9s6qzAa2fVD1S/A8YUPwNRm4DKHFddWeNBUToX6xlro3gSKvqOSX95sbT0n6zT53vsJVAZbQKdPa6y8z2nsjxn6VEwWn4b/S60kgkFxKGgmK9j+UBcAxdDO9RTTdu+J8os0LqbCc0X7W/HKq77+0qkMgM8i/uLqKQ6KnhzaMkM9PD/4Y5jf5v5YMpGQkgfeSD+OKx8g2PGtk/dgmwLB7A== 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=VE9QcKGDoUZhfJe4o47yAi9yM9BKIcAXhlDwk+vQ/74=; b=q729wGKZXwOSzoV74M1+sjgoVESnsyA0j17PtzGY3hvgaTlcToNxdSLovrDdYBfoc0Ofd21y0pJ9z+hlDkrd3Wl6rmgV86B39tw0OwWo1DZ09JGZI7x0Qk0qKR+aoFU9cOsYynhf6kgdRb4o9coAi0GQ+uiHbzBXMsQ5ihJ2Eqg= 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 DB7PR04MB4443.eurprd04.prod.outlook.com (2603:10a6:5:32::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Fri, 11 Mar 2022 07:52:31 +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.5061.022; Fri, 11 Mar 2022 07:52:31 +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 2/5] media: imx-jpeg: Identify and handle precision correctly Date: Fri, 11 Mar 2022 15:51:44 +0800 Message-Id: X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SGXP274CA0015.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::27) 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: b88abc27-3188-4735-4e1f-08da033418b1 X-MS-TrafficTypeDiagnostic: DB7PR04MB4443: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: 1m9purfkm2vOqhSdvNO68oya4rtVBFVyXfZgLGEL9KA27NseaRMgGmfY+41POQ2Okrn2qwSh7G/ElYPHNQ1FsTVwCsOV4NnNSbYUibTXYEmNz4mXKh+Tv5lVC4u6UHVlcg53zZuad3QTvpBUmTdXnUa91TdxptrKJ/95WY+8XT8vtbaf1UwocHpqCvxNsezNzyCSdWKE4aldqjlEIhZ5WdZsCA8FlARqhYMDSZ9Bln0Px0CIdXQd2SQXmXFlrZQBpksFsaA89H+HzDDsi4131yJoLcE3kUNbYANdoupSkp6DPLsCkNebC9ebivCW4WF/eoo6uMOPZW6iFZ2rlpX4LchmrHkNZ4MazzXIMWTh2XLcf5h6AIktSsdbLeKaZRLq30haKXPN2wYbJmwuc9idzbpIcov6HOXSp0hFBSw001H16uGth7NRBhpYD8Tpk2ptXf0Kj4lAUcTxzVBaYqgGbTU040i13sxC8S6oNt7/UJYok0Je7Eotd5meoHtx69V1jA83hgq7Q8EPscZEF5fUCkNfA0lQi9gv5o3QX+KM7u9/8xItVaXp1fsxKaQ9Rus3PbuINGsOy8Uq23cr5RbgoJSgv6EjKd3WA61k2kRr6rv2EiesB+xD2dQpzOf60iPtH5vuRULBChK7ZsLqavZ5VrvtEPE9KesPD4teFZjL/3aHst3D9FnyzZc+YxNZ98T8V3/6l4N75Op+fSpxq0HNdA== 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)(7416002)(8936002)(26005)(52116002)(44832011)(2906002)(8676002)(6486002)(2616005)(508600001)(86362001)(4326008)(186003)(66946007)(6512007)(6506007)(5660300002)(66556008)(38350700002)(6666004)(38100700002)(66476007)(316002)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: s2tVwOUIQznyeevss/SAUXbElkGAFHbjm+YyxPPI4Vn17GhwkvOkX6MsgYqeMiYawpcwJAL1jtJyUf7LYQ+R2Y+sYFR8/N6F9tL+PATGDsda97MGF+JG4mxkf5Sb7MRMY5MbbB4BvJA6aAQUJoUNSIo5wEbnlGRLvCV3s3vsf18r69UBpkRn9FGBvrcxX2Ay3hhvZavNvovhRnFvzPD3tsEzZsv0k6WvFx3uMot3BNZaDZG5H6WKfNQsZjU4KYOF3hGdewzkYm54OeZrN9asI0Cm3H66ifdoSGYGQKQHbJN+JTloncKRzW9AK/EhdKyKydVbW8Pbipw2dGZWfI+Kguxqcydsi/nE9S9QQGWHR8WG8AAisNmYvTO8TSTKcZXdUvrlqqH+FCoQnZKIaQE8ZV3ihpgmXJ6RMonQ+lXeEzfmZGqwdMkUohUWQ2OPLo8trwrDjcjbtNo3CL51G0RmGBy12lKdEpkhb4Ha8g7KX/9IWvHVF59wzHRITHWZUM8n7jeFAVA40XEMRJayvYS5Z3uihHEFyL6ALDMCeuKHSA0UC+1PbzaoCUZX0DcfJ2TwvkawmYxZk2eyYxphopjB+HC/RcxoXph2aLJNNQRzu1N8IMlGOUM8cu8w0ETEPI9tjCtKAS75wkU/oXAba+0GnsJHoixWTau0SHt6iPgl4gcx34mpEpOdhEiuoW742IV9zqyGMh21xi/xbzobJpj4cKhIzJB/waeJzB9FviG9tXe92zXy37uGZg5xAchcL6LItPhhAGwHwgoNj2jii9L4AbZz2Dqy3pmyY6Bj4u/zWA6+nfTImFP3fTLfeDOdy6cujNzkRYIeu78mlFpX7FcuoYy7NLipFDURn71DB1p4rz2pQMtjht7Nfuk7jVgb4iTaHT9fndxkykwFjyOWUfTvLE6smNZhAxoRDakNfvD+ev8eBNnzYQGjxrtWcg8KzYjlNTSpZ2bkJOhSShodszhSpU6qOwDgY/IPFxF6CfJwAosiQhMRcx3NiWaRbEinhI8czqHdlP+0PRzins9DEjcerarcblvZxHlmzTe+qFjJdjhw4GP/PanNPqcg6vIBEzDY4k+3UdWX933Js2gNvzEhIC4+fR9XQGXzoo1gi8ywqzCR8SXOAFulRPw6H8mlfMkyCBtcVetJDnyihZT2yAgTv31od7w1GqPnoXsdVM/7ftxVZtEYWgRWKg5Ee+EdpCzee5FrGKcSKSnaM8cNMAJlRy2yE7QMcIkjdTtUzXG5oICVMuhYoP+6LH/dXYdMQ8CtGVBM9zcL8UaHhEQW36VvZS+dTNeAafFkx8rasRfG/iik7vcrpsNuxx/hs8y7e1OVwJtcsnmLqzLQSOdr8YTEnriIsyo2xS3AULM6YJjoyrjRwdghTDOrCUJ5/EEQt5b3zcl7EcBtikSWkKLUJYmScZARWWO5kMFG0qlqGG2BmNhQ2s1yRYYJgfpJ+4ueNL4LQNsGOzWYvWVJhCDQD2sZSenduwMrOlOc+/0zzCR6Pe4WiYF2HIV9HrwOUjCXzEIod+zndyXS+kvVXya6HgdDZWpTJNfKnSWPhgYcROYv/J8/zElxWOR2MvRm3hNoMshQAQUPgLzulPatMpwNVDyGskH6Z0QR5KQ2L5D9KwSs36I= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b88abc27-3188-4735-4e1f-08da033418b1 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 07:52:31.5364 (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: xZXK1wC0UGnSNHHR9C/qVzIe/Y3VBfRGvpegw45uJazzQ/E7tfDIujyBZ7ZzujCh6kZfiGL6bVkppVz1nrNHDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4443 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220310_235234_590092_2B185722 X-CRM114-Status: GOOD ( 19.92 ) 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 --- drivers/media/platform/imx-jpeg/mxc-jpeg.c | 37 +++++++++++++++------- drivers/media/platform/imx-jpeg/mxc-jpeg.h | 1 + 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/imx-jpeg/mxc-jpeg.c index d8d24c19f423..82b9b4630d9c 100644 --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/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/imx-jpeg/mxc-jpeg.h b/drivers/media/platform/imx-jpeg/mxc-jpeg.h index f53f004ba851..82b38cc2dfab 100644 --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.h +++ b/drivers/media/platform/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 Fri Mar 11 07:51:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 12777581 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 5EB45C433FE for ; Fri, 11 Mar 2022 07:54:36 +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=GdfN4KlKeQufE/GHS7qVeipx39E/sZTdfHJjLh3IKQA=; b=FLAuNjB/LOUji8 UtJPGnYykTHUS1rGqA/0Bw5q5IyFl2Deqw6sUSycEAXNrus9OHTi8ACA00hZ7PeV700kQLg6L/L3a b0THrdeDmAefh67+Ym/7ZIUkuj+gIUWmX7a+p+QcvZdiZX76oRIjWiurnPk6OxDEAoDIP6lTiYI17 UHLZbT75SKwL/zlPkpza+HkHRQYkiiVv0G+s2CiMkXmhmoAxeSVB1LzwR5Dk5Jfe4AAgVTyrqB95x +V/Lo35xji1GU2X27nMk931GceZyQRfxCemHwjPx2zgjCNNjc6Uxm9iHRzwyuvhw0a5nN9tnZmyfx 4sTvnMlRolSM3fel/2/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSa5G-00FOxZ-HI; Fri, 11 Mar 2022 07:53:10 +0000 Received: from mail-vi1eur05on20607.outbound.protection.outlook.com ([2a01:111:f400:7d00::607] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSa4l-00FOj7-QD for linux-arm-kernel@lists.infradead.org; Fri, 11 Mar 2022 07:52:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AIxdjQBQAbN3xxV0zfYFqmMvZ/gGSqEYewMOm+z6fpUKKBawa9J/2PYM4p1cTqb4WdcTBqh00xQ8IFM5CHStVMX7a3Vtsjqi6d0hJf1FM5h6m/Y6+UrM6juF8hW3KfrvKWWw718zR87MjS1LvDHFL8p8PfxcO2si9FGOgzF18cShB4gfwCq1UClTbsfiDjZm8oXDtvUW9V5rPqMS7rZa9DimG0lWj51z49NwsJ5Srx7z1WIMu275Pc02RCPDM2iCdTketOlsdaEx2VQDnRHbaX8GkUs1bsuK/IotT4UjeE3AVTHZF+VwoSF+NbBVrzVhpfzdssMs+Gq8DNstRweAEA== 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=ku317mUSHruXe+eqtL9Jhx41SjsYYJOst5rCfUruQV0=; b=A1gQ9pXRv1NknBpJxT9iBbJC/41GuWiKJDQUcwzRky+kFTmA6xqa3/dmzI4UwJL5sMIGWDDkIDavjChGWPDlbvOYDoqVJ7yDS3ppUIw5r7oIE0/+zI1OZd6dkIs9qtoW6WXsvroWXOLZGrtowNHkKHdOadvTfpjpFM8H4EqUJ92lO+EfGeQRqG1LiaSh3u2Mc+eYV2SteLFSjgBcNPF7XFcowOtsiZ7PnKgMUaLMOztaWQwCmMumT9bNVWRtdjtOgVi5oNXZ8LW0RwCvJRy6mNEdU9Fjof2+SOL+7i0LDkedxpmNYCqLmjGcKosz8xOZ2eNaoR6xt84uLjLZkqDigQ== 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=ku317mUSHruXe+eqtL9Jhx41SjsYYJOst5rCfUruQV0=; b=ZHBwT+U5mdAlC+QCh2c9bXQNQEyd54tJp5TH57uHRVB05Rpcjfz082hviZzcSpImbsG+pHKkXhl2/a41saGE8n7/TZRHWE2ZrH2iA0A0HZFVX1ljIRbZ9UzURK+WYYJsfaOWwKEGnTEx8G2YWSS2e09NEtYUUL8w8aGh45H4644= 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 DB7PR04MB4443.eurprd04.prod.outlook.com (2603:10a6:5:32::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Fri, 11 Mar 2022 07:52:35 +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.5061.022; Fri, 11 Mar 2022 07:52:35 +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 3/5] media: imx-jpeg: Propagate the output frame size to the capture side Date: Fri, 11 Mar 2022 15:51:45 +0800 Message-Id: X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SGXP274CA0015.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::27) 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: 2600a90e-3dc0-4fac-a2b7-08da03341af4 X-MS-TrafficTypeDiagnostic: DB7PR04MB4443: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: XvbHJyob2eZvcyOfJP8CpYjL2PMkQmVjclDec/TNye/LkbMocSLfNnGafv9Exn8jhAfccPYIvqevFW30nYr0xtyNYfl+oW1WRrvX/jPDxvpRlZcI3VG+pLrrwqh9JpESNvEpwJ8u3SbdkdAxQBC1IDrc4heLvm8Asf7lDI37Oiu+WiTsIf1N3pMmpDq7UQH5oxgo1/mY1UDJDC0n6e9pV3Ln4Vu90f8XfoU1wpQrEZbzPn/0MEtcvQEJwn1LV40HaE7r+g9wvQzpn3dlves0kM6raCom/Yi7dkcm91dhGl34pMTfeyWz82EWA7UJ4fpwn1+IOlln1RyE2D2rK5K5/SD5Woka3M2GovpAGg+v5511NehkHp0cLmanYrEJaYvaUJG3B+y1sXZxOAz0t1OWm/ccUHdJ9/yzylSfmo4Q859N1wOIp0a0xpywI3FwR1vfFR5zUxUjA1MpZnPisP6kqaGsdT7/5xF1BNfdv2THODXRFA6IjnQTWOF65D4iL1Z/tVxl/RKTvnDGccj4Jepny3gg5km3daZFOY9P/xRigsoCityGFvBPXDcQYpwEvDtC58aCAU3H/ALq5LF16FUpoMys4PXw4zzq9IZe0syEr0peksI4Ix2HKDM3u0GGSookkaYAtHVH8zc08OGDhdbau9ndfFQaYEXCz/ITnYSvxJni3SHHqQVhRfIp8hG1PAXFn0WVi5ufmCE0ROvANMGF9w== 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)(7416002)(8936002)(26005)(52116002)(44832011)(2906002)(8676002)(6486002)(2616005)(508600001)(86362001)(4326008)(186003)(66946007)(6512007)(6506007)(5660300002)(66556008)(38350700002)(6666004)(38100700002)(66476007)(316002)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Tet9QfBlwgEe111tKBeUvGQVe9YiZfOM0/n+ikhGogBnX2skkCk+RTxqpv0dJ0albz8WoJ4mANZAVU2MkAwPrTzlfePk6KH8igq2uQdSy+fxvDVM4lWo0N8dFWj62kL42Y5BYqxzHMVxvKoVHB+PBN1DOj+blW1KHTEE6XI6NGR5f/IDV/YQW6Y7NfDT1XYlKRoCXunMVdEWdsgi7hOqkALFqqX9+ZemqFZMDM3+cDw4FIjN3fJsoHr+NdUI0agzGXEqYTNQXg+G/c+wwRJpUUs1yneGy58taliZm+tdTSb1abkAy61iosQ6YRmXDc0CztKVz7U98WiRs+ZlHZrlGXKir6b7UK/bbiclUDmZU66xZWQb7fg+xzvjrRMJrBgBORnLg+YiFn3Z5+JUgduiSeVI3NCYOIqsu52iqhN6YdSrVCeqcOlnL9RpJf4g42EESmIinlg5ltUWYrI1Y5uEyPkB8hnFXWY+3OnHLQo2fOu4EuCd6g6gLYsl1V3AD7xj46U+zOhoVUbtjqMjFDH3ciPoqC4psyRZN0Iq2MOa/mHci1RZsMm0R5dXuvokrjvjbt3RsTOk+x11k/DAJBOK1R3f5hAys8cne1MInEN+vdAzRCO6QpA3S6EBZVdB7hj82ediWj9lRkHI9IOf6dcNJCgUmvhvLv9H0ZxDTssLmGl9FkxdDxE0Am84h997Q/VoUOH2PUwpSIeuUKLsLN2sA6Eqb1zpC6afHLuGcPQty4BkycRQyXzDYj0r4mbhKDjmW8T532OX9IUl2Tgcg14FyVQepM4hyBMZGCpoEy35ng+qNkTEDa/Eq42MDEMYUJhV/2mjz3mTlYDYgjjwVuqNLvxLPU8uSvgRzO2/ZFO8VoF4FbdevCAXO4eyMlvr+9j4tXyK6pFy2isPwn2YL27jyfmrUy6j1mvUPvmPhp5Zx1uU/jhoBdLRzlJ5+QUxe3bonwA0Q1nbt4NUdBT0qs8IuMmumu06cDmXO1W2KlVGn7LJUHRWv5DmbBWHCWn9MmOgC2z5HHN3TWExgCRhARGQCzpylNx4MXwTDG1rYBt6qzRQyfFZJ2dalJXXsCSAVl49WSIIgu5FIp/9kNPTmtrsdpNoCJuWnv8dm/H6xB6SdWKTVSBwlsgSea3ngWZ/TjFiXiInz/K5oZnndMlbJqawb7Qj+2fyzkQ8N8u/XCbVY4G9XNtMsjo7XFEwcRDs9cXkq2ycjOYO7EffVs2s7vaYWtMaybWL6IobKPJhBi9DwaywOpL3DCPNBGfNqsour62TxmCWSzxwj/PKFugxTKV41veFZ39sBXu/U7v9SlkSbO4jhmp67d1R0ibpKrkGQbt02i58HlGJ15TmA6gkCPOvhkKfn7YOt8/3BhCZjdrCXa8XPqY8+qn4fZ6h9ieR/l2AyFdxLklY8L7H8mc1rGYOAz3VQaraN/xVkLl3osjqwhN4lYdrgpyJh53hp1Qk8PKz4OQyIGASeooA4wcs2WYWte5YP72QpRtX2TZR65NMG6QDbvaxolzgM/Un8kqmsgvkOzetwsfd5ngPNe9Bt1lNLrWkfqq23uLtVwiMx+u94O2DHYeBnIBfULQNfMECDdtSMDk2kETbgtbcfNuYzj2Z0VLXB/lM7gCj2WK40CmzGYI= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2600a90e-3dc0-4fac-a2b7-08da03341af4 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 07:52:35.5519 (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: MSbYlqDjIRxRI6Atgzm1+CvTu6qPT4vLY4Gs2+q96KIVcHoBmEk5ylAVyPiAczWwKo+zdaU4THv4RSrBeCgoDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4443 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220310_235239_893276_B8EA131E X-CRM114-Status: GOOD ( 11.85 ) 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 --- drivers/media/platform/imx-jpeg/mxc-jpeg.c | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/imx-jpeg/mxc-jpeg.c index 82b9b4630d9c..9e8a4157ce2f 100644 --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/imx-jpeg/mxc-jpeg.c @@ -1831,12 +1831,35 @@ 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; + + 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); + 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 Fri Mar 11 07:51:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 12777582 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 600BEC433F5 for ; Fri, 11 Mar 2022 07:55:01 +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=XD0Nqy7yZFPf5Nu/1CcHFxQL4NB9XcmiLmzoIeuOsvY=; b=P3dFLBXJyoVqP9 b5YqDB8kooyO/Z+d/EpU+ARJgVXxuIDXxm+e/RTWezRd5dMPcNXvveGkoPs147LtUtqUTW8xhOfin /jF41YUht7Uk3/Hzf+S6xSLZy/CeI+8rpkFCw4Qp2fm56FzWqxnmXBwt8QiQZV3memgb4kaFLbm+m 9urwIeToLJkP1ANSLDpNfDdpx/aomjpomAklIxFZFq5DT8tdzHXk8OEJgiYwrTeSCXr2E5fy4pKJH 2myHVpHvsv9D/KuVUKMkch4vHQC5wRdGLNjW3Eex0NUvIaLu44QJiO20TC7wHlvPqkmlh5SQ2tTNC bzI9qFn07HEQYCpX9nbQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSa5T-00FP2q-0A; Fri, 11 Mar 2022 07:53:23 +0000 Received: from mail-vi1eur05on20607.outbound.protection.outlook.com ([2a01:111:f400:7d00::607] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSa4n-00FOj7-Kt for linux-arm-kernel@lists.infradead.org; Fri, 11 Mar 2022 07:52:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fRm44I/AqO9i8oVtGjoAwz2HuHuwAZoKhtckuycJBZhd71WEL09F0m6U1Rw7HNZIHJxcoleGrlOLNN2rWU4aej574zb+tZkJvOXETmx/USo3SlemG2+UaAZyVkymAaqnousF/KQY+qHFDohpCrWzXyg9oTZtFTBOwlAIKyYOGfOXqmUhxY7IviTo4vcC719jdwv/zbm/ktO2JL6gS8QUEJaYFVuJnJawAYbKCQgeoDaUbygv/Tv5URN7nwLvsuia+zRI6FKHnWCfyncntESDb+51gusvS3Wu6+B0fkLEwiohjcm7gTOM8nkZM3DqjLJkE1FoDstlgrL90u4/19Zgow== 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=1bUeLjEYNurmQmNiZYNV+D5rwdXTOYZz+osKmYIV90w=; b=Kg5MoKNn9rL2TRgKWNW7kQ1KSHK9H2ElYHjcRiPCNJ4ZwVld/3BU34Rqp5po99eFq2lW8HydXbi+VADQ4ze4bpstH+oVpw3ovBVr2n/UMDbiymlmsP2FczgIpFYUv2oIRdY8bhuy9dIQ4r7+ApUjmK3OUfxe14qIcKpAUwMVeNhufTqv1eKbYKIJEdukuCRpBMeGDInyMA/IxJ6kiATEC5VjFZwWfVgjTODNgZqWh142d1IMSzBOJNBwoDDB9pVXaMgPdc65vrJdb03rKqe61z+sxX0quokBmlFWecpa97VnZo1dmLKisY2D1He8wj0noeIA9xSC3OZZfy/SssIIOw== 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=1bUeLjEYNurmQmNiZYNV+D5rwdXTOYZz+osKmYIV90w=; b=PaiJ9PTGv3shDqUNYwUTVm6yaX0R9c65tbJYzLcltEz0UHBNMEVVtXepYZqL4mFDhGDhojyTIni86AAhUBoKAZOZn2E73Woi/GBB05ZaguVwxOcW/CAoYJ85sGk/y2tgDBc4vAbye2s+uluBygQlzsGIYxaVRwjmkHeHKhyumYg= 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 DB7PR04MB4443.eurprd04.prod.outlook.com (2603:10a6:5:32::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Fri, 11 Mar 2022 07:52:39 +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.5061.022; Fri, 11 Mar 2022 07:52:39 +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 4/5] media: imx-jpeg: Handle source change in a function Date: Fri, 11 Mar 2022 15:51:46 +0800 Message-Id: <538ff8ce60241c4a0729f1a518ecf0ee74291cad.1646983646.git.ming.qian@nxp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SGXP274CA0015.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::27) 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: 30850c2e-1e6e-419b-57dd-08da03341d59 X-MS-TrafficTypeDiagnostic: DB7PR04MB4443: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: 2+gU6ocIV+wTQVqOW8Ks62vZZwlmllE3GIasfR/y9d/wlb1Aim4oB54VHl66fJab/mRfKKf/gu4Aj0XZnDWflAlNBZ6JJwso2oe9XTvOkT7/Eoullt2XEO1c6gEhIm2KalfJROkss7cmoM/vEKaVKFfBeUU7a3nq456uzsmjAMGYqpCZJBzrKGUbMeX+AsDqqBs2o76teeqsorNklJObweuzJNkUTUdjx//R7qm6ml8YYrdyUPDBwS20kmGgY6dLke0MMpdymNmHtomXig4AZZderMO5tNou2u2CwiVgtFnJ2XcZOfGhvkivAC16fHUWZ5H0pH7tIcGd7kGBMWoiUk9VvRsrPgjGzixDL7G1+ZK8bXmG3j9kUxqgzKdebwlgg8B67NdgKdfabuanAlzOm06dhP3Ahl7xJlyHkLQwPhsV8mjcD93sFFQzbBFPdYd0EyT+zKNflRvR/pSQZPyfSs1OjKZH0haMi6zTXFyNq4Uf0ANMvwxC3ZJVEa8HAYdcWsGivDshDaIl7w1s60ZRH3SyTgPyTS7kgSvAnIcEt/SzVykGD1rBoR8dlXR3AovG2KrYqox+plmNWRxrz6LAMUA/cq/IaXO3idI2X+bq43iw4Xcigg0a204FAF7eEXMILjHZ6dTWLQRdClCiXAXmynbZFuluhXOUx24Rm6wWELHuCJlEJSZ3lAtjA7R6bQ187Lj9rjECtbp3qOLbYJPUWQ== 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)(7416002)(8936002)(26005)(52116002)(44832011)(2906002)(8676002)(6486002)(2616005)(508600001)(86362001)(4326008)(186003)(66946007)(6512007)(6506007)(5660300002)(66556008)(38350700002)(6666004)(38100700002)(66476007)(316002)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lSUSLUlp6c0ydu3iCkuC/4WxPiVYmJ5KJWB+Z6T5fCKZeJiR+ThR58vdFsAuB36/8t8/XBfA4ZHqXmFm96xvKGnxNzx0UJz4imTmwwd4dvVQJ6v+tgMVv+L92fqrfJ3C8I6YTlfDaBJGiGLbH4GqoCAkyvjjUrVEgKIgsew71c6cTcR8Bm9qCUZfvUREOMzHccrHclaT1ju8UPsTWpJ878tm3GRKP9Ttlx0ssl/UEeAkL5qGl3JiHNgZydCeiPB026Ppwq5f8Ob1FGTGGdCx5GfKGOhco1JVCms3Er4eB/e16n9dsoNTdUpV7P8xZFHwR0A8oNQguBG9B8WKkN91KG2mLVQPu2/85FCmBfTDZ09Cs8FqGzF+12ja/GF+nNf49bSfCF4mg4fY4I4uPTAr4Q/DdsdRNP4ZwStuJNyQFos/aVvS33RP2F3pbKQUcodFjEJ/2mAP0To7jZclnS3N7GeqXB/dCfmQOunXbLj38D9okJ5QynuOHQBddnyGELBp2TfMESjDAhvgoGjeWsJg4JgOwY5yYsPoqqiC4C3CJJr4L8udFu8bRI7PUtY01XUpS6nF9boiRrMQ8rVwKtDYMjL3K067vPSYwMbXnuPLnsXGw2YXj453rlAe2LsmSmPi+Nx7YeQxuhwhDPqUf6hcVO9tFzKUc28z/A+ltT0cLjJvs4B8JC3ZQbA3jVrOidgCmVMzFIdemk6engvNosz/YsJo2b4Y6fi56YjzBIDU1QiNGvBYKblS1IBmmaeolKGi+jgeY0TPl5Zzk8xk5vEK3Q+ajc2ZaiQSQPtJUBHwRbjYMpA3OKtlVHZFNeK8I+LkcGWVUUstadQgUFTMELrpEhemMBSesyhOcmcuIpXMp/Nnw696oGWaBxidiGSyWtWLAU635NSnt0yejNIbunsviDHErVnBGC3CR8N6snNA0BtAXNbCtqF20S/2Qu+zwsqI/ZkUmBb5TyGUW8OKQVGN98bg6BsFUZHl/hXaNVI95k0QJ2mE7s+9USi8K2RcAb2cyGTJAH6oGryQdVXisTbrxACBkzjl5Oc2zp+hTK0Ro8c6U9c/IhL0cTvfFGW60WkzK7BqGZYS1Ib+QiojEpNgmzBbDzAVZHpW6110ebct+k/q/e03ytt/X6IvHeft0nGrZB/IJbQQpr/ZIJW2zrUP6+6qLAckY1WPJpOUHQHEaALVIRmW5fR3tXAF6oT+o4klVyRyz6mEzAkZk/DgW2lGEUlQOjSJ0/ogWV+mmIsbPe7f6yjK/BTw/dER6dfIAD8eFHFpi4PUrtk4TZmK1T39n6LVVb3K7cl42UetyjhGF0hIQHHuq81tz71Vv5rHrHrl7/JcMBf5hyP8FewnACsHNK8eAc4PU3Q4o8vxd41W3+RNvE3ECqhQxhh4LO9vco9OjY4+bAo0jwPz/hMEUIdc4jTscMjZbQZCxT41hLmQNQOxUnXfq31mFhEi81f5dmP3xo2zwcU02QPBIoO0bLOPFQV8Xk66sScbfq/VI8HZ/Lwl65COVklj6gNhncMmqZ4hs7C64MSnczLSJrTVG0gdspPJ8zeLRY8mN0S/D3MMoptJy6SvtYm0+r2Niwl3nOBqXTRVPOeE0rrvbRVNWRgXhlunIP3/TiqUYpLKRZF4iNo= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30850c2e-1e6e-419b-57dd-08da03341d59 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 07:52:39.3798 (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: phK7j6usU1LQ3yOUbHD2nH32ciBcLJs8PaUD07oj/BsQFTM6TE3CFN9+lGM7GSKHX/jq3sxLiaKnEMgmNbQC1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4443 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220310_235241_747550_EBA6CA3F X-CRM114-Status: GOOD ( 19.82 ) 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/imx-jpeg/mxc-jpeg.c | 114 ++++++++++++--------- 1 file changed, 65 insertions(+), 49 deletions(-) diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/imx-jpeg/mxc-jpeg.c index 9e8a4157ce2f..dbcb83ed86e4 100644 --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/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 Fri Mar 11 07:51:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 12777583 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 CEDA0C433F5 for ; Fri, 11 Mar 2022 07:55:13 +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=vF8UBssR/DWuG0p7c1Ds1Xev3QI96BZSSLs9AQLJFDA=; b=FHiIXNwsL18xQq pvnlLlgXs3fHtgW9l1SnvuxXRL5uxIm29qdytu5UK+UEWfkYA5qM79CuFOcXPPuwGKnOz2Uc2Yh50 vuvIHboVMPY/LwC/7Wr7y7ih1uqPM8cInBBXJKhmHw8kCXLXUw+e++tSGnOnkSuB3eKpqZRc/LzTf fYE8e0w5k+52ZByxxdK6m3YQa4e3CkvDReErLtbugFicMTm/oN8nXZ8bvtIMFG1ivCtprqzSsjH2Y 62ZthOCUJYbEYyDZMGQsMqfDl/1LdQGxlTZQlCG0L4wqMUassH1y/CZiYfMG7PwPTWeK1AsyT+vWC 6XNY4nOpELOIIENP9Law==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSa5o-00FPBM-Qe; Fri, 11 Mar 2022 07:53:45 +0000 Received: from mail-vi1eur05on20607.outbound.protection.outlook.com ([2a01:111:f400:7d00::607] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSa4r-00FOj7-7i for linux-arm-kernel@lists.infradead.org; Fri, 11 Mar 2022 07:52:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pum9Dg448ENuENHezdP8vsI/On+VPDT5on1qEuP1Ot2TmkNsvUcCMjDy+46r/BtJiqTdkgG9hfd9rDFwWsBNIG9+i4UZpeBL12UeMP9tOJUXbyh8Z+0inz+VzGO2y4AYZUVCvsT7Qm21QKRmYvH63Zw+8pzTP2yXTKC1nlo2PMNCneUX6GkotmE5YrhH9zGXx3ILPvY5L1XNqIvLFTeNho4x+dTo+MdrM+wfQ7m8wyWMnZxl9D5Djvu57FsziA6Db9/z9eTRxanvxk8aJwUim1EpIhDfClqp1FootmvCkC+OBaTU5z0mQOv8OlCZfIJ9T85kWV0HlJhT+6XC1K1vQg== 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=prmxw1sdsDypUMG8otmd/XhaE7mFmMevqvhhIPGOk40=; b=fmNFkDnMPeAUsRX9MBjcfwsphm59BlwPqY8QNps1FUZ13S6yQNRjogSylVNkiPP8kdkE4MT+ym1acJmBMQM+Dbogo6/u97jgUh04ZF8mhfzhSrM/YHNKPGpUNtSDTqQhO/wGdF9eJ+/N069FKmE5ZigCC9D5ssgOZvtRlXT50HIMEEOBC/OePVSVx2I/JjveOuHo6GcHTgdQzbcZLCZd1GCZheKbdEuCL4cUsJNoN2nnCVXArQm1iT66wf8c9+/CwsCpnTf8oLD7Pz3tpLxapAlnlv1gXriRO/9ZzE1eRROXCSwd9X1A2nrcDFUyk2FIkhaFfCv13cCpGyLUBFAxTg== 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=prmxw1sdsDypUMG8otmd/XhaE7mFmMevqvhhIPGOk40=; b=THBrFemfzQyuN0l9V9H8dPZHu6LXOuc5L+iUQLKwwzWjDeWIg3hdrfUGp1wcaqjqsj8dkIebiRw0IwAb+K7yIWXhSRyZNHgOmmkJUUatnMJFWXilzEOc4OkgCibr/Y0t54JlcEbV4w2vMF1otsWNEEcmDHY7odORglNyNtVIOW0= 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 DB7PR04MB4443.eurprd04.prod.outlook.com (2603:10a6:5:32::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Fri, 11 Mar 2022 07:52:43 +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.5061.022; Fri, 11 Mar 2022 07:52:43 +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 5/5] media: imx-jpeg: Support dynamic resolution change Date: Fri, 11 Mar 2022 15:51:47 +0800 Message-Id: X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SGXP274CA0015.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::27) 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: d66dea7e-666b-4ad7-ac64-08da03341f9c X-MS-TrafficTypeDiagnostic: DB7PR04MB4443: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: 6/G0Mik3tIIbzSL/XCwmTXDm3joMQxnUoJhjTKcJSKJ+oQPZ8c5AoStx4LSQYw6DMmUZ2F3y9ZzS9E0FG9FRpZ/tGmQ2hlqKVLjhIwa/gMNPFRTFOOQGCXa47TpiRKjCK0Us8tgvN6jH3pneX7SjhJuSctHNJI7Zx5xzJ+Pd6ERkZx70fe7HLc6CRSDEGTwZfSOnsw8uExQ+ua7tE9YAZl4TlqBPUUYGBFcPnDOV3zWiFA4g2HujgVKlEfnC1MFfvFi+fbxhmCe+IEODxbqIsynHxnJdtZvyaS5//GTgQFQl5h7wk0lhTIi6+QNjofcB4x9z4BO6cyRfeK3hfWwB6h+kw2sRsRaV4cBTCJzww07osNxxXMYE2X/lsBPgJyW+4sNUAjmT9r29sF93ZZtYbhOlIvxoNGQIdeJ/h2MX8phxb+C0hPGZndMYH2nVH62Xc04z9lbTBsJ9aXg3Nfw4fPOas+8TCwyvtVnzEBfRjwnSGZaTXWNtge3z+ZQtrrpoPo2nPPfShPQ+4F3Oowqf95TckeAMWlaaSHyNUcGZaoCrJZz23+w3wm0FaNdCZldk1S4kjnPpCf4tsjvhrQ10sPmlW1kSArLjEyMxf63sndTcpHdcpMbOyURcoUBZ/g9xB4ZfppYAGMxXWMhbEsK+Lzn8CcIyNUQR5V3S8Rfpjjm3juFy8MG0DkQeRDzyDO9DCxxRkQjoZyPsD/E4IU1Hqw== 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)(7416002)(8936002)(26005)(52116002)(44832011)(2906002)(8676002)(6486002)(2616005)(508600001)(86362001)(4326008)(186003)(66946007)(6512007)(6506007)(5660300002)(66556008)(38350700002)(38100700002)(66476007)(316002)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Z+5MVFyPthGV5O21pA6BuuEDixpiytqpdTaJNtkh1iUBsJ0gQaffRQXzG6BiCmKjfGs20fvYbMSXeKYun3nXA5vma/u7oYDdMfYKnlWBVGqkGGDnol7lx/J4waMotatg7P2sLqoUiVxztOYnrP0Qmdi7s9vg9wXK16zEyag/IqmwWb/amUrnA0+OHnmMUNrUHsxRWaBF4JplZzIghWGZ5DN2zxtPX0OpRXxvfeP0CDNknPeSc0LRjCdIR/QD+edgcaOif2L1NQqZBPq9ND9yjpJdsUnXj5QECuX8q95E9faMBKk+3pMXpziuav03fLYcTZX4jG8xYDeYp8nIgDGC89TLddSl9m1zusqallEoNZIUnNh2zeubHx8QqKL9YW1SExTe3GFuk1v2TEzA41okak/7YraEBv3YdxCGeepovDBnf05YZRlffWCW8oklJS3KmMxkeaecJXssXSrSCBSH1YPQ9MJFJuN9RdBhoBmGMwNHosKHTSlzJze1xDDnhycQ7h8n+wg2j2KExXrbv5mBBP0hmO0gasOjuYWqxrh71SOlQnrLcZuRQh27tCvQji9TYvn0PWXoMhxCnT52W21keZktj/3mbax/t64zqTQeMupsGVXo0MgxwbivYhUuFFBAn6R48zi27ybFDcuGUy3fGZjM2UmJVO58rT0T2lyRu0f8dkIfC9B0nkGGA8HRRuK/Q0ZPdcsm4Q/c0w2hJXwtJQIwVp6iwppYO5tKlMg3ztumUkFKrjlcpB8snanjE3T96XLlwrZ9DgJ7DgrBVYiFZOYfw0gx+lvOcyzkGr6A++Smawv1HaiezboTzyzxo0fyhxpXcnbNDL+gK4JidCKeFIPWa8+EQT2YLIhRDEo8Y6DnkYmSur4wkBHpT4sSGIGGCRSzhFYG5F23kYjJyUwzp+IyAod52DnlwZqBQXTkt+r4o8Zs6BAysmeqsrZ2aN7icoPxKORxd6t9MAi/+ig0lZtvt688EX7JBAV1RDONtdEVFYOvoQx7osayx1qbL4HlclW6QhAVJjV9A3arc8BE7pb5Q3jS6sUNKm6gNafEHPOhg610u0N7iKsUh+8PXGH2oDYhy3aiYWyvsTyPIzsst7nkXTP6eA6OAd9FlPnofP55jdjqTXk6TKMMQNO9vdx08twED/nN31fYfIEEeWFhLX+k33sLRm3W6lCGXsgEwibS81cVhvx97RwdWLSvUrETK/dsQbhHmLnJIZVfZYDonOlA3+cCTBn+mdyKNLSfiuWAtHcxjetpXjWHZSAisFsd2E92BTXEiKK0SIXS4R+Jyz50+l2jhlaqhdvLv4FfMf0eWGdcUnxCFDTYYiDS4T5pW8PXLlvElANo3rNVv3jN2WqpOnioeJx5U15DiqDphXU8skrscy4qOlPF6NHgGFYcjx/s/LaAXbOsI7Wmxi53+R0KBaXqQuOZK/yjzTBaDeNpRpq3lm74jw5+vyFKgLacZwW17JR8z2hC+bkG7DTg5aq+w138qeT9/nXsxMQgFY0bJsN1P4ranA3lO7+GggCCkyFMNUqlKC4pzc2VvqkDJxr5M/jvZ0AJsHXiwoDfId0eJHl6z9bgUP2uI5czYrqUOx3JDL/z6z6wqtKWwKP2BnB7oicCSMb6ZGWcEJ4ZJPo= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d66dea7e-666b-4ad7-ac64-08da03341f9c X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 07:52:43.2078 (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: CxCk8la2bW0WNKuSxYuk9A+ojBpQero5ywROv2oXuQwms/gq90ZiXuQeJ1Tiw8I5nCrb3YmtJcw1wTW1nkHIJg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4443 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220310_235245_316680_DB7C0F0F X-CRM114-Status: GOOD ( 19.37 ) 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 --- drivers/media/platform/imx-jpeg/mxc-jpeg.c | 69 +++++++++++++++++----- drivers/media/platform/imx-jpeg/mxc-jpeg.h | 2 + 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/imx-jpeg/mxc-jpeg.c index dbcb83ed86e4..3a78673d6c6f 100644 --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/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, @@ -2013,6 +2049,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/imx-jpeg/mxc-jpeg.h b/drivers/media/platform/imx-jpeg/mxc-jpeg.h index 82b38cc2dfab..9ae56e6e0fbe 100644 --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.h +++ b/drivers/media/platform/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 {