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