#pragma once
#include <cstdint>
namespace smartcut::core {
struct RationalTimebase { std::int64_t num{1}; std::int64_t den{1}; };
class PreviewClock {
 public:
  PreviewClock(RationalTimebase audio_timebase, RationalTimebase video_timebase) : audio_timebase_(audio_timebase), video_timebase_(video_timebase) {}
  void set_audio_pts(std::int64_t pts) { audio_pts_ = pts; }
  void set_video_pts(std::int64_t pts) { video_pts_ = pts; }
  std::int64_t audio_master_video_pts() const { return rescale(audio_pts_, audio_timebase_, video_timebase_); }
  std::int64_t video_drift_ticks() const { return video_pts_ - audio_master_video_pts(); }
 private:
  static std::int64_t rescale(std::int64_t value, RationalTimebase source, RationalTimebase target) { const auto numerator = value * source.num * target.den; const auto denominator = source.den * target.num; return denominator == 0 ? 0 : numerator / denominator; }
  RationalTimebase audio_timebase_;
  RationalTimebase video_timebase_;
  std::int64_t audio_pts_ = 0;
  std::int64_t video_pts_ = 0;
};
}  // namespace smartcut::core
