Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
3.9 KiB

  1. //**************************************************************************
  2. //
  3. // Title : ctime.cpp
  4. //
  5. // Date : 1998.01.27 1st making
  6. //
  7. // Author : Toshiba [PCS](PSY) Hideki Yagi
  8. //
  9. // Copyright 1997 Toshiba Corporation. All Rights Reserved.
  10. //
  11. // -------------------------------------------------------------------------
  12. //
  13. // Change log :
  14. //
  15. // Date Revision Description
  16. // ------------ ---------- -----------------------------------------------
  17. // 1998.01.27 000.0000 1st making.
  18. //
  19. //**************************************************************************
  20. #include "includes.h"
  21. #include "ctime.h"
  22. //--- 98.06.01 S.Watanabe
  23. #ifdef DBG
  24. char * DebugLLConvtoStr( ULONGLONG val, int base );
  25. #endif
  26. CTickTime::CTickTime( void )
  27. {
  28. m_SamplingTime = m_StreamTime = 0;
  29. m_TimeState = StopState;
  30. m_Rate = 10000;
  31. }
  32. CTickTime::~CTickTime( void )
  33. {
  34. m_SamplingTime = m_StreamTime = 0;
  35. m_TimeState = StopState;
  36. m_Rate = 10000;
  37. }
  38. BOOL CTickTime::Stop( void )
  39. {
  40. DBG_PRINTF(("CTickTime:: Stop !!!! rate = %d\r\n",m_Rate ));
  41. m_SamplingTime = 0;
  42. m_StreamTime = 0;
  43. m_TimeState = StopState;
  44. return TRUE;
  45. };
  46. BOOL CTickTime::Pause( void )
  47. {
  48. DBG_PRINTF(("CTickTime:: Pause !!!! rate = %d\r\n",m_Rate ));
  49. switch( m_TimeState )
  50. {
  51. case StopState:
  52. break;
  53. case PauseState:
  54. break;
  55. case RunState:
  56. CalcDiffTime();
  57. break;
  58. };
  59. m_TimeState = PauseState;
  60. return TRUE;
  61. };
  62. BOOL CTickTime::Run( void )
  63. {
  64. DBG_PRINTF(("CTickTime:: Run !!!! rate = %d\r\n",m_Rate ));
  65. switch( m_TimeState )
  66. {
  67. case StopState:
  68. m_SamplingTime = GetSystemTime();
  69. break;
  70. case PauseState:
  71. m_SamplingTime = GetSystemTime();
  72. break;
  73. case RunState:
  74. break;
  75. };
  76. m_TimeState = RunState;
  77. return TRUE;
  78. };
  79. BOOL CTickTime::GetStreamTime( ULONGLONG *time )
  80. {
  81. switch( m_TimeState )
  82. {
  83. case StopState:
  84. *time = 0;
  85. break;
  86. case PauseState:
  87. *time = m_StreamTime;
  88. break;
  89. case RunState:
  90. CalcDiffTime();
  91. *time = m_StreamTime;
  92. break;
  93. };
  94. // DBG_PRINTF(("CTickTime:: GetSteamTime Rate = %d Time = 0x%s STC=0x%x\r\n", m_Rate, DebugLLConvtoStr( *time, 16 ),(DWORD)(*time * 9 / 1000) ));
  95. return TRUE;
  96. };
  97. ULONGLONG CTickTime::GetStreamTime( void )
  98. {
  99. ULONGLONG TmpTime;
  100. GetStreamTime( &TmpTime );
  101. return TmpTime;
  102. };
  103. BOOL CTickTime::GetStreamSTC( DWORD *time )
  104. {
  105. *time = (DWORD)(GetStreamTime() * 9 / 1000);
  106. return TRUE;
  107. };
  108. DWORD CTickTime::GetStreamSTC( void )
  109. {
  110. return (DWORD)(GetStreamTime() * 9 / 1000);
  111. };
  112. ULONGLONG CTickTime::GetSystemTime( void )
  113. {
  114. ULONGLONG ticks;
  115. ULONGLONG rate;
  116. ticks = (ULONGLONG)KeQueryPerformanceCounter((PLARGE_INTEGER)&rate).QuadPart;
  117. //
  118. // convert from ticks to 100ns clock
  119. //
  120. ticks = (ticks & 0xFFFFFFFF00000000) / rate * 10000000 +
  121. (ticks & 0xFFFFFFFF) * 10000000 /rate;
  122. // DBG_PRINTF( ("DVDWDM:System time = %x\n\r", ticks ) );
  123. return( ticks );
  124. }
  125. BOOL CTickTime::SetRate( DWORD Rate )
  126. {
  127. if( m_TimeState == RunState )
  128. {
  129. CalcDiffTime();
  130. };
  131. m_Rate = Rate;
  132. DBG_PRINTF(("CTickTime:: New Rate !!!!! %d \r\n", Rate ));
  133. return TRUE;
  134. };
  135. BOOL CTickTime::SetStreamTime( ULONGLONG time )
  136. {
  137. if( m_TimeState == StopState )
  138. return FALSE;
  139. //--- 98.09.17 S.Watanabe
  140. // DBG_PRINTF(("CTickTime:: Set Stream Time 0x%s \r\n", DebugLLConvtoStr( time, 16 ) ));
  141. DBG_PRINTF(("CTickTime:: Set Stream Time 0x%x( 0x%s(100ns) )\r\n", (DWORD)(time*9/1000), DebugLLConvtoStr( time, 16 ) ));
  142. //--- End.
  143. m_StreamTime = time;
  144. m_SamplingTime = GetSystemTime();
  145. return TRUE;
  146. };
  147. void CTickTime::CalcDiffTime( void )
  148. {
  149. ULONGLONG SysTime = GetSystemTime();
  150. if( m_Rate > 10000 )
  151. {
  152. m_StreamTime += (SysTime - m_SamplingTime ) / ( m_Rate / 10000 );
  153. };
  154. if( m_Rate < 10000 )
  155. {
  156. m_StreamTime += (SysTime - m_SamplingTime ) * ( 10000 / m_Rate );
  157. }
  158. if( m_Rate == 10000 )
  159. {
  160. m_StreamTime += ( SysTime - m_SamplingTime );
  161. };
  162. m_SamplingTime = SysTime;
  163. };