1 //------------------------------------------------------------------------------
4 // Desc: DirectShow base classes - defines CRefTime, a class that manages
7 // Copyright (c) 1992-2002 Microsoft Corporation. All rights reserved.
8 //------------------------------------------------------------------------------
14 // Manage reference times.
15 // Shares same data layout as REFERENCE_TIME, but adds some (nonvirtual)
16 // functions providing simple comparison, conversion and arithmetic.
18 // A reference time (at the moment) is a unit of seconds represented in
19 // 100ns units as is used in the Win32 FILETIME structure. BUT the time
20 // a REFERENCE_TIME represents is NOT the time elapsed since 1/1/1601 it
21 // will either be stream time or reference time depending upon context
23 // This class provides simple arithmetic operations on reference times
25 // keep non-virtual otherwise the data layout will not be the same as
30 // note that you are safe to cast a CRefTime* to a REFERENCE_TIME*, but
31 // you will need to do so explicitly
39 const LONGLONG MILLISECONDS
= (1000); // 10 ^ 3
40 const LONGLONG NANOSECONDS
= (1000000000); // 10 ^ 9
41 const LONGLONG UNITS
= (NANOSECONDS
/ 100); // 10 ^ 7
43 /* Unfortunately an inline function here generates a call to __allmul
46 #define MILLISECONDS_TO_100NS_UNITS(lMs) \
47 Int32x32To64((lMs), (UNITS / MILLISECONDS))
53 // *MUST* be the only data member so that this class is exactly
54 // equivalent to a REFERENCE_TIME.
55 // Also, must be *no virtual functions*
57 REFERENCE_TIME m_time
;
65 inline CRefTime(LONG msecs
)
67 m_time
= MILLISECONDS_TO_100NS_UNITS(msecs
);
70 inline CRefTime(REFERENCE_TIME rt
)
75 inline operator REFERENCE_TIME() const
80 inline CRefTime
& operator=(const CRefTime
& rt
)
86 inline CRefTime
& operator=(const LONGLONG ll
)
92 inline CRefTime
& operator+=(const CRefTime
& rt
)
94 return (*this = *this + rt
);
97 inline CRefTime
& operator-=(const CRefTime
& rt
)
99 return (*this = *this - rt
);
102 inline LONG
Millisecs(void)
104 return (LONG
)(m_time
/ (UNITS
/ MILLISECONDS
));
107 inline LONGLONG
GetUnits(void)
113 const LONGLONG TimeZero
= 0;
115 #endif /* __REFTIME__ */