7#define LOC QString("VTBInterop: ")
11 if (Render->isOpenGLES() || Render->
IsEGL())
14 if (Render->hasExtension(
"GL_ARB_texture_rg"))
29 for (
auto type : vtb->second)
52 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"Mismatched OpenGL contexts");
55 QSize surfacesize(
Frame->m_width,
Frame->m_height);
60 LOG(VB_GENERAL, LOG_WARNING,
LOC + QString(
"Video texture size changed! %1x%2->%3x%4")
78 return reinterpret_cast<CVPixelBufferRef
>(
Frame->m_buffer);
81std::vector<MythVideoTextureOpenGL*>
87 std::vector<MythVideoTextureOpenGL*> result;
90 CVPixelBufferRef buffer =
Verify(Context, ColourSpace,
Frame);
100 int planes = CVPixelBufferGetPlaneCount(buffer);
101 CVPixelBufferLockBaseAddress(buffer, kCVPixelBufferLock_ReadOnly);
111 for (
int plane = 0; plane < planes; ++plane)
113 int width = CVPixelBufferGetWidthOfPlane(buffer, plane);
114 int height = CVPixelBufferGetHeightOfPlane(buffer, plane);
115 QSize size(width, height);
124 result.push_back(texture);
128 if (result.size() !=
static_cast<uint>(planes))
129 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to create all textures");
139 for (
int plane = 0; plane < planes; ++plane)
141 if (
static_cast<uint>(plane) >= result.size())
144 int width = CVPixelBufferGetWidthOfPlane(buffer, plane);
145 int height = CVPixelBufferGetHeightOfPlane(buffer, plane);
146 int bytes = CVPixelBufferGetBytesPerRowOfPlane(buffer, plane) / width;
147 void* buf = CVPixelBufferGetBaseAddressOfPlane(buffer, plane);
148 result[plane]->m_texture->bind();
149 if ((
bytes == 1) && buf)
151 m_openglContext->glTexImage2D(QOpenGLTexture::Target2D, 0, QOpenGLTexture::RGBA, width, height,
152 0, QOpenGLTexture::Red, QOpenGLTexture::UInt8, buf);
154 else if ((
bytes == 2) && buf)
156 m_openglContext->glTexImage2D(QOpenGLTexture::Target2D, 0, QOpenGLTexture::RGBA, width, height,
157 0, QOpenGLTexture::RG, QOpenGLTexture::UInt8, buf);
159 result[plane]->m_texture->release();
162 CVPixelBufferUnlockBaseAddress(buffer, kCVPixelBufferLock_ReadOnly);
171std::vector<MythVideoTextureOpenGL*>
177 std::vector<MythVideoTextureOpenGL*> result;
180 CVPixelBufferRef buffer =
Verify(Context, ColourSpace,
Frame);
184 IOSurfaceRef surface = CVPixelBufferGetIOSurface(buffer);
187 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to retrieve IOSurface from CV buffer");
191 IOSurfaceID surfaceid = IOSurfaceGetID(surface);
196 bool needreferences =
false;
227 int planes = IOSurfaceGetPlaneCount(surface);
228 IOSurfaceLock(surface, kIOSurfaceLockReadOnly,
nullptr);
231 std::vector<QSize> sizes;
232 for (
int plane = 0; plane < planes; ++plane)
234 int width = IOSurfaceGetWidthOfPlane(surface, plane);
235 int height = IOSurfaceGetHeightOfPlane(surface, plane);
236 sizes.emplace_back(width, height);
244 IOSurfaceUnlock(surface, kIOSurfaceLockReadOnly,
nullptr);
245 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Unsupported frame format %1")
252 for (
uint plane = 0; plane < result.size(); ++plane)
260 GLenum format = (plane == 0) ? QOpenGLTexture::Red : QOpenGLTexture::RG;;
261 GLenum dataformat = (frameformat ==
FMT_NV12) ? QOpenGLTexture::UInt8 : QOpenGLTexture::UInt16;
263 CGLError
error = CGLTexImageIOSurface2D(
264 CGLGetCurrentContext(), QOpenGLTexture::TargetRectangle, format,
266 format, dataformat, surface, plane);
267 if (
error != kCGLNoError)
268 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"CGLTexImageIOSurface2D error %1").arg(
error));
272 IOSurfaceUnlock(surface, kIOSurfaceLockReadOnly,
nullptr);
298 std::vector<MythVideoTextureOpenGL*> result;
310 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Reference frame error");
static VideoFrameType PixelFormatToFrameType(AVPixelFormat Fmt)
uint64_t m_discontinuityCounter
std::vector< InteropType > InteropTypes
std::map< VideoFrameType, InteropTypes > InteropMap
virtual void DeleteTextures()
MythRenderOpenGL * m_openglContext
QHash< unsigned long long, std::vector< MythVideoTextureOpenGL * > > m_openglTextures
CVPixelBufferRef Verify(MythRenderOpenGL *Context, MythVideoColourSpace *ColourSpace, MythVideoFrame *Frame)
static MythVTBInterop * CreateVTB(MythPlayerUI *Player, MythRenderOpenGL *Context)
static void GetVTBTypes(MythRenderOpenGL *Render, MythInteropGPU::InteropMap &Types)
MythVTBInterop(MythPlayerUI *Player, MythRenderOpenGL *Context, MythOpenGLInterop::InteropType Type)
std::vector< MythVideoTextureOpenGL * > Acquire(MythRenderOpenGL *Context, MythVideoColourSpace *ColourSpace, MythVideoFrame *Frame, FrameScanType Scan) override
MythVTBSurfaceInterop(MythPlayerUI *Player, MythRenderOpenGL *Context)
QVector< IOSurfaceID > m_referenceFrames
std::vector< MythVideoTextureOpenGL * > GetReferenceFrames(void)
std::vector< MythVideoTextureOpenGL * > Acquire(MythRenderOpenGL *Context, MythVideoColourSpace *ColourSpace, MythVideoFrame *Frame, FrameScanType Scan) override
void RotateReferenceFrames(IOSurfaceID Buffer)
MythVideoColourSpace contains a QMatrix4x4 that can convert YCbCr data to RGB.
void SetSupportedAttributes(PictureAttributeSupported Supported)
Enable the given set of picture attributes.
bool UpdateColourSpace(const MythVideoFrame *Frame)
Set the current colourspace to use.
static QString FormatDescription(VideoFrameType Type)
VideoFrameType m_frameFormat
static std::vector< MythVideoTextureOpenGL * > CreateTextures(MythRenderOpenGL *Context, VideoFrameType Type, VideoFrameType Format, std::vector< QSize > Sizes, GLenum Target=QOpenGLTexture::Target2D)
Create a set of textures suitable for the given Type and Format.
static MythVideoTextureOpenGL * CreateTexture(MythRenderOpenGL *Context, QSize Size, GLenum Target=QOpenGLTexture::Target2D, QOpenGLTexture::PixelType PixelType=QOpenGLTexture::UInt8, QOpenGLTexture::PixelFormat PixelFormat=QOpenGLTexture::RGBA, QOpenGLTexture::TextureFormat Format=QOpenGLTexture::NoFormat, QOpenGLTexture::Filter Filter=QOpenGLTexture::Linear, QOpenGLTexture::WrapMode Wrap=QOpenGLTexture::ClampToEdge)
Create and initialise a MythVideoTexture that is backed by a QOpenGLTexture.
VideoFrameType m_frameType
static const struct wl_interface * types[]
static constexpr uint64_t DUMMY_INTEROP_ID
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
MBASE_PUBLIC long long copy(QFile &dst, QFile &src, uint block_size=0)
Copies src file to dst file.
bool is_interlaced(FrameScanType Scan)
#define ALL_PICTURE_ATTRIBUTES