Friday, June 27, 2008

CLSID_VideoCapture Filter Problem in windows Mobile Recorder application

CLSID_VideoCapture Filter problem:
----------------------------------------
I have developed the video capture application;
I have created the object for video capture filter( CoCreateInstance(CLSID_VideoCapture)),
and rendered the video successfully, if I released the video capture filter and created the CoCreateInstance(CLSID_VideoCapture Filter) I got the problem
in
PropertyBag->Load() fn;


CComPtr m_pPropertyBag;
CPropertyBag m_PropBag;
CComVariant m_varCamName;

hr = CoCreateInstance( CLSID_VideoCapture, NULL, CLSCTX_INPROC,
IID_IBaseFilter, (void** ) &m_pVideoCaptureFilter );

hr = m_pVideoCaptureFilter->QueryInterface( &m_pPropertyBag );
m_varCamName = _T ("CAM1:");
hr = m_PropBag.Write( L"VCapName", &m_varCamName );
hr = m_pPropertyBag->Load( &m_PropBag, NULL);
m_pPropertyBag.Release();
If I released the video capture filter and created the Second time , I got the error in


hr = m_pPropertyBag->Load( &m_PropBag, NULL); fn, it returns error as
" The Specified network resource or device is no longer available"


Solution:
------------
Error Message indicates "Video capture filter was not properly released;"
We need to release it properly;



We are releasing the video Capture Filter properly But it is not released; So Next time we got problems;
So Just confirm it, we have to release the video capture Filters only after all the Streams are stopped;




Code:
---------
For Releasing All the Filters and their Pins use the following code:

For Releasing the Source Filter use the following two methods and release all other things normally;
void CRecorder::NukeDownstream(IBaseFilter *pf)
{
IPin *pP=0, *pTo=0;
ULONG u;
IEnumPins *pins = NULL;
PIN_INFO pininfo;
if (!pf)
return;
HRESULT hr = pf->EnumPins(&pins);
pins->Reset();
while(hr == NOERROR)
{
hr = pins->Next(1, &pP, &u);
if(hr == S_OK && pP)
{
pP->ConnectedTo(&pTo);
if(pTo)
{
hr = pTo->QueryPinInfo(&pininfo);
if(hr == NOERROR)
{
if(pininfo.dir == PINDIR_INPUT)
{
NukeDownstream(pininfo.pFilter);
m_pGraphBuilder->Disconnect(pTo);
m_pGraphBuilder->Disconnect(pP);
m_pGraphBuilder->RemoveFilter(pininfo.pFilter);
}
pininfo.pFilter->Release();
}
pTo->Release();
}
pP->Release();
}
}
if(pins)
pins->Release();
}



void CRecorder::MyNukeDown( IBaseFilter *pFilter )
{
IEnumPins *pEnumPins;
IPin *pPin;
ULONG uNumPin;
HRESULT hr;
do
{
if( NULL == pFilter )
{
break;
}
hr = pFilter->EnumPins(&pEnumPins);
pEnumPins->Reset();
if( FAILED(hr) )
{
break;
}
while( S_OK == pEnumPins->Next( 1, &pPin, &uNumPin ) )
{
hr = m_pGraphBuilder->Disconnect(pPin);
if( S_OK != hr )
{
OutputDebugString(L"\n Disconect Failed");
}
}
m_pGraphBuilder->RemoveFilter( pFilter );
pFilter->Release();
//HELPER_RELEASE( pFilter );
pPin->Release();
pEnumPins->Release();
}while( FALSE );
}
Usage of this code is as follows:
NukeDownstream(m_pVideoCaptureFilter);
MyNukeDown(m_pVideoCaptureFilter);
CHECK_AND_RELEASE_COM_QI(m_pVideoWindow);
#ifdef _STILL
CHECK_AND_RELEASE_COM(m_pIImageSinkFilter);
CHECK_AND_RELEASE_COM(m_pImageSinkFilter);
#endif

CHECK_AND_RELEASE_COM(m_pVideoRenderer);
CHECK_AND_RELEASE_COM(m_pVideoEncoder);
CHECK_AND_RELEASE_COM(m_pVideoCaptureFilter);

No comments: