Skip to content

Commit 8ab45cf

Browse files
committed
save local refs to global to reduce deep copies
1 parent 73203fa commit 8ab45cf

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

source/utils/deviceCapabilities.brs

+44-35
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,24 @@ sub PostDeviceProfile()
5959
end sub
6060

6161
function getDeviceProfile() as object
62+
globalDevice = m.global.device
6263
return {
6364
"Name": "Official Roku Client",
64-
"Id": m.global.device.id,
65+
"Id": globalDevice.id,
6566
"Identification": {
66-
"FriendlyName": m.global.device.friendlyName,
67-
"ModelNumber": m.global.device.model,
67+
"FriendlyName": globalDevice.friendlyName,
68+
"ModelNumber": globalDevice.model,
6869
"SerialNumber": "string",
69-
"ModelName": m.global.device.name,
70-
"ModelDescription": "Type: " + m.global.device.modelType,
71-
"Manufacturer": m.global.device.modelDetails.VendorName
70+
"ModelName": globalDevice.name,
71+
"ModelDescription": "Type: " + globalDevice.modelType,
72+
"Manufacturer": globalDevice.modelDetails.VendorName
7273
},
73-
"FriendlyName": m.global.device.friendlyName,
74-
"Manufacturer": m.global.device.modelDetails.VendorName,
75-
"ModelName": m.global.device.name,
76-
"ModelDescription": "Type: " + m.global.device.modelType,
77-
"ModelNumber": m.global.device.model,
78-
"SerialNumber": m.global.device.serial,
74+
"FriendlyName": globalDevice.friendlyName,
75+
"Manufacturer": globalDevice.modelDetails.VendorName,
76+
"ModelName": globalDevice.name,
77+
"ModelDescription": "Type: " + globalDevice.modelType,
78+
"ModelNumber": globalDevice.model,
79+
"SerialNumber": globalDevice.serial,
7980
"MaxStreamingBitrate": 120000000,
8081
"MaxStaticBitrate": 100000000,
8182
"MusicStreamingTranscodingBitrate": 192000,
@@ -88,6 +89,7 @@ function getDeviceProfile() as object
8889
end function
8990

9091
function GetDirectPlayProfiles() as object
92+
globalUserSettings = m.global.session.user.settings
9193
directPlayProfiles = []
9294
di = CreateObject("roDeviceInfo")
9395
' all possible containers
@@ -122,7 +124,7 @@ function GetDirectPlayProfiles() as object
122124
audioCodecs = ["mp3", "mp2", "pcm", "lpcm", "wav", "ac3", "ac4", "aiff", "wma", "flac", "alac", "aac", "opus", "dts", "wmapro", "vorbis", "eac3", "mpg123"]
123125

124126
' check if hevc is disabled
125-
if m.global.session.user.settings["playback.compatibility.disablehevc"] = false
127+
if globalUserSettings["playback.compatibility.disablehevc"] = false
126128
videoCodecs.push("hevc")
127129
end if
128130

@@ -142,12 +144,12 @@ function GetDirectPlayProfiles() as object
142144
end for
143145

144146
' user setting overrides
145-
if m.global.session.user.settings["playback.mpeg4"]
147+
if globalUserSettings["playback.mpeg4"]
146148
for each container in supportedCodecs
147149
supportedCodecs[container]["video"].push("mpeg4")
148150
end for
149151
end if
150-
if m.global.session.user.settings["playback.mpeg2"]
152+
if globalUserSettings["playback.mpeg2"]
151153
for each container in supportedCodecs
152154
supportedCodecs[container]["video"].push("mpeg2video")
153155
end for
@@ -208,6 +210,7 @@ function GetDirectPlayProfiles() as object
208210
end function
209211

210212
function getTranscodingProfiles() as object
213+
globalUserSettings = m.global.session.user.settings
211214
transcodingProfiles = []
212215

213216
di = CreateObject("roDeviceInfo")
@@ -224,7 +227,7 @@ function getTranscodingProfiles() as object
224227
' in order of preference from left to right
225228
audioCodecs = ["mp3", "vorbis", "opus", "flac", "alac", "ac4", "pcm", "wma", "wmapro"]
226229
surroundSoundCodecs = ["eac3", "ac3", "dts"]
227-
if m.global.session.user.settings["playback.forceDTS"] = true
230+
if globalUserSettings["playback.forceDTS"] = true
228231
surroundSoundCodecs = ["dts", "eac3", "ac3"]
229232
end if
230233

@@ -275,7 +278,7 @@ function getTranscodingProfiles() as object
275278
end for
276279

277280
' HEVC / h265
278-
if m.global.session.user.settings["playback.compatibility.disablehevc"] = false
281+
if globalUserSettings["playback.compatibility.disablehevc"] = false
279282
for each container in transcodingContainers
280283
if di.CanDecodeVideo({ Codec: "hevc", Container: container }).Result
281284
if container = "mp4"
@@ -317,7 +320,7 @@ function getTranscodingProfiles() as object
317320
end for
318321

319322
' MPEG2
320-
if m.global.session.user.settings["playback.mpeg2"]
323+
if globalUserSettings["playback.mpeg2"]
321324
for each container in transcodingContainers
322325
if di.CanDecodeVideo({ Codec: "mpeg2", Container: container }).Result
323326
if container = "mp4"
@@ -425,7 +428,7 @@ function getTranscodingProfiles() as object
425428
}
426429

