根据clsid取得取得filter.docx_第1页
根据clsid取得取得filter.docx_第2页
根据clsid取得取得filter.docx_第3页
根据clsid取得取得filter.docx_第4页
根据clsid取得取得filter.docx_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

CoInitialize(NULL); HRESULT hr; IGraphBuilder* pGraphBuilder=NULL; CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void *)&pGraphBuilder); IBaseFilter*pMpeg4PSFileStream; IBaseFilter*pMpegDemuxFilter; IBaseFilter*pMpeg4VideoDecoder; IBaseFilter*pOverlayMaxer2; IBaseFilter*pVideoRenderer; hr=CoCreateInstance(CLSID_Mpeg4PSFileStream, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void*)&pMpeg4PSFileStream); if (FAILED(hr) AfxMessageBox(err create CLSID_Mpeg4PSFileStream); hr=CoCreateInstance(CLSID_MpegDemuxFilter, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void*)&pMpegDemuxFilter); if (FAILED(hr) AfxMessageBox(err create CLSID_MpegDemuxFilter); hr=CoCreateInstance(CLSID_Mpeg4VideoDecoder, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void*)&pMpeg4VideoDecoder); if (FAILED(hr) AfxMessageBox(err create CLSID_Mpeg4VideoDecoder); hr=CoCreateInstance(CLSID_OverlayMaxer2, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void*)&pOverlayMaxer2); if (FAILED(hr) AfxMessageBox(err create CLSID_OverlayMaxer2); hr=CoCreateInstance(CLSID_VideoRenderer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void*)&pVideoRenderer); if (FAILED(hr) AfxMessageBox(err create CLSID_VideoRenderer); pGraphBuilder-AddFilter(pMpeg4PSFileStream, NULL); pGraphBuilder-AddFilter(pMpegDemuxFilter, NULL); pGraphBuilder-AddFilter(pMpeg4VideoDecoder , NULL); pGraphBuilder-AddFilter(pOverlayMaxer2 , NULL); pGraphBuilder-AddFilter(pVideoRenderer , NULL); /set the source file IFileSourceFilter * pLoader; pMpeg4PSFileStream-QueryInterface(IID_IFileSourceFilter, (void *)&pLoader); hr=pLoader-Load(LE:tempmpeg4_ps.mpg,NULL); if (FAILED(hr) AfxMessageBox(装载文件出错!); /connect filter char *strPinName = new char; IEnumPins*EnumPins; IPin*OutPin; IPin*InPin; ULONGfetched; PIN_INFOpinfo; / find source output pMpeg4PSFileStream-EnumPins(&EnumPins); EnumPins-Reset(); EnumPins-Next(1, &OutPin, &fetched);/ only 1 pin for source, so we know this is the one we need EnumPins-Release(); / find Demux Filter input pMpegDemuxFilter-EnumPins(&EnumPins); EnumPins-Reset(); EnumPins-Next(1, &InPin, &fetched); InPin-QueryPinInfo(&pinfo); pinfo.pFilter-Release();/ make sure you release the returned IBaseFilter interface while (pinfo.dir = PINDIR_OUTPUT)/ check if we have wrong pin (not input pin),2 output pin InPin-Release(); EnumPins-Next(1, &InPin, &fetched);/ if so, get next pin InPin-QueryPinInfo(&pinfo); pinfo.pFilter-Release(); / connect - 1 pGraphBuilder-Connect(OutPin, InPin); InPin-Release(); OutPin-Release(); / find Demux Filter output EnumPins-Reset(); EnumPins-Next(1, &OutPin, &fetched); OutPin-QueryPinInfo(&pinfo); pinfo.pFilter-Release(); if (pinfo.dir = PINDIR_INPUT)/ check if we have wrong pin (not input pin),only 1 input pin InPin-Release(); EnumPins-Next(1, &OutPin, &fetched);/ if so, get next pin EnumPins-Release(); / find Vweb Mpeg4 Video Decoder input pMpeg4VideoDecoder-EnumPins(&EnumPins); EnumPins-Reset(); EnumPins-Next(1, &InPin, &fetched); InPin-QueryPinInfo(&pinfo); pinfo.pFilter-Release();/ make sure you release the returned IBaseFilter interface if (pinfo.dir = PINDIR_OUTPUT)/ check if we have wrong pin (not input pin),only 1 input pin InPin-Release(); EnumPins-Next(1, &InPin, &fetched);/ if so, get next pin / connect - 2 pGraphBuilder-Connect(OutPin, InPin); InPin-Release(); OutPin-Release(); / find Vweb Mpeg4 Video Decoder output * EnumPins-Reset(); EnumPins-Next(1, &OutPin, &fetched); OutPin-QueryPinInfo(&pinfo); pinfo.pFilter-Release();/ make sure you release the returned IBaseFilter interface if (pinfo.dir = PINDIR_INPUT)/ check if we have wrong pin (not input pin),only 1 input pin OutPin-Release(); EnumPins-Next(1, &OutPin, &fetched);/ if so, get next pin OutPin-QueryPinInfo(&pinfo); pinfo.pFilter-Release(); WCHAR *s=pinfo.achName; EnumPins-Release(); / find Overlay Mixer2 input pOverlayMaxer2-EnumPins(&EnumPins); EnumPins-Reset(); EnumPins-Next(1, &InPin, &fetched); InPin-QueryPinInfo(&pinfo); pinfo.pFilter-Release();/ make sure you release the returned IBaseFilter interface WCHAR *s=pinfo.achName; if (pinfo.dir = PINDIR_OUTPUT)/ check if we have wrong pin (not input pin),2 input pin InPin-Release(); EnumPins-Next(1, &InPin, &fetched);/ if so, get next pin / connect - 3 pGraphBuilder-Connect(OutPin, InPin); InPin-Release(); OutPin-Release(); / find Overlay Mixer2 output EnumPins-Reset(); EnumPins-Next(1, &OutPin, &fetched); OutPin-QueryPinInfo(&pinfo); pinfo.pFilter-Release();/ make sure you release the returned IBaseFilter interface while (pinfo.dir = PINDIR_INPUT)/ check if we have wrong pin (not input pin),2 input pin OutPin-Release(); EnumPins-Next(1, &OutPin, &fetched);/ if so, get next pin OutPin-QueryPinInfo(&pinfo); pinfo.pFilter-Release(); WCHAR *s=pinfo.achName; EnumPins-Release(); / find renderer input pVideoRenderer-EnumPins(&EnumPins); EnumPins-Reset(); EnumPins-Next(1, &InPin, &fetched);/ renderer has only 1 pin, so this is the pin we need EnumPins-Release(); / connect - 4 pGraphBuilder-Connect(OutPin, InPin); InPin-Release(); OutPin-Release(); IMediaEvent *pEvent; IMediaControl *pMediaControl; / Create the filter graph manager and query for interfaces. hr=pGraphBuilder-QueryInterface(IID_IMediaControl, (void *)&pMediaControl); hr=pGraphBuilder-QueryInterface(IID_IMediaEvent, (void *)&pEvent); / Run the graph. pMediaControl-Run(); / Wait for completion. long evCode; pEvent-WaitForCompletion(INFINITE, &evCode); / Clean up. pMpeg4PSFileStream-Release(); pMpegDemuxFilter-Release(); pMpeg4VideoDecoder-Release(); pOverlayMaxer2-Release(); pVideoRenderer-Release(); pMediaControl-Release(); pEvent-Release(); pGraphBuilder-Release(); delete strPinName; CoUninitialize(); 长枪大戟的代码都已经包括了,不过听说不在directshow filter里的filter需要枚举才能正常使用,但是我没有试过,不知道是不是,以下代码是枚举捕捉设备的. HRESULT CCaptureEx:FindCaptureDevice(IBaseFilter *ppSrcFilter) HRESULT hr; IBaseFilter * pSrc = NULL; CComPtr pMoniker =NULL; ULONG cFetched; if (!ppSrcFilter) return E_POINTER; / Create the system device enumerator CComPtr pDevEnum =NULL; hr = CoCreateInstance (CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, IID_ICreateDevEnum, (void *) &pDevEnum); if (FAILED(hr) Msg(TEXT(Couldnt create system enumerator!hr=0x%x), hr); return hr; / Create an enumerator for the video capture devices CComPtr pClassEnum = NULL; hr = pDevEnum-CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &pClassEnum, 0); if (FAILED(hr) /Msg(TEXT(Couldnt create class enumerator!hr=0x%x), hr); return hr; / If there are no enumerators for the requested type, then / CreateClassEnumerator will succeed, but pClassEnum will be NULL. if (pClassEnum = NULL) return E_FAIL; / Use the first video capture device on the device list. / Note that if the Next() call succeeds but there are no monikers, / it will return S_FALSE (which is not a failure).Therefore, we / check that the return code is S_OK instead of using SUCCEEDED() macro. if (S_OK = (pClassEnum-Next (1, &pMoniker, &cFetched) / Bind Moniker to a filter object hr = pMoniker-BindToObject(0,0,IID_IBaseFilter, (void*)&pSrc); if (FAILED(hr) /Msg(TEXT(Couldnt bind moniker to filter object!hr=0x%x), hr); return hr; else /Msg(TEXT(Unable to access video capture device!); return E_FAIL; / Copy the found filter pointer to the output parameter. / Do NOT Release() the reference, since it will still be used / by the calling function. *ppSrcFilter = pSrc; return hr; / 根据Filter的DisplayName来获取其IMoniker指针,并将IMoniker指针绑定到一个IBaseFilter指针中 HRESULT CDXGraph:DisplayNameToMoniker(WCHAR * szDisplayName, IBaseFilter * ppBf) if (! mGraph | ! szDisplayName| ! ppBf) return E_POINTER; IBaseFilter *pFilter = NULL; IBindCtx *pBindCtx; HRESULT hr = CreateBindCtx(0, &pBindCtx); ULONG chEaten = 0; CComPtr pMoniker = NULL; hr = MkParseDisplayName(pBindCtx, szDisplayName, &chEaten, &pMoniker); pBindCtx-Release(); if (SUCCEEDED(hr) hr = pMoniker-BindToObject(NULL, NULL, IID_IBaseFilter,(void *)&pFilter); if (FAILED(hr) AfxMessageBox(TEXT(Couldnt bind moniker to filter object!); return E_FAIL; / Copy the found filter pointer to the output parameter. / Do NOT Release() the reference, since it will still be used / by the calling function. *ppBf = pFilter; return hr; return hr; /使用xvid mpge4的代码,其中szDisplay存储的是Filter的DisplayName,可以重GraphEdit中查看 WCHAR szDisplay = Ldevice:cm:33D9A760-90C8-11D0-BD43-00A0C911CE86xvid; if (SUCCEEDED(mFilterGraph-DisplayNameToMoniker(szDisplay, &pVideoCompressFilter) if (SUCCEEDED(mFilterGraph-GetGraph()-AddFilter(pVideoCompressFilter,LXVid MPEG-4 Codec) /pVideoCompressFilter-Release(); / 获取视频采集的Capture Source Filter和FriendlyName HRESULT CDXGraph:EnumVideoCaptureSource(IBaseFilter * ppBf, WCHAR* szFilterName) if (!mGraph | ! ppBf) return E_POINTER; / Create the System Device Enumerator. IBaseFilter *pFilter = NULL; HRESULT hr; CComPtr pSysDevEnum = NULL; hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void *)&pSysDevEnum); if (FAILED(hr) return hr; / Obtain a class enumerator for the video capture Source category. CComPtr pEnumCat = NULL; hr = pSysDevEnum-CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0); if (FAILED(hr) AfxMessageBox(Create class enumerator for the video capture Failed.); return hr; / If there are no enumerators for the requested type, then / CreateClassEnumerator will succeed, but pClassEnum will be NULL. if (pEnumCat = NULL) CString str(); str += TEXT(No video capture device was detected.rnrn); str += TEXT(This sample requires a video capture device, such as a USB WebCam,rn); str += TEXT(This sample requires a video capture device, such as a USB WebCam,rn); str += TEXT(This sample requires a video capture device, such as a USB WebCam,rn); str += TEXT(to be installed and working properly.The sample will now close.); AfxMessageBox(str); return E_FAIL; / Use the first video capture device on the device list. / Note that if the Next() call succeeds but there are no monikers, / it will return S_FALSE (which is not a failure).Therefore, we / check that the return code is S_OK instead of using SUCCEEDED() macro. CComPtr pMoniker = NULL; U

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论