MythTV  0.28pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
OpenGLVideo Class Reference

A class used to display video frames and associated imagery using the OpenGL API. More...

#include <openglvideo.h>

Collaboration diagram for OpenGLVideo:
Collaboration graph
[legend]

Public Member Functions

 OpenGLVideo ()
 Create a new OpenGLVideo instance that must be initialised with a call to OpenGLVideo::Init() More...
 
 ~OpenGLVideo ()
 
bool Init (MythRenderOpenGL *glcontext, VideoColourSpace *colourspace, QSize videoDim, QSize videoDispDim, QRect displayVisibleRect, QRect displayVideoRect, QRect videoRect, bool viewport_control, QString options, bool hwaccel)
 
uint GetInputTexture (void) const
 
uint GetTextureType (void) const
 
void SetInputUpdated (void)
 
void UpdateInputFrame (const VideoFrame *frame, bool soft_bob=false)
 Update the current input texture using the data from the given YV12 video frame. More...
 
bool AddFilter (const QString &filter)
 Public interface to AddFilter(OpenGLFilterType filter) More...
 
bool RemoveFilter (const QString &filter)
 
bool AddDeinterlacer (const QString &deinterlacer)
 Extends the functionality of the basic YUV->RGB filter stage to include deinterlacing (combining the stages is significantly more efficient than 2 separate stages). More...
 
void SetDeinterlacing (bool deinterlacing)
 
QString GetDeinterlacer (void) const
 
void SetSoftwareDeinterlacer (const QString &filter)
 
void PrepareFrame (bool topfieldfirst, FrameScanType scan, bool softwareDeinterlacing, long long frame, StereoscopicMode stereo, bool draw_border=false)
 Render the contents of the current input texture to the framebuffer using the currently enabled filters. More...
 
void SetMasterViewport (QSize size)
 
QSize GetViewPort (void) const
 
void SetVideoRect (const QRect &dispvidrect, const QRect &vidrect)
 
QSize GetVideoSize (void) const
 

Private Member Functions

void Teardown (void)
 
void SetViewPort (const QSize &new_viewport_size)
 
bool AddFilter (OpenGLFilterType filter)
 Add a new filter stage and create any additional resources needed. More...
 
bool RemoveFilter (OpenGLFilterType filter)
 
void CheckResize (bool deinterlacing, bool allow=true)
 Determine if the output is to be scaled at all and create or destroy the appropriate filter as necessary. More...
 
bool OptimiseFilters (void)
 Ensure the current chain of OpenGLFilters is logically correct and has the resources required to complete rendering. More...
 
bool AddFrameBuffer (uint &framebuffer, uint &texture, QSize vid_size)
 Add a FrameBuffer object of the correct size to the given texture. More...
 
uint AddFragmentProgram (OpenGLFilterType name, QString deint=QString::null, FrameScanType field=kScan_Progressive)
 Create the correct fragment program for the given filter type. More...
 
uint CreateVideoTexture (QSize size, QSize &tex_size)
 Create and initialise an OpenGL texture suitable for a YV12 video frame of the given size. More...
 
QString GetProgramString (OpenGLFilterType filter, QString deint=QString::null, FrameScanType field=kScan_Progressive)
 
void GetProgramStrings (QString &vertex, QString &fragment, OpenGLFilterType filter, QString deint=QString::null, FrameScanType field=kScan_Progressive)
 
void CustomiseProgramString (QString &string)
 
QSize GetTextureSize (const QSize &size)
 
void SetFiltering (void)
 Set the OpenGL texture mapping functions to optimise speed and quality. More...
 
void RotateTextures (void)
 
void SetTextureFilters (vector< GLuint > *textures, int filt, int clamp)
 
void DeleteTextures (vector< GLuint > *textures)
 
void TearDownDeinterlacer (void)
 

Static Private Member Functions

static QString FilterToString (OpenGLFilterType filter)
 
