CRefTime class

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

creftime class hierarchy

The CRefTime class is a helper class for managing reference times.

A reference time is a unit of time represented in 100-nanosecond units. This class shares the same data layout as the REFERENCE_TIME data type, but adds some methods and operators that provide comparison, conversion, and arithmetic functions. For more information about reference times, see Time and Clocks in DirectShow.

Public Member Variables Description
m_time Specifies the REFERENCE_TIME value.
Public Methods Description
CRefTime Constructor method.
GetUnits Retrieves the reference time in 100-nanosecond units.
Millisecs Converts the reference time to milliseconds.
Operators Description
operator REFERENCE_TIME() Casts the object to a REFERENCE_TIME data type.
operator= Assigns a new reference time.
operator+= Adds two reference times.
operator = Subtracts one reference time from another.

Remarks

There is a potential pitfall with using this class. If you apply the += operator with a CRefTime object as the left operand and a variable of type LONG as the right operand, the compiler will implicitly coerce the right operand into a CRefTime object. This coercion uses the CRefTime constructor that converts milliseconds into REFERENCE_TIME units; as a result, the right operand is multiplied by 10,000:

CRefTime rt;   // rt.m_time is 0.
LONG val = 20;
rt += val;    // Coerce val to CRefTime, rt.m_time is now 200,000.

However, the same thing does not happen using the + operator:

CRefTime rt;   // rt.m_time is 0.
LONG val = 20;
rt = rt + val; // CRefTime, rt.m_time is 20.

Requirements

Requirement Value
Header
Reftime.h (include Streams.h)
Library
Strmbase.lib (retail builds);
Strmbasd.lib (debug builds)