1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 07:12:39 +00:00

cocoa: get fps only from dislaylink

In my tests, CGDisplayModeGetRefreshRate returns 24.0 even though the nominal
one is set to 24000/1001. This is obviously not good for video.
This commit is contained in:
Stefano Pigozzi 2016-01-06 13:33:42 +01:00
parent 0fad73862c
commit bc1dce5d5b

View File

@ -374,22 +374,23 @@ static void vo_cocoa_update_screen_fps(struct vo *vo)
NSDictionary* sinfo = [screen deviceDescription];
NSNumber* sid = [sinfo objectForKey:@"NSScreenNumber"];
CGDirectDisplayID did = [sid longValue];
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(did);
s->screen_fps = CGDisplayModeGetRefreshRate(mode);
CGDisplayModeRelease(mode);
if (s->screen_fps == 0.0) {
CVDisplayLinkRef link;
CVDisplayLinkCreateWithCGDisplay(did, &link);
s->screen_fps = CVDisplayLinkGetActualOutputVideoRefreshPeriod(link);
if (s->screen_fps == 0) {
// Fallback to using Nominal refresh rate from DisplayLink,
// CVDisplayLinkGet *Actual* OutputVideoRefreshPeriod seems to
// return 0 as well if CG returns 0
CVDisplayLinkRef link;
CVDisplayLinkCreateWithCGDisplay(did, &link);
// return 0 on some Apple devices. Use the nominal refresh period
// instead.
const CVTime t = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
if (!(t.flags & kCVTimeIsIndefinite))
s->screen_fps = (t.timeScale / (double) t.timeValue);
CVDisplayLinkRelease(link);
}
CVDisplayLinkRelease(link);
flag_events(vo, VO_EVENT_WIN_STATE);
}