static OpenGLFilterType StringToFilter (const QString &filter)
 

Private Attributes

MythRenderOpenGLgl_context
 
QSize video_disp_dim
 
QSize video_dim
 
QSize viewportSize
 
QSize masterViewportSize
 
QRect display_visible_rect
 
QRect display_video_rect
 
QRect video_rect
 
QRect frameBufferRect
 
QString softwareDeinterlacer
 
QString hardwareDeinterlacer
 
bool hardwareDeinterlacing
 
VideoColourSpacecolourSpace
 
bool viewportControl
 
vector< GLuint > referenceTextures
 
vector< GLuint > inputTextures
 
QSize inputTextureSize
 
glfilt_map_t filters
 
long long currentFrameNum
 
bool inputUpdated
 
int refsNeeded
 
bool textureRects
 
uint textureType
 
uint helperTexture
 
OpenGLFilterType defaultUpsize
 
uint gl_features
 
uint videoTextureType
 
bool preferYCBCR
 

Detailed Description

A class used to display video frames and associated imagery using the OpenGL API.

The basic operational concept is to use a series of filter stages to generate the desired video output, using limited software assistance alongside OpenGL fragment programs (deinterlacing and YUV->RGB conversion) , FrameBuffer Objects (flexible GPU storage) and PixelBuffer Objects (faster CPU->GPU memory transfers).

In the most basic case, for example, a YV12 frame pre-converted in software to BGRA format is simply blitted to the frame buffer. Currently, the most complicated example is the rendering of a standard definition, interlaced frame to a high(er) definition display using OpenGL (i.e. hardware based) deinterlacing, colourspace conversion and bicubic upsampling.

Higher level tasks such as coordination between OpenGLVideo instances, video buffer management, audio/video synchronisation etc are handled by the higher level classes VideoOutput and NuppelVideoPlayer. The bulk of the lower level interface with the window system and OpenGL is handled by MythRenderOpenGL.

N.B. Direct use of OpenGL calls is minimised to maintain platform independance. The only member function where this is impractical is PrepareFrame().

Warning
Any direct OpenGL calls must be wrapped by calls to gl_context->MakeCurrent(). Alternatively use the convenience class OpenGLLocker.

Definition at line 37 of file openglvideo.h.

Constructor & Destructor Documentation

OpenGLVideo::OpenGLVideo ( )

Create a new OpenGLVideo instance that must be initialised with a call to OpenGLVideo::Init()

Definition at line 65 of file openglvideo.cpp.

OpenGLVideo::~OpenGLVideo ( )

Definition at line 82 of file openglvideo.cpp.

Member Function Documentation

bool OpenGLVideo::Init ( MythRenderOpenGL glcontext,
VideoColourSpace colourspace,
QSize  videoDim,
QSize  videoDispDim,
QRect  displayVisibleRect,
QRect  displayVideoRect,
QRect  videoRect,
bool  viewport_control,
QString  options,
bool  hwaccel 
)
Parameters
glcontextthe MythRenderOpenGL object responsible for lower levelwindow and OpenGL context integration
colour_controlif true, manipulation of video attributes (colour, contrast etc) will be enabled
videoDimthe size of the video source
displayVisibleRectthe bounding rectangle of the OpenGL window
displayVideoRectthe bounding rectangle for the area to display the video frame
videoRectthe portion of the video frame to display in displayVideoRect
viewport_controlif true, this instance may permanently change the OpenGL viewport
optionsa string defining OpenGL features to disable
hw_accelif true, a GPU decoder will copy frames directly to an RGBA texture

Definition at line 126 of file openglvideo.cpp.

Referenced by VideoOutputOpenGL::SetupOpenGL(), and VideoOutputOpenGL::ShowPIP().

uint OpenGLVideo::GetInputTexture ( void  ) const

Definition at line 771 of file openglvideo.cpp.

Referenced by VideoOutputOpenGLVAAPI::ProcessFrame().

