1
0

VideoClock.h 861 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include <windows.h>
  3. namespace nu
  4. {
  5. class VideoClock
  6. {
  7. public:
  8. VideoClock()
  9. {
  10. video_sync_start_time=0;
  11. pause_start_time=0;
  12. length_paused=0;
  13. paused=0;
  14. }
  15. void Reset()
  16. {
  17. length_paused = 0;
  18. paused=0;
  19. }
  20. void Pause()
  21. {
  22. paused=1;
  23. pause_start_time = GetTickCount();
  24. }
  25. void Unpause()
  26. {
  27. paused=0;
  28. length_paused += (GetTickCount() - pause_start_time);
  29. }
  30. int GetOutputTime()
  31. {
  32. if (paused)
  33. {
  34. return pause_start_time - video_sync_start_time - length_paused;
  35. }
  36. else
  37. {
  38. return GetTickCount() - video_sync_start_time - length_paused;
  39. }
  40. }
  41. void Seek(int time_ms)
  42. {
  43. video_sync_start_time = GetTickCount() - time_ms;
  44. length_paused = 0;
  45. }
  46. void Start()
  47. {
  48. video_sync_start_time = GetTickCount();
  49. }
  50. private:
  51. DWORD video_sync_start_time;
  52. DWORD pause_start_time;
  53. DWORD length_paused;
  54. int paused;
  55. };
  56. }