DirectShow相关

//得到Pin
HRESULT GetPin(IBaseFilter *pFilter, PIN_DIRECTION PinDir, const WCHAR * pinName, IPin **ppPin)
{
 IEnumPins  *pEnum;
 IPin       *pPin;
 HRESULT    hr;

 hr = pFilter->EnumPins(&pEnum);
 if (FAILED(hr)) return hr;

 while(pEnum->Next(1, &pPin, 0) == S_OK)
 {
  PIN_INFO pInfo;
  hr = pPin->QueryPinInfo(&pInfo);
  if (SUCCEEDED(hr) && PinDir == pInfo.dir)
  {
   //检查名字是否相同,用于有多个输入或输出的Pin
   if(pinName != NULL && wcsncmp(pInfo.achName,pinName,128) != 0)
   {
    pPin->Release();
    continue;
   }
   pEnum->Release();
   *ppPin = pPin;
   return S_OK;
  }
  pPin->Release();
 }
 pEnum->Release();
 return E_FAIL; 
}

//连接Pin
HRESULT ConnectFilters(IGraphBuilder *pGraph, IBaseFilter *pFirst, const WCHAR * pinOutName, IBaseFilter *pSecond, const WCHAR * pinInName)
{
 IPin *pOut = NULL, *pIn = NULL;
 HRESULT hr = GetPin(pFirst, PINDIR_OUTPUT, pinOutName, &pOut);
 if (FAILED(hr)) return hr;
 hr = GetPin(pSecond, PINDIR_INPUT, pinInName, &pIn);
 if (FAILED(hr))
 {
  pOut->Release();
  return E_FAIL;
 }
 hr = pGraph->Connect(pOut, pIn);
 pIn->Release();
 pOut->Release();
 return hr;
}

posted @ 2010-07-06 23:49  边城浪  阅读(318)  评论(0编辑  收藏  举报