[DirectShow] 039 - Enumerating Pins

Filters support the IBaseFilter::EnumPins method, which enumerates the pins available on the filter. It returns a pointer to the IEnumPins interface. The IEnumPins::Next method retrieves IPin interface pointers.

filter 支持 IBaseFilter::EnumPins 方法用来枚举 filter 上可见的 pin 。这个函数返回 IEnumPins 接口的指针。 IEnumPins::Next 方法获得 IPin 接口指针。

The following example shows a function that locates a pin with a given direction (input or output) on a given filter. It uses the PIN_DIRECTION enumeration to specify the pin direction, and the IPin::QueryDirection method to find the direction of each enumerated pin. If this function finds a matching pin, it returns an IPin interface pointer with an outstanding reference count. The caller is responsible for releasing the interface.

以下例子展示一个方法,在给定 filter 上指出指定方法的 pin 。使用 PIN_DIRECTION 枚举表示 pin 方向,用 IPin::QueryDirection 方法找出每一个被枚举的 pin 的方法。如果这个方法找到了一个匹配的 pin ,就返回这个 pin 的接口指针。调用者有责任释放这个接口。

 

HRESULT GetPin(IBaseFilter *pFilter, PIN_DIRECTION PinDir, IPin **ppPin) { IEnumPins *pEnum = NULL; IPin *pPin = NULL; HRESULT hr; if (ppPin == NULL) { return E_POINTER; } hr = pFilter->EnumPins(&pEnum); if (FAILED(hr)) { return hr; } while(pEnum->Next(1, &pPin, 0) == S_OK) { PIN_DIRECTION PinDirThis; hr = pPin->QueryDirection(&PinDirThis); if (FAILED(hr)) { pPin->Release(); pEnum->Release(); return hr; } if (PinDir == PinDirThis) { // Found a match. Return the IPin pointer to the caller. *ppPin = pPin; pEnum->Release(); return S_OK; } // Release the pin for the next time through the loop. pPin->Release(); } // No more pins. We did not find a match. pEnum->Release(); return E_FAIL; }

 


 

你可能感兴趣的:(function,filter,null,interface,reference,output)