From a08ecbbf33598924e93542f737fc6169a26b481e Mon Sep 17 00:00:00 2001 From: Lennox Schneider Date: Mon, 19 Aug 2024 15:25:26 +0200 Subject: [PATCH] screencopy: attempt retry when pw doesn't return buffers (#249) * portals: fix output screencopy not capturing after error * portals: limit amount of retries for screencopy * portals: change max retries count --- src/portals/Screencopy.cpp | 8 ++++++++ src/portals/Screencopy.hpp | 1 + 2 files changed, 9 insertions(+) diff --git a/src/portals/Screencopy.cpp b/src/portals/Screencopy.cpp index e9fe867..24d1443 100644 --- a/src/portals/Screencopy.cpp +++ b/src/portals/Screencopy.cpp @@ -8,6 +8,8 @@ #include #include +constexpr static int MAX_RETRIES = 10; + // --------------- Wayland Protocol Handlers --------------- // static void wlrOnBuffer(void* data, zwlr_screencopy_frame_v1* frame, uint32_t format, uint32_t width, uint32_t height, uint32_t stride) { @@ -128,10 +130,16 @@ static void wlrOnBufferDone(void* data, zwlr_screencopy_frame_v1* frame) { PSESSION->sharingData.frameCallback = nullptr; Debug::log(LOG, "[screencopy/pipewire] Out of buffers"); PSESSION->sharingData.status = FRAME_NONE; + if (PSESSION->sharingData.copyRetries++ < MAX_RETRIES) { + Debug::log(LOG, "[sc] Retrying screencopy ({}/{})", PSESSION->sharingData.copyRetries, MAX_RETRIES); + g_pPortalManager->m_sPortals.screencopy->m_pPipewire->updateStreamParam(PSTREAM); + g_pPortalManager->m_sPortals.screencopy->queueNextShareFrame(PSESSION); + } return; } zwlr_screencopy_frame_v1_copy_with_damage(frame, PSTREAM->currentPWBuffer->wlBuffer); + PSESSION->sharingData.copyRetries = 0; Debug::log(TRACE, "[sc] wlr frame copied"); } diff --git a/src/portals/Screencopy.hpp b/src/portals/Screencopy.hpp index 1396ecb..b2fc874 100644 --- a/src/portals/Screencopy.hpp +++ b/src/portals/Screencopy.hpp @@ -81,6 +81,7 @@ class CScreencopyPortal { uint32_t framerate = 60; wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL; std::chrono::system_clock::time_point begunFrame = std::chrono::system_clock::now(); + uint32_t copyRetries = 0; struct { uint32_t w = 0, h = 0, size = 0, stride = 0, fmt = 0;