Skip to content

Commit

Permalink
dxva: 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 19, 2014
1 parent 71f50d3 commit 0d687ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 24 additions & 1 deletion xbmc/cores/dvdplayer/DVDCodecs/Video/DXVA.cpp
Expand Up @@ -608,6 +608,17 @@ bool CSurfaceContext::HasFree()
return !m_freeSurfaces.empty();
}

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

//-----------------------------------------------------------------------------
// DXVA RednerPictures
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -656,6 +667,16 @@ CDecoder::~CDecoder()
free(m_context);
}

long CDecoder::Release()
{
// if ffmpeg holds any references, flush buffers
if (m_surface_context && m_surface_context->HasRefs())
{
avcodec_flush_buffers(m_avctx);
}
return IHardwareDecoder::Release();
}

void CDecoder::Close()
{
CSingleLock lock(m_section);
Expand Down Expand Up @@ -902,6 +923,8 @@ bool CDecoder::Open(AVCodecContext *avctx, enum PixelFormat fmt, unsigned int su
avctx->get_buffer2 = GetBufferS;
avctx->hwaccel_context = m_context;

m_avctx = avctx;

D3DADAPTER_IDENTIFIER9 AIdentifier = g_Windowing.GetAIdentifier();
if (AIdentifier.VendorId == PCIV_Intel && m_input == DXVADDI_Intel_ModeH264_E)
{
Expand Down Expand Up @@ -1093,7 +1116,7 @@ void CDecoder::RelBuffer(uint8_t *data)
}
m_surface_context->ClearReference(surface);

Release();
IHardwareDecoder::Release();
}

int CDecoder::GetBuffer(AVCodecContext *avctx, AVFrame *pic, int flags)
Expand Down
3 changes: 3 additions & 0 deletions xbmc/cores/dvdplayer/DVDCodecs/Video/DXVA.h
Expand Up @@ -60,6 +60,7 @@ class CSurfaceContext
void Reset();
int Size();
bool HasFree();
bool HasRefs();

protected:
std::map<IDirect3DSurface9*, int> m_state;
Expand Down Expand Up @@ -122,6 +123,7 @@ class CDecoder
virtual void Close();
virtual const std::string Name() { return "dxva2"; }
virtual unsigned GetAllowedReferences();
virtual long Release();

bool OpenTarget(const GUID &guid);
bool OpenDecoder();
Expand Down Expand Up @@ -155,6 +157,7 @@ class CDecoder

CSurfaceContext* m_surface_context;
CDXVAContext* m_dxva_context;
AVCodecContext* m_avctx;

unsigned int m_shared;

Expand Down

0 comments on commit 0d687ed

Please sign in to comment.