Problem with CROSSBAR in DirectShow
-
Dear All, I am developing an application to preview the video from a Capture device. I have developed the application and it is working fine, but the problem is that it is playing two times correctly but for the third time i got error while connecting with video renderer. Please help me. Code snippet is given below :
void DialogPlayer::OnBnClickedButton12()
{
bool x= CreateVideoGraph();
}BOOL DialogPlayer::CreateVideoGraph()//Creating the graph for video
{
hr = CoCreateInstance(CLSID_FilterGraph, NULL,CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);
if(FAILED(hr))
{
return FALSE;
}
if (SUCCEEDED(hr))
{
//Create the Capture Graph Builder.
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL,CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2,(void **)&pBuilder);
if(FAILED(hr))
{
return FALSE;
}
if (SUCCEEDED(hr))
{
hr=pBuilder->SetFiltergraph(pGraph);
if(FAILED(hr))
{
return FALSE;
}
}
}
hr= pGraph->QueryInterface(IID_IMediaControl,(LPVOID *) &(pControl));
hr=pGraph->QueryInterface(IID_IVideoWindow, (LPVOID *) &(VideoWindow));
ICreateDevEnum *pSysDevEnum = NULL;
hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
if(FAILED(hr))
{
return FALSE;
}
IEnumMoniker *pEnumCat = NULL;
hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);
if (hr == S_OK)
{
IMoniker *pMoniker = NULL;
ULONG cFetched;
while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
{
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
if (SUCCEEDED(hr))
{
VARIANT varName;
VariantInit(&varName);
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
BSTR name2=varName.bstrVal;
if((wcscmp(name2, "Video Capture AV")==0))
{
hr=pMoniker->BindToObject(0,0,IID_IBaseFilter, (void**)&(VideoSourceFilter));
hr=pGraph->AddFilter(VideoSourceFilter,L"Video Source");
check1=1;
}
if(check1==0)
{
return FALSE;
}
pPropBag->Release();
}
pMoniker->Release();
}
pEnumCat->Release();
}
else
{
return FALSE -
Dear All, I am developing an application to preview the video from a Capture device. I have developed the application and it is working fine, but the problem is that it is playing two times correctly but for the third time i got error while connecting with video renderer. Please help me. Code snippet is given below :
void DialogPlayer::OnBnClickedButton12()
{
bool x= CreateVideoGraph();
}BOOL DialogPlayer::CreateVideoGraph()//Creating the graph for video
{
hr = CoCreateInstance(CLSID_FilterGraph, NULL,CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);
if(FAILED(hr))
{
return FALSE;
}
if (SUCCEEDED(hr))
{
//Create the Capture Graph Builder.
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL,CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2,(void **)&pBuilder);
if(FAILED(hr))
{
return FALSE;
}
if (SUCCEEDED(hr))
{
hr=pBuilder->SetFiltergraph(pGraph);
if(FAILED(hr))
{
return FALSE;
}
}
}
hr= pGraph->QueryInterface(IID_IMediaControl,(LPVOID *) &(pControl));
hr=pGraph->QueryInterface(IID_IVideoWindow, (LPVOID *) &(VideoWindow));
ICreateDevEnum *pSysDevEnum = NULL;
hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
if(FAILED(hr))
{
return FALSE;
}
IEnumMoniker *pEnumCat = NULL;
hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);
if (hr == S_OK)
{
IMoniker *pMoniker = NULL;
ULONG cFetched;
while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
{
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
if (SUCCEEDED(hr))
{
VARIANT varName;
VariantInit(&varName);
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
BSTR name2=varName.bstrVal;
if((wcscmp(name2, "Video Capture AV")==0))
{
hr=pMoniker->BindToObject(0,0,IID_IBaseFilter, (void**)&(VideoSourceFilter));
hr=pGraph->AddFilter(VideoSourceFilter,L"Video Source");
check1=1;
}
if(check1==0)
{
return FALSE;
}
pPropBag->Release();
}
pMoniker->Release();
}
pEnumCat->Release();
}
else
{
return FALSEYou didn't say what kind of error you were getting. Is it possible that on one of your previous runs you aborted the program or took a path that didn't close everything? I had a problem with an OpenCV app I wrote that got very unhappy if I exited without properly releasing everything. COM is funny that way. :suss:
If you don't have the data, you're just another asshole with an opinion.
-
Dear All, I am developing an application to preview the video from a Capture device. I have developed the application and it is working fine, but the problem is that it is playing two times correctly but for the third time i got error while connecting with video renderer. Please help me. Code snippet is given below :
void DialogPlayer::OnBnClickedButton12()
{
bool x= CreateVideoGraph();
}BOOL DialogPlayer::CreateVideoGraph()//Creating the graph for video
{
hr = CoCreateInstance(CLSID_FilterGraph, NULL,CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);
if(FAILED(hr))
{
return FALSE;
}
if (SUCCEEDED(hr))
{
//Create the Capture Graph Builder.
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL,CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2,(void **)&pBuilder);
if(FAILED(hr))
{
return FALSE;
}
if (SUCCEEDED(hr))
{
hr=pBuilder->SetFiltergraph(pGraph);
if(FAILED(hr))
{
return FALSE;
}
}
}
hr= pGraph->QueryInterface(IID_IMediaControl,(LPVOID *) &(pControl));
hr=pGraph->QueryInterface(IID_IVideoWindow, (LPVOID *) &(VideoWindow));
ICreateDevEnum *pSysDevEnum = NULL;
hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
if(FAILED(hr))
{
return FALSE;
}
IEnumMoniker *pEnumCat = NULL;
hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);
if (hr == S_OK)
{
IMoniker *pMoniker = NULL;
ULONG cFetched;
while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
{
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
if (SUCCEEDED(hr))
{
VARIANT varName;
VariantInit(&varName);
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
BSTR name2=varName.bstrVal;
if((wcscmp(name2, "Video Capture AV")==0))
{
hr=pMoniker->BindToObject(0,0,IID_IBaseFilter, (void**)&(VideoSourceFilter));
hr=pGraph->AddFilter(VideoSourceFilter,L"Video Source");
check1=1;
}
if(check1==0)
{
return FALSE;
}
pPropBag->Release();
}
pMoniker->Release();
}
pEnumCat->Release();
}
else
{
return FALSEHi are you releasing the reference count on the
CrossbarFilter
IPin *outPin;these two interfaces when done.
tanvon malik http://tanvon.wordpress.com http://DirectShow.wordpress.com DirectShow in URDU language http://groups.yahoo.com/group/tanvon http://www.codeproject.com/script/articles/list_articles.asp?userid=1638055
-
Hi are you releasing the reference count on the
CrossbarFilter
IPin *outPin;these two interfaces when done.
tanvon malik http://tanvon.wordpress.com http://DirectShow.wordpress.com DirectShow in URDU language http://groups.yahoo.com/group/tanvon http://www.codeproject.com/script/articles/list_articles.asp?userid=1638055
I tried releasing everything and nothing happens. Finally I remove all the filters in the graph using IEnuFilters and this works for me. Thanks for your kindness and reply.