Skip to content

v4l2: apply the control values userspace set before STREAMON - #329

Merged
patjak merged 1 commit into
patjak:masterfrom
vrilutza:controls-at-streamon-and-width-align
Sep 4, 2026
Merged

v4l2: apply the control values userspace set before STREAMON#329
patjak merged 1 commit into
patjak:masterfrom
vrilutza:controls-at-streamon-and-width-align

Conversation

@vrilutza

@vrilutza vrilutza commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

fthd_start_channel() forces brightness and contrast to 0x80, so every VIDIOC_STREAMON throws away whatever the application had set. VIDIOC_G_CTRL keeps reporting the value that was asked for, which is what makes it hard to see: the control reads back correctly while the ISP runs with the default.

Drop the two hardcoded commands and call v4l2_ctrl_handler_setup() once the channel is up. That covers saturation, hue and auto white balance too, which had the same problem.

Measured on a MacBookPro14,1 against a module built from clean master. One open(), four frames from the same file descriptor, 20 frames dropped between each so the exposure settles. Mean luma of the Y plane at 640x360:

brightness      set when           master r1   master r2   patched
40              before STREAMON        37.38       34.36      0.02
210             while streaming       119.36      116.77    116.37
40              while streaming         0.01        0.01      0.01
128 (default)   while streaming        37.46       33.61     34.29

Before the change, brightness 40 set before STREAMON gives the same picture as the default — not as 40. The third row is the negative control taken in the same run: the setting does work, it is only the pre-STREAMON value that is lost. The two master columns are the same module measured twice, interleaved with the patched one; absolute values move with the ambient light, the relation does not.

After the change, the first row matches the third rather than the fourth.


The series

Seven PRs on this driver, all on master (364b1c6), all found while debugging a camera problem on a MacBookPro14,1:

#328 two small cleanups: missing break, hardcoded buffer count
#329 (this one) control values discarded at every VIDIOC_STREAMON
#330 cmd.y1 never assigned in the crop command — one line
#331 ALIGN(width, 7) aligns nothing; second commit re-does 545cb18 and should wait
#332 one firmware timeout leaves the driver with no usable buffers
#333 the camera writes in front of any buffer that is not page aligned
#334 the auto-exposure wait: 1000 ms → 200 ms

They can be taken in any order, with one exception: the second commit of #331 should not be taken yet — reasons in that PR.

(Until 23 August there was a second exception: #328 and #334 both carried the same mdelaymsleep commit, so whichever merged first made the other conflict. I have dropped it from #328; it lives in #334. The seven are now independent of each other.)

There is one more patch not sent yet: the channel-start crop returns the top left corner of the frame at any size below the sensor. It is measured and ready, and it sits on top of #330. I am holding it back rather than adding an eighth PR to the pile.

@vrilutza
vrilutza force-pushed the controls-at-streamon-and-width-align branch from a9457b3 to 4b7d5e3 Compare August 22, 2026 08:53
vrilutza added a commit to vrilutza/facetimehd that referenced this pull request Aug 22, 2026
VIDIOC_ENUM_FRAMESIZES advertises a single discrete size while
fthd_v4l2_adjust_format() clamps to FTHD_MIN_WIDTH/HEIGHT at the bottom and to
the detected sensor size at the top, with the scaler covering everything
between. VIDIOC_ENUM_FRAMEINTERVALS already accepts any width that is a
multiple of eight up to the maximum, so the enumeration is the only place
claiming the device does one size and nothing else.

Applications that pick a resolution from the enumeration therefore never offer
anything below the sensor's native size, even though the hardware scales down.
In issue patjak#52 the reporter had to hand-edit Skype's shared.xml to force 640x480
and then 320x240 before the camera would work at all, and issue patjak#243 is a user
asking why the enumeration shows one size; neither needed a driver change to
capture at the smaller sizes, only a way to find out they exist.

Report a stepwise range matching what adjust_format() does, keeping the sensor
detection from 98b55fd as the upper bound: FTHD_MIN_WIDTH to the sensor width
in steps of 8, FTHD_MIN_HEIGHT to the sensor height in steps of 1.

The horizontal step of 8 is the constraint enum_frameintervals() has always
enforced. Nothing enforces one vertically, and heights of 241, 245 and 481 were
verified to capture correctly, so the vertical step is 1.

Tested on a MacBookPro14,1, where CISP_CMD_CH_CAMERA_CONFIG_GET reports a
1296x736 sensor, so the upper bound comes from the detection rather than from
FTHD_MAX_WIDTH/HEIGHT:

	[0]: 'YUYV' (YUYV 4:2:2)
		Size: Stepwise 320x240 - 1296x736 with step 8/1

and it takes v4l2-compliance 1.32.0 from "test Scaling: FAIL" to
"test Scaling: OK".

Depends on "v4l2: align the width to 8, not to 7" (patjak#329); without it the driver
would advertise a step of 8 that adjust_format() does not honour.

It should also not go in ahead of "isp: crop a centred window with the aspect
ratio of the output" (patjak#330). Until that one is in, fthd_start_channel() asks the ISP
for a crop window the size of the output placed at the sensor origin, so every
size below the sensor comes back as the top left corner of the frame.
Advertising the range first would hand applications exactly the resolutions that
are framed wrong.

Signed-off-by: Viorel Cernateanu <vrilutza@gmail.com>
(cherry picked from commit 9992af1)
@vrilutza vrilutza changed the title Two user-visible fixes: controls discarded at every STREAMON, width aligned to 7 v4l2: apply the control values userspace set before STREAMON Aug 22, 2026
@vrilutza
vrilutza force-pushed the controls-at-streamon-and-width-align branch 2 times, most recently from d66f0ca to 30f3ac7 Compare August 22, 2026 10:00
@vrilutza
vrilutza force-pushed the controls-at-streamon-and-width-align branch from 30f3ac7 to 8d14425 Compare August 23, 2026 15:43
Comment thread fthd_isp.c Outdated
* away whatever userspace had set through VIDIOC_S_CTRL. The control
* values are pushed to the ISP from fthd_start_streaming() instead,
* once the channel is up.
*/

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to explain what the code used to do here. Just removing the brightness and contrast commands is enough.

fthd_start_channel() programmed brightness and contrast to 0x80
unconditionally, so every VIDIOC_STREAMON discarded whatever userspace
had configured. VIDIOC_G_CTRL kept reporting the requested value,
because the control framework caches it, so the control read back
correctly while the ISP ran with the default.

Drop the two hardcoded commands and call v4l2_ctrl_handler_setup() once
the channel is up. That covers saturation, hue and auto white balance
too, which had the same problem.

Measured on a MacBookPro14,1 at 640x360, mean luma of a frame taken with
brightness set to 40 before STREAMON, against the same value set while
streaming and against the default of 128:

	                       clean master   with this patch
	set before STREAMON       37.38            0.02
	set while streaming        0.01            0.01
	default, 128              37.46           34.29

On master the pre-STREAMON frame matches the default rather than the
value it asked for: the setting was discarded. With the patch it matches
the value set while streaming, which is the negative control taken in
the same run.

Signed-off-by: Viorel Cernateanu <vrilutza@gmail.com>
@vrilutza
vrilutza force-pushed the controls-at-streamon-and-width-align branch from 8d14425 to 78e72b4 Compare September 3, 2026 11:51
@patjak
patjak merged commit 70d06fb into patjak:master Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants