Hello,
My goal is to gain access to the IMFDXGIBuffer from inside of the IMFSourceReader::OnReadSample call back function that gives us an IMFSample buffer...
HRESULT CSourceReaderCB::OnReadSample( HRESULT hrStatus, DWORD /* dwStreamIndex */, DWORD /* dwStreamFlags */, LONGLONG /* llTimestamp */, IMFSample *pMFSample )
{
...
hr = pMFSample->GetBufferByIndex(0, &pMFMediaBuffer);
if (FAILED(hr)) { goto done; } hr = pMFMediaBuffer->QueryInterface(__uuidof(IMFDXGIBuffer), (LPVOID *)(&pMFDXGIBuffer));if (FAILED(hr)) { goto done; } hr = pMFDXGIBuffer->GetResource(__uuidof(ID3D11Texture2D), (LPVOID *)(&g_pSharedTexure));if (FAILED(hr)) { goto done; }
...
}
My image path after this function is DirectX11 textures. So I want to prevent a CPU copy from the IMFMediaSample to a ID3DTexture2D. I do have the CPU copy working as per the MFCaptureD3D sample.
In order for this to work, I have used ...
if (SUCCEEDED(hr)) { hr = MFCreateVideoSampleAllocatorEx(IID_IMFVideoSampleAllocatorEx, (LPVOID*)&pMFVideoSampleAllocatorEx); }if (SUCCEEDED(hr)) { hr = pMFVideoSampleAllocatorEx->SetDirectXManager(pMFDXGIManager); }...
if (SUCCEEDED(hr)) { hr = MFCreateAttributes( &pMFAttributes1, 3 ); }if (SUCCEEDED(hr)) { hr = pMFAttributes1->SetUnknown( MF_SOURCE_READER_ASYNC_CALLBACK, this ); }if (SUCCEEDED(hr)) { hr = pMFAttributes1->SetUINT32( MF_SOURCE_READER_ENABLE_ADVANCED_VIDEO_PROCESSING, true ); }if (SUCCEEDED(hr)) { hr = pMFAttributes1->SetUINT32( MF_READWRITE_DISABLE_CONVERTERS, false ); }if (SUCCEEDED(hr)) { hr = MFCreateSourceReaderFromMediaSource( m_pMFMediaSource, pMFAttributes1, &m_pMFSourceReader ); }
...
//DWORD dwBindFlags = D3D11_BIND_RENDER_TARGET;// | D3D11_BIND_SHADER_RESOURCE;if (SUCCEEDED(hr)) { hr = MFCreateAttributes(&pMFAttributes2, 2); }if (SUCCEEDED(hr)) { hr = pMFAttributes2->SetUINT32( MF_SA_D3D11_BINDFLAGS, 0 ); }if (SUCCEEDED(hr)) { hr = pMFAttributes2->SetUINT32( MF_SA_D3D11_USAGE, D3D11_USAGE_DEFAULT ); }//if (SUCCEEDED(hr)) { hr = pMFAttributes2->SetUINT32( MF_SA_BUFFERS_PER_SAMPLE, 1 ); }//if (SUCCEEDED(hr)) { hr = pMFAttributes2->SetUINT32( MF_SA_D3D11_AWARE, 1 ); }//if (SUCCEEDED(hr)) { hr = pMFAttributes2->SetUINT32( MF_SA_D3D11_SHARED, 1 ); } hr = m_pMFVideoSampleAllocatorEx->InitializeSampleAllocatorEx( 1, 10, pMFAttributes2, pMFMediaType );
Everything succeeds until the InitializeSampleAllocatorEx call.
Another bit of information is the type for pMFMediaType ...
// GUID majortype = { 0 };
// WMMEDIATYPE_Video = 73646976-0000-0010-8000-00AA00389B71//GUID subtype = { 0 };
// MEDIASUBTYPE_YUY2 = 32595559-0000-0010-8000-00AA00389B71What am I missing here?
The hr reads 0x80041000.
Thank you for reading this and your time on helping me.
Cheers,
Pete