Skip to content

Commit

Permalink
add DisplayCriteria
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Dec 14, 2023
1 parent 95e6e61 commit cc38cbd
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 80 deletions.
1 change: 1 addition & 0 deletions Demo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ workspace 'Demo.xcworkspace'
install! 'cocoapods', :generate_multiple_pod_projects => true
def common
pod 'KSPlayer', :path => '../', :testspecs => ['Tests']
pod 'DisplayCriteria', :path => '../'
pod 'Libass', :path => '../FFmpegKit'
pod 'OpenSSL', :path => '../FFmpegKit'
pod 'FFmpegKit', :path => '../FFmpegKit'
Expand Down
6 changes: 0 additions & 6 deletions Demo/SwiftUI/Player.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
AC3CAD6228BB88A200AA1C2C /* AVDisplayCriteriaKS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AVDisplayCriteriaKS.h; sourceTree = "<group>"; };
AC3CAD6328BB893500AA1C2C /* Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Bridging-Header.h"; sourceTree = "<group>"; };
AC43F6402A5172830026ECF2 /* FavoriteView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteView.swift; sourceTree = "<group>"; };
AC43F6432A51916F0026ECF2 /* Model.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model.xcdatamodel; sourceTree = "<group>"; };
AC43F6652A519D400026ECF2 /* Persistence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Persistence.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -70,8 +68,6 @@
AC77DFAF26402327001351AE /* Shared */ = {
isa = PBXGroup;
children = (
AC3CAD6228BB88A200AA1C2C /* AVDisplayCriteriaKS.h */,
AC3CAD6328BB893500AA1C2C /* Bridging-Header.h */,
ACEA9FEA298BFC8800FBA74B /* MovieModel.swift */,
AC44E0F929290CBB00617BD3 /* HomeView.swift */,
AC44E0FA29290CBC00617BD3 /* ContentView.swift */,
Expand Down Expand Up @@ -368,7 +364,6 @@
SUPPORTS_MACCATALYST = YES;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_OBJC_BRIDGING_HEADER = "Shared/Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,6,7";
};
Expand Down Expand Up @@ -411,7 +406,6 @@
SUPPORTS_MACCATALYST = YES;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_OBJC_BRIDGING_HEADER = "Shared/Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,6,7";
VALIDATE_PRODUCT = YES;
Expand Down
12 changes: 0 additions & 12 deletions Demo/SwiftUI/Shared/Bridging-Header.h

This file was deleted.

18 changes: 0 additions & 18 deletions Demo/SwiftUI/Shared/MovieModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,6 @@ class MEOptions: KSOptions {
super.process(assetTrack: assetTrack)
}

override func updateVideo(refreshRate: Float, isDovi: Bool, formatDescription: CMFormatDescription?) {
#if os(tvOS) || os(xrOS)
guard let displayManager = UIApplication.shared.windows.first?.avDisplayManager,
displayManager.isDisplayCriteriaMatchingEnabled
else {
return
}
if let formatDescription {
if KSOptions.displayCriteriaFormatDescriptionEnabled, #available(tvOS 17.0, *) {
displayManager.preferredDisplayCriteria = AVDisplayCriteria(refreshRate: refreshRate, formatDescription: formatDescription)
} else {
let dynamicRange = isDovi ? .dolbyVision : formatDescription.dynamicRange
displayManager.preferredDisplayCriteria = AVDisplayCriteria(refreshRate: refreshRate, videoDynamicRange: dynamicRange.rawValue)
}
}
#endif
}

override func isUseDisplayLayer() -> Bool {
MEOptions.isUseDisplayLayer && display == .plane
}
Expand Down
6 changes: 0 additions & 6 deletions Demo/demo-tvOS/demo-tvOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

