reftime.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. // default to 0 time
  48. m_time = 0;
  49. };
  50. inline CRefTime(LONG msecs) {
  51. m_time = MILLISECONDS_TO_100NS_UNITS(msecs);
  52. };
  53. inline CRefTime(REFERENCE_TIME rt) {
  54. m_time = rt;
  55. };
  56. inline operator REFERENCE_TIME() const {
  57. return m_time;
  58. };
  59. inline CRefTime& operator=(const CRefTime& rt) {
  60. m_time = rt.m_time;
  61. return *this;
  62. };
  63. inline CRefTime& operator=(const LONGLONG ll) {
  64. m_time = ll;
  65. return *this;
  66. };
  67. inline CRefTime& operator+=(const CRefTime& rt) {
  68. return (*this = *this + rt);
  69. };
  70. inline CRefTime& operator-=(const CRefTime& rt) {
  71. return (*this = *this - rt);
  72. };
  73. inline LONG Millisecs(void) {
  74. return (LONG)(m_time / (UNITS / MILLISECONDS));
  75. };
  76. inline LONGLONG GetUnits(void) {
  77. return m_time;
  78. };
  79. };
  80. const LONGLONG TimeZero = 0;
  81. #endif /* __REFTIME__ */