2011-09-10 109 views
1

我正嘗試使用GmfBridge庫來動態地將源濾波器從凸輪更改爲文件,反之亦然。所有函數都返回S_OK(好吧,幾乎所有 - pMediaControlOutput-> Run()實際上返回S_FALSE,但在msdn中說這也可以),所以我認爲一切正常,但數據不會轉移到其他橋的一側。我使用GraphStudio連接到遠程圖形,並且全部似乎都沒問題 - 兩個圖形中的所有過濾器都按照原樣連接。不過,雖然打我收到的橋樑日誌文件以下消息:GmfBridge不會將源濾波器與源濾波器連接

0: Started 2011-09-10 15:58:38 
0: Buffer minimum 100 
0: Added stream 1: 畡楤o, Decompressed Only, Discard mode 
1: Sink 0x7ae0ca8 has 1 pins 
1: Sink filter 0x7ae0cf8 in graph 0x193bf0 
2: Source 0x7ae1030 has 1 pins 
2: Source filter 0x7ae1080 in graph 0x194c18 
14: ReceiveConnection Aware: false 
14: Bridging 0x194c18 to 0x193bf0 
14: Pin 0x7ae3438 disconnect 
25: Source 0x7ae1030 pause from 0 
25: Source pin 0x7ae3618 active 
2234: Pin 0x7ae3438 receive 0x721ec68 
2234: Sink pin 0x7ae3438 disconnected: discarding 0x721ec68 
3389: Pin 0x7ae3438 receive 0x721ec68 
3389: Sink pin 0x7ae3438 disconnected: discarding 0x721ec68 
3940: Pin 0x7ae3438 receive 0x721ec68 
3940: Sink pin 0x7ae3438 disconnected: discarding 0x721ec68 
4440: Pin 0x7ae3438 receive 0x721ec68 

因此,大家可以看到,左邊的圖沒有,儘管()返回S_OK和媒體樣品被丟棄BridgeGraphs連接到正確的。下面是我的代碼。我哪裏錯了?

// Create graphs 
HRESULT hr = m_graphInput.CreateInstance(CLSID_FilterGraph); 
ATLASSERT(SUCCEEDED(hr)); 
hr = m_graphOutput.CreateInstance(CLSID_FilterGraph); 
ATLASSERT(SUCCEEDED(hr)); 

// Get IMediaControl interfaces 
hr = m_graphInput.QueryInterface(IID_IMediaControl, (void**)&pMediaControlInput); 
ATLASSERT(SUCCEEDED(hr)); 
hr = m_graphOutput.QueryInterface(IID_IMediaControl, (void**)&pMediaControlOutput); 
ATLASSERT(SUCCEEDED(hr)); 

// Get builder interfaces 
hr = m_graphInput.QueryInterface(IID_IGraphBuilder, (void**)&pBuilderInput); 
ATLASSERT(SUCCEEDED(hr)); 
hr = m_graphOutput.QueryInterface(IID_IGraphBuilder, (void**)&pBuilderOutput); 
ATLASSERT(SUCCEEDED(hr)); 

// Load source filter (on sink side) 
LocateFilter(SOURCE_FILTER_NAME, CLSID_LegacyAmFilterCategory, &inputDevice); 
hr = m_graphInput->AddFilter(inputDevice, SOURCE_FILTER_NAME); 
ATLASSERT(SUCCEEDED(hr)); 

// Load render filter (on bridge's source side) 
LocateFilter(_T("Default DirectSound Device"), CLSID_AudioRendererCategory, &audioOutputPreview); 
hr = m_graphOutput->AddFilter(audioOutputPreview, _T("Default DirectSound Device")); 
ATLASSERT(SUCCEEDED(hr)); 

// Init bridge 
bridge.CreateInstance(__uuidof(GMFBridgeController)); 
hr = bridge->SetBufferMinimum(100); 
ATLASSERT(SUCCEEDED(hr)); 
hr = bridge->AddStream(false, eUncompressed, false); 
ATLASSERT(SUCCEEDED(hr)); 

// Add sink filter and connect to input graph 
IUnknownPtr pSinkFilter; 
{ 
    hr = bridge->InsertSinkFilter(m_graphInput, (IUnknown**)&pSinkFilter); 
    ATLASSERT(SUCCEEDED(hr)); 

    // Using own functions get pins 
    IPin* pInAudio = CPinController::getOutputPin(inputDevice, _T("Audio")); 
    IPin* pOutAudio = CPinController::getInputPin(pSinkFilter); 
    hr = pBuilderInput->Connect(pOutAudio, pInAudio); 
    ATLASSERT(SUCCEEDED(hr)); 
} 

// Add output filter and connect to output graph 
IUnknownPtr pFeederFilter; 
{ 
    hr = bridge->InsertSourceFilter(pSinkFilter, m_graphOutput, &pFeederFilter); 
    ATLASSERT(SUCCEEDED(hr)); 

    // Get pins 
    IPin* pInAudio = CPinController::getOutputPin(pFeederFilter/*, _T("Audio")*/); 
    IPin* pOutAudio = CPinController::getInputPin(audioOutputPreview); 
    hr = pBuilderOutput->Connect(pInAudio, pOutAudio); 
    ATLASSERT(SUCCEEDED(hr)); 
} 

// Run left 
hr = pMediaControlInput->Run(); 
ATLASSERT(SUCCEEDED(hr)); 

// Run right 
hr = pMediaControlOutput->Run(); 
ATLASSERT(SUCCEEDED(hr)); 

hr = bridge->BridgeGraphs(m_graphOutput, m_graphInput); 
ATLASSERT(SUCCEEDED(hr)); 

回答

2

這真的很荒謬,但大約幾分鐘前,經過一天的搜索,我們找到了答案。所有的交易都是關於GmfBridge的巨大漏洞。我在這裏給錯誤的接口(有圖,而不是橋的接收器和源過濾器)「怎麼函數需要指針的IUnknown:

hr = bridge->BridgeGraphs(m_graphOutput, m_graphInput); 

而且在GmfBridge庫這種情況下,沒有正確處理 - 沒有「其他「早午餐處理錯誤和函數會返回一個被設置在開始S_OK小時:

HRESULT STDMETHODCALLTYPE BridgeGraphs( 
     /* [in] */ IUnknown *pSourceGraphSinkFilter, 
     /* [in] */ IUnknown *pRenderGraphSourceFilter) 
{ 
    HRESULT hr = S_OK; 
    ... 
    // if we are not given both filters, then 
    // we need do nothing 
    IBridgeSinkPtr pSink = pSourceGraphSinkFilter; 
    IBridgeSourcePtr pSource = pRenderGraphSourceFilter; 
    if ((pSink != NULL) && (pSource != NULL)) 
    { 
     ... 
    } 

    return hr; 
} 

因此,大家可以看到它只是說有什麼不對,然後就去做什麼!我認爲通知lib的作者關於這個錯誤是個好主意。 希望這個信息會幫助別人。

+2

感謝您的意見。幸運的是,你有足夠的資源來跟蹤這一點。我將在下次更新時添加一些錯誤檢查。 –

+0

@Geraint哇,你回覆得太快了(我甚至沒有給你發過電子郵件來描述這個問題,我認爲它不再需要了? –