Valkka  1.6.1
OpenSource Video Management
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
OpenGLThread Class Reference

This class does a lot of things: More...

#include <openglthread.h>

Inheritance diagram for OpenGLThread:
Inheritance graph
[legend]
Collaboration diagram for OpenGLThread:
Collaboration graph
[legend]

Public Member Functions

 OpenGLThread (const char *name, OpenGLFrameFifoContext fifo_ctx=OpenGLFrameFifoContext(), unsigned msbuftime=DEFAULT_OPENGLTHREAD_BUFFERING_TIME, const char *x_connection="")
 Default constructor. More...
 
virtual ~OpenGLThread ()
 Virtual destructor // <pyapi>
 
unsigned getSwapInterval (GLXDrawable drawable=0)
 
void setSwapInterval (unsigned i, GLXDrawable drawable=0)
 
bool hasRenderGroup (Window window_id)
 Check if we have render groups.
 
RenderGroupgetRenderGroup (Window window_id)
 Returns a reference to RenderGroup in OpenGLThread::render_groups .. returns null if not found.
 
bool newRenderGroup (Window window_id)
 Creates a RenderGroup and inserts it into OpenGLThread::render_groups.
 
bool delRenderGroup (Window window_id)
 Remove RenderGroup from OpenGLThread::render_groups.
 
void newRenderContext (SlotNumber slot, Window window_id, int id, unsigned int z)
 Creates a new render context.
 
bool delRenderContext (int id)
 Runs through OpenGLThread::render_groups and removes indicated RenderContext.
 
bool contextAddRectangle (int id, float left, float right, float top, float bottom)
 
bool contextClearObjects (int id)
 
void loadYUVFrame (SlotNumber n_slot, YUVFrame *yuvframe)
 Load PBO to texture in OpenGLThread::slots_[n_slot].
 
void render (SlotNumber n_slot)
 Render all RenderGroup(s) depending on slot n_slot.
 
void checkSlots (long int mstime)
 
Display * getDisplayId ()
 
const GLXContext & getGlc ()
 
const Window & getRootId ()
 
bool slotUsed (SlotNumber i)
 
void activateSlot (SlotNumber i, YUVFrame *yuvframe)
 
void activateSlotIf (SlotNumber i, YUVFrame *yuvframe)
 
bool manageSlotTimer (SlotNumber i, long int mstime)
 
void debugOn ()
 
void debugOff ()
 
void run ()
 Main execution loop is defined here.
 
void preRun ()
 Called before entering the main execution loop, but after creating the thread. Calls OpenGLThread::createShaders and OpenGLThread::reserveFrames.
 
void postRun ()
 Called after the main execution loop exits, but before joining the thread.
 
void handleSignal (OpenGLSignalContext &signal_ctx)
 
void handleSignals ()
 From signals to methods.
 
void sendSignal (OpenGLSignalContext signal_ctx)
 Send a signal to the thread.
 
void sendSignalAndWait (OpenGLSignalContext signal_ctx)
 Send a signal to the thread and wait all signals to be executed.
 
void initGLX ()
 Connect to X11 server, init GLX direct rendering.
 
void closeGLX ()
 Close connection to X11.
 
void loadExtensions ()
 Load OpenGL extensions using GLEW. More...
 
void VSyncOff ()
 Turn off vsync for swapbuffers.
 
int hasCompositor (int screen)
 Detect if a compositor is running.
 
void makeShaders ()
 Compile shaders.
 
void delShaders ()
 Delete shader.
 
void reserveFrames ()
 Attaches YUVPBO instances with direct GPU memory access to Frame::yuvpbo.
 
void releaseFrames ()
 Deletes YUVPBO by calling Frame::reset.
 
void reportSlots ()
 
void reportRenderGroups ()
 
void reportRenderList ()
 
Window createWindow (bool map=true, bool show=false)
 Creates a new X window (for debugging/testing only) // <pyapi>
 
void makeCurrent (const Window window_id)
 Set current X windox // <pyapi>
 
unsigned getVsyncAtStartup ()
 What vsync was at startup time? // <pyapi>
 
void reConfigWindow (Window window_id)
 
Window getChildWindow (Window parent_id)
 
FifoFrameFiltergetFrameFilter ()
 API method: get filter for passing frames to this thread // <pyapi>
 
