screencast: remove frame callbacks on every stream state change

This commit is contained in:
Vaxry 2024-01-25 01:23:05 +00:00
parent 4fc83e6871
commit 5a59264758
2 changed files with 27 additions and 14 deletions

View file

@ -730,6 +730,20 @@ CPipewireConnection::CPipewireConnection() {
Debug::log(LOG, "[pipewire] connected"); Debug::log(LOG, "[pipewire] connected");
} }
void CPipewireConnection::removeSessionFrameCallbacks(CScreencopyPortal::SSession* pSession) {
Debug::log(TRACE, "[pipewire] removeSessionFrameCallbacks called");
if (pSession->sharingData.frameCallback)
zwlr_screencopy_frame_v1_destroy(pSession->sharingData.frameCallback);
if (pSession->sharingData.windowFrameCallback)
hyprland_toplevel_export_frame_v1_destroy(pSession->sharingData.windowFrameCallback);
pSession->sharingData.windowFrameCallback = nullptr;
pSession->sharingData.frameCallback = nullptr;
pSession->sharingData.status = FRAME_NONE;
}
CPipewireConnection::~CPipewireConnection() { CPipewireConnection::~CPipewireConnection() {
if (m_pCore) if (m_pCore)
pw_core_disconnect(m_pCore); pw_core_disconnect(m_pCore);
@ -753,21 +767,22 @@ static void pwStreamStateChange(void* data, pw_stream_state old, pw_stream_state
if (PSTREAM->pSession->sharingData.status == FRAME_NONE) if (PSTREAM->pSession->sharingData.status == FRAME_NONE)
g_pPortalManager->m_sPortals.screencopy->startFrameCopy(PSTREAM->pSession); g_pPortalManager->m_sPortals.screencopy->startFrameCopy(PSTREAM->pSession);
else { else {
if (PSTREAM->pSession->sharingData.frameCallback) g_pPortalManager->m_sPortals.screencopy->m_pPipewire->removeSessionFrameCallbacks(PSTREAM->pSession);
zwlr_screencopy_frame_v1_destroy(PSTREAM->pSession->sharingData.frameCallback);
if (PSTREAM->pSession->sharingData.windowFrameCallback)
hyprland_toplevel_export_frame_v1_destroy(PSTREAM->pSession->sharingData.windowFrameCallback);
PSTREAM->pSession->sharingData.windowFrameCallback = nullptr;
PSTREAM->pSession->sharingData.frameCallback = nullptr;
g_pPortalManager->m_sPortals.screencopy->startFrameCopy(PSTREAM->pSession); g_pPortalManager->m_sPortals.screencopy->startFrameCopy(PSTREAM->pSession);
} }
break; break;
default: PSTREAM->streamState = false; break; default: {
PSTREAM->streamState = false;
g_pPortalManager->m_sPortals.screencopy->m_pPipewire->removeSessionFrameCallbacks(PSTREAM->pSession);
break;
}
} }
if (state == PW_STREAM_STATE_UNCONNECTED) if (state == PW_STREAM_STATE_UNCONNECTED) {
g_pPortalManager->m_sPortals.screencopy->m_pPipewire->removeSessionFrameCallbacks(PSTREAM->pSession);
g_pPortalManager->m_sPortals.screencopy->m_pPipewire->destroyStream(PSTREAM->pSession); g_pPortalManager->m_sPortals.screencopy->m_pPipewire->destroyStream(PSTREAM->pSession);
} }
}
static void pwStreamParamChanged(void* data, uint32_t id, const spa_pod* param) { static void pwStreamParamChanged(void* data, uint32_t id, const spa_pod* param) {
const auto PSTREAM = (CPipewireConnection::SPWStream*)data; const auto PSTREAM = (CPipewireConnection::SPWStream*)data;

View file

@ -7,22 +7,19 @@
#include <gbm.h> #include <gbm.h>
#include "../shared/Session.hpp" #include "../shared/Session.hpp"
enum cursorModes enum cursorModes {
{
HIDDEN = 1, HIDDEN = 1,
EMBEDDED = 2, EMBEDDED = 2,
METADATA = 4, METADATA = 4,
}; };
enum sourceTypes enum sourceTypes {
{
MONITOR = 1, MONITOR = 1,
WINDOW = 2, WINDOW = 2,
VIRTUAL = 4, VIRTUAL = 4,
}; };
enum frameStatus enum frameStatus {
{
FRAME_NONE = 0, FRAME_NONE = 0,
FRAME_QUEUED, FRAME_QUEUED,
FRAME_READY, FRAME_READY,
@ -152,6 +149,7 @@ class CPipewireConnection {
std::unique_ptr<SBuffer> createBuffer(SPWStream* pStream, bool dmabuf); std::unique_ptr<SBuffer> createBuffer(SPWStream* pStream, bool dmabuf);
SPWStream* streamFromSession(CScreencopyPortal::SSession* pSession); SPWStream* streamFromSession(CScreencopyPortal::SSession* pSession);
void removeSessionFrameCallbacks(CScreencopyPortal::SSession* pSession);
uint32_t buildFormatsFor(spa_pod_builder* b[2], const spa_pod* params[2], SPWStream* stream); uint32_t buildFormatsFor(spa_pod_builder* b[2], const spa_pod* params[2], SPWStream* stream);
void updateStreamParam(SPWStream* pStream); void updateStreamParam(SPWStream* pStream);