MythTV  master
mythopenglvideo.h
Go to the documentation of this file.
1 #ifndef MYTH_OPENGL_VIDEO_H_
2 #define MYTH_OPENGL_VIDEO_H_
3 
4 // Qt
5 #include <QRect>
6 #include <QObject>
7 
8 // MythTV
9 #include "mythvideoout.h"
10 #include "videoouttypes.h"
12 #include "mythavutil.h"
13 #include "mythopenglinterop.h"
14 
15 // Std
16 #include <vector>
17 #include <map>
18 using std::vector;
19 using std::map;
20 
21 class MythOpenGLTonemap;
22 
23 class MythOpenGLVideo : public QObject
24 {
25  Q_OBJECT
26 
27  public:
29  {
30  Default = 0, // Plain blit
31  Progressive = 1, // Progressive video frame
32  InterlacedTop = 2, // Deinterlace with top field first
33  InterlacedBot = 3, // Deinterlace with bottom field first
35  };
36 
38  {
39  None = 0x000,
40  Deinterlacer = 0x001,
41  Sampling = 0x002,
42  Performance = 0x004,
43  Framebuffer = 0x008,
44  ToneMap = 0x010
45  };
46 
47  Q_DECLARE_FLAGS(VideoResizing, VideoResize)
48 
49  static QString TypeToProfile(VideoFrameType Type);
50  static QString VideoResizeToString(VideoResizing Resize);
51 
53  QSize VideoDim, QSize VideoDispDim, QRect DisplayVisibleRect,
54  QRect DisplayVideoRect, QRect videoRect,
55  bool ViewportControl, QString Profile);
56  ~MythOpenGLVideo() override;
57 
58  bool IsValid(void) const;
60  void PrepareFrame(VideoFrame *Frame, bool TopFieldFirst, FrameScanType Scan,
61  StereoscopicMode Stereo, bool DrawBorder = false);
62  void SetMasterViewport(QSize Size);
63  QSize GetVideoSize(void) const;
64  QString GetProfile() const;
65  void SetProfile(const QString &Profile);
66  void ResetFrameFormat(void);
67  void ResetTextures(void);
68 
69  signals:
70  void OutputChanged(QSize VideoDim, QSize VideoDispDim, float);
71 
72  public slots:
73  void SetVideoDimensions(const QSize &VideoDim, const QSize &VideoDispDim);
74  void SetVideoRects(const QRect &DisplayVideoRect, const QRect &VideoRect);
75  void SetViewportRect(const QRect &DisplayVisibleRect);
76  void UpdateColourSpace(bool PrimariesChanged);
77  void UpdateShaderParameters(void);
78 
79  private:
80  bool SetupFrameFormat(VideoFrameType InputType, VideoFrameType OutputType,
81  QSize Size, GLenum TextureTarget);
83  void BindTextures(bool Deinterlacing, vector<MythVideoTexture*> &Current,
84  MythGLTexture** Textures, uint &TextureCount);
86  MythDeintType Filter = DEINT_SHADER, bool CreateReferences = true);
87  QOpenGLFramebufferObject* CreateVideoFrameBuffer(VideoFrameType OutputType, QSize Size);
88  void CleanupDeinterlacers(void);
89 
90  bool m_valid { false };
91  QString m_profile;
94  MythRenderOpenGL *m_render { nullptr };
95  int m_gles { 0 };
97  QSize m_videoDim;
100  QRect m_videoRect;
102  bool m_deinterlacer2x { false };
106  QOpenGLShaderProgram* m_shaders[ShaderCount] { nullptr };
108  vector<MythVideoTexture*> m_inputTextures;
109  vector<MythVideoTexture*> m_prevTextures;
110  vector<MythVideoTexture*> m_nextTextures;
111  QOpenGLFramebufferObject* m_frameBuffer { nullptr };
114  QOpenGLFunctions::OpenGLFeatures m_features;
115  int m_extraFeatures { 0 };
116  VideoResizing m_resizing { None };
117  GLenum m_textureTarget { QOpenGLTexture::Target2D };
118  long long m_discontinuityCounter { 0 };
119  int m_lastRotation { 0 };
120  bool m_chromaUpsamplingFilter { false };
122 };
123 #endif // MYTH_OPENGL_VIDEO_H_
MythOpenGLTonemap
Definition: mythopengltonemap.h:12
MythOpenGLVideo::m_toneMap
MythOpenGLTonemap * m_toneMap
Attempt to fix Chroma Upsampling Error in shaders.
Definition: mythopenglvideo.h:121
MythOpenGLVideo::SetProfile
void SetProfile(const QString &Profile)
Definition: mythopenglvideo.cpp:162
MythOpenGLVideo::m_gles
int m_gles
Definition: mythopenglvideo.h:95
MythGLTexture
Definition: mythrenderopengl.h:44
MythOpenGLVideo::CreateVideoFrameBuffer
QOpenGLFramebufferObject * CreateVideoFrameBuffer(VideoFrameType OutputType, QSize Size)
Definition: mythopenglvideo.cpp:1083
mythvideoout.h
MythOpenGLVideo::InterlacedTop
@ InterlacedTop
Definition: mythopenglvideo.h:32
MythOpenGLVideo::Deinterlacer
@ Deinterlacer
Definition: mythopenglvideo.h:40
MythOpenGLVideo::m_prevTextures
vector< MythVideoTexture * > m_prevTextures
Previous textures with raw video data.
Definition: mythopenglvideo.h:109
DEINT_SHADER
@ DEINT_SHADER
Definition: mythframe.h:128
MythOpenGLVideo::ToneMap
@ ToneMap
Definition: mythopenglvideo.h:44
MythOpenGLVideo::m_displayVideoRect
QRect m_displayVideoRect
Sub-rect of display_visible_rect for video.
Definition: mythopenglvideo.h:99
MythOpenGLVideo::GetProfile
QString GetProfile() const
Definition: mythopenglvideo.cpp:155
MythOpenGLVideo::Framebuffer
@ Framebuffer
Definition: mythopenglvideo.h:43
mythopenglinterop.h
Frame
Definition: zmdefines.h:93
MythOpenGLVideo::None
@ None
Definition: mythopenglvideo.h:39
DEINT_NONE
@ DEINT_NONE
Definition: mythframe.h:123
MythOpenGLVideo::~MythOpenGLVideo
~MythOpenGLVideo() override
Definition: mythopenglvideo.cpp:62
MythOpenGLVideo::Performance
@ Performance
Definition: mythopenglvideo.h:42
FrameScanType
FrameScanType
Definition: videoouttypes.h:78
MythOpenGLVideo::m_resizing
VideoResizing m_resizing
Definition: mythopenglvideo.h:116
slots
unsigned int slots[4]
Definition: element.cpp:38
MythOpenGLVideo::m_frameBufferTexture
MythVideoTexture * m_frameBufferTexture
Definition: mythopenglvideo.h:112
VideoFrame
Definition: mythframe.h:137
MythOpenGLVideo::SetViewportRect
void SetViewportRect(const QRect &DisplayVisibleRect)
Definition: mythopenglvideo.cpp:150
MythOpenGLVideo::SetupFrameFormat
bool SetupFrameFormat(VideoFrameType InputType, VideoFrameType OutputType, QSize Size, GLenum TextureTarget)
Definition: mythopenglvideo.cpp:506
MythOpenGLVideo::SetVideoRects
void SetVideoRects(const QRect &DisplayVideoRect, const QRect &VideoRect)
Definition: mythopenglvideo.cpp:144
MythOpenGLVideo::ResetTextures
void ResetTextures(void)
Clear reference frames after a seek as they will contain old images.
Definition: mythopenglvideo.cpp:1015
MythOpenGLVideo::m_fallbackDeinterlacer
MythDeintType m_fallbackDeinterlacer
Only used if there are insufficient texture units (for kernel)
Definition: mythopenglvideo.h:103
MythOpenGLVideo::m_frameBuffer
QOpenGLFramebufferObject * m_frameBuffer
Definition: mythopenglvideo.h:111
FMT_NONE
@ FMT_NONE
Definition: mythframe.h:26
mythrenderopengl.h
MythOpenGLVideo::m_features
QOpenGLFunctions::OpenGLFeatures m_features
Default features available from Qt.
Definition: mythopenglvideo.h:114
MythOpenGLVideo::VideoResize
VideoResize
Definition: mythopenglvideo.h:37
MythOpenGLVideo::m_viewportControl
bool m_viewportControl
Video has control over view port.
Definition: mythopenglvideo.h:105
MythOpenGLVideo::m_inputType
VideoFrameType m_inputType
Usually YV12 for software, VDPAU etc for hardware.
Definition: mythopenglvideo.h:92
MythOpenGLVideo::GetVideoSize
QSize GetVideoSize(void) const
Definition: mythopenglvideo.cpp:167
videoouttypes.h
kScan_Progressive
@ kScan_Progressive
Definition: videoouttypes.h:84
MythOpenGLVideo::InterlacedBot
@ InterlacedBot
Definition: mythopenglvideo.h:33
MythOpenGLVideo::ProcessFrame
void ProcessFrame(VideoFrame *Frame, FrameScanType Scan=kScan_Progressive)
Update the current input texture using the data from the given video frame.
Definition: mythopenglvideo.cpp:586
MythOpenGLVideo::TypeToProfile
static QString TypeToProfile(VideoFrameType Type)
Definition: mythopenglvideo.cpp:1058
MythOpenGLVideo::MythOpenGLVideo
MythOpenGLVideo(MythRenderOpenGL *Render, VideoColourSpace *ColourSpace, QSize VideoDim, QSize VideoDispDim, QRect DisplayVisibleRect, QRect DisplayVideoRect, QRect videoRect, bool ViewportControl, QString Profile)
Definition: mythopenglvideo.cpp:26
MythOpenGLVideo::m_chromaUpsamplingFilter
bool m_chromaUpsamplingFilter
Definition: mythopenglvideo.h:120
MythOpenGLVideo::m_textureTarget
GLenum m_textureTarget
Some interops require custom texture targets.
Definition: mythopenglvideo.h:117
MythOpenGLVideo::m_shaders
QOpenGLShaderProgram * m_shaders[ShaderCount]
Definition: mythopenglvideo.h:106
MythOpenGLVideo::Progressive
@ Progressive
Definition: mythopenglvideo.h:31
MythOpenGLVideo::m_inputTextures
vector< MythVideoTexture * > m_inputTextures
Current textures with raw video data.
Definition: mythopenglvideo.h:108
MythOpenGLVideo::CleanupDeinterlacers
void CleanupDeinterlacers(void)
Definition: mythopenglvideo.cpp:172
uint
unsigned int uint
Definition: compat.h:140
MythOpenGLVideo::OutputChanged
void OutputChanged(QSize VideoDim, QSize VideoDispDim, float)
MythOpenGLVideo::VideoShaderType
VideoShaderType
Definition: mythopenglvideo.h:28
MythOpenGLVideo::m_lastRotation
int m_lastRotation
Track rotation for pause frame.
Definition: mythopenglvideo.h:119
MythOpenGLVideo::UpdateColourSpace
void UpdateColourSpace(bool PrimariesChanged)
Definition: mythopenglvideo.cpp:82
StereoscopicMode
StereoscopicMode
Definition: videoouttypes.h:118
MythOpenGLVideo::m_valid
bool m_valid
Definition: mythopenglvideo.h:90
MythRenderOpenGL
Definition: mythrenderopengl.h:86
MythOpenGLVideo::Default
@ Default
Definition: mythopenglvideo.h:30
VideoColourSpace
VideoColourSpace contains a QMatrix4x4 that can convert YCbCr data to RGB.
Definition: videocolourspace.h:17
MythDeintType
MythDeintType
Definition: mythframe.h:121
MythOpenGLVideo::ShaderCount
@ ShaderCount
Definition: mythopenglvideo.h:34
MythOpenGLVideo::AddDeinterlacer
bool AddDeinterlacer(const VideoFrame *Frame, FrameScanType Scan, MythDeintType Filter=DEINT_SHADER, bool CreateReferences=true)
Definition: mythopenglvideo.cpp:194
MythOpenGLVideo::ResetFrameFormat
void ResetFrameFormat(void)
Definition: mythopenglvideo.cpp:561
MythOpenGLVideo::SetMasterViewport
void SetMasterViewport(QSize Size)
Definition: mythopenglvideo.cpp:133
MythOpenGLVideo
Definition: mythopenglvideo.h:23
MythOpenGLVideo::CreateVideoShader
bool CreateVideoShader(VideoShaderType Type, MythDeintType Deint=DEINT_NONE)
Create the appropriate shader for the operation Type.
Definition: mythopenglvideo.cpp:334
MythOpenGLVideo::m_masterViewportSize
QSize m_masterViewportSize
Current viewport into which OpenGL is rendered, usually the window size.
Definition: mythopenglvideo.h:98
MythOpenGLVideo::m_discontinuityCounter
long long m_discontinuityCounter
Check when to release reference frames after a skip.
Definition: mythopenglvideo.h:118
MythOpenGLVideo::m_videoDispDim
QSize m_videoDispDim
Useful video frame size e.g. 1920x1080.
Definition: mythopenglvideo.h:96
MythOpenGLVideo::m_shaderCost
int m_shaderCost[ShaderCount]
Definition: mythopenglvideo.h:107
MythOpenGLVideo::SetVideoDimensions
void SetVideoDimensions(const QSize &VideoDim, const QSize &VideoDispDim)
Definition: mythopenglvideo.cpp:138
MythOpenGLVideo::m_deinterlacer2x
bool m_deinterlacer2x
Definition: mythopenglvideo.h:102
mythavutil.h
MythOpenGLVideo::VideoResizeToString
static QString VideoResizeToString(VideoResizing Resize)
Definition: mythopenglvideo.cpp:1073
MythOpenGLVideo::IsValid
bool IsValid(void) const
Definition: mythopenglvideo.cpp:77
MythOpenGLVideo::PrepareFrame
void PrepareFrame(VideoFrame *Frame, bool TopFieldFirst, FrameScanType Scan, StereoscopicMode Stereo, bool DrawBorder=false)
Definition: mythopenglvideo.cpp:687
MythOpenGLVideo::m_profile
QString m_profile
Definition: mythopenglvideo.h:91
MythOpenGLVideo::m_inputTextureSize
QSize m_inputTextureSize
Actual size of input texture(s)
Definition: mythopenglvideo.h:113
MythOpenGLVideo::BindTextures
void BindTextures(bool Deinterlacing, vector< MythVideoTexture * > &Current, MythGLTexture **Textures, uint &TextureCount)
Definition: mythopenglvideo.cpp:1025
VideoFrameType
VideoFrameType
Definition: mythframe.h:24
MythOpenGLVideo::m_extraFeatures
int m_extraFeatures
OR'd list of extra, Myth specific features.
Definition: mythopenglvideo.h:115
MythOpenGLVideo::m_nextTextures
vector< MythVideoTexture * > m_nextTextures
Next textures with raw video data.
Definition: mythopenglvideo.h:110
MythOpenGLVideo::Sampling
@ Sampling
Definition: mythopenglvideo.h:41
MythVideoTexture
Definition: mythvideotexture.h:20
MythOpenGLVideo::m_deinterlacer
MythDeintType m_deinterlacer
Definition: mythopenglvideo.h:101
MythOpenGLVideo::m_videoRect
QRect m_videoRect
Sub-rect of video_disp_dim to display (after zoom adjustments etc)
Definition: mythopenglvideo.h:100
MythOpenGLVideo::m_videoDim
QSize m_videoDim
Total video frame size e.g. 1920x1088.
Definition: mythopenglvideo.h:97
MythOpenGLVideo::m_videoColourSpace
VideoColourSpace * m_videoColourSpace
Definition: mythopenglvideo.h:104
MythOpenGLVideo::UpdateShaderParameters
void UpdateShaderParameters(void)
Definition: mythopenglvideo.cpp:108
MythOpenGLVideo::m_render
MythRenderOpenGL * m_render
Definition: mythopenglvideo.h:94
MythOpenGLVideo::m_outputType
VideoFrameType m_outputType
Set by profile for software or decoder for hardware.
Definition: mythopenglvideo.h:93