Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Jan 6, 2024
1 parent c02dca4 commit be2e1a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
6 changes: 5 additions & 1 deletion Sources/KSPlayer/AVPlayer/KSOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ open class KSOptions {
var yadifMode = KSOptions.yadifMode
if let assetTrack = assetTrack as? FFmpegAssetTrack {
if assetTrack.realFrameRate.num == 2 * assetTrack.avgFrameRate.num, assetTrack.realFrameRate.den == assetTrack.avgFrameRate.den {
yadifMode = 0
if yadifMode == 1 {
yadifMode = 0
} else if yadifMode == 3 {
yadifMode = 2
}
}
}
videoFilters.append("\(yadif)=mode=\(yadifMode):parity=-1:deint=1")
Expand Down
19 changes: 13 additions & 6 deletions Sources/KSPlayer/MEPlayer/MetalPlayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ public final class MetalPlayView: UIView, VideoOutput {
private var fps = Float(60) {
didSet {
if fps != oldValue {
let preferredFramesPerSecond = Int(ceil(fps))
displayLink.preferredFramesPerSecond = preferredFramesPerSecond << 1
#if os(iOS)
if #available(iOS 15.0, tvOS 15.0, *) {
displayLink.preferredFrameRateRange = CAFrameRateRange(minimum: Float(preferredFramesPerSecond), maximum: Float(preferredFramesPerSecond << 1))
let preferredFramesPerSecond = ceil(fps)
if #available(iOS 15.0, tvOS 15.0, macOS 14.0, *) {
displayLink.preferredFrameRateRange = CAFrameRateRange(minimum: preferredFramesPerSecond, maximum: 2 * preferredFramesPerSecond, __preferred: preferredFramesPerSecond)
} else {
displayLink.preferredFramesPerSecond = Int(preferredFramesPerSecond) << 1
}
#endif
options.updateVideo(refreshRate: fps, isDovi: isDovi, formatDescription: formatDescription)
}
}
Expand Down Expand Up @@ -363,6 +362,14 @@ class CADisplayLink {
private var runloop: RunLoop?
private var mode = RunLoop.Mode.default
public var preferredFramesPerSecond = 60
@available(macOS 12.0, *)
public var preferredFrameRateRange: CAFrameRateRange {
get {
CAFrameRateRange()
}
set {}
}

public var timestamp: TimeInterval {
var timeStamp = CVTimeStamp()
if CVDisplayLinkGetCurrentTime(displayLink, &timeStamp) == kCVReturnSuccess, (timeStamp.flags & CVTimeStampFlags.hostTimeValid.rawValue) != 0 {
Expand Down

0 comments on commit be2e1a7

Please sign in to comment.