ts,ps,mpeg2 decoder and analysis

mepg 2, iptv, stream parse,mov,mxf,gxf,ac3,aac

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  21 随笔 :: 0 文章 :: 54 评论 :: 0 Trackbacks


directshow,filter: 什么时候调用 m_pGraphBuilder->RemoveFilter

code如下: 如果用下列函数,调用系统自带的File Source,就无需 调用 m_pGraph->RemoveFilter,只要

调用 pFIFileSource->release();就可以了。

但是,如果不是系统的,必需用m_pGraphBuilder->RemoveFilter(),否则,filter的析构函数不会被调

用。


if (SUCCEEDED(hr)) 
  hr = CoCreateInstance(CLSID_AsyncSample, NULL, CLSCTX_INPROC,
        IID_IBaseFilter, (LPVOID *)

&pFIFileSource) ;
 if (SUCCEEDED(hr))
  hr = m_pGraphBuilder->AddFilter(pFIFileSource,L"Sample File Source");

 IFileSourceFilter *pAVIFileSource = NULL;

 if (SUCCEEDED(hr)) 
  hr = pFIFileSource->QueryInterface(IID_IFileSourceFilter,(void **)

&pAVIFileSource);


同样:
if (SUCCEEDED(hr)) 
  hr = CoCreateInstance(CLSID_MYSocketSource, NULL, CLSCTX_INPROC,
        IID_IBaseFilter, (LPVOID *)

&pFIFileSource) ;
 if (SUCCEEDED(hr))
  hr = m_pGraphBuilder->AddFilter(pFIFileSource,L"MY Socket Source");


...
最后必需用m_pGraphBuilder->RemoveFilter(),否则,filter的析构函数不会被调用。否则有很大的内

存泄露。

不知道是什么原因:

因为  www.directshow.cn: 这个网址不行了,所以贴出下列code,请大家分享。


