| 1 | #include <TimerTraits.h>
|
|---|
| 2 |
|
|---|
| 3 | #include <Assert.h>
|
|---|
| 4 | #include <CheckedInt64.h>
|
|---|
| 5 |
|
|---|
| 6 | #include <windows.h>
|
|---|
| 7 |
|
|---|
| 8 | namespace {
|
|---|
| 9 |
|
|---|
| 10 | LONGLONG GetPerfFreq()
|
|---|
| 11 | {
|
|---|
| 12 | LARGE_INTEGER large_int;
|
|---|
| 13 |
|
|---|
| 14 | ASSERT(::QueryPerformanceFrequency(&large_int));
|
|---|
| 15 |
|
|---|
| 16 | return large_int.QuadPart;
|
|---|
| 17 | }
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | boost::int64_t TimerTraits::performance_freq_ = GetPerfFreq();
|
|---|
| 21 |
|
|---|
| 22 | TimerTraits::time_type TimerTraits::now()
|
|---|
| 23 | {
|
|---|
| 24 | LARGE_INTEGER large_int;
|
|---|
| 25 |
|
|---|
| 26 | ::QueryPerformanceCounter(&large_int);
|
|---|
| 27 |
|
|---|
| 28 | time_type result;
|
|---|
| 29 | result.ticks_ = large_int.QuadPart;
|
|---|
| 30 | return result;
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | boost::posix_time::time_duration TimerTraits::to_posix_duration(
|
|---|
| 34 | const TimerTraits::duration_type& d)
|
|---|
| 35 | {
|
|---|
| 36 | CheckedInt64 counts(d.ticks_);
|
|---|
| 37 | CheckedInt64 freq(performance_freq_);
|
|---|
| 38 |
|
|---|
| 39 | // Convert the counts from the performance
|
|---|
| 40 | // counter
|
|---|
| 41 |
|
|---|
| 42 | counts.ScaleEq(CheckedInt64(1000), freq);
|
|---|
| 43 |
|
|---|
| 44 | // Assert that there is no error in the conversion
|
|---|
| 45 |
|
|---|
| 46 | ASSERT(counts.GetError() == CheckedInt64::NONE);
|
|---|
| 47 |
|
|---|
| 48 | return boost::posix_time::milliseconds(counts.GetValue());
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | boost::int64_t
|
|---|
| 52 | TimerTraits::milliseconds_to_duration(boost::uint32_t milliseconds)
|
|---|
| 53 | {
|
|---|
| 54 | CheckedInt64 counts(milliseconds);
|
|---|
| 55 | CheckedInt64 freq(performance_freq_);
|
|---|
| 56 |
|
|---|
| 57 | // Convert the counts from milliseconds
|
|---|
| 58 | // into the performance counter frequency
|
|---|
| 59 |
|
|---|
| 60 | counts.ScaleEq(freq, CheckedInt64(1000));
|
|---|
| 61 |
|
|---|
| 62 | // Assert that there is no error in the conversion
|
|---|
| 63 |
|
|---|
| 64 | ASSERT(counts.GetError() == CheckedInt64::NONE);
|
|---|
| 65 |
|
|---|
| 66 | return counts.GetValue();
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | } // namespace Details
|
|---|
| 71 | } // namespace AVCPlat
|
|---|