1
0

ClockLayer.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "Main.h"
  2. #include "ClockLayer.h"
  3. #include "config.h"
  4. ClockLayer::ClockLayer(IWMReader *reader)
  5. : clock(0), startTime(0),
  6. clockTick(2500000), curTime(0),
  7. startTimeMilliseconds(0),
  8. realTime(false),
  9. lastOutputTime(0)
  10. {
  11. if (FAILED(reader->QueryInterface(&clock)))
  12. clock=0;
  13. }
  14. void ClockLayer::Opened()
  15. {
  16. realTime=!config_clock;
  17. WMHandler::Opened();
  18. if (!realTime)
  19. {
  20. HRESULT hr = clock->SetUserProvidedClock(TRUE);
  21. if (FAILED(hr))
  22. {
  23. realTime=false;
  24. }
  25. }
  26. else
  27. clock->SetUserProvidedClock(FALSE);
  28. curTime = startTime;
  29. }
  30. void ClockLayer::Started()
  31. {
  32. if (!realTime && config_clock)
  33. clock->DeliverTime((QWORD) - 1);
  34. if (startTimeMilliseconds != 0)
  35. out->Flush(startTimeMilliseconds);
  36. SetLastOutputTime(startTimeMilliseconds);
  37. WMHandler::Started();
  38. }
  39. void ClockLayer::Clock()
  40. {
  41. if (!realTime && config_clock)
  42. clock->DeliverTime((QWORD) - 1);
  43. }
  44. void ClockLayer::SetStartTimeMilliseconds(long time)
  45. {
  46. startTimeMilliseconds=time;
  47. startTime = time;
  48. startTime *= 10000;
  49. }
  50. void ClockLayer::TimeReached(QWORD &timeReached)
  51. {
  52. curTime = timeReached;
  53. }
  54. QWORD ClockLayer::GetStartTime()
  55. {
  56. return startTime;
  57. }
  58. void ClockLayer::GoRealTime()
  59. {
  60. realTime = true;
  61. }
  62. int ClockLayer::GetOutputTime()
  63. {
  64. if (realTime)
  65. return (int) (curTime / 10000LL);
  66. else
  67. return lastOutputTime + (out->GetOutputTime() - out->GetWrittenTime());
  68. }
  69. void ClockLayer::TimeToSync(QWORD timeStamp, __int64 &diff)
  70. {
  71. if (realTime)
  72. diff = 0;
  73. else
  74. {
  75. QWORD outputTime = this->GetOutputTime();
  76. outputTime *= 10000LL;
  77. diff = timeStamp - outputTime;
  78. }
  79. }
  80. void ClockLayer::SampleReceived(QWORD &timeStamp, QWORD &duration, unsigned long &outputNum, unsigned long &flags, INSSBuffer *&sample)
  81. {
  82. if (realTime)
  83. curTime = timeStamp;
  84. WMHandler::SampleReceived(timeStamp, duration, outputNum, flags, sample);
  85. }