From cb890d1bd501068a63b1a9a7ab3ae468f851cf9e Mon Sep 17 00:00:00 2001 From: columbarius Date: Sun, 13 Jun 2021 18:22:10 +0200 Subject: [PATCH] screencast: use refcounting to restart wlroots loop after reneg this complements the previous commit, which won't restart the wlroots loop after renegotiation. Restarting the stream on the first new add_buffer call works, but maybe we can find a nicer solution here. --- include/screencast_common.h | 1 + src/screencast/pipewire_screencast.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/screencast_common.h b/include/screencast_common.h index c0265ada..6aca0b1d 100644 --- a/include/screencast_common.h +++ b/include/screencast_common.h @@ -92,6 +92,7 @@ struct xdpw_screencast_instance { uint32_t node_id; bool pwr_stream_state; struct pw_buffer *current_pw_buffer; + int buffer_refcount; // wlroots struct zwlr_screencopy_frame_v1 *frame_callback; diff --git a/src/screencast/pipewire_screencast.c b/src/screencast/pipewire_screencast.c index 67e05c7b..7c6bdeaa 100644 --- a/src/screencast/pipewire_screencast.c +++ b/src/screencast/pipewire_screencast.c @@ -72,7 +72,7 @@ static void pwr_handle_stream_state_changed(void *data, switch (state) { case PW_STREAM_STATE_STREAMING: cast->pwr_stream_state = true; - xdpw_wlr_frame_start(cast); + xdpw_wlr_register_cb(cast); break; default: cast->pwr_stream_state = false; @@ -156,6 +156,12 @@ static void pwr_handle_stream_add_buffer(void *data, struct pw_buffer *buffer) { // create wl_buffer d[0].data = import_shm_buffer(cast, d[0].fd, cast->simple_frame.format, cast->simple_frame.width, cast->simple_frame.height, cast->simple_frame.stride); + + cast->buffer_refcount++; + } + // TODO: start stream again after renegotiation + if (cast->pwr_stream_state && cast->buffer_refcount == 1) { + xdpw_wlr_frame_start(cast); } }