Skip to content

Commit 7084c9d

Browse files
committed
Update code docs
1 parent a31060b commit 7084c9d

4 files changed

Lines changed: 92 additions & 56 deletions

File tree

docs/data/search.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/module-deviceCapabilities.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/source_api_Items.bs.html

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -94,39 +94,31 @@
9494
end if
9595
end if
9696

97-
' Cap H264 codec profile to 1080p when the source video is H264.
97+
' Cap H264 codec profile when the source video is H264.
9898
' Applied dynamically here rather than in the static device profile so it doesn't
9999
' interfere with non-H264 content (e.g. HEVC DoVi remux needs unrestricted resolution).
100+
' 1080p (1920x1080) is the H264 hardware ceiling on all Roku devices, but a lower
101+
' user resolution cap is respected if set.
100102
if isValid(mediaStreams)
101103
for each stream in mediaStreams
102104
if isValid(stream.Type) and stream.Type = "Video" and isValid(stream.Codec) and LCase(stream.Codec) = "h264"
103105
if isValid(postData.DeviceProfile.CodecProfiles)
106+
' Start from the H264 hardware ceiling, then clamp down to the user's cap if lower
107+
h264CapHeight = 1080
108+
h264CapWidth = 1920
109+
userResConditions = getResolutionConditions()
110+
for each condition in userResConditions
111+
if condition.Property = "Height" and condition.Value.toInt() < h264CapHeight
112+
h264CapHeight = condition.Value.toInt()
113+
end if
114+
if condition.Property = "Width" and condition.Value.toInt() < h264CapWidth
115+
h264CapWidth = condition.Value.toInt()
116+
end if
117+
end for
118+
104119
for each codecProfile in postData.DeviceProfile.CodecProfiles
105-
if isValid(codecProfile.Codec) and LCase(codecProfile.Codec) = "h264" and isValid(codecProfile.Conditions)
106-
' Check if a Height condition already exists at or below 1080
107-
hasHeightCap = false
108-
for each condition in codecProfile.Conditions
109-
if isValid(condition.Property) and condition.Property = "Height"
110-
if condition.Value.toInt() <= 1080
111-
hasHeightCap = true
112-
end if
113-
end if
114-
end for
115-
116-
if not hasHeightCap
117-
codecProfile.Conditions.push({
118-
"Condition": "LessThanEqual",
119-
"Property": "Height",
120-
"Value": "1080",
121-
"IsRequired": false
122-
})
123-
codecProfile.Conditions.push({
124-
"Condition": "LessThanEqual",
125-
"Property": "Width",
126-
"Value": "1920",
127-
"IsRequired": false
128-
})
129-
end if
120+
if isValid(codecProfile.Codec) and LCase(codecProfile.Codec) = "h264"
121+
applyResolutionCapToProfile(codecProfile, h264CapHeight, h264CapWidth)
130122
end if
131123
end for
132124
end if

docs/source_utils_deviceCapabilities.bs.html

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,10 @@
424424
"SegmentLength": 6
425425
}
426426

427-
' Add height restriction if configured
428-
maxHeightArray = getMaxHeightArray(true)
429-
if maxHeightArray.count() > 0
430-
profile.Conditions = [maxHeightArray]
427+
' Add resolution restriction if configured
428+
resolutionConditions = getResolutionConditions(true)
429+
if resolutionConditions.count() > 0
430+
profile.Conditions = resolutionConditions
431431
end if
432432

433433
transcodingProfiles.push(profile)
@@ -457,7 +457,7 @@
457457
"av1": {}
458458
}
459459
di = CreateObject("roDeviceInfo")
460-
maxHeightArray = getMaxHeightArray()
460+
resolutionConditions = getResolutionConditions()
461461

462462
' ========================================
463463
' DETECT SURROUND PASSTHROUGH SUPPORT
@@ -738,9 +738,7 @@
738738
end if
739739

740740
' set max resolution
741-
if maxHeightArray.count() > 0
742-
h264ProfileArray.Conditions.push(maxHeightArray)
743-
end if
741+
h264ProfileArray.Conditions.Append(resolutionConditions)
744742

745743
' set bitrate restrictions based on user settings
746744
bitRateArray = GetBitRateLimit("h264")
@@ -774,9 +772,7 @@
774772
}
775773

776774
' set max resolution
777-
if maxHeightArray.count() > 0
778-
mpeg2ProfileArray.Conditions.push(maxHeightArray)
779-
end if
775+
mpeg2ProfileArray.Conditions.Append(resolutionConditions)
780776

781777
' set bitrate restrictions based on user settings
782778
bitRateArray = GetBitRateLimit("mpeg2")
@@ -826,9 +822,7 @@
826822
}
827823

828824
' set max resolution
829-
if maxHeightArray.count() > 0
830-
av1ProfileArray.Conditions.push(maxHeightArray)
831-
end if
825+
av1ProfileArray.Conditions.Append(resolutionConditions)
832826

833827
' set bitrate restrictions based on user settings
834828
bitRateArray = GetBitRateLimit("av1")
@@ -891,9 +885,7 @@
891885
end if
892886

893887
' set max resolution
894-
if maxHeightArray.count() > 0
895-
hevcProfileArray.Conditions.push(maxHeightArray)
896-
end if
888+
hevcProfileArray.Conditions.Append(resolutionConditions)
897889

898890
' set bitrate restrictions based on user settings
899891
bitRateArray = GetBitRateLimit("h265")
@@ -931,9 +923,7 @@
931923
}
932924

933925
' set max resolution
934-
if maxHeightArray.count() > 0
935-
vp9ProfileArray.Conditions.push(maxHeightArray)
936-
end if
926+
vp9ProfileArray.Conditions.Append(resolutionConditions)
937927

938928
' set bitrate restrictions based on user settings
939929
bitRateArray = GetBitRateLimit("vp9")
@@ -1026,35 +1016,89 @@
10261016
return {}
10271017
end function
10281018

1029-
function getMaxHeightArray(isRequired = false as boolean) as object
1019+
function getResolutionConditions(isRequired = false as boolean) as object
10301020
userMaxHeight = m.global.user.settings.playbackResolutionMax
10311021
if userMaxHeight = invalid or userMaxHeight = "" then userMaxHeight = "auto"
1032-
if userMaxHeight = "off" then return {}
1022+
if userMaxHeight = "off" then return []
10331023

1034-
deviceMaxHeight = m.global.device.videoHeight
1024+
globalDevice = m.global.device ' cache - accessed twice below
1025+
deviceMaxHeight = globalDevice.videoHeight
10351026

10361027
maxVideoHeight = 1080 ' default to 1080p in case all our validation checks fail
1028+
maxVideoWidth = 1920
10371029

10381030
if userMaxHeight = "auto"
10391031
if isValid(deviceMaxHeight) and deviceMaxHeight <> 0 and deviceMaxHeight > maxVideoHeight
10401032
maxVideoHeight = deviceMaxHeight
1033+
maxVideoWidth = globalDevice.videoWidth ' paired width for device's native video mode
10411034
end if
10421035
else
10431036
userMaxHeight = userMaxHeight.ToInt()
10441037
if isValid(userMaxHeight) and userMaxHeight > 0 and userMaxHeight < maxVideoHeight
10451038
maxVideoHeight = userMaxHeight
1039+
' Settings only stores height, so derive the paired 16:9 width
1040+
' (same standard resolution pairs as SaveDeviceToGlobal in globals.bs)
1041+
heightToWidth = {
1042+
"480": 720,
1043+
"576": 720,
1044+
"720": 1280,
1045+
"1080": 1920,
1046+
"2160": 3840,
1047+
"4320": 7680
1048+
}
1049+
mappedWidth = heightToWidth[maxVideoHeight.toStr()]
1050+
maxVideoWidth = isValid(mappedWidth) ? mappedWidth : int(maxVideoHeight * 16 / 9)
10461051
end if
10471052
end if
10481053

1049-
return {
1054+
return [
1055+
{
1056+
"Condition": "LessThanEqual",
1057+
"Property": "Height",
1058+
"Value": maxVideoHeight.toStr(),
1059+
"IsRequired": isRequired
1060+
},
1061+
{
1062+
"Condition": "LessThanEqual",
1063+
"Property": "Width",
1064+
"Value": maxVideoWidth.toStr(),
1065+
"IsRequired": isRequired
1066+
}
1067+
]
1068+
end function
1069+
1070+
' Apply a paired Height + Width resolution cap to a codec profile's Conditions.
1071+
' No-ops if a Height condition at or below maxHeight already exists.
1072+
' @param codecProfile {object} - The codec profile AA containing a Conditions array
1073+
' @param maxHeight {integer} - The max height to cap at (e.g. 1080)
1074+
' @param maxWidth {integer} - The max width to cap at (e.g. 1920)
1075+
' @param isRequired {boolean} - Whether the condition is required for direct play
1076+
sub applyResolutionCapToProfile(codecProfile as object, maxHeight as integer, maxWidth as integer, isRequired = false as boolean)
1077+
if not isValid(codecProfile) or not isValid(codecProfile.Conditions) then return
1078+
1079+
for each condition in codecProfile.Conditions
1080+
if isValid(condition.Property) and condition.Property = "Height"
1081+
if condition.Value.toInt() <= maxHeight
1082+
return ' Resolution cap already present
1083+
end if
1084+
end if
1085+
end for
1086+
1087+
codecProfile.Conditions.push({
10501088
"Condition": "LessThanEqual",
10511089
"Property": "Height",
1052-
"Value": maxVideoHeight.toStr(),
1090+
"Value": maxHeight.toStr(),
10531091
"IsRequired": isRequired
1054-
}
1055-
end function
1092+
})
1093+
codecProfile.Conditions.push({
1094+
"Condition": "LessThanEqual",
1095+
"Property": "Width",
1096+
"Value": maxWidth.toStr(),
1097+
"IsRequired": isRequired
1098+
})
1099+
end sub
10561100

1057-
' Recieves and returns an assArray of supported profiles and levels for each video codec
1101+
' Receives and returns an assArray of supported profiles and levels for each video codec
10581102
function updateProfileArray(profileArray as object, videoCodec as string, videoProfile as string, profileLevel = "" as string) as object
10591103
' validate params
10601104
if not isValid(profileArray) then return {}

0 commit comments

Comments
 (0)