MythTV  master
mythopenglinterop.cpp
Go to the documentation of this file.
1 // MythTV
2 #include "mythplayerui.h"
3 #include "mythcorecontext.h"
4 #include "mythvideocolourspace.h"
7 
8 #ifdef USING_VAAPI
9 #include "mythvaapiinterop.h"
10 #endif
11 #ifdef USING_VTB
12 #include "mythvtbinterop.h"
13 #endif
14 #ifdef USING_MEDIACODEC
15 #include "mythmediacodeccontext.h"
16 #endif
17 #ifdef USING_VDPAU
18 #include "mythvdpauinterop.h"
19 #endif
20 #ifdef USING_NVDEC
21 #include "mythnvdecinterop.h"
22 #endif
23 #ifdef USING_MMAL
24 #include "mythmmalinterop.h"
25 #endif
26 #ifdef USING_EGL
27 #include "mythdrmprimeinterop.h"
28 #endif
29 
30 #define LOC QString("OpenGLInterop: ")
31 
33 {
34  auto * openglrender = dynamic_cast<MythRenderOpenGL*>(Render);
35  if (!openglrender)
36  return;
37 
38 #ifdef USING_MEDIACODEC
39  Types[FMT_MEDIACODEC] = { GL_MEDIACODEC };
40 #endif
41 
42 #ifdef USING_VDPAU
43  MythVDPAUInterop::GetVDPAUTypes(openglrender, Types);
44 #endif
45 
46 #ifdef USING_VAAPI
47  MythVAAPIInterop::GetVAAPITypes(openglrender, Types);
48 #endif
49 
50 #ifdef USING_EGL
51  MythDRMPRIMEInterop::GetDRMTypes(openglrender, Types);
52 #endif
53 
54 #ifdef USING_MMAL
55  MythMMALInterop::GetMMALTypes(openglrender, Types);
56 #endif
57 
58 #ifdef USING_VTB
59  MythVTBInterop::GetVTBTypes(openglrender, Types);
60 #endif
61 
62 #ifdef USING_NVDEC
63  MythNVDECInterop::GetNVDECTypes(openglrender, Types);
64 #endif
65 }
66 
67 vector<MythVideoTextureOpenGL*> MythOpenGLInterop::Retrieve(MythRenderOpenGL *Context,
68  MythVideoColourSpace *ColourSpace,
70  FrameScanType Scan)
71 {
72  vector<MythVideoTextureOpenGL*> result;
73  if (!(Context && Frame))
74  return result;
75 
76  if (!(Frame->m_priv[1] && MythVideoFrame::HardwareFormat(Frame->m_type) &&
77  (Frame->m_type == MythAVUtil::PixelFormatToFrameType(static_cast<AVPixelFormat>(Frame->m_pixFmt)))))
78  {
79  LOG(VB_GENERAL, LOG_WARNING, LOC + "Not a valid hardware frame");
80  return result;
81  }
82 
83  MythOpenGLInterop* interop = nullptr;
84  if ((Frame->m_type == FMT_VTB) || (Frame->m_type == FMT_MEDIACODEC) ||
85  (Frame->m_type == FMT_MMAL) || (Frame->m_type == FMT_DRMPRIME))
86  {
87  interop = reinterpret_cast<MythOpenGLInterop*>(Frame->m_priv[1]);
88  }
89  else
90  {
91  // Unpick
92  auto* buffer = reinterpret_cast<AVBufferRef*>(Frame->m_priv[1]);
93  if (!buffer || !buffer->data)
94  return result;
95  if (Frame->m_type == FMT_NVDEC)
96  {
97  auto* context = reinterpret_cast<AVHWDeviceContext*>(buffer->data);
98  if (!context || !context->user_opaque)
99  return result;
100  interop = reinterpret_cast<MythOpenGLInterop*>(context->user_opaque);
101  }
102  else
103  {
104  auto* frames = reinterpret_cast<AVHWFramesContext*>(buffer->data);
105  if (!frames || !frames->user_opaque)
106  return result;
107  interop = reinterpret_cast<MythOpenGLInterop*>(frames->user_opaque);
108  }
109  }
110 
111  if (interop)
112  return interop->Acquire(Context, ColourSpace, Frame, Scan);
113  LOG(VB_GENERAL, LOG_ERR, LOC + "No OpenGL interop found");
114  return result;
115 }
116 
118  : MythInteropGPU(Context, Type, Player),
119  m_openglContext(Context)
120 {
121 }
122 
124 {
126 }
127 
128 vector<MythVideoTextureOpenGL*> MythOpenGLInterop::Acquire(MythRenderOpenGL* /*Context*/,
129  MythVideoColourSpace* /*ColourSpace*/,
130  MythVideoFrame* /*Frame*/, FrameScanType /*Scan*/)
131 {
132  return vector<MythVideoTextureOpenGL*>();
133 }
134 
136 {
137  if (m_openglContext && !m_openglTextures.isEmpty())
138  {
140  int count = 0;
141  for (auto it = m_openglTextures.constBegin(); it != m_openglTextures.constEnd(); ++it)
142  {
143  vector<MythVideoTextureOpenGL*> textures = it.value();
144  for (auto & texture : textures)
145  {
146  if (texture->m_textureId)
147  m_openglContext->glDeleteTextures(1, &texture->m_textureId);
149  count++;
150  }
151  textures.clear();
152  }
153  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Deleted %1 textures in %2 groups")
154  .arg(count).arg(m_openglTextures.size()));
155  m_openglTextures.clear();
156  }
157 }
FMT_MEDIACODEC
@ FMT_MEDIACODEC
Definition: mythframe.h:61
MythNVDECInterop::GetNVDECTypes
static void GetNVDECTypes(MythRenderOpenGL *Render, MythInteropGPU::InteropMap &Types)
Definition: mythnvdecinterop.cpp:94
mythvaapiinterop.h
mythplayerui.h
mythvdpauinterop.h
MythInteropGPU::GL_MEDIACODEC
@ GL_MEDIACODEC
Definition: mythinteropgpu.h:34
FMT_VTB
@ FMT_VTB
Definition: mythframe.h:62
MythDRMPRIMEInterop::GetDRMTypes
static void GetDRMTypes(MythRenderOpenGL *Render, MythInteropGPU::InteropMap &Types)
Definition: mythdrmprimeinterop.cpp:77
FMT_DRMPRIME
@ FMT_DRMPRIME
Definition: mythframe.h:64
mythopenglinterop.h
MythVAAPIInterop::GetVAAPITypes
static void GetVAAPITypes(MythRenderOpenGL *Context, MythInteropGPU::InteropMap &Types)
Return a list of interops that are supported by the current render device.
Definition: mythvaapiinterop.cpp:38
Frame
Definition: zmdefines.h:93
FrameScanType
FrameScanType
Definition: videoouttypes.h:94
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythVideoFrame::HardwareFormat
static bool HardwareFormat(VideoFrameType Type)
Definition: mythframe.h:425
MythOpenGLInterop::~MythOpenGLInterop
~MythOpenGLInterop() override
Definition: mythopenglinterop.cpp:123
MythInteropGPU::InteropMap
std::map< VideoFrameType, InteropTypes > InteropMap
Definition: mythinteropgpu.h:45
MythVTBInterop::GetVTBTypes
static void GetVTBTypes(MythRenderOpenGL *Render, MythInteropGPU::InteropMap &Types)
Definition: mythvtbinterop.cpp:9
mythrenderopengl.h
MythPlayerUI
Definition: mythplayerui.h:10
MythMMALInterop::GetMMALTypes
static void GetMMALTypes(MythRenderOpenGL *Render, MythInteropGPU::InteropMap &Types)
Definition: mythmmalinterop.cpp:25
mythvideocolourspace.h
MythOpenGLInterop
Definition: mythopenglinterop.h:17
MythOpenGLInterop::m_openglTextures
QHash< unsigned long long, vector< MythVideoTextureOpenGL * > > m_openglTextures
Definition: mythopenglinterop.h:39
MythOpenGLInterop::m_openglContext
MythRenderOpenGL * m_openglContext
Definition: mythopenglinterop.h:38
MythVideoTextureOpenGL::DeleteTexture
static void DeleteTexture(MythRenderOpenGL *Context, MythVideoTextureOpenGL *Texture)
Definition: mythvideotextureopengl.cpp:17
mythvtbinterop.h
mythmmalinterop.h
mythmediacodeccontext.h
MythOpenGLInterop::Retrieve
static vector< MythVideoTextureOpenGL * > Retrieve(MythRenderOpenGL *Context, MythVideoColourSpace *ColourSpace, MythVideoFrame *Frame, FrameScanType Scan)
Definition: mythopenglinterop.cpp:67
MythAVUtil::PixelFormatToFrameType
static VideoFrameType PixelFormatToFrameType(AVPixelFormat Fmt)
Definition: mythavutil.cpp:70
LOC
#define LOC
Definition: mythopenglinterop.cpp:30
FMT_NVDEC
@ FMT_NVDEC
Definition: mythframe.h:63
MythRenderOpenGL
Definition: mythrenderopengl.h:99
MythOpenGLInterop::MythOpenGLInterop
MythOpenGLInterop(MythRenderOpenGL *Context, InteropType Type, MythPlayerUI *Player=nullptr)
Definition: mythopenglinterop.cpp:117
mythcorecontext.h
MythRender
Definition: mythrender_base.h:23
MythOpenGLInterop::DeleteTextures
virtual void DeleteTextures()
Definition: mythopenglinterop.cpp:135
mythdrmprimeinterop.h
mythnvdecinterop.h
FMT_MMAL
@ FMT_MMAL
Definition: mythframe.h:60
Player
Definition: zmliveplayer.h:34
MythVideoFrame
Definition: mythframe.h:88
MythInteropGPU::InteropType
InteropType
Definition: mythinteropgpu.h:26
MythOpenGLInterop::Acquire
virtual vector< MythVideoTextureOpenGL * > Acquire(MythRenderOpenGL *Context, MythVideoColourSpace *ColourSpace, MythVideoFrame *Frame, FrameScanType Scan)
Definition: mythopenglinterop.cpp:128
MythVideoColourSpace
MythVideoColourSpace contains a QMatrix4x4 that can convert YCbCr data to RGB.
Definition: mythvideocolourspace.h:18
MythOpenGLInterop::GetTypes
static void GetTypes(MythRender *Render, MythInteropGPU::InteropMap &Types)
Definition: mythopenglinterop.cpp:32
MythVDPAUInterop::GetVDPAUTypes
static void GetVDPAUTypes(MythRenderOpenGL *Render, MythInteropGPU::InteropMap &Types)
Definition: mythvdpauinterop.cpp:25
MythInteropGPU
Definition: mythinteropgpu.h:21
OpenGLLocker
Definition: mythrenderopengl.h:261