Using Directshow causes the application to crash
Aaron
45
Reputation points
Hi,
When I debugged with graphedit, I was able to preview the camera as normal.The graphedit configuration is as follows.
But when I used the code to configure the camera preview, my application crashed. My code configuration is as follows.
hr = CoCreateInstance(CLSID_FilterGraph, nullptr, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **) &pGraphBuilder);
if (FAILED(hr)) { qDebug() << "create FilterGraph failed"; return false; }
hr = CoCreateInstance(CLSID_H264DS, nullptr, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **) &m_pH264Filter);
if (FAILED(hr)) { qDebug() << "create H264 Filter failed: " << hr; return false; }
hr = CoCreateInstance(CLSID_EnhancedVideoRenderer, nullptr, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **) &m_pEvrFilter);
if (FAILED(hr)) { qDebug() << "create EVR Filter failed: " << hr; return false; }
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, nullptr, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void **) &pCaptureGraphBuilder2);
if (FAILED(hr)) { qDebug() << "create CaptureGraphBuilder2 failed"; return false; }
hr = pCaptureGraphBuilder2->SetFiltergraph(pGraphBuilder);
if (FAILED(hr)) { qDebug() << "SetFilterGraph failed: " << hr; return false; }
hr = pGraphBuilder->AddFilter(pVideoCaptureFilter, L"Video Capture");
if (FAILED(hr)) { qDebug() << "couldn't add video capture filter to graph hr = " << hr; return false; }
hr = pGraphBuilder->AddFilter(m_pH264Filter, L"H264 DS Filter"); if (FAILED(hr)) { qDebug() << "couldn't add H264 filter to graph hr = " << hr; return false; }
hr = pGraphBuilder->AddFilter(m_pEvrFilter, L"EVR Filter"); if (FAILED(hr)) { qDebug() << "couldn't add EVR filter to graph hr = " << hr; return false; }
hr = pCaptureGraphBuilder2->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, pVideoCaptureFilter, nullptr, nullptr);
if (FAILED(hr)) { qDebug() << "couldn't render stream hr = " << hr; return false; }
Windows development Windows API - Win32
2,782 questions
Windows for business Windows Client for IT Pros User experience Other
Developer technologies C++
3,972 questions
Sign in to answer