Microsoft DirectX 8.1 (C++) |
The Sample Grabber functions in one of two modes:
This article describes only buffering mode. Before using callback mode, be aware that the callback function must be quite limited. Otherwise, it can drastically reduce performance or even cause deadlocks. For more information, see ISampleGrabber::SetCallback.
To activate buffering mode, call the ISampleGrabber::SetBufferSamples method with the value TRUE. You can also use the ISampleGrabber::SetOneShot method, which causes the Sample Grabber to stop the graph after it receives one sample. This is useful if you want to grab a single frame from the stream. To do so, seek the graph to the desired time, run the graph, and wait for the EC_COMPLETE event. Note that the level of frame accuracy depends on the source. For example, seeking an MPEG file is often not frame accurate.
// Set one-shot mode and buffering.
hr = pGrabber->SetOneShot(TRUE);
hr = pGrabber->SetBufferSamples(TRUE);
IMediaFilter *pMediaFilter = NULL;
IMediaControl *pControl = NULL;
IMediaEventEx *pEvent = NULL;
/* Query the Filter Graph Manager for these interfaces. (Not shown.) */
pMediaFilter->SetSyncSource(NULL); // Turn off the reference clock.
pControl->Run(); // Run the graph.
pEvent->WaitForCompletion(INFINITE, &evCode); // Wait till it's done.