mirror of
https://github.com/hyprwm/xdg-desktop-portal-hyprland.git
synced 2024-11-23 22:55:58 +01:00
c++ification a bit
This commit is contained in:
parent
daa9a2386b
commit
f63678ad11
3 changed files with 45 additions and 41 deletions
|
@ -491,9 +491,8 @@ static void pwStreamStateChange(void* data, pw_stream_state old, pw_stream_state
|
||||||
default: PSTREAM->streamState = false;
|
default: PSTREAM->streamState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == PW_STREAM_STATE_UNCONNECTED) {
|
if (state == PW_STREAM_STATE_UNCONNECTED)
|
||||||
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) {
|
||||||
|
@ -568,44 +567,10 @@ static void pwStreamAddBuffer(void* data, pw_buffer* buffer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto PBUFFER = PSTREAM->buffers.emplace_back(std::make_unique<SBuffer>()).get();
|
const auto PBUFFER = PSTREAM->buffers.emplace_back(g_pPortalManager->m_sPortals.screencopy->m_pPipewire->createBuffer(PSTREAM, type == SPA_DATA_DmaBuf)).get();
|
||||||
|
|
||||||
buffer->user_data = PBUFFER;
|
|
||||||
|
|
||||||
PBUFFER->fmt = PSTREAM->pSession->sharingData.frameInfoSHM.fmt;
|
|
||||||
PBUFFER->h = PSTREAM->pSession->sharingData.frameInfoSHM.h;
|
|
||||||
PBUFFER->w = PSTREAM->pSession->sharingData.frameInfoSHM.w;
|
|
||||||
PBUFFER->isDMABUF = type == SPA_DATA_DmaBuf;
|
|
||||||
PBUFFER->pwBuffer = buffer;
|
PBUFFER->pwBuffer = buffer;
|
||||||
|
buffer->user_data = PBUFFER;
|
||||||
Debug::log(TRACE, "[pw] Adding buffer of type {}", PBUFFER->isDMABUF ? "DMA" : "SHM");
|
|
||||||
|
|
||||||
// wl_shm only
|
|
||||||
PBUFFER->planeCount = 1;
|
|
||||||
PBUFFER->size[0] = PSTREAM->pSession->sharingData.frameInfoSHM.size;
|
|
||||||
PBUFFER->stride[0] = PSTREAM->pSession->sharingData.frameInfoSHM.stride;
|
|
||||||
PBUFFER->offset[0] = 0;
|
|
||||||
PBUFFER->fd[0] = anonymous_shm_open();
|
|
||||||
if (PBUFFER->fd[0] == -1) {
|
|
||||||
Debug::log(ERR, "buffer fd failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ftruncate(PBUFFER->fd[0], PBUFFER->size[0]) < 0) {
|
|
||||||
close(PBUFFER->fd[0]);
|
|
||||||
Debug::log(ERR, "buffer ftruncate failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PBUFFER->wlBuffer =
|
|
||||||
import_wl_shm_buffer(PBUFFER->fd[0], (wl_shm_format)wlSHMFromDrmFourcc(PSTREAM->pSession->sharingData.frameInfoSHM.fmt), PSTREAM->pSession->sharingData.frameInfoSHM.w,
|
|
||||||
PSTREAM->pSession->sharingData.frameInfoSHM.h, PSTREAM->pSession->sharingData.frameInfoSHM.stride);
|
|
||||||
if (PBUFFER->wlBuffer == NULL) {
|
|
||||||
close(PBUFFER->fd[0]);
|
|
||||||
Debug::log(ERR, "buffer import failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
|
|
||||||
Debug::log(TRACE, "[pw] buffer datas {}", buffer->buffer->n_datas);
|
Debug::log(TRACE, "[pw] buffer datas {}", buffer->buffer->n_datas);
|
||||||
|
|
||||||
|
@ -720,7 +685,6 @@ void CPipewireConnection::destroyStream(CScreencopyPortal::SSession* pSession) {
|
||||||
|
|
||||||
uint32_t CPipewireConnection::buildFormatsFor(spa_pod_builder* b[2], const spa_pod* params[2], CPipewireConnection::SPWStream* stream) {
|
uint32_t CPipewireConnection::buildFormatsFor(spa_pod_builder* b[2], const spa_pod* params[2], CPipewireConnection::SPWStream* stream) {
|
||||||
uint32_t paramCount = 0;
|
uint32_t paramCount = 0;
|
||||||
uint32_t modCount = 0;
|
|
||||||
|
|
||||||
if (/*TODO: dmabuf*/ false) {
|
if (/*TODO: dmabuf*/ false) {
|
||||||
|
|
||||||
|
@ -797,3 +761,42 @@ void CPipewireConnection::dequeue(CScreencopyPortal::SSession* pSession) {
|
||||||
|
|
||||||
PSTREAM->currentPWBuffer = PBUF;
|
PSTREAM->currentPWBuffer = PBUF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<SBuffer> CPipewireConnection::createBuffer(CPipewireConnection::SPWStream* pStream, bool dmabuf) {
|
||||||
|
std::unique_ptr<SBuffer> pBuffer = std::make_unique<SBuffer>();
|
||||||
|
|
||||||
|
pBuffer->w = pStream->pSession->sharingData.frameInfoSHM.w;
|
||||||
|
pBuffer->h = pStream->pSession->sharingData.frameInfoSHM.h;
|
||||||
|
pBuffer->fmt = pStream->pSession->sharingData.frameInfoSHM.fmt;
|
||||||
|
pBuffer->isDMABUF = dmabuf;
|
||||||
|
|
||||||
|
if (dmabuf) {
|
||||||
|
// todo
|
||||||
|
} else {
|
||||||
|
|
||||||
|
pBuffer->planeCount = 1;
|
||||||
|
pBuffer->size[0] = pStream->pSession->sharingData.frameInfoSHM.size;
|
||||||
|
pBuffer->stride[0] = pStream->pSession->sharingData.frameInfoSHM.stride;
|
||||||
|
pBuffer->offset[0] = 0;
|
||||||
|
pBuffer->fd[0] = anonymous_shm_open();
|
||||||
|
|
||||||
|
if (pBuffer->fd[0] == -1) {
|
||||||
|
Debug::log(ERR, "[screencopy] anonymous_shm_open failed");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ftruncate(pBuffer->fd[0], pBuffer->size[0]) < 0) {
|
||||||
|
Debug::log(ERR, "[screencopy] ftruncate failed");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
pBuffer->wlBuffer = import_wl_shm_buffer(pBuffer->fd[0], wlSHMFromDrmFourcc(pStream->pSession->sharingData.frameInfoSHM.fmt), pStream->pSession->sharingData.frameInfoSHM.w,
|
||||||
|
pStream->pSession->sharingData.frameInfoSHM.h, pStream->pSession->sharingData.frameInfoSHM.stride);
|
||||||
|
if (!pBuffer->wlBuffer) {
|
||||||
|
Debug::log(ERR, "[screencopy] import_wl_shm_buffer failed");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::move(pBuffer);
|
||||||
|
}
|
||||||
|
|
|
@ -137,7 +137,8 @@ class CPipewireConnection {
|
||||||
std::vector<std::unique_ptr<SBuffer>> buffers;
|
std::vector<std::unique_ptr<SBuffer>> buffers;
|
||||||
};
|
};
|
||||||
|
|
||||||
SPWStream* streamFromSession(CScreencopyPortal::SSession* pSession);
|
std::unique_ptr<SBuffer> createBuffer(SPWStream* pStream, bool dmabuf);
|
||||||
|
SPWStream* streamFromSession(CScreencopyPortal::SSession* pSession);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<SPWStream>> m_vStreams;
|
std::vector<std::unique_ptr<SPWStream>> m_vStreams;
|
||||||
|
|
|
@ -15,7 +15,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
|
|
||||||
#define XDPH_PWR_BUFFERS 2
|
#define XDPH_PWR_BUFFERS 4
|
||||||
#define XDPH_PWR_BUFFERS_MIN 2
|
#define XDPH_PWR_BUFFERS_MIN 2
|
||||||
#define XDPH_PWR_ALIGN 16
|
#define XDPH_PWR_ALIGN 16
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue