OpenGLVideo Class Reference

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

#include <openglvideo.h>

List of all members.

Public Member Functions

 OpenGLVideo ()
 Create a new OpenGLVideo instance that must be initialised with a call to OpenGLVideo::Init().
 ~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.
bool AddFilter (const QString &filter)
 Public interface to AddFilter(OpenGLFilterType filter).
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).
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)
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.
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.
bool OptimiseFilters (void)
 Ensure the current chain of OpenGLFilters is logically correct and has the resources required to complete rendering.
bool AddFrameBuffer (uint &framebuffer, uint &texture, QSize vid_size)
 Add a FrameBuffer object of the correct size to the given texture.
uint AddFragmentProgram (OpenGLFilterType name, QString deint=QString::null, FrameScanType field=kScan_Progressive)
 Create the correct fragment program for the given filter type.
uint CreateVideoTexture (QSize size, QSize &tex_size)
 Create and initialise an OpenGL texture suitable for a YV12 video frame of the given size.
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.
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 
)

Definition at line 126 of file openglvideo.cpp.

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

uint OpenGLVideo::GetInputTexture ( void   )  const

Definition at line 770 of file openglvideo.cpp.

Referenced by VideoOutputOpenGLVAAPI::ProcessFrame().

uint OpenGLVideo::GetTextureType ( void   )  const

Definition at line 775 of file openglvideo.cpp.

Referenced by VideoOutputOpenGLVAAPI::ProcessFrame().

void OpenGLVideo::SetInputUpdated ( void   ) 

Definition at line 780 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 792 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 AddFilter(), CheckResize(), and Init().

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

Definition at line 57 of file openglvideo.h.

Referenced by AddFilter(), CheckResize(), RemoveFilter(), 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 561 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 
)

Definition at line 877 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 697 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 501 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 678 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 648 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 717 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 1278 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 1577 of file openglvideo.cpp.

Referenced by AddFragmentProgram().

void OpenGLVideo::CustomiseProgramString ( QString &  string  )  [private]

Definition at line 1355 of file openglvideo.cpp.

Referenced by GetProgramString(), and GetProgramStrings().

QString OpenGLVideo::FilterToString ( OpenGLFilterType  filter  )  [static, private]

Definition at line 1127 of file openglvideo.cpp.

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

OpenGLFilterType OpenGLVideo::StringToFilter ( const QString &  filter  )  [static, private]

Definition at line 1113 of file openglvideo.cpp.

Referenced by AddFilter(), and RemoveFilter().

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

Definition at line 749 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 1076 of file openglvideo.cpp.

Referenced by UpdateInputFrame().

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

Definition at line 1103 of file openglvideo.cpp.

Referenced by SetFiltering().

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

Definition at line 1093 of file openglvideo.cpp.

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

void OpenGLVideo::TearDownDeinterlacer ( void   )  [private]

Definition at line 530 of file openglvideo.cpp.

Referenced by AddDeinterlacer().


Member Data Documentation

QSize OpenGLVideo::video_disp_dim [private]
QSize OpenGLVideo::video_dim [private]

Definition at line 109 of file openglvideo.h.

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

QSize OpenGLVideo::viewportSize [private]

Definition at line 110 of file openglvideo.h.

Referenced by GetViewPort(), and SetViewPort().

Definition at line 111 of file openglvideo.h.

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

Definition at line 112 of file openglvideo.h.

Referenced by Init(), and PrepareFrame().

Definition at line 113 of file openglvideo.h.

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

QRect OpenGLVideo::video_rect [private]

Definition at line 114 of file openglvideo.h.

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

Definition at line 115 of file openglvideo.h.

Referenced by Init(), and PrepareFrame().

Definition at line 116 of file openglvideo.h.

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

Definition at line 117 of file openglvideo.h.

Referenced by AddDeinterlacer(), GetDeinterlacer(), and PrepareFrame().

Definition at line 119 of file openglvideo.h.

Referenced by Init(), and PrepareFrame().

Definition at line 120 of file openglvideo.h.

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

vector<GLuint> OpenGLVideo::referenceTextures [private]
vector<GLuint> OpenGLVideo::inputTextures [private]

Definition at line 123 of file openglvideo.h.

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

long long OpenGLVideo::currentFrameNum [private]

Definition at line 125 of file openglvideo.h.

Referenced by Init(), and PrepareFrame().

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().

Definition at line 128 of file openglvideo.h.

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

Definition at line 129 of file openglvideo.h.

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

Definition at line 130 of file openglvideo.h.

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

Definition at line 131 of file openglvideo.h.

Referenced by CheckResize(), and Init().

Definition at line 134 of file openglvideo.h.

Referenced by Init().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends
Generated on Mon May 28 06:42:19 2012 for MythTV by  doxygen 1.6.3