PipeWire video capture: mmap() PipeWire buffers with MAP_SHARED

Some DMAbuf types don't properly implement MAP_PRIVATE as it requires
copy-on-write support. As we don't need to write to these buffers, we
can switch to MAP_SHARED instead, making it work reliably on current
kernels without having any drawbacks in this context.

Tested and confirmed with libcamera software ISP on Thinkpad X13 with
an arm processor.

Bug: webrtc:42225999
Change-Id: Ic47b8c90456cccf3742e8274945dbd64fb8aac6d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/354623
Commit-Queue: Jan Grulich <grulja@gmail.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42484}
This commit is contained in:
Jan Grulich 2024-06-14 07:59:09 +02:00 committed by WebRTC LUCI CQ
parent f13a0e9ec5
commit 025d69b4d0

View File

@ -418,7 +418,7 @@ void VideoCaptureModulePipeWire::ProcessBuffers() {
ScopedBuf frame; ScopedBuf frame;
frame.initialize( frame.initialize(
static_cast<uint8_t*>( static_cast<uint8_t*>(
mmap(nullptr, spaBuffer->datas[0].maxsize, PROT_READ, MAP_PRIVATE, mmap(nullptr, spaBuffer->datas[0].maxsize, PROT_READ, MAP_SHARED,
spaBuffer->datas[0].fd, spaBuffer->datas[0].mapoffset)), spaBuffer->datas[0].fd, spaBuffer->datas[0].mapoffset)),
spaBuffer->datas[0].maxsize, spaBuffer->datas[0].fd, spaBuffer->datas[0].maxsize, spaBuffer->datas[0].fd,
spaBuffer->datas[0].type == SPA_DATA_DmaBuf); spaBuffer->datas[0].type == SPA_DATA_DmaBuf);