Producing Data in a Capture Filter

 
Microsoft DirectShow 9.0

Producing Data in a Capture Filter

State Changes

A capture filter should produce data only when the filter is running. Do not send data from your pins when the filter is paused. Also, return VFW_S_CANT_CUE from the CBaseFilter::GetState method when the filter is paused. This return code informs the Filter Graph Manager that it should not wait for any data from your filter while the filter is paused. For more information, see Filter States.

The following code shows how to implement the GetState method:

CMyVidcapFilter::GetState(DWORD dw, FILTER_STATE *pState)
{
    CheckPointer(pState, E_POINTER);
    *pState = m_State;
    if (m_State == State_Paused)
        return VFW_S_CANT_CUE;
    else
        return S_OK;
}

Controlling Individual Streams

A capture filter's output pins should support the IAMStreamControl interface, so that an application can turn each pin on or off individually. For example, an application can preview without capturing, and then switch to capture mode without rebuilding the filter graph. You can use the CBaseStreamControl class to implement this interface.

Time Stamps

When the filter captures a sample, time stamp the sample with the current stream time . The end time is the start time plus the duration. For example, if the filter is capturing at ten samples per second, and the stream time is 200,000,000 units when the filter captures the sample, the time stamps should be 200000000 and 201000000. (There are 10,000,000 units per second.) Use the IReferenceClock::GetTime method to get the current reference time, and the IMediaSample::SetTime method to set the time stamps.

Time stamps must always increase from one sample to the next. This is true even when the filter pauses. If the filter runs, pauses, and then runs again, the first sample after the pause must have a larger time stamp than the last sample before the pause.

Samples from the preview pin should not have time stamps, however. Preview samples always reach the renderer slightly after the time of capture, so the renderer will treat them as late samples. This might cause the renderer to drop samples, in a futile attempt to catch up. Note that the IAMStreamControl interface requires the pin to keep track of sample times. For a preview pin, you might need to modify the implementation so that it does not rely on time stamps.

Depending on the data you are capturing, it might be appropriate to set the media time on the samples.

For more information, see Time and Clocks in DirectShow.