From bc1dce5d5b8eabc29813b85ea79dd6d69a9367a3 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 6 Jan 2016 13:33:42 +0100 Subject: [PATCH] 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. --- video/out/cocoa_common.m | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index 586a51dbe4..30b832da75 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -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); }