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