Microsoft DirectX 8.1 (C++)

CSourceSeeking Class

CSourceSeeking Class Hierarchy

The CSourceSeeking class is an abstract class for implementing seeking in source filters with one output pin.

This class supports the IMediaSeeking interface. It provides default implementations for all of the IMediaSeeking methods. Protected member variables store the start time, stop time, and current rate. By default, the only time format supported by the class is TIME_FORMAT_MEDIA_TIME (100-nanosecond units).

Whenever the start position, stop position, or playback rate changes, the CSourceSeeking object calls a corresponding pure virtual method:

The derived class must implement these methods. After any seek operation, a filter must do the following:

  1. Call the IPin::BeginFlush method on the downstream input pin.
  2. Halt the worker thread that is delivering data.
  3. Call the IPin::EndFlush method on the input pin.
  4. Restart the worker thread.
  5. Call the IPin::NewSegment method on the input pin.
  6. Set the discontinuity property on the first sample. Call the IMediaSample::SetDiscontinuity method.

The call to BeginFlush frees the worker thread, if the thread is blocked waiting to deliver a sample.

In step 2, make sure that the thread has stopped sending data. Depending on the implementation, you might need to wait for the thread to exit, or for the thread to signal a response of some kind. If your filter uses the CSourceStream class, the CSourceStream::Stop method blocks until the worker thread replies.

Ideally, the new segment (step 5) should be delivered from the worker thread. It can also be done by the CSourceSeeking object, as long as the filter serializes it with the samples.

The following example shows a possible implementation. It assumes that the source filter's output pin is derived from CSourceSeeking and CSourceStream. This example defines a helper method, UpdateFromSeek, that performs steps 1–4. The CSourceStream::OnThreadStartPlay method is overridden to send the new segment, and to set a flag indicating the discontinuity. The worker thread picks up this flag and calls the IMediaSample::SetDiscontinuity method:

void CMyStream::UpdateFromSeek()
{
    if (ThreadExists()) 
    {
        DeliverBeginFlush();
        Stop();
        DeliverEndFlush();
        Run();
    }
}

HRESULT CMyStream::OnThreadStartPlay()
{
    m_bDiscontinuity = TRUE;
    return DeliverNewSegment(m_rtStart, m_rtStop, m_dRateSeeking);
}

Requirements

Header: Declared in Ctlutil.h; include Streams.h.

Library: Use Strmbase.lib (retail builds) or Strmbasd.lib (debug builds).

Protected Member Variables  
m_rtDuration Duration of the stream.
m_rtStart Start time.
m_rtStop Stop time.
m_dRateSeeking Playback rate.
m_dwSeekingCaps Seeking capabilities.
m_pLock Pointer to a critical section object for locking.
Protected Methods  
CSourceSeeking Constructor method.
Pure Virtual Methods  
ChangeRate Called when the playback rate changes.
ChangeStart Called when the start position changes.
ChangeStop Called when the stop position changes.
IMediaSeeking Methods  
IsFormatSupported Determines whether a specified time format is supported.
QueryPreferredFormat Retrieves the object's preferred time format.
SetTimeFormat Sets the time format.
IsUsingTimeFormat Determines whether a specified time format is the format currently in use.
GetTimeFormat Retrieves the current time format.
GetDuration Retrieves the duration of the stream.
GetStopPosition Retrieves the time at which the playback will stop, relative to the duration of the stream.
GetCurrentPosition Retrieves the current position, relative to the total duration of the stream.
GetCapabilities Retrieves all the seeking capabilities of the stream.
CheckCapabilities Queries whether the stream has specified seeking capabilities.
ConvertTimeFormat Converts from one time format to another.
SetPositions Sets the current position and the stop position.
GetPositions Retrieves the current position and the stop position.
GetAvailable Retrieves the range of times in which seeking is efficient.
SetRate Sets the playback rate.
GetRate Retrieves the playback rate.
GetPreroll Retrieves the preroll time.