427430
' apply max res to transcoding profile
428-
if m.global.session.user.settings["playback.resolution.max"] <> "off"
431+
if globalUserSettings["playback.resolution.max"] <> "off"
429432
tsArray.Conditions = [getMaxHeightArray(), getMaxWidthArray()]
430433
mp4Array.Conditions = [getMaxHeightArray(), getMaxWidthArray()]
431434
end if
@@ -477,6 +480,7 @@ function getContainerProfiles() as object
477480
end function
478481

479482
function getCodecProfiles() as object
483+
globalUserSettings = m.global.session.user.settings
480484
codecProfiles = []
481485
profileSupport = {
482486
"h264": {},
@@ -487,7 +491,7 @@ function getCodecProfiles() as object
487491
"mpeg2": {},
488492
"av1": {}
489493
}
490-
maxResSetting = m.global.session.user.settings["playback.resolution.max"]
494+
maxResSetting = globalUserSettings["playback.resolution.max"]
491495
di = CreateObject("roDeviceInfo")
492496
maxHeightArray = getMaxHeightArray()
493497
maxWidthArray = getMaxWidthArray()
@@ -662,7 +666,7 @@ function getCodecProfiles() as object
662666
}
663667

664668
' check user setting before adding video level restrictions
665-
if not m.global.session.user.settings["playback.tryDirect.h264ProfileLevel"]
669+
if not globalUserSettings["playback.tryDirect.h264ProfileLevel"]
666670
h264ProfileArray.Conditions.push({
667671
"Condition": "LessThanEqual",
668672
"Property": "VideoLevel",
@@ -672,7 +676,7 @@ function getCodecProfiles() as object
672676
end if
673677

674678
' set max resolution
675-
if m.global.session.user.settings["playback.resolution.mode"] = "everything" and maxResSetting <> "off"
679+
if globalUserSettings["playback.resolution.mode"] = "everything" and maxResSetting <> "off"
676680
h264ProfileArray.Conditions.push(maxHeightArray)
677681
h264ProfileArray.Conditions.push(maxWidthArray)
678682
end if
@@ -687,7 +691,7 @@ function getCodecProfiles() as object
687691

688692
' MPEG2
689693
' NOTE: the mpeg2 levels are being saved in the profileSupport array as if they were profiles
690-
if m.global.session.user.settings["playback.mpeg2"]
694+
if globalUserSettings["playback.mpeg2"]
691695
mpeg2Levels = []
692696
for each level in profileSupport["mpeg2"]
693697
if not arrayHasValue(mpeg2Levels, level)
@@ -709,7 +713,7 @@ function getCodecProfiles() as object
709713
}
710714

711715
' set max resolution
712-
if m.global.session.user.settings["playback.resolution.mode"] = "everything" and maxResSetting <> "off"
716+
if globalUserSettings["playback.resolution.mode"] = "everything" and maxResSetting <> "off"
713717
mpeg2ProfileArray.Conditions.push(maxHeightArray)
714718
mpeg2ProfileArray.Conditions.push(maxWidthArray)
715719
end if
@@ -762,7 +766,7 @@ function getCodecProfiles() as object
762766
}
763767

