Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipewire DMA & EGL hardware support (Wayland/x11 grabber) #556

Merged
merged 4 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ SET ( DEFAULT_MAC_SYSTEM OFF )
SET ( DEFAULT_V4L2 OFF )
SET ( DEFAULT_X11 OFF )
SET ( DEFAULT_PIPEWIRE OFF )
SET ( DEFAULT_PIPEWIRE_EGL OFF )
SET ( DEFAULT_FRAMEBUFFER OFF )
SET ( DEFAULT_SOUNDCAPWINDOWS OFF )
SET ( DEFAULT_SOUNDCAPMACOS OFF )
Expand Down Expand Up @@ -246,8 +247,17 @@ if (DEFAULT_PIPEWIRE)
if(NOT PIPEWIRE_FOUND OR NOT PIPEWIRE_INCLUDE_DIRS OR NOT PIPEWIRE_LIBRARIES)
message( WARNING "Pipewire >= 3.0 not found (did you install libpipewire-0.3-dev?). Disabling support for PipeWire software grabber.")
SET ( DEFAULT_PIPEWIRE OFF )
else()
if(POLICY CMP0072)
cmake_policy(SET CMP0072 NEW)
endif()
find_package(OpenGL)
if (NOT OpenGL_OpenGL_FOUND OR NOT OpenGL_EGL_FOUND)
message( WARNING "OpenGL/EGL not found. Disabling DMA buffers for Pipewire.")
else()
SET ( DEFAULT_PIPEWIRE_EGL ON )
endif()
endif()

endif()
endif()

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

option(ENABLE_PIPEWIRE_EGL "Enable the pipewire EGL extension" ${DEFAULT_PIPEWIRE_EGL})
if (DEFAULT_PIPEWIRE)
colorMe("ENABLE_PIPEWIRE_EGL = " ${ENABLE_PIPEWIRE_EGL})
endif()

option(ENABLE_X11 "Enable the X11 Linux system grabber" ${DEFAULT_X11})
colorMe("ENABLE_X11 = " ${ENABLE_X11})

Expand Down
3 changes: 3 additions & 0 deletions HyperhdrConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
// PipeWire system grabber
#cmakedefine ENABLE_PIPEWIRE

// PipeWire EGL extension
#cmakedefine ENABLE_PIPEWIRE_EGL

// Define to enable boblight server
#cmakedefine ENABLE_BOBLIGHT

Expand Down
2 changes: 2 additions & 0 deletions include/base/Grabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class Grabber : public DetectionAutomatic, public DetectionManual
};

public slots:
virtual bool isRunning();

virtual bool start() = 0;

virtual void stop() = 0;
Expand Down
1 change: 1 addition & 0 deletions include/base/SystemWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public slots:
void setHdrToneMappingEnabled(int mode);
void handleSettingsUpdate(settings::type type, const QJsonDocument& config);
virtual void stateChanged(bool state);
bool isRunning();

protected:
virtual QString getGrabberInfo();
Expand Down
12 changes: 7 additions & 5 deletions include/grabber/PipewireGrabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <utils/PixelFormat.h>
#include <base/Grabber.h>
#include <utils/Components.h>
#include <grabber/smartPipewire.h>

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

void stateChanged(bool state);

private slots:

void grabFrame();
static void callbackFunction(const PipewireImage& frame);

public slots:

void grabFrame(const PipewireImage& data);

bool start() override;

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

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

bool isRunning() override;

private:
QString GetSharedLut();

Expand All @@ -75,12 +78,11 @@ public slots:

private:
QString _configurationPath;
QTimer _timer;
QSemaphore _semaphore;

void* _library;
int _actualDisplay;
bool _isActive;
bool _storedToken;
bool _versionCheck;
bool _hasFrame;
};
1 change: 1 addition & 0 deletions include/grabber/PipewireWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class PipewireWrapper : public SystemWrapper

public slots:
void stateChanged(bool state) override;
void processFrame(const PipewireImage& frame);

protected:
QString getGrabberInfo() override;
Expand Down
15 changes: 10 additions & 5 deletions include/grabber/smartPipewire.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
#pragma once

#include <cstdint>

struct PipewireImage
{
int version;
bool isError;
int width, height;
int width, height, stride;
bool isOrderRgb;
unsigned char* data;
uint8_t* data;
};

typedef int (*pipewire_callback_func)(const PipewireImage& frame);

extern "C" const char* getPipewireToken();
extern "C" const char* getPipewireError();
extern "C" bool hasPipewire();
extern "C" void initPipewireDisplay(const char* restorationToken);
extern "C" void initPipewireDisplay(const char* restorationToken, uint32_t requestedFPS, pipewire_callback_func callback);
extern "C" void uniniPipewireDisplay();
extern "C" PipewireImage getFramePipewire();
extern "C" void releaseFramePipewire();

5 changes: 5 additions & 0 deletions sources/base/Grabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,3 +927,8 @@ QString Grabber::getConfigurationPath()
{
return _configurationPath;
}

bool Grabber::isRunning()
{
return false;
}
2 changes: 1 addition & 1 deletion sources/base/HyperHdrInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ void HyperHdrInstance::updateResult(std::vector<ColorRgb> _ledBuffer)
else if (prevToken != (_computeStats.token = PerformanceCounters::currentToken()))
{

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

Expand Down
3 changes: 3 additions & 0 deletions sources/base/SystemControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ void SystemControl::handleCompStateChangeRequest(hyperhdr::Components component,

void SystemControl::setSysInactive()
{
if (SystemWrapper::getInstance() != nullptr && SystemWrapper::getInstance()->isRunning())
return;

if (!_alive)
_hyperhdr->setInputInactive(_sysCaptPrio);

Expand Down
10 changes: 10 additions & 0 deletions sources/base/SystemWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,13 @@ QJsonObject SystemWrapper::getJsonInfo()

return systemDevice;
}

bool SystemWrapper::isRunning()
{
if (_grabber != NULL)
{
return _grabber->isRunning();
}

return false;
}
2 changes: 1 addition & 1 deletion sources/grabber/pipewire/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_library(smartPipewire SHARED ${SMARTPIPEWIRE_SOURCES} )
set_target_properties(smartPipewire PROPERTIES VERSION 1)

# Pipewire
target_include_directories(smartPipewire PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${PIPEWIRE_INCLUDE_DIRS} )
target_include_directories(smartPipewire PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${PIPEWIRE_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIR} ${OPENGL_EGL_INCLUDE_DIRS} )
target_link_libraries(smartPipewire PUBLIC ${PIPEWIRE_LIBRARIES} Qt${Qt_VERSION}::Core Qt${Qt_VERSION}::DBus )

# Grabber
Expand Down
Loading