Previewing a Project
Microsoft DirectShow 9.0 |
Previewing a Project
To preview a project, first call CoCreateInstance to create an instance of the Basic Render Engine. The class identifier is CLSID_RenderEngine. Then call the IRenderEngine::SetTimelineObject method to specify the timeline that you are rendering.
The first time that you preview the timeline, perform the following calls in the order listed:
- Call IRenderEngine::SetRenderRange to specify which portion of the timeline to preview. (Optional)
- Call IRenderEngine::ConnectFrontEnd to build the front end of the graph.
- Call IRenderEngine::RenderOutputPins. This method connects each output pin to a video renderer or audio renderer, completing the graph.
The following code example shows these steps:
IRenderEngine *pRender = NULL; hr = CoCreateInstance(CLSID_RenderEngine, NULL, CLSCTX_INPROC_SERVER, IID_IRenderEngine, (void**)&pRender); hr = pRender->SetTimelineObject(pTL); hr = pRender->ConnectFrontEnd(); hr = pRender->RenderOutputPins();
Now run the filter graph. First, call the IRenderEngine::GetFilterGraph method to retrieve a pointer to the Filter Graph Manager's IGraphBuilder interface. Then query the Filter Graph Manager for the IMediaControl interface and call IMediaControl::Run, as shown in the following code:
IGraphBuilder *pGraph = NULL; IMediaControl *pControl = NULL; hr = pRender->GetFilterGraph(&pGraph); hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); hr = pControl->Run();
Use the Filter Graph Manager's IMediaEventEx interface to wait for the preview to complete. You can also seek the graph using the Filter Graph Manager's IMediaSeeking interface, just as you would with a file playback graph.
To preview the project again, seek the graph back to time zero and call Run again. If you change the contents of the timeline, do the following:
- Call SetRenderRange. (Optional)
- Call ConnectFrontEnd.
- If the ConnectFrontEnd method returns S_WARN_OUTPUTRESET, call RenderOutputPins. (If ConnectFrontEnd returns S_OK, you can skip this step.)
- Seek the graph back to time zero.
- Run the graph.
The following example shows these steps:
hr = pRender->ConnectFrontEnd(); if (hr == S_WARN_OUTPUTRESET) { hr = pRender->RenderOutputPins(); } LONGLONG llStart = 0; hr = pSeek->SetPositions(&llStart, AM_SEEKING_AbsolutePositioning, 0, 0); hr = pControl->Run();
For a complete example that loads and previews a project file, see Loading and Previewing a Project.
See Also