Skip to content

Commit 8143d8b

Browse files
authored
Pipewire DMA & EGL hardware support (Wayland/x11 grabber) (#556)
* Pipewire DMA & EGL hardware support * Add pipewire locking section * Fix EGL for x11 session using Pipewire * Change Pipewire frame capture
1 parent e4264bf commit 8143d8b

17 files changed

+985
-207
lines changed

Diff for: CMakeLists.txt

+16-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ SET ( DEFAULT_MAC_SYSTEM OFF )
3131
SET ( DEFAULT_V4L2 OFF )
3232
SET ( DEFAULT_X11 OFF )
3333
SET ( DEFAULT_PIPEWIRE OFF )
34+
SET ( DEFAULT_PIPEWIRE_EGL OFF )
3435
SET ( DEFAULT_FRAMEBUFFER OFF )
3536
SET ( DEFAULT_SOUNDCAPWINDOWS OFF )
3637
SET ( DEFAULT_SOUNDCAPMACOS OFF )
@@ -246,8 +247,17 @@ if (DEFAULT_PIPEWIRE)
246247
if(NOT PIPEWIRE_FOUND OR NOT PIPEWIRE_INCLUDE_DIRS OR NOT PIPEWIRE_LIBRARIES)
247248
message( WARNING "Pipewire >= 3.0 not found (did you install libpipewire-0.3-dev?). Disabling support for PipeWire software grabber.")
248249
SET ( DEFAULT_PIPEWIRE OFF )
250+
else()
251+
if(POLICY CMP0072)
252+
cmake_policy(SET CMP0072 NEW)
253+
endif()
254+
find_package(OpenGL)
255+
if (NOT OpenGL_OpenGL_FOUND OR NOT OpenGL_EGL_FOUND)
256+
message( WARNING "OpenGL/EGL not found. Disabling DMA buffers for Pipewire.")
257+
else()
258+
SET ( DEFAULT_PIPEWIRE_EGL ON )
259+
endif()
249260
endif()
250-
251261
endif()
252262
endif()
253263

@@ -329,6 +339,11 @@ colorMe("ENABLE_MAC_SYSTEM = " ${ENABLE_MAC_SYSTEM})
329339
option(ENABLE_PIPEWIRE "Enable the pipewire/portal Linux system grabber" ${DEFAULT_PIPEWIRE})
330340
colorMe("ENABLE_PIPEWIRE = " ${ENABLE_PIPEWIRE})
331341

342+
option(ENABLE_PIPEWIRE_EGL "Enable the pipewire EGL extension" ${DEFAULT_PIPEWIRE_EGL})
343+
if (DEFAULT_PIPEWIRE)
344+
colorMe("ENABLE_PIPEWIRE_EGL = " ${ENABLE_PIPEWIRE_EGL})
345+
endif()
346+
332347
option(ENABLE_X11 "Enable the X11 Linux system grabber" ${DEFAULT_X11})
333348
colorMe("ENABLE_X11 = " ${ENABLE_X11})
334349

Diff for: HyperhdrConfig.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
// PipeWire system grabber
2222
#cmakedefine ENABLE_PIPEWIRE
2323

24+
// PipeWire EGL extension
25+
#cmakedefine ENABLE_PIPEWIRE_EGL
26+
2427
// Define to enable boblight server
2528
#cmakedefine ENABLE_BOBLIGHT
2629

Diff for: include/base/Grabber.h

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ class Grabber : public DetectionAutomatic, public DetectionManual
141141
};
142142

143143
public slots:
144+
virtual bool isRunning();
145+
144146
virtual bool start() = 0;
145147

146148
virtual void stop() = 0;

Diff for: include/base/SystemWrapper.h

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public slots:
5959
void setHdrToneMappingEnabled(int mode);
6060
void handleSettingsUpdate(settings::type type, const QJsonDocument& config);
6161
virtual void stateChanged(bool state);
62+
bool isRunning();
6263

6364
protected:
6465
virtual QString getGrabberInfo();

Diff for: include/grabber/PipewireGrabber.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <utils/PixelFormat.h>
1919
#include <base/Grabber.h>
2020
#include <utils/Components.h>
21+
#include <grabber/smartPipewire.h>
2122

2223
// general JPEG decoder includes
2324
#include <QImage>
@@ -42,12 +43,12 @@ class PipewireGrabber : public Grabber
4243

4344
void stateChanged(bool state);
4445

45-
private slots:
46-
47-
void grabFrame();
46+
static void callbackFunction(const PipewireImage& frame);
4847