uint OpenGLVideo::GetTextureType ( void  ) const

Definition at line 776 of file openglvideo.cpp.

Referenced by VideoOutputOpenGLVAAPI::ProcessFrame().

void OpenGLVideo::SetInputUpdated ( void  )

Definition at line 781 of file openglvideo.cpp.

Referenced by VideoOutputOpenGLVAAPI::ProcessFrame().

void OpenGLVideo::UpdateInputFrame ( const VideoFrame frame,
bool  soft_bob = false 
)

Update the current input texture using the data from the given YV12 video frame.

If the required hardware support is not available, fall back to software YUV->RGB conversion.

Definition at line 793 of file openglvideo.cpp.

Referenced by VideoOutputOpenGL::ProcessFrame(), and VideoOutputOpenGL::ShowPIP().

bool OpenGLVideo::AddFilter ( const QString &  filter)
inline

Public interface to AddFilter(OpenGLFilterType filter)

Definition at line 55 of file openglvideo.h.

Referenced by CheckResize(), and Init().

bool OpenGLVideo::RemoveFilter ( const QString &  filter)
inline

Definition at line 57 of file openglvideo.h.

Referenced by AddFilter(), CheckResize(), and Teardown().

bool OpenGLVideo::AddDeinterlacer ( const QString &  deinterlacer)

Extends the functionality of the basic YUV->RGB filter stage to include deinterlacing (combining the stages is significantly more efficient than 2 separate stages).

Create 2 deinterlacing fragment programs, 1 for each required field.

Definition at line 562 of file openglvideo.cpp.

Referenced by VideoOutputOpenGL::SetupDeinterlace().

void OpenGLVideo::SetDeinterlacing ( bool  deinterlacing)
QString OpenGLVideo::GetDeinterlacer ( void  ) const
inline
void OpenGLVideo::SetSoftwareDeinterlacer ( const QString &  filter)
void OpenGLVideo::PrepareFrame ( bool  topfieldfirst,
FrameScanType  scan,
bool  softwareDeinterlacing,
long long  frame,
StereoscopicMode  stereo,
bool  draw_border = false 
)

Render the contents of the current input texture to the framebuffer using the currently enabled filters.

Parameters
topfieldfirstthe frame is interlaced and top_field_first is set
scaninterlaced or progressive?
softwareDeinerlacingthe frame has been deinterlaced in software
framethe frame number
draw_borderif true, draw a red border around the frame
Warning
This function is a finely tuned, sensitive beast. Tinker at your own risk.

Definition at line 878 of file openglvideo.cpp.

Referenced by VideoOutputOpenGL::PrepareFrame().

void OpenGLVideo::SetMasterViewport ( QSize  size)
inline

Definition at line 71 of file openglvideo.h.

Referenced by VideoOutputOpenGL::ShowPIP().

QSize OpenGLVideo::GetViewPort ( void  ) const
inline

Definition at line 72 of file openglvideo.h.

Referenced by VideoOutputOpenGL::ShowPIP().

void OpenGLVideo::SetVideoRect ( const QRect &  dispvidrect,
const QRect &  vidrect 
)
inline
QSize OpenGLVideo::GetVideoSize ( void  ) const
inline

Definition at line 75 of file openglvideo.h.

Referenced by VideoOutputOpenGL::ShowPIP().

void OpenGLVideo::Teardown ( void  )
private

Definition at line 88 of file openglvideo.cpp.

Referenced by Init(), and ~OpenGLVideo().

void OpenGLVideo::SetViewPort ( const QSize &  new_viewport_size)
private

Definition at line 698 of file openglvideo.cpp.

Referenced by Init().

bool OpenGLVideo::AddFilter ( OpenGLFilterType  filter)
private

Add a new filter stage and create any additional resources needed.

Definition at line 422 of file openglvideo.cpp.

bool OpenGLVideo::RemoveFilter ( OpenGLFilterType  filter)
private

