From a33fdad76850fbb8b7aad6bcbe34f3a9e47a3d68 Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Wed, 3 Jul 2013 12:59:58 +0200 Subject: [PATCH] Handle VFW_E_BUFFERS_OUTSTANDING errors during reconnection The VMR-9 renderer can send these errors when trying to reconnect and its still rendering a frame. To work around the issue, try to give the renderer a bit time to finish rendering the frames, and as a last resort do a flush to ensure we can reconnect. --- decoder/LAVVideo/LAVVideo.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/decoder/LAVVideo/LAVVideo.cpp b/decoder/LAVVideo/LAVVideo.cpp index c08701cf2..cbb05e8fa 100644 --- a/decoder/LAVVideo/LAVVideo.cpp +++ b/decoder/LAVVideo/LAVVideo.cpp @@ -885,6 +885,7 @@ HRESULT CLAVVideo::ReconnectOutput(int width, int height, AVRational ar, DXVA2_E HRESULT hr = S_FALSE; BOOL bNeedReconnect = FALSE; + int timeout = 100; DWORD dwAspectX = 0, dwAspectY = 0; RECT rcTargetOld = {0}; @@ -1033,6 +1034,7 @@ HRESULT CLAVVideo::ReconnectOutput(int width, int height, AVRational ar, DXVA2_E m_bSendMediaType = TRUE; m_pOutput->SetMediaType(&mt); } else { +receiveconnection: hr = m_pOutput->GetConnected()->ReceiveConnection(m_pOutput, &mt); if(SUCCEEDED(hr)) { IMediaSample *pOut = NULL; @@ -1059,6 +1061,18 @@ HRESULT CLAVVideo::ReconnectOutput(int width, int height, AVRational ar, DXVA2_E } pOut->Release(); } + } else if (hr == VFW_E_BUFFERS_OUTSTANDING && timeout != -1) { + if (timeout > 0) { + DbgLog((LOG_TRACE, 10, L"-> Buffers outstanding, retrying in 10ms..")); + Sleep(10); + timeout -= 10; + } else { + DbgLog((LOG_TRACE, 10, L"-> Buffers outstanding, timeout reached, flushing..")); + m_pOutput->DeliverBeginFlush(); + m_pOutput->DeliverEndFlush(); + timeout = -1; + } + goto receiveconnection; } else if (hrQA == S_OK) { DbgLog((LOG_TRACE, 10, L"-> Downstream accepts new format, but cannot reconnect dynamically...")); if (pBIH->biSizeImage > oldSizeImage) {