Skip to content

fix(sensors): make camera capture robust against missing frames - #126

Open
Ed-web-d wants to merge 1 commit into
FedeDP:masterfrom
Ed-web-d:fix/camera-capture-timeout
Open

Ed-web-d wants to merge 1 commit into
FedeDP:masterfrom
Ed-web-d:fix/camera-capture-timeout

Conversation

@Ed-web-d

Copy link
Copy Markdown

Summary

Make camera capture fail instead of blocking clightd forever when a camera
stops delivering frames.

Root cause

recv_frame() calls VIDIOC_DQBUF directly. If the device never produces a
buffer, the ioctl blocks indefinitely and the whole clightd event loop is
stuck; Sensor.Capture never returns.

This is reproducible with a facetimehd camera whose firmware is stuck in
IO: timeout, but any misbehaving UVC camera can trigger it.

Reproduction

busctl --system call org.clightd.clightd /org/clightd/clightd/Sensor \
  org.clightd.clightd.Sensor Capture "sis" "video0" 1 ""

Before: hangs until clightd is killed.
After: returns within 1s (capture failure), daemon stays responsive.

Changes

  • poll() the video fd with a 1s timeout before VIDIOC_DQBUF.
  • Stop the capture loop when a frame is not received.
  • Guard the histogram code against NULL/zero-sized decoded frames.

Testing

Built and exercised on Fedora 45 / MacBookPro12,1 with both facetimehd and
a 1080P USB camera. Normal cameras still capture 5/5 frames.

VIDIOC_DQBUF is blocking; a camera that stops delivering frames (e.g.
facetimehd firmware stuck in IO timeout) blocks clightd forever.  Poll
the device with a 1s timeout, stop the capture loop on failure, and
validate the decoded frame before running the histogram code.

This turns a permanent daemon hang into a failed capture.
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.

1 participant