码迷,mamicode.com
首页 > 其他好文 > 详细

查找IFileSourceFilter上的Pin

时间:2014-10-27 19:37:44      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:style   io   os   ar   for   sp   文件   on   cti   

创建了IFileSourceFilter,可IFileSourceFilter好像不是从IBaseFilter继承来的,没有EnumPins,那应该怎么查找IFileSourceFilter上的pin啊?
IGraphBuilder *pigb  = NULL;
IMediaControl *pimc  = NULL;
IMediaEventEx *pimex = NULL;
IVideoWindow  *pivw  = NULL;
IMediaSeeking  *pims  = NULL;

HRESULT AddSourceByFilterCLSID(IGraphBuilder *pGraph,const GUID& clsid,	LPCWSTR wszName,LPCWSTR wszFileName)
{
		if  (!pGraph) return E_POINTER; 
		IBaseFilter *pF = 0; 
		HRESULT      hr = S_OK; 
		hr = CoCreateInstance(clsid, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, reinterpret_cast<void**>(&pF)); 
		if (SUCCEEDED(hr)) 
		{ 
			hr = pGraph->AddFilter(pF, wszName); 
			if (SUCCEEDED(hr))
			{
				IFileSourceFilter *pSF = NULL;
				hr = pF->QueryInterface(IID_IFileSourceFilter, (void**)&pSF);
				if (SUCCEEDED(hr))
				{
					pSF->Load(wszFileName, NULL);
					pSF->Release();
				}
			}
			
			if (SUCCEEDED(hr))
			{
				IEnumPins *pEnum;
				IPin      *pPin;
				hr = pF->EnumPins(&pEnum);
				if (SUCCEEDED(hr))
				{
					while(pEnum->Next(1, &pPin, 0) == S_OK)
					{
						PIN_DIRECTION pinDirThis;
						pPin->QueryDirection(&pinDirThis);
						if (PINDIR_OUTPUT == pinDirThis)
						{
							hr = pGraph->Render(pPin);
							if (FAILED(hr))
							{
								break;
							}
						}
						pPin->Release();
					}
					pEnum->Release();
				}
			}
			
			pF->Release(); 
		} 
		return hr; 
} 

HRESULT RenderAVI(LPCTSTR szFilePath,IGraphBuilder * gb)
{
	LPCTSTR szExt = _tcsrchr(szFilePath,‘.‘);//过滤avi文件
	if(!szExt)
	{
		return E_FAIL;
	}
	++szExt;
	if(_tcsicmp(szExt,_T("avi"))!=0) return E_INVALIDARG;
	USES_CONVERSION;
	const GUID CLSID_AviSource={0xCEA8DEFF,0x0AF7,0x4DB9,{0x9A,0x38,0xFB,0x3C,0x3A,0xEF,0xC0,0xDE}};
	CComPtr<IBaseFilter> spAviSource;
	HRESULT hr = AddSourceByFilterCLSID(gb,CLSID_AviSource,L"SOURCE FILTER",T2W(szFilePath));
	if(spAviSource==NULL) return hr;
/*	CComQIPtr<IFileSourceFilter> FileSource(spAviSource);
	hr = FileSource->Load(T2W(szFilePath),NULL);
	if(FAILED(hr)) return hr;
	CComPtr<IEnumPins> ep;
	hr = spAviSource->EnumPins(&ep);
	if(FAILED(hr)) return hr;
	CComPtr<IPin> pin;
	DWORD dwCount;
	int i = 0;
	for(;;)
	{
		dwCount = 0;
		hr = ep->Next(1,&pin,&dwCount);
		if(hr!=NOERROR)
		{
			if(i) hr = NOERROR;
			break;
		}
		hr = gb->Render(pin);
		if(hr==NOERROR) ++i;
		pin = NULL;
	}
	return hr;*/
	return NOERROR;
}

void CTestFilterDlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
	CoInitialize(NULL);
    HRESULT	hr = CoCreateInstance(CLSID_FilterGraph,
		NULL,
		CLSCTX_INPROC_SERVER,
		IID_IGraphBuilder,
		(void **)&pigb);
	   pigb->QueryInterface(IID_IMediaControl, (void **)&pimc);
	   pigb->QueryInterface(IID_IMediaEventEx, (void **)&pimex);
       pigb->QueryInterface(IID_IMediaSeeking, (void **)&pims);
	   pigb->QueryInterface(IID_IVideoWindow, (void **)&pivw);
	  // hr = pigb->RenderFile(L"d:\\temp\\bmw.MPG", NULL);//
      hr = RenderAVI("F:\\FFOutput\\ff640480.avi",pigb);

      if (hr)
      {
		  MessageBox("ERR RENDERAVI!");
      }

	   HWND m_hwndScreen = m_Screen2.GetSafeHwnd();
	   
	   RECT rc;

	   hr = pivw->put_Owner((OAHWND)m_hwndScreen);
	   hr = pivw->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);
	   m_Screen2.GetClientRect(&rc);
	   hr = pivw->SetWindowPosition(0, 0, (rc.right), (rc.bottom));
	   hr = pivw->put_Visible(OATRUE);//*/
	   hr = pimc->Run();
}


查找IFileSourceFilter上的Pin

标签:style   io   os   ar   for   sp   文件   on   cti   

原文地址:http://blog.csdn.net/mao0514/article/details/40511685

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!