void setStaticTexFile (const char *fname)
 API method: set a file where the static texture (yuv image that's shown when no stream is received) is read from // <pyapi>
 
void requestStopCall ()
 API call: Like Thread::stopCall() but does not block.
 
void infoCall ()
 API call: reports render groups and lists.
 
bool newRenderGroupCall (Window window_id)
 API call: create a rendering group. More...
 
bool delRenderGroupCall (Window window_id)
 API call: delete a rendering group. More...
 
int newRenderContextCall (SlotNumber slot, Window window_id, unsigned int z)
 API call: create a new rendering context, i.e. More...
 
bool delRenderContextCall (int id)
 API call: delete a rendering context. More...
 
void addRectangleCall (int id, float left, float right, float top, float bottom)
 API call: add a rectangle that is drawn on the texture. More...
 
void clearObjectsCall (int id)
 API call: clear all objects drawn on the texture. More...
 
- Public Member Functions inherited from Thread
 Thread (const char *name)
 Default constructor. More...
 
 ~Thread ()
 Destructor:not virtual. More...
 
virtual void preJoin ()
 Called before the thread is joined.
 
virtual void postJoin ()
 Called after the thread has been joined.
 
virtual void sendSignal (SignalContext signal_ctx)
 Send a signal to the thread.
 
virtual void sendSignalAndWait (SignalContext signal_ctx)
 Send a signal to the thread and wait for all signals to be executed.
 
void setAffinity (int i)
 API method for setting the thread affinity. More...
 
void startCall ()
 API method: starts the thread.
 
virtual void stopCall ()
 API method: stops the thread. More...
 
virtual void waitStopCall ()
 API method: waits until the thread is joined. More...
 
virtual void waitReady ()
 Wait until thread has processed all its signals.
 

Public Attributes

unsigned swap_flavor
 
unsigned swap_interval_at_startup
 The value of swap interval when this thread was started.
 
std::deque< OpenGLSignalContextsignal_fifo
 Redefinition of signal fifo. Signal fifo of Thread::SignalContext(s) is now hidden.
 

Protected Member Functions

void dumpPresFifo ()
 Dump the presentation queue.
 
void diagnosis ()
 Dump presentation queue size and diagnosis output for infifo (YUVdiagnosis)
 
void resetCallTime ()
 
void reportCallTime (unsigned i)
 How much time since handleFifo exited.
 
long unsigned insertFifo (Frame *f)
 Sorted insert: insert a timestamped frame into the fifo. More...
 
void readStaticTex ()
 Reads a static texture that's shown on a window when no stream is received. Uses OpenGLThread::static_texture_file.
 
long unsigned handleFifo ()
 Runs through the fifo, presents / scraps frames, returns timeout until next frame presentation. More...
 
void delRenderContexes ()
 
- Protected Member Functions inherited from Thread
void mainRun ()
 Does the preRun, run, postRun sequence.
 
void closeThread ()
 Sends exit signal to the thread, calls join. This method blocks until thread has exited. Set Thread::has_thread to false.
 

Protected Attributes

OpenGLFrameFifoinfifo
 This thread reads from this communication fifo.
 
FifoFrameFilter infilter
 A FrameFilter for writing incoming frames.
 
std::string x_connection
 X-server connection string (i.e. ":0.0", ":0.1", etc.

 
YUVShaderyuv_shader
 Initialized by OpenGLThread::makeShaders.
 
RGBShaderrgb_shader
 Initialized by OpenGLThread::makeShaders.
 
YUVTEXstatictex
 Texture to be shown when there is no stream.
 
std::string static_texture_file
 Name of the file where statictex is.
 
Display * display_id
 
bool doublebuffer_flag
 
GLXContext glc
 
int * att
 
Window root_id
 
XVisualInfo * vi
 
GLXFBConfig * fbConfigs
 
Colormap cmap
 
YUVFramedummyframe
 A PBO membuf which we reserve from the GPU as the first membuf, but is never used.
 
std::vector< SlotContext * > slots_
 index => SlotContext mapping (based on vector indices) // WARNING: not they're pointers .. no copy_ctor ambiguity with std::vector
 
std::map< Window, RenderGrouprender_groups
 window_id => RenderGroup mapping. RenderGroup objects are warehoused here.
 
std::vector< std::list< RenderGroup * > > render_lists
 Each vector element corresponds to a slot. Each list inside a vector element has pointers to RenderGroups to be rendered.
 
std::map< int, RenderContext * > render_contexes
 Shortcut to render contexes.
 
unsigned msbuftime
 Buffering time in milliseconds.
 
unsigned future_ms_tolerance
 If frame is this much in the future, it will be discarded. See OpenGLThread::OpenGLThread for its value (some multiple of OpenGLThread::msbuftime)
 
std::list< Frame * > presfifo
 Double-linked list of buffered frames about to be presented.
 
long int calltime
 
long int callswaptime
 Debugging: when handleFifo was last called?
 
bool debug
 
- Protected Attributes inherited from Thread
std::string name
 Name of the thread.
 
bool has_thread
 true if thread has been started
 
bool stop_requested
 
bool thread_joined
 
std::mutex start_mutex
 Mutex protecting start_condition.
 
std::condition_variable start_condition
 Notified when the thread has been started.
 
std::mutex mutex
 Mutex protecting the condition variable and signal queue.
 
std::condition_variable condition
 Condition variable for the signal queue (triggered when all signals processed). Not necessarily used by all subclasses.
 
std::mutex loop_mutex
 Protects thread's main execution loop (if necessary)
 
std::deque< SignalContextsignal_fifo
 Signal queue (fifo). Redefine in child classes.
 
bool loop
 Use this boolean to control if the main loop in Thread:run should exit.
 
int core_id
 
pthread_attr_t thread_attr
 Thread attributes, pthread_* way.
 
cpu_set_t cpuset
 
pthread_t internal_thread
 

Private Attributes

PFNGLXSWAPINTERVALEXTPROC pglXSwapIntervalEXT
 
PFNGLXGETSWAPINTERVALMESAPROC pglXGetSwapIntervalMESA
 
PFNGLXSWAPINTERVALMESAPROC pglXSwapIntervalMESA
 

Additional Inherited Members

- Static Protected Member Functions inherited from Thread
static void * mainRun_ (void *p)
 

Detailed Description

This class does a lot of things:

See also: Code walkthrough: rendering

Constructor & Destructor Documentation

◆ OpenGLThread()

OpenGLThread::OpenGLThread ( const char *  name,
OpenGLFrameFifoContext  fifo_ctx = OpenGLFrameFifoContext(),
unsigned  msbuftime = DEFAULT_OPENGLTHREAD_BUFFERING_TIME,
const char *  x_connection = "" 
)

Default constructor.

Parameters
nameA name indentifying this thread
fifo_ctxParameters for the internal OpenGLFrameFifo
msbuftimeJitter buffer size in milliseconds (default=100 ms)

Member Function Documentation

◆ addRectangleCall()

void OpenGLThread::addRectangleCall ( int  id,
float  left,
float  right,
float  top,
float  bottom 
)

API call: add a rectangle that is drawn on the texture.

Parameters
idRendering context id
leftleft, right, top, bottom define the rectangle in relative (0..1) coordinates
Here is the call graph for this function:

◆ clearObjectsCall()

void OpenGLThread::clearObjectsCall ( int  id)

API call: clear all objects drawn on the texture.

Parameters
idRendering context id
Here is the call graph for this function:

◆ delRenderContextCall()

bool OpenGLThread::delRenderContextCall ( int  id)

API call: delete a rendering context.

Parameters
idRendering context id
  • // new
Here is the call graph for this function:

◆ delRenderGroupCall()

bool OpenGLThread::delRenderGroupCall ( Window  window_id)

API call: delete a rendering group.

Parameters
window_idX window id
Here is the call graph for this function:

◆ handleFifo()

long unsigned OpenGLThread::handleFifo ( )
protected

Runs through the fifo, presents / scraps frames, returns timeout until next frame presentation.

See also Presention timing and playing

Here is the call graph for this function:

◆ insertFifo()

long unsigned OpenGLThread::insertFifo ( Frame f)
protected

Sorted insert: insert a timestamped frame into the fifo.

Here is the call graph for this function:

◆ loadExtensions()

void OpenGLThread::loadExtensions ( )

Load OpenGL extensions using GLEW.

Here is the call graph for this function:

◆ newRenderContextCall()

int OpenGLThread::newRenderContextCall ( SlotNumber  slot,
Window  window_id,
unsigned int  z 
)

API call: create a new rendering context, i.e.

a new stream-to-render mapping

Parameters
slotSlot number identifying the stream
window_idX window id (corresponding to a created rendering group)
zStacking order of the rendered bitmap

returns a unique integer id presenting the rendering context. return 0 if the call failed.

Here is the call graph for this function:

◆ newRenderGroupCall()

bool OpenGLThread::newRenderGroupCall ( Window  window_id)

API call: create a rendering group.

Parameters
window_idX window id
  • // new

The documentation for this class was generated from the following files: