Skip to content

Commit

Permalink
Fix crash when playing HDR on SDR TV. Improve device profile (#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
cewert authored Oct 15, 2024
1 parent 2d91603 commit c14ec8f
Showing 1 changed file with 79 additions and 21 deletions.
100 changes: 79 additions & 21 deletions source/utils/deviceCapabilities.bs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,14 @@ function getContainerProfiles() as object
end function

function getCodecProfiles() as object
globalUserSettings = m.global.session.user.settings
myGlobal = m.global
globalUserSettings = myGlobal.session.user.settings
displayMaxBitDepth = myGlobal.device.videoBitDepth
if displayMaxBitDepth = invalid
displayMaxBitDepth = "8"
else
displayMaxBitDepth = displayMaxBitDepth.toStr()
end if
codecProfiles = []
profileSupport = {
"h264": {},
Expand Down Expand Up @@ -556,25 +563,27 @@ function getCodecProfiles() as object
vp9VideoRangeTypes = "SDR"
av1VideoRangeTypes = "SDR"

dp = di.GetDisplayProperties()
if dp.Hdr10
hevcVideoRangeTypes = hevcVideoRangeTypes + "|HDR10"
vp9VideoRangeTypes = vp9VideoRangeTypes + "|HDR10"
av1VideoRangeTypes = av1VideoRangeTypes + "|HDR10"
end if
if dp.Hdr10Plus
av1VideoRangeTypes = av1VideoRangeTypes + "|HDR10+"
end if
if dp.HLG
hevcVideoRangeTypes = hevcVideoRangeTypes + "|HLG"
vp9VideoRangeTypes = vp9VideoRangeTypes + "|HLG"
av1VideoRangeTypes = av1VideoRangeTypes + "|HLG"
end if
if dp.DolbyVision
h264VideoRangeTypes = h264VideoRangeTypes + "|DOVI"
hevcVideoRangeTypes = hevcVideoRangeTypes + "|DOVI"
'vp9VideoRangeTypes = vp9VideoRangeTypes + ",DOVI" no evidence that vp9 can hold DOVI
av1VideoRangeTypes = av1VideoRangeTypes + "|DOVI"
if canPlay4k()
dp = di.GetDisplayProperties()
if dp.Hdr10
hevcVideoRangeTypes = hevcVideoRangeTypes + "|HDR10"
vp9VideoRangeTypes = vp9VideoRangeTypes + "|HDR10"
av1VideoRangeTypes = av1VideoRangeTypes + "|HDR10"
end if
if dp.Hdr10Plus
av1VideoRangeTypes = av1VideoRangeTypes + "|HDR10+"
end if
if dp.HLG
hevcVideoRangeTypes = hevcVideoRangeTypes + "|HLG"
vp9VideoRangeTypes = vp9VideoRangeTypes + "|HLG"
av1VideoRangeTypes = av1VideoRangeTypes + "|HLG"
end if
if dp.DolbyVision
h264VideoRangeTypes = h264VideoRangeTypes + "|DOVI"
hevcVideoRangeTypes = hevcVideoRangeTypes + "|DOVI"
'vp9VideoRangeTypes = vp9VideoRangeTypes + ",DOVI" no evidence that vp9 can hold DOVI
av1VideoRangeTypes = av1VideoRangeTypes + "|DOVI"
end if
end if

' H264
Expand Down Expand Up @@ -670,7 +679,13 @@ function getCodecProfiles() as object
"Property": "VideoLevel",
"Value": mpeg2Levels.join("|"),
"IsRequired": false
}
},
{
"Condition": "LessThanEqual",
"Property": "VideoBitDepth",
"Value": displayMaxBitDepth,
"IsRequired": false
},
]
}

Expand Down Expand Up @@ -706,6 +721,12 @@ function getCodecProfiles() as object
"Type": "Video",
"Codec": "av1",
"Conditions": [
{
"Condition": "LessThanEqual",
"Property": "VideoBitDepth",
"Value": displayMaxBitDepth,
"IsRequired": false
},
{
"Condition": "EqualsAny",
"Property": "VideoProfile",
Expand Down Expand Up @@ -765,6 +786,12 @@ function getCodecProfiles() as object
"Type": "Video",
"Codec": "hevc",
"Conditions": [
{
"Condition": "LessThanEqual",
"Property": "VideoBitDepth",
"Value": displayMaxBitDepth,
"IsRequired": false
},
{
"Condition": "NotEquals",
"Property": "IsAnamorphic",
Expand Down Expand Up @@ -834,6 +861,12 @@ function getCodecProfiles() as object
"Type": "Video",
"Codec": "vp9",
"Conditions": [
{
"Condition": "LessThanEqual",
"Property": "VideoBitDepth",
"Value": displayMaxBitDepth,
"IsRequired": false
},
{
"Condition": "EqualsAny",
"Property": "VideoProfile",
Expand Down Expand Up @@ -1094,3 +1127,28 @@ function setPreferredCodec(codecString as string, preferredCodec as string) as s
return newCodecString
end if
end function

' does the connected display support playing 4k video?
function canPlay4k() as boolean
deviceInfo = CreateObject("roDeviceInfo")
hdmiStatus = CreateObject("roHdmiStatus")

' Check if the output mode is 2160p or higher
maxVideoHeight = m.global.device.videoHeight
if maxVideoHeight = invalid then return false
if maxVideoHeight.ToInt() < 2160
return false
end if

' Check if HDCP 2.2 is enabled, skip check for TVs
if deviceInfo.GetModelType() = "STB" and hdmiStatus.IsHdcpActive("2.2") <> true
return false
end if

' Check if the Roku player can decode 4K 60fps HEVC streams
if deviceInfo.CanDecodeVideo({ Codec: "hevc", Profile: "main", Level: "5.1" }).result <> true
return false
end if

return true
end function

0 comments on commit c14ec8f

Please sign in to comment.