/* Begin PBXFileReference section */
055202483CC6922E098C6565 /* Pods-demo-tvOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-demo-tvOS.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-demo-tvOS/Pods-demo-tvOS.debug.xcconfig"; sourceTree = "<group>"; };
06D08BDA294DDA7400D919DB /* AVDisplayCriteriaKS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AVDisplayCriteriaKS.h; sourceTree = "<group>"; };
06D08BDB294DDA9900D919DB /* Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Bridging-Header.h"; sourceTree = "<group>"; };
AC08611420B69A1C00D801FC /* demo-tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "demo-tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
AC08611E20B69A1C00D801FC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
AC08612020B69A1C00D801FC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -78,8 +76,6 @@
AC08611E20B69A1C00D801FC /* Assets.xcassets */,
AC80333124BA1B54002B3D40 /* Main.storyboard */,
AC08612020B69A1C00D801FC /* Info.plist */,
06D08BDA294DDA7400D919DB /* AVDisplayCriteriaKS.h */,
06D08BDB294DDA9900D919DB /* Bridging-Header.h */,
);
path = "demo-tvOS";
sourceTree = "<group>";
Expand Down Expand Up @@ -362,7 +358,6 @@
PRODUCT_BUNDLE_IDENTIFIER = kintan.player.demo.tvos;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "demo-tvOS/Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
Expand All @@ -388,7 +383,6 @@
OTHER_CODE_SIGN_FLAGS = "--deep";
PRODUCT_BUNDLE_IDENTIFIER = kintan.player.demo.tvos;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "demo-tvOS/Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
};
Expand Down
21 changes: 0 additions & 21 deletions Demo/demo-tvOS/demo-tvOS/AVDisplayCriteriaKS.h

This file was deleted.

12 changes: 0 additions & 12 deletions Demo/demo-tvOS/demo-tvOS/Bridging-Header.h

This file was deleted.

22 changes: 22 additions & 0 deletions DisplayCriteria.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Pod::Spec.new do |s|
s.name = 'DisplayCriteria'
s.version = '1.1.0'
s.summary = 'Video Player Using Swift, based on AVPlayer,FFmpeg'

s.description = <<-DESC
Video Player Using Swift, based on ffmpeg, support for the horizontal screen, vertical screen, the upper and lower slide to adjust the volume, the screen brightness, or so slide to adjust the playback progress.
DESC

s.homepage = 'https://github.com/kingslay/KSPlayer'
s.authors = { 'kintan' => 'kingslay@icloud.com' }
s.license = 'MIT'
s.source = { :git => 'https://github.com/kingslay/KSPlayer.git', :tag => s.version.to_s }

s.ios.deployment_target = '13.0'
s.osx.deployment_target = '10.15'
# s.watchos.deployment_target = '2.0'
s.tvos.deployment_target = '13.0'
s.static_framework = true
s.source_files = 'Sources/DisplayCriteria/**/*'
s.frameworks = 'AVFoundation'
end
2 changes: 1 addition & 1 deletion FFmpegKit
1 change: 1 addition & 0 deletions KSPlayer.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Pod::Spec.new do |s|
ss.ios.frameworks = 'UIKit'
ss.tvos.frameworks = 'UIKit'
ss.osx.frameworks = 'AppKit'
ss.dependency 'DisplayCriteria'
end
#ffmpeg播放内核
s.subspec 'MEPlayer' do |ss|
Expand Down
4 changes: 4 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ let package = Package(
.product(name: "FFmpegKit", package: "FFmpegKit"),
// .product(name: "Libass", package: "FFmpegKit"),
// .product(name: "Libmpv", package: "FFmpegKit"),
"DisplayCriteria",
],
resources: [.process("Metal/Shaders.metal")]
),
.target(
name: "DisplayCriteria"
),
.testTarget(
name: "KSPlayerTests",
dependencies: ["KSPlayer"],
Expand Down
4 changes: 4 additions & 0 deletions Package@swift-5.9.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ let package = Package(
.product(name: "FFmpegKit", package: "FFmpegKit"),
// .product(name: "Libass", package: "FFmpegKit"),
// .product(name: "Libmpv", package: "FFmpegKit"),
"DisplayCriteria",
],
resources: [.process("Metal/Shaders.metal")]
),
.target(
name: "DisplayCriteria"
),
.testTarget(
name: "KSPlayerTests",
dependencies: ["KSPlayer"],
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Make sure to use the latest version **cocoapods 1.10.1+**, which can be installe
target 'ProjectName' do
use_frameworks!
pod 'KSPlayer',:git => 'https://github.com/kingslay/KSPlayer.git', :branch => 'develop'
pod 'DisplayCriteria',:git => 'https://github.com/kingslay/KSPlayer.git', :branch => 'develop'
pod 'FFmpegKit',:git => 'https://github.com/kingslay/FFmpegKit.git', :branch => 'main'
pod 'OpenSSL',:git => 'https://github.com/kingslay/FFmpegKit.git', :branch => 'main'
pod 'Libass',:git => 'https://github.com/kingslay/FFmpegKit.git', :branch => 'main'
Expand Down
1 change: 1 addition & 0 deletions Sources/DisplayCriteria/DisplayCriteria.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
@end
#endif
#endif /* AVDisplayCriteriaKS_h */

10 changes: 7 additions & 3 deletions Sources/KSPlayer/AVPlayer/KSOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
//

import AVFoundation
#if os(tvOS) || os(xrOS)
import DisplayCriteria
#endif
import OSLog

#if canImport(UIKit)
import UIKit
#endif
Expand Down Expand Up @@ -315,7 +319,7 @@ open class KSOptions {
}
}

