【问题标题】:Add sound filters and connect sound pins添加声音过滤器并连接声音引脚
【发布时间】:2014-10-14 20:09:24
【问题描述】:

上下文

带有用户控件的 WPF UI 可实例化多个 COMS 并通过 directshow.net 使用过滤器

问题

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

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

图表

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

问题

当引脚名称根据正在运行的 .avi 文件而改变时,如何连接过滤器?顺便说一句,一个 avi 文件是“自制”,而另一个是 microsoft 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;
}

获取密码

    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;
    }

【问题讨论】:

    标签: c# audio directshow avi directshow.net


    【解决方案1】:

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

    【讨论】:

    • 老兄。您是 Directshow 通天塔的主人和先知。你得到了我来自加拿大 QC 萨格奈的尊重。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多