Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1674726rdf; Sun, 5 Nov 2023 09:07:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpiHS7sWV9QuqK6rFjsNLy9XTL/JiqkA3j3DYYC7vjkDW3CJFif1TlBiUW7GpnN9jKhb3M X-Received: by 2002:a05:6808:2395:b0:3ae:26cb:9756 with SMTP id bp21-20020a056808239500b003ae26cb9756mr34352096oib.3.1699204042579; Sun, 05 Nov 2023 09:07:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699204042; cv=none; d=google.com; s=arc-20160816; b=FrGOg20sCmceNdosVPQIEqLqwGvTqJigztshPUboMtT3dnjQuvqKvVTIMsTo+7BeCf Dzzo56TbMhx5xeUmYM0ADVcQVKTX3EoyPTzk4c7AV60LTEM+3kGJwUBmEqxAt4XTHsqW NZA5qkr2AKCOaCcfRgsXzaZ9an1iexwTx+zCj3juACNjQk0FfZYexsmy5jQe/nFu2vXm cjiNdMmeeV+kaii+XvoR8os4ngTTC4F38+9jl9SJ5ngPu02CWNMuwPreHOqOSHyRQQ/N T+4pbjRWlowbbd8gNBiNCVxd87EuKqUNcO6mspaavceAh7/ozI3rhUQpyo3sFTwgLVQx OhzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=agrfRALBNiUBrIChitGx/tWeu1YIIhSrbadQHiAr0/U=; fh=ZAb5e/67NTsWML6RpVmzFEm3L9CC7ETVZIg6hSgYq5w=; b=kGUzLGzLOf6IN/+8q9SvQgYVDxRQgUyRojCgwnfuFpKEGBQy6b7mkhdBB1sLYclV18 GcGVYVq9PXt1VD0W7cPtoh/pjq9UaU7y5br7aLc5fChPln322gmZaM5ZprLgtbmXyAaS xgcdsAea0ydoTfnf0raqVSBmnBpRvJj1NBu5yNM9AMWD4qs2SNK5wGXcnmH9GnHzLLLM kp9RD03WKqAVGx6bAmRE+gi63uFHdj+KePcTMjMJpHhbk+Yn3LRHhPZGYh/hW1naDcjw 3TFRoiiujGSNg1cXR6FF+F0JeNBGe1DdDa4QwLGI6A5S7vpsKwy44e43kgUs/+CW+jKE FriQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kwiboo.se header.s=fe-e1b5cab7be header.b=EqAb0U5L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kwiboo.se Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id bg29-20020a056808179d00b003aa16f1779bsi2705562oib.229.2023.11.05.09.07.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 09:07:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kwiboo.se header.s=fe-e1b5cab7be header.b=EqAb0U5L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kwiboo.se Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 777EA805B201; Sun, 5 Nov 2023 09:07:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229932AbjKERGk (ORCPT + 99 others); Sun, 5 Nov 2023 12:06:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjKERGe (ORCPT ); Sun, 5 Nov 2023 12:06:34 -0500 Received: from smtp.forwardemail.net (smtp.forwardemail.net [149.28.215.223]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65B2FC0; Sun, 5 Nov 2023 09:06:31 -0800 (PST) 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=1699203989; bh=agrfRALBNiUBrIChitGx/tWeu1YIIhSrbadQHiAr0/U=; b=EqAb0U5L9SU595Hn0hOfOqRGiHEhR7msr6AoN8PLhH//fPEIGnD2XGrABq//gcZ0L4iFzDMn1 LQVWfRPX2+HolbeaZU5GJYid4xPzyEiMaE7b1ME83f895yElL7cWkVNNruYw2+OZEwf83G1gOhX 30GscCQ6yADNSg0vZUkJ8O+Gn0wsiC/8o491YC2Vm633H2NTnYBfnn8DD8mt8QjOteS1iO2CLGV qRol7kkRs4B5Sw159YFgD2PjT5phdzjb3s5weGf4bC0Oy4NKAzVq8PfKtsRyGjLUWFwyOr5gLf/ VoOB+lXhBbfM9YZcTvjcotOutLz4xDS89FXy5NWgjjlw== 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 , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Jonas Karlman Subject: [PATCH v4 09/11] media: rkvdec: Add image format concept Date: Sun, 5 Nov 2023 16:55:08 +0000 Message-ID: <20231105165521.3592037-10-jonas@kwiboo.se> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231105165521.3592037-1-jonas@kwiboo.se> References: <20231105165521.3592037-1-jonas@kwiboo.se> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: 6547c92242ad2f8d1524694f X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 05 Nov 2023 09:07:19 -0800 (PST) Add an enum rkvdec_image_fmt used to signal an image format, e.g. 4:2:0 8-bit, 4:2:0 10-bit or any. Tag each supported CAPUTRE format with an image format and use this tag to filter out unsupported CAPTURE formats. Signed-off-by: Jonas Karlman --- v4: - Change fmt_opaque into an image format - Split patch into two v3: - New patch drivers/staging/media/rkvdec/rkvdec.c | 45 ++++++++++++++++++++------- drivers/staging/media/rkvdec/rkvdec.h | 13 +++++++- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c index c3aede94c872..5949d59d4cf9 100644 --- a/drivers/staging/media/rkvdec/rkvdec.c +++ b/drivers/staging/media/rkvdec/rkvdec.c @@ -27,26 +27,42 @@ #include "rkvdec.h" #include "rkvdec-regs.h" -static u32 rkvdec_enum_decoded_fmt(struct rkvdec_ctx *ctx, int index) +static inline bool rkvdec_image_fmt_match(enum rkvdec_image_fmt fmt1, + enum rkvdec_image_fmt fmt2) +{ + return fmt1 == fmt2 || fmt2 == RKVDEC_IMG_FMT_ANY || + fmt1 == RKVDEC_IMG_FMT_ANY; +} + +static u32 rkvdec_enum_decoded_fmt(struct rkvdec_ctx *ctx, int index, + enum rkvdec_image_fmt image_fmt) { const struct rkvdec_coded_fmt_desc *desc = ctx->coded_fmt_desc; + unsigned int i, j; if (WARN_ON(!desc)) return 0; - if (index >= desc->num_decoded_fmts) - return 0; + for (i = 0, j = 0; i < desc->num_decoded_fmts; i++) { + if (rkvdec_image_fmt_match(desc->decoded_fmts[i].image_fmt, + image_fmt) && + index == j++) + return desc->decoded_fmts[i].fourcc; + } - return desc->decoded_fmts[index]; + return 0; } -static bool rkvdec_is_valid_fmt(struct rkvdec_ctx *ctx, u32 fourcc) +static bool rkvdec_is_valid_fmt(struct rkvdec_ctx *ctx, u32 fourcc, + enum rkvdec_image_fmt image_fmt) { const struct rkvdec_coded_fmt_desc *desc = ctx->coded_fmt_desc; unsigned int i; for (i = 0; i < desc->num_decoded_fmts; i++) { - if (desc->decoded_fmts[i] == fourcc) + if (rkvdec_image_fmt_match(desc->decoded_fmts[i].image_fmt, + image_fmt) && + desc->decoded_fmts[i].fourcc == fourcc) return true; } @@ -80,7 +96,7 @@ static void rkvdec_reset_decoded_fmt(struct rkvdec_ctx *ctx) struct v4l2_format *f = &ctx->decoded_fmt; u32 fourcc; - fourcc = rkvdec_enum_decoded_fmt(ctx, 0); + fourcc = rkvdec_enum_decoded_fmt(ctx, 0, ctx->image_fmt); rkvdec_reset_fmt(ctx, f, fourcc); f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; f->fmt.pix_mp.width = ctx->coded_fmt.fmt.pix_mp.width; @@ -149,8 +165,11 @@ static const struct rkvdec_ctrls rkvdec_h264_ctrls = { .num_ctrls = ARRAY_SIZE(rkvdec_h264_ctrl_descs), }; -static const u32 rkvdec_h264_vp9_decoded_fmts[] = { - V4L2_PIX_FMT_NV12, +static const struct rkvdec_decoded_fmt_desc rkvdec_h264_vp9_decoded_fmts[] = { + { + .fourcc = V4L2_PIX_FMT_NV12, + .image_fmt = RKVDEC_IMG_FMT_420_8BIT, + }, }; static const struct rkvdec_ctrl_desc rkvdec_vp9_ctrl_descs[] = { @@ -282,8 +301,9 @@ static int rkvdec_try_capture_fmt(struct file *file, void *priv, if (WARN_ON(!coded_desc)) return -EINVAL; - if (!rkvdec_is_valid_fmt(ctx, pix_mp->pixelformat)) - pix_mp->pixelformat = rkvdec_enum_decoded_fmt(ctx, 0); + if (!rkvdec_is_valid_fmt(ctx, pix_mp->pixelformat, ctx->image_fmt)) + pix_mp->pixelformat = rkvdec_enum_decoded_fmt(ctx, 0, + ctx->image_fmt); /* Always apply the frmsize constraint of the coded end. */ pix_mp->width = max(pix_mp->width, ctx->coded_fmt.fmt.pix_mp.width); @@ -400,6 +420,7 @@ static int rkvdec_s_output_fmt(struct file *file, void *priv, * * Note that this will propagates any size changes to the decoded format. */ + ctx->image_fmt = RKVDEC_IMG_FMT_ANY; rkvdec_reset_decoded_fmt(ctx); /* Propagate colorspace information to capture. */ @@ -449,7 +470,7 @@ static int rkvdec_enum_capture_fmt(struct file *file, void *priv, struct rkvdec_ctx *ctx = fh_to_rkvdec_ctx(priv); u32 fourcc; - fourcc = rkvdec_enum_decoded_fmt(ctx, f->index); + fourcc = rkvdec_enum_decoded_fmt(ctx, f->index, ctx->image_fmt); if (!fourcc) return -EINVAL; diff --git a/drivers/staging/media/rkvdec/rkvdec.h b/drivers/staging/media/rkvdec/rkvdec.h index 633335ebb9c4..6f8cf50c5d99 100644 --- a/drivers/staging/media/rkvdec/rkvdec.h +++ b/drivers/staging/media/rkvdec/rkvdec.h @@ -75,13 +75,23 @@ struct rkvdec_coded_fmt_ops { int (*try_ctrl)(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl); }; +enum rkvdec_image_fmt { + RKVDEC_IMG_FMT_ANY = 0, + RKVDEC_IMG_FMT_420_8BIT, +}; + +struct rkvdec_decoded_fmt_desc { + u32 fourcc; + enum rkvdec_image_fmt image_fmt; +}; + struct rkvdec_coded_fmt_desc { u32 fourcc; struct v4l2_frmsize_stepwise frmsize; const struct rkvdec_ctrls *ctrls; const struct rkvdec_coded_fmt_ops *ops; unsigned int num_decoded_fmts; - const u32 *decoded_fmts; + const struct rkvdec_decoded_fmt_desc *decoded_fmts; u32 subsystem_flags; }; @@ -104,6 +114,7 @@ struct rkvdec_ctx { const struct rkvdec_coded_fmt_desc *coded_fmt_desc; struct v4l2_ctrl_handler ctrl_hdl; struct rkvdec_dev *dev; + enum rkvdec_image_fmt image_fmt; void *priv; }; -- 2.42.0