kungfoo
kungfoo

Reputation: 597

Convert CADisplayLink.timestamp CFTimeInterval to host time (uint64)

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!

Upvotes: 1

Views: 993

Answers (1)

olynoise
olynoise

Reputation: 2066

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;

Upvotes: 3

Related Questions