Repository navigation
Conversation
A UVC camera's MJPEG frames are full-range JPEG, but neither dshow nor v4l2 declare a range for them, and the camera input never read one: the frames reached the conversion as unspecified, which the BT.601/709 path reads as limited, stretching every code by 255/219. On the CAVE's C930e, JPEG black came out at -0.073 and everything above code 235 over 1.0. The renderer now resolves the range from what the source declares, else the decoded frame's own range, else full range for the YUVJ formats. This applies to every live source that declares no range: cameras, network streams (LibavStreamInput) and gphoto2 (YUVJ422P), which now show full-range frames as full range. The file decoder defaults an unspecified MJPEG or YUVJ stream to full range instead of limited; files that declare a range are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KdPgufk1W2MBbpcjraruZq
…it captures The camera thread stopped reading once its queue held 4 frames. The renderer always takes the newest one, so the queue only fills when renders come slower than camera frames, and then the device kept capturing into its own buffer (dshow's real-time buffer) while nothing read it: the latency grew to a second and more and never came back down. On the CAVE, Structured Light Calibration reads the camera back every frame and a C930e at 30 fps went several patterns late, so nothing decoded at 1/32 s while 1/8 s (8 fps) worked. The thread now always reads, and drops the oldest queued frame when the queue is full (FrameQueue::enqueue_latest). A camera nobody reads (its queue full and nothing taken for a second of frames) still drains the device, but for intra-only codecs (MJPEG, raw video) it drops the packets without decoding them, as the old code did by not reading at all. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KdPgufk1W2MBbpcjraruZq
…p to its newest frame Follow-up to the two camera commits. Colour. A decoded MJPEG frame says full range and BT.601 (JFIF), and libavcodec tags it so (yuvj4xxp, pc, bt470bg). Only the range was read from the frame; the matrix stayed unspecified and fell back to the size-based guess, BT.709 from 1280 wide, so an HD MJPEG camera was converted with the wrong matrix. The range, matrix, transfer and primaries an input does not declare are now all completed from the frame, and a YUVJ format with no matrix anywhere is BT.601. Inputs that only tag their frames (AJA staging path of the videoio add-on, the depth-camera add-on's MJPEG colour stream) get their description too. Latency. Reading one packet per iteration keeps up only while decoding is faster than the camera; past that the backlog sits in the driver (v4l2 queues up to 32 buffers, dshow its rtbufsize) and the latency stays. For intra-only codecs the thread now reads up to the newest buffered packet and decodes that one. Devices that block instead of answering EAGAIN end the backlog by the time the read took. An idle consumer is now one that stopped asking for frames, rather than one that stopped getting them, so the queue can be emptied when it goes idle: a consumer that comes back gets the next captured frame instead of the one queued when it left. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KdPguixxwrpgc8UWhoHDeQ
This branch is waiting to be deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two camera input bugs, both found while calibrating with a Logitech C930e on the CAVE.
The drivers do not help. V4L2/uvcvideo never sets a quantization, and V4L2's default rule then says limited for YUV unless the colorspace is
V4L2_COLORSPACE_JPEG, which uvcvideo does not report. dshow reports a range only when the driver fills its colour info, and FFmpeg's v4l2 and avfoundation inputs report nothing. FFmpeg's MJPEG decoder tags every frame asyuvj4xxp,pc,bt470bg(or limited for streams carryingCS=ITU601), so the decoded frame is the reliable source. This is the same bug as crbug 40144925; Chromium's Media Foundation path makes the same call ("0..255 range NV12 is usually just an unpacked MJPG").The renderer now completes what a source does not declare from the decoded frame: range, matrix, transfer and primaries. With nothing anywhere, YUVJ formats are full range and BT.601. This applies to every live source that declares nothing: cameras, network streams (
LibavStreamInput), gphoto2 (YUVJ422P), the depth-camera add-on's MJPEG colour stream and the AJA CPU path of the videoio add-on (whose BT.2020/PQ/HLG tagging was lost). The file decoder now defaults an unspecified MJPEG or YUVJ stream to full range. Sources that declare their colour are unchanged.The thread now always reads, and drops the oldest queued frame when the queue is full (
FrameQueue::enqueue_latest). For intra-only codecs (MJPEG, raw video) it reads up to the newest buffered packet and decodes only that one (readNewestPacket), so a decoder slower than the camera (4K MJPEG decodes single-threaded in live mode) no longer leaves a backlog in the driver. Devices that block instead of answering EAGAIN are detected by how long the read took.A consumer is idle once it stops asking for frames. The queue is then emptied, and intra-only packets are read without decoding. A consumer that comes back gets the next captured frame, not the ones queued when it left (before this, it got a frame about 4 s old after a 5 s pause).
Commits
1376c8259cvideo: MJPEG from a camera is decoded as full rangebb8fd88defvideo: a camera keeps reading frames while score renders slower than it captures5a27bcdc3cvideo: MJPEG frames are converted with BT.601, and a camera is read up to its newest frameTests
VideoRebuildTest(inscore-plugin-gfx/tests) checkseffectiveColorRangeandeffectiveColorSpace: an HD MJPEG frame is converted with full-range BT.601, a frame's own description is used when the source declares nothing (including HDR transfer and primaries), a declared description wins, and plain YUV with nothing anywhere keeps the size-based guess.test_unit_video_frame_queuecoversenqueue_latest, the poll count,discard_queued, idle detection, andreadNewestPacketagainst a fake device (backlog drained to the newest packet, other streams skipped, waiting then giving up, blocking devices, the backlog cap).CameraInput): frames arrive taggedyuvj420p pc bt470bg, steady and 5 Hz consumers stay at the live frame, and after 5 s without a consumer the next frame is live. With only the first two commits, the same run returns a frame 98 frames old.ctest -R "VideoRebuildTest|video|camera|gpu_formats|decoder|media": everything passes excepttest_integration_pipewire_video_output, which fails the same way without these commits.Related add-on PRs
Not tested
Notes for review
🤖 Generated with Claude Code
https://claude.ai/code/session_01KdPguixxwrpgc8UWhoHDeQ