Media (Intel® oneAPI Video Processing Library, Intel Media SDK)
Access community support with transcoding, decoding, and encoding in applications using media tools from Intel. This includes Intel® oneAPI Video Processing Library and Intel® Media SDK.
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
2935 Discussions

How to copy YUV data from d3d video surface to my system memory in Intel media SDK samples?


I noticed a interesting difference between Intel media samples,and some samples of earlier edition.

With samples, when I selected d3d9 surface video memory as the video memory type, run D3D API IDirect3DSurface9::LockRect and UnLockRect method, hoping to copy YUV data from surface to my system memory. Then my program would always be crashed ! However, in the earlier edition sample, the calling of LockRect and UnLockRect works perfectly.

Then I try to find some clues in the samples.

Firstly, In some earlier samples, source file <d3d_allocator.cpp>,  function D3DFrameAllocator::AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response), it pass a pointer array to "response", all the members of the array are pointers to video surfaces assigned by 
  [in]      UINT              Width,
  [in]      UINT              Height, [in]      UINT              BackBuffers,
  [in]      D3DFORMAT         Format,
  [in]      D3DPOOL           Pool,
  [in]      DWORD             Usage,
  [in]      DWORD             DxvaType,
  [out]     IDirect3DSurface9 **ppSurface,
  [in, out] HANDLE            *pSharedHandle)with a "NULL" in parameter"HANDLE *pSharedHandle". like:

hr = m_decoderService->CreateSurface(
            request->NumFrameSuggested - 1,
            (IDirect3DSurface9 **)mids.get(),

After allocate surface memory in this way, I could run  my program on methods like "LockRect and UnLockRect ", YUV data could be copied out of that way.

However in samples source file <d3d_allocator.cpp>, It defined a struct:

struct directxMemId
    IDirect3DSurface9* m_surface;
    HANDLE m_handle;

Then it called IDirectXVideoAccelerationService::CreateSurface(); , pass a surface pointer and a HANDLE as parameters to create aviliable d3d surfaces and pass them to the user. As a user, I got a surface and a handle once time. Then I would never get my YUV data out !!!

I searched msdn, it told me the parameter" pSharedHandle" is pointer to a handle that is used to share the surfaces between Direct3D devices. I can pass a NULL to it. I tried it and LockRect and UnLockRect could no longer cause a crash. But I do need this "pSharedHandle"  when creating a opencl&d3d shared surface(call clCreateFromDX9MediaSurfaceKHR).

I guess things may get related to the "Handle". How can I copy YUV data from d3d video surface to my system memory now?

0 Kudos
1 Reply

Hi there, 

I see you are using samples_version_6.0.0.36 which was released earlier this year. There has been couple more releases after that, can you please move to the latest sample and confirm the same behavior. If you do, please let us know your test case so that we can reproduce the issue at our end, debug and suggest a solution/workaround.