Compartir a través de


Handling Repaint Events in Video Capture

 
Microsoft DirectShow 9.0

Handling Repaint Events in Video Capture

If you build a video capture graph without using the ICaptureGraphBuilder2 interface, and you preview the video using the old Video Renderer filter, then you should override the default handling for EC_REPAINT events. Query the Filter Graph Manager for the IMediaEvent interface and call the IMediaEvent::CancelDefaultHandling method with the value EC_REPAINT:

IMediaEvent *pEvent = 0;
hr = pGraph->QueryInterface(IID_IMediaEvent, (void**)&pEvent);
if (SUCCEEDED(hr))
{
    pEvent->CancelDefaultHandling (EC_REPAINT);
    pEvent->Release();
}

This prevents a possible error that can corrupt your capture file. If the user covers and uncovers the preview window, the Video Renderer filter receives a WM_PAINT message. By default, the Video Renderer requests a new frame, and the Filter Graph Manager pauses the graph in order to cue another video frame. If that happens while the graph is writing a file, it will corrupt the file. Overriding the default EC_REPAINT behavior prevents the renderer from requesting a new frame.

You do not have to perform this step if you are using the ICaptureGraphBuilder2 interface, because the Capture Graph Builder does it for you automatically. Also, it is not required if you are using the Video Mixing Renderer (VMR) for preview. The VMR always has the most recent frame available, so it does not send EC_REPAINT events.

See Also