MythTV  master
Go to the documentation of this file.
1 #ifndef _OPENGL_VIDEO_H__
2 #define _OPENGL_VIDEO_H__
4 #include <vector>
5 #include <map>
6 using std::vector;
7 using std::map;
9 #include <QRect>
11 #include "videooutbase.h"
12 #include "videoouttypes.h"
13 #include "mythrender_opengl.h"
14 #include "mythavutil.h"
15 #include "util-opengl.h"
17 class OpenGLFilter;
20 {
22  {
25  // Conversion filters
29  // Frame scaling/resizing filters
32  };
33  typedef map<OpenGLFilterType,OpenGLFilter*> glfilt_map_t;
35  public:
36  enum VideoType
37  {
38  kGLGPU, // Frame is already in GPU memory
39  kGLYCbCr, // Use Mesa or Apple YCbCr extensions (UYVY) - 16bpp
40  kGLUYVY, // CPU conversion to UYVY422 format - 16bpp
41  kGLYV12, // All processing on GPU - 12bpp
42  kGLHQUYV, // High quality interlaced CPU conversion to UYV - 32bpp
43  kGLRGBA // fallback software YV12 to RGB - 32bpp
44  };
46  OpenGLVideo();
47  ~OpenGLVideo();
49  bool Init(MythRenderOpenGL *glcontext, VideoColourSpace *colourspace,
50  QSize videoDim, QSize videoDispDim, QRect displayVisibleRect,
51  QRect displayVideoRect, QRect videoRect,
52  bool viewport_control, VideoType type,
53  const QString& options);
55  uint GetInputTexture(void) const;
56  uint GetTextureType(void) const;
57  void SetInputUpdated(void);
58  void UpdateInputFrame(const VideoFrame *frame, bool soft_bob = false);
61  bool AddFilter(const QString &filter)
62  { return AddFilter(StringToFilter(filter)); }
63  bool RemoveFilter(const QString &filter)
64  { return RemoveFilter(StringToFilter(filter)); }
66  bool AddDeinterlacer(const QString &deinterlacer);
67  void SetDeinterlacing(bool deinterlacing);
68  QString GetDeinterlacer(void) const
69  { return hardwareDeinterlacer; }
70  void SetSoftwareDeinterlacer(const QString &filter);
72  void PrepareFrame(bool topfieldfirst, FrameScanType scan,
73  bool softwareDeinterlacing,
74  long long frame, StereoscopicMode stereo,
75  bool draw_border = false);
77  void SetMasterViewport(QSize size) { masterViewportSize = size; }
78  QSize GetViewPort(void) const { return viewportSize; }
79  void SetVideoRect(const QRect &dispvidrect, const QRect &vidrect);
80  QSize GetVideoSize(void) const { return video_dim;}
81  static VideoType StringToType(const QString &Type);
82  static QString TypeToString(VideoType Type);
83  VideoType GetType() { return videoType; }
85  private:
86  void Teardown(void);
87  void SetViewPort(const QSize &viewPortSize);
88  bool AddFilter(OpenGLFilterType filter);
89  bool RemoveFilter(OpenGLFilterType filter);
90  void CheckResize(bool deinterlacing, bool allow = true);
91  bool OptimiseFilters(void);
92  bool AddFrameBuffer(uint &framebuffer, uint &texture, QSize vid_size);
94  const QString& deint = QString(),
96  uint CreateVideoTexture(QSize size, QSize &tex_size);
98  const QString& deint = QString(),
100  void GetProgramStrings(QString &vertex, QString &fragment,
101  OpenGLFilterType filter,
102  const QString& deint = QString(),
104  void CustomiseProgramString(QString &string);
105  static QString FilterToString(OpenGLFilterType filter);
106  static OpenGLFilterType StringToFilter(const QString &filter);
107  QSize GetTextureSize(const QSize &size);
108  void SetFiltering(void);
110  void RotateTextures(void);
111  void SetTextureFilters(vector<GLuint> *textures, int filt, int wrap);
112  void DeleteTextures(vector<GLuint> *textures);
113  void TearDownDeinterlacer(void);
118  QSize video_dim;
119  QSize viewportSize;
123  QRect video_rect;
130  vector<GLuint> referenceTextures;
131  vector<GLuint> inputTextures;
134  long long currentFrameNum;
143  bool forceResize;
144 };
145 #endif // _OPENGL_VIDEO_H__
void GetProgramStrings(QString &vertex, QString &fragment, OpenGLFilterType filter, const QString &deint=QString(), FrameScanType field=kScan_Progressive)
def scan(profile, smoonURL, gate)
void CustomiseProgramString(QString &string)
QRect frameBufferRect
Rect version of video_disp_dim.
Definition: openglvideo.h:124
void UpdateInputFrame(const VideoFrame *frame, bool soft_bob=false)
Update the current input texture using the data from the given YV12 video frame.
bool Init(MythRenderOpenGL *glcontext, VideoColourSpace *colourspace, QSize videoDim, QSize videoDispDim, QRect displayVisibleRect, QRect displayVideoRect, QRect videoRect, bool viewport_control, VideoType type, const QString &options)
QRect video_rect
Sub-rect of video_disp_dim to display (after zoom adjustments etc)
Definition: openglvideo.h:123
void SetVideoRect(const QRect &dispvidrect, const QRect &vidrect)
QRect display_visible_rect
Total useful, visible rectangle.
Definition: openglvideo.h:121
MythAVCopy Copy AVFrame<->frame, performing the required conversion if any.
Definition: mythavutil.h:114
uint GetInputTexture(void) const
uint helperTexture
Extra texture for bicubic filter.
Definition: openglvideo.h:139
QSize video_dim
Total video frame size e.g. 1920x1088.
Definition: openglvideo.h:118
Definition: videoouttypes.h:80
bool AddDeinterlacer(const QString &deinterlacer)
Extends the functionality of the basic YUV->RGB filter stage to include deinterlacing (combining the ...
unsigned int uint
Definition: compat.h:140
void SetSoftwareDeinterlacer(const QString &filter)
glfilt_map_t filters
Filter stages to be applied to frame.
Definition: openglvideo.h:133
QString GetProgramString(OpenGLFilterType name, const QString &deint=QString(), FrameScanType field=kScan_Progressive)
bool textureRects
OpenGLVideo is using rectangular textures.
Definition: openglvideo.h:137
void SetDeinterlacing(bool deinterlacing)
uint GetTextureType(void) const
QSize GetTextureSize(const QSize &size)
MythRenderOpenGL * gl_context
Definition: openglvideo.h:116
static OpenGLFilterType StringToFilter(const QString &filter)
int refsNeeded
Number of reference textures expected.
Definition: openglvideo.h:136
QRect display_video_rect
Sub-rect of display_visible_rect for video.
Definition: openglvideo.h:122
VideoType GetType()
Definition: openglvideo.h:83
uint CreateVideoTexture(QSize size, QSize &tex_size)
Create and initialise an OpenGL texture suitable for a YV12 video frame of the given size.
QSize GetVideoSize(void) const
Definition: openglvideo.h:80
vector< GLuint > inputTextures
Textures with raw video data.
Definition: openglvideo.h:131
vector< GLuint > referenceTextures
Up to 3 reference textures for filters.
Definition: openglvideo.h:130
void SetViewPort(const QSize &viewPortSize)
bool inputUpdated
Input texture has been refreshed with new data.
Definition: openglvideo.h:135
uint gl_features
OR'd list of GLFeatures in use.
Definition: openglvideo.h:141
uint textureType
Texture type (e.g. GL_TEXTURE_2D or GL_TEXTURE_RECT)
Definition: openglvideo.h:138
static QString FilterToString(OpenGLFilterType 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 filte...
MythAVCopy m_copyCtx
Conversion context for YV12 to UYVY.
Definition: openglvideo.h:142
QSize viewportSize
Can be removed.
Definition: openglvideo.h:119
bool forceResize
Global setting to force a resize stage.
Definition: openglvideo.h:143
const char * name
Definition: ParseText.cpp:328
QSize GetViewPort(void) const
Definition: openglvideo.h:78
QSize inputTextureSize
Actual size of input texture(s)
Definition: openglvideo.h:132
QString hardwareDeinterlacer
Definition: openglvideo.h:126
A class used to display video frames and associated imagery using the OpenGL API.
Definition: openglvideo.h:19
bool AddFilter(const QString &filter)
Public interface to AddFilter(OpenGLFilterType filter)
Definition: openglvideo.h:61
QString softwareDeinterlacer
Definition: openglvideo.h:125
void Teardown(void)
Definition: openglvideo.cpp:89
QSize video_disp_dim
Useful video frame size e.g. 1920x1080.
Definition: openglvideo.h:117
void DeleteTextures(vector< GLuint > *textures)
void SetInputUpdated(void)
VideoColourSpace * colourSpace
Definition: openglvideo.h:128
QSize masterViewportSize
Current viewport into which OpenGL is rendered.
Definition: openglvideo.h:120
QString GetDeinterlacer(void) const
Definition: openglvideo.h:68
bool viewportControl
Video has control over view port.
Definition: openglvideo.h:129
void SetMasterViewport(QSize size)
Definition: openglvideo.h:77
static QString TypeToString(VideoType Type)
bool OptimiseFilters(void)
Ensure the current chain of OpenGLFilters is logically correct and has the resources required to comp...
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 necess...
bool AddFrameBuffer(uint &framebuffer, uint &texture, QSize vid_size)
Add a FrameBuffer object of the correct size to the given texture.
map< OpenGLFilterType, OpenGLFilter * > glfilt_map_t
Definition: openglvideo.h:33
void SetFiltering(void)
Set the OpenGL texture mapping functions to optimise speed and quality.
bool RemoveFilter(const QString &filter)
Definition: openglvideo.h:63
long long currentFrameNum
Can be removed.
Definition: openglvideo.h:134
VideoType videoType
Definition: openglvideo.h:115
void SetTextureFilters(vector< GLuint > *textures, int filt, int wrap)
uint AddFragmentProgram(OpenGLFilterType name, const QString &deint=QString(), FrameScanType field=kScan_Progressive)
Create the correct fragment program for the given filter type.
void RotateTextures(void)
void TearDownDeinterlacer(void)
OpenGLFilterType defaultUpsize
Regular or bicubic upsizing.
Definition: openglvideo.h:140
static VideoType StringToType(const QString &Type)
Create a new OpenGLVideo instance that must be initialised with a call to OpenGLVideo::Init()
Definition: openglvideo.cpp:66
bool hardwareDeinterlacing
OpenGL deinterlacing is enabled.
Definition: openglvideo.h:127