0

MSDN page about Filter threading Considerations for flushing data为具有单个输入引脚和一个或多个输出引脚的过滤器提供了BeginFlushEndFlush的建议实现。

对于具有多个输入引脚的滤波器,应该如何安全地扩展它?应该为每个输入引脚调用 DeliverBeginFlush 和 DeliverEndFlush,还是为第一个或最后一个输入引脚调用 BeginFlush/EndFlush?输入引脚之间的确切操作顺序重要吗?是否允许一个输入引脚在其他引脚接收 BeginFlush 和/或 EndFlush 之前完成 BeginFlush 和 EndFlush 并接收新样本?在这种情况下还有其他考虑因素或陷阱吗?

目前,我的带有多个输入引脚的过滤器有时会在 EndFlush 完成后从上游接收陈旧的排队样本,我正在尝试诊断错误是在我的过滤器中还是在上游更远的地方。输入引脚正在为另一个生成输出样本的线程排队样本,因此我确实使用了 m_hSomeEventThatReceiveNeedsToWaitOn 技术来解除阻塞执行输出处理的线程。

HRESULT CMyInputPin::BeginFlush()
{
    CAutoLock lock_it(m_pLock);

    // First, make sure the Receive method will fail from now on.
    HRESULT hr = CBaseInputPin::BeginFlush();

    // Force downstream filters to release samples. If our Receive method
    // is blocked in GetBuffer or Deliver, this will unblock it.
    for (each output pin)
    {
    hr = pOutputPin->DeliverBeginFlush();
    }

    // Unblock our Receive method if it is waiting on an event.
    SetEvent(m_hSomeEventThatReceiveNeedsToWaitOn);

    // At this point, the Receive method can't be blocked. Make sure 
    // it finishes, by taking the streaming lock. (Not necessary if this 
    // is the last step.)
    { 
    CAutoLock lock_2(&m_csReceive);

    /* Now it's safe to do anything that would crash or hang 
       if Receive were executing. */
    }
    return hr;
}

HRESULT CMyInputPin::EndFlush()
{
    CAutoLock lock_it(m_pLock);
    for (each output pin)
        hr = pOutputPin->DeliverEndFlush();
    return CBaseInputPin::EndFlush();
}   
4

1 回答 1

1

在我的代码中,我只是愚蠢地为我收到的每个人提供一个冲洗下游。它似乎没有问题。

HRESULT JoinFilterInputPin::BeginFlush()
{
    JoinFilter* filter = (JoinFilter*)m_pFilter;
    CAutoLock lock(m_pLock);
    CBaseInputPin::BeginFlush();
    filter->output->DeliverBeginFlush();
    return S_OK;
}

HRESULT JoinFilterInputPin::EndFlush()
{
    JoinFilter* filter = (JoinFilter*)m_pFilter;
    CAutoLock lock(m_pLock);
    filter->output->DeliverEndFlush();
    return CBaseInputPin::EndFlush();
}
于 2013-02-05T18:58:01.620 回答