This topic describes how to implement a Direct3D-aware Media Foundation transform (MFT) for video.
An video MFT is considered Direct3D-aware if it can process samples that contain Direct3D surfaces. The typical reason for supporting Direct3D in a video MFT is to enable hardware-accelerated decoding, using DirectX Video Acceleration (DXVA).
This topic describes the steps that are required to make your MFT Direct3D-aware. This topic does not cover the mechanics of DXVA decoding. For information about DXVA, see DirectX Video Acceleration 2.0.
- Implement the IMFTransform::GetAttributes method. This method returns a pointer to an attribute store.
- The MFT must set the value of the MF_SA_D3D_AWARE attribute to TRUE on its own attribute store. Beginning in Windows 8, if using Direct3D 11 use MF_SA_D3D11_AWARE.
- During format negotiation, if the MF_SA_D3D_AWARE (or MF_SA_D3D11_AWARE if using Direct3D 11) attribute is TRUE, the client may send the MFT_MESSAGE_SET_D3D_MANAGER message to the MFT. The ulParam event parameter is a pointer to the IDirect3DDeviceManager9 interface. Beginning in Windows 8, you can use IMFDXGIDeviceManager instead of IDirect3DDeviceManager9. The client is not required to send this message.
- The MFT calls IDirect3DDeviceManager9::GetVideoService to query for the DXVA service it needs. Beginning in Windows 8, if IMFDXGIDeviceManager was used the MFT calls IMFDXGIDeviceManager::GetVideoService. Typically a decoder would query for IDirectXVideoDecoderService, and a video processor would query for IDirectXVideoProcessorService.
- Assuming the previous step is successful, the IMFTransform::GetInputAvailableType and IMFTransform::GetOutputAvailableType methods must return DXVA-compatible formats.
- The client configures the media types on the MFT. If a media type is not compatible with DXVA, the MFT must return the error code MF_E_UNSUPPORTED_D3D_TYPE.
- At this point, there are two options, depending on whether the client finds a suitable DXVA format.
- If the client successfully configures a DXVA format, it may begin processing. At this point, the MFT can use DXVA for processing, or fall back to software processing.
- Alternatively, if the client does not find an acceptable DXVA format, the client may send another MFT_MESSAGE_SET_D3D_MANAGER message, this time setting ulParam to NULL. The MFT must release the IDirect3DDeviceManager9 pointer (the IMFDXGIDeviceManager pointer, if IMFDXGIDeviceManager was used) and any other DXVA interfaces, and revert to software processing. At this point, the MFT must not use DXVA processing.
A Direct3D-aware MFT must be prepared to handle samples that contain a Direct3D surface. The sample will contain exactly one media buffer. To get the Direct3D surface from the buffer, call the MFGetService function and specify the MR_BUFFER_SERVICE service. For more information, see DirectX Surface Buffer.
An MFT that uses DXVA must allocate its own output samples, as follows:
- In the IMFTransform::GetOutputStreamInfo method, set the MFT_OUTPUT_STREAM_PROVIDES_SAMPLES flag.
- Create a pool of DXVA surfaces, as described in the DXVA specification.
- Create media samples by calling MFCreateVideoSampleFromSurface.
The MFT should always support software processing as a fallback, because DXVA processing might not available, for several reasons:
- The GPU might not support DXVA.
- The client might not use Direct3D.
- DXVA profiles are not defined for every video format.
A Direct3D-aware MFT must have a single output stream. It cannot have multiple outputs.