Skip to content

Commit

Permalink
MythNVDECInterop: Reset opengl textures when the frame size changes
Browse files Browse the repository at this point in the history
- this is largely driven by how the FFmpeg nvdec decoder works -
normally the interop would be deleted but under certain circumstances it
just carries on with a new frame size
  • Loading branch information
mark-kendall committed May 21, 2019
1 parent 8737112 commit cb7fe54
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
33 changes: 21 additions & 12 deletions mythtv/libs/libmythtv/mythnvdecinterop.cpp
Expand Up @@ -25,10 +25,22 @@ MythNVDECInterop::MythNVDECInterop(MythRenderOpenGL *Context)
}

MythNVDECInterop::~MythNVDECInterop()
{
if (m_cudaFuncs)
{
if (m_cudaContext)
CUDA_CHECK(m_cudaFuncs->cuCtxDestroy(m_cudaContext));
cuda_free_functions(&m_cudaFuncs);
}
}

void MythNVDECInterop::DeleteTextures(void)
{
CUcontext dummy;
if (m_cudaContext && m_cudaFuncs)
CUDA_CHECK(m_cudaFuncs->cuCtxPushCurrent(m_cudaContext));
if (!(m_cudaContext && m_cudaFuncs))
return;

CUDA_CHECK(m_cudaFuncs->cuCtxPushCurrent(m_cudaContext));

if (!m_openglTextures.isEmpty())
{
Expand All @@ -51,15 +63,9 @@ MythNVDECInterop::~MythNVDECInterop()
}
}

if (m_cudaFuncs)
{
if (m_cudaContext)
{
CUDA_CHECK(m_cudaFuncs->cuCtxPopCurrent(&dummy));
CUDA_CHECK(m_cudaFuncs->cuCtxDestroy(m_cudaContext));
}
cuda_free_functions(&m_cudaFuncs);
}
CUDA_CHECK(m_cudaFuncs->cuCtxPopCurrent(&dummy));

MythOpenGLInterop::DeleteTextures();
}

bool MythNVDECInterop::IsValid(void)
Expand Down Expand Up @@ -114,7 +120,10 @@ vector<MythVideoTexture*> MythNVDECInterop::Acquire(MythRenderOpenGL *Context,
if (m_openglTextureSize != surfacesize)
{
if (!m_openglTextureSize.isEmpty())
LOG(VB_GENERAL, LOG_WARNING, LOC + "Video texture size changed!");
LOG(VB_GENERAL, LOG_WARNING, LOC + QString("Video texture size changed! %1x%2->%3x%4")
.arg(m_openglTextureSize.width()).arg(m_openglTextureSize.height())
.arg(Frame->width).arg(Frame->height));
DeleteTextures();
m_openglTextureSize = surfacesize;
}

Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythtv/mythnvdecinterop.h
Expand Up @@ -28,6 +28,7 @@ class MythNVDECInterop : public MythOpenGLInterop

private:
bool InitialiseCuda(void);
void DeleteTextures(void) override;

CUcontext m_cudaContext;
CudaFunctions *m_cudaFuncs;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/mythopenglinterop.h
Expand Up @@ -56,7 +56,7 @@ class MythOpenGLInterop : public QObject, public ReferenceCounter

protected:
explicit MythOpenGLInterop (MythRenderOpenGL *Context, Type InteropType);
void DeleteTextures (void);
virtual void DeleteTextures (void);

protected:
MythRenderOpenGL *m_context;
Expand Down

0 comments on commit cb7fe54

Please sign in to comment.