11#pragma once
22
3+ #include < QDebug>
34#include < QObject>
45#include < QVector>
56#include < QList>
1314#include < spa/debug/types.h>
1415#include < grabber/linux/pipewire/smartPipewire.h>
1516#include < linux/types.h>
17+ #include < sys/mman.h>
1618#include < HyperhdrConfig.h>
1719#include < memory>
20+ #include < atomic>
21+ #include < array>
1822
1923#if !PW_CHECK_VERSION(0, 3, 29)
2024#define SPA_POD_PROP_FLAG_MANDATORY (1u << 3 )
@@ -40,16 +44,25 @@ typedef EGLBoolean (*eglDestroyImageKHRFun)(EGLDisplay dpy, EGLImageKHR image);
4044typedef EGLContext (*eglCreateContextFun)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint* attrib_list);
4145typedef EGLBoolean (*eglDestroyContextFun)(EGLDisplay display, EGLContext context);
4246typedef EGLBoolean (*eglMakeCurrentFun)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
47+ typedef EGLContext (*eglGetCurrentContextFun)(void );
4348typedef EGLBoolean (*eglBindAPIFun)(EGLenum api);
4449typedef void (*glEGLImageTargetTexture2DOESFun)(GLenum target, GLeglImageOES image);
4550
46- typedef void * (*glXGetProcAddressARBFun)(const char *);
4751typedef void (*glBindTextureFun)(GLenum target, GLuint texture);
4852typedef void (*glDeleteTexturesFun)(GLsizei n, const GLuint* textures);
4953typedef void (*glGenTexturesFun)(GLsizei n, GLuint* textures);
5054typedef GLenum (*glGetErrorFun)(void );
5155typedef void (*glGetTexImageFun)(GLenum target, GLint level, GLenum format, GLenum type, void * pixels);
5256typedef void (*glTexParameteriFun)(GLenum target, GLenum pname, GLint param);
57+ typedef void (*glGenerateMipmapFun)(GLenum target);
58+ typedef void (*glPixelStoreiFun)(GLenum pname,GLint param);
59+ typedef void (*glGenFramebuffersFun)(GLsizei n, GLuint* ids);
60+ typedef void (*glBindFramebufferFun)(GLenum target, GLuint framebuffer);
61+ typedef void (*glFramebufferTexture2DFun)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
62+ typedef void (*glReadPixelsFun)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void * data);
63+ typedef void (*glDeleteFramebuffersFun)(GLsizei n, GLuint* framebuffers);
64+ typedef void (*glBlitFramebufferFun)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
65+ typedef void (*glTexImage2DFun)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void * data);
5366
5467#define fourcc_code (a, b, c, d ) ((__u32)(a) | ((__u32)(b) << 8 ) | \
5568 ((__u32)(c) << 16 ) | ((__u32)(d) << 24 ))
@@ -79,14 +92,18 @@ class PipewireHandler : public QObject
7992
8093 PipewireHandler ();
8194 ~PipewireHandler ();
82- void startSession (QString restorationToken, uint32_t requestedFPS);
95+
96+ void startSession (QString restorationToken, uint32_t requestedFPS, bool enableEGL, int targetMaxSize);
8397 void closeSession ();
8498 bool hasError ();
8599
86100 int getVersion ();
87101 QString getToken ();
88102 QString getError ();
89103
104+ pw_stream* getPipewireStream ();
105+ bool hasIncomingFrame (struct pw_buffer * dequeueFrame);
106+
90107 static int readVersion ();
91108
92109 struct PipewireStructure
@@ -107,6 +124,7 @@ public Q_SLOTS:
107124 void onStateChanged (enum pw_stream_state old, enum pw_stream_state state, const char * error);
108125 void onProcessFrame ();
109126 void onCoreError (uint32_t id, int seq, int res, const char *message);
127+ void onReleaseBuffer (struct pw_buffer * buffer);
110128
111129signals:
112130 void onParamsChangedSignal (uint32_t id, const struct spa_pod * param);
@@ -117,7 +135,7 @@ public Q_SLOTS:
117135private:
118136 uint8_t * createMemory (int size);
119137 void reportError (const QString& input);
120- const QString fourCCtoString (int64_t val);
138+ QString fourCCtoString (int64_t val);
121139
122140 pw_stream* createCapturingStream ();
123141 QString getSessionToken ();
@@ -146,14 +164,15 @@ public Q_SLOTS:
146164 struct pw_buffer * _backupFrame;
147165 struct pw_buffer * _workingFrame;
148166
167+ int _targetMaxSize;
149168 int _frameWidth;
150169 int _frameHeight;
151170 bool _frameOrderRgb;
152- bool _framePaused;
153171 uint32_t _requestedFPS;
154- bool _hasFrame ;
155- bool _infoUpdated ;
172+ std::atomic< struct pw_buffer *> _incomingFrame ;
173+ int _infoUpdate ;
156174 bool _initEGL;
175+ bool _enableEGL;
157176 void * _libEglHandle;
158177 void * _libGlHandle;
159178 int64_t _frameDrmFormat;
@@ -181,19 +200,31 @@ public Q_SLOTS:
181200 eglCreateContextFun eglCreateContext = nullptr ;
182201 eglDestroyContextFun eglDestroyContext = nullptr ;
183202 eglMakeCurrentFun eglMakeCurrent = nullptr ;
203+ eglGetCurrentContextFun eglGetCurrentContext = nullptr ;
184204 glEGLImageTargetTexture2DOESFun glEGLImageTargetTexture2DOES = nullptr ;
185205 eglBindAPIFun eglBindAPI = nullptr ;
186206
187- glXGetProcAddressARBFun glXGetProcAddressARB = nullptr ;
188207 glBindTextureFun glBindTexture = nullptr ;
189208 glDeleteTexturesFun glDeleteTextures = nullptr ;
190209 glGenTexturesFun glGenTextures = nullptr ;
191210 glGetErrorFun glGetError = nullptr ;
192211 glGetTexImageFun glGetTexImage = nullptr ;
193212 glTexParameteriFun glTexParameteri = nullptr ;
213+ glGenerateMipmapFun glGenerateMipmap = nullptr ;
214+ glPixelStoreiFun glPixelStorei = nullptr ;
215+ glGenFramebuffersFun glGenFramebuffers = nullptr ;
216+ glBindFramebufferFun glBindFramebuffer = nullptr ;
217+ glFramebufferTexture2DFun glFramebufferTexture2D = nullptr ;
218+ glReadPixelsFun glReadPixels = nullptr ;
219+ glDeleteFramebuffersFun glDeleteFramebuffers = nullptr ;
220+ glBlitFramebufferFun glBlitFramebuffer = nullptr ;
221+ glTexImage2DFun glTexImage2D = nullptr ;
194222
195223 EGLDisplay displayEgl = EGL_NO_DISPLAY;
196224 EGLContext contextEgl = EGL_NO_CONTEXT;
225+ GLuint _eglTexture = 0 ;
226+ GLuint _eglScratchTex = 0 ;
227+ std::array<GLuint, 2 > _eglFbos = { 0 , 0 };
197228
198229 const char * eglErrorToString (EGLint error_number);
199230 const char * glErrorToString (GLenum errorType);
@@ -214,7 +245,16 @@ public Q_SLOTS:
214245 { DRM_FORMAT_XBGR8888, SPA_VIDEO_FORMAT_RGBx, GL_RGBA, " DRM_FORMAT_XBGR8888" , false },
215246 { DRM_FORMAT_ABGR8888, SPA_VIDEO_FORMAT_RGBA, GL_RGBA, " DRM_FORMAT_ABGR8888" , false }
216247 };
217-
218248#endif
219249
250+ struct PipewireCache {
251+
252+ #ifdef ENABLE_PIPEWIRE_EGL
253+ EGLImageKHR eglImage = EGL_NO_IMAGE_KHR;
254+ #endif
255+
256+ void * mmapPtr = MAP_FAILED;
257+ size_t mmapSize = 0 ;
258+
259+ };
220260};
0 commit comments