實作預覽釘選 (選擇性)
[與此頁面相關聯的功能,DirectShow是舊版功能。 它已被 MediaPlayer、IMFMediaEngine以及媒體基金會中的音訊/視訊擷取所取代。 這些功能已針對 Windows 10 和 Windows 11 進行優化。 Microsoft強烈建議新程式代碼盡可能在媒體 基礎中使用 MediaPlayer、IMFMediaEngine 和 音訊/視訊擷取,而不是 DirectShow。 Microsoft建議使用舊版 API 的現有程式代碼,盡可能改寫成使用新的 API。]
本主題描述如何在 DirectShow 捕捉濾鏡上實作預覽接腳。
如果您的篩選有預覽釘選,預覽釘選必須傳送擷取釘選所傳遞數據的複本。 在不會導致擷取端口丟幀的情況下,才從預覽端口傳送數據。 擷取插腳一律優先於預覽插腳。
擷取釘選和預覽釘選必須傳送具有相同格式的數據。 因此,它們必須使用相同的媒體類型進行連線。 如果擷取接口先連接,預覽接口應該提供相同的媒體類型,並拒絕任何其他類型。 如果預覽連接點首先連接,而擷取連接點使用不同的媒體類型連接,則預覽連接點應該使用新的媒體類型重新連接。 如果預覽針腳下游的過濾器拒絕新類型,擷取針腳也應該拒絕新類型。 使用 IPin::QueryAccept 方法來查詢在預覽接腳下游的篩檢,並使用 IFilterGraph::Reconnect 方法來重新連接接腳。 如果 Filter Graph Manager 重新連接擷取端口,這些規則也適用。
下列範例顯示此程式的大綱:
// Override CBasePin::CheckMediaType.
CCapturePin::CheckMediaType(CMediaType *pmt)
{
if (m_pMyPreviewPin->IsConnected())
{
// The preview pin is already connected, so query the pin it is
// connected to. If the other pin rejects it, so do we.
hr = m_pMyPreviewPin->GetConnected()->QueryAccept(pmt);
if (hr != S_OK)
{
// The preview pin cannot reconnect with this media type.
return E_INVALIDARG;
}
// The preview pin will reconnect when SetMediaType is called.
}
// Decide whether the capture pin accepts the format.
BOOL fAcceptThisType = ... // (Not shown.)
return (fAcceptThisType? S_OK : E_FAIL);
}
// Override CBasePin::SetMediaType.
CCapturePin::SetMediaType(CMediaType *pmt);
{
if (m_pMyPreviewPin->IsConnected())
{
// The preview pin is already connected, so it must reconnect.
if (m_pMyPreviewPin->GetConnected()->QueryAccept(pmt) == S_OK)
{
// The downstream pin will accept the new type, so it's safe
// to reconnect.
m_pFilter->m_pGraph->Reconnect(m_pMyPreviewPin);
}
else
{
return VFW_E_INVALIDMEDIATYPE;
}
}
// Now do anything that the capture pin needs to set the type.
hr = MyInternalSetMediaType(pmt);
// And finally, call the base-class method.
return CBasePin::SetMediaType(pmt);
}
CPreviewPin::CheckMediaType(CMediaType *pmt)
{
if (m_pMyCapturePin->IsConnected())
{
// The preview pin must connect with the same type.
CMediaType cmt = m_pMyCapturePin->m_mt;
return (*pmt == cmt ? S_OK : VFW_E_INVALIDMEDIATYPE);
}
// Decide whether the preview pin accepts the format. You can use your
// knowledge of which types the capture pin will accept. Regardless,
// when the capture pin connects, the preview pin will reconnect.
return (fAcceptThisType? S_OK : E_FAIL);
}
相關主題