全部博文(282)
分类:
2007-09-20 23:08:50
// 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 // Define a typedef for a list of filters. typedef CGenericList // 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(); } } |