扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:智慧的鱼 来源:天极开发 2007年10月16日
关键字:
// Get the first upstream or downstream filter HRESULT GetNextFilter( IBaseFilter *pFilter, // 开始的filter PIN_DIRECTION Dir, // 搜索的方向 (upstream 还是 downstream) IBaseFilter **ppNext) // Receives a pointer to the next filter. { if (!pFilter || !ppNext) return E_POINTER; IEnumPins *pEnum = 0; IPin *pPin = 0; HRESULT hr = pFilter->EnumPins(&pEnum); if (FAILED(hr)) return hr; while (S_OK == pEnum->Next(1, &pPin, 0)) { // See if this pin matches the specified direction. PIN_DIRECTION ThisPinDir; hr = pPin->QueryDirection(&ThisPinDir); if (FAILED(hr)) { // Something strange happened. hr = E_UNEXPECTED; pPin->Release(); break; } if (ThisPinDir == Dir) { // Check if the pin is connected to another pin. IPin *pPinNext = 0; hr = pPin->ConnectedTo(&pPinNext); if (SUCCEEDED(hr)) { // Get the filter that owns that pin. PIN_INFO PinInfo; hr = pPinNext->QueryPinInfo(&PinInfo); pPinNext->Release(); pPin->Release(); pEnum->Release(); if (FAILED(hr) || (PinInfo.pFilter == NULL)) { // Something strange happened. return E_UNEXPECTED; } // This is the filter we're looking for. *ppNext = PinInfo.pFilter; // Client must release. return S_OK; } } pPin->Release(); } pEnum->Release(); // Did not find a matching filter. return E_FAIL; } |
IBaseFilter *pF; // Pointer to some filter. IBaseFilter *pUpstream = NULL; if (SUCCEEDED(GetNextFilter(pF, PINDIR_INPUT, &pUpstream))) { // Use pUpstream ... pUpstream->Release(); } |
#include <streams.h> // Link to the DirectShow base class library // Define a typedef for a list of filters. typedef CGenericList<IBaseFilter> CFilterList; // Forward declaration. Adds a filter to the list unless it's a duplicate. void AddFilterUnique(CFilterList &FilterList, IBaseFilter *pNew); // Find all the immediate upstream or downstream peers of a filter. HRESULT GetPeerFilters( IBaseFilter *pFilter, // Pointer to the starting filter PIN_DIRECTION Dir, // Direction to search (upstream or downstream) CFilterList &FilterList) // Collect the results in this list. { if (!pFilter) return E_POINTER; IEnumPins *pEnum = 0; IPin *pPin = 0; HRESULT hr = pFilter->EnumPins(&pEnum); if (FAILED(hr)) return hr; while (S_OK == pEnum->Next(1, &pPin, 0)) { // See if this pin matches the specified direction. PIN_DIRECTION ThisPinDir; hr = pPin->QueryDirection(&ThisPinDir); if (FAILED(hr)) { // Something strange happened. hr = E_UNEXPECTED; pPin->Release(); break; } if (ThisPinDir == Dir) { // Check if the pin is connected to another pin. IPin *pPinNext = 0; hr = pPin->ConnectedTo(&pPinNext); if (SUCCEEDED(hr)) { // Get the filter that owns that pin. PIN_INFO PinInfo; hr = pPinNext->QueryPinInfo(&PinInfo); pPinNext->Release(); if (FAILED(hr) || (PinInfo.pFilter == NULL)) { // Something strange happened. pPin->Release(); pEnum->Release(); return E_UNEXPECTED; } // 将符合的filter添加到list中 AddFilterUnique(FilterList, PinInfo.pFilter); PinInfo.pFilter->Release(); } } pPin->Release(); } pEnum->Release(); return S_OK; } void AddFilterUnique(CFilterList &FilterList, IBaseFilter *pNew) { if (pNew == NULL) return; POSITION pos = FilterList.GetHeadPosition(); while (pos) { IBaseFilter *pF = FilterList.GetNext(pos); if (IsEqualObject(pF, pNew)) { return; } } pNew->AddRef(); // The caller must release everything in the list. FilterList.AddTail(pNew); } |
IBaseFilter *pF; // Pointer to some filter. CFilterList FList(NAME("MyList")); // List to hold the downstream peers. hr = GetPeerFilters(pF, PINDIR_OUTPUT, FList); if (SUCCEEDED(hr)) //解析filter 的集合。 { POSITION pos = FList.GetHeadPosition(); while (pos) { IBaseFilter *pDownstream = FList.GetNext(pos); pDownstream->Release(); } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者