Skip to content

Commit

Permalink
Close support automatic screen refresh, iina#3414
Browse files Browse the repository at this point in the history
This commit builds on top of the core code developed by @jesec to
add support for detecting additional cases where the display needs to
be adjusted, notifying the user using the OSD and logging the decisions
made by the feature.

The original code has been refactored out of MainWindowController and
into a new DisplaySynchronizer class. That class contains the core code
that manages a display a selects an appropriate refresh rate. That class
is used by a new RefreshRateMatcher class that handles the higher level
aspects of the feature.

Control of the feature has been moved from IINA Preferences to a menu
item in the Video menu. This provides a way to quickly turn the feature
off if a display proves problematic.

IINA must be running under macOS 12 or above for this feature to be
available. Older versions of macOS return zero for a display's refresh
rate preventing this feature from working. When running on an older
version of macOS the menu item will be hidden.

The commits in the pull request will:
- Add a new item "Match Refresh Rate" to video menu
- Bind the menu item to the ctrl+meta+r key
- Add a new class DisplaySynchronizer to control displays
- Add a new class RefreshRateMatcher to control the feature
- Change MainWindowController to use RefreshRateMatcher
- Add a new OSD message to show the display refresh rate
- Change PlayerCore to support short internal pause/resume cycles
- Add the ability to suppress pause/resume OSD messages
  • Loading branch information
