Skip to main content

 none
Getting null IMFDXGIBuffer RRS feed

  • Question

  • Hi,

    I am new to media foundation and DirectX. I am capturing frames from webcam using IMFSourceReader. and getting the IMFSourceReaderCallback as expected. Now I want to render these frames on ID3D11Device that I have created using D3D11CreateDeviceAndSwapChain. Below is my code for that. In code below when 'CComQIPtr<IMFDXGIBuffer> dxgiBuffer(SourceMediaPtr);' gets executed I am getting dxgiBuffer as NULL. I tried to go through documentation and tutorials available but not able to figure out the error. Also once I get this buffer should I be using CopySubresourceRegion to render frame ? 


    //Method from IMFSourceReaderCallback
    HRESULT Media::OnReadSample(HRESULT status, DWORD streamIndex, DWORD streamFlags, LONGLONG timeStamp, IMFSample *pSample)
    {
    HRESULT hr = S_OK;
    DWORD NumBuffers = 0;

    //RenderFrame();
    EnterCriticalSection(&criticalSection);
    do {
    if (pSample == NULL)
    break;
    hr = pSample->GetBufferCount(&NumBuffers);

    if (FAILED(hr) || NumBuffers < 1)
    {
    break;
    }

    IMFMediaBuffer* SourceMediaPtr = nullptr;
    hr = pSample->GetBufferByIndex(0, &SourceMediaPtr);

    if (FAILED(hr))
    {
    break;
    }

    if (SourceMediaPtr)
    {
    CComQIPtr<IMFDXGIBuffer> dxgiBuffer(SourceMediaPtr);
    ID3D11Texture2D *pTexture = nullptr;
    unsigned int subresource;

    if (dxgiBuffer)
    {
    hr = dxgiBuffer->GetResource(__uuidof(ID3D11Texture2D), (LPVOID*)&pTexture);
    if (pTexture)
    {
    dxgiBuffer->GetSubresourceIndex(&subresource);
    D3D11_TEXTURE2D_DESC texDesc;
    pTexture->GetDesc(&texDesc);
    CComQIPtr<ID3D11Device> device;
    CComQIPtr<ID3D11DeviceContext> context;
    pTexture->GetDevice(&device);
    device->GetImmediateContext(&context);
    //context->CopySubresourceRegion(m_pSwapChain, 0, 0, 0, 0, pTexture.Get(), subresource, nullptr);
    }
    }


    SafeRelease(&SourceMediaPtr);
    }

    } while (FALSE);
    LeaveCriticalSection(&criticalSection);
    hr = sourceReader->ReadSample((DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, NULL, NULL, NULL, NULL);
    return hr;
    }

    regardsm

    Surabhi

    Wednesday, August 7, 2019 4:42 AM

All replies