From patchwork Fri Mar 18 08:16:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 553276 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C936EC433F5 for ; Fri, 18 Mar 2022 08:17:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233663AbiCRITD (ORCPT ); Fri, 18 Mar 2022 04:19:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233653AbiCRITA (ORCPT ); Fri, 18 Mar 2022 04:19:00 -0400 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150045.outbound.protection.outlook.com [40.107.15.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E22B2DD9BD; Fri, 18 Mar 2022 01:17:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E59V/KY1vmRgbHQf1XT1nmY7pRdEZRtqN9jCPmdtzMdQXSB52HY7gsBteTkS18VV0BRqQ/IgktmPLWHde7fHgfw4XUTt/r151mbDcCmgb/j7A23AeS1c1VgZcX0hJoGSYxAEm5z+0B1glMq3XySG2uCjcfBZsCqwMAOXHoHzz1QSvqbIYnkAgDQssp71Dln8aDnlkaZ/aeO7HpynsAQP4FWr7ICypNqiqjUD1MbAuDJf/NyS4WQNElg0PYvAzCBjNriJia3YUBzzX6Ppg8B8GkZVfNJUZCCEKpKlth4Hc9CK7TISXqa/KZORFiKiaSgitRMlwV51xcspViShhTI2/A== 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=Yv5BOcWXKH7gjwhP0yB0HQRxWF1YZ3jSSkeiSCfN0ahvxIcC24GyjoTgRgI5KWLiY0FRBlMdyaNrN27bRmfdRBk+vLXYg85BxvPh1iYWVrl3+jXWqx++faBI/OA26S9HP08TIGCnUF9Ow43DhcnEmJgrHt8j5eizqrI836uPeNwQdNNvKgiTrj8KIStnDUlwckA3HIxAe+MquWw9kFFPWvDo8BAFtphWf6KhA5LJoOM8nxWSSV+EwmTsMiXqIzkFNNnkwR1hhPHMOWhpAPL/OOMa0duWmvZdXUvBS6U25stcwM2y+0O+P+bLu7w/rKY9foKsTbOTnFEH9FgSZz7+Nw== 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=aGl2FXfnL8esoq7L+6ag6cVP1w37fUGV2IIiVYNRwBQuLCU7P8eODjtO2kWbvML5MkbgPbCMpH6KHgAeuoDdOEmZm9bhUaWmgUlztk2sOSC/mZQtlmry9ONCbxS+78zV+ds+e0UScaavRtC8XR8Wr6Q1Yh1nvTesW80w8ikN6mo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB8PR04MB6346.eurprd04.prod.outlook.com (2603:10a6:10:10c::14) by VI1PR04MB6285.eurprd04.prod.outlook.com (2603:10a6:803:fc::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.18; Fri, 18 Mar 2022 08:17:40 +0000 Received: from DB8PR04MB6346.eurprd04.prod.outlook.com ([fe80::a8a5:945f:4d08:69c2]) by DB8PR04MB6346.eurprd04.prod.outlook.com ([fe80::a8a5:945f:4d08:69c2%4]) with mapi id 15.20.5081.018; Fri, 18 Mar 2022 08:17: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 v2 1/5] media: imx-jpeg: Refactor function mxc_jpeg_parse Date: Fri, 18 Mar 2022 16:16:51 +0800 Message-Id: <9f67125ccbab5d36f985c783990ac2767df50f36.1647590462.git.ming.qian@nxp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SI2PR06CA0015.apcprd06.prod.outlook.com (2603:1096:4:186::7) To DB8PR04MB6346.eurprd04.prod.outlook.com (2603:10a6:10:10c::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d43917a2-1cdb-4283-e6cd-08da08b7c46c X-MS-TrafficTypeDiagnostic: VI1PR04MB6285: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: 8sG6MlP5zitEKqADsdSEvbzDkfWPfjVTiP6A6180IfR+IRYF2sRm2kNkxKkypPLJy0x7+q+TNLyMXyXoHE8uClxYH65OtoZgh/x9NWe8+qSn12I2X2KpnUKsSZfpobnehBWfbKaMRiDQDLnJGSejTyazYAhknMVV4U00oqCmKW3WhaQCDOQ225p4o263QAJqdwlgp2x3rNsMDgi8ugsPnZwqMaX5hFqE26xbLT2aX9eazuDsycPpA0U4WlqV6M4MiiXfSWZld+PwtfcC1VM9L66Og0hlJRtr6mhISI11cbJnEh9NbCEKZSqX/xhJtPxJGzJpn7DbGLfi0Eb9kPkKhwTBmjBVk8Fc1g2iIHGQU4rNtOnzEVU187Jj0JuwWCB37ndcieI6z1/EmFak3RLs443PqLudEenUXkZzGxEMxYIVJDfD+IHJo4KDcmcbv2spyg5Ji8CF0eMyOTA8UXQe9M63JPwkFCVfh6vP7WhSRyzLNx/AMHEuCllzmxphEJVZ0ifCB0Y4ihxQAtqACR/FY2DiCZ3K2wVp6myQGQwN9H4ccu/5XyRsaIW9+/7NwbzdqIQqt+TjqgJGFvzVwFFbpOwCVann4sBwTxy/XQptZh9CTBVY7C03IzANtGfShpGPxiLqxr0BvaqCNcnnAOj0U5xgaHstGtjj1QrrVytntStvZIq783SJ6VU4+EIbfvoM11mp2XciB0yymi4Yjycidw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB8PR04MB6346.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(186003)(38350700002)(26005)(38100700002)(5660300002)(6506007)(4326008)(8676002)(66946007)(66556008)(66476007)(52116002)(86362001)(7416002)(8936002)(44832011)(6512007)(6666004)(2616005)(316002)(508600001)(83380400001)(6486002)(36756003)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mb3Rpk2D2Psh/jHFqgtyaHkmKwkk5uyeA8OvwdDHG2hV9xje1adb3TqKCI9hIF9F4y9X/a2/0geICWr54ZESIs5E61AzPLuYO2MdQdKdKxa4R3SjrWI+L2awZMKiknKgrLRHjkecEHP4Wp5g0CwQXdhDk8FCsJF9bbrGqLaPiIwiW/Rix4SFltibm0IFTO+LgWpe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b/9u4IG6vtjB5u1SNpq5rbCESXXCK+tOADAuvOWi5auVtHGYgAsr34E0fdN4huJyvZBSQe1AjGaCy6qIzjcMYBbbsRHQucW7Ernceb8Bbq1ymPtXRzQ9eh3Dz2i0sCNPeJG3FoAYahlTAb2Xtweu4zTwGz/TUfTeluNqrxayV2qrt9w2h3BQPlroLpoWAnEppzh X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d43917a2-1cdb-4283-e6cd-08da08b7c46c X-MS-Exchange-CrossTenant-AuthSource: DB8PR04MB6346.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2022 08:17:39.5730 (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: s3e59wMcGzfsXCg9B5KsaK9JXNMycwdPvFlEm8NxK9TVclQsesmMQxwHIW94obnliebC4nkRpp5qqqGfw2bilg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6285 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.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 Fri Mar 18 08:16:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 552932 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27162C433F5 for ; Fri, 18 Mar 2022 08:17:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233679AbiCRITG (ORCPT ); Fri, 18 Mar 2022 04:19:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233668AbiCRITE (ORCPT ); Fri, 18 Mar 2022 04:19:04 -0400 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150050.outbound.protection.outlook.com [40.107.15.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CEC82DF145; Fri, 18 Mar 2022 01:17:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c6Z3IT9Oq2DyxyoMydY6cDctUbSe3zcMaNRAy3NfFLQSVH+4j533279SAJPISTdolfT/RlKc0kzsE/oY9H/fIgphnPjsGuGa46liN+wU7whC3vG45wOWlSJ/3xFK/Q3LrqOhN0n1KYuGnwvmb3d1kO/+IFmyVVqzQpO7eWmwExK+crxIobtWMW65MQshLav/lsmPlbMcjD3EA2wbOlazCsnggcvCPIEPS5bTdcZ2Crl85ZaXuC1Qx+od+V2KeKE4peXyHnSkdiDsVNaXkUK2x9LBXo3TuxIKgVNkAxPAYXUR9Yc+azCZ0qT1yuL+FGjo0VxV72MIGk3S0hxU0PAHWg== 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=RyxhrD4851aAwndZcE6vMysPf93MerQ5xlH4ViUVp2Hq+zwsfZShFE4Ur1KqEycQOK9UCGuUMMIphyi9mEfUIDE6pQUgsH6PsleLd8W6FPCMJ5HIX1k2s2LAiqpjSNRiaSWDtBediidBIV64aqh8fVbHmn8je5ppH8Zv2DdHpQMgJoGdQP0OYgTWFJ2Je1qdAq1UEe1tIM2A/vvQ80w/hbjpC5YdysfnKs/CBu1NHKn8v/UyEQLRmjbZyxa/WxGUW3a8oRIk9fUuoSIMJwHkIn9fXk+huUMOgOuTkIVOlOb7mqbWzIdNBp5quaIWG+DfM6KAHbB2v9NDqv0WXDmQrw== 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=pkM/Zwn/JBFnjQFxQj9Rt7f9499EzS/aiP0Ol5I6OwHF7i3L+ikupm9RjdZQb5iHzrhNEyGGIgEESxU/SBFEnLSkaSGWUOYCtE2+6iP/Uox0OQWbEY2cedBVe9E20DTX5uLb17iWGAzFKqhKFovHX2VyOR2KJ64X6psWUndKJbE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB8PR04MB6346.eurprd04.prod.outlook.com (2603:10a6:10:10c::14) by VI1PR04MB6285.eurprd04.prod.outlook.com (2603:10a6:803:fc::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.18; Fri, 18 Mar 2022 08:17:43 +0000 Received: from DB8PR04MB6346.eurprd04.prod.outlook.com ([fe80::a8a5:945f:4d08:69c2]) by DB8PR04MB6346.eurprd04.prod.outlook.com ([fe80::a8a5:945f:4d08:69c2%4]) with mapi id 15.20.5081.018; Fri, 18 Mar 2022 08:17: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 v2 2/5] media: imx-jpeg: Identify and handle precision correctly Date: Fri, 18 Mar 2022 16:16:52 +0800 Message-Id: <629549f287c71d78b726fecdd2a3eea35982ffe9.1647590462.git.ming.qian@nxp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SI2PR06CA0015.apcprd06.prod.outlook.com (2603:1096:4:186::7) To DB8PR04MB6346.eurprd04.prod.outlook.com (2603:10a6:10:10c::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c83ea986-2e1e-4d69-c1ef-08da08b7c6b9 X-MS-TrafficTypeDiagnostic: VI1PR04MB6285: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: c1QeeHa5/ZO09y7/27CZrVZMiPSDjWxZuOC0GghCHqquhbpUTr80Cm+hMGZd54nH2d/Il0rzY/K5hdpHpyL7kxEKhPDX9v7BeA5T9pxK7abipPXBRxYx5fCF4wngIUHe//Cmgcjx2heGpmOLRIukk5SbwNr+Or35zyWaELQvXVQdlMuUy3ASy6XBWV0jaDcpTPr1CSIDhXn2l5ZfUiTyBbpZDczaGtbwmaE6cxTSEhCQ0BdXJ2n5GZXMHJy+4gh5fYcBExN/4f6+7PHgzVBOl2hBd2uRKVT8ufhqSqzWyTHinyDPwVXfXln8vcByIf3mjPkYG4c4024atdwzRV0psG9cT6cL6Gd6m3gM4mBWVihg9/RdefmqjsVmBpPJJC5gpH6GYFSOXjWzwt/ezm1ijTXGPy2iJz8joU/CVJ4JA5xnEjoEIyKyt8XOftS1Eho/2IVFyfYFQ+uXsIg6zLpAz0ZFMDVoZHyUCnmwQQEHsi7CQ1g7sjf7EHRRqxSliJpqYlpLZT5pBMFg9suV6n/qx59PjXm3xbwdd1I51tYvleaZs4y/cx0y/iw6DOwik9wa8UD3xWe8fRGdR9YwfeNi4XnbML04fOZfHR9N0BXpisKuzS13kgraTFiJN1k0KRO4vVOFAN0hydXaX73wgCw3OW9mG+fA9NF9BZ3DQ7LoeGWaM5PrDvIlnPdmAAFOV08lQtXlxt0b+bS2xd377uw+fw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB8PR04MB6346.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(186003)(38350700002)(26005)(38100700002)(5660300002)(6506007)(4326008)(8676002)(66946007)(66556008)(66476007)(52116002)(86362001)(7416002)(8936002)(44832011)(6512007)(6666004)(2616005)(316002)(508600001)(83380400001)(6486002)(36756003)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Pd7qpUxkGAPq4ZWwBML/q7WqudbSngbe0hLJ/FxhJN70U02ShdwNTnx8dCz26qx9vQbJn9CXDghaLyeFDlA7apCYpEUlQUtKpYutpmDVLD47TevuO7azPaDAsJyKJWKO6zo8dafvbiJeKrPBrt4CIQSlmTSurkXPFX+ezqJRO6JB+nW7vY3CxIq9FPNPvJ2+Aqy0GuvvczE0JNZtK5AJh4CT+By7ZCHPaaLtt2okGS+2Q96OAx/M51ouVQIdEQuFxg/9NVqMt0cKzfRB0qFESuS0CpiHWMk7ZtqccYiuoHCNPS7sWhHheJFPJGZZpQVDqZT6et+/RGkEkNautfrOhfHXPHO+8sMSgqYTrytiwAz/yPc2wwF/n5DIO6BXkiE4XH6Swwp4xa8+t/nw4JchARAlLpmV4CqMwgk0EtNlUJE7VYfCP33RE6sPR7n4pXc2jV/SO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-c1ef-08da08b7c6b9 X-MS-Exchange-CrossTenant-AuthSource: DB8PR04MB6346.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2022 08:17:43.5102 (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: z4LEjAoddbBQczTHmosgM7Q6USo26vDJSsF2UYw6xPO6Mk95FpcxKmv6t2IEK8Dg1MDup48+gDplR/epboQFug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6285 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.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 Fri Mar 18 08:16:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 553275 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19BCCC433FE for ; Fri, 18 Mar 2022 08:17:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233689AbiCRITN (ORCPT ); Fri, 18 Mar 2022 04:19:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233660AbiCRITK (ORCPT ); Fri, 18 Mar 2022 04:19:10 -0400 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150072.outbound.protection.outlook.com [40.107.15.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 638302E1A83; Fri, 18 Mar 2022 01:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OWmVyvIVMVIgX6zFe2NuWnXGlit34UvFHFyXHbM5MFPws6dP4+MEmHcnFRndijo/irwKYnc03XZtRH8awxrznDxq7a7bRMQZhpp8LiW6GETG5ZwLnWPSfCf99htBjlSP/+drA2C+OO2Iww9gLd8SKuKxYIjUWCCjqaOaHPtxYwcTEPNHernfX2ZqM5uqCJHAoq3hJ5aW09QuRCiV+MxabriG5BCvAWXQa3RxPy3piOM1rrQZPNlFHWRyr8PlVqZuYUEWGW4ml/p8JPp2yrp6Bq8YfllrLzUe0LYTKzqecMkmnDp1PScrfgNyjGzlMPZ/NckxnZDWlgNur8sw6nEP8g== 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=ICyghvJRyomCtrEkMPimsa5pCA8XKB6BWA6hy0c0UlU=; b=UIeMRrQclPfDzYeOsiuxj9VJMoEkQK3NfOW5RkmK8VlWW54uRrYegJoSFi9QdYMLZKR2U6mbhD9l7FS+A0EcWwXzW17tZC7ihQvLBNE/p8lQQzDbzHraAK+UVN1DdAM7x2UQ/JygI8pVOqc33mF40bef/5Fqp11GE/NC/Sw4fTkRuXwshsuuIUvlt0lufDiDLXRk5UEx8QoEaehvfX9dSTF/AEXenOG73IeZuSmaCt1ybpNelMVDJQMpikZKHRK7KIEFnvnByhg2XExRBjYMAfjnOvTSJ6tsPsiVJ/tCAisizgaUNUa9tSJvg13xQFLM6yJBHUJXF5DsC/ffJ4LNAA== 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=ICyghvJRyomCtrEkMPimsa5pCA8XKB6BWA6hy0c0UlU=; b=MBpsr3qfWxCTS9LTvnDjLZJtBYlJlbzsu4eoWjpktSKMIAGvs4LDodGjcTps/jwvr4dwDLNCCwPOZyEFixLKPUIeHFKUwZ3h6Hh9wheEoS/1dZnHSNVPOQivENM94VBVEGK+jYn31InP+g7EQqc5hkzqLo3Je0BBuBVhhz2WAs0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB8PR04MB6346.eurprd04.prod.outlook.com (2603:10a6:10:10c::14) by VI1PR04MB6285.eurprd04.prod.outlook.com (2603:10a6:803:fc::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.18; Fri, 18 Mar 2022 08:17:47 +0000 Received: from DB8PR04MB6346.eurprd04.prod.outlook.com ([fe80::a8a5:945f:4d08:69c2]) by DB8PR04MB6346.eurprd04.prod.outlook.com ([fe80::a8a5:945f:4d08:69c2%4]) with mapi id 15.20.5081.018; Fri, 18 Mar 2022 08:17:47 +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 v2 3/5] media: imx-jpeg: Propagate the output frame size to the capture side Date: Fri, 18 Mar 2022 16:16:53 +0800 Message-Id: <18af657bba31a7aa49a23e9952884beba7cd4f04.1647590462.git.ming.qian@nxp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SI2PR06CA0015.apcprd06.prod.outlook.com (2603:1096:4:186::7) To DB8PR04MB6346.eurprd04.prod.outlook.com (2603:10a6:10:10c::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e5fed04f-46d2-4259-eb1a-08da08b7c914 X-MS-TrafficTypeDiagnostic: VI1PR04MB6285: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: 543763QqF2FgvIqpXGK7cLDgB6LnINEWHnMNvut88QRSfGJbSPMmeyvAsiapAD19tQSJjB+4l/V63O3yzOyzUYoTVDQNwMAXuUjLycThXS06rH3o2ZRopkeJBprykCvFehFkfPu7+DU+6VP+0k1iUcSNrw1MeHBU/2lwrkU5LESxN50LTWNKmQt3DSeXXHgR8vwxHa8DhFpbxWl3RsW5m5lLIekYDH9tkvfQ1xjOQKDtXje3qHyj2tTFvEE6qGqQBTEHRA2akyJT/4TjSiejvMuI5ehIdEAIScm+PE08zcw5JU8lksfdgUk1ykeFP5Q4NrZ3WRdqXZOO945q7+2nt7YIvk6AfEETy28k92RGmmTGhj9s+Ew7dZdst8Gqf5/3xta5VLUJjhKVoPUFKDA2CQ98uF3EjgAQQR9bw5v0lJxt9xoKiyaFC5X4Ud2fzr/KeQ6huAeGW/hVvD2exFDzpJIEObKTD7nLY98AYFgM0HNMEs/5IpR1KiaQuDnNHL9sYIigs8UP+Wuhjx3MM8Pd/Au67hXeSibCL7/upluL4FNvwbBEX2L+PQvj9neUA102hlQe7YKGYdv9LW/H87GhSPUQfw+62CDvqa93IfR4E6zKOq+wD7MwPOgVBkcdIZOuT8C53VJDY7CokgNO0AbkGqy+BxB5kqolqR4skS/ee1/BZy3Mq+bFfxojs7Wo06p/6nFKx2V1kX00dGk7PbXp7g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB8PR04MB6346.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(186003)(38350700002)(26005)(38100700002)(5660300002)(6506007)(4326008)(8676002)(66946007)(66556008)(66476007)(52116002)(86362001)(7416002)(8936002)(44832011)(6512007)(6666004)(2616005)(316002)(508600001)(83380400001)(6486002)(36756003)(2906002); DIR:OUT; SFP:1101; X-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Vgi/tlJ2v5Kz1nYqC0KX8OWdO3uUqhzCKCjYxniJ8lvWSAkomAhldrkNh11YNpHCEihfp/XCroaLabD3ydL+NQQKipzVIxaXGaChEXz71AC6Rh9ebBVc2b4UeWWiMg4zSgxDYZcbXVtURT/Z/Ka5vlAxInELomsyEd7NbF3O3vO0BDPTHJyDSPXwIFBjN6QVS+dfwC4VJr9F6sC9KewjyNiU5VRl2Mo8dd+Jkdu7a85LHGmW9JavcWFNwt4y1VpbOHfgEPvopsCCv+hJ8dUr4cP6lObWvZ1SKoPbd97pd7AIgPsaE4gbM6V3MHDai9zGKlxu+sMJcC7Fhp4mTx7TccVvlxJGHJinNl84v9sd5gXBRatBkz5yDZ1FLrI8QLc5vNEGnJGEN1cBUQWa6kDpIsBTaVoluTgvp9GwDX5aqiMZG5T16/G1P X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e5fed04f-46d2-4259-eb1a-08da08b7c914 X-MS-Exchange-CrossTenant-AuthSource: DB8PR04MB6346.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2022 08:17:47.3850 (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: cbvkUMDKUt6kRVZuIUl3dR63LOep27OBZbHsCgP6iNG3uOD7vTnpI0pVP1p9us2Z6Hn8IcH8iHpBw71gmNHRCg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6285 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.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 | 25 ++++++++++++++++++- 1 file changed, 24 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..d2110731346b 100644 --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/nxp/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 18 08:16: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: 552931 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74C39C433EF for ; Fri, 18 Mar 2022 08:18:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233678AbiCRITW (ORCPT ); Fri, 18 Mar 2022 04:19:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233660AbiCRITT (ORCPT ); Fri, 18 Mar 2022 04:19:19 -0400 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150082.outbound.protection.outlook.com [40.107.15.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05257F14; Fri, 18 Mar 2022 01:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MhxZeNeirube0ZhhWs1AygKpzKFgHPkO81wFMgcNPEyHKa8yaZXu7l6zzvHM/HPINs8i/d6qo8E02HxIq+k3W5dAHswqS7ZuCSr8HeG7i5cUzms4SxasW5TVefxlaMuNUhn7/tpIybNtHZR2Yf+Wt5RyKb3rjUvD/xtSO7gQCNqwCDp5yhrhhhjbmU0/d81g4GSq03mFhPw+hYdyUGjSjZJT0nm8dCJHGJhgQ5/JQ+v+d+0DWH5uQDgHus9BJHzMJJhWgvj7a9r0G9I8RYWr3PAxhxc6FGl1jjrx7nPc33qC9eHBtjDf5lCTaSAwKRGT1BRD1gqSXpwPpBezqCDfRg== 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=uoeWsAPNw7r5DQeUqLdbjG80sclODBcn2yzd9EAAUzk=; b=bHSkZyj9JIH02L8VfmOAhbvEGuLshP05lOt2GdfjjFjegpnbZ/ubrqCsvJP7zxZtCp+Su8/Hw5+7To9dOZqDGMvhPSyPTSJMdeRO4m+oHqsErdnF04mFMxy4a8voGZLQbyEKu2xKAhcRBRBgAtx54ioqcc56kwYPo2hiBkjJCTMG2KT3Qp/jz7O4V3c9U6o4TN35tDEXoM2V9rQa3Q54BXddy717SvlTyQVODu4OrPvhnHhN0XYtZgforjtVcyLq5ML2CynTS/WMIYWXByn06afUgkc1BD55mx/AaeAqKd+owZMx9rbWgtt0qZ90hsgzHhha3Di0HzRzOi+9PfCo0g== 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=uoeWsAPNw7r5DQeUqLdbjG80sclODBcn2yzd9EAAUzk=; b=XhN1CN+qqXVZMwjq7w+mWysGmglQ9lcqFyo/V/bDCWJMwpfLa/L34rfgnJTbWaHceovhGrvCJqQfhaLv+LzWN35psPPDxCFgo66s2sKavXIxC0NFofqShlyxSu4rt7Re7eG7bdXhJJu+4tCYUno0DL2rApOAYDQJiihxOzkpNN8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB8PR04MB6346.eurprd04.prod.outlook.com (2603:10a6:10:10c::14) by VI1PR04MB6285.eurprd04.prod.outlook.com (2603:10a6:803:fc::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.18; Fri, 18 Mar 2022 08:17:51 +0000 Received: from DB8PR04MB6346.eurprd04.prod.outlook.com ([fe80::a8a5:945f:4d08:69c2]) by DB8PR04MB6346.eurprd04.prod.outlook.com ([fe80::a8a5:945f:4d08:69c2%4]) with mapi id 15.20.5081.018; Fri, 18 Mar 2022 08:17:51 +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 v2 4/5] media: imx-jpeg: Handle source change in a function Date: Fri, 18 Mar 2022 16:16:54 +0800 Message-Id: X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SI2PR06CA0015.apcprd06.prod.outlook.com (2603:1096:4:186::7) To DB8PR04MB6346.eurprd04.prod.outlook.com (2603:10a6:10:10c::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4cf7e90a-ebe9-4b69-ed42-08da08b7cb68 X-MS-TrafficTypeDiagnostic: VI1PR04MB6285: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: RjPGOfYNnR8NGhSt+0tQBbxeJ6lLqNygDzNhCDZRhnEDGj9GsYs9W8Aq8/V/HGkVS8Vs8e6wOxqx0PVM8QUVnmzKS4l2HTMF/TX2pw0uij/b48KlD2seoPMPHcpsRuxCfsowLlo1lZZ1lWpZ6Vuv7thXzQuc0z0HpdfXnhSUc2O+KqX9Yu+ve1jrxIwlFU1nY9wIc6Hevjq9UtRACKMD3S74QstqIBu5F9e0UrFs72cwong85cexyKGtXX6fH4rIe8RXUZX9XrjP8OXD/SX78sFMHEvjHuxJdMUqAMvF+e8rAQMNYi2pxzVDj2vIoy4cu26g1gPgmgVs2c3cEWI2kJS92ksSNTFe0PCwNUjI1tGUqNEPijIXPfF77OG52rNjPvrrX8UQK+eCx+2TrZAKP9UnAR1aWREiWBsE/EI0YmxSwXESmNIJGE/z5Id5cF1aYGrNmhJujpl+IQr0/kKmRRrdXSb4+FARkc8ypXa9nRRNAwrBnrUnkhER+GcZvidn3Kw16SP6VwNG+Lq4bcDJmx3UADmtxK7dvGTJ5X7f8ZtBKj9r88Ylk1eANVb0QRS2SE6Qh6TGsGfBLelUK50FHAT90KSWGhdQaqSge3YqnqmC3es9t/FBX/c+GTISfBRnGeje7dE14pZcqoD6x/2naGpte1lwOfJDW0CIIpDD//lgSHAOw2gcNhbGybR5F83cPEuaJBpzTulRjm69E/cxDA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB8PR04MB6346.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(186003)(38350700002)(26005)(38100700002)(5660300002)(6506007)(4326008)(8676002)(66946007)(66556008)(66476007)(52116002)(86362001)(7416002)(8936002)(44832011)(6512007)(2616005)(316002)(508600001)(83380400001)(6486002)(36756003)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1bqGK1riv2mQNIZ6NsxCMLgzfYbr6wPoEbLLKOaaNAZvii+02YIdfM0BnPGsNP8bVULHFEiIbYt4u3GlOEfrysHDoCAB/DJVIep5gtzc6c0Apfbv8+hv0+qxUDs6u/bYrALIyIpMnswuTD0wPk+lTdR0H3uXLhEASICZ0nyuyoLmi87aI7E3dI+6y3CPKLzjcYU4niNydPiIoDcLEU4Na/EqTNEAdxQ/tw3ABSy7SwTcxG9F8eHX5Ql0Ycf6t+HuU2zuucnGprVoKPbcjfLBbW7uIFNVhbWrgOEKYOF4FpO18R//8LUnKyw7j9uq+jZ0aiq1sQ2K1zLCS/s+1c+lHQq5vkOIMPRMWLeGGyXl0m+UZqpatNYmb9iFkSgEPAhG7YUqQHoKuQ6sa9fHFzV6mRZpvG3sH0FPEQqHXkVCXNA6/2LcXZ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MS-Exchange-CrossTenant-Network-Message-Id: 4cf7e90a-ebe9-4b69-ed42-08da08b7cb68 X-MS-Exchange-CrossTenant-AuthSource: DB8PR04MB6346.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2022 08:17:51.2910 (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: 14pJsOA9CadxPsayy2tph8jINNAnZ25CZZnDaVMVA2PlC4nLa5qgKqBGYqVxRtfK8KpZuJMgvv2Tv2mp+52Pjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6285 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.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 d2110731346b..5bce74de7cf2 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 Fri Mar 18 08:16: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: 553274 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 410ABC433FE for ; Fri, 18 Mar 2022 08:18:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233705AbiCRITY (ORCPT ); Fri, 18 Mar 2022 04:19:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233710AbiCRITU (ORCPT ); Fri, 18 Mar 2022 04:19:20 -0400 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150082.outbound.protection.outlook.com [40.107.15.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72E07222A1; Fri, 18 Mar 2022 01:17:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VafPXqKeynrwhy1vs/2neTLMsb0oq/OmkjwNWn0SdUzGLDWZPbqlPKq3YtQl8LI7guq/d22qh0jzOV2LSAkPxfKUhTTW3nzYN5Tx4+lw74JmYIfhBnmz0bJxE05PWlb8aIzvJY2NvuOP61d9JMSicakZRhc7NpUprWnfBEOUQVJGPahRuZo5eo1UaEUOIfMTWohzUrBaJTfX6E+kn5aE7pPsItCzzz20dNTrCnubgmKGzuuQsGubjf4EnuB/tUnEiZAnOqkdfH7b30oCU+pZu/9dnzET6eufsWhvDXLq2oMrr+L+BfetBVyRaej94WC7yUzZcAoa/ru2ufScS/XRow== 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=qSP+wNzua7vbfftMiEf1QRK1mgGgsnw1qa5RCzCG5rA=; b=LytNgXmk+vN6bwWYvwjArrlqRlUDSA4Iqf4jj+w9ytZVavj9z3pBKHESCrR942YAzsPcupbNUWe5fpsSGL2PeYnQJqETfYfyiqSNPDAivgEmJb9nLSS/7ZlNCFwoWSHK2fQxA/0wWqLYtdlSHsw6kV2RCMNpiMFWuAK8f5EjmbSHIIQJKdaNEgwDTg+csw4LLdbradOuSiP7/Qu63U6IT2aninuBN8pH+SEx+PXdQPK8hCevnhG2NXnveAEWjwuIxZ2orY/CWLHu+1jqQUYIUl0EA8ZF0DZDH5il0W7pxbVNxyU/ifkeLYdcfqbbtVQlezERMYsyPJ8MYZPvatfV+g== 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=qSP+wNzua7vbfftMiEf1QRK1mgGgsnw1qa5RCzCG5rA=; b=sl0DvOoao/jITRqxfGVqLGr2oOaPRjBYSf505Icgwo0ccFTtVD+P+4wQYVvH7xLOtcKGYZqWJ7Qw1CgwJaqBi8dSKV2rucDrrEkFvkF2LKGN8od1fGM+etPQO9pTr25Q/8FEPYwOa9TboJZhSKVOCuhdi2tNSFbBomCs9wq7rBQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB8PR04MB6346.eurprd04.prod.outlook.com (2603:10a6:10:10c::14) by VI1PR04MB6285.eurprd04.prod.outlook.com (2603:10a6:803:fc::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.18; Fri, 18 Mar 2022 08:17:55 +0000 Received: from DB8PR04MB6346.eurprd04.prod.outlook.com ([fe80::a8a5:945f:4d08:69c2]) by DB8PR04MB6346.eurprd04.prod.outlook.com ([fe80::a8a5:945f:4d08:69c2%4]) with mapi id 15.20.5081.018; Fri, 18 Mar 2022 08:17:55 +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 v2 5/5] media: imx-jpeg: Support dynamic resolution change Date: Fri, 18 Mar 2022 16:16:55 +0800 Message-Id: X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SI2PR06CA0015.apcprd06.prod.outlook.com (2603:1096:4:186::7) To DB8PR04MB6346.eurprd04.prod.outlook.com (2603:10a6:10:10c::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2f886b7a-7006-4713-ef7b-08da08b7cdbc X-MS-TrafficTypeDiagnostic: VI1PR04MB6285: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: nqme/2NP/xc1Yer/DIFZXPse4aWAG07fqXZ3AUKHk0lvkaTEoRQUAH76sT+5I7QOUykHD5mijFyJMvHcXhFO6VlFZpNXq4qX5BZsFbC0Q3qo9JNc7ekeVM3Ay9VCfFciZKybgVNY/LeG59vgYbKNfLEo8cW7c98EBpuVBg6Qcf4M6YaIBk2XbJJbTBS4M9xCzZtD5BW1YlOGh348i+0auS0ay/I7gseSV487lQls10QOSYz0plfsaC9w7kAsB4U8ut1fL72aiUIes123smOUqitaElgMJiZC/q+wq5BJcPSkMdmye867bfz1oPRKaZYp35okYA3LaX6IYTqVPxupSN/dOcyQrGaJNkwvE+QgbhyYaydgdx+scLbJ5nemM4hhn2fvgR5y4HkGS2Skt24lLVVVh6Eqkk+Q0AWOh3Xl0w4jyD560d9YR9f1TsuVSkii/GKij/w9EMEXRdOGH4BHRorokbeK/h/Qpj4eMlFUc4xSk8ho/ahc2RiY2MkuycD1Ja504o9H9hK4UvzbEejPZuYeQg8HiMKb+Uta15q9RcK5DXXljTIunztrzOHbc8z+rIPwS1TBpKOfB1ORGHoysYafPJ0rYEi99qfaxRq+9gyLPDizkatdhyJQYwm1tFTPaLGnd7PRhk4T0pLKm3e4JXbZKRxfV8g6HKmzYjxkPjcXuGaLyLIwzv5vJopd+/mpp3IBKCyLFVcqSaT2rvtFNA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB8PR04MB6346.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(186003)(38350700002)(26005)(38100700002)(5660300002)(6506007)(4326008)(8676002)(66946007)(66556008)(66476007)(52116002)(86362001)(7416002)(8936002)(44832011)(6512007)(2616005)(316002)(508600001)(83380400001)(6486002)(36756003)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LHHR8k5TGtiAYm1UVW1KHPv51aJFn92hi6F6A8vmUOtv1/X5ojs7XQLpY7JNu6YlxGxZLDnVezveSU89/IC9NQ/WE0E3Qj6wZ4OP2EP9IFUBmk/C6JXl8ZQM73nqGhw491ZZUbI4j3TlFmDnHqfYeWxHgmae1KUBaKJsl00iyrNFHCJiYF9FrbUpZfi4axBFFOkAs/JVHeZRoEyfgaiIFfd7iJph0f3Zt53PNN669an4qn3vaxsvChHfHYPiJJPfxcXr5Bn27oPCxAEeo5lxf83/YKB5ESKjIf3wwJsJL7c4ActzYKiMu3ovZzTNE9urzTmSrJqE2532p8jHWeW1jw8KqdJaKghRIiA4kQI0ikW7GjIug1UJpIERBd7um2cyxnR1Rpyx8UeOQy1++oafsJkNxiC2jPCYc9HkJ4ERTFCwem9Rf72nMiF9poTYXD+SwoY/AN4JiwYUf9c2QsFRW+/YvmJGUAmaiPjq7TFTSOnru336qxZjZrH62bsFGOOIxQuWASKCbjc6+d1hIE06q58j5MZSycZHZqrXJAAAn4jjudSFMaDyt+oNJi/zBI9Bz4+5KYSTx61QkifBAEbK2GBbmslez/qxMmNH49oRD3tAGzqAhzso9nhIACBhOc9fOc0Rn5zxaENvVm3dbgoylGtfsBrt+kQV79MXTnvu82xvjR+bh9h0XHPchvjAkdPEM+wNZOk4z0Wn5z1rx0ZRDozXkzhIxeVHmgNlBwBJkidcVX9dAo94gxaaJw6S8aftb1I7z1ePgs/fBxLT0zvZPNYqzqlDRCdADlcu8qIZuLXpWj3scMHBnogTlWMMKeTplLR+ptyUUAG3e2bKaCFH+EAye8sq1IaatzZ/AlSyP8SIYI4RZ1ceI9gVQ+UjA7vZ3NBAeLzcgs7d+ai40jrMtyvTE3jNnZN6lW7/R4iEEZUYxk8spIAssX+mdtaqbLg1XaSCkKFDnGlfCOfJM/YPZ00YCyj/pLT6tVotEEi4tI84CJDXn0Fm4Oqe3kmZF5g9WGlA4Jho1IL2bI0tksn6FNZQSkGYSogI3I3c+3nyBumO1zsicFSyCj4AdeQbWXNcdn+uOKg45YXaWCq+qhmeqik4EfVd4/D92lIvmgqueeOmHR3RQB/WiXD/XyxMIJp+LjsC73CQuylyzYhtk+zbLqTu/GEtVBiJMzolvYRuaVqPfLv/h1VC15Cn/kXV31ruQLqKdLu31dHf7PGAITurph1j+IMZ3tBgHzxyRGVonID0V5VQitVYeZHGwzVHOGO4PBNi2exPFPo6ggLAx2ZMasYHT9/PMTbCZIKpobDwLNPDoea1urgMxAcDPRqbLuX/600XhQl0lPSOL7Ja6YxbfDbZ6Po3z0t5LeQpZc+iBvkF1wkhrxawNXGxaRlVYqYVStqrCid3wUZkU3ayYEUMEIUF4vlOYjELm5dkY5WLtgXo3zIwFzS++j5n4inv0ErH X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f886b7a-7006-4713-ef7b-08da08b7cdbc X-MS-Exchange-CrossTenant-AuthSource: DB8PR04MB6346.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2022 08:17:55.1970 (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: kozNkaoXKbP2/inCbOCG9ijpaGPBpSHMs2m2xAaEAPYMnFCkPSss4+ANAd9g3RQ0HnWhiWppzZlBqhMUkeIyig== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6285 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.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 5bce74de7cf2..5584b40fb36d 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, @@ -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/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 {