Skip to content

vo_dmabuf_wayland: fix OSD shm pool allocation failure handling - #18684

Open
enchan087 wants to merge 2 commits into
mpv-player:masterfrom
enchan087:dmabuf-osd-pool
Open

enchan087 wants to merge 2 commits into
mpv-player:masterfrom
enchan087:dmabuf-osd-pool

Conversation

@enchan087

Copy link
Copy Markdown

If the OSD shm pool allocation in create_shm_pool() fails, osd_buffer_create() passes a NULL pool to wl_shm_pool_create_buffer(). After a resize, the old pool is kept instead, and draw_osd() writes the OSD for the new size into the smaller mapping.

  • vo_dmabuf_wayland: handle a failed OSD shm pool allocation
  • vo_dmabuf_wayland: keep the OSD shm pool if the size is unchanged: VOCTRL_SET_PANSCAN reallocated a pool of the same size.

Not compiled or tested, I have no Linux/Wayland setup. The error paths need a failing memfd, mmap or wl_shm_create_pool and were checked by reading the code.

Written with Claude Opus 5.5 in Claude Code.

If the OSD shm pool could not be allocated, osd_buffer_create() passed
a NULL pool to wl_shm_pool_create_buffer(). If a pool already existed,
the old pool and its buffers were kept, and draw_osd() copied the OSD
for the new size into the smaller mapping.

Destroy the old pool before allocating the new one, and don't create OSD
buffers without a pool. A failed allocation now leaves no OSD until a
later resize allocates the pool.

Not compiled or tested. The error paths need a failing memfd, mmap or
wl_shm_create_pool and were checked by reading the code.
Comment thread video/out/vo_dmabuf_wayland.c Outdated

if (p->osd_shm_pool && p->osd_shm_width == vo->dwidth &&
p->osd_shm_height == vo->dheight)
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check should be in resize.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your advice. I'll change it.

@CounterPillow

Copy link
Copy Markdown
Contributor

Not compiled or tested, I have no Linux/Wayland setup.

Then what motivated this PR?

@enchan087

Copy link
Copy Markdown
Author

Not compiled or tested, I have no Linux/Wayland setup.

Then what motivated this PR?

I spotted an opportunity for improvement while reading the code. I鈥檝e been using it for a long time, so I decided to contribute.
I鈥檒l complete the test soon and attach it.

resize() also runs when the window size did not change, e.g. on
VOCTRL_SET_PANSCAN. create_shm_pool() then allocated a new pool of the
same size and destroyed all OSD buffers. Keep the existing pool instead.

Not compiled or tested.
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.

3 participants