My Project
reftime.h
1 //------------------------------------------------------------------------------
2 // File: RefTime.h
3 //
4 // Desc: DirectShow base classes - defines CRefTime, a class that manages
5 // reference times.
6 //
7 // Copyright (c) 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 #pragma once
35 
36 #ifndef __REFTIME__
37 #define __REFTIME__
38 
39 
40 const LONGLONG MILLISECONDS = (1000); // 10 ^ 3
41 const LONGLONG NANOSECONDS = (1000000000); // 10 ^ 9
42 const LONGLONG UNITS = (NANOSECONDS / 100); // 10 ^ 7
43 
44 /* Unfortunately an inline function here generates a call to __allmul
45  - even for constants!
46 */
47 #define MILLISECONDS_TO_100NS_UNITS(lMs) \
48  Int32x32To64((lMs), (UNITS / MILLISECONDS))
49 
50 class CRefTime
51 {
52 public:
53 
54  // *MUST* be the only data member so that this class is exactly
55  // equivalent to a REFERENCE_TIME.
56  // Also, must be *no virtual functions*
57 
58  REFERENCE_TIME m_time;
59 
60  inline CRefTime()
61  {
62  // default to 0 time
63  m_time = 0;
64  };
65 
66  inline CRefTime(LONG msecs)
67  {
68  m_time = MILLISECONDS_TO_100NS_UNITS(msecs);
69  };
70 
71  inline CRefTime(REFERENCE_TIME rt)
72  {
73  m_time = rt;
74  };
75 
76  inline operator REFERENCE_TIME() const
77  {
78  return m_time;
79  };
80 
81  inline CRefTime& operator=(const CRefTime& rt)
82  {
83  m_time = rt.m_time;
84  return *this;
85  };
86 
87  inline CRefTime& operator=(const LONGLONG ll)
88  {
89  m_time = ll;
90  return *this;
91  };
92 
93  inline CRefTime& operator+=(const CRefTime& rt)
94  {
95  return (*this = *this + rt);
96  };
97 
98  inline CRefTime& operator-=(const CRefTime& rt)
99  {
100  return (*this = *this - rt);
101  };
102 
103  inline LONG Millisecs(void)
104  {
105  return (LONG)(m_time / (UNITS / MILLISECONDS));
106  };
107 
108  inline LONGLONG GetUnits(void)
109  {
110  return m_time;
111  };
112 };
113 
114 const LONGLONG TimeZero = 0;
115 
116 #endif /* __REFTIME__ */
117 
Definition: reftime.h:50