Reputation: 273
I have a function that takes in an IMFSample
pointer as a parameter. I am able to successfully convert it to an IMFMediaBuffer
object. However, when I call QueryInterface
for the IMFDXGIBuffer
on the IMFMediaBuffer
object, the HRESULT
returned is E_NOINTERFACE
.
Here is a very basic version of the method in which this is happening (for reference, the real function is based off of the CPresenter::ProcessFrame
method in Microsoft's DX11VideoRenderer project).
HRESULT TPresenter::ProcessFrame(IMFMediaType* pCurrentType, IMFSample* pSample, UINT32* punInterlaceMode, BOOL* pbDeviceChanged, IMFSample** ppOutputSample)
{
TObject::ThreadLock();
// Code to Check Shutdown and pointers
*pbDeviceChanged = FALSE;
DWORD cBuffers = 0;
HRESULT res = pSample->GetBufferCount(&cBuffers);
if (FAILED(res))
{
TObject::ThreadRelease();
return res;
}
IMFMediaBuffer* pBuffer = nullptr;
IMFMediaBuffer* pEVBuffer = nullptr;
if (1 == cBuffers)
{
res = pSample->GetBufferByIndex(0, &pBuffer);
}
else
res = pSample->ConvertToContiguousBuffer(&pBuffer);
// Code to Check Interlace mode
// Code to get the Device and Device Context for Direct3D
IMFDXGIBuffer* mfdxgiBuff = nullptr;
ID3D11Texture2D* d3dText = nullptr;
UINT resourceIndex = 0;
res = pBuffer.QueryInterface<IMFDXGIBuffer>(&mfdxgiBuff); // Currently returns E_NOINTERFACE
if (SUCCEEDED(res))
res = mfdxgiBuff->QueryInterface<ID3D11Texture2D>(&d3dText);
if (SUCCEEDED(res))
res = mfdxgiBuff->GetSubresourceIndex(&resourceIndex);
if (FAILED(res))
{
ThreadRelease();
return res;
}
// Continues on
}
OS: Windows 10 Home (Version 20H2)
VS: Community 2019 (Version 16.10.0)
Every resource I've seen relative to getting an IMFDXGIBuffer
from an IMFMediaBuffer
is saying to use the QueryInterface
method. Is it possible that Media Foundation has updated requirements regarding this procedure (new way we have to do this)? Or is there something I should be telling Media Foundation so that way, when these samples are provided, the IMFDXGIBuffer
is available?
Upvotes: 1
Views: 400
Reputation: 69642
You are seeing behavior by design.
Some buffers are backed by system memory, others - by D3D11 2D textures. You are assuming that the input is a texture while effectively it is a plain memory buffer.
You need a separate code path to handle this case (or you could possibly have an additional transform, including possibly third party one, that uploads data to video memory and ensures the samples are backed by textures).
Upvotes: 2