Definition at line 502 of file openglvideo.cpp.

void OpenGLVideo::CheckResize ( bool  deinterlacing,
bool  allow = true 
)
private

Determine if the output is to be scaled at all and create or destroy the appropriate filter as necessary.

Definition at line 280 of file openglvideo.cpp.

Referenced by AddDeinterlacer(), Init(), SetDeinterlacing(), and SetSoftwareDeinterlacer().

bool OpenGLVideo::OptimiseFilters ( void  )
private

Ensure the current chain of OpenGLFilters is logically correct and has the resources required to complete rendering.

Definition at line 323 of file openglvideo.cpp.

Referenced by AddFilter(), and CheckResize().

bool OpenGLVideo::AddFrameBuffer ( uint framebuffer,
uint texture,
QSize  vid_size 
)
private

Add a FrameBuffer object of the correct size to the given texture.

Definition at line 679 of file openglvideo.cpp.

Referenced by OptimiseFilters().

uint OpenGLVideo::AddFragmentProgram ( OpenGLFilterType  name,
QString  deint = QString::null,
FrameScanType  field = kScan_Progressive 
)
private

Create the correct fragment program for the given filter type.

Definition at line 649 of file openglvideo.cpp.

Referenced by AddDeinterlacer(), and AddFilter().

uint OpenGLVideo::CreateVideoTexture ( QSize  size,
QSize &  tex_size 
)
private

Create and initialise an OpenGL texture suitable for a YV12 video frame of the given size.

Definition at line 718 of file openglvideo.cpp.

Referenced by AddDeinterlacer(), and Init().

QString OpenGLVideo::GetProgramString ( OpenGLFilterType  filter,
QString  deint = QString::null,
FrameScanType  field = kScan_Progressive 
)
private

Definition at line 1279 of file openglvideo.cpp.

Referenced by AddFragmentProgram().

void OpenGLVideo::GetProgramStrings ( QString &  vertex,
QString &  fragment,
OpenGLFilterType  filter,
QString  deint = QString::null,
FrameScanType  field = kScan_Progressive 
)
private

Definition at line 1578 of file openglvideo.cpp.

Referenced by AddFragmentProgram().

void OpenGLVideo::CustomiseProgramString ( QString &  string)
private

Definition at line 1356 of file openglvideo.cpp.

Referenced by GetProgramString(), and GetProgramStrings().

QString OpenGLVideo::FilterToString ( OpenGLFilterType  filter)
staticprivate

Definition at line 1128 of file openglvideo.cpp.

Referenced by AddFilter(), GetProgramString(), and RemoveFilter().

OpenGLFilterType OpenGLVideo::StringToFilter ( const QString &  filter)
staticprivate

Definition at line 1114 of file openglvideo.cpp.

QSize OpenGLVideo::GetTextureSize ( const QSize &  size)
private

Definition at line 750 of file openglvideo.cpp.

Referenced by CustomiseProgramString(), and PrepareFrame().

void OpenGLVideo::SetFiltering ( void  )
private

Set the OpenGL texture mapping functions to optimise speed and quality.

Definition at line 386 of file openglvideo.cpp.

Referenced by OptimiseFilters().

void OpenGLVideo::RotateTextures ( void  )
private

Definition at line 1077 of file openglvideo.cpp.

Referenced by UpdateInputFrame().

void OpenGLVideo::SetTextureFilters ( vector< GLuint > *  textures,
int  filt,
int  clamp 
)
private

Definition at line 1104 of file openglvideo.cpp.

Referenced by SetFiltering().

void OpenGLVideo::DeleteTextures ( vector< GLuint > *  textures)
private

Definition at line 1094 of file openglvideo.cpp.

Referenced by RemoveFilter(), Teardown(), and TearDownDeinterlacer().

void OpenGLVideo::TearDownDeinterlacer ( void  )
private

Definition at line 531 of file openglvideo.cpp.

Referenced by AddDeinterlacer().

