Skip to content

Commit

Permalink
Include core video return code in fatal error (#4575)
Browse files Browse the repository at this point in the history
* Include core video return code in fatal error

This commit will add code to VideoView that includes the result code
returned by CVDisplayLinkCreateWithActiveCGDisplays in the alert posted
when a display link can not be created.

* Include core video return code in fatal error

This commit will add code to VideoView that includes the result code
returned by CVDisplayLinkCreateWithActiveCGDisplays in the alert posted
when a display link can not be created.

Co-authored-by: Yuze Jiang <i@uiryuu.moe>

---------

Co-authored-by: Yuze Jiang <i@uiryuu.moe>
  • Loading branch information
low-batt and uiryuu committed Dec 26, 2023
1 parent caa7b44 commit feaf4a6
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions iina/VideoView.swift
Expand Up @@ -204,14 +204,27 @@ class VideoView: NSView {

// MARK: Display link

func startDisplayLink() {
if link == nil {
checkResult(CVDisplayLinkCreateWithActiveCGDisplays(&link),
"CVDisplayLinkCreateWithActiveCGDisplays")
}
/// Returns a [Core Video](https://developer.apple.com/documentation/corevideo) display link.
///
/// If a display link has already been created then that link will be returned, otherwise a display link will be created and returned.
///
/// - Note: Issue [#4520](https://github.com/iina/iina/issues/4520) reports a case where it appears the call to
///[CVDisplayLinkCreateWithActiveCGDisplays](https://developer.apple.com/documentation/corevideo/1456863-cvdisplaylinkcreatewithactivecgd) is failing. In case that failure is
///encountered again this method is careful to log any failure and include the [result code](https://developer.apple.com/documentation/corevideo/1572713-result_codes) in the alert displayed
/// by `Logger.fatal`.
/// - Returns: A [CVDisplayLink](https://developer.apple.com/documentation/corevideo/cvdisplaylink-k0k).
private func obtainDisplayLink() -> CVDisplayLink {
if let link = link { return link }
let result = CVDisplayLinkCreateWithActiveCGDisplays(&link)
checkResult(result, "CVDisplayLinkCreateWithActiveCGDisplays")
guard let link = link else {
Logger.fatal("Cannot Create display link!")
Logger.fatal("Cannot create display link: \(codeToString(result)) (\(result))")
}
return link
}

func startDisplayLink() {
let link = obtainDisplayLink()
guard !CVDisplayLinkIsRunning(link) else { return }
updateDisplayLink()
checkResult(CVDisplayLinkSetOutputCallback(link, displayLinkCallback, mutableRawPointerOf(obj: self)),
Expand Down

0 comments on commit feaf4a6

Please sign in to comment.