764768
' set max resolution
765-
if m.global.session.user.settings["playback.resolution.mode"] = "everything" and maxResSetting <> "off"
769+
if globalUserSettings["playback.resolution.mode"] = "everything" and maxResSetting <> "off"
766770
av1ProfileArray.Conditions.push(maxHeightArray)
767771
av1ProfileArray.Conditions.push(maxWidthArray)
768772
end if
@@ -776,7 +780,7 @@ function getCodecProfiles() as object
776780
codecProfiles.push(av1ProfileArray)
777781
end if
778782

779-
if not m.global.session.user.settings["playback.compatibility.disablehevc"] and di.CanDecodeVideo({ Codec: "hevc" }).Result
783+
if not globalUserSettings["playback.compatibility.disablehevc"] and di.CanDecodeVideo({ Codec: "hevc" }).Result
780784
hevcLevelSupported = 0.0
781785
hevcAssProfiles = {}
782786

@@ -821,7 +825,7 @@ function getCodecProfiles() as object
821825
}
822826

823827
' check user setting before adding VideoLevel restrictions
824-
if not m.global.session.user.settings["playback.tryDirect.hevcProfileLevel"]
828+
if not globalUserSettings["playback.tryDirect.hevcProfileLevel"]
825829
hevcProfileArray.Conditions.push({
826830
"Condition": "LessThanEqual",
827831
"Property": "VideoLevel",
@@ -831,7 +835,7 @@ function getCodecProfiles() as object
831835
end if
832836

833837
' set max resolution
834-
if m.global.session.user.settings["playback.resolution.mode"] = "everything" and maxResSetting <> "off"
838+
if globalUserSettings["playback.resolution.mode"] = "everything" and maxResSetting <> "off"
835839
hevcProfileArray.Conditions.push(maxHeightArray)
836840
hevcProfileArray.Conditions.push(maxWidthArray)
837841
end if
@@ -890,7 +894,7 @@ function getCodecProfiles() as object
890894
}
891895

892896
' set max resolution
893-
if m.global.session.user.settings["playback.resolution.mode"] = "everything" and maxResSetting <> "off"
897+
if globalUserSettings["playback.resolution.mode"] = "everything" and maxResSetting <> "off"
894898
vp9ProfileArray.Conditions.push(maxHeightArray)
895899
vp9ProfileArray.Conditions.push(maxWidthArray)
896900
end if
@@ -931,8 +935,9 @@ function getSubtitleProfiles() as object
931935
end function
932936

933937
function GetBitRateLimit(codec as string) as object
934-
if m.global.session.user.settings["playback.bitrate.maxlimited"] = true
935-
userSetLimit = m.global.session.user.settings["playback.bitrate.limit"].ToInt()
938+
globalUserSettings = m.global.session.user.settings
939+
if globalUserSettings["playback.bitrate.maxlimited"]
940+
userSetLimit = globalUserSettings["playback.bitrate.limit"].ToInt()
936941
if isValid(userSetLimit) and type(userSetLimit) = "Integer" and userSetLimit > 0
937942
userSetLimit *= 1000000
938943
return {
@@ -984,13 +989,15 @@ function GetBitRateLimit(codec as string) as object
984989
end function
985990

986991
function getMaxHeightArray() as object
987-
maxResSetting = m.global.session.user.settings["playback.resolution.max"]
992+
myGlobal = m.global
993+
994+
maxResSetting = myGlobal.session.user.settings["playback.resolution.max"]
988995
if maxResSetting = "off" then return {}
989996

990997
maxVideoHeight = maxResSetting
991998

992999
if maxResSetting = "auto"
993-
maxVideoHeight = m.global.device.videoHeight
1000+
maxVideoHeight = myGlobal.device.videoHeight
9941001
end if
9951002

9961003
return {
@@ -1002,13 +1009,15 @@ function getMaxHeightArray() as object
10021009
end function
10031010

10041011
function getMaxWidthArray() as object
1005-
maxResSetting = m.global.session.user.settings["playback.resolution.max"]
1012+
myGlobal = m.global
1013+
1014+
maxResSetting = myGlobal.session.user.settings["playback.resolution.max"]
10061015
if maxResSetting = "off" then return {}
10071016

10081017
maxVideoWidth = invalid
10091018

10101019
if maxResSetting = "auto"
1011-
maxVideoWidth = m.global.device.videoWidth
1020+
maxVideoWidth = myGlobal.device.videoWidth
10121021
else if maxResSetting = "360"
10131022
maxVideoWidth = "480"
10141023
else if maxResSetting = "480"

0 commit comments

Comments
 (0)