Member Data Documentation

MythRenderOpenGL* OpenGLVideo::gl_context
private
QSize OpenGLVideo::video_disp_dim
private
QSize OpenGLVideo::video_dim
private

Definition at line 109 of file openglvideo.h.

Referenced by AddDeinterlacer(), Init(), PrepareFrame(), and UpdateInputFrame().

QSize OpenGLVideo::viewportSize
private

Definition at line 110 of file openglvideo.h.

Referenced by SetViewPort().

QSize OpenGLVideo::masterViewportSize
private

Definition at line 111 of file openglvideo.h.

Referenced by Init(), and PrepareFrame().

QRect OpenGLVideo::display_visible_rect
private

Definition at line 112 of file openglvideo.h.

Referenced by Init(), and PrepareFrame().

QRect OpenGLVideo::display_video_rect
private

Definition at line 113 of file openglvideo.h.

Referenced by CheckResize(), Init(), and PrepareFrame().

QRect OpenGLVideo::video_rect
private

Definition at line 114 of file openglvideo.h.

Referenced by Init(), and PrepareFrame().

QRect OpenGLVideo::frameBufferRect
private

Definition at line 115 of file openglvideo.h.

Referenced by Init(), and PrepareFrame().

QString OpenGLVideo::softwareDeinterlacer
private

Definition at line 116 of file openglvideo.h.

Referenced by Init(), PrepareFrame(), and SetSoftwareDeinterlacer().

QString OpenGLVideo::hardwareDeinterlacer
private

Definition at line 117 of file openglvideo.h.

Referenced by AddDeinterlacer(), and PrepareFrame().

bool OpenGLVideo::hardwareDeinterlacing
private
VideoColourSpace* OpenGLVideo::colourSpace
private

Definition at line 119 of file openglvideo.h.

Referenced by Init(), and PrepareFrame().

bool OpenGLVideo::viewportControl
private

Definition at line 120 of file openglvideo.h.

Referenced by Init(), PrepareFrame(), and SetViewPort().

vector<GLuint> OpenGLVideo::referenceTextures
private
vector<GLuint> OpenGLVideo::inputTextures
private
QSize OpenGLVideo::inputTextureSize
private

Definition at line 123 of file openglvideo.h.

Referenced by AddDeinterlacer(), CustomiseProgramString(), Init(), and PrepareFrame().

glfilt_map_t OpenGLVideo::filters
private
long long OpenGLVideo::currentFrameNum
private

Definition at line 125 of file openglvideo.h.

Referenced by Init(), and PrepareFrame().

bool OpenGLVideo::inputUpdated
private

Definition at line 126 of file openglvideo.h.

Referenced by Init(), PrepareFrame(), SetInputUpdated(), and UpdateInputFrame().

int OpenGLVideo::refsNeeded
private

Definition at line 127 of file openglvideo.h.

Referenced by AddDeinterlacer(), PrepareFrame(), RotateTextures(), and TearDownDeinterlacer().

bool OpenGLVideo::textureRects
private

Definition at line 128 of file openglvideo.h.

Referenced by CustomiseProgramString(), GetTextureSize(), Init(), and PrepareFrame().

uint OpenGLVideo::textureType
private

Definition at line 129 of file openglvideo.h.

Referenced by AddFrameBuffer(), CreateVideoTexture(), GetTextureType(), and Init().

uint OpenGLVideo::helperTexture
private

Definition at line 130 of file openglvideo.h.

Referenced by AddFilter(), PrepareFrame(), and Teardown().

OpenGLFilterType OpenGLVideo::defaultUpsize
private

Definition at line 131 of file openglvideo.h.

Referenced by CheckResize(), and Init().

uint OpenGLVideo::gl_features
private
uint OpenGLVideo::videoTextureType
private
bool OpenGLVideo::preferYCBCR
private

Definition at line 134 of file openglvideo.h.

Referenced by Init().


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