Description
Problem
On Hyprland with xdg-desktop-portal-hyprland, PipeWire screen capture (rs/moq-video/src/capture/pipewire.rs) negotiates a DMA-BUF format and then delivers no frame, ever. The log repeats for every buffer:
WARN moq_video::capture::pipewire: DMA-BUF chunk does not contain a complete frame required=33177600 available=9
required is one 4K BGRx frame (3840 × 2160 × 4); available is the chunk size the portal reported.
Hyprland's portal does not know a DMA-BUF's byte size. It leaves maxsize at 0 and writes a placeholder chunk size on purpose (src/portals/Screencopy.cpp on master, around line 1205):
spaData[plane].maxsize = PBUFFER->size[plane];
spaData[plane].chunk->size = PBUFFER->size[plane];
...
// clients have implemented to check chunk->size if the buffer is valid instead
// of using the flags. Until they are patched we should use some arbitrary value.
if (PBUFFER->isDMABUF && spaData[plane].chunk->size == 0) {
spaData[plane].chunk->size = 9; // This was choosen by a fair d20.
}https://github.com/hyprwm/xdg-desktop-portal-hyprland/blob/master/src/portals/Screencopy.cpp
It marks a bad frame with SPA_CHUNK_FLAG_CORRUPTED instead. The process callback requires chunk.size >= frame size for every DMA-BUF (dma_buf_chunk_contains), accepting only a chunk size of exactly 0, so 9 bytes against a 33 MB frame rejects every frame.
The chunk size is not what the frame is read with. The GPU import and the CPU download go by the layout, the chunk offset, and the fd's own allocation size (dma_buf_allocation_size, SEEK_END), which the callback already checks right after this test. So for DMA-BUF the chunk-size bound is redundant, and wrong for this producer.
Seen on moq-video 0.1.21; pipewire.rs is byte-identical in 0.1.22 and 0.1.23.
Approach
Treat the chunk size as advisory for DMA-BUF. dma_buf_chunk_contains(required, size, maxsize) becomes dma_buf_maxsize_contains(required, maxsize): a frame is rejected at that point only when the producer states a nonzero maxsize and the frame does not fit in it. The CORRUPTED/EMPTY flag handling (chunk_kind) before it and the allocation-size check after it are unchanged. The warning names the bound that failed.
Two unit tests beside the existing ones: Hyprland's shape (size 9, maxsize 0, required 33177600) is accepted and a CORRUPTED chunk is still rejected; a stated maxsize smaller than the frame still rejects it.
With this change a Hyprland user shares a 4K display to a Mac over moq with no other change. Tests pass on Linux with --features pipewire against PipeWire 1.6.11.
Impact
- No public API or wire change.
- Behavior: a DMA-BUF whose chunk size is smaller than the frame is no longer dropped when
maxsizeis 0. Shared-memory buffers are unaffected.
Alternatives
- Offer only MemFd/MemPtr formats so the compositor copies into shared memory. Works on Hyprland, but gives up zero-copy for every Wayland producer to work around one.
- Keep the chunk-size bound and special-case 9. Fragile; the portal's comment says the value is arbitrary.
- When the allocation-size query fails and
maxsizeis 0, nothing bounds the frame before the GPU import. That is the same as the existing behavior for a chunk size of 0, so it is left as is.
Follow-ups
- The
pipewire.rstest module does not compile against PipeWire 1.0.9 headers: it referencesSPA_VIDEO_TRANSFER_SMPTE2084, which they lack. The library builds there. Minor, separate.
Patch
Diff against 0.1.21, for the issue form:
diff --git a/rs/moq-video/src/capture/pipewire.rs b/rs/moq-video/src/capture/pipewire.rs
--- a/rs/moq-video/src/capture/pipewire.rs
+++ b/rs/moq-video/src/capture/pipewire.rs
@@ -1056,11 +1056,14 @@ fn run_loop(args: CaptureLoop) -> Result<(), Error> {
return;
};
let offset = normalize_dma_buf_offset(chunk_offset, maxsize);
- if !dma_buf_chunk_contains(required, chunk_size, maxsize) {
+ // The chunk size is advisory for a DMA-BUF; only a
+ // stated maxsize bounds the frame here. The allocation check
+ // below is the real one.
+ if !dma_buf_maxsize_contains(required, maxsize) {
tracing::warn!(
required,
- available = size,
- "DMA-BUF chunk does not contain a complete frame"
+ maxsize,
+ "DMA-BUF frame is larger than the buffer's stated maxsize"
);
return;
}
@@ -1264,8 +1267,15 @@ fn dma_buf_chunk_size(size: u32, maxsize: u32) -> usize {
}
}
-fn dma_buf_chunk_contains(required: usize, size: u32, maxsize: u32) -> bool {
- size == 0 || required <= dma_buf_chunk_size(size, maxsize)
+// Was `dma_buf_chunk_contains(required, size, maxsize)`, which
+// rejected a frame whenever the chunk size was smaller than it. A producer
+// cannot always know a DMA-BUF's byte size: xdg-desktop-portal-hyprland leaves
+// maxsize 0 and writes a placeholder 9 as the chunk size, so every frame was
+// dropped. The size is not used to read the frame (the layout and the fd's own
+// allocation size are), so only a nonzero maxsize, the producer's stated
+// allocation, bounds it here. Bad frames are flagged CORRUPTED (`chunk_kind`).
+fn dma_buf_maxsize_contains(required: usize, maxsize: u32) -> bool {
+ maxsize == 0 || required <= maxsize as usize
}
fn chunk_bytes(data: &[u8], offset: usize, size: usize) -> Option<Cow<'_, [u8]>> {
@@ -1792,9 +1802,35 @@ mod tests {
assert_eq!(clamp_chunk_size(8, 16), 8);
assert_eq!(dma_buf_chunk_size(8, 16), 8);
assert_eq!(dma_buf_chunk_size(8, 0), 8);
- assert!(dma_buf_chunk_contains(16, 0, 0));
- assert!(!dma_buf_chunk_contains(16, 8, 0));
- assert!(dma_buf_chunk_contains(16, 16, 16));
+ // The chunk size no longer bounds a DMA-BUF frame.
+ assert!(dma_buf_maxsize_contains(16, 0));
+ assert!(dma_buf_maxsize_contains(16, 16));
+ }
+
+ // xdg-desktop-portal-hyprland's shape for a 4K BGRx frame.
+ #[test]
+ fn dma_buf_placeholder_chunk_size_is_accepted() {
+ let required = 3840 * 2160 * 4;
+ assert_eq!(required, 33_177_600);
+ assert_eq!(dma_buf_chunk_size(9, 0), 9);
+ assert!(dma_buf_maxsize_contains(required, 0));
+ assert_eq!(
+ chunk_kind(dma_buf_chunk_size(9, 0), spa::buffer::ChunkFlags::empty(), true),
+ ChunkKind::Data
+ );
+ // A bad frame is flagged, which still rejects it.
+ assert_eq!(
+ chunk_kind(9, spa::buffer::ChunkFlags::CORRUPTED, true),
+ ChunkKind::Invalid
+ );
+ }
+
+ // A stated maxsize still bounds the frame.
+ #[test]
+ fn dma_buf_frame_larger_than_maxsize_is_rejected() {
+ assert!(!dma_buf_maxsize_contains(17, 16));
+ assert!(!dma_buf_maxsize_contains(33_177_600, 33_177_599));
+ assert!(dma_buf_maxsize_contains(33_177_600, 33_177_600));
}
#[test]
Activity
kixelated commentedon Nov 12, 2026
Thanks for the clear diagnosis and patch. We've planned the fix as
quest/m1/pipewire-dmabuf-chunk.md(planned in #8582).One change from your patch: we're dropping the chunk-size bound outright rather than swapping in a
maxsizecheck. The chunk size never reads a DMA-BUF, and the allocation-size check right after it (offset + required <= allocation) already bounds the frame, including the offset that amaxsize-only check ignores. The quest also definesSPA_VIDEO_TRANSFER_SMPTE2084locally so the tests build against PipeWire 1.0.x headers, the way #3387 did for the library. This issue closes when that PR lands.Anyone who wants to donate tokens can run
/quest-start quest/m1/pipewire-dmabuf-chunk.(Written by Opus 5.5)
quest: import moq-dev#8571, moq-dev#8577, and moq-dev#8559 (moq-dev#8582