Microsoft DirectX 9.0

Creating Stream Buffer Graphs

This topic applies to Windows XP Service Pack 1 only.

The Stream Buffer Engine uses multiple filter graphs:

Stream Buffer Engine filter graphs

The sink graph can also create permanent recordings, which can be viewed later using the Stream Buffer Source filter. Currently, the Stream Buffer Engine supports MPEG-2 video and digital video (DV) sources.

To build the sink graph:

  1. Create an instance of the Filter Graph Manager.
  2. Create the Stream Buffer Sink filter and add it to the filter graph.
  3. Build a regular DirectShow capture graph or television graph, but route all of the streams to the Stream Buffer Sink filter, instead of sending them to the usual renderer filters.
  4. Query the Stream Buffer Sink filter for the IStreamBufferSink interface.
  5. Call the IStreamBufferSink::LockProfile method. This method does several things:

    The profile is automatically unlocked when the graph stops.

For MPEG-2 content, insert the MPEG-2 Video Analyzer filter directly between the MPEG-2 Demultiplexer filter and the Stream Buffer Sink filter. The Video Analyzer filter enables the source graph to use playback rates faster than 4x or less than 0 (reverse playback).

MPEG-2 sink graph

For more information about building the capture portion of the sink graph, see the following topics:

To build the source graph:

  1. Create a new instance of the Filter Graph Manager.
  2. Create the Stream Buffer Source filter and add it to the filter graph.
  3. Establish a source for the Stream Buffer Source filter, by doing one of the following:
  4. Enumerate the output pins on the Stream Buffer Source filter.
  5. Call IGraphBuilder::Render on each pin to render the stream.

The following code shows how to create the source graph. Error checking is omitted for brevity.

// Create the filter graph.
CComPtr<IGraphBuilder> pSourceGraph;
hr = pSourceGraph.CoCreateInstance(CLSID_FilterGraph);

// Add the Stream Buffer Source filter to the graph.
CComPtr<IStreamBufferSource> pSource;
hr = pSource.CoCreateInstance(CLSID_StreamBufferSource);
CComQIPtr<IBaseFilter> pSourceF(pSource);
hr = pSourceGraph->AddFilter(pSourceF, L"SBESource");

// Set the stream sink.
hr = pSource->SetStreamSink(pSink);
// Or, pass in the file name, as follows:
// CComQIPtr<IFileSourceFilter> pFileSource(pSource);
// pFileSource->Load(L"StubFileNameHere", 0);

// Render each output pin.
CComPtr<IPin> pSourcePinOut;
CComPtr<IEnumPins> pPinEnum;
hr = pSourceF->EnumPins(&pPinEnum);
while (hr = pPinEnum->Next(1, &pSourcePinOut, 0), hr == S_OK)
{
    hr = pSourceGraph->Render(pSourcePinOut);
    pSourcePinOut.Release();
}

To start capturing, run the sink graph. To start playback, run the source graph. The source graph can be run, paused, or stopped independently of the sink graph.

There is normally no reason to stop the source graph until the viewing or recording session is over. The sink graph uses a ring buffer, so the total size of the temporary backing files will not exceed a preset maximum. Stopping the source graph will create holes in the recorded content. For television sources, it is possible to change channels while the source graph is running.

To seek the source graph, use the IStreamBufferMediaSeeking interface directly on the Stream Buffer Source filter. For finished recordings, you can also use the IMediaSeeking or IMediaPosition interfaces on the Filter Graph Manager. Do not use these interfaces for live content, however. For more information, see Stream Buffer Source Filter.