All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil+cisco@kernel.org>
To: Jai Luthra <jai.luthra@ideasonboard.com>,
	Hans Verkuil <hverkuil@kernel.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
	Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
	linux-media@vger.kernel.org
Cc: Ricardo Ribalda <ribalda@chromium.org>,
	Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>,
	Ma Ke <make24@iscas.ac.cn>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 04/10] media: v4l2-dev: Add helpers to get current format from the state
Date: Mon, 22 Sep 2025 10:06:59 +0200	[thread overview]
Message-ID: <f2178b2d-d8ea-470f-8f8f-8ffc0380cee5@kernel.org> (raw)
In-Reply-To: <20250919-vdev-state-v2-4-b2c42426965c@ideasonboard.com>

On 19/09/2025 11:55, Jai Luthra wrote:
> Add a helper function that drivers can call to retrieve the current
> v4l2_format stored in a video device state for internal use.
> 
> Additionally, provide a G_FMT ioctl implementation that drivers can use
> instead of writing their own when the format is stored in the active
> state.
> 
> Signed-off-by: Jai Luthra <jai.luthra@ideasonboard.com>
> --
> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> Cc: Hans Verkuil <hverkuil@kernel.org>
> Cc: Jai Luthra <jai.luthra@ideasonboard.com>
> Cc: Ricardo Ribalda <ribalda@chromium.org>
> Cc: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> Cc: Ma Ke <make24@iscas.ac.cn>
> Cc: linux-media@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/media/v4l2-core/v4l2-dev.c | 23 +++++++++++++++++++++++
>  include/media/v4l2-dev.h           | 18 ++++++++++++++++++
>  2 files changed, 41 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
> index dff23c6a0b56fb3d29e1c04e386bb445fa8773bb..2606077538be0e83032c6ae8956c1d67da0d0c5d 100644
> --- a/drivers/media/v4l2-core/v4l2-dev.c
> +++ b/drivers/media/v4l2-core/v4l2-dev.c
> @@ -199,6 +199,29 @@ void __video_device_state_free(struct video_device_state *state)
>  }
>  EXPORT_SYMBOL_GPL(__video_device_state_free);
>  
> +struct v4l2_format *video_device_state_get_fmt(struct video_device_state *state)
> +{
> +	if (WARN_ON_ONCE(!state))
> +		return NULL;
> +
> +	return &state->fmt;
> +}
> +EXPORT_SYMBOL_GPL(video_device_state_get_fmt);
> +
> +int video_device_g_fmt(struct file *file, void *priv, struct v4l2_format *fmt)
> +{
> +	struct video_device_state *state = priv;
> +	struct v4l2_format *vfmt = video_device_state_get_fmt(state);

Obviously, if multiple format types are stored in state (e.g. video capture and
output), then this code needs to pick the right format based on fmt->type.

I would also suggest moving this to v4l2-common.c and renaming it to v4l2_g_fmt,
consistent with other helpers there (v4l2_g/s_parm_cap).

Regards,

	Hans

> +
> +	if (!vfmt)
> +		return -EINVAL;
> +
> +	*fmt = *vfmt;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(video_device_g_fmt);
> +
>  static inline void video_get(struct video_device *vdev)
>  {
>  	get_device(&vdev->dev);
> diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
> index d327be16f6def70554a7d92d10436a29384ae32a..b5312823fbff9c236d4394d48fa9a14412b17c68 100644
> --- a/include/media/v4l2-dev.h
> +++ b/include/media/v4l2-dev.h
> @@ -612,6 +612,24 @@ __video_device_state_alloc(struct video_device *vdev,
>   */
>  void __video_device_state_free(struct video_device_state *state);
>  
> +/**
> + * video_device_state_get_fmt - get current v4l2_format.
> + *
> + * @state: pointer to struct video_device_state
> + */
> +struct v4l2_format *
> +video_device_state_get_fmt(struct video_device_state *state);
> +
> +/**
> + * video_device_g_fmt - fill v4l2_format from the state.
> + *
> + * @file: pointer to struct file
> + * @state: pointer to struct video_device_state
> + * @format: pointer to struct v4l2_format
> + */
> +int video_device_g_fmt(struct file *file, void *priv,
> +		       struct v4l2_format *format);
> +
>  /**
>   * v4l2_debugfs_root - returns the dentry of the top-level "v4l2" debugfs dir
>   *
> 


  reply	other threads:[~2025-09-22  8:07 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-19  9:55 [PATCH v2 00/10] media: Introduce video device state management Jai Luthra
2025-09-19  9:55 ` Jai Luthra
2025-09-19  9:55 ` [PATCH v2 01/10] media: v4l2-core: Introduce state management for video devices Jai Luthra
2025-09-22  7:44   ` Hans Verkuil
2025-09-22  8:00     ` Hans Verkuil
2025-09-29 15:30       ` Jai Luthra
2025-09-29 20:02         ` Michael Riesch
2025-09-30  7:26           ` Jacopo Mondi
2025-09-30  7:15         ` Jacopo Mondi
2025-09-30  7:24         ` Hans Verkuil
2025-09-24  7:06     ` Hans Verkuil
2025-09-24 10:15   ` Mauro Carvalho Chehab
2025-09-29 16:50     ` Jai Luthra
2025-09-19  9:55 ` [PATCH v2 02/10] media: v4l2-dev: Add support for try state Jai Luthra
2025-09-22  7:52   ` Hans Verkuil
2025-09-22  7:58     ` Hans Verkuil
2025-09-29 16:15       ` Jai Luthra
2025-09-30  7:30         ` Hans Verkuil
2025-09-30  9:35           ` Jacopo Mondi
2025-09-30 10:07             ` Hans Verkuil
2025-09-19  9:55 ` [PATCH v2 03/10] media: v4l2-dev: Add callback for initializing video device state Jai Luthra
2025-09-19  9:55 ` [PATCH v2 04/10] media: v4l2-dev: Add helpers to get current format from the state Jai Luthra
2025-09-22  8:06   ` Hans Verkuil [this message]
2025-09-29 16:16     ` Jai Luthra
2025-09-19  9:55 ` [PATCH v2 05/10] media: v4l2-ioctl: Add video_device_state argument to v4l2 ioctl wrappers Jai Luthra
2025-09-22  8:09   ` Hans Verkuil
2025-09-22  8:10     ` Hans Verkuil
2025-09-19  9:55 ` [PATCH v2 06/10] media: Replace void * with video_device_state * in all driver ioctl implementations Jai Luthra
2025-09-19  9:55   ` Jai Luthra
2026-03-07 19:49   ` David Dull
2026-03-08 10:37     ` Laurent Pinchart
2026-03-07 20:06   ` David Dull
2025-09-19  9:55 ` [PATCH v2 07/10] media: v4l2-ioctl: Pass device state for G/S/TRY_FMT ioctls Jai Luthra
2025-09-22  8:11   ` Hans Verkuil
2025-09-19  9:56 ` [PATCH v2 08/10] media: ti: j721e-csi2rx: Use video_device_state Jai Luthra
2025-09-22  8:16   ` Hans Verkuil
2025-09-29 16:21     ` Jai Luthra
2025-09-19  9:56 ` [PATCH v2 09/10] media: rkisp1: " Jai Luthra
2025-09-19  9:56   ` Jai Luthra
2025-09-19  9:56 ` [PATCH v2 10/10] media: rkisp1: Calculate format information on demand Jai Luthra
2025-09-19  9:56   ` Jai Luthra
2025-09-20 10:48 ` [PATCH v2 00/10] media: Introduce video device state management Andy Shevchenko
2025-09-20 10:48   ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f2178b2d-d8ea-470f-8f8f-8ffc0380cee5@kernel.org \
    --to=hverkuil+cisco@kernel.org \
    --cc=hverkuil@kernel.org \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=jai.luthra@ideasonboard.com \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=make24@iscas.ac.cn \
    --cc=mchehab@kernel.org \
    --cc=ribalda@chromium.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tomi.valkeinen@ideasonboard.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.