reftime.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. // CRefTime
  11. //
  12. // Manage reference times.
  13. // Shares same data layout as REFERENCE_TIME, but adds some (nonvirtual)
  14. // functions providing simple comparison, conversion and arithmetic.
  15. //
  16. // A reference time (at the moment) is a unit of seconds represented in
  17. // 100ns units as is used in the Win32 FILETIME structure. BUT the time
  18. // a REFERENCE_TIME represents is NOT the time elapsed since 1/1/1601 it
  19. // will either be stream time or reference time depending upon context
  20. //
  21. // This class provides simple arithmetic operations on reference times
  22. //
  23. // keep non-virtual otherwise the data layout will not be the same as
  24. // REFERENCE_TIME
  25. // -----
  26. // note that you are safe to cast a CRefTime* to a REFERENCE_TIME*, but
  27. // you will need to do so explicitly
  28. // -----
  29. #ifndef __REFTIME__
  30. #define __REFTIME__
  31. const LONGLONG MILLISECONDS = (1000); // 10 ^ 3
  32. const LONGLONG NANOSECONDS = (1000000000); // 10 ^ 9
  33. const LONGLONG UNITS = (NANOSECONDS / 100); // 10 ^ 7
  34. /* Unfortunately an inline function here generates a call to __allmul
  35. - even for constants!
  36. */
  37. #define MILLISECONDS_TO_100NS_UNITS(lMs) \
  38. Int32x32To64((lMs), (UNITS / MILLISECONDS))
  39. class CRefTime
  40. {
  41. public:
  42. // *MUST* be the only data member so that this class is exactly
  43. // equivalent to a REFERENCE_TIME.
  44. // Also, must be *no virtual functions*
  45. REFERENCE_TIME m_time;
  46. inline CRefTime()
  47. {
  48. // default to 0 time
  49. m_time = 0;
  50. };
  51. inline CRefTime(LONG msecs)
  52. {
  53. m_time = MILLISECONDS_TO_100NS_UNITS(msecs);
  54. };
  55. inline CRefTime(REFERENCE_TIME rt)
  56. {
  57. m_time = rt;
  58. };
  59. inline operator REFERENCE_TIME() const
  60. {
  61. return m_time;
  62. };
  63. inline CRefTime& operator=(const CRefTime& rt)
  64. {
  65. m_time = rt.m_time;
  66. return *this;
  67. };
  68. inline CRefTime& operator=(const LONGLONG ll)
  69. {
  70. m_time = ll;
  71. return *this;
  72. };
  73. inline CRefTime& operator+=(const CRefTime& rt)
  74. {
  75. return (*this = *this + rt);
  76. };
  77. inline CRefTime& operator-=(const CRefTime& rt)
  78. {
  79. return (*this = *this - rt);
  80. };
  81. inline LONG Millisecs(void)
  82. {
  83. return (LONG)(m_time / (UNITS / MILLISECONDS));
  84. };
  85. inline LONGLONG GetUnits(void)
  86. {
  87. return m_time;
  88. };
  89. };
  90. const LONGLONG TimeZero = 0;
  91. #endif /* __REFTIME__ */