i
i
i
i
i
i
i
i
404 15. Using Multimedia in VR
ICaptureGraphBuilder2
*
g_pCapture=NULL;// declare global pointer
// this is main function to build/run the capture graph
HRESULT CaptureVideo(){
HRESULT hr;
// this will point to the Video source filter
IBaseFilter
*
pSrcFilter=NULL;
hr = GetInterfaces(); // Get DirectShow interfaces
// Tell the capture graph builter to do its work on the graph.
hr = g_pCapture->SetFiltergraph(g_pGraph);
// Use the system device enumerator and class enumerator to find
// a video capture/preview device, such as a desktop USB video camera.
hr = FindCaptureDevice(&pSrcFilter);// see next listing
// Add Capture filter to our graph.
hr = g_pGraph->AddFilter(pSrcFilter, L"Video Capture");
// Render the preview pin on the video capture filter
// Use this instead of g_pGraph->RenderFile
hr = g_pCapture->RenderStream(&PIN_CATEGORY_PREVIEW,&MEDIATYPE_Video,
pSrcFilter, NULL, NULL);
// Now that the filter has been added to the graph and we have
// rendered its stream, we can release this reference to the filter.
pSrcFilter->Release();
hr = SetupVideoWindow(); // Setup video window
hr = g_pMC->Run(); // Start previewing video data
return S_OK;
}
// very similar to movie player - (Do check for errors in hr!!!
HRESULT GetInterfaces(void){
HRESULT hr;
// Create the filter graph
hr = CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IGraphBuilder, (void
**
) &g_pGraph);
// Create the capture graph builder
hr = CoCreateInstance (CLSID_CaptureGraphBuilder2 , NULL, CLSCTX_INPROC,
IID_ICaptureGraphBuilder2, (void
**
) &g_pCapture);
// Obtain interfaces for media control and Video Window
hr = g_pGraph->QueryInterface(IID_IMediaControl,(LPVOID
*
) &g_pMC);
hr = g_pGraph->QueryInterface(IID_IVideoWindow, (LPVOID
*
) &g_pVW);
hr = g_pGraph->QueryInterface(IID_IMediaEvent, (LPVOID
*
) &g_pME);
// Set the window handle used to process graph events
hr = g_pME->SetNotifyWindow((OAHWND)ghApp, WM_GRAPHNOTIFY, 0);
return hr;
}
Listing 15.7. Build FilterGraph thatpreviews live video from a DV/USB camera. Note
the call to
FindCaptureDevice(), which finds the video source filter. Its code is
given in Listing 15.8.