#include #include #include #include namespace { LONGLONG GetPerfFreq() { LARGE_INTEGER large_int; ASSERT(::QueryPerformanceFrequency(&large_int)); return large_int.QuadPart; } } boost::int64_t TimerTraits::performance_freq_ = GetPerfFreq(); TimerTraits::time_type TimerTraits::now() { LARGE_INTEGER large_int; ::QueryPerformanceCounter(&large_int); time_type result; result.ticks_ = large_int.QuadPart; return result; } boost::posix_time::time_duration TimerTraits::to_posix_duration( const TimerTraits::duration_type& d) { CheckedInt64 counts(d.ticks_); CheckedInt64 freq(performance_freq_); // Convert the counts from the performance // counter counts.ScaleEq(CheckedInt64(1000), freq); // Assert that there is no error in the conversion ASSERT(counts.GetError() == CheckedInt64::NONE); return boost::posix_time::milliseconds(counts.GetValue()); } boost::int64_t TimerTraits::milliseconds_to_duration(boost::uint32_t milliseconds) { CheckedInt64 counts(milliseconds); CheckedInt64 freq(performance_freq_); // Convert the counts from milliseconds // into the performance counter frequency counts.ScaleEq(freq, CheckedInt64(1000)); // Assert that there is no error in the conversion ASSERT(counts.GetError() == CheckedInt64::NONE); return counts.GetValue(); } } // namespace Details } // namespace AVCPlat