From patchwork Thu Jan 12 12:56:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 641777 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 02E41C54EBD for ; Thu, 12 Jan 2023 12:57:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232658AbjALM5n (ORCPT ); Thu, 12 Jan 2023 07:57:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232322AbjALM5d (ORCPT ); Thu, 12 Jan 2023 07:57:33 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0501A5130D; Thu, 12 Jan 2023 04:57:05 -0800 (PST) Received: from localhost (89-26-75-29.goll.dyn.salzburg-online.at [89.26.75.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sebastianfricke) by madras.collabora.co.uk (Postfix) with ESMTPSA id B56856602DB1; Thu, 12 Jan 2023 12:57:03 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1673528223; bh=KAJmQ51TusAs/OBMlUcE6FAB/zXgKsXdACD+yS0cJJs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=abuLMAtI+0Ssmb0Qet0J4hPnVAdraA31EB3fvZ/zDjZvc2UyLQpbuGpOiFbxXhOqc S9NUy9xnqLwAqNNtyQFTUiP7+lJpwbtRYRwTevw/9OIF62BM43kv9v/Y8O5Dan8zJD zy3+0jfREptqFrzuMIuITsGVocKGn8VB9qrbRTUXlbka8E6UkheBghOkMgwWlfjhJ6 bvU2BcEkzGokpvaFOODMzAKJe3+Xa3+EXgkqaaYK3u3a9zVb6+KOCsN5F9v9WFMQIW dAqSQiVNpyzqaypDHC12Df8AFUhQ4HVKlMv25c6RbKfbpJOAj4W627U9Xoa2Xkd1Up n9oHDOyuMFo1Q== From: Sebastian Fricke Date: Thu, 12 Jan 2023 13:56:26 +0100 Subject: [PATCH v2 11/12] staging: media: rkvdec: Enable S_CTRL IOCTL MIME-Version: 1.0 Message-Id: <20230101-patch-series-v2-6-2-rc1-v2-11-fa1897efac14@collabora.com> References: <20230101-patch-series-v2-6-2-rc1-v2-0-fa1897efac14@collabora.com> In-Reply-To: <20230101-patch-series-v2-6-2-rc1-v2-0-fa1897efac14@collabora.com> To: Mauro Carvalho Chehab , Ezequiel Garcia , Greg Kroah-Hartman Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, Jonas Karlman , Alex Bee , Nicolas Dufresne , Collabora Kernel-domain , Robert Beckett , Laurent Pinchart , Andrzej Pietrasiewicz , Benjamin Gaignard , Sebastian Fricke X-Mailer: b4 0.11.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1673528186; l=3704; i=sebastian.fricke@collabora.com; s=linux-media; h=from:subject:message-id; bh=KAJmQ51TusAs/OBMlUcE6FAB/zXgKsXdACD+yS0cJJs=; b=3Q8dYQ7JJV91gBKcZI7SdzmsUpSj8tSF8FmAoOpA4+8doicKKzpHZXOKqfCS3w0RSMTTwbQ545S3 /EmOOuLQCwWk/liG7p+9gfjw2YEBe+DwYIkP0cAdOuppKUob+jYn X-Developer-Key: i=sebastian.fricke@collabora.com; a=ed25519; pk=pYXedPwrTtErcj7ERYeo/IpTrpe4QbJuEzSB52fslBg= Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Enable user-space to set the SPS of the current byte-stream on the decoder. This action will enable the decoder to pick the optimal pixel-format for the capture queue, whenever it is required. Signed-off-by: Sebastian Fricke Signed-off-by: Jonas Karlman --- drivers/staging/media/rkvdec/rkvdec.c | 81 +++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c index b303c6e0286d..3d413c5ad1d2 100644 --- a/drivers/staging/media/rkvdec/rkvdec.c +++ b/drivers/staging/media/rkvdec/rkvdec.c @@ -93,6 +93,79 @@ static int rkvdec_get_sps_attributes(struct rkvdec_ctx *ctx, void *sps, return 0; } +static int rkvdec_set_sps(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl) +{ + struct v4l2_pix_format_mplane *pix_mp; + struct sps_attributes attributes = {0}; + void *new_sps = NULL; + + /* + * SPS structures are not filled until the control handler is set up + */ + if (!ctx->fh.ctrl_handler) + return 0; + + switch (ctrl->id) { + case V4L2_CID_STATELESS_H264_SPS: + new_sps = (void *)ctrl->p_new.p_h264_sps; + break; + case V4L2_CID_STATELESS_HEVC_SPS: + new_sps = (void *)ctrl->p_new.p_hevc_sps; + break; + default: + dev_err(ctx->dev->dev, "Unsupported stateless control ID: %x\n", ctrl->id); + return -EINVAL; + }; + rkvdec_get_sps_attributes(ctx, new_sps, &attributes); + + /* + * Providing an empty SPS is valid but we do not store it. + */ + if (attributes.width == 0 && attributes.height == 0) + return 0; + + pix_mp = &ctx->decoded_fmt.fmt.pix_mp; + + /* + * SPS must match the provided format dimension, if it doesn't userspace has to + * first reset the output format + */ + if ((attributes.width > pix_mp->width) || (attributes.height > pix_mp->height)) { + dev_err(ctx->dev->dev, + "Dimension mismatch. [%s SPS] W: %d, H: %d, [Format] W: %d, H: %d)\n", + ctrl->id == V4L2_CID_STATELESS_HEVC_SPS ? "HEVC" : "H264", + attributes.width, attributes.height, pix_mp->width, pix_mp->height); + return -EINVAL; + } + + if (ctx->sps && pix_mp->pixelformat == rkvdec_get_valid_fmt(ctx)) { + /* + * Userspace is allowed to change the SPS at any point, if the + * pixel format doesn't differ from the format in the context, + * just accept the change even if buffers are queued + */ + ctx->sps = new_sps; + } else { + /* + * Do not accept changing the SPS, while buffers are queued, + * when the new SPS would cause switching the CAPTURE pixel format + */ + if (pix_mp->pixelformat != rkvdec_get_valid_fmt(ctx)) { + if (rkvdec_queue_busy(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) + return -EBUSY; + } + ctx->sps = new_sps; + /* + * For the initial SPS setting and when the pixel format is + * changed adjust the pixel format stored in the context + */ + pix_mp->pixelformat = rkvdec_get_valid_fmt(ctx); + rkvdec_fill_decoded_pixfmt(ctx, pix_mp); + } + + return 0; +} + static int rkvdec_try_ctrl(struct v4l2_ctrl *ctrl) { struct rkvdec_ctx *ctx = container_of(ctrl->handler, struct rkvdec_ctx, ctrl_hdl); @@ -104,8 +177,16 @@ static int rkvdec_try_ctrl(struct v4l2_ctrl *ctrl) return 0; } +static int rkvdec_s_ctrl(struct v4l2_ctrl *ctrl) +{ + struct rkvdec_ctx *ctx = container_of(ctrl->handler, struct rkvdec_ctx, ctrl_hdl); + + return rkvdec_set_sps(ctx, ctrl); +} + 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[] = {