Alexandre Lision | 8af73cb | 2013-12-10 14:11:20 -0500 | [diff] [blame] | 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-2001 Microsoft Corporation. All rights reserved.
|
| 8 | //------------------------------------------------------------------------------
|
| 9 |
|
| 10 |
|
| 11 | //
|
| 12 | // CRefTime
|
| 13 | //
|
| 14 | // Manage reference times.
|
| 15 | // Shares same data layout as REFERENCE_TIME, but adds some (nonvirtual)
|
| 16 | // functions providing simple comparison, conversion and arithmetic.
|
| 17 | //
|
| 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
|
| 22 | //
|
| 23 | // This class provides simple arithmetic operations on reference times
|
| 24 | //
|
| 25 | // keep non-virtual otherwise the data layout will not be the same as
|
| 26 | // REFERENCE_TIME
|
| 27 |
|
| 28 |
|
| 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 | // -----
|
| 33 |
|
| 34 |
|
| 35 | #ifndef __REFTIME__
|
| 36 | #define __REFTIME__
|
| 37 |
|
| 38 |
|
| 39 | const LONGLONG MILLISECONDS = (1000); // 10 ^ 3
|
| 40 | const LONGLONG NANOSECONDS = (1000000000); // 10 ^ 9
|
| 41 | const LONGLONG UNITS = (NANOSECONDS / 100); // 10 ^ 7
|
| 42 |
|
| 43 | /* Unfortunately an inline function here generates a call to __allmul
|
| 44 | - even for constants!
|
| 45 | */
|
| 46 | #define MILLISECONDS_TO_100NS_UNITS(lMs) \
|
| 47 | Int32x32To64((lMs), (UNITS / MILLISECONDS))
|
| 48 |
|
| 49 | class CRefTime
|
| 50 | {
|
| 51 | public:
|
| 52 |
|
| 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*
|
| 56 |
|
| 57 | REFERENCE_TIME m_time;
|
| 58 |
|
| 59 | inline CRefTime()
|
| 60 | {
|
| 61 | // default to 0 time
|
| 62 | m_time = 0;
|
| 63 | };
|
| 64 |
|
| 65 | inline CRefTime(LONG msecs)
|
| 66 | {
|
| 67 | m_time = MILLISECONDS_TO_100NS_UNITS(msecs);
|
| 68 | };
|
| 69 |
|
| 70 | inline CRefTime(REFERENCE_TIME rt)
|
| 71 | {
|
| 72 | m_time = rt;
|
| 73 | };
|
| 74 |
|
| 75 | inline operator REFERENCE_TIME() const
|
| 76 | {
|
| 77 | return m_time;
|
| 78 | };
|
| 79 |
|
| 80 | inline CRefTime& operator=(const CRefTime& rt)
|
| 81 | {
|
| 82 | m_time = rt.m_time;
|
| 83 | return *this;
|
| 84 | };
|
| 85 |
|
| 86 | inline CRefTime& operator=(const LONGLONG ll)
|
| 87 | {
|
| 88 | m_time = ll;
|
| 89 | return *this;
|
| 90 | };
|
| 91 |
|
| 92 | inline CRefTime& operator+=(const CRefTime& rt)
|
| 93 | {
|
| 94 | return (*this = *this + rt);
|
| 95 | };
|
| 96 |
|
| 97 | inline CRefTime& operator-=(const CRefTime& rt)
|
| 98 | {
|
| 99 | return (*this = *this - rt);
|
| 100 | };
|
| 101 |
|
| 102 | inline LONG Millisecs(void)
|
| 103 | {
|
| 104 | return (LONG)(m_time / (UNITS / MILLISECONDS));
|
| 105 | };
|
| 106 |
|
| 107 | inline LONGLONG GetUnits(void)
|
| 108 | {
|
| 109 | return m_time;
|
| 110 | };
|
| 111 | };
|
| 112 |
|
| 113 | const LONGLONG TimeZero = 0;
|
| 114 |
|
| 115 | #endif /* __REFTIME__ */
|
| 116 |
|