1 #ifndef openglthread_HEADER_GUARD
2 #define openglthread_HEADER_GUARD
38 #include "openglframefifo.h"
42 #include "threadsignal.h"
46 typedef void ( *PFNGLXSWAPINTERVALEXTPROC) (Display *dpy, GLXDrawable drawable,
int interval);
95 bool isUsed()
const {
return ref_count>0;}
97 bool isDead()
const {
return is_dead;}
100 void inc_ref_count() {ref_count++;}
101 void dec_ref_count() {ref_count--;}
102 void loadFlag(
bool val);
103 void keepFlag(
bool val);
128 const unsigned int z;
141 long int render_mstime, render_mstime_old;
144 std::list<OverlayObject*> overlays;
160 void addRectangle(
float left,
float right,
float top,
float bottom);
206 Window getWindowId()
const {
return window_id;}
207 const std::list<RenderContext*>& getRenderContexes()
const {
return render_contexes;}
210 std::list<RenderContext*>::iterator
getContext(
int id);
229 const static unsigned none =0;
230 const static unsigned ext =1;
231 const static unsigned mesa =2;
232 const static unsigned sgi =3;
280 bool doublebuffer_flag;
285 GLXFBConfig* fbConfigs;
298 PFNGLXSWAPINTERVALEXTPROC pglXSwapIntervalEXT;
299 PFNGLXGETSWAPINTERVALMESAPROC pglXGetSwapIntervalMESA;
300 PFNGLXSWAPINTERVALMESAPROC pglXSwapIntervalMESA;
303 unsigned swap_flavor;
305 unsigned getSwapInterval(GLXDrawable drawable=0);
306 void setSwapInterval(
unsigned i, GLXDrawable drawable=0);
325 void newRenderContext(SlotNumber slot, Window window_id,
int id,
unsigned int z);
329 bool contextAddRectangle(
int id,
float left,
float right,
float top,
float bottom);
330 bool contextClearObjects(
int id);
334 void render(SlotNumber n_slot);
335 void checkSlots(
long int mstime);
338 Display* getDisplayId() {
return display_id;}
339 const GLXContext& getGlc() {
return glc;}
340 const Window& getRootId() {
return root_id;}
343 bool slotUsed (SlotNumber i);
344 void activateSlot (SlotNumber i,
YUVFrame *yuvframe);
345 void activateSlotIf (SlotNumber i,
YUVFrame *yuvframe);
346 bool manageSlotTimer(SlotNumber i,
long int mstime);
349 void debugOn() {debug=
true;}
350 void debugOff() {debug=
false;}
378 void resetCallTime();
388 void delRenderContexes();
392 void reportRenderGroups();
393 void reportRenderList();
406 void reConfigWindow(Window window_id);
407 Window getChildWindow(Window parent_id);
453 void addRectangleCall(
int id,
float left,
float right,
float top,
float bottom);
Passes frames to a FrameFifo.
Definition: framefilter.h:530
virtual void recycle(Frame *f)
Like FrameFifo::recycle_ but with mutex protection.
Definition: framefifo.cpp:225
virtual void dumpFifo()
Dump frames in the fifo.
Definition: framefifo.cpp:266
Frame: An abstract queueable class.
Definition: frame.h:112
A FrameFifo managed and used by OpenGLThread.
Definition: openglframefifo.h:69
void YUVdiagnosis()
Brief resumen of OpenGLFrameFifo::yuv_stacks.
Definition: openglframefifo.cpp:239
void dumpYUVStacks()
Dump frames in OpenGLFrameFifo::yuv_stacks.
Definition: openglframefifo.cpp:223
This class does a lot of things:
Definition: openglthread.h:247
long unsigned insertFifo(Frame *f)
Sorted insert: insert a timestamped frame into the fifo.
Definition: openglthread.cpp:1168
unsigned future_ms_tolerance
If frame is this much in the future, it will be discarded. See OpenGLThread::OpenGLThread for its val...
Definition: openglthread.h:310
void setStaticTexFile(const char *fname)
API method: set a file where the static texture (yuv image that's shown when no stream is received) i...
Definition: openglthread.cpp:2021
virtual ~OpenGLThread()
Virtual destructor // <pyapi>
Definition: openglthread.cpp:806
void dumpPresFifo()
Dump the presentation queue.
Definition: openglthread.cpp:1126
bool delRenderContext(int id)
Runs through OpenGLThread::render_groups and removes indicated RenderContext.
Definition: openglthread.cpp:959
std::vector< SlotContext * > slots_
index => SlotContext mapping (based on vector indices) // WARNING: not they're pointers ....
Definition: openglthread.h:289
void reportCallTime(unsigned i)
How much time since handleFifo exited.
Definition: openglthread.cpp:1161
void infoCall()
API call: reports render groups and lists.
Definition: openglthread.cpp:2113
void addRectangleCall(int id, float left, float right, float top, float bottom)
API call: add a rectangle that is drawn on the texture.
Definition: openglthread.cpp:2231
void postRun()
Called after the main execution loop exits, but before joining the thread.
Definition: openglthread.cpp:1497
void YUVdiagnosis()
Brief resumen of the state of the YUV Frame stack.
Definition: openglthread.h:396
void dumpInFifo()
Incoming fifo: here we have all kinds of frames, including YUVFrame(s)
Definition: openglthread.h:397
bool hasRenderGroup(Window window_id)
Check if we have render groups.
Definition: openglthread.cpp:858
bool newRenderGroup(Window window_id)
Creates a RenderGroup and inserts it into OpenGLThread::render_groups.
Definition: openglthread.cpp:875
RenderGroup & getRenderGroup(Window window_id)
Returns a reference to RenderGroup in OpenGLThread::render_groups .. returns null if not found.
Definition: openglthread.cpp:870
void loadExtensions()
Load OpenGL extensions using GLEW.
Definition: openglthread.cpp:1762
void makeCurrent(const Window window_id)
Set current X windox // <pyapi>
Definition: openglthread.cpp:1730
std::vector< std::list< RenderGroup * > > render_lists
Each vector element corresponds to a slot. Each list inside a vector element has pointers to RenderGr...
Definition: openglthread.h:292
void handleSignals()
From signals to methods.
Definition: openglthread.cpp:1599
void requestStopCall()
API call: Like Thread::stopCall() but does not block.
Definition: openglthread.cpp:2099
void delShaders()
Delete shader.
Definition: openglthread.cpp:1885
void preRun()
Called before entering the main execution loop, but after creating the thread. Calls OpenGLThread::cr...
Definition: openglthread.cpp:1472
bool delRenderContextCall(int id)
API call: delete a rendering context.
Definition: openglthread.cpp:2206
void reserveFrames()
Attaches YUVPBO instances with direct GPU memory access to Frame::yuvpbo.
YUVFrame * dummyframe
A PBO membuf which we reserve from the GPU as the first membuf, but is never used.
Definition: openglthread.h:287
RGBShader * rgb_shader
Initialized by OpenGLThread::makeShaders.
Definition: openglthread.h:272
OpenGLFrameFifo * infifo
This thread reads from this communication fifo.
Definition: openglthread.h:261
void render(SlotNumber n_slot)
Render all RenderGroup(s) depending on slot n_slot.
Definition: openglthread.cpp:1091
void sendSignal(OpenGLSignalContext signal_ctx)
Send a signal to the thread.
Definition: openglthread.cpp:1628
std::string static_texture_file
Name of the file where statictex is.
Definition: openglthread.h:276
void clearObjectsCall(int id)
API call: clear all objects drawn on the texture.
Definition: openglthread.cpp:2246
int newRenderContextCall(SlotNumber slot, Window window_id, unsigned int z)
API call: create a new rendering context, i.e.
Definition: openglthread.cpp:2179
std::deque< OpenGLSignalContext > signal_fifo
Redefinition of signal fifo. Signal fifo of Thread::SignalContext(s) is now hidden.
Definition: openglthread.h:353
bool newRenderGroupCall(Window window_id)
API call: create a rendering group.
Definition: openglthread.cpp:2121
void closeGLX()
Close connection to X11.
Definition: openglthread.cpp:1752
std::string x_connection
X-server connection string (i.e. ":0.0", ":0.1", etc.
Definition: openglthread.h:263
void sendSignalAndWait(OpenGLSignalContext signal_ctx)
Send a signal to the thread and wait all signals to be executed.
Definition: openglthread.cpp:1634
OpenGLThread(const char *name, OpenGLFrameFifoContext fifo_ctx=OpenGLFrameFifoContext(), unsigned msbuftime=DEFAULT_OPENGLTHREAD_BUFFERING_TIME, const char *x_connection="")
Default constructor.
Definition: openglthread.cpp:785
void VSyncOff()
Turn off vsync for swapbuffers.
Definition: openglthread.cpp:1865
YUVShader * yuv_shader
Initialized by OpenGLThread::makeShaders.
Definition: openglthread.h:271
void loadYUVFrame(SlotNumber n_slot, YUVFrame *yuvframe)
Load PBO to texture in OpenGLThread::slots_[n_slot].
Definition: openglthread.cpp:1028
void readStaticTex()
Reads a static texture that's shown on a window when no stream is received. Uses OpenGLThread::static...
Definition: openglthread.cpp:2026
unsigned msbuftime
Buffering time in milliseconds.
Definition: openglthread.h:309
void initGLX()
Connect to X11 server, init GLX direct rendering.
Definition: openglthread.cpp:1643
bool delRenderGroupCall(Window window_id)
API call: delete a rendering group.
Definition: openglthread.cpp:2152
void releaseFrames()
Deletes YUVPBO by calling Frame::reset.
int hasCompositor(int screen)
Detect if a compositor is running.
Definition: openglthread.cpp:1743
Window createWindow(bool map=true, bool show=false)
Creates a new X window (for debugging/testing only) // <pyapi>
Definition: openglthread.cpp:1891
void newRenderContext(SlotNumber slot, Window window_id, int id, unsigned int z)
Creates a new render context.
Definition: openglthread.cpp:919
unsigned swap_interval_at_startup
The value of swap interval when this thread was started.
Definition: openglthread.h:304
FifoFrameFilter infilter
A FrameFilter for writing incoming frames.
Definition: openglthread.h:262
std::list< Frame * > presfifo
Double-linked list of buffered frames about to be presented.
Definition: openglthread.h:311
long int callswaptime
Debugging: when handleFifo was last called?
Definition: openglthread.h:312
std::map< int, RenderContext * > render_contexes
Shortcut to render contexes.
Definition: openglthread.h:293
std::map< Window, RenderGroup > render_groups
window_id => RenderGroup mapping. RenderGroup objects are warehoused here.
Definition: openglthread.h:291
void diagnosis()
Dump presentation queue size and diagnosis output for infifo (YUVdiagnosis)
Definition: openglthread.cpp:1148
long unsigned handleFifo()
Runs through the fifo, presents / scraps frames, returns timeout until next frame presentation.
Definition: openglthread.cpp:1271
unsigned getVsyncAtStartup()
What vsync was at startup time? // <pyapi>
Definition: openglthread.cpp:1738
void run()
Main execution loop is defined here.
Definition: openglthread.cpp:1395
FifoFrameFilter & getFrameFilter()
API method: get filter for passing frames to this thread // <pyapi>
Definition: openglthread.cpp:2016
void dumpYUVStacks()
State of the YUV Frame stack.
Definition: openglthread.h:395
void recycle(Frame *f)
Recycle a frame back to OpenGLFrameFifo.
Definition: openglthread.h:400
void makeShaders()
Compile shaders.
Definition: openglthread.cpp:1870
bool delRenderGroup(Window window_id)
Remove RenderGroup from OpenGLThread::render_groups.
Definition: openglthread.cpp:892
YUVTEX * statictex
Texture to be shown when there is no stream.
Definition: openglthread.h:275
Encapsulates data for rendering a single bitmap: vertex array object (VAO), vertex buffer object (VBO...
Definition: openglthread.h:112
void render(XWindowAttributes x_window_attr)
Sets x_window_attr and calls renderTexture and renderObjects.
Definition: openglthread.cpp:381
std::array< GLuint, 6 > indices
data of the element buffer object
Definition: openglthread.h:138
XWindowAttributes x_window_attr
X window size, etc.
Definition: openglthread.h:150
void bindVertexArray()
Bind the vertex array and draw.
Definition: openglthread.cpp:601
GLuint VAO
id of the vertex array object
Definition: openglthread.h:133
void bindTextures()
Associate textures with the shader program. Uses parameters from Shader reference.
Definition: openglthread.cpp:442
int id
A unique id identifying this render context.
Definition: openglthread.h:130
const unsigned int z
Stacking order.
Definition: openglthread.h:128
void bindVars()
Upload other data to the GPU (say, transformation matrix). Uses parameters from Shader reference.
Definition: openglthread.cpp:491
void activate()
Init VAO, VBO, etc.
Definition: openglthread.cpp:241
void renderTexture()
Render the texture.
Definition: openglthread.cpp:370
std::array< GLfloat, 16 > transform
data of the transformation matrix
Definition: openglthread.h:136
GLuint VBO
id of the vertex buffer object
Definition: openglthread.h:134
RenderContext(SlotContext *slot_context, int id, unsigned int z=0)
Default constructor.
Definition: openglthread.cpp:187
std::array< GLfloat, 20 > vertices
data of the vertex buffer object
Definition: openglthread.h:137
SlotContext * slot_context
Knows relevant Shader and YUVTEX.
Definition: openglthread.h:127
void renderObjects()
Render objects overlaying the texture.
Definition: openglthread.cpp:373
int getId() const
Returns the unique id of this render context.
Definition: openglthread.h:153
virtual ~RenderContext()
Default virtual destructor.
Definition: openglthread.cpp:210
void bindVarsObj()
bindVars for the overlay objects. Uses previously calculated value of RenderContext::transform
Definition: openglthread.cpp:591
GLuint EBO
id of the element buffer object
Definition: openglthread.h:135
Group of bitmaps that are rendered into the same X-window.
Definition: openglthread.h:182
std::list< RenderContext * >::iterator getContext(int id)
Returns iterator at matched render context id.
Definition: openglthread.cpp:649
RenderContext * delContext(int id)
Remove RenderContext from RenderGroup::render_contexes (with checking)
Definition: openglthread.cpp:679
XWindowAttributes x_window_attr
X window attributes.
Definition: openglthread.h:203
bool addContext(RenderContext *render_context)
Add RenderContext to RenderGroup::render_contexes (with checking)
Definition: openglthread.cpp:660
Display * display_id
X display id.
Definition: openglthread.h:197
bool doublebuffer_flag
Double buffer rendering or not?
Definition: openglthread.h:201
void render()
Render everything in this group (i.e.
Definition: openglthread.cpp:699
Window child_id
X window id: rendering target.
Definition: openglthread.h:200
RenderGroup(Display *display_id, const GLXContext &glc, Window window_id, Window child_id, bool doublebuffer_flag=true)
Default constructor.
Definition: openglthread.cpp:641
const GLXContext & glc
GLX Context.
Definition: openglthread.h:198
std::list< RenderContext * > render_contexes
RenderContext instances in ascending z order. User created rendercontexes are warehoused here.
Definition: openglthread.h:202
bool isEmpty()
Checks if there are any render contexes in the render_contexes list.
Definition: openglthread.cpp:694
~RenderGroup()
Default destructor.
Definition: openglthread.cpp:645
Window window_id
X window id: render group id.
Definition: openglthread.h:199
Each Frame carries information about it's slot number in Frame::slot.
Definition: openglthread.h:58
bool isActive() const
Check if active.
Definition: openglthread.h:96
void activate(BitmapPars bmpars)
Allocate SlotContext::yuvtex (for a frame of certain size)
Definition: openglthread.cpp:61
bool load_flag
This flag is cleared when a new frame is loaded.
Definition: openglthread.h:78
long int lastmstime
Last millisecond timestamp when this slot received a frame.
Definition: openglthread.h:71
YUVTEX * statictex
A static texture to be shown on the screen if no video is received.
Definition: openglthread.h:68
bool manageTimer(long int mstime)
Updates SlotContext::lastmstime. Returns false if too little time has passed since receiving the last...
Definition: openglthread.cpp:105
YUVTEX * yuvtex
This could be a base class for different kinds of textures (now only YUVTEX)
Definition: openglthread.h:67
YUVShader * shader
Base class for the chosen Shader for this slot. Now always YUVShader.
Definition: openglthread.h:69
void loadYUVFrame(YUVFrame *yuvframe)
Load bitmap from YUVFrame to SlotContext::yuvtex.
Definition: openglthread.cpp:88
~SlotContext()
Default destructor.
Definition: openglthread.cpp:55
bool active
Is activated or not. Active = has received a setup frame.
Definition: openglthread.h:75
bool isPending(long int mstime)
Compares SlotContext::lastmstime to mstime and returns true of a treshold is met (if last frame was r...
Definition: openglthread.cpp:130
void deActivate()
Deallocate textures.
Definition: openglthread.cpp:76
bool is_dead
Has received frames or not for a while ?
Definition: openglthread.h:76
AVCodecID codec_id
FFmpeg codec id.
Definition: openglthread.h:77
void checkIfDead(long int mstime)
Compares SlotContext::lastmstime to mstime and changes the state of SlotContext::is_dead.
Definition: openglthread.cpp:119
bool keep_flag
Should we keep on showing the previous frame, even if the slot is_dead?
Definition: openglthread.h:79
YUVTEX * getTEX()
Returns the relevant texture set (static or live)
Definition: openglthread.cpp:145
SlotContext(YUVTEX *statictex, YUVShader *shader)
Default constructor.
Definition: openglthread.cpp:51
long int prev_mstimestamp
for debugging: check if frames are fed in correct timestamp order
Definition: openglthread.h:82
A class for multithreading with a signaling system.
Definition: thread.h:87
std::string name
Name of the thread.
Definition: thread.h:116
A GPU YUV frame.
Definition: frame.h:492
A class encapsulating information about an OpenGL texture set for a YUV pixmap (sizes,...
Definition: tex.h:77
Constant/default values, version numbers.
GLX extensions for controlling the vertical sync / framerate issue are a mess.
Definition: openglthread.h:228
OpenGL objects, i.e. stuff that can be drawn on the OpenGL canvas on top the textures (boxes,...
For AVBitmapFrames, linesizes are the widths + padding bytes.
Definition: constant.h:132
Describes the stack structure and fifo behaviour for an OpenGLFrameFifo.
Definition: openglframefifo.h:45
Encapsulates data sent by the signal.
Definition: threadsignal.h:149
Handling OpenGL textures.
Base class for multithreading.