在媒体会话中应用MFT(灰度样本)

时间:2017-10-26 12:30:48

标签: ms-media-foundation mft

我使用以下MSDN示例代码(媒体基础)

  1. 音频/视频播放
  2. 创建转换节点
  3. 将解码器添加到拓扑中
  4. 我想将MFT应用于基于媒体会话的播放 MFT_Grayscale示例   - https://msdn.microsoft.com/en-us/library/windows/desktop/bb970487(v=vs.85).aspx

    .dll已注册,并且与TopoEdit配合良好。

    根据以上示例,我只添加了topolgy链接。 但它没有用。

    这是我添加的内容。

    HRESULT AddBranchToPartialTopology(
    IMFTopology *pTopology,         // Topology.
    IMFMediaSource *pSource,        // Media source.
    IMFPresentationDescriptor *pPD, // Presentation descriptor.
    DWORD iStream,                  // Stream index.
    HWND hVideoWnd)                 // Window for video playback. 
    
    
    {
    
        IMFStreamDescriptor *pSD = NULL;
        IMFActivate         *pSinkActivate = NULL;
        IMFTopologyNode     *pSourceNode = NULL;
        IMFTopologyNode     *pOutputNode = NULL;
        IMFTopologyNode     *pDecoderNode = NULL;
        IMFTopologyNode     *pMFTNode = NULL;
    
        BOOL fSelected = FALSE;
        CLSID clsidDecoder = GUID_NULL;
    
        HRESULT hr = pPD->GetStreamDescriptorByIndex(iStream, &fSelected, &pSD);
        if (FAILED(hr))
        {
            goto done;
        }
    
        if (fSelected)
        {
            // Create the media sink activation object.
            hr = CreateMediaSinkActivate(pSD, hVideoWnd, &pSinkActivate);
            if (FAILED(hr))
            {
                goto done;
            }
    
            // Add a source node for this stream.
            hr = AddSourceNode(pTopology, pSource, pPD, pSD, &pSourceNode);
            if (FAILED(hr))
            {
                goto done;
            }
    
            // Create the output node for the renderer.
            hr = AddOutputNode(pTopology, pSinkActivate, 0, &pOutputNode);
            if (FAILED(hr))
            {
                goto done;
            }
    
            // Find a decoder.
            if (SUCCEEDED(hr))
            {
                hr = FindDecoderForStream(pSD, &clsidDecoder);
            }
    
            if (SUCCEEDED(hr))
            {
                if (clsidDecoder == GUID_NULL)
                {
                    // No decoder is required. 
                    // Connect the source node to the output node.
                    hr = pSourceNode->ConnectOutput(0, pOutputNode, 0);
                }
                else
                {
                    // Add a decoder node.
                    hr = AddTransformNode(pTopology, clsidDecoder, &pDecoderNode);
                    hr = AddTransformNode(pTopology, CLSID_GrayscaleMFT, &pMFTNode);
    
                    if (SUCCEEDED(hr))
                    {
                        hr = pSourceNode->ConnectOutput(0, pDecoderNode, 0);
                    }
    
                    // Connect the decoder node to the output node.
                    if (SUCCEEDED(hr))
                    {
                        hr = pDecoderNode->ConnectOutput(0, pMFTNode, 0);
                    }
    
                    if (SUCCEEDED(hr))
                    {
                        hr = pMFTNode->ConnectOutput(0, pOutputNode, 0);
                    }
                }
            }
            // Mark this branch as not requiring a decoder.
            if (SUCCEEDED(hr))
            {
                hr = pOutputNode->SetUINT32(
                    MF_TOPONODE_CONNECT_METHOD,
                    MF_CONNECT_ALLOW_CONVERTER
                    );
            }
    
            if (SUCCEEDED(hr))
            {
                hr = pDecoderNode->SetUINT32(
                    MF_TOPONODE_CONNECT_METHOD,
                    MF_CONNECT_ALLOW_CONVERTER
                    );
            }
    
            if (SUCCEEDED(hr))
            {
                hr = pMFTNode->SetUINT32(
                    MF_TOPONODE_CONNECT_METHOD,
                    MF_CONNECT_ALLOW_CONVERTER
                    );
            }
        }
        // else: If not selected, don't add the branch. 
    done:
        SafeRelease(&pSD);
        SafeRelease(&pSinkActivate);
        SafeRelease(&pSourceNode);
        SafeRelease(&pOutputNode);
        SafeRelease(&pDecoderNode);
        SafeRelease(&pMFTNode);
        return hr;
    }    
    

1 个答案:

答案 0 :(得分:1)

我觉得自己很傻。

MFT_Grayscale仅转换视频流。

不应连接音频流。

如下......

if (MFMediaType_Audio == guidMajorType)
{
    pSourceNode->ConnectOutput(0, pDecoderNode, 0);
    pDecoderNode->ConnectOutput(0, pOutputNode, 0);
}
else if (MFMediaType_Video == guidMajorType)
{
    pSourceNode->ConnectOutput(0, pDecoderNode, 0);
    pDecoderNode->ConnectOutput(0, pMFTNode, 0);
    pMFTNode->ConnectOutput(0, pOutputNode, 0);
}