Microsoft DirectX 8.1 (C++)

Controlling a Capture Graph

The filter graph's IMediaControl interface has methods for running, stopping, and pausing the entire graph. However, if the graph has multiple streams, you might want independent control over them. For example, you might want the preview stream to run while the capture stream is stopped. Or, you might want to mute the audio during preview but enable it during file capture.

The ICaptureGraphBuilder2::ControlStream method provides a way to set the start and stop times on individual streams. Call this method before you call IMediaControl::Run. When you call Run, any streams not included in your call to ControlStream start immediately.

The following code example starts the video capture stream at 2 seconds and stops it at 5 seconds:

IMediaControl   *pControl;
REFERENCE_TIME  rtStart = 20000000, 
                rtStop = 50000000;

pBuilder->ControlStream(
        &PIN_CATEGORY_CAPTURE, 
        &MEDIATYPE_Video, 
        pSrc,       // Source filter
        &rtStart,   // Start time
        &rtStop,    // Stop time
        0,          // Start cookie
        0           // Stop cookie
    );
pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
pControl->Run();

The first three parameters specify the stream to control, by pin category, media type, and capture filter. The last two parameters are cookies—arbitrary values defined in your application—which you can use to identify the stop and start events. For more information, see ICaptureGraphBuilder2::ControlStream.

To control several streams at once, omit the media type and source filter. The following example controls all capture streams in the graph:

pBuilder->ControlStream(&PIN_CATEGORY_CAPTURE, NULL, NULL, 
    &rtStart, &rtStop, 0, 0);
pControl->Run();