Skip to content

Commit

Permalink
Fix pipewire grabber for non-contiguous DMA memory & EGL (#711)
Browse files Browse the repository at this point in the history
* fix pipewire portal by removing blocks parameter
* DMA special query filter
* Fix valgrind findings

---------

Co-authored-by: Awawa <[email protected]>
  • Loading branch information
Mic92 and awawa-dev authored Jan 10, 2024
1 parent 7a6ed10 commit 5b94d91
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: HyperHDR CI Build

on:
push:
pull_request:

env:
USE_CACHE: "1"
Expand Down
59 changes: 40 additions & 19 deletions sources/grabber/pipewire/PipewireHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,15 @@ void PipewireHandler::closeSession()
#ifdef ENABLE_PIPEWIRE_EGL
if (contextEgl != EGL_NO_CONTEXT)
{
eglDestroyContext(displayEgl, contextEgl);
auto res = eglDestroyContext(displayEgl, contextEgl);
std::cout << "PipewireEGL: destroying EGL context => " << res << std::endl;
contextEgl = EGL_NO_CONTEXT;
}

if (displayEgl != EGL_NO_DISPLAY)
{
printf("PipewireEGL: terminate the display\n");
eglTerminate(displayEgl);
auto res = eglTerminate(displayEgl);
std::cout << "PipewireEGL: terminate the display => " << res << std::endl;
displayEgl = EGL_NO_DISPLAY;
}

Expand Down Expand Up @@ -590,7 +591,7 @@ void PipewireHandler::onStateChanged(pw_stream_state old, pw_stream_state state,

void PipewireHandler::onParamsChanged(uint32_t id, const struct spa_pod* param)
{
struct spa_video_info format;
struct spa_video_info format {};

std::cout << "Pipewire: got new video format selected" << std::endl;

Expand Down Expand Up @@ -632,24 +633,46 @@ void PipewireHandler::onParamsChanged(uint32_t id, const struct spa_pod* param)
? (1 << SPA_DATA_DmaBuf) | (1 << SPA_DATA_MemFd) | (1 << SPA_DATA_MemPtr)
: (1 << SPA_DATA_MemFd) | (1 << SPA_DATA_MemPtr);

if (bufferTypes & (1 << SPA_DATA_DmaBuf))
const bool hasDma = (bufferTypes & (1 << SPA_DATA_DmaBuf));

// display capabilities
if (hasDma)
{
printf("Pipewire: DMA buffer available. Format: %s. Modifier: %s.\n",
fourCCtoString(_frameDrmFormat).toLocal8Bit().constData(),
fourCCtoString(_frameDrmModifier).toLocal8Bit().constData());
}
if (bufferTypes & (1 << SPA_DATA_MemFd))
{
printf("Pipewire: MemFD buffer available\n");
}
if (bufferTypes & (1 << SPA_DATA_MemPtr))
{
printf("Pipewire: MemPTR buffer available\n");
}

if (hasDma)
{
updatedParams[0] = reinterpret_cast<spa_pod*> (spa_pod_builder_add_object(&updateBufferBuilder,
SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers,
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(2, 2, 16),
SPA_PARAM_BUFFERS_size, SPA_POD_Int(size),
SPA_PARAM_BUFFERS_stride, SPA_POD_CHOICE_RANGE_Int(stride, stride, INT32_MAX),
SPA_PARAM_BUFFERS_align, SPA_POD_Int(16),
SPA_PARAM_BUFFERS_dataType, SPA_POD_CHOICE_FLAGS_Int(bufferTypes)));
}
else
{
updatedParams[0] = reinterpret_cast<spa_pod*> (spa_pod_builder_add_object(&updateBufferBuilder,
SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers,
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(2, 2, 16),
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1),
SPA_PARAM_BUFFERS_size, SPA_POD_Int(size),
SPA_PARAM_BUFFERS_stride, SPA_POD_CHOICE_RANGE_Int(stride, stride, INT32_MAX),
SPA_PARAM_BUFFERS_align, SPA_POD_Int(16),
SPA_PARAM_BUFFERS_dataType, SPA_POD_CHOICE_FLAGS_Int(bufferTypes)));
}

updatedParams[0] = (spa_pod*)(spa_pod*)spa_pod_builder_add_object(&updateBufferBuilder,
SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers,
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(2, 2, 16),
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1),
SPA_PARAM_BUFFERS_size, SPA_POD_Int(size),
SPA_PARAM_BUFFERS_stride, SPA_POD_CHOICE_RANGE_Int(stride, stride, INT32_MAX),
SPA_PARAM_BUFFERS_align, SPA_POD_Int(16),
SPA_PARAM_BUFFERS_dataType, SPA_POD_CHOICE_FLAGS_Int(bufferTypes));

pw_thread_loop_lock(_pwMainThreadLoop);

printf("Pipewire: updated parameters %d\n", pw_stream_update_params(_pwStream, updatedParams, 1));
Expand Down Expand Up @@ -1268,12 +1291,12 @@ pw_stream* PipewireHandler::createCapturingStream()

if (stream != nullptr)
{
const int spaBufferSize = 2048;
const spa_pod* streamParams[(sizeof(_supportedDmaFormatsList) / sizeof(supportedDmaFormat)) + 1];
int streamParamsIndex = 0;

MemoryBuffer<uint8_t> spaBufferMem(2048);

uint8_t* spaBuffer = static_cast<uint8_t*>(calloc(spaBufferSize, 1));
auto spaBuilder = SPA_POD_BUILDER_INIT(spaBuffer, spaBufferSize);
auto spaBuilder = SPA_POD_BUILDER_INIT(spaBufferMem.data(), static_cast<uint32_t>(spaBufferMem.size()));

#ifdef ENABLE_PIPEWIRE_EGL

Expand Down Expand Up @@ -1333,8 +1356,6 @@ pw_stream* PipewireHandler::createCapturingStream()
}
else
printf("Pipewire: the stream is connected\n");

free(spaBuffer);
}

return stream;
Expand Down

0 comments on commit 5b94d91

Please sign in to comment.