Skip to content

Commit

Permalink
fix: Pods not sorted after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
echoy-harmonicinc committed Jun 1, 2023
1 parent 39e789e commit 41e0917
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/source/DashParser.bs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DashParser
return invalid
end function

private function parseXml(str as string) as dynamic
private function parseXml(str as dynamic) as dynamic
if str = invalid then return invalid 'if the response is invalid, return invalid
m.mpd = CreateObject("roXMLElement") '
return m.mpd.Parse(str)
Expand Down
37 changes: 37 additions & 0 deletions lib/source/PodHelper.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class PodHelper
function insert(arr, start, el)
res = []
for i = 0 to arr.count() - 1 step 1:
if i = start then res.push(el)
res.push(arr[i])
end for
return res
end function

function binaryInsert(arr, el)
res = []
idx = m.getSortedIndex(arr, el, 0, arr.count() - 1)
if idx >= 0
res = m.insert(arr, idx, el)
else if idx < 0
res = m.insert(arr, idx * -1 - 1, el)
end if
return res
end function

private function getSortedIndex(arr, el, lBound, uBound)
m = lBound
n = uBound
while m <= n
k = (n + m) >> 1
cmp = el.renderTime - arr[k].renderTime
if cmp > 0
m = k + 1
else if cmp < 0
n = k - 1
else return k
end if
end while
return -m - 1
end function
end class
10 changes: 8 additions & 2 deletions lib/source/SSAI.bs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
import "MetadataParser.bs"
import "DashParser.bs"
import "PodHelper.bs"

class RAFX_SSAI
__name__ = "harmonic"
Expand Down Expand Up @@ -35,6 +36,7 @@ class RAFX_SSAI
private rafMetadata = {}
private metadataParser
private dashParser
private podHelper
private logLevel = 0
private roku_ads
private lastPingTime = 0
Expand All @@ -50,6 +52,7 @@ class RAFX_SSAI
sub new()
m.metadataParser = new MetadataParser()
m.dashParser = new DashParser()
m.podHelper = new PodHelper()
m.roku_ads = Roku_Ads()
end sub

Expand Down Expand Up @@ -99,7 +102,6 @@ class RAFX_SSAI
function requestMetadata()
if m.metadataUrl <> invalid
url = not m.timeInRange() ? `${m.metadataUrl}&start=${m.getMpdTime() * 1000}` : m.metadataUrl
print url
r = rokurequests_Requests().get(url)
if r.ok and r.statusCode = 200 and r.headers?.["content-type"] = "application/json" and r.json <> invalid
if r.json.dataRange <> invalid and r.json.dataRange.keys().count() > 0
Expand Down Expand Up @@ -148,7 +150,11 @@ class RAFX_SSAI
for each newPod in newPods.adBreaks
podExist = m.findPodById(current, newPod.id)
if podExist = invalid
current.push(newPod)
if current.count() = 0
current.push(newPod)
else
current = m.podHelper.binaryInsert(current, newPod)
end if
adOpportunities += newPod.ads.count()
end if
end for
Expand Down

0 comments on commit 41e0917

Please sign in to comment.