open func updateVideo(refreshRate: Float, isDovi _: Bool, formatDescription: CMFormatDescription?) {
open func updateVideo(refreshRate: Float, isDovi: Bool, formatDescription: CMFormatDescription?) {
#if os(tvOS) || os(xrOS)
guard let displayManager = UIApplication.shared.windows.first?.avDisplayManager,
displayManager.isDisplayCriteriaMatchingEnabled
Expand All @@ -327,8 +331,8 @@ open class KSOptions {
if KSOptions.displayCriteriaFormatDescriptionEnabled, #available(tvOS 17.0, *) {
displayManager.preferredDisplayCriteria = AVDisplayCriteria(refreshRate: refreshRate, formatDescription: formatDescription)
} else {
// let dynamicRange = isDovi ? .dolbyVision : formatDescription.dynamicRange
// displayManager.preferredDisplayCriteria = AVDisplayCriteria(refreshRate: refreshRate, videoDynamicRange: dynamicRange.rawValue)
let dynamicRange = isDovi ? .dolbyVision : formatDescription.dynamicRange
displayManager.preferredDisplayCriteria = AVDisplayCriteria(refreshRate: refreshRate, videoDynamicRange: dynamicRange.rawValue)
}
}
#endif
Expand Down

2 comments on commit cc38cbd

@FaiChou
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在是不需要手动指定来开启 HDR 了吗?也就是说下面的代码可以删掉?

    override func updateVideo(refreshRate: Float, isDovi: Bool, formatDescription: CMFormatDescription?) {
        #if os(tvOS) || os(xrOS)
        guard let displayManager = UIApplication.shared.windows.first?.avDisplayManager,
              displayManager.isDisplayCriteriaMatchingEnabled,
              !displayManager.isDisplayModeSwitchInProgress
        else {
            return
        }
        if let formatDescription {
            if KSOptions.displayCriteriaFormatDescriptionEnabled, #available(tvOS 17.0, *) {
                displayManager.preferredDisplayCriteria = AVDisplayCriteria(refreshRate: refreshRate, formatDescription: formatDescription)
            } else {
                let dynamicRange = isDovi ? .dolbyVision : formatDescription.dynamicRange
                displayManager.preferredDisplayCriteria = AVDisplayCriteria(refreshRate: refreshRate, videoDynamicRange: dynamicRange.rawValue)
            }
        }
        #endif
    }

@kingslay
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,这个库会自动帮你处理了

Please sign in to comment.