Repository navigation
media: apple: jpeg: take NV12/NV16 in one buffer, keep CAPTURE size, fix drain - #1072
Merged
Merged
Conversation
…fix drain Three problems showed up with GStreamer's v4l2jpegenc on the J616s (T6041); the same code runs on the A18 Pro (T8140). The engine prefetches its input up to AJ_INPUT_END. With NV12M/NV16M the luma and chroma planes are separate buffers, and the driver set AJ_INPUT_END to the end of whichever plane lies higher. The engine then read past the end of the lower plane into whatever followed it, and faulted on the DART whenever that was unmapped: at 640x480 and 1280x720 too, where no MCU padding is involved. It only worked when the chroma buffer happened to sit right below the luma buffer. The planes also covered whole MCU rows (1088 rows at 1080p) in sizeimage, and GStreamer places the chroma plane by those sizes, so it copied the frame to the wrong offset and crashed or hung at 1080p. Take NV12 and NV16 instead: one buffer with the visible luma rows, the chroma rows straight after them at the same stride, and the chroma rows up to the next MCU boundary at the end. AJ_INPUT_END is the end of that buffer, so every read the engine makes is inside it. The luma rows of the last MCU row read into the chroma rows, which are cropped from the JPEG. bytesperline and the chroma offset are those any client computes for NV12/NV16; only sizeimage carries the extra tail. S_FMT on OUTPUT recomputed the CAPTURE size from the new raw size. A client that sized CAPTURE first (GStreamer does, at the 1080p default) and then set 1280x720 got smaller buffers from REQBUFS than the size it had agreed, and refused them. Keep the CAPTURE size that S_FMT returned as a floor when OUTPUT changes later, and honour a larger size a client asks for on TRY/S_FMT(CAPTURE), bounded at 64 MiB. ENCODER_CMD STOP chooses the last queued source buffer, and the IRQ handler removes finished buffers, with no common lock: a job completing while STOP ran could leave the queue just after STOP chose it, and no CAPTURE buffer was ever flagged LAST. gst-launch -e at 4K, where a job takes several milliseconds, waited for EOS forever. Serialise the completion, STOP and CAPTURE QBUF on a per-context spinlock, send the EOS event also when STOP completes at once or a late CAPTURE buffer is returned as LAST, and clear the last-buffer-dequeued state on START so a second stream drains too. KUnit covers the raw layout (1080p, 720p, 480p, 4K, an odd size and 4:2:2) and the coded size floor and bound. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide
added a commit
that referenced
this pull request
Nov 7, 2026
Brings aurora-wip up to the tested release branch: CTXR execmem (#985, #1079), KFIX speaker sleep and resume fixes (#1077, #1080), JPEG v2 (#1072), Jonathan's G17 and USB work (#1073-#1076), brcmfmac flowring count (#1081), ANE H16 startup restart (#1066) and the Touch ID per-prompt match (#904). Signed-off-by: Ryan Murray <[email protected]> Assisted-by: LLM
RyanTheTide
added a commit
that referenced
this pull request
Nov 8, 2026
Take the T8112 wide64 and T6000 legacy32 layout work onto current integration. Integration already describes the T8112 and T6000 JPEG engines and their DARTs (disabled) in the per-SoC peripherals files, and its binding already covers both compatibles with the apple,jpeg fallback, so keep integrations binding and DT files and drop the branchs duplicate nodes. Keep the single-buffer NV12/NV16 wording from #1072. Signed-off-by: Ryan Murray <[email protected]> Assisted-by: LLM
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.
What
GStreamer's
v4l2jpegencon the J616s (T6041) failed in three ways with the merged driver. This fixes all three indrivers/media/platform/apple/jpeg/. The same code runs on the Neo (T8140).AJ_INPUT_END. With NV12M/NV16M the luma and chroma planes were separate buffers. The driver setAJ_INPUT_ENDto the end of whichever plane was higher, so the engine read past the end of the lower plane and faulted whenever the next page was unmapped. That happened at 640x480 and 1280x720 too, where no MCU padding is involved. It only worked when chroma happened to sit right below luma. At 1080p the planes were also sized in whole MCU rows (1088), and GStreamer places chroma using those sizes.The fix takes NV12/NV16 instead: one buffer holding the visible luma rows, the chroma rows right after them at the same stride, and the chroma rows up to the next MCU boundary at the end.
AJ_INPUT_ENDis the end of the negotiated surface, so every read stays inside the buffer.gst-launch -e). ENCODER_CMD STOP and the IRQ completion raced with no common lock, so no CAPTURE buffer ever got LAST. Completion, STOP and CAPTURE QBUF now share a per-context spinlock. EOS is also sent when STOP completes at once or a late CAPTURE buffer is returned as LAST, and START clears the last-buffer-dequeued state.A Daybreak review (t-5381) checked the design against the clean-room contract.
AJ_INPUT_ENDis a single global input bound, and the proven encode layout is one allocation with chroma at an offset, so NV12M/NV16M cannot be made safe.Hardware evidence (J616s, 7.3.0-aurora-fleet17 with this module, one-shot aura-try Stage 2 with the JPEG nodes enabled)
gst-launch -eEOSBefore this change: 1080p hit a DART read fault (
job failed: status 0x40), 720p and 480p were refused by GStreamer (buffer size 2785280 is smaller then negotiated size 6242304), and 4K with-etimed out at EOS.After it, with both engines: 0 DART faults and 0 failed jobs. Throughput at q75 is 207 fps at 4K (bound by
videotestsrc, which manages 199 fps on its own), 774 fps at 1080p and 1589 fps at 720p. The CPUjpegencmanages 98 fps at 4K. SELinux was enforcing with 0 AVCs.Checks
checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks.drivers/media/platform/apple/jpeg0 warnings before and after.apple_jpeg_raw_layout_test(1080p, 720p, 480p, 4K, an odd size, 4:2:2) andapple_jpeg_coded_size_test.Neo (T8140), 7.3.0-aurora-fleet18ctxr with this module, no reboot: 3840x2160, 1920x1080, 1280x720 and 640x480 each encoded 8/8. PSNR averages were 41.6, 43.4, 43.3 and 41.6 dB, and
gst-launch -ereached EOS 3 times out of 3 at every size. Throughput was 188 fps at 4K and 623 fps at 1080p. There were 0 JPEG or DART faults, no error-level log lines, and SELinux was enforcing with 0 AVCs.🤖 Generated with Claude Code