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)
56 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"Mismatched OpenGL contexts");
59 QSize surfacesize(
Frame->m_width,
Frame->m_height);
64 LOG(VB_GENERAL, LOG_WARNING,
LOC + QString(
"Video texture size changed! %1x%2->%3x%4")
82 return reinterpret_cast<CVPixelBufferRef
>(
Frame->m_buffer);
85std::vector<MythVideoTextureOpenGL*>
91 std::vector<MythVideoTextureOpenGL*> result;
94 CVPixelBufferRef buffer =
Verify(Context, ColourSpace,
Frame);
104 int planes = CVPixelBufferGetPlaneCount(buffer);
105 CVPixelBufferLockBaseAddress(buffer, kCVPixelBufferLock_ReadOnly);
115 for (
int plane = 0; plane < planes; ++plane)
117 int width = CVPixelBufferGetWidthOfPlane(buffer, plane);
118 int height = CVPixelBufferGetHeightOfPlane(buffer, plane);
119 QSize size(width, height);
128 result.push_back(texture);
132 if (result.size() !=
static_cast<uint>(planes))
133 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to create all textures");
143 for (
int plane = 0; plane < planes; ++plane)
145 if (
static_cast<uint>(plane) >= result.size())
148 int width = CVPixelBufferGetWidthOfPlane(buffer, plane);
149 int height = CVPixelBufferGetHeightOfPlane(buffer, plane);
150 int bytes = CVPixelBufferGetBytesPerRowOfPlane(buffer, plane) / width;
151 void* buf = CVPixelBufferGetBaseAddressOfPlane(buffer, plane);
152 result[plane]->m_texture->bind();
153 if ((
bytes == 1) && buf)
155 m_openglContext->glTexImage2D(QOpenGLTexture::Target2D, 0, QOpenGLTexture::RGBA, width, height,
156 0, QOpenGLTexture::Red, QOpenGLTexture::UInt8, buf);
158 else if ((
bytes == 2) && buf)
160 m_openglContext->glTexImage2D(QOpenGLTexture::Target2D, 0, QOpenGLTexture::RGBA, width, height,
161 0, QOpenGLTexture::RG, QOpenGLTexture::UInt8, buf);
163 result[plane]->m_texture->release();
166 CVPixelBufferUnlockBaseAddress(buffer, kCVPixelBufferLock_ReadOnly);
179std::vector<MythVideoTextureOpenGL*>
185 std::vector<MythVideoTextureOpenGL*> result;
188 CVPixelBufferRef buffer =
Verify(Context, ColourSpace,
Frame);
192 IOSurfaceRef surface = CVPixelBufferGetIOSurface(buffer);
195 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to retrieve IOSurface from CV buffer");
199 IOSurfaceID surfaceid = IOSurfaceGetID(surface);
204 bool needreferences =
false;
235 int planes = IOSurfaceGetPlaneCount(surface);
236 IOSurfaceLock(surface, kIOSurfaceLockReadOnly,
nullptr);
239 std::vector<QSize> sizes;
240 for (
int plane = 0; plane < planes; ++plane)
242 int width = IOSurfaceGetWidthOfPlane(surface, plane);
243 int height = IOSurfaceGetHeightOfPlane(surface, plane);
244 sizes.push_back(QSize(width, height));
252 IOSurfaceUnlock(surface, kIOSurfaceLockReadOnly,
nullptr);
253 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Unsupported frame format %1")
260 for (
uint plane = 0; plane < result.size(); ++plane)
268 GLenum format = (plane == 0) ? QOpenGLTexture::Red : QOpenGLTexture::RG;;
269 GLenum dataformat = (frameformat ==
FMT_NV12) ? QOpenGLTexture::UInt8 : QOpenGLTexture::UInt16;
271 CGLError
error = CGLTexImageIOSurface2D(
272 CGLGetCurrentContext(), QOpenGLTexture::TargetRectangle, format,
274 format, dataformat, surface, plane);
275 if (
error != kCGLNoError)
276 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"CGLTexImageIOSurface2D error %1").arg(
error));
280 IOSurfaceUnlock(surface, kIOSurfaceLockReadOnly,
nullptr);
306 std::vector<MythVideoTextureOpenGL*> result;
318 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
~MythVTBInterop() override
MythVTBSurfaceInterop(MythPlayerUI *Player, MythRenderOpenGL *Context)
QVector< IOSurfaceID > m_referenceFrames
~MythVTBSurfaceInterop() override
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