MFCreateVideoSampleFromSurface callback function

Creates a media sample that manages a Direct3D surface.

Syntax

MFCreateVideoSampleFromSurface Mfcreatevideosamplefromsurface;

EVRPUBLIC Mfcreatevideosamplefromsurface(
  IUnknown *pUnkSurface,
  IMFSample **ppSample
)
{...}

Parameters

pUnkSurface

A pointer to the IUnknown interface of the Direct3D surface. This parameter can be NULL.

ppSample

Receives a pointer to the sample's IMFSample interface. The caller must release the interface.

Return Value

If this callback function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

The media sample created by this function exposes the following interfaces in addition to IMFSample:

If pUnkSurface is non-NULL, the sample contains a single media buffer, which holds a pointer to the Direct3D surface. To get the Direct3D surface from the media buffer, call IMFGetService::GetService on the buffer, using the service identifier MR_BUFFER_SERVICE. The media buffer does not implement IMF2DBuffer, nor does it implement the IMFMediaBuffer::Lock and Unlock methods.

Alternatively, you can set pUnkSurface to NULL, and later add a DirectX surface buffer to the sample by calling IMFSample::AddBuffer. To create a DirectX surface buffer, call MFCreateDXSurfaceBuffer.

Examples

The following example is taken from the EVRPresenter Sample.

C++
//-----------------------------------------------------------------------------
// CreateD3DSample
//
// Creates a sample object (IMFSample) to hold a Direct3D swap chain.
//-----------------------------------------------------------------------------

HRESULT D3DPresentEngine::CreateD3DSample( IDirect3DSwapChain9 *pSwapChain, IMFSample **ppVideoSample ) { // Caller holds the object lock.

D3DCOLOR clrBlack = D3DCOLOR_ARGB(0xFF, 0x00, 0x00, 0x00);

IDirect3DSurface9* pSurface = NULL;
IMFSample* pSample = NULL;

// Get the back buffer surface.
HRESULT hr = pSwapChain->GetBackBuffer(
    0, D3DBACKBUFFER_TYPE_MONO, &pSurface);
if (FAILED(hr))
{
    goto done;
}

// Fill it with black.
hr = m_pDevice->ColorFill(pSurface, NULL, clrBlack);
if (FAILED(hr))
{
    goto done;
}

// Create the sample.
hr = MFCreateVideoSampleFromSurface(pSurface, &pSample);
if (FAILED(hr))
{
    goto done;
}

// Return the pointer to the caller.
*ppVideoSample = pSample;
(*ppVideoSample)->AddRef();

done: SafeRelease(&pSurface); SafeRelease(&pSample); return hr; }

Requirements

   
Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2008 [desktop apps only]
Target Platform Windows
Header evr.h

See Also

DirectX Surface Buffer

Media Foundation Functions

Media Samples