将CADisplayLink.timestamp CFTimeInterval转换为主机时间(uint64)

时间:2012-12-28 16:09:40

标签: ios avfoundation cadisplaylink

我正在从CADisplayLink获得回调。该链接在CFTimeInterval中有一个时间戳。如何在uint64中将该时间戳转换为hosttime?

谢谢!

1 个答案:

答案 0 :(得分:2)

这是一份描述马赫时间转换为秒的文件。 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 

因为CGTimeInterval以秒为单位,我们可以简单地执行此操作:

uint64_t displayLinkTime = displayLink.timeStamp * clockFrequency;