Skip to content

stream: recycle decoded MJPEG frames, lay out padded and YV12 planes - #14

Open
jcelerier wants to merge 1 commit into
masterfrom
fix/mjpeg-frame-recycling
Open

jcelerier wants to merge 1 commit into
masterfrom
fix/mjpeg-frame-recycling

Conversation

@jcelerier

Copy link
Copy Markdown
Member

Three bugs in how the host turns backend frames into AVFrames.

  • Decoded MJPEG frames were never recycled. decodeCompressed allocated a fresh frame per compressed colour frame. Consumers hand frames back to the queue's released list, which only newFrame() pops, and the decode path never called it, so every frame stayed allocated until the stream closed. MJPEG is the default colour format on Orbbec and Azure Kinect. Decoding now takes its frame from the queue.
  • Padded rows broke planar layouts. The backend's row stride was written to plane 0 only, after the planes had been laid out tightly, so I420/NV12 frames with padded rows read chroma from the wrong offsets. The planes are now laid out from the stride, with chroma rows scaling with the luma row as in I420 and NV12. A stride the buffer cannot hold drops the frame instead of reading past it.
  • Orbbec YV12 had U and V swapped. It was reported as DEPTHCAM_FMT_YUV420P. It now has its own DEPTHCAM_FMT_YV12, appended to the ABI enum, and the host exchanges the chroma planes. A host that predates it drops these frames; the ABI version is unchanged since no struct changed.

The synthetic backend gains inject() so tests can feed the host layouts the scene does not produce.

Related: ossia/score#2417. With it, the decoded MJPEG colour stream is converted as full-range BT.601. Before that change it was full range but used the BT.709 matrix at 1280 wide and above, so an Azure Kinect's colour stream always got the wrong matrix.

Tests

  • score_addon_orbbec_unit_test gains three cases: decoded MJPEG frames are reused (at most 2 distinct frames over 10 decodes) and tagged full range; YV12 planes come out in U, V order; padded I420 lays out every plane, and an impossible stride is refused.
  • Negative control: with the old DepthCameraStream.cpp/.hpp, all three cases fail (7 assertions).
  • ctest -R orbbec: unit, settings, gfx and device tests pass. Built on Linux with clang 23, lld 23, Qt 6.12 (Debug, shared plug-ins) against the score branch of #2417.
  • OrbbecBackend.cpp was syntax-checked against the OrbbecSDK_v2 headers; the backends were not built.

Not tested

  • No depth camera on the build machine.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KdPguixxwrpgc8UWhoHDeQ

Decoded frames were allocated with av_frame_alloc for every compressed
colour frame. The consumer hands frames back to the queue's released
list, which only newFrame() pops, and the decode path never called it,
so every MJPEG frame (the default colour format on Orbbec and Azure
Kinect) stayed allocated until the stream closed. Decoding now takes its
frame from the queue.

A backend row stride was applied to plane 0 only, after the planes had
been laid out tightly, so a planar or semi-planar frame with padded rows
had its chroma planes read from the wrong offsets. The planes are now
laid out from the stride, chroma rows scaling with the luma row as in
I420 and NV12, and a stride the buffer cannot hold drops the frame.

Orbbec YV12 was reported as YUV420P, with U and V swapped. It now has
its own format, DEPTHCAM_FMT_YV12, appended to the ABI enum, which the
host lays out with the chroma planes exchanged. A host that predates it
drops these frames.

The synthetic backend gains inject(), so tests can hand the host frame
layouts the scene does not produce.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPguixxwrpgc8UWhoHDeQ
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