kingslay / KSPlayer

A video player for iOS、macOS、tvOS、visionOS , based on AVPlayer and FFmpeg, support the horizontal, vertical screen. support adjust volume, brightness and seek by slide, SwiftUI, support subtitles.
https://apps.apple.com/app/tracyplayer/id6450770064
GNU General Public License v3.0
984 stars 197 forks source link

FormatDescription DisplayCriteria: dynamic range problem. #669

Closed djokt closed 10 months ago

djokt commented 10 months ago

On Tracy, when we activate "FormatDescription DisplayCriteria", Dolby Vision content is played as HDR10. (Tested on tvOS 17.1)

Alanko5 commented 10 months ago

https://github.com/kingslay/KSPlayer/issues/633

cdguy commented 10 months ago

633

@Alanko5 So you mean that only using this code would solve the problem?

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
}
Alanko5 commented 10 months ago

Yes you need add bridging header for objc file header. https://github.com/kingslay/KSPlayer/blob/119f75a6251ac0807b9a529e8ef335c1033ba4ab/Demo/SwiftUI/Shared/AVDisplayCriteriaKS.h