DirectShow删除链路 和 删除graph中的所有filter

一般应用DirectShow的时候,我们会封装一个类。

一般情况下,如果摄像头被占用,就无法再次开启。


这里举个例子,如:


在类中声明主要变量;

清理变量;


CCaptureCam

{


IGraphBuilder* m_pGraphBuilder;
IFilterGraph*           m_pFilterGraph;
ICaptureGraphBuilder2 * m_pCaptureGraphBuilder2;

IMediaControl *         m_pMediaControl; 
    IVideoWindow *          m_pVideoWindow;  
    IMediaSeeking *         m_pMediaSeeking; 
    IBaseFilter *           m_pSrcFilter;     
    IBaseFilter *           m_pRenderFilter; 
IBasicVideo * m_pBasicVideo;
 

IBaseFilter * m_pGrabber; 


IMediaEvent *           m_pMediaEvent;

IAMVideoProcAmp * m_pProcAmp;



~CCaptureVideo()

{

//假定变量已经创建,链路已经建立运行;


//删除链路中的所有Filter;

// Stop the graph.
m_pMediaControl->Stop();
// Enumerate the filters in the graph.
IEnumFilters *pEnum = NULL;
hr = m_pGraphBuilder->EnumFilters(&pEnum);
if (SUCCEEDED(hr))
{
IBaseFilter *pFilter = NULL;
while (S_OK == pEnum->Next(1, &pFilter, NULL))
{
// Remove the filter.
m_pGraphBuilder->RemoveFilter(pFilter);
// Reset the enumerator.
pEnum->Reset();
pFilter->Release();
}
pEnum->Release();
}



//释放变量资源;如果仅仅释放资源,上述中的Filter和链路没有被删;
if(m_pMediaControl)
{
m_pMediaControl->Release();
m_pMediaControl=NULL;
}
if(m_pMediaEvent)
{
m_pMediaEvent->Release();
m_pMediaEvent=NULL;
}
if(m_pVideoWindow)
{
m_pVideoWindow->Release();
m_pVideoWindow = NULL;
}
if(m_pBasicVideo)
{
m_pBasicVideo->Release();
m_pBasicVideo = NULL;
}
if(m_pMediaSeeking)
{
m_pMediaSeeking->Release();


}
if(m_pSrcFilter)
{
m_pSrcFilter->Release();
}
if(m_pRenderFilter)
{
m_pRenderFilter->Release();
}




if(m_pGrabber)
{
m_pGrabber->Release();
}
if(m_pProcAmp)
{
m_pProcAmp->Release();
}

}



}

你可能感兴趣的:(DirectShow删除链路 和 删除graph中的所有filter)