low-batt committed May 16, 2022
1 parent 5bbe6b3 commit f665148
Show file tree
Hide file tree
Showing 14 changed files with 866 additions and 39 deletions.
25 changes: 25 additions & 0 deletions iina.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
49542986216C34950058F680 /* OpenInIINA.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 49542973216C34950058F680 /* OpenInIINA.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
496B19921E2968530035AF10 /* PIP.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 496B19911E2968530035AF10 /* PIP.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
519872FF26879B9B00F84BCC /* AccessibilityPreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 519872FE26879B9B00F84BCC /* AccessibilityPreferences.swift */; };
51FC32D928231A4100B1B2BC /* RefreshRateMatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51FC32D828231A4100B1B2BC /* RefreshRateMatcher.swift */; };
51FC32DB282366F600B1B2BC /* DisplaySynchronizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51FC32DA282366F600B1B2BC /* DisplaySynchronizer.swift */; };
51FDECDB281F2DCC008CA84F /* Atomics in Frameworks */ = {isa = PBXBuildFile; productRef = 51FDECDA281F2DCC008CA84F /* Atomics */; };
6100FF2B1EDF9806002CF0FB /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = 6100FF2A1EDF9806002CF0FB /* dsa_pub.pem */; };
8400D5C41E17C6D2006785F5 /* AboutWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8400D5C21E17C6D2006785F5 /* AboutWindowController.swift */; };
8400D5C61E1AB2F1006785F5 /* MainWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8400D5C81E1AB2F1006785F5 /* MainWindowController.xib */; };
Expand Down Expand Up @@ -536,6 +539,8 @@
49542983216C34950058F680 /* OpenInIINA.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = OpenInIINA.entitlements; sourceTree = "<group>"; };
496B19911E2968530035AF10 /* PIP.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PIP.framework; path = ../../../../System/Library/PrivateFrameworks/PIP.framework; sourceTree = "<group>"; };
519872FE26879B9B00F84BCC /* AccessibilityPreferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessibilityPreferences.swift; sourceTree = "<group>"; };
51FC32D828231A4100B1B2BC /* RefreshRateMatcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshRateMatcher.swift; sourceTree = "<group>"; };
51FC32DA282366F600B1B2BC /* DisplaySynchronizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplaySynchronizer.swift; sourceTree = "<group>"; };
5879479521A87DD700757A6F /* sk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sk; path = sk.lproj/MiniPlayerWindowController.strings; sourceTree = "<group>"; };
5879479621A87E6100757A6F /* sk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sk; path = sk.lproj/PreferenceWindowController.strings; sourceTree = "<group>"; };
5EF9F7E521FB42E900748374 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/MainMenu.strings"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1548,6 +1553,7 @@
E3B25F4524FF505D0068B9B0 /* libpcre.1.dylib in Frameworks */,
E3B25F5124FF505D0068B9B0 /* libidn2.0.dylib in Frameworks */,
496B19921E2968530035AF10 /* PIP.framework in Frameworks */,
51FDECDB281F2DCC008CA84F /* Atomics in Frameworks */,
8403CEA72007CBD400645516 /* MediaPlayer.framework in Frameworks */,
B4E446F225CB53FF0069F06E /* Gzip in Frameworks */,
E3B25F4424FF505D0068B9B0 /* libb2.1.dylib in Frameworks */,
Expand Down Expand Up @@ -1849,6 +1855,8 @@
E342832E20B7149800139865 /* Logger.swift */,
E3F698862120D878005792C9 /* ExtendedColors.swift */,
E301EFD921312AB300BC8588 /* KeychainAccess.swift */,
51FC32DA282366F600B1B2BC /* DisplaySynchronizer.swift */,
51FC32D828231A4100B1B2BC /* RefreshRateMatcher.swift */,
);
name = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -2275,6 +2283,7 @@
B4E446F625CB54EF0069F06E /* Mustache */,
B4E4470025CE3F930069F06E /* Sparkle */,
8451E6D82604AEFC009A15D7 /* Just */,
51FDECDA281F2DCC008CA84F /* Atomics */,
);
productName = mpvx;
productReference = 84EB1ED61D2F51D3004FA5A1 /* IINA.app */;
Expand Down Expand Up @@ -2361,6 +2370,7 @@
B4E446F525CB54EF0069F06E /* XCRemoteSwiftPackageReference "GRMustache" */,
B4E446FF25CE3F930069F06E /* XCRemoteSwiftPackageReference "Sparkle" */,
8451E6D72604AEFC009A15D7 /* XCRemoteSwiftPackageReference "Just" */,
51FDECD9281F2DCC008CA84F /* XCRemoteSwiftPackageReference "swift-atomics" */,
);
productRefGroup = 84EB1ED71D2F51D3004FA5A1 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -2538,6 +2548,7 @@
8450403D1E0A9EE20079C194 /* InspectorWindowController.swift in Sources */,
84C6D3671EB2A427009BF721 /* HistoryWindowController.swift in Sources */,
9E47DAC01E3CFA6D00457420 /* DurationDisplayTextField.swift in Sources */,
51FC32DB282366F600B1B2BC /* DisplaySynchronizer.swift in Sources */,
840AF5821E732C8F00F4AF92 /* JustXMLRPC.swift in Sources */,
E3513AF820EF79C500F8C347 /* PreferenceWindowController.swift in Sources */,
841A599D1E1FF5800079E177 /* SleepPreventer.swift in Sources */,
Expand Down Expand Up @@ -2588,6 +2599,7 @@
842F55A51EA17E7E0081D475 /* IINACommand.swift in Sources */,
8434BAAD1D5E4546003BECF2 /* SlideUpButton.swift in Sources */,
840D47981DFEEE6A000D9A64 /* KeyMapping.swift in Sources */,
51FC32D928231A4100B1B2BC /* RefreshRateMatcher.swift in Sources */,
84BEEC3F1DFEDE2F00F945CA /* PrefKeyBindingViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -3939,6 +3951,14 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
51FDECD9281F2DCC008CA84F /* XCRemoteSwiftPackageReference "swift-atomics" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/apple/swift-atomics.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.0.0;
};
};
8451E6D72604AEFC009A15D7 /* XCRemoteSwiftPackageReference "Just" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/dduan/Just";
Expand Down Expand Up @@ -3982,6 +4002,11 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
51FDECDA281F2DCC008CA84F /* Atomics */ = {
isa = XCSwiftPackageProductDependency;
package = 51FDECD9281F2DCC008CA84F /* XCRemoteSwiftPackageReference "swift-atomics" */;
productName = Atomics;
};
8451E6D82604AEFC009A15D7 /* Just */ = {
isa = XCSwiftPackageProductDependency;
package = 8451E6D72604AEFC009A15D7 /* XCRemoteSwiftPackageReference "Just" */;
Expand Down
1 change: 1 addition & 0 deletions iina/Base.lproj/KeyBinding.strings
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"iina.fit-to-screen" = "Fit to Screen";
"iina.toggle-flip" = "Toggle flip";
"iina.toggle-mirror" = "Toggle mirror";
"iina.toggle-match-refresh-rate" = "Toggle Match Refresh Rate";
"iina.save-playlist" = "Save current playlist";
"iina.delete-current-file" = "Delete current file";
"iina.delete-current-file-hard" = "Delete current file directly without moving to trash";
Expand Down
8 changes: 6 additions & 2 deletions iina/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16097.2"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand Down Expand Up @@ -423,6 +423,9 @@ CA
<menuItem title="Delogo" id="ArE-2s-JIV">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Match Refresh Rate" id="cuA-ze-ZZG">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem isSeparatorItem="YES" id="kNp-jq-01c"/>
<menuItem title="Video Filters…" keyEquivalent="F" id="PyY-pR-jz7">
<modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
Expand Down Expand Up @@ -720,6 +723,7 @@ CA
<outlet property="jumpTo" destination="2id-wn-xsC" id="wyH-9I-JHJ"/>
<outlet property="jumpToBegin" destination="2Ya-3g-1hy" id="atq-PX-lIt"/>
<outlet property="loadExternalSub" destination="k6x-hf-ATi" id="lVp-BV-A2C"/>
<outlet property="matchRefreshRate" destination="cuA-ze-ZZG" id="XaV-hF-MWN"/>
<outlet property="miniPlayer" destination="bGN-E4-V5A" id="gMc-FE-SVO"/>
<outlet property="mirror" destination="JJq-qH-toq" id="EWI-VS-c7Q"/>
<outlet property="mute" destination="WOL-Us-ByA" id="Hry-sv-WhY"/>
Expand Down
Loading

0 comments on commit f665148

Please sign in to comment.