From patchwork Mon Oct 24 20:15:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jernej_=C5=A0krabec?= X-Patchwork-Id: 10339 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp672627wru; Mon, 24 Oct 2022 15:05:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6qx8pVGNCqAXnZhwFY5v2ichCXOCc1+l4GaiO7Ir4jIgIR/mqf2AtikbOWdUSfMf4Ey9mE X-Received: by 2002:a63:28c:0:b0:46e:9da9:80f8 with SMTP id 134-20020a63028c000000b0046e9da980f8mr20878991pgc.373.1666649099803; Mon, 24 Oct 2022 15:04:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666649099; cv=none; d=google.com; s=arc-20160816; b=kGTTveKtVcEi3bbnPHSkpMHN5Ns63NHZtF1d1lx5SC4OUY+Y6Ya65Ss46yvRJPiIkd HI/f49wwK+5Bu0V+/drqxDZGS4dw4Zq3JoplaDLf0l/qZsU8Q8PvGDTnujQ9aGAcs4nE ExCnNrpw++jST/HdLAJN3O0C5H7WwL14iZo76tzJJoxocZaestkFCWLxh7Uzl8p0pmGV QYhf4BGB64i8Vgi2cM8vzdGaAPtYIDdyM4xi+q/3xURS0VzYYNOloK0+fTZyGXw99QIu qZA9bUeKWCw7UToJVTmSS/QNoBHRXzuDpHMcvgdW5UQdw44zgskjNquMs8EY3PbxXI6R brdQ== 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=4uzd84Lo8isAFXRphDOp8YM5rfTGeiE2OqupA7quo4Y=; b=rRt5rGTaz2oKGsZ9TTGxBvW7UgSAcqFXwSDg9HXTYo5jm9XqkVVDOjCfL74flh2vVD 5Qe9yFYxJjUDZklMXHYq1Br9iM0PX9hTkYwXUph9dvS83SfYnjLIAUFUh97n77EHeDOo LSNmWP4NKQLMxwRuTaJ8wk+xGZ6snyTKcuMKJJ1vSkIwVK4BdnsHcQ9iq/PypbU+h8tB 3HOgUEv6yVZ84gSeRZB9bX+FN7rebCYbo77C6eC78TZDbOK7fuGXyibkuZKus9xYk+sp nnOrjIMqyvA72G/8r+qqnqX50+l2YoRQeatbFsd+YSVmLwP5kID5ISgQ5kf3Bdep0wo/ FfYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cqKQd2gK; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 9-20020a630309000000b0043c1cb75c22si743278pgd.333.2022.10.24.15.04.45; Mon, 24 Oct 2022 15:04:59 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b=cqKQd2gK; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231635AbiJXWEV (ORCPT + 99 others); Mon, 24 Oct 2022 18:04:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231588AbiJXWDj (ORCPT ); Mon, 24 Oct 2022 18:03:39 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9082C16; Mon, 24 Oct 2022 13:17:47 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id bj12so7530462ejb.13; Mon, 24 Oct 2022 13:17:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4uzd84Lo8isAFXRphDOp8YM5rfTGeiE2OqupA7quo4Y=; b=cqKQd2gKzVNMX+5x/YFpR+RBIFY+Djo+X6IMVKyhCRl8jxEW9kQOGfDZBiKyi7ljRg C/MtxDmJB5eZ5EinpJIBOJR2Ku57De+BBMw2S6bygvkqrRBWmJyM9vt3b1sC/f3LPXm9 TR3dGaW7uEsETlRJeqcAiqJrJgAMOTRm/FCAKLEyTXIt4oGAFgmBAlg7bcIYEDI44DJh hFyqnA2iWsa9rA3oJZtyGyum7LI4qFX8EOP+B5pjkgwxhnCtXb40WvpX4QSJMUU63ReV jGoVJzuekyzC2Zh8lvM2DKNIGS46F5G7smK/jWJNfEjha2sV8rojZkz3JNfg2GiPqnIB 8DEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4uzd84Lo8isAFXRphDOp8YM5rfTGeiE2OqupA7quo4Y=; b=hoRN24rfQwMTWHhr745hj1hCksBTq62lKdGFeb6U6T5mBs1N/k2kYSanl/mB8cL8On Fox7L2yQhEvHIHBYAu+glkjubAx3ju2tY72cTcMzJaJZHV+WRiPdKT/IHIFUmmfymq1S BoVtLipyVz05+46rzPU+kqQCb56NLj7qBKoitCc3aYg3llELP4Zb3r5TucTmHW4YTlCQ lemaw5UsiFcD/loj5a/sRzQUla6FNGoxOvVGO7M3eFHtKhN4MF3wjhWWTsKYIkN4ESjw uwtyZrKBqsyJIEsvRiO62HvoPYb4e85DKupCtE1hqmcOJTzAT8UxwTh9CrtKHVVkI/1w lDAA== X-Gm-Message-State: ACrzQf3soUkxJ+/XO6EHlWL/iVpHUggJUeHgB+JmsqWCmPQzu52fxgBA m6518+R/gt9aSqv8j8scUiE= X-Received: by 2002:a17:906:ef8c:b0:78d:46b7:6847 with SMTP id ze12-20020a170906ef8c00b0078d46b76847mr28751369ejb.241.1666642531636; Mon, 24 Oct 2022 13:15:31 -0700 (PDT) Received: from kista.localdomain (82-149-19-102.dynamic.telemach.net. [82.149.19.102]) by smtp.gmail.com with ESMTPSA id op7-20020a170906bce700b0073d638a7a89sm332023ejb.99.2022.10.24.13.15.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 13:15:31 -0700 (PDT) From: Jernej Skrabec To: mripard@kernel.org, paul.kocialkowski@bootlin.com Cc: mchehab@kernel.org, gregkh@linuxfoundation.org, wens@csie.org, samuel@sholland.org, hverkuil-cisco@xs4all.nl, linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Jernej Skrabec Subject: [PATCH 02/11] media: cedrus: Add format reset helpers Date: Mon, 24 Oct 2022 22:15:06 +0200 Message-Id: <20221024201515.34129-3-jernej.skrabec@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024201515.34129-1-jernej.skrabec@gmail.com> References: <20221024201515.34129-1-jernej.skrabec@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747608246673386244?= X-GMAIL-MSGID: =?utf-8?q?1747608246673386244?= By re-arranging try format handlers and set out format handler, we can easily implement reset out/cap format helpers. There is only one subtle, but important functional change. Capture pixel format will be reset each time output format is set. This is actually expected behaviour per stateless decoder API. Signed-off-by: Jernej Skrabec --- .../staging/media/sunxi/cedrus/cedrus_video.c | 100 +++++++++++------- .../staging/media/sunxi/cedrus/cedrus_video.h | 2 + 2 files changed, 66 insertions(+), 36 deletions(-) diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c index 1c3c1d080d31..27a7120fa6fb 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c @@ -241,12 +241,10 @@ static int cedrus_g_fmt_vid_out(struct file *file, void *priv, return 0; } -static int cedrus_try_fmt_vid_cap(struct file *file, void *priv, - struct v4l2_format *f) +static int cedrus_try_fmt_vid_cap_p(struct cedrus_ctx *ctx, + struct v4l2_pix_format *pix_fmt) { - struct cedrus_ctx *ctx = cedrus_file2ctx(file); struct cedrus_dev *dev = ctx->dev; - struct v4l2_pix_format *pix_fmt = &f->fmt.pix; struct cedrus_format *fmt = cedrus_find_format(pix_fmt->pixelformat, CEDRUS_DECODE_DST, dev->capabilities); @@ -262,12 +260,16 @@ static int cedrus_try_fmt_vid_cap(struct file *file, void *priv, return 0; } -static int cedrus_try_fmt_vid_out(struct file *file, void *priv, +static int cedrus_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { - struct cedrus_ctx *ctx = cedrus_file2ctx(file); + return cedrus_try_fmt_vid_cap_p(cedrus_file2ctx(file), &f->fmt.pix); +} + +static int cedrus_try_fmt_vid_out_p(struct cedrus_ctx *ctx, + struct v4l2_pix_format *pix_fmt) +{ struct cedrus_dev *dev = ctx->dev; - struct v4l2_pix_format *pix_fmt = &f->fmt.pix; struct cedrus_format *fmt = cedrus_find_format(pix_fmt->pixelformat, CEDRUS_DECODE_SRC, dev->capabilities); @@ -281,6 +283,12 @@ static int cedrus_try_fmt_vid_out(struct file *file, void *priv, return 0; } +static int cedrus_try_fmt_vid_out(struct file *file, void *priv, + struct v4l2_format *f) +{ + return cedrus_try_fmt_vid_out_p(cedrus_file2ctx(file), &f->fmt.pix); +} + static int cedrus_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { @@ -301,13 +309,60 @@ static int cedrus_s_fmt_vid_cap(struct file *file, void *priv, return 0; } +void cedrus_reset_cap_format(struct cedrus_ctx *ctx) +{ + ctx->dst_fmt.pixelformat = 0; + cedrus_try_fmt_vid_cap_p(ctx, &ctx->dst_fmt); +} + +static int cedrus_s_fmt_vid_out_p(struct cedrus_ctx *ctx, + struct v4l2_pix_format *pix_fmt) +{ + struct vb2_queue *vq; + int ret; + + ret = cedrus_try_fmt_vid_out_p(ctx, pix_fmt); + if (ret) + return ret; + + ctx->src_fmt = *pix_fmt; + + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); + + switch (ctx->src_fmt.pixelformat) { + case V4L2_PIX_FMT_H264_SLICE: + case V4L2_PIX_FMT_HEVC_SLICE: + vq->subsystem_flags |= + VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF; + break; + default: + vq->subsystem_flags &= + ~VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF; + break; + } + + /* Propagate format information to capture. */ + ctx->dst_fmt.colorspace = pix_fmt->colorspace; + ctx->dst_fmt.xfer_func = pix_fmt->xfer_func; + ctx->dst_fmt.ycbcr_enc = pix_fmt->ycbcr_enc; + ctx->dst_fmt.quantization = pix_fmt->quantization; + cedrus_reset_cap_format(ctx); + + return 0; +} + +void cedrus_reset_out_format(struct cedrus_ctx *ctx) +{ + ctx->src_fmt.pixelformat = 0; + cedrus_s_fmt_vid_out_p(ctx, &ctx->src_fmt); +} + static int cedrus_s_fmt_vid_out(struct file *file, void *priv, struct v4l2_format *f) { struct cedrus_ctx *ctx = cedrus_file2ctx(file); struct vb2_queue *vq; struct vb2_queue *peer_vq; - int ret; vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); /* @@ -328,34 +383,7 @@ static int cedrus_s_fmt_vid_out(struct file *file, void *priv, if (vb2_is_busy(peer_vq)) return -EBUSY; - ret = cedrus_try_fmt_vid_out(file, priv, f); - if (ret) - return ret; - - ctx->src_fmt = f->fmt.pix; - - switch (ctx->src_fmt.pixelformat) { - case V4L2_PIX_FMT_H264_SLICE: - case V4L2_PIX_FMT_HEVC_SLICE: - vq->subsystem_flags |= - VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF; - break; - default: - vq->subsystem_flags &= - ~VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF; - break; - } - - /* Propagate format information to capture. */ - ctx->dst_fmt.colorspace = f->fmt.pix.colorspace; - ctx->dst_fmt.xfer_func = f->fmt.pix.xfer_func; - ctx->dst_fmt.ycbcr_enc = f->fmt.pix.ycbcr_enc; - ctx->dst_fmt.quantization = f->fmt.pix.quantization; - ctx->dst_fmt.width = ctx->src_fmt.width; - ctx->dst_fmt.height = ctx->src_fmt.height; - cedrus_prepare_format(&ctx->dst_fmt); - - return 0; + return cedrus_s_fmt_vid_out_p(cedrus_file2ctx(file), &f->fmt.pix); } const struct v4l2_ioctl_ops cedrus_ioctl_ops = { diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.h b/drivers/staging/media/sunxi/cedrus/cedrus_video.h index 05050c0a0921..8e1afc16a6a1 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_video.h +++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.h @@ -27,5 +27,7 @@ extern const struct v4l2_ioctl_ops cedrus_ioctl_ops; int cedrus_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq); void cedrus_prepare_format(struct v4l2_pix_format *pix_fmt); +void cedrus_reset_cap_format(struct cedrus_ctx *ctx); +void cedrus_reset_out_format(struct cedrus_ctx *ctx); #endif