共用方式為


Reference Clocks

 
Microsoft DirectShow 9.0

Reference Clocks

One function of the Filter Graph Manager is to synchronize all of the filters in the graph to the same clock, called the reference clock.

Any object that exposes the IReferenceClock interface can act as the reference clock. The reference clock might be provided by a DirectShow filter — typically the audio renderer, which has access to a hardware timer. As a fallback, the Filter Graph Manager can use the system time.

Nominally, a reference clock measures time in 100-nanosecond intervals, although the actual accuracy of the clock might be less. To retrieve the clock's current time, call the IReferenceClock::GetTime method. The clock's baseline—the time from which it starts counting—depends on the implementation, so the value returned by GetTime is not inherently meaningful. What matters is the delta from when the graph started running. 

Although the accuracy of a reference clock can vary, the times returned by the GetTime method are guaranteed to increase monotonically. In other words, clock times will never go backward. If a reference clock is generating clock times from a hardware source and the hardware clock jumps backward (for example, if there is an adjustment to the clock), the GetTime method should continue to return the last reported time until the hardware clock catches up. For more information, see CBaseReferenceClock Class.

Default Reference Clock

The Filter Graph Manager automatically selects a reference clock when the graph runs. It uses the following algorithm to select the clock:

  • If the application has selected a clock (see below), use that clock.
  • If the graph contains a live source filter that supports IReferenceClock, use that filter. For the definition of a live source, see Live Sources.
  • If the graph does not contain any live source filters, use any filter in the graph that supports IReferenceClock, starting from the renderers and working upstream.  Prefer connected filters over unconnected filters. (If the graph is rendering an audio stream, this step in the algorithm will normally select the audio renderer filter.)
  • If no filter provides a suitable clock, use the System Reference Clock, which is based on the system time.

Setting the Reference Clock

An application can select a clock by calling the IMediaFilter::SetSyncSource method on the Filter Graph Manager. You should do this only if you have a particular reason to prefer another clock.

You can instruct the Filter Graph Manager not to use a reference clock by calling SetSyncSource with the value NULL. For example, you might do this to process samples as quickly as possible. To restore the default reference clock, call the IFilterGraph::SetDefaultSyncSource method on the Filter Graph Manager.

Whenever the reference clock changes, the Filter Graph Manager notifies each filter by calling its IMediaFilter::SetSyncSource method. Applications should never call this method on filters.

See Also