Reputation: 597
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
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