From 35cba5040900c0dd279c4844dcc6558eb3aa5303 Mon Sep 17 00:00:00 2001 From: columbarius Date: Wed, 3 Nov 2021 22:37:56 +0100 Subject: [PATCH] screencast: drop imported PipeWire buffer on remove_buffer PipeWire can request to destroy the allocated buffers anytime. This isn't a problem for us, since the screencopy protocol can handle disappearing buffers. The only thing we have to do is not to use a destroyed buffer. --- src/screencast/pipewire_screencast.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/screencast/pipewire_screencast.c b/src/screencast/pipewire_screencast.c index b82a810..7da0370 100644 --- a/src/screencast/pipewire_screencast.c +++ b/src/screencast/pipewire_screencast.c @@ -150,9 +150,16 @@ static void pwr_handle_stream_add_buffer(void *data, struct pw_buffer *buffer) { } static void pwr_handle_stream_remove_buffer(void *data, struct pw_buffer *buffer) { + struct xdpw_screencast_instance *cast = data; + logprint(TRACE, "pipewire: remove buffer event handle"); struct spa_data *d = buffer->buffer->datas; + if (cast->current_frame.current_pw_buffer == buffer) { + logprint(TRACE, "pipewire: remove buffer currently in use"); + cast->current_frame.current_pw_buffer = NULL; + cast->current_frame.buffer = NULL; + } switch (d[0].type) { case SPA_DATA_MemFd: wl_buffer_destroy(buffer->user_data);