1

I am getting a callback from CADisplayLink. The link has a timestamp in CFTimeInterval. How to you convert that timestamp to hosttime in uint64?

Thanks!

kungfoo
  • 597
  • 5
  • 16

1 Answers1

3

Here's a document describing the conversion of mach time into seconds. https://developer.apple.com/library/ios/qa/qa1643/_index.html

#include <mach/mach_time.h>
...

struct mach_timebase_info timeBaseInfo;
mach_timebase_info(&timeBaseInfo);

CGFloat clockFrequency = (CGFloat)timeBaseInfo.denom / (CGFloat)timeBaseInfo.numer;
clockFrequency *= 1000000000.0;

// clock frequency (for me) is 24000000 

Because CGTimeInterval is in seconds, we can simply do this:

uint64_t displayLinkTime = displayLink.timeStamp * clockFrequency;
olynoise
  • 2,016
  • 2
  • 19
  • 32