2023-08-31 23:02:39 +00:00
import "pkg:/source/utils/misc.brs"
2020-05-31 10:57:41 +00:00
'Device Capabilities for Roku.
2020-07-11 07:52:52 +00:00
'This will likely need further tweaking
2020-05-31 10:57:41 +00:00
function getDeviceCapabilities() as object
return {
2021-07-09 20:08:32 +00:00
"PlayableMediaTypes": [
"Audio",
2023-06-01 03:19:03 +00:00
"Video",
"Photo"
2021-07-09 20:08:32 +00:00
],
"SupportedCommands": [],
2023-06-01 04:38:31 +00:00
"SupportsPersistentIdentifier": false,
2021-07-09 20:08:32 +00:00
"SupportsMediaControl": false,
"DeviceProfile": getDeviceProfile()
}
2020-05-31 10:57:41 +00:00
end function
2023-05-27 20:43:05 +00:00
' Send Device Profile information to server
sub PostDeviceProfile()
2023-06-01 03:19:03 +00:00
profile = getDeviceCapabilities()
2023-05-27 20:43:05 +00:00
req = APIRequest("/Sessions/Capabilities/Full")
req.SetRequest("POST")
2023-06-01 03:19:03 +00:00
print "profile =", profile
print "profile.DeviceProfile =", profile.DeviceProfile
print "profile.DeviceProfile.CodecProfiles ="
for each prof in profile.DeviceProfile.CodecProfiles
print prof
for each cond in prof.Conditions
print cond
end for
end for
print "profile.DeviceProfile.ContainerProfiles =", profile.DeviceProfile.ContainerProfiles
print "profile.DeviceProfile.DirectPlayProfiles ="
for each prof in profile.DeviceProfile.DirectPlayProfiles
print prof
end for
print "profile.DeviceProfile.SubtitleProfiles ="
for each prof in profile.DeviceProfile.SubtitleProfiles
print prof
end for
print "profile.DeviceProfile.TranscodingProfiles ="
for each prof in profile.DeviceProfile.TranscodingProfiles
print prof
end for
print "profile.PlayableMediaTypes =", profile.PlayableMediaTypes
print "profile.SupportedCommands =", profile.SupportedCommands
postJson(req, FormatJson(profile))
2023-05-27 20:43:05 +00:00
end sub
2020-05-31 10:57:41 +00:00
function getDeviceProfile() as object
2023-06-01 12:43:27 +00:00
playMpeg2 = m.global.session.user.settings["playback.mpeg2"]
playAv1 = m.global.session.user.settings["playback.av1"]
2023-06-01 03:19:03 +00:00
di = CreateObject("roDeviceInfo")
2023-06-06 04:24:54 +00:00
' TRANSCODING
' use strings to preserve order
mp4AudioCodecs = "aac"
mp4VideoCodecs = "h264"
tsAudioCodecs = "aac"
tsVideoCodecs = "h264"
' profileSupport["mp4"]["hevc"]["profile name"]["profile level"]
profileSupport = {
mp4: {},
ts: {}
}
' does the users setup support surround sound?
maxAudioChannels = "2" ' jellyfin expects this as a string
' in order of preference from left to right
audioCodecs = ["mp3", "vorbis", "opus", "flac", "alac", "ac4", "pcm", "wma", "wmapro"]
2023-09-01 13:53:36 +00:00
surroundSoundCodecs = ["eac3", "ac3", "dts"]
2023-09-01 14:26:08 +00:00
if m.global.session.user.settings["playback.forceDTS"] = true
surroundSoundCodecs = ["dts", "eac3", "ac3"]
end if
2023-06-06 04:24:54 +00:00
surroundSoundCodec = invalid
2023-06-03 03:47:16 +00:00
if di.GetAudioOutputChannel() = "5.1 surround"
maxAudioChannels = "6"
2023-06-06 04:24:54 +00:00
for each codec in surroundSoundCodecs
if di.CanDecodeAudio({ Codec: codec, ChCnt: 6 }).Result
surroundSoundCodec = codec
if di.CanDecodeAudio({ Codec: codec, ChCnt: 8 }).Result
maxAudioChannels = "8"
end if
2023-06-03 03:47:16 +00:00
exit for
end if
end for
end if
2023-06-06 04:24:54 +00:00
' VIDEO CODECS
'
' AVC / h264 / MPEG4 AVC
2023-06-02 04:37:22 +00:00
h264Profiles = ["main", "high"]
h264Levels = ["4.1", "4.2"]
2023-06-06 04:24:54 +00:00
for each container in profileSupport
2023-06-02 04:37:22 +00:00
for each profile in h264Profiles
for each level in h264Levels
if di.CanDecodeVideo({ Codec: "h264", Container: container, Profile: profile, Level: level }).Result
2023-06-06 04:24:54 +00:00
profileSupport[container] = updateProfileArray(profileSupport[container], "h264", profile, level)
end if
if di.CanDecodeVideo({ Codec: "mpeg4 avc", Container: container, Profile: profile, Level: level }).Result
profileSupport[container] = updateProfileArray(profileSupport[container], "mpeg4 avc", profile, level)
if container = "mp4"
' check for codec string before adding it
if mp4VideoCodecs.Instr(0, ",mpeg4 avc") = -1
mp4VideoCodecs = mp4VideoCodecs + ",mpeg4 avc"
end if
else if container = "ts"
' check for codec string before adding it
if tsVideoCodecs.Instr(0, ",mpeg4 avc") = -1
tsVideoCodecs = tsVideoCodecs + ",mpeg4 avc"
end if
2023-06-02 04:37:22 +00:00
end if
end if
end for
end for
end for
2023-06-01 03:19:03 +00:00
2023-06-02 04:37:22 +00:00
' HEVC / h265
hevcProfiles = ["main", "main 10"]
hevcLevels = ["4.1", "5.0", "5.1"]
2023-06-06 04:24:54 +00:00
addHevc = false
for each container in profileSupport
2023-06-01 03:19:03 +00:00
for each profile in hevcProfiles
for each level in hevcLevels
2023-06-02 04:37:22 +00:00
if di.CanDecodeVideo({ Codec: "hevc", Container: container, Profile: profile, Level: level }).Result
2023-06-06 04:24:54 +00:00
addHevc = true
profileSupport[container] = updateProfileArray(profileSupport[container], "hevc", profile, level)
profileSupport[container] = updateProfileArray(profileSupport[container], "h265", profile, level)
if container = "mp4"
' check for codec string before adding it
if mp4VideoCodecs.Instr(0, "h265,") = -1
mp4VideoCodecs = "h265," + mp4VideoCodecs
end if
if mp4VideoCodecs.Instr(0, "hevc,") = -1
mp4VideoCodecs = "hevc," + mp4VideoCodecs
end if
else if container = "ts"
' check for codec string before adding it
if tsVideoCodecs.Instr(0, "h265,") = -1
tsVideoCodecs = "h265," + tsVideoCodecs
end if
if tsVideoCodecs.Instr(0, "hevc,") = -1
tsVideoCodecs = "hevc," + tsVideoCodecs
end if
2023-06-02 04:37:22 +00:00
end if
2023-06-06 04:24:54 +00:00
end if
end for
end for
end for
' VP9
vp9Profiles = ["profile 0", "profile 2"]
addVp9 = false
for each container in profileSupport
for each profile in vp9Profiles
if di.CanDecodeAudio({ Codec: "vp9", Container: container, Profile: profile }).Result
addVp9 = true
profileSupport[container] = updateProfileArray(profileSupport[container], "vp9", profile)
if container = "mp4"
' check for codec string before adding it
if mp4VideoCodecs.Instr(0, ",vp9") = -1
mp4VideoCodecs = mp4VideoCodecs + ",vp9"
2023-06-02 04:37:22 +00:00
end if
2023-06-06 04:24:54 +00:00
else if container = "ts"
' check for codec string before adding it
if tsVideoCodecs.Instr(0, ",vp9") = -1
tsVideoCodecs = tsVideoCodecs + ",vp9"
2023-06-01 03:19:03 +00:00
end if
2023-06-02 04:37:22 +00:00
end if
2023-06-06 04:24:54 +00:00
end if
2023-06-02 04:37:22 +00:00
end for
end for
2023-06-01 03:19:03 +00:00
2023-06-02 04:37:22 +00:00
' MPEG2
2023-08-18 01:51:59 +00:00
' mpeg2 uses levels with no profiles. see https://developer.roku.com/en-ca/docs/references/brightscript/interfaces/ifdeviceinfo.md#candecodevideovideo_format-as-object-as-object
' NOTE: the mpeg2 levels are being saved in the profileSupport array as if they were profiles
mpeg2Levels = ["main", "high"]
2023-06-06 04:24:54 +00:00
addMpeg2 = false
2023-06-02 04:37:22 +00:00
if playMpeg2
2023-06-06 04:24:54 +00:00
for each container in profileSupport
2023-08-18 01:51:59 +00:00
for each level in mpeg2Levels
if di.CanDecodeVideo({ Codec: "mpeg2", Container: container, Level: level }).Result
2023-06-06 04:24:54 +00:00
addMpeg2 = true
2023-08-18 01:51:59 +00:00
profileSupport[container] = updateProfileArray(profileSupport[container], "mpeg2", level)
2023-06-06 04:24:54 +00:00
if container = "mp4"
' check for codec string before adding it
if mp4VideoCodecs.Instr(0, ",mpeg2video") = -1
mp4VideoCodecs = mp4VideoCodecs + ",mpeg2video"
end if
else if container = "ts"
' check for codec string before adding it
if tsVideoCodecs.Instr(0, ",mpeg2video") = -1
tsVideoCodecs = tsVideoCodecs + ",mpeg2video"
end if
2023-06-02 04:37:22 +00:00
end if
2023-06-01 03:19:03 +00:00
end if
end for
end for
2023-06-02 04:37:22 +00:00
end if
2023-06-01 03:19:03 +00:00
2023-06-02 04:37:22 +00:00
' AV1
av1Profiles = ["main", "main 10"]
av1Levels = ["4.1", "5.0", "5.1"]
2023-06-06 04:24:54 +00:00
addAv1 = false
2023-06-02 04:37:22 +00:00
if playAv1
2023-06-06 04:24:54 +00:00
for each container in profileSupport
2023-06-02 04:37:22 +00:00
for each profile in av1Profiles
for each level in av1Levels
if di.CanDecodeVideo({ Codec: "av1", Container: container, Profile: profile, Level: level }).Result
2023-06-06 04:24:54 +00:00
addAv1 = true
profileSupport[container] = updateProfileArray(profileSupport[container], "av1", profile, level)
if container = "mp4"
' check for codec string before adding it
if mp4VideoCodecs.Instr(0, ",av1") = -1
mp4VideoCodecs = mp4VideoCodecs + ",av1"
end if
else if container = "ts"
' check for codec string before adding it
if tsVideoCodecs.Instr(0, ",av1") = -1
tsVideoCodecs = tsVideoCodecs + ",av1"
end if
2023-06-02 04:37:22 +00:00
end if
end if
end for
end for
end for
end if
2023-06-06 04:24:54 +00:00
' AUDIO CODECS
for each container in profileSupport
for each codec in audioCodecs
if di.CanDecodeAudio({ Codec: codec, Container: container }).result
if container = "mp4"
2023-06-06 04:42:33 +00:00
mp4AudioCodecs = mp4AudioCodecs + "," + codec
2023-06-06 04:24:54 +00:00
else if container = "ts"
2023-06-06 04:42:33 +00:00
tsAudioCodecs = tsAudioCodecs + "," + codec
2023-06-02 04:37:22 +00:00
end if
2023-06-01 03:19:03 +00:00
end if
2023-06-02 04:37:22 +00:00
end for
end for
2023-06-06 04:24:54 +00:00
' HDR SUPPORT
h264VideoRangeTypes = "SDR"
2022-07-07 19:58:01 +00:00
hevcVideoRangeTypes = "SDR"
vp9VideoRangeTypes = "SDR"
av1VideoRangeTypes = "SDR"
dp = di.GetDisplayProperties()
2023-06-06 04:24:54 +00:00
if dp.Hdr10
2022-10-16 10:45:53 +00:00
hevcVideoRangeTypes = hevcVideoRangeTypes + "|HDR10"
vp9VideoRangeTypes = vp9VideoRangeTypes + "|HDR10"
av1VideoRangeTypes = av1VideoRangeTypes + "|HDR10"
2022-07-07 19:58:01 +00:00
end if
2023-06-06 04:24:54 +00:00
if dp.Hdr10Plus
av1VideoRangeTypes = av1VideoRangeTypes + "|HDR10+"
end if
2022-07-07 19:58:01 +00:00
if dp.HLG
2022-10-16 10:45:53 +00:00
hevcVideoRangeTypes = hevcVideoRangeTypes + "|HLG"
vp9VideoRangeTypes = vp9VideoRangeTypes + "|HLG"
av1VideoRangeTypes = av1VideoRangeTypes + "|HLG"
2022-07-07 19:58:01 +00:00
end if
if dp.DolbyVision
2023-08-31 00:02:35 +00:00
h264VideoRangeTypes = h264VideoRangeTypes + "|DOVI"
2022-10-16 10:45:53 +00:00
hevcVideoRangeTypes = hevcVideoRangeTypes + "|DOVI"
2022-07-07 19:58:01 +00:00
'vp9VideoRangeTypes = vp9VideoRangeTypes + ",DOVI" no evidence that vp9 can hold DOVI
2022-10-16 10:45:53 +00:00
av1VideoRangeTypes = av1VideoRangeTypes + "|DOVI"
2022-07-07 19:58:01 +00:00
end if
2022-10-16 10:45:53 +00:00
2021-10-12 07:13:25 +00:00
DirectPlayProfile = GetDirectPlayProfiles()
2021-08-24 01:21:15 +00:00
2022-10-16 10:45:53 +00:00
deviceProfile = {
2020-05-31 10:57:41 +00:00
"MaxStreamingBitrate": 120000000,
"MaxStaticBitrate": 100000000,
"MusicStreamingTranscodingBitrate": 192000,
2021-10-12 07:13:25 +00:00
"DirectPlayProfiles": DirectPlayProfile,
2023-06-02 04:37:22 +00:00
"TranscodingProfiles": [],
2020-05-31 10:57:41 +00:00
"ContainerProfiles": [],
"CodecProfiles": [
2023-06-06 04:24:54 +00:00
' {
' "Type": "VideoAudio",
' "Codec": DirectPlayProfile[1].AudioCodec, ' Use supported MKV Audio list
' "Conditions": [
' {
' "Condition": "LessThanEqual",
' "Property": "AudioChannels",
' "Value": maxAudioChannels,
' "IsRequired": false
' }
' ]
' }
2020-05-31 10:57:41 +00:00
],
"SubtitleProfiles": [
{
"Format": "vtt",
"Method": "External"
},
{
2020-07-11 07:52:52 +00:00
"Format": "srt",
2020-05-31 10:57:41 +00:00
"Method": "External"
},
{
2020-07-11 07:52:52 +00:00
"Format": "ttml",
2020-05-31 10:57:41 +00:00
"Method": "External"
2022-03-29 19:54:46 +00:00
},
{
"Format": "sub",
"Method": "External"
2020-05-31 10:57:41 +00:00
}
2020-07-11 07:52:52 +00:00
]
}
2023-06-02 04:37:22 +00:00
' build TranscodingProfiles
2023-06-06 04:24:54 +00:00
'
2023-09-01 13:53:36 +00:00
' add mp3 to TranscodingProfile for music
2023-08-30 19:06:33 +00:00
deviceProfile.TranscodingProfiles.push({
"Container": "mp3",
"Type": "Audio",
"AudioCodec": "mp3",
"Context": "Streaming",
"Protocol": "http",
2023-09-01 13:53:36 +00:00
"MaxAudioChannels": "2"
2023-08-30 19:06:33 +00:00
})
deviceProfile.TranscodingProfiles.push({
"Container": "mp3",
"Type": "Audio",
"AudioCodec": "mp3",
"Context": "Static",
"Protocol": "http",
2023-09-01 13:53:36 +00:00
"MaxAudioChannels": "2"
2023-08-30 19:06:33 +00:00
})
2023-09-01 13:53:36 +00:00
' add aac to TranscodingProfile for stereo audio
2023-08-30 19:06:33 +00:00
deviceProfile.TranscodingProfiles.push({
2023-09-01 13:53:36 +00:00
"Container": "ts",
2023-08-30 19:06:33 +00:00
"Type": "Audio",
2023-09-01 13:53:36 +00:00
"AudioCodec": "aac",
2023-08-30 19:06:33 +00:00
"Context": "Streaming",
"Protocol": "http",
2023-09-01 13:53:36 +00:00
"MaxAudioChannels": "2"
2023-08-30 19:06:33 +00:00
})
deviceProfile.TranscodingProfiles.push({
2023-09-01 13:53:36 +00:00
"Container": "ts",
2023-08-30 19:06:33 +00:00
"Type": "Audio",
2023-09-01 13:53:36 +00:00
"AudioCodec": "aac",
2023-08-30 19:06:33 +00:00
"Context": "Static",
"Protocol": "http",
2023-09-01 13:53:36 +00:00
"MaxAudioChannels": "2"
2023-08-30 19:06:33 +00:00
})
2023-06-02 04:37:22 +00:00
2023-06-06 04:24:54 +00:00
tsArray = {
"Container": "ts",
"Context": "Streaming",
"Protocol": "hls",
"Type": "Video",
"AudioCodec": tsAudioCodecs,
"VideoCodec": tsVideoCodecs,
"MaxAudioChannels": maxAudioChannels,
"MinSegments": 1,
"BreakOnNonKeyFrames": false
}
mp4Array = {
"Container": "mp4",
"Context": "Streaming",
"Protocol": "hls",
"Type": "Video",
"AudioCodec": mp4AudioCodecs,
"VideoCodec": mp4VideoCodecs,
"MaxAudioChannels": maxAudioChannels,
"MinSegments": 1,
"BreakOnNonKeyFrames": false
}
' surround sound
2023-08-30 19:06:33 +00:00
if surroundSoundCodec <> invalid
2023-09-01 13:53:36 +00:00
' add preferred surround sound codec to TranscodingProfile
deviceProfile.TranscodingProfiles.push({
"Container": surroundSoundCodec,
"Type": "Audio",
"AudioCodec": surroundSoundCodec,
"Context": "Streaming",
"Protocol": "http",
"MaxAudioChannels": maxAudioChannels
})
deviceProfile.TranscodingProfiles.push({
"Container": surroundSoundCodec,
"Type": "Audio",
"AudioCodec": surroundSoundCodec,
"Context": "Static",
"Protocol": "http",
"MaxAudioChannels": maxAudioChannels
})
' put codec in front of AudioCodec string
if tsArray.AudioCodec = ""
tsArray.AudioCodec = surroundSoundCodec
else
tsArray.AudioCodec = surroundSoundCodec + "," + tsArray.AudioCodec
2023-06-06 04:24:54 +00:00
end if
2023-06-06 04:42:33 +00:00
2023-09-01 13:53:36 +00:00
if mp4Array.AudioCodec = ""
mp4Array.AudioCodec = surroundSoundCodec
else
mp4Array.AudioCodec = surroundSoundCodec + "," + mp4Array.AudioCodec
end if
2023-06-06 04:24:54 +00:00
end if
deviceProfile.TranscodingProfiles.push(tsArray)
deviceProfile.TranscodingProfiles.push(mp4Array)
' Build CodecProfiles
2023-09-01 16:45:00 +00:00
' max resolution
maxResSetting = m.global.session.user.settings["playback.resolution"]
maxVideoHeight = invalid
maxVideoWidth = invalid
maxVideoHeight = maxResSetting
if maxResSetting = "auto"
maxVideoHeight = m.global.device.videoHeight
maxVideoWidth = m.global.device.videoWidth
2023-09-01 19:56:20 +00:00
else if maxResSetting <> "off"
if maxResSetting = "360"
maxVideoWidth = "480"
else if maxResSetting = "480"
maxVideoWidth = "640"
else if maxResSetting = "720"
maxVideoWidth = "1280"
else if maxResSetting = "1080"
maxVideoWidth = "1920"
else if maxResSetting = "2160"
maxVideoWidth = "3840"
else if maxResSetting = "4320"
maxVideoWidth = "7680"
end if
2023-09-01 16:45:00 +00:00
end if
maxVideoHeightArray = {
"Condition": "LessThanEqual",
"Property": "Width",
"Value": maxVideoWidth,
"IsRequired": true
}
maxVideoWidthArray = {
"Condition": "LessThanEqual",
"Property": "Height",
"Value": maxVideoHeight,
"IsRequired": true
}
2023-06-06 04:24:54 +00:00
' H264
h264Mp4LevelSupported = 0.0
h264TsLevelSupported = 0.0
h264AssProfiles = {}
h264LevelString = invalid
for each container in profileSupport
for each profile in profileSupport[container]["h264"]
h264AssProfiles.AddReplace(profile, true)
for each level in profileSupport[container]["h264"][profile]
levelFloat = level.ToFloat()
if container = "mp4"
if levelFloat > h264Mp4LevelSupported
h264Mp4LevelSupported = levelFloat
2023-06-03 03:47:16 +00:00
end if
2023-06-06 04:24:54 +00:00
else if container = "ts"
if levelFloat > h264TsLevelSupported
h264TsLevelSupported = levelFloat
end if
end if
2023-06-02 04:37:22 +00:00
end for
end for
2023-06-06 04:24:54 +00:00
end for
2023-06-02 04:37:22 +00:00
2023-06-06 04:24:54 +00:00
h264LevelString = h264Mp4LevelSupported
if h264TsLevelSupported > h264Mp4LevelSupported
h264LevelString = h264TsLevelSupported
end if
' convert to string
h264LevelString = h264LevelString.ToStr()
' remove decimals
h264LevelString = removeDecimals(h264LevelString)
2023-06-03 03:47:16 +00:00
2023-06-06 04:24:54 +00:00
codecProfileArray = {
"Type": "Video",
"Codec": "h264",
"Conditions": [
{
"Condition": "NotEquals",
"Property": "IsAnamorphic",
"Value": "true",
"IsRequired": false
},
{
"Condition": "EqualsAny",
"Property": "VideoProfile",
"Value": h264AssProfiles.Keys().join("|"),
"IsRequired": false
},
{
"Condition": "EqualsAny",
"Property": "VideoRangeType",
"Value": h264VideoRangeTypes,
"IsRequired": false
}
2023-09-01 16:45:00 +00:00
2023-06-06 04:24:54 +00:00
]
}
2023-09-01 16:45:00 +00:00
' set max resolution
if maxResSetting <> "off"
codecProfileArray.Conditions.push(maxVideoHeightArray)
codecProfileArray.Conditions.push(maxVideoWidthArray)
end if
2023-09-01 14:26:08 +00:00
' check user setting before adding video level restrictions
if not m.global.session.user.settings["playback.tryDirect.h264ProfileLevel"]
codecProfileArray.Conditions.push({
"Condition": "LessThanEqual",
"Property": "VideoLevel",
"Value": h264LevelString,
"IsRequired": false
})
end if
2023-09-01 15:53:54 +00:00
' set bitrate restrictions based on user settings
2023-06-06 04:24:54 +00:00
bitRateArray = GetBitRateLimit("h264")
if bitRateArray.count() > 0
codecProfileArray.Conditions.push(bitRateArray)
2023-06-02 04:37:22 +00:00
end if
2023-09-01 15:53:54 +00:00
2023-06-06 04:24:54 +00:00
deviceProfile.CodecProfiles.push(codecProfileArray)
2023-06-03 03:47:16 +00:00
2023-06-06 04:24:54 +00:00
' MPEG2
2023-08-18 01:51:59 +00:00
' NOTE: the mpeg2 levels are being saved in the profileSupport array as if they were profiles
2023-06-06 04:24:54 +00:00
if addMpeg2
2023-06-02 04:37:22 +00:00
mpeg2Levels = []
2023-06-06 04:24:54 +00:00
for each container in profileSupport
for each level in profileSupport[container]["mpeg2"]
2023-09-03 14:48:40 +00:00
if not arrayHasValue(mpeg2Levels, level)
2023-06-06 04:24:54 +00:00
mpeg2Levels.push(level)
2023-06-02 04:37:22 +00:00
end if
2023-06-06 04:24:54 +00:00
end for
2023-06-02 04:37:22 +00:00
end for
2023-06-03 03:47:16 +00:00
codecProfileArray = {
2023-06-01 03:19:03 +00:00
"Type": "Video",
"Codec": "mpeg2",
"Conditions": [
{
"Condition": "EqualsAny",
"Property": "VideoLevel",
2023-06-02 04:37:22 +00:00
"Value": mpeg2Levels.join("|"),
2023-06-01 03:19:03 +00:00
"IsRequired": false
2023-09-01 16:45:00 +00:00
}
2023-06-01 03:19:03 +00:00
]
2023-06-03 03:47:16 +00:00
}
2023-09-01 15:53:54 +00:00
2023-09-01 16:45:00 +00:00
' set max resolution
if maxResSetting <> "off"
codecProfileArray.Conditions.push(maxVideoHeightArray)
codecProfileArray.Conditions.push(maxVideoWidthArray)
end if
2023-09-01 15:53:54 +00:00
' set bitrate restrictions based on user settings
2023-06-03 03:47:16 +00:00
bitRateArray = GetBitRateLimit("mpeg2")
if bitRateArray.count() > 0
codecProfileArray.Conditions.push(bitRateArray)
end if
2023-09-01 15:53:54 +00:00
2023-06-03 03:47:16 +00:00
deviceProfile.CodecProfiles.push(codecProfileArray)
2023-06-01 03:19:03 +00:00
end if
2023-06-02 04:37:22 +00:00
2023-06-06 04:24:54 +00:00
if addAv1
av1Mp4LevelSupported = 0.0
av1TsLevelSupported = 0.0
av1AssProfiles = []
av1HighestLevel = 0.0
for each container in profileSupport
for each profile in profileSupport[container]["av1"]
av1AssProfiles.AddReplace(profile, true)
for each level in profileSupport[container]["av1"][profile]
2023-06-03 03:47:16 +00:00
levelFloat = level.ToFloat()
2023-06-06 04:24:54 +00:00
if container = "mp4"
if levelFloat > av1Mp4LevelSupported
av1Mp4LevelSupported = levelFloat
end if
else if container = "ts"
if levelFloat > av1TsLevelSupported
av1TsLevelSupported = levelFloat
end if
2023-06-03 03:47:16 +00:00
end if
end for
2023-06-02 04:37:22 +00:00
end for
end for
2023-06-06 04:24:54 +00:00
av1HighestLevel = av1Mp4LevelSupported
if av1TsLevelSupported > av1Mp4LevelSupported
av1HighestLevel = av1TsLevelSupported
end if
2023-06-03 03:47:16 +00:00
codecProfileArray = {
2022-10-16 10:45:53 +00:00
"Type": "Video",
"Codec": "av1",
"Conditions": [
2023-06-02 04:37:22 +00:00
{
"Condition": "EqualsAny",
"Property": "VideoProfile",
2023-06-06 04:24:54 +00:00
"Value": av1AssProfiles.Keys().join("|"),
2023-06-02 04:37:22 +00:00
"IsRequired": false
},
2022-10-16 10:45:53 +00:00
{
"Condition": "EqualsAny",
"Property": "VideoRangeType",
"Value": av1VideoRangeTypes,
"IsRequired": false
2022-12-19 00:15:10 +00:00
},
2023-06-02 04:37:22 +00:00
{
"Condition": "LessThanEqual",
"Property": "VideoLevel",
2023-06-06 04:24:54 +00:00
"Value": (120 * av1HighestLevel).ToStr(),
2023-06-02 04:37:22 +00:00
"IsRequired": false
2023-09-01 16:45:00 +00:00
}
2022-10-16 10:45:53 +00:00
]
2023-06-03 03:47:16 +00:00
}
2023-09-01 15:53:54 +00:00
2023-09-01 16:45:00 +00:00
' set max resolution
if maxResSetting <> "off"
codecProfileArray.Conditions.push(maxVideoHeightArray)
codecProfileArray.Conditions.push(maxVideoWidthArray)
end if
2023-09-01 15:53:54 +00:00
' set bitrate restrictions based on user settings
2023-06-03 03:47:16 +00:00
bitRateArray = GetBitRateLimit("av1")
if bitRateArray.count() > 0
codecProfileArray.Conditions.push(bitRateArray)
end if
2023-09-01 15:53:54 +00:00
2023-06-03 03:47:16 +00:00
deviceProfile.CodecProfiles.push(codecProfileArray)
2022-07-07 20:13:30 +00:00
end if
2023-06-02 04:37:22 +00:00
2023-06-06 04:24:54 +00:00
if addHevc
hevcMp4LevelSupported = 0.0
hevcTsLevelSupported = 0.0
hevcAssProfiles = {}
hevcHighestLevel = 0.0
for each container in profileSupport
for each profile in profileSupport[container]["hevc"]
hevcAssProfiles.AddReplace(profile, true)
for each level in profileSupport[container]["hevc"][profile]
2023-06-03 03:47:16 +00:00
levelFloat = level.ToFloat()
2023-06-06 04:24:54 +00:00
if container = "mp4"
if levelFloat > hevcMp4LevelSupported
hevcMp4LevelSupported = levelFloat
end if
else if container = "ts"
if levelFloat > hevcTsLevelSupported
hevcTsLevelSupported = levelFloat
end if
2023-06-03 03:47:16 +00:00
end if
end for
2023-06-02 04:37:22 +00:00
end for
end for
2023-06-06 04:24:54 +00:00
hevcHighestLevel = hevcMp4LevelSupported
if hevcTsLevelSupported > hevcMp4LevelSupported
hevcHighestLevel = hevcTsLevelSupported
end if
2023-06-03 03:47:16 +00:00
hevcLevelString = "120"
2023-06-06 04:24:54 +00:00
if hevcHighestLevel = 5.1
2023-06-03 03:47:16 +00:00
hevcLevelString = "153"
end if
codecProfileArray = {
2022-10-16 10:45:53 +00:00
"Type": "Video",
"Codec": "hevc",
"Conditions": [
2023-06-03 03:47:16 +00:00
{
"Condition": "NotEquals",
"Property": "IsAnamorphic",
"Value": "true",
"IsRequired": false
},
2022-10-16 10:45:53 +00:00
{
"Condition": "EqualsAny",
"Property": "VideoProfile",
2023-06-06 04:24:54 +00:00
"Value": profileSupport["ts"]["hevc"].Keys().join("|"),
2022-10-16 10:45:53 +00:00
"IsRequired": false
},
{
"Condition": "EqualsAny",
"Property": "VideoRangeType",
"Value": hevcVideoRangeTypes,
"IsRequired": false
2023-09-01 16:45:00 +00:00
}
2022-10-16 10:45:53 +00:00
]
2023-06-03 03:47:16 +00:00
}
2023-06-06 04:24:54 +00:00
2023-09-01 16:45:00 +00:00
' set max resolution
if maxResSetting <> "off"
codecProfileArray.Conditions.push(maxVideoHeightArray)
codecProfileArray.Conditions.push(maxVideoWidthArray)
end if
2023-09-01 14:26:08 +00:00
' check user setting before adding VideoLevel restrictions
if not m.global.session.user.settings["playback.tryDirect.hevcProfileLevel"]
codecProfileArray.Conditions.push({
"Condition": "LessThanEqual",
"Property": "VideoLevel",
"Value": hevcLevelString,
"IsRequired": false
})
end if
2023-09-01 15:53:54 +00:00
' set bitrate restrictions based on user settings
2023-06-03 03:47:16 +00:00
bitRateArray = GetBitRateLimit("h265")
if bitRateArray.count() > 0
codecProfileArray.Conditions.push(bitRateArray)
end if
2023-09-01 15:53:54 +00:00
2023-06-03 03:47:16 +00:00
deviceProfile.CodecProfiles.push(codecProfileArray)
2022-07-07 20:13:30 +00:00
end if
2023-06-02 04:37:22 +00:00
2023-06-06 04:24:54 +00:00
if addVp9
vp9Profiles = []
for each container in profileSupport
for each profile in profileSupport[container]["vp9"]
if vp9Profiles[profile] = invalid
vp9Profiles.push(profile)
end if
end for
2023-06-02 04:37:22 +00:00
end for
2023-06-03 03:47:16 +00:00
codecProfileArray = {
2022-10-16 10:45:53 +00:00
"Type": "Video",
"Codec": "vp9",
"Conditions": [
2023-06-02 04:37:22 +00:00
{
"Condition": "EqualsAny",
2023-06-06 04:24:54 +00:00
"Property": "VideoLevel",
"Value": vp9Profiles.join("|"),
2023-06-02 04:37:22 +00:00
"IsRequired": false
},
2022-10-16 10:45:53 +00:00
{
"Condition": "EqualsAny",
"Property": "VideoRangeType",
"Value": vp9VideoRangeTypes,
"IsRequired": false
2023-09-01 16:45:00 +00:00
}
2022-10-16 10:45:53 +00:00
]
2023-06-03 03:47:16 +00:00
}
2023-06-06 04:24:54 +00:00
2023-09-01 16:45:00 +00:00
' set max resolution
if maxResSetting <> "off"
codecProfileArray.Conditions.push(maxVideoHeightArray)
codecProfileArray.Conditions.push(maxVideoWidthArray)
end if
2023-09-01 15:53:54 +00:00
' set bitrate restrictions based on user settings
2023-06-03 03:47:16 +00:00
bitRateArray = GetBitRateLimit("vp9")
if bitRateArray.count() > 0
codecProfileArray.Conditions.push(bitRateArray)
end if
2023-09-01 15:53:54 +00:00
2023-06-03 03:47:16 +00:00
deviceProfile.CodecProfiles.push(codecProfileArray)
2022-07-07 19:58:01 +00:00
end if
2022-10-16 10:45:53 +00:00
2022-07-07 19:58:01 +00:00
return deviceProfile
2020-07-11 07:52:52 +00:00
end function
function GetDirectPlayProfiles() as object
di = CreateObject("roDeviceInfo")
2023-06-01 04:35:08 +00:00
' all possible containers
supportedCodecs = {
mp4: {
audio: [],
video: []
},
2023-06-02 04:37:22 +00:00
hls: {
2023-06-01 04:35:08 +00:00
audio: [],
video: []
},
2023-06-02 04:37:22 +00:00
mkv: {
2023-06-01 04:35:08 +00:00
audio: [],
video: []
},
2023-06-02 04:37:22 +00:00
ism: {
2023-06-01 04:35:08 +00:00
audio: [],
video: []
},
2023-06-02 04:37:22 +00:00
dash: {
audio: [],
video: []
},
ts: {
2023-06-01 04:35:08 +00:00
audio: [],
video: []
}
}
' all possible codecs
2023-09-01 00:04:11 +00:00
videoCodecs = ["h264", "mpeg4 avc", "vp8", "hevc", "vp9", "av1", "h263", "mpeg1"]
audioCodecs = ["mp3", "mp2", "pcm", "lpcm", "wav", "ac3", "ac4", "aiff", "wma", "flac", "alac", "aac", "opus", "dts", "wmapro", "vorbis", "eac3", "mpg123"]
2023-06-01 04:35:08 +00:00
' check video codecs for each container
for each container in supportedCodecs
for each videoCodec in videoCodecs
if di.CanDecodeVideo({ Codec: videoCodec, Container: container }).Result
if videoCodec = "hevc"
supportedCodecs[container]["video"].push("hevc")
supportedCodecs[container]["video"].push("h265")
else
' device profile string matches codec string
supportedCodecs[container]["video"].push(videoCodec)
end if
end if
end for
end for
2023-08-31 23:02:39 +00:00
2023-09-01 00:04:11 +00:00
' user setting overrides
2023-08-31 02:51:47 +00:00
if m.global.session.user.settings["playback.mpeg4"]
for each container in supportedCodecs
2023-09-03 14:48:40 +00:00
supportedCodecs[container]["video"].push("mpeg4")
end for
end if
if m.global.session.user.settings["playback.mpeg2"]
for each container in supportedCodecs
supportedCodecs[container]["video"].push("mpeg2video")
2023-08-31 02:51:47 +00:00
end for
end if
2023-06-03 03:47:16 +00:00
2023-06-01 04:35:08 +00:00
' check audio codecs for each container
for each container in supportedCodecs
for each audioCodec in audioCodecs
if di.CanDecodeAudio({ Codec: audioCodec, Container: container }).Result
supportedCodecs[container]["audio"].push(audioCodec)
end if
end for
end for
2023-06-03 03:47:16 +00:00
2023-06-01 04:35:08 +00:00
' check audio codecs with no container
supportedAudio = []
for each audioCodec in audioCodecs
if di.CanDecodeAudio({ Codec: audioCodec }).Result
supportedAudio.push(audioCodec)
end if
end for
2023-06-03 03:47:16 +00:00
2023-06-02 04:37:22 +00:00
' build return array
2023-06-01 04:35:08 +00:00
returnArray = []
for each container in supportedCodecs
2023-06-01 04:37:04 +00:00
videoCodecString = supportedCodecs[container]["video"].Join(",")
if videoCodecString <> ""
2023-06-03 03:47:16 +00:00
containerString = container
2023-06-02 04:37:22 +00:00
if container = "mp4"
containerString = "mp4,mov,m4v"
else if container = "mkv"
containerString = "mkv,webm"
end if
2023-06-03 03:47:16 +00:00
2023-06-01 04:35:08 +00:00
returnArray.push({
2023-06-02 04:37:22 +00:00
"Container": containerString,
2023-06-01 04:35:08 +00:00
"Type": "Video",
2023-06-01 04:37:04 +00:00
"VideoCodec": videoCodecString,
2023-06-01 04:35:08 +00:00
"AudioCodec": supportedCodecs[container]["audio"].Join(",")
})
end if
end for
2020-07-11 07:52:52 +00:00
2023-06-01 04:35:08 +00:00
returnArray.push({
"Container": supportedAudio.Join(","),
"Type": "Audio"
})
return returnArray
2022-03-28 19:40:34 +00:00
end function
2023-01-25 13:44:26 +00:00
2023-06-02 04:37:22 +00:00
function GetBitRateLimit(codec as string) as object
2023-06-01 12:43:27 +00:00
if m.global.session.user.settings["playback.bitrate.maxlimited"] = true
2023-09-01 19:56:20 +00:00
userSetLimit = m.global.session.user.settings["playback.bitrate.limit"].ToInt()
2023-06-02 14:40:30 +00:00
if isValid(userSetLimit) and type(userSetLimit) = "Integer" and userSetLimit > 0
userSetLimit *= 1000000
2023-01-26 03:25:22 +00:00
return {
"Condition": "LessThanEqual",
"Property": "VideoBitrate",
2023-02-04 13:54:39 +00:00
"Value": userSetLimit.ToStr(),
2023-06-01 03:19:03 +00:00
"IsRequired": true
2023-01-26 03:25:22 +00:00
}
2023-02-04 13:54:39 +00:00
else
2023-06-02 04:37:22 +00:00
codec = Lcase(codec)
2023-02-04 13:54:39 +00:00
' Some repeated values (e.g. same "40mbps" for several codecs)
' but this makes it easy to update in the future if the bitrates start to deviate.
2023-06-02 04:37:22 +00:00
if codec = "h264"
2023-02-04 13:54:39 +00:00
' Roku only supports h264 up to 10Mpbs
return {
"Condition": "LessThanEqual",
"Property": "VideoBitrate",
"Value": "10000000",
2023-06-01 03:19:03 +00:00
"IsRequired": true
2023-02-04 13:54:39 +00:00
}
2023-06-02 04:37:22 +00:00
else if codec = "av1"
2023-02-04 13:54:39 +00:00
' Roku only supports AV1 up to 40Mpbs
return {
"Condition": "LessThanEqual",
"Property": "VideoBitrate",
"Value": "40000000",
2023-06-01 03:19:03 +00:00
"IsRequired": true
2023-02-04 13:54:39 +00:00
}
2023-06-02 04:37:22 +00:00
else if codec = "h265"
2023-02-04 13:54:39 +00:00
' Roku only supports h265 up to 40Mpbs
return {
"Condition": "LessThanEqual",
"Property": "VideoBitrate",
"Value": "40000000",
2023-06-01 03:19:03 +00:00
"IsRequired": true
2023-02-04 13:54:39 +00:00
}
2023-06-02 04:37:22 +00:00
else if codec = "vp9"
2023-02-04 13:54:39 +00:00
' Roku only supports VP9 up to 40Mpbs
return {
"Condition": "LessThanEqual",
"Property": "VideoBitrate",
"Value": "40000000",
2023-06-01 03:19:03 +00:00
"IsRequired": true
2023-02-04 13:54:39 +00:00
}
end if
2023-01-26 03:25:22 +00:00
end if
2023-01-25 13:44:26 +00:00
end if
return {}
end function
2023-06-06 04:24:54 +00:00
' Recieves and returns an assArray of supported profiles and levels for each video codec
function updateProfileArray(profileArray as object, videoCodec as string, videoProfile as string, profileLevel = "" as string) as object
' validate params
if profileArray = invalid then return {}
if videoCodec = "" or videoProfile = "" then return profileArray
if profileArray[videoCodec] = invalid
profileArray[videoCodec] = {}
end if
if profileArray[videoCodec][videoProfile] = invalid
profileArray[videoCodec][videoProfile] = {}
end if
' add profileLevel if a value was provided
if profileLevel <> ""
if profileArray[videoCodec][videoProfile][profileLevel] = invalid
profileArray[videoCodec][videoProfile].AddReplace(profileLevel, true)
end if
end if
' profileSupport[container][codec][profile][level]
return profileArray
end function
' Remove all decimals from a string
function removeDecimals(value as string) as string
r = CreateObject("roRegex", "\.", "")
value = r.ReplaceAll(value, "")
return value
end function