From patchwork Tue Jun 18 19:46:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Karlman X-Patchwork-Id: 13702889 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 6F175C27C4F for ; Tue, 18 Jun 2024 19:48:03 +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=H+d/uCaYIeSy3uLR3B9XfFFH8OmoKEc82sYaiYI48ww=; b=eM809IqAzbX4RW EN8e3OIJdv+qdFmlK4N452P4DGnhKDGwntXzF0re1BtY1teKONJPkSfq3C+Q0h6ODPkSF4kPSy36q KfFgX7BCCgJH9YweBFzYCFXG4KlXkhdB37CRo1+39AGjbOcaLQt9tc5zKcPaobAiw+0wwyb9+5mXO wpFutbu9XSgV2GCckd6P5nwunfz6T6+z8NX4rkf2aXMY+/9kOPfQqopSGjXhklaCBgY0czwkDPXZO qHTlOlNycnWDCjSeFTlbhExVxU9XQSPguDC8QpZ6jxHauozMDKL9I3F2bO4M+lFRiKXvcIbLuH8+A ti3IAnUqeu6OfNGEB8tQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJeoC-0000000GPEj-0Q9d; Tue, 18 Jun 2024 19:48:00 +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 1sJeo8-0000000GPC4-3YP7 for linux-rockchip@lists.infradead.org; Tue, 18 Jun 2024 19:47:58 +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=1718740058; bh=gLGuV1Op7vcspjOywkdVAgjVRmPHAb5yxsn8Ldz0h8k=; b=tXSsnzywDpE+bZg5SRXVLBOAW/+S9hLjrbke6o3RKLmXbZ26bqFjm6vtmC2RmgN4BFAUu/jl9 MuhHYoC5MZWU8RLYjQSvoMnCrYrOPtAT2g8Dm/wptitgrt44dQtlhpgk5wi+wkqpaXZJUiL9ubx n7yepdjL5XQchyZb3LGYPnumAjjE1yVN/2w1V55E4YJFZa9tEEiuo6JgwPgehfRS/fbRnxlHxJA IK2ztpr2BYfvF4bm7islBgZHGAdX/53mVxHyiQ2ey8IeB1VsHGWlr8c379YITY0sbyBPagR/v9E X5Cf2P2JPkwmrf3Q62B1zpsqYolM8BOKH5MI3N6UEuqw== From: Jonas Karlman To: Ezequiel Garcia , Mauro Carvalho Chehab , Hans Verkuil , "Greg Kroah-Hartman" Cc: Alex Bee , Nicolas Dufresne , Benjamin Gaignard , Sebastian Fricke , Christopher Obbard , Detlev Casanova , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Jonas Karlman Subject: [PATCH v5 09/10] media: rkvdec: Add get_image_fmt ops Date: Tue, 18 Jun 2024 19:46:33 +0000 Message-ID: <20240618194647.742037-10-jonas@kwiboo.se> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618194647.742037-1-jonas@kwiboo.se> References: <20240618194647.742037-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: 6671e45564ade33c9005a013 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240618_124757_473665_EE20DA7D X-CRM114-Status: GOOD ( 13.48 ) 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 --- 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 d8fb2d935ffc..455b9cd34b6a 100644 --- a/drivers/staging/media/rkvdec/rkvdec.c +++ b/drivers/staging/media/rkvdec/rkvdec.c @@ -108,15 +108,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 {