MythTV master
mythopenglinterop.cpp
Go to the documentation of this file.
1// MythTV
4
5#include "mythplayerui.h"
8
9#if CONFIG_VAAPI
10#include "mythvaapiinterop.h"
11#endif
12#if CONFIG_VIDEOTOOLBOX
13#include "mythvtbinterop.h"
14#endif
15#if CONFIG_MEDIACODEC
17#endif
18#if CONFIG_VDPAU
19#include "mythvdpauinterop.h"
20#endif
21#if CONFIG_NVDEC
22#include "mythnvdecinterop.h"
23#endif
24#if CONFIG_MMAL
25#include "mythmmalinterop.h"
26#endif
27#if CONFIG_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#if CONFIG_MEDIACODEC
40 Types[FMT_MEDIACODEC] = { GL_MEDIACODEC };
41#endif
42
43#if CONFIG_VDPAU
44 MythVDPAUInterop::GetVDPAUTypes(openglrender, Types);
45#endif
46
47#if CONFIG_VAAPI
48 MythVAAPIInterop::GetVAAPITypes(openglrender, Types);
49#endif
50
51#if CONFIG_EGL
52 MythDRMPRIMEInterop::GetDRMTypes(openglrender, Types);
53#endif
54
55#if CONFIG_MMAL
56 MythMMALInterop::GetMMALTypes(openglrender, Types);
57#endif
58
59#if CONFIG_VIDEOTOOLBOX
60 MythVTBInterop::GetVTBTypes(openglrender, Types);
61#endif
62
63#if CONFIG_NVDEC
64 MythNVDECInterop::GetNVDECTypes(openglrender, Types);
65#endif
66}
67
68std::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
130std::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}
static VideoFrameType PixelFormatToFrameType(AVPixelFormat Fmt)
Definition: mythavutil.cpp:72
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