CarterLi / iina

The modern video player for macOS with additional features and bug fixes.
https://iina.io
GNU General Public License v3.0
679 stars 29 forks source link

IINA+ sometimes can't detect my monitor supports HDR #64

Open kailiu42 opened 2 years ago

kailiu42 commented 2 years ago

System and IINA version:

Expected behavior: HDR switch on the video setup panel is on every time when playing on HDR monitor.

Actual behavior: I have an LG 27UP600 monitor which supports HDR, the macOS monitor configuration screen shows a "High Dynamic Range" checkbox and is checked by default. However, I noticed that sometimes IINA+ thinks my monitor supports HDR and allows me to turn on HDR on the video setup panel, but sometimes that switch is greyed out as if it thinks my monitor doesn't support HDR.

When that switch is greyed out, I have to go to macOS monitor configuration, uncheck and check again the HDR checkbox, then reopen IINA+, then the switch is no longer grey and HDR is turned on.

How often does this happen? This seems to happen each time after my monitor power is turned off then on, or after the DP cable is unplugged then plugged back. The monitor shows a HDR notification each time it powers on if the macOS HDR option is on, and it indeed shows it after powered on so it seems the OS is correctly recognizing the monitor as HDR and configured it as HDR. But IINA+ is not as described above.

CarterLi commented 2 years ago

iina used macOS system API to detect HDR monitors. if it lied, who knows what happened.

I can't fix an issue that can't be reproduced on my machine. Sorry.

kailiu42 commented 2 years ago

I too suspect this might be a OS bug that returns incorrect HDR monitor information.

Is it possible to add a config option for "allow turning on HDR even if the OS tells the monitor is not HDR for some reason"?

low-batt commented 2 years ago

This tool is useful to check what macOS thinks about the capabilities of your display: https://gist.github.com/Akemi/67f7a566d758bb843cb2ae405feecfa1

The LG site 27UP600-W lists the brightness as 320cd (Min)/400cd (Typ).

Many people would not consider that HDR capable.

Apple supports Extended Dynamic Range (EDR) as discussed here: Displaying HDR Content in a Metal Layer

EDR takes advantage of "headroom" to do better than SDR. From Performing Your Own Tone Mapping:

On Macs that support EDR, a 1.0 value for a pixel corresponds to the maximum standard dynamic range (SDR) brightness level, but this brightness level doesn't have to correspond to the maximum brightness of the display. If the display can produce higher brightness levels, additional range (headroom) may be available. The amount of headroom may vary, depending on the actual display characteristics:

  • If the UI brightness level is at 100 nits and the panel is capable of a maximum brightness of 400 nits, then enabling EDR allows values up to 4.0 to be displayed at 400 nits.

  • On the same panel, if the user adjusts the UI brightness level to 200 nits, then 1.0 values are displayed at 200 nits, and 2.0 values are at 400 nits.

So whether macOS enables EDR can change depending upon room brightness and the brightness level you have set your display at.

This is what the output of the above tool looks like when run on a MacBook Pro with a XDR display:

----------------------------- BEFORE EDR REQUEST ------------------------------
unknown
maximumPotentialExtendedDynamicRangeColorComponentValue: 16.0
maximumReferenceExtendedDynamicRangeColorComponentValue: 0.0
maximumExtendedDynamicRangeColorComponentValue: 1.0
-------------------------------------------------------------------------------
--------- Layer with EDR: false ---------
--------- View with EDR: false ---------
2022-08-12 17:18:32.762951-0400 edr[75649:12463202] Metal API Validation Enabled
Created CGL pixel format with attributes: kCGLPFAOpenGLProfile, kCGLOGLPVersion_3_2_Core, kCGLPFAAccelerated, kCGLPFADoubleBuffer, kCGLPFAColorSize, 64, kCGLPFAColorFloat, kCGLPFABackingStore, kCGLPFAAllowOfflineRenderers, kCGLPFASupportsAutomaticGraphicsSwitching, 0
--------- Layer with EDR: true ---------
--------- View with EDR: true ---------
Created CGL pixel format with attributes: kCGLPFAOpenGLProfile, kCGLOGLPVersion_3_2_Core, kCGLPFAAccelerated, kCGLPFADoubleBuffer, kCGLPFAColorSize, 64, kCGLPFAColorFloat, kCGLPFABackingStore, kCGLPFAAllowOfflineRenderers, kCGLPFASupportsAutomaticGraphicsSwitching, 0
------------------------------ AFTER EDR REQUEST ------------------------------
unknown
maximumPotentialExtendedDynamicRangeColorComponentValue: 16.0
maximumReferenceExtendedDynamicRangeColorComponentValue: 0.0
maximumExtendedDynamicRangeColorComponentValue: 1.8428928852081299
-------------------------------------------------------------------------------
kailiu42 commented 2 years ago

This tool is useful to check what macOS thinks about the capabilities of your display: gist.github.com/Akemi/67f7a566d758bb843cb2ae405feecfa1

Thanks for this tool.

This is how the output looks like when IINA+ HDR switch is greyed out:

-----------------------------------------------------------------------------
LG ULTRAFINE
maximumPotentialExtendedDynamicRangeColorComponentValue: 1.0
maximumReferenceExtendedDynamicRangeColorComponentValue: 0.0
maximumExtendedDynamicRangeColorComponentValue: 1.0
-----------------------------------------------------------------------------

And after unchecked/checked the HDR option of macOS system monitor preference page, it looks like below:

-----------------------------------------------------------------------------
LG ULTRAFINE
maximumPotentialExtendedDynamicRangeColorComponentValue: 2.0
maximumReferenceExtendedDynamicRangeColorComponentValue: 0.0
maximumExtendedDynamicRangeColorComponentValue: 1.0
-----------------------------------------------------------------------------

maximumPotentialExtendedDynamicRangeColorComponentValue changed from 1.0 to 2.0. And it keep reverting back to 1.0 after my LG monitor is powered off/on, like mentioned above. So it indeed looks more like a OS bug.

So whether macOS enables EDR can change depending upon room brightness and the brightness level you have set your display at.

Above are tested without touching other system configuration such as brightness, and I don't think the environmental brightness has noticeably changed during that few seconds of unchecking/checking that macOS HDR option. So I'm inclined to believe this is a macOS bug that it doesn't calculate the monitor capability on power on or plug in, but only after changing of the HDR preference.

low-batt commented 2 years ago

This definitely confirms that as suspected macOS is having trouble determining the capabilities of this monitor.

kailiu42 commented 2 years ago

This definitely confirms that as suspected macOS is having trouble determining the capabilities of this monitor.

Yes. So as I asked earlier, would it be possible for IINA+ to provide a workaround for such case? This is a DisplayHDR400 monitor so yes it has very limited HDR capability, but yet still better than nothing. I would appreciate if it could be best exploited.

CarterLi commented 2 years ago

This definitely confirms that as suspected macOS is having trouble determining the capabilities of this monitor.

Yes. So as I asked earlier, would it be possible for IINA+ to provide a workaround for such case? This is a DisplayHDR400 monitor so yes it has very limited HDR capability, but yet still better than nothing. I would appreciate if it could be best exploited.

I will take a look later

kailiu42 commented 2 years ago

I will take a look later

Very much appreciated!

CarterLi commented 2 years ago

Did a quick build for you. https://github.com/iina-plus/iina/actions/runs/3291067627

I just removed the HDR support check. Please check if it works

kailiu42 commented 2 years ago

Yes it works. I compared it with the original IINA+ side by side, when the HDR switch was grey in the original one, in this version it's usable and made a difference when turned on.