Skip to content

Commit

Permalink
vaapi: flush ffmpeg buffers if it holds any refs on close
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed Sep 21, 2014
1 parent 24494c3 commit 794e4d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions xbmc/cores/dvdplayer/DVDCodecs/Video/VAAPI.cpp
Expand Up @@ -417,6 +417,17 @@ bool CVideoSurfaces::HasFree()
return !m_freeSurfaces.empty();
}

bool CVideoSurfaces::HasRefs()
{
CSingleLock lock(m_section);
for (std::map<VASurfaceID, int>::iterator it = m_state.begin(); it != m_state.end(); ++it)
{
if (it->second & SURFACE_USED_FOR_REFERENCE)
return true;
}
return false;
}

//-----------------------------------------------------------------------------
// VAAPI
//-----------------------------------------------------------------------------
Expand All @@ -440,6 +451,7 @@ CDecoder::CDecoder() : m_vaapiOutput(&m_inMsgEvent)
m_vaapiConfig.context = 0;
m_vaapiConfig.contextId = VA_INVALID_ID;
m_vaapiConfig.configId = VA_INVALID_ID;
m_avctx = NULL;
}

CDecoder::~CDecoder()
Expand Down Expand Up @@ -568,6 +580,8 @@ bool CDecoder::Open(AVCodecContext* avctx, const enum PixelFormat fmt, unsigned
avctx->hwaccel_context = &m_hwContext;
avctx->get_buffer2 = CDecoder::FFGetBuffer;
avctx->slice_flags = SLICE_FLAG_CODED_ORDER|SLICE_FLAG_ALLOW_FIELD;

m_avctx = avctx;
return true;
}

Expand All @@ -586,6 +600,12 @@ void CDecoder::Close()

long CDecoder::Release()
{
// if ffmpeg holds any references, flush buffers
if (m_avctx && m_videoSurfaces.HasRefs())
{
avcodec_flush_buffers(m_avctx);
}

// check if we should do some pre-cleanup here
// a second decoder might need resources
if (m_vaapiConfigured == true)
Expand Down
2 changes: 2 additions & 0 deletions xbmc/cores/dvdplayer/DVDCodecs/Video/VAAPI.h
Expand Up @@ -331,6 +331,7 @@ class CVideoSurfaces
void Reset();
int Size();
bool HasFree();
bool HasRefs();
protected:
std::map<VASurfaceID, int> m_state;
std::list<VASurfaceID> m_freeSurfaces;
Expand Down Expand Up @@ -427,6 +428,7 @@ class CDecoder
CVaapiConfig m_vaapiConfig;
CVideoSurfaces m_videoSurfaces;
vaapi_context m_hwContext;
AVCodecContext* m_avctx;

COutput m_vaapiOutput;
CVaapiBufferStats m_bufferStats;
Expand Down

0 comments on commit 794e4d1

Please sign in to comment.