test2
[test_vsfilter.git] / src / filters / BaseClasses / reftime.h
blob65cfe8585851e4065b680c6874516fb8b7633e4e
1 //------------------------------------------------------------------------------
2 // File: RefTime.h
3 //
4 // Desc: DirectShow base classes - defines CRefTime, a class that manages
5 // reference times.
6 //
7 // Copyright (c) 1992-2002 Microsoft Corporation. All rights reserved.
8 //------------------------------------------------------------------------------
12 // CRefTime
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
26 // REFERENCE_TIME
29 // -----
30 // note that you are safe to cast a CRefTime* to a REFERENCE_TIME*, but
31 // you will need to do so explicitly
32 // -----
35 #ifndef __REFTIME__
36 #define __REFTIME__
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
44 - even for constants!
46 #define MILLISECONDS_TO_100NS_UNITS(lMs) \
47 Int32x32To64((lMs), (UNITS / MILLISECONDS))
49 class CRefTime
51 public:
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;
59 inline CRefTime()
61 // default to 0 time
62 m_time = 0;
65 inline CRefTime(LONG msecs)
67 m_time = MILLISECONDS_TO_100NS_UNITS(msecs);
70 inline CRefTime(REFERENCE_TIME rt)
72 m_time = rt;
75 inline operator REFERENCE_TIME() const
77 return m_time;
80 inline CRefTime& operator=(const CRefTime& rt)
82 m_time = rt.m_time;
83 return *this;
86 inline CRefTime& operator=(const LONGLONG ll)
88 m_time = ll;
89 return *this;
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)
109 return m_time;
113 const LONGLONG TimeZero = 0;
115 #endif /* __REFTIME__ */