mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Volodymyr Chapman <volodymyrchapman@gmail.com>
To: Hans de Goede <hansg@kernel.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>,
	Andy Shevchenko <andy@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-media@vger.kernel.org, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Volodymyr Chapman <volodymyrchapman@gmail.com>
Subject: [PATCH 2/2] media: atomisp: Report frame interval for sensors without enum_frame_interval
Date: Mon, 16 Nov 2026 17:57:50 +0000	[thread overview]
Message-ID: <20261116175750.21905-3-volodymyrchapman@gmail.com> (raw)
In-Reply-To: <20261116175750.21905-1-volodymyrchapman@gmail.com>

atomisp_enum_frameintervals() passes VIDIOC_ENUM_FRAMEINTERVALS on to the
sensor's enum_frame_interval pad op. Most sensor drivers used with atomisp
do not implement it, e.g. the OV2722 driver only implements
get_frame_interval and raw sensor drivers such as the IMX175 driver set
their frame rate with the pixel rate and blanking controls instead. For
these sensors VIDIOC_ENUM_FRAMEINTERVALS fails, so userspace does not know
the frame rate.

PipeWire's V4L2 source then advertises a framerate range of 1/1 to 120/1.
Firefox (libwebrtc) takes the minimum of such a range as the camera's
maximum framerate and drops all but 1 frame per second, while the sensor
runs at 30 fps.

When the sensor has no enum_frame_interval, report one discrete frame
interval: the sensor's get_frame_interval if it has that, or else the one
following from its V4L2_CID_PIXEL_RATE, V4L2_CID_HBLANK and V4L2_CID_VBLANK
controls and active format, rounded to a whole number of frames per
second. This is the interval of the sensor's current mode, which is
reported for every frame size; for the OV2722 and IMX175 all modes run at
30 fps.

Tested on a Lenovo ThinkPad 10 (20C3, Atom Z3795) with this file built out
of tree against a 7.2.15 kernel: ENUM_FRAMEINTERVALS reports 30 fps for
both the OV2722 front sensor (from get_frame_interval) and the IMX175 rear
sensor (256 MHz / (3430 * 2500)), and webcamtests.com in Firefox 160 shows
about 30 fps for both instead of 1 fps. This was build-tested on top of
media.git next.

The problem was investigated and this patch drafted with the help of an
AI coding assistant (Claude); the testing was done on the hardware by the
submitter.

Signed-off-by: Volodymyr Chapman <volodymyrchapman@gmail.com>
---
 .../staging/media/atomisp/pci/atomisp_ioctl.c | 64 +++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
index 046a95857..c83834405 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
@@ -576,6 +576,65 @@ static int atomisp_enum_framesizes(struct file *file, void *priv,
 	return 0;
 }
 
+/*
+ * For sensors without enum_frame_interval, get the frame interval of the
+ * sensor's current mode: from get_frame_interval, or else from the pixel rate
+ * and blanking controls which raw sensor drivers use to set the frame rate.
+ */
+static int atomisp_sensor_frame_interval(struct atomisp_input_subdev *input,
+					 struct v4l2_fract *interval)
+{
+	struct v4l2_subdev_frame_interval fi = {
+		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
+	};
+	struct v4l2_subdev_format fmt = {
+		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
+	};
+	struct v4l2_ctrl *pixel_rate, *hblank, *vblank;
+	struct v4l2_subdev_state *act_sd_state;
+	u64 frame_size, fps;
+	int ret;
+
+	act_sd_state = v4l2_subdev_lock_and_get_active_state(input->sensor);
+	ret = v4l2_subdev_call(input->sensor, pad, get_frame_interval,
+			       act_sd_state, &fi);
+	if (ret != -ENOIOCTLCMD) {
+		if (act_sd_state)
+			v4l2_subdev_unlock_state(act_sd_state);
+		if (ret)
+			return ret;
+		if (!fi.interval.numerator || !fi.interval.denominator)
+			return -EINVAL;
+		*interval = fi.interval;
+		return 0;
+	}
+
+	ret = v4l2_subdev_call(input->sensor, pad, get_fmt, act_sd_state, &fmt);
+	if (act_sd_state)
+		v4l2_subdev_unlock_state(act_sd_state);
+	if (ret)
+		return ret;
+
+	pixel_rate = v4l2_ctrl_find(input->sensor->ctrl_handler,
+				    V4L2_CID_PIXEL_RATE);
+	hblank = v4l2_ctrl_find(input->sensor->ctrl_handler, V4L2_CID_HBLANK);
+	vblank = v4l2_ctrl_find(input->sensor->ctrl_handler, V4L2_CID_VBLANK);
+	if (!pixel_rate || !hblank || !vblank)
+		return -EINVAL;
+
+	frame_size = (u64)(fmt.format.width + v4l2_ctrl_g_ctrl(hblank)) *
+		     (fmt.format.height + v4l2_ctrl_g_ctrl(vblank));
+	fps = div64_u64(v4l2_ctrl_g_ctrl_int64(pixel_rate) + frame_size / 2,
+			frame_size);
+	if (!fps)
+		return -EINVAL;
+
+	interval->numerator = 1;
+	interval->denominator = fps;
+
+	return 0;
+}
+
 static int atomisp_enum_frameintervals(struct file *file, void *priv,
 				       struct v4l2_frmivalenum *fival)
 {
@@ -601,6 +660,11 @@ static int atomisp_enum_frameintervals(struct file *file, void *priv,
 			       act_sd_state, &fie);
 	if (act_sd_state)
 		v4l2_subdev_unlock_state(act_sd_state);
+	if (ret == -ENOIOCTLCMD) {
+		if (fival->index)
+			return -EINVAL;
+		ret = atomisp_sensor_frame_interval(input, &fie.interval);
+	}
 	if (ret)
 		return ret;
 
-- 
2.43.0


      parent reply	other threads:[~2026-11-16 17:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 17:57 [PATCH 0/2] media: atomisp: Fix PipeWire/Firefox streaming for sensors without crop or frame interval support Volodymyr Chapman
2026-11-16 17:57 ` [PATCH 1/2] media: atomisp: Don't enumerate frame sizes the preview pipe can't output Volodymyr Chapman
2026-11-17 10:31   ` Andy Shevchenko
2026-11-16 17:57 ` Volodymyr Chapman [this message]

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=20261116175750.21905-3-volodymyrchapman@gmail.com \
    --to=volodymyrchapman@gmail.com \
    --cc=andy@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hansg@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®