From patchwork Mon Sep 9 19:25:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Karlman X-Patchwork-Id: 13797461 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 1D974ECE587 for ; Mon, 9 Sep 2024 19:26: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=n4s11XuinmJsMq/lMPAinQW7ZCmsfoQixPlPjmqNjTg=; b=pk6m/l5Bo1E6tz WDtS7MQwx1wDv5iKm+mh1fe6LoOtpQJy0avNU2WQs8vSG3gY2gmQQ/xluvP2VnpqUGesCp9SuOm38 cFixxPvKxYmYcvDkFXUy49kNkTSL11j/BnRjbzYXw+q496eK8b5CcTVtew1wXiRvbQS4cX7v05MKL M+wYT3Xd25a7Yrjs4VhJgDEYb8gRs0xeqD18vr2yRAKYzBnzgpvlvOQQR9yQxEm6ltjPiKosyWqKr Dgy1AxL23rZkNQVJs5hC1QqYZ4doop3PC7XmUqPoU0OWhI0EjMutzYkWSm7pPB+mHfz7hBoi/NrTu Is1L5DuTwcakUZmdUZFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1snk1w-000000035EA-3k3t; Mon, 09 Sep 2024 19:26:32 +0000 Received: from smtp.forwardemail.net ([149.28.215.223]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1snk1t-000000035By-1bNe for linux-rockchip@lists.infradead.org; Mon, 09 Sep 2024 19:26:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-ID: Date: Subject: Cc: To: From; q=dns/txt; s=fe-e1b5cab7be; t=1725909983; bh=WUtNqV5Bor6zEzVia1V8H1hXPJSpLb+pccjKkjnBtXI=; b=0ZcH5B59Zrjo0DMYDQ8F/8jiNndciY5zoBQXymYmZPhGPNVb61JgePJt6Kz5vHwP+C8TjXHC2 mDsIJ2bKqPJZqSZ86lKHQzthcCGUF2qas8nEVaVRDsQxphU7p1qrxiga5yZ5c52iZU7ZCzozKTF HDcQRQFtF1ibnWGBMV3jaLqgWXHMp4OC9pl7JHO24wxFB1+ujhLOeUcY/dfnt4QE7uGZyN/dNOJ ASmdq7d1R0vVdf3VfChvQrVaUJIjGAYtC6uWhgwkcM0fXYxfy1fhd/P32LUBnLX45EtrFChxwuk fph3NQ+drGbBGAUH10eRbDze4j8QjBOSslCZSaDD/IFQ== From: Jonas Karlman To: Sebastian Fricke , Ezequiel Garcia , Mauro Carvalho Chehab , Greg Kroah-Hartman Cc: Alex Bee , Nicolas Dufresne , Benjamin Gaignard , Detlev Casanova , Dan Carpenter , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Jonas Karlman , Christopher Obbard Subject: [PATCH v6 09/11] media: rkvdec: Add get_image_fmt ops Date: Mon, 9 Sep 2024 19:25:07 +0000 Message-ID: <20240909192522.1076704-10-jonas@kwiboo.se> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240909192522.1076704-1-jonas@kwiboo.se> References: <20240909192522.1076704-1-jonas@kwiboo.se> MIME-Version: 1.0 X-Report-Abuse-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Complaints-To: abuse@forwardemail.net X-ForwardEmail-Version: 0.4.40 X-ForwardEmail-Sender: rfc822; jonas@kwiboo.se, smtp.forwardemail.net, 149.28.215.223 X-ForwardEmail-ID: 66df4bdec680cb8b7d2dc234 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240909_122629_475911_2BA146FC X-CRM114-Status: GOOD ( 14.16 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Add support for a get_image_fmt() ops that return the required image format. The CAPTURE format is reset when required image format changes and the buffer queue is not busy. Signed-off-by: Jonas Karlman Tested-by: Nicolas Dufresne Tested-by: Christopher Obbard Reviewed-by: Nicolas Dufresne --- v6: - No change v5: - Collect t-b tags v4: - Change fmt_opaque into an image format - Split patch into two v3: - New patch --- drivers/staging/media/rkvdec/rkvdec.c | 49 +++++++++++++++++++++++++-- drivers/staging/media/rkvdec/rkvdec.h | 2 ++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c index 467fc05b347a..8df49ee12820 100644 --- a/drivers/staging/media/rkvdec/rkvdec.c +++ b/drivers/staging/media/rkvdec/rkvdec.c @@ -111,15 +111,60 @@ static int rkvdec_try_ctrl(struct v4l2_ctrl *ctrl) { struct rkvdec_ctx *ctx = container_of(ctrl->handler, struct rkvdec_ctx, ctrl_hdl); const struct rkvdec_coded_fmt_desc *desc = ctx->coded_fmt_desc; + struct v4l2_pix_format_mplane *pix_mp = &ctx->decoded_fmt.fmt.pix_mp; + enum rkvdec_image_fmt image_fmt; + struct vb2_queue *vq; + int ret; + + if (desc->ops->try_ctrl) { + ret = desc->ops->try_ctrl(ctx, ctrl); + if (ret) + return ret; + } + + if (!desc->ops->get_image_fmt) + return 0; - if (desc->ops->try_ctrl) - return desc->ops->try_ctrl(ctx, ctrl); + image_fmt = desc->ops->get_image_fmt(ctx, ctrl); + if (ctx->image_fmt == image_fmt) + return 0; + + if (rkvdec_is_valid_fmt(ctx, pix_mp->pixelformat, image_fmt)) + return 0; + + /* format change not allowed when queue is busy */ + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); + if (vb2_is_busy(vq)) + return -EINVAL; + + return 0; +} + +static int rkvdec_s_ctrl(struct v4l2_ctrl *ctrl) +{ + struct rkvdec_ctx *ctx = container_of(ctrl->handler, struct rkvdec_ctx, ctrl_hdl); + const struct rkvdec_coded_fmt_desc *desc = ctx->coded_fmt_desc; + struct v4l2_pix_format_mplane *pix_mp = &ctx->decoded_fmt.fmt.pix_mp; + enum rkvdec_image_fmt image_fmt; + + if (!desc->ops->get_image_fmt) + return 0; + + image_fmt = desc->ops->get_image_fmt(ctx, ctrl); + if (ctx->image_fmt == image_fmt) + return 0; + + ctx->image_fmt = image_fmt; + if (!rkvdec_is_valid_fmt(ctx, pix_mp->pixelformat, ctx->image_fmt)) + rkvdec_reset_decoded_fmt(ctx); return 0; } static const struct v4l2_ctrl_ops rkvdec_ctrl_ops = { .try_ctrl = rkvdec_try_ctrl, + .s_ctrl = rkvdec_s_ctrl, }; static const struct rkvdec_ctrl_desc rkvdec_h264_ctrl_descs[] = { diff --git a/drivers/staging/media/rkvdec/rkvdec.h b/drivers/staging/media/rkvdec/rkvdec.h index 6f8cf50c5d99..e466a2753ccf 100644 --- a/drivers/staging/media/rkvdec/rkvdec.h +++ b/drivers/staging/media/rkvdec/rkvdec.h @@ -73,6 +73,8 @@ struct rkvdec_coded_fmt_ops { struct vb2_v4l2_buffer *dst_buf, enum vb2_buffer_state result); int (*try_ctrl)(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl); + enum rkvdec_image_fmt (*get_image_fmt)(struct rkvdec_ctx *ctx, + struct v4l2_ctrl *ctrl); }; enum rkvdec_image_fmt {