Experimental HDR support on macOS using colorSpace approach#8404
Experimental HDR support on macOS using colorSpace approach#8404anastasiuspernat wants to merge 5 commits intompv-player:masterfrom
Conversation
|
i added a few comments. it would also be nice to have some mpv option examples and some screenshots with before, now and quicktime. mostly out of curiosity and for future reference. |
|
The commits add (and update) |
|
Sorry about |
I didn't look at the commits one by one, but assuming you intend to keep the commits incremental without squashing, then removing them only at the last commit is not enough - you'll need to remove them from all commits (might be slightly painful, but not too much, though the pain would also make it easier to avoid next time :p). |
|
No I don't intend to keep all the commits. Would be happy if you could help me to squash them the right way if that's necessary. I think only the current final stage is important, thank you. |
|
Not necessary to squash them right away, depends on how you want to present it - incremental changes or one commit which changes over time. But you can do that it you prefer to work only on one commit. This is git territory, but you can squash commits locally by running For fllowup changes, you can either do the same with new commits before you push them, or just amend the existing commit, and again force push will update the PR. Force ( |
|
OK great! Thanks for the details. One commit per major followup would definitely look better. Will squash it on next iteration. |
|
There are no hard rules, but the convention is that you can force push in a PR (change existing commits), but preferably keep a set of commits which is intended to be pushed individually, where each commit does one "thing". Deciding what a "thing" is is subjective, but if your code does two unrelated things for instance, then it's preferable to keep those in two distinct commits. I just briefly looked at the combined diff of this PR, and indeed I agree it should probably end up as one commit. |
video/out/mac/common.swift
Outdated
| // HDR is supported fully only on macOS 10.15 and higher | ||
| // some of the HDR color spaces are available on 10.14 though | ||
| #if HAVE_MACOS_10_15_FEATURES | ||
| switch (mpv?.macOpts.macos_hdr_csp) |
There was a problem hiding this comment.
Fixed it! Also some color spaces are declared as supported by 10.14.X SDKs, like 10.14.6 etc but seems HAVE_MACOS_10_14_FEATURES checking for 14.0 and Travis won't let me to go through if I put them inside HAVE_MACOS_10_14_FEATURES.
Here's PR: 427d81c
Travis build log: https://travis-ci.org/github/mpv-player/mpv/jobs/751898275
(the error is "'CGColorSpace' has no member 'displayP3_HLG'", with the check for #available(macOS 10.14.6...).
In any case only macOS Catalina 10.15 supports HDR output and it's better be compiled against this version. So most of those are now inside HAVE_MACOS_10_15_FEATURES.
There was a problem hiding this comment.
no those color spaces are specifically defined to be available on 10.14.6 and not 10.14.X/any 10.14 SDK. it needs a specific minor configure check too.
HAVE_MACOS_10_14_FEATURES only checks for 10.14(.0) features but not for 10.14.6. this needs a separate configure check.
video/out/mac/common.swift
Outdated
| (view?.layer as! CAOpenGLLayer).colorspace = CGColorSpace(name: name) | ||
| } else | ||
| { | ||
| (view?.layer as! CAOpenGLLayer).colorspace = windowColorSpace.cgColorSpace |
There was a problem hiding this comment.
no forced casts. i still dislike the else case here.
There was a problem hiding this comment.
Need some help here. How else can I set color space on the view.layer? It's CALayer, right? Doesn't have colorspace property.
Also what's wrong with else, you mean the curly bracket?
There was a problem hiding this comment.
typecasting is okay, but you should not force typecasting by any means, eg as? instead of as!. the latter case will crash when failing. see https://docs.swift.org/swift-book/LanguageGuide/TypeCasting.html
the else is unnecessary there.
colorSpcace = defaultColorSpace
if someCondtion == true {
colorSpcace = differentColorSpace
}
There was a problem hiding this comment.
Unfortunately this way typecasting doesn't work. With as? I receive a compilation error about unwrapping CAOpenGLLayer, probably view.layer has a wrong type definition?
There was a problem hiding this comment.
something like this should haves worked. though i would need to see the specific error.
guard let newlayer = layer as? CAOpenGLLayer else {
return
}
// access newlayer here
|
i am not sure if what we see on those screenshots is 'intended' or more likely a 'coincidence' that it looks somewhat similar/okay'ish. |
|
|
||
| var cursorVisibilityWanted: Bool = true | ||
|
|
||
| var colorSpace: NSColorSpace? |
There was a problem hiding this comment.
i believe this variable is not needed.
There was a problem hiding this comment.
It's used in updateICCProfile for setRenderICCProfile in cocoa_cb_common.swift.
There was a problem hiding this comment.
what i meant here, is that we don't need a variable that is available to the whole object of that class but just a function local variable would have done perfectly fine.
d53d47c to
266f583
Compare
Experimental HDR support on macOS using colorSpace approach Experimental HDR support on macOS using colorSpace approach Experimental HDR support on macOS using colorSpace approach Experimental HDR support on macOS using colorSpace approach Experimental HDR support on macOS using colorSpace approach Experimental HDR support on macOS using colorSpace approach Experimental HDR support on macOS using colorSpace approach Added macOS version check Added macOS version check for Catalina Stricter check for macOS Catalina features Switched from runtime check to compile time check of macOS features Made macOS HDR implementation more consistent Made macOS HDR implementation more consistent Made macOS HDR implementation more consistent Made macOS HDR implementation more consistent Made macOS HDR implementation more consistent Improved macOS HDR-related code by PR comments Improved macOS HDR-related code by PR comments Improved macOS HDR-related code by PR comments Improved macOS HDR-related code by PR comments Improved macOS HDR-related code by PR comments
87d52f8 to
8cd7d2d
Compare
@Akemi Also squashed the PR and updated code by our conversation. Answered on the rest of the issues. |
|
Please don't forget iOS version for the HDR support, i think it's almost the same as MacOS |
this has nothing to do with iOS though. there is no iOS backend in mpv. on iOS you will use libmpv and there the layer is handled by the libmpv user. so it's entirely in the hands of the one using libmpv on iOS to support this. |
|
@Akemi |
|
i just didn't get around looking at it again. |
|
i opened my own PR #8485. i don't mean this to be disrespectful towards you and i hope it isn't seen as this. but what i had in mind and what you did here was a bit too far apart for me to explain everything i wanted. it would be nice if you could also test my PR. nevertheless i will give you some more feedback on this PR for the future. |
| {"macos-output-csp", OPT_CHOICE(macos_output_csp, | ||
| {"auto", -1}, {"displayP3_HLG", 0}, {"displayP3_PQ_EOTF", 1}, | ||
| {"extendedLinearDisplayP3", 2}, {"itur_2020", 3}, {"itur_2020_HLG", 4}, | ||
| {"itur_2020_PQ_EOTF", 5}, {"extendedSRGB",6}, {"extendedLinearSRGB",7} |
There was a problem hiding this comment.
the extended color spaces expect component values below 0 and above 1.0. that's what mpv can't do atm and with that those color spaces are a bit useless atm.
| layer?.colorspace = colorSpace.cgColorSpace | ||
| } | ||
| super.updateICCProfile() | ||
| libmpv.setRenderICCProfile(colorSpace!) |
There was a problem hiding this comment.
never use a forced unwrapping in swift if not necessary. always use a guard, if let or ? instead of !. otherwise it will only end up in hard crashes.
|
|
||
| if (mpv?.macOpts.macos_output_csp != -1) { | ||
| (view.layer as! CAOpenGLLayer).wantsExtendedDynamicRangeContent = true | ||
| view.wantsExtendedDynamicRangeOpenGLSurface = true; |
| if #available(macOS 10.12, *) { | ||
| switch (mpv?.macOpts.macos_output_csp) | ||
| { | ||
| case 6: name = CGColorSpace.extendedSRGB; break |
There was a problem hiding this comment.
breaks are not necessary on swift switch case. it will only fall through if an explicit fallthrough keyword is used. also the semicolons.
No worries haha! You better know your codebase, also Swift is a new language to me. In any case my main intention was to make IINA (mpv-based video player) play with my HDR monitor on macOS. I thought mpv is the main culprit but now I see it's not. My fork of IINA now plays HDR videos perfectly so my main goal is achieved and I just wanted to give back my findings (which are based on your knowledge) to the world. I rarely take part in opensource and it was a lot of fun. I'll try to test and answer when I have time! Thanks again for the guidance. |
|
@Akemi @anastasiuspernat any progress on this? |
|
any progress on this? |
|
sorry for stalling this for so long. i am going to close this one i favour of #8485. i will also revisit #8485 and see how we will proceed with it. also see the last comment und the linked issue for discussion (#7341 (comment)). |

Enabling support for HDR monitors (in manual mode).
Main discussion is here: #7341
Added a new switch called
--macos_hdr_csp(similar to d3d color space approach at #5804). It specifies the extended HDR color space. Doesn't require any shader or video render pipeline modification. Auto-activates EDR/HDR mode on the video layer.Currently supported color spaces (passed to
--macos_hdr_cspswitch):displayP3_PQ_EOTFDCI P3 primaries, PQ transfer function - that's the most common color profile for most videosdisplayP3_HLGDCI P3 primaries, and the HLG gammaextendedLinearDisplayP3P3 primaries and linear transfer functionitur_2020BT.2020itur_2020_PQ_EOTFBT.2020 with PQ transfer functionThis can (and probably must) be set together with
target-trcswitch. Both values must correspond to video's color primaries/transfer characteristics in order to get the correct color reproduction.Tested on varios video footage on macOS Catalina 10.15.5. Produces same results as QuickTime player on the same footage.