Is DX11VideoRenderer thread safe?

0

I'm using the Microsoft sample DX11VideoRenderer to render real time video in Windows 10. When I run just one stream, the video looks great. However when I run more than 4 or 5 streams, some of the video in their respective windows start blanking out intermittently. The effect can be over just a portion or all of each video window.

Also I get a few intermittent errors from this function call in my log file:

hr = pVideoContext->VideoProcessorBlt(m_pVideoProcessor, pOutputView, 0, 1, &StreamData );

The error returned is: E_INVALIDARG One or more arguments are not valid 0x80070057

I'm only using the Presenter.cpp and display.cpp modules of the DX11VideoRenderer in my code. The source is located at: DirectX video rendering sample

My initial suspicion at this stage is that DXVideoRenderer may not be thread safe. I found this information about multithreading: Introduction to Multithreading in Direct3D 11 which states:

While the use of a device context (ID3D11DeviceContext) is not thread-safe, the use of a Direct3D 11 device (ID3D11Device) is thread-safe.

But it seems that since I'm using separate instances of the CPresenter class for each window, there should not be a problem with ID3D11DeviceContext not being thread safe because each window should have it's own instance of ID3D11DeviceContext.

Does anyone have any experience or ideas about this DX11VideoRenderer software sample and what might be causing this problem?

Thank you!

-UPDATE-

I have been able to duplicate the problem with just one window so it no longer appears to be a threading issue. If I manually resize the window many times I can sometimes get the video in the window to flicker. When this happens I see in my log that the same function call to VideoProcessorBlt() had a failure with the same return code, E_INVALIDARG.

directx
directx-11
ms-media-foundation
hardware-acceleration
dxva
asked on Stack Overflow May 10, 2018 by Gary G. • edited May 10, 2018 by Gary G.

1 Answer

0

If I manually resize the window many times I can sometimes get the video in the window to flicker. When this happens I see in my log that the same function call to VideoProcessorBlt() had a failure with the same return code, E_INVALIDARG.

This behaviour is not documented by Microsoft.

The problem is the same with DirectX9, but the error occurs with IDirect3DDevice9::Present, just after VideoProcessBltHD. The HRESULT code is 0x88760872, and 0x88760872 is not documented.

So when resizing window, the error can occur.

See H264Dxva2Decoder :

In Dxva2Renderer.cpp, check for HANDLE_DIRECTX_ERROR_UNDOCUMENTED.

The strategy I choosed is to pause the video if playing (see WindowsFormProc and WM_ENTERSIZEMOVE/WM_SYSCOMMAND), also, this avoid flickering.

Doing this, the error disappears.

PS: normally this error can be safely ignored.

I think this error is just there to tell you that when the window is resized, the underlying API is struggling to synchronize the DirectX presentation with your HWND, which changes size quickly.

answered on Stack Overflow Jan 27, 2020 by mofo77 • edited Jan 27, 2020 by mofo77

User contributions licensed under CC BY-SA 3.0