4948
public slots:
5049

50+
void grabFrame(const PipewireImage& data);
51+
5152
bool start() override;
5253

5354
void stop() override;
@@ -56,6 +57,8 @@ public slots:
5657

5758
void newWorkerFrameError(unsigned int workerIndex, QString error, quint64 sourceCount) override {};
5859

60+
bool isRunning() override;
61+
5962
private:
6063
QString GetSharedLut();
6164

@@ -75,12 +78,11 @@ public slots:
7578

7679
private:
7780
QString _configurationPath;
78-
QTimer _timer;
79-
QSemaphore _semaphore;
8081

8182
void* _library;
8283
int _actualDisplay;
8384
bool _isActive;
8485
bool _storedToken;
8586
bool _versionCheck;
87+
bool _hasFrame;
8688
};

Diff for: include/grabber/PipewireWrapper.h

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class PipewireWrapper : public SystemWrapper
1313

1414
public slots:
1515
void stateChanged(bool state) override;
16+
void processFrame(const PipewireImage& frame);
1617

1718
protected:
1819
QString getGrabberInfo() override;

Diff for: include/grabber/smartPipewire.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
15
struct PipewireImage
26
{
37
int version;
48
bool isError;
5-
int width, height;
9+
int width, height, stride;
610
bool isOrderRgb;
7-
unsigned char* data;
11+
uint8_t* data;
812
};
13+
14+
typedef int (*pipewire_callback_func)(const PipewireImage& frame);
15+
916
extern "C" const char* getPipewireToken();
1017
extern "C" const char* getPipewireError();
1118
extern "C" bool hasPipewire();
12-
extern "C" void initPipewireDisplay(const char* restorationToken);
19+
extern "C" void initPipewireDisplay(const char* restorationToken, uint32_t requestedFPS, pipewire_callback_func callback);
1320
extern "C" void uniniPipewireDisplay();
14-
extern "C" PipewireImage getFramePipewire();
15-
extern "C" void releaseFramePipewire();
1621

Diff for: sources/base/Grabber.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -927,3 +927,8 @@ QString Grabber::getConfigurationPath()
927927
{
928928
return _configurationPath;
929929
}
930+
931+
bool Grabber::isRunning()
932+
{
933+
return false;
934+
}

Diff for: sources/base/HyperHdrInstance.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ void HyperHdrInstance::updateResult(std::vector<ColorRgb> _ledBuffer)
701701
else if (prevToken != (_computeStats.token = PerformanceCounters::currentToken()))
702702
{
703703

704-
if (diff >= 59000 && diff <= 65000)
704+
if (diff >= 59000)
705705
emit PerformanceCounters::getInstance()->newCounter(
706706
PerformanceReport(static_cast<int>(PerformanceReportType::INSTANCE), _computeStats.token, _name, _computeStats.total / qMax(diff/1000.0, 1.0), _computeStats.total, 0, 0, getInstanceIndex()));
707707

Diff for: sources/base/SystemControl.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ void SystemControl::handleCompStateChangeRequest(hyperhdr::Components component,
136136

137137
void SystemControl::setSysInactive()
138138
{
139+
if (SystemWrapper::getInstance() != nullptr && SystemWrapper::getInstance()->isRunning())
140+
return;
141+
139142
if (!_alive)
140143
_hyperhdr->setInputInactive(_sysCaptPrio);
141144

Diff for: sources/base/SystemWrapper.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,13 @@ QJsonObject SystemWrapper::getJsonInfo()
231231

232232
return systemDevice;
233233
}
234+
235+
bool SystemWrapper::isRunning()
236+
{
237+
if (_grabber != NULL)
238+
{
239+
return _grabber->isRunning();
240+
}
241+
242+
return false;
243+
}

Diff for: sources/grabber/pipewire/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ add_library(smartPipewire SHARED ${SMARTPIPEWIRE_SOURCES} )
88
set_target_properties(smartPipewire PROPERTIES VERSION 1)
99

1010
# Pipewire
11-
target_include_directories(smartPipewire PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${PIPEWIRE_INCLUDE_DIRS} )
11+
target_include_directories(smartPipewire PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${PIPEWIRE_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIR} ${OPENGL_EGL_INCLUDE_DIRS} )
1212
target_link_libraries(smartPipewire PUBLIC ${PIPEWIRE_LIBRARIES} Qt${Qt_VERSION}::Core Qt${Qt_VERSION}::DBus )
1313

1414
# Grabber

0 commit comments

Comments
 (0)