Skip to content

Commit

Permalink
screencopy: attempt retry when pw doesn't return buffers (#249)
Browse files Browse the repository at this point in the history
* portals: fix output screencopy not capturing after error

* portals: limit amount of retries for screencopy

* portals: change max retries count
  • Loading branch information
lennoxlotl authored Aug 19, 2024
1 parent 7f2a77d commit a08ecbb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/portals/Screencopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <protocols/linux-dmabuf-unstable-v1-protocol.h>
#include <unistd.h>

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) {
Expand Down Expand Up @@ -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");
}
Expand Down
1 change: 1 addition & 0 deletions src/portals/Screencopy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a08ecbb

Please sign in to comment.