找回密码
 
查看: 1542|回复: 0

[Media] Supporting Direct3D 11 Video Decoding in Media Foundation

[复制链接]
Source : https://msdn.microsoft.com/en-us ... 2%28v=vs.85%29.aspx

This topic describes how to support  Microsoft Direct3D 11 in a Microsoft Media Foundation decoder. Specifically, it describes the communication between the decoder and the video renderer. This topic does not describe how to implement the decoding operations.

OverviewIn the remainder of this topic, the following terms are used:
  • Software decoder. The software  decoder is the Media Foundation transform (MFT) that receives compressed video samples and outputs uncompressed video frames.
  • Decoder device. The decoder device is the video accelerator, and is implemented by the graphics driver. The decoder device performs accelerated decoding operations.
  • Pipeline. The pipeline hosts the software decoder and delivers buffers to and from the software decoder. Depending on the application, the pipeline might be the Media Session, the Source Reader, or application code that directly calls into the MFT.
To perform  decoding using Direct3D 11, the software decoder must have a pointer to a Direct3D 11 device. The  Direct3D 11 device is created externally to the software decoder. In a Media Session scenario, the video renderer creates the  Direct3D 11 device. In a Source Reader scenario, typically the application creates the Direct3D 11  device.
The DXGI Device Manager is used to share the Direct3D 11 between components. The DXGI Device Manager exposes the IMFDXGIDeviceManager interface. The pipeline sets the IMFDXGIDeviceManager pointer on the software decoder by sending the MFT_MESSAGE_SET_D3D_MANAGER message.
The following diagram shows the relation between the software decoder, the Direct3D 11, and the pipeline.
https://i-msdn.sec.s-msft.com/dynimg/IC534273.png
Here are the basic steps that a software decoder must perform to support Direct3D 11 in Media Foundation:
  • Open a handle to the Direct3D 11 device.
  • Find a decoder configuration.
  • Allocate uncompressed buffers.
  • Decode frames.
These steps are described in more detail in the remainder of this topic.
Open a Device HandleThe decoder MFT uses the DXGI device manager to get a handle to the Direct3D 11 device. To open the device handle, perform the following steps:
Find a Decoder ConfigurationTo perform decoding, the software decoder must find a compatible  configuration that is supported by the decoder device, including a render-target format. This step occurs inside the IMFTransform::SetInputType method, as follows.
In the IMFTransform::GetOutputAvailableType method, return an uncompressed video format based on the proposed render-target format.
In the IMFTransform::SetOutputType method, check the media type against the render target format.
Fallback to Software DecodingThe MFT might be unable to find a configuration. For example, the graphics driver might not support the right capabilities. In that case, the MFT must fall back to software decoding, as follows.
At this point, the MFT can use software decoding.
Allocating Uncompressed BuffersThe decoder is responsible for allocating Direct3D 11 textures to use as uncompressed video buffers. The MF_SA_MINIMUM_OUTPUT_SAMPLE_COUNT attribute in the output stream attributes (seeIMFTransform::GetOutputStreamAttributes) is used to determine how  many surfaces the decoder should allocate for the video renderer to use for deinterlacing  . A decoder should use this value bounding it for some reasonable upper and lower limits, for example 3-32.  For progressive content see MF_SA_MINIMUM_OUTPUT_SAMPLE_COUNT_PROGRESSIVE.
In the IMFTransform::GetOutputStreamInfo method, set the MFT_OUTPUT_STREAM_PROVIDES_SAMPLES flag in the MFT_OUTPUT_STREAM_INFO structure. This flag notifies the Media Session that the MFT allocates its own output samples. To allocate the output samples, the MFT performs the following steps:
You should destroy all the textures you create at  the same time, rather then destroying only some and continuing  to use the reminder.
DecodingTo create the decoder device, call ID3D11VideoDevice::CreateVideoDecoder. The method returns a pointer to the ID3D11VideoDecoder interface. Decoding should occur inside the IMFTransform::ProcessOutput method. On each frame, call IMFDXGIDeviceManager::TestDevice to test the availability of the DXGI. If the device has changed, the software decoder must recreate the decoder device, as follows:
Assuming that the device handle is valid, the decoding process works as follows:
Direct3D 11 uses the same data structures as DXVA 2.0 for decoding operations. For the original set of DXVA profiles (for H.261, H.263, and MPEG-2), these data structures are described in the DXVA 1.0 specification.
Within each pair of DecoderBeginFrame and SubmitDecoderBuffer calls, you may call GetDecoderBuffer multiple times, but only once for each type of buffer. If you use the same buffer type twice without calling SubmitDecoderBuffer, you will overwrite the data in the buffer.
Related topicsDirectX Video Acceleration 2.0

GMT,

Powered by Discuz!

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表