Skip to content

Commit

Permalink
Pipewire DMA & EGL hardware support
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Apr 29, 2023
1 parent 3353015 commit dda5e54
Show file tree
Hide file tree
Showing 17 changed files with 968 additions and 208 deletions.
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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 @@ -252,13 +253,21 @@ if (DEFAULT_PIPEWIRE)
message( WARNING "QT dbus library is required for PipeWire/Portal support" )
SET ( DEFAULT_PIPEWIRE OFF )
else()

pkg_check_modules(PIPEWIRE libpipewire-0.3)
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 @@ -340,6 +349,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 @@ -139,6 +139,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 @@ -58,6 +58,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 @@ -910,3 +910,8 @@ QJsonObject Grabber::getJsonInfo()
void Grabber::alternativeCaching(bool alternative)
{
}

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 @@ -665,7 +665,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 @@ -137,6 +137,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 @@ -237,3 +237,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

0 comments on commit dda5e54

Please sign in to comment.