av_clock.h 584 B

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef AVCLOCK_H
  2. #define AVCLOCK_H
  3. #include "ffmpeg_compat.h"
  4. class AVClock
  5. {
  6. public:
  7. AVClock()
  8. : m_pts(0.0)
  9. , m_drift(0.0)
  10. {}
  11. inline void reset()
  12. {
  13. m_pts = 0.0;
  14. m_drift = 0.0;
  15. }
  16. inline void setClock(double pts) { setCloctAt(pts); }
  17. inline double getClock() { return m_drift + av_gettime_relative() / 1000000.0; }
  18. private:
  19. inline void setCloctAt(double pts)
  20. {
  21. m_drift = pts - av_gettime_relative() / 1000000.0;
  22. m_pts = pts;
  23. }
  24. double m_pts;
  25. double m_drift;
  26. };
  27. #endif // AVCLOCK_H