Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp210189rwb; Thu, 12 Jan 2023 05:28:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXtQFTdz2ZGHCpVcY/nznZfdmteax4hqxmbv/k7GTZqCvTn93S6MUDXdwA/dScy0mmEShNH9 X-Received: by 2002:a17:907:6e16:b0:7c0:9f6f:6d8 with SMTP id sd22-20020a1709076e1600b007c09f6f06d8mr85437162ejc.2.1673530127855; Thu, 12 Jan 2023 05:28:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673530127; cv=none; d=google.com; s=arc-20160816; b=Hbf6UsbKmI8uoyllUpCC2QDLimG/cZrr7hTGglAIvWrEghBuCaIqjnn34aPAM/jCZQ KLqLCDQ9InxIUXNm1xDFuqJap/dJzQyTb8CK9pkpFAZZHoeUOIFeiOrnCrqU+qkltQCf Y43wdAGUywXZVXl+D6ixz1zY/86WA5B2ggB7ieg5auSN8Wqv7+lDfYviHAZlLDIs45QU Iorz0XKnKWpb8BwYCeOsKkapzsal50GlXrv4fVPgDYYMkpJU5Flt+Gsr2s4hleZ2KEgr cuISmTeIZh2Eg5ALb1NLgOjXvsWfTl++fQPVKicWBByfW1HNexM7UBUbnBmYBme7aRms sa3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=CNwrJQ+s9lIphVQ7BUrazGk8K5ZLZfO1lcOMTRX1o5U=; b=nr3EvMBFq90xc0PoUMF724qZUlKjZKj6lnFDi6P3daGqgsU0qVlcYaoRO0/TADsJrW 1F4gDKzK5nsMdB1qNnRixrSdWp4YynxFckB5yz0jU4nJ/g0zvfmjAVuVoi0ATxVkmj5u DKSeYMDl/H5EjzXUiJK4t+5etrg9W5e1EP6OC20X9m8Yj/bSyWpCM0Q8s9+t9PjLaGkK vQkrDNGLXO8imp39uPXjPCxIPfHXcEahRsOG2HcHT8j3NngusER7xUn3lpHiuwDHQcxi sySotlw0B+GER6cY/bW/asoXAtvRTmznxpDMl7x+h7wEPLGi94pILRaZUc+LQsS9ONkN Ou4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=d7S8hzbl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs18-20020a170906f19200b00711da52c6e4si14261291ejb.309.2023.01.12.05.28.35; Thu, 12 Jan 2023 05:28:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=d7S8hzbl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232681AbjALM5q (ORCPT + 50 others); Thu, 12 Jan 2023 07:57:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231934AbjALM5A (ORCPT ); Thu, 12 Jan 2023 07:57:00 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF9C638BC; Thu, 12 Jan 2023 04:56:58 -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 7A1636602DBA; Thu, 12 Jan 2023 12:56:57 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1673528217; bh=19U+A00eX7GomcVZ4hwuwzX1XI4Jf/K9mYqNNP1Mc6c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=d7S8hzbl9CZf9tINvxTrwAjOPyZGpYeDkOqtO15LV6A+mhlACIc8cO4x/l0QhLMDV RKtUTsC7nqNRAguPa6HrSTppiAP+1MA8FDk9ZHJ6IeS3YiPDk9+Z0RHqgXca364iyY kPl9M+S+OxTFPmU58ZejKKYo/UXx+XjYE7gInFp8dzFpr6PjgyppTspRMHeBo6B0vR wGh0SrbnkraovnN/1QBadr3FDZT4PVFJePnsNXM/Ey47S0Kgc8cBk0q4HU3KAmJ+AT CSQoFV/3kRVQDouTMqx+p/j/egX/DTbgfWmQixUEaho3i+DQosC1e3d9d3RjYAvhRy txFyOGKwsixbA== From: Sebastian Fricke Date: Thu, 12 Jan 2023 13:56:24 +0100 Subject: [PATCH v2 09/12] staging: media: rkvdec: h264: Add callbacks for h264 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230101-patch-series-v2-6-2-rc1-v2-9-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=5576; i=sebastian.fricke@collabora.com; s=linux-media; h=from:subject:message-id; bh=19U+A00eX7GomcVZ4hwuwzX1XI4Jf/K9mYqNNP1Mc6c=; b=q/7dHZEZC7Om5sfZ593nhkIVNVGwUmKnKRnaq5y/97IVmaJeS8raTGDHwcL5TyDW1rqoym9zCAKB cUypHMjIB7YqWAGX5s3xun+/JDEUBTd5vaUDxzWqeURvM7C16Agw X-Developer-Key: i=sebastian.fricke@collabora.com; a=ed25519; pk=pYXedPwrTtErcj7ERYeo/IpTrpe4QbJuEzSB52fslBg= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement the valid format and sps validation callbacks for H264. H264 already has a SPS validation function, adjust it to fit the function the declaration and add error messages. Additionally, add a function to fetch attributes from the SPS in a human readable format to make the code more self documenting. Signed-off-by: Sebastian Fricke --- drivers/staging/media/rkvdec/rkvdec-h264.c | 105 ++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 25 deletions(-) diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c index 4fc167b42cf0..17b215874ddd 100644 --- a/drivers/staging/media/rkvdec/rkvdec-h264.c +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c @@ -1026,40 +1026,80 @@ static int rkvdec_h264_adjust_fmt(struct rkvdec_ctx *ctx, return 0; } -static int rkvdec_h264_validate_sps(struct rkvdec_ctx *ctx, - const struct v4l2_ctrl_h264_sps *sps) +/* + * Convert some fields from the SPS structure into human readable attributes. + */ +static int rkvdec_h264_get_sps_attributes(struct rkvdec_ctx *ctx, void *sps, + struct sps_attributes *attributes) +{ + struct v4l2_ctrl_h264_sps *h264_sps = sps; + unsigned int width = (h264_sps->pic_width_in_mbs_minus1 + 1) * 16; + unsigned int height = (h264_sps->pic_height_in_map_units_minus1 + 1) * 16; + /* + * When frame_mbs_only_flag is not set, this is field height, + * which is half the final height (see (7-18) in the + * specification) + */ + if (!(h264_sps->flags & V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY)) + height *= 2; + + attributes->width = width; + attributes->height = height; + attributes->luma_bitdepth = h264_sps->bit_depth_luma_minus8 + 8; + attributes->chroma_bitdepth = h264_sps->bit_depth_chroma_minus8 + 8; + switch (h264_sps->chroma_format_idc) { + case 0: + attributes->subsampling = 400; + break; + case 1: + attributes->subsampling = 420; + break; + case 2: + attributes->subsampling = 422; + break; + case 3: + attributes->subsampling = 444; + break; + }; + return 0; +} + +static int rkvdec_h264_validate_sps(struct rkvdec_ctx *ctx, void *sps, + struct v4l2_pix_format_mplane *pix_mp) { - unsigned int width, height; + struct sps_attributes attributes = {0}; + + rkvdec_h264_get_sps_attributes(ctx, sps, &attributes); /* * TODO: The hardware supports 10-bit and 4:2:2 profiles, * but it's currently broken in the driver. * Reject them for now, until it's fixed. */ - if (sps->chroma_format_idc > 1) - /* Only 4:0:0 and 4:2:0 are supported */ + if (attributes.subsampling > 420) { + dev_err(ctx->dev->dev, + "Only 4:0:0 and 4:2:0 subsampling schemes are supported, got: %d\n", + attributes.subsampling); return -EINVAL; - if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8) - /* Luma and chroma bit depth mismatch */ + } + if (attributes.luma_bitdepth != attributes.chroma_bitdepth) { + dev_err(ctx->dev->dev, + "Luma and chroma bit depth mismatch, luma %d, chroma %d\n", + attributes.luma_bitdepth, attributes.chroma_bitdepth); return -EINVAL; - if (sps->bit_depth_luma_minus8 != 0) - /* Only 8-bit is supported */ + } + if (attributes.luma_bitdepth != 8) { + dev_err(ctx->dev->dev, "Only 8-bit H264 formats supported, SPS %d\n", + attributes.luma_bitdepth); return -EINVAL; + } - width = (sps->pic_width_in_mbs_minus1 + 1) * 16; - height = (sps->pic_height_in_map_units_minus1 + 1) * 16; - - /* - * When frame_mbs_only_flag is not set, this is field height, - * which is half the final height (see (7-18) in the - * specification) - */ - if (!(sps->flags & V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY)) - height *= 2; - - if (width > ctx->coded_fmt.fmt.pix_mp.width || - height > ctx->coded_fmt.fmt.pix_mp.height) + if (attributes.width > pix_mp->width || attributes.height > pix_mp->height) { + dev_err(ctx->dev->dev, + "Incompatible SPS dimension, SPS %dx%d, Pixel format %dx%d.", + attributes.width, attributes.height, pix_mp->width, pix_mp->height); return -EINVAL; + } return 0; } @@ -1077,8 +1117,9 @@ static int rkvdec_h264_start(struct rkvdec_ctx *ctx) if (!ctrl) return -EINVAL; - ret = rkvdec_h264_validate_sps(ctx, ctrl->p_new.p_h264_sps); - if (ret) + ret = rkvdec_h264_validate_sps(ctx, ctrl->p_new.p_h264_sps, + &ctx->coded_fmt.fmt.pix_mp); + if (ret < 0) return ret; h264_ctx = kzalloc(sizeof(*h264_ctx), GFP_KERNEL); @@ -1175,10 +1216,21 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) return 0; } +static u32 rkvdec_h264_valid_fmt(struct rkvdec_ctx *ctx) +{ + /* + * Only 8 bit 4:0:0 and 4:2:0 formats supported for now. + * The SPS is validated at a different function thus we can assume that + * it is correct. + */ + return V4L2_PIX_FMT_NV12; +} + static int rkvdec_h264_try_ctrl(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl) { if (ctrl->id == V4L2_CID_STATELESS_H264_SPS) - return rkvdec_h264_validate_sps(ctx, ctrl->p_new.p_h264_sps); + return rkvdec_h264_validate_sps(ctx, ctrl->p_new.p_h264_sps, + &ctx->coded_fmt.fmt.pix_mp); return 0; } @@ -1189,4 +1241,7 @@ const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops = { .stop = rkvdec_h264_stop, .run = rkvdec_h264_run, .try_ctrl = rkvdec_h264_try_ctrl, + .valid_fmt = rkvdec_h264_valid_fmt, + .sps_check = rkvdec_h264_validate_sps, + .get_sps_attributes = rkvdec_h264_get_sps_attributes, }; -- 2.25.1