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
This commit is contained in:
Lennox Schneider 2024-08-19 15:25:26 +02:00 committed by GitHub
parent 7f2a77ddf6
commit a08ecbbf33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View file

@ -8,6 +8,8 @@
#include <protocols/linux-dmabuf-unstable-v1-protocol.h> #include <protocols/linux-dmabuf-unstable-v1-protocol.h>
#include <unistd.h> #include <unistd.h>
constexpr static int MAX_RETRIES = 10;
// --------------- Wayland Protocol Handlers --------------- // // --------------- 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) { 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; PSESSION->sharingData.frameCallback = nullptr;
Debug::log(LOG, "[screencopy/pipewire] Out of buffers"); Debug::log(LOG, "[screencopy/pipewire] Out of buffers");
PSESSION->sharingData.status = FRAME_NONE; 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; return;
} }
zwlr_screencopy_frame_v1_copy_with_damage(frame, PSTREAM->currentPWBuffer->wlBuffer); zwlr_screencopy_frame_v1_copy_with_damage(frame, PSTREAM->currentPWBuffer->wlBuffer);
PSESSION->sharingData.copyRetries = 0;
Debug::log(TRACE, "[sc] wlr frame copied"); Debug::log(TRACE, "[sc] wlr frame copied");
} }

View file

@ -81,6 +81,7 @@ class CScreencopyPortal {
uint32_t framerate = 60; uint32_t framerate = 60;
wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL; wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
std::chrono::system_clock::time_point begunFrame = std::chrono::system_clock::now(); std::chrono::system_clock::time_point begunFrame = std::chrono::system_clock::now();
uint32_t copyRetries = 0;
struct { struct {
uint32_t w = 0, h = 0, size = 0, stride = 0, fmt = 0; uint32_t w = 0, h = 0, size = 0, stride = 0, fmt = 0;