HRESULT ConnectPins( IGraphBuilder* pGraphBuilder,
     IBaseFilter* pOutput,
     IBaseFilter* pInput,
     int nOutIndex,
     int nInIndex)
{
 HRESULT hr = NOERROR;
 ULONG cFetched = 0;
 IEnumPins* pEnumPins = 0;
 IPin* pPinOutput = 0;
 IPin* pPinInput = 0;

 //enum output filter pins.
 hr = pOutput->EnumPins(&pEnumPins);
 if(FAILED(hr))
 {
  return hr;
 }
 //if the pin to connect is not the first one, we must skip nOutIndex-1 pins.
 if(nOutIndex>1)
 {
  hr = pEnumPins->Skip(nOutIndex-1);
  if(FAILED(hr))
  {
   pEnumPins->Release();
   return hr;
  }
 }
 //now we can get the output pin we wanted.
 hr = pEnumPins->Next(1,&pPinOutput,&cFetched);
 if(FAILED(hr))
 {
  pEnumPins->Release();
  return hr;
 }
 pEnumPins->Release();

 //enum input filter pins.
 hr = pInput->EnumPins(&pEnumPins);
 if(FAILED(hr))
 {
  pPinOutput->Release();
  return hr;
 }
 //if input pin is not the first to connect, we must skip nInIndex-1 pins.
 if(nInIndex>1)
 {
  hr = pEnumPins->Skip(nInIndex-1);
  if( FAILED(hr) )
  {
   pPinOutput->Release();
   pEnumPins->Release();
   return hr;
  }
 }
 //now we can get the input pin we wanted.
 hr = pEnumPins->Next(1,&pPinInput,&cFetched);
 if(FAILED(hr))
 {
  pPinOutput->Release();
  pEnumPins->Release();
  return hr;
 }
 pEnumPins->Release();

 //now connect from output pin to input pin.
 hr = pGraphBuilder->Connect(pPinOutput,pPinInput);
 pPinOutput->Release();
 pPinInput->Release();
 return hr;
}
IPin* xMyFindPin(IBaseFilter *pFilter, const WCHAR achName[])
{
 BOOL       bFound = FALSE;
 IEnumPins  *pEnum;
 IPin       *pPin;
 PIN_INFO pininfo;

 if(pFilter==NULL)
  return NULL;
 pFilter->EnumPins(&pEnum);
 while(pEnum->Next(1, &pPin, 0) == S_OK)
 {
  pPin->QueryPinInfo(&pininfo);
  pininfo.pFilter->Release();
  if (bFound = (0 == wcscmp(pininfo.achName,achName)))
   break;
  pPin->Release();
 }
 pEnum->Release();
 return (bFound ? pPin : 0); 
}
static const GUID  CLSID_NULL_USER1=
{0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

HRESULT GetUnconnectedPin( IBaseFilter *pFilter,
        PIN_DIRECTION PinDir,
        IPin **ppPin,GUID gMajortype,WCHAR *achName)
{
 *ppPin = 0;
 IEnumPins *pEnum = 0;
 IPin *pPin = 0;
 HRESULT hr = pFilter->EnumPins( &pEnum );
 if( FAILED( hr ) )
 {
  return hr;
 }
 while( pEnum->Next( 1, &pPin, NULL ) == S_OK )
 {
  PIN_DIRECTION ThisPinDir;
  pPin->QueryDirection( &ThisPinDir );
  if( ThisPinDir == PinDir )
  {
   IPin *pTmp = 0;
   hr = pPin->ConnectedTo( &pTmp );
   if( SUCCEEDED( hr ) )
   {
    pTmp->Release( );
   }
   else
   {    
    PIN_INFO pininfo;
    pPin->QueryPinInfo(&pininfo);
    pininfo.pFilter->Release();
    if(achName && (wcslen(achName)>= wcslen(pininfo.achName)))
     wcscpy(achName,pininfo.achName);

    if(gMajortype==CLSID_NULL_USER1)
    {
     pEnum->Release( );
     *ppPin = pPin;
     return S_OK;
    }
    else
    {
     IEnumMediaTypes* pTypeEnum;
     hr = pPin->EnumMediaTypes (&pTypeEnum);

     hr =pTypeEnum->Reset();
     AM_MEDIA_TYPE* pMediaType;
     ULONG            ul ;

     do
     {
      hr = pTypeEnum->Next(1, &pMediaType, &ul) ;
      if (FAILED(hr) || 0 == ul)
      {
       pTypeEnum->Release();
       //pEnum->Release( );
       if(pTmp)
        pTmp->Release();
       break ;
      }

      if (pMediaType->majortype == gMajortype)
      // ||       pMediaType->subtype == MEDIASUBTYPE_DVSD)
      { pTypeEnum->Release();
       pEnum->Release( );
       *ppPin = pPin;
       return S_OK;
      }
     }while (1) ;   

    }
   }
   if(pTmp)
    pTmp->Release();
  }
  pPin->Release( );
 }
 pEnum->Release( );

 return E_FAIL;
}



TS,MPEG2,dvbc专家 2009-10-21 13:36 发表评论

文章来源:http://www.cnitblog.com/dvb-dvb/archive/2009/10/21/directshow.html
posted on 2009-10-21 13:36 TS,MPEG2,dvbc专家 阅读(1963) 评论(6)  编辑 收藏 引用

评论

# re: [导入]directshow,filter: 什么时候调用 m_pGraphBuilder->RemoveFilter 2009-10-23 12:16 dvbcn
test  回复  更多评论
  

# re: directshow,filter: 什么时候调用 m_pGraphBuilder->RemoveFilter 2009-10-23 13:37 126
不太明白  回复  更多评论
  

# re: directshow,filter: 什么时候调用 m_pGraphBuilder->RemoveFilter 2009-10-23 13:38 126.com
不是太懂  回复  更多评论
  

# re: directshow,filter: 什么时候调用 m_pGraphBuilder->RemoveFilter 2009-10-28 13:32 coloriy
哦也不太懂  回复  更多评论
  

# re: directshow,filter: 什么时候调用 m_pGraphBuilder->RemoveFilter 2009-10-28 17:26 TS,MPEG2,dvbc专家
感觉大家都不懂,我是不是学了 “回字有四种写法” ,这种无用的知识了,唉!  回复  更多评论
  

# re: directshow,filter: 什么时候调用 m_pGraphBuilder->RemoveFilter 2010-11-03 14:51 lxy
我也遇到了这个问题,跟踪调试了好久,调用connect之后就多出好多引用,调用pGraph->release()释放不全,必须手动调用pGraph->removefilter()  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理


ts,ps,mpeg2 decoder and analysis,ts分析.