From 5481a235eda0477a83ef95fac7b9cc2bcea675ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 11 Nov 2025 21:06:17 +0100 Subject: [PATCH] examples: Make fixate examples optionally stream DMA buffers The video-play-fixate example will downgrade the stream to MemFd one modifier at a time. Sometimes it's useful to test with not downgrading; to avoid having to depend on actual DRM devices (real or virtual), fake them by using memfd and mapping them in the sink. --- src/examples/video-play-fixate.c | 21 ++++++++++++++++++++- src/examples/video-src-fixate.c | 25 +++++++++---------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/examples/video-play-fixate.c b/src/examples/video-play-fixate.c index ed250d914..3c6875a15 100644 --- a/src/examples/video-play-fixate.c +++ b/src/examples/video-play-fixate.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -22,6 +23,9 @@ #include +/* If defined, emulate failing to import DMA buffer. */ +#define EMULATE_DMA_BUF_IMPORT_FAIL 1 + #define WIDTH 640 #define HEIGHT 480 #define RATE 30 @@ -197,10 +201,12 @@ on_process(void *_data) struct pw_stream *stream = data->stream; struct pw_buffer *b; struct spa_buffer *buf; + struct spa_data *d; void *sdata, *ddata; int sstride, dstride, ostride; uint32_t i; uint8_t *src, *dst; + bool needs_unmap = false; b = NULL; /* dequeue and queue old buffers, use the last available @@ -219,11 +225,13 @@ on_process(void *_data) } buf = b->buffer; + d = buf->datas; pw_log_info("new buffer %p", buf); handle_events(data); +#ifdef EMULATE_DMA_BUF_IMPORT_FAIL if (buf->datas[0].type == SPA_DATA_DmaBuf) { // Simulate a failed import of a DmaBuf // We should try another modifier @@ -232,8 +240,17 @@ on_process(void *_data) pw_loop_signal_event(pw_main_loop_get_loop(data->loop), data->reneg); goto done; } +#endif - if ((sdata = buf->datas[0].data) == NULL) + if (buf->datas[0].type == SPA_DATA_DmaBuf) { + sdata = mmap(NULL, d[0].maxsize, PROT_READ, + MAP_SHARED, d[0].fd, d[0].mapoffset); + needs_unmap = true; + } else { + sdata = buf->datas[0].data; + } + + if (sdata == NULL) goto done; if (SDL_LockTexture(data->texture, NULL, &ddata, &dstride) < 0) { @@ -263,6 +280,8 @@ on_process(void *_data) SDL_RenderPresent(data->renderer); done: + if (needs_unmap) + munmap(d[0].data, d[0].maxsize); pw_stream_queue_buffer(stream, b); } diff --git a/src/examples/video-src-fixate.c b/src/examples/video-src-fixate.c index 53c5776c6..64eb32895 100644 --- a/src/examples/video-src-fixate.c +++ b/src/examples/video-src-fixate.c @@ -304,26 +304,19 @@ static void on_stream_add_buffer(void *_data, struct pw_buffer *buffer) #else d[0].fd = -1; #endif - d[0].data = NULL; - return; - } - - if ((d[0].type & (1<