* Logger

* etag cache fix

* xml refactor

* whitespace

* NodePathUtils

* Http2
This commit is contained in:
Brahim Hadriche authored and GitHub committed 2024-02-05 09:56:22 -05:00
1 parent 44ee6681c5
commit f3aeb58b38
13 files changed
+104 -75

No files matched your search

+5 -1
View File
@@ -15,7 +15,11 @@ function Init()
m.port = port
StartLogger(m.top)
#if DEBUG
StartLogger(m.top, LogLevel.Debug)
#else
StartLogger(m.top, LogLevel.Info)
#end if
end function
function StartLogger(logger as object, logLevel = LogLevel.Info as LogLevel) as void
@@ -8,6 +8,7 @@
</interface>
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/AutoBind.part.brs" />
<script type="text/brightscript" uri="pkg:/components/MainScene_bindings.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/NodePathUtils.brs" />
<script type="text/brightscript" uri="pkg:/components/MainScene.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/LoadingScreen.brs" />
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/OnNodeReadyNoOp.brs" />
@@ -73,11 +73,10 @@ class DashManifest
end if
if xml.Node("AdaptationSet", adaptationSetAttributes)
xml.Node("Role", {
xml.EmptyNode("Role", {
"schemeIdUri": "urn:mpeg:dash:role:2011"
"value": audioSet.acont = "original" ? "main" : "alternate"
})
xml.End()
for i = 0 to audioStreams.Count() - 1
stream = audioStreams[i]
@@ -100,31 +99,23 @@ class DashManifest
"bandwidth": stream.bitrate
})
xml.Node("AudioChannelConfiguration", {
xml.EmptyNode("AudioChannelConfiguration", {
"schemeIdUri": "urn:mpeg:dash:23003:3:audio_channel_configuration:2011"
"value": `${stream.audioChannels}`
})
xml.End()
if xml.Node("BaseURL")
xml.Text(stream.url)
xml.End()
end if
xml.TextNode("BaseURL", stream.url)
if xml.Node("SegmentBase", { "indexRange": stream.index })
xml.EmptyNode("Initialization", { "range": stream.init })
if xml.Node("SegmentBase", {
"indexRange": stream.index
})
if xml.Node("Initialization", {
"range": stream.init
})
xml.End()
end if
xml.End()
end if
xml.End()
end if
end for
xml.End()
end if
@@ -178,14 +169,9 @@ class DashManifest
xml.End()
end if
if xml.Node("SegmentBase", {
"indexRange": stream.index
})
if xml.Node("Initialization", {
"range": stream.init
})
xml.End()
end if
if xml.Node("SegmentBase", { "indexRange": stream.index })
xml.EmptyNode("Initialization", { "range": stream.init })
xml.End()
end if
@@ -249,12 +235,11 @@ class DashManifest
"mimeType": "image/jpeg"
"contentType": "image"
})
xml.Node("SegmentTemplate", {
xml.EmptyNode("SegmentTemplate", {
"media": url
"duration": duration
"startNumber": 0
})
xml.End()
if xml.Node("Representation", {
"id": `thumbnails_${id}`
@@ -263,11 +248,10 @@ class DashManifest
"height": storyboardHeightInPixels
})
xml.Node("EssentialProperty", {
xml.EmptyNode("EssentialProperty", {
"schemeIdUri": "http://dashif.org/guidelines/thumbnail_tile"
"value": `${storyboardWidth}x${storyboardHeight}`
})
xml.End()
xml.End()
end if
@@ -399,11 +383,10 @@ class DashManifest
if videoStream.colorInfo.primaries <> invalid
primaries = m.colorInfo.primaries[videoStream.colorInfo.primaries]
if primaries <> invalid
xml.Node("EssentialProperty", {
xml.EmptyNode("EssentialProperty", {
"schemeIdUri": "urn:mpeg:mpegB:cicp:ColourPrimaries"
"value": primaries
})
xml.End()
else
LogWarn("Unknown colorInfo.primaries:", videoStream.colorInfo.primaries)
end if
@@ -412,11 +395,10 @@ class DashManifest
if videoStream.colorInfo.transferCharacteristics <> invalid
transferCharacteristics = m.colorInfo.transferCharacteristics[videoStream.colorInfo.transferCharacteristics]
if transferCharacteristics <> invalid
xml.Node("EssentialProperty", {
xml.EmptyNode("EssentialProperty", {
"schemeIdUri": "urn:mpeg:mpegB:cicp:TransferCharacteristics"
"value": transferCharacteristics
})
xml.End()
else
LogWarn("Unknown colorInfo.transferCharacteristics:", videoStream.colorInfo.transferCharacteristics)
end if
@@ -425,11 +407,10 @@ class DashManifest
if videoStream.colorInfo.matrixCoefficients <> invalid
matrixCoefficients = m.colorInfo.matrixCoefficients[videoStream.colorInfo.matrixCoefficients]
if matrixCoefficients <> invalid
xml.Node("EssentialProperty", {
xml.EmptyNode("EssentialProperty", {
"schemeIdUri": "urn:mpeg:mpegB:cicp:MatrixCoefficients"
"value": matrixCoefficients
})
xml.End()
else
LogWarn("Unknown colorInfo.matrixCoefficients:", videoStream.colorInfo.matrixCoefficients)
end if
@@ -174,7 +174,7 @@ namespace Http
function SetState(newState as Http.HttpConnectionState)
if m.state <> newState
LogDebug(m, "state change" + Stri(m.state) + " ->" + Stri(newState))
LogDebug("state change" + Stri(m.state) + " ->" + Stri(newState))
m.state = newState
end if
end function
@@ -58,11 +58,11 @@ namespace Http
m.http_code = errcode
buffer = `<html><head><title>${errcode} ${errname}</title></head><body>
<h1>${errname}</h1>
${reason}
<hr>
${m.GeneratedBy()}
</body></html>`
<h1>${errname}</h1>
${reason}
<hr>
${m.GeneratedBy()}
</body></html>`
m.SetBodyDataString(buffer)
m.ContentType("text/html")
@@ -11,6 +11,11 @@ namespace Http
return false
end if
cacheControl = response.headers["Cache-Control"]
if IsString(cacheControl) and cacheControl.instr("no-cache") <> -1
return false
end if
etag = response.headers["ETag"]
if not StringUtils.IsNullOrEmpty(etag)
return false
@@ -42,6 +47,11 @@ namespace Http
return false
end if
cacheControl = response.headers["Cache-Control"]
if IsString(cacheControl) and cacheControl.instr("no-cache") <> -1
return false
end if
etag = response.headers["ETag"]
if not StringUtils.IsNullOrEmpty(etag)
return false
@@ -1,3 +1,5 @@
import "pkg:/source/utils/NodePathUtils.bs"
' Bind all nodes that registered for auto-binding
' Should be called once from a root node
' Can be called later to rebind nodes that were added after the first call
@@ -35,7 +37,7 @@ function BindNodeFieldsAndProps(_unused as dynamic) as void
if node.getField(fieldId) <> invalid
continue for
end if
reference = FindNodeFromPath(node, bindings.fields[fieldId])
reference = NodePathUtils.FindNodeFromPath(node, bindings.fields[fieldId])
if reference <> invalid
node[fieldId] = reference
end if
@@ -54,7 +56,7 @@ function BindNodeFieldsAndProps(_unused as dynamic) as void
if child.getField(childPropId) <> invalid
continue for
end if
reference = FindNodeFromPath(child, childProps[childPropId])
reference = NodePathUtils.FindNodeFromPath(child, childProps[childPropId])
if reference <> invalid
child[childPropId] = reference
end if
@@ -63,38 +65,6 @@ function BindNodeFieldsAndProps(_unused as dynamic) as void
end if
end function
function FindNodeFromPath(root as object, path as string) as object
node = root
if path.StartsWith("/")
node = node.getScene()
path = path.Mid(1)
end if
pathParts = path.Tokenize("/")
for i = 0 to pathParts.Count() - 1
if node = invalid
return invalid
end if
if pathParts[i] = "."
continue for
end if
if pathParts[i] = ".."
node = node.getParent()
continue for
end if
node = node.findNode(pathParts[i])
end for
if root.isSameNode(node)
' if a node is referencing itself, it's probably a mistake
return invalid
end if
return node
end function
' Create scoped fields (m.fieldName) for all fields in this node
' To be called after BindNodeFieldsAndProps
function BindScopeFields(_unused as dynamic)
@@ -12,6 +12,7 @@
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/tests/AutoBindNode1_bindings.brs" />
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/tests/AutoBindNode1.brs" />
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/OnNodeReadyNoOp.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/NodePathUtils.brs" />
<script type="text/brightscript" uri="pkg:/source/bslib.brs" />
<children>
<AutoBindNode2 id="AutoBindNode2" />
@@ -10,6 +10,7 @@
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/tests/AutoBindNode1Container_bindings.brs" />
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/tests/AutoBindNode1Container.brs" />
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/OnNodeReadyNoOp.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/NodePathUtils.brs" />
<script type="text/brightscript" uri="pkg:/source/bslib.brs" />
<children>
<AutoBindNode1 id="AutoBindNode1" reference2=".." />
@@ -12,6 +12,7 @@
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/tests/AutoBindNode2_bindings.brs" />
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/tests/AutoBindNode2.brs" />
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/OnNodeReadyNoOp.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/NodePathUtils.brs" />
<script type="text/brightscript" uri="pkg:/source/bslib.brs" />
</component>
<!--//# sourceMappingURL=./AutoBindNode2.xml.map -->
@@ -242,6 +242,11 @@ namespace HttpClient
return m
end function
function UseHttp2() as HttpRequest
m._useHttp2 = true
return m
end function
function Cancellation(cancellation as object) as HttpRequest
m._cancellation = cancellation
return m
@@ -261,6 +266,10 @@ namespace HttpClient
command += ` \\\n --compressed`
end if
if m._useHttp2 = true
command += ` \\\n --http2`
end if
if m._headers <> invalid
for each key in m._headers
command += ` \\\n -H '${key}: ${m._headers[key]}'`
@@ -489,6 +498,11 @@ namespace HttpClient
urlTransfer.SetCertificatesFile("common:/certs/ca-bundle.crt")
urlTransfer.InitClientCertificates()
end if
if m._useHttp2 = true
urlTransfer.SetHttpVersion("http2")
end if
return urlTransfer
end function
@@ -32,6 +32,17 @@ class XmlObject
end if
end function
function TextNode(name as string, text as string, attributes = invalid as object)
m.Node(name, attributes)
m.Text(text)
m.End()
end function
function EmptyNode(name as string, attributes = invalid as object)
m.Node(name, attributes)
m.End()
end function
function End()
m.stack.pop()
end function
@@ -0,0 +1,35 @@
namespace NodePathUtils
function FindNodeFromPath(root as object, path as string) as object
node = root
if path.StartsWith("/")
node = node.getScene()
path = path.Mid(1)
end if
pathParts = path.Tokenize("/")
for i = 0 to pathParts.Count() - 1
if node = invalid
return invalid
end if
if pathParts[i] = "."
continue for
end if
if pathParts[i] = ".."
node = node.getParent()
continue for
end if
node = node.findNode(pathParts[i])
end for
if root.isSameNode(node)
' if a node is referencing itself, it's probably a mistake
return invalid
end if
return node
end function
end namespace