首页 文章

添加声音过滤器并连接声音引脚

提问于
浏览
1

上下文

带有用户控件的WPF UI,用于实现多个COMS并使用带有directshow.net的过滤器

问题

音频引脚的名称会根据播放的视频而改变 . (两者都是.avi文件)正如您在屏幕截图中看到的那样,声音引脚不一样 . (一个是'Stream 01',而另一个是'01 Microsoft wave form .....')

在我的代码中,我使用ConnectDirect和方法GetPin . 要使用GetPin,您需要提供一个引脚名称 .

图表

使用完全相同的代码生成的图表,仅更改视频文件 .

Graph generated with exactly the same code, only change the video files.

问题

当引脚名称发生变化时,如何根据运行的.avi文件连接过滤器?顺便说一下,一个avi文件是'自制的'而另一个是微软avi样本文件(12秒蓝色时钟)

相关代码

//sound filter linker
IBaseFilter pACMWrapper = (IBaseFilter)new ACMWrapper();
hr = m_FilterGraph.AddFilter(pACMWrapper, "ACM wrapper");


//add le default direct sound device

IBaseFilter pDefaultDirectSoundDevice = null;

try
{
    pDefaultDirectSoundDevice = (IBaseFilter)new DSoundRender();
    hr = m_FilterGraph.AddFilter(pDefaultDirectSoundDevice, "Default DirectSound Device");


    IBaseFilter aviSplitter;
    //find the avi splitter automatically added when I connect samp grabber to source filter.
    m_FilterGraph.FindFilterByName("AVI Splitter", out aviSplitter);

    System.Windows.MessageBox.Show(""); // graph screenshot is from here.

    hr = m_FilterGraph.Connect(GetPin(aviSplitter, "Stream 01"), GetPin(pACMWrapper, "Input"));
    DsError.ThrowExceptionForHR(hr);

    //connect audio filters 
    hr = m_FilterGraph.ConnectDirect(GetPin(pACMWrapper, "Output"), GetPin(pDefaultDirectSoundDevice, "Audio Input pin (rendered)"), null);
    DsError.ThrowExceptionForHR(hr);
}
catch (Exception)
{
    pDefaultDirectSoundDevice = null;
    //log error, play video without sound
    //throw;
}

GetPin代码

private IPin GetPin(IBaseFilter destinationFilter, string pinName)
    {
        IEnumPins pinEnum;
        int hr = destinationFilter.EnumPins(out pinEnum);
        DsError.ThrowExceptionForHR(hr);

        IPin[] pins = new IPin[1];

        IntPtr fetched = Marshal.AllocCoTaskMem(4);

        while (pinEnum.Next(1, pins, fetched) == 0)
        {
            PinInfo pInfo;
            pins[0].QueryPinInfo(out pInfo);

            bool found = (pInfo.name == pinName);
            DsUtils.FreePinInfo(pInfo);
            if (found)
                return pins[0];
        }
        return null;
    }

1 回答

  • 2

    您无需使用硬编码名称选择输出引脚 . 相反,它实际上是一种更可靠的方式,您需要枚举引脚 - 正如您的 GetPin 函数已经执行的那样 - 然后枚举给定引脚上的媒体类型 . 只看第一种媒体类型(如果有的话)是可以的 . 如果它的主要类型是 MEDIATYPE_Audio 那么无论它的有效名称是什么,它都是你的引脚 .

相关问题