247 lines
12 KiB
Plaintext
247 lines
12 KiB
Plaintext
import "pkg:/components/Services/Dash/DashManifest.bs"
|
|
|
|
namespace Tests
|
|
|
|
@suite
|
|
class DashManifestTests extends Rooibos.BaseTestSuite
|
|
|
|
@describe("DashManifest.ProxyFormatsThroughInvidious")
|
|
|
|
@it("routes each url through the instance, keeping the original host as a param")
|
|
function _()
|
|
manifest = new DashManifest("https://inv.example")
|
|
proxied = manifest.ProxyFormatsThroughInvidious([{ itag: "137", url: "https://rr1.googlevideo.com/videoplayback?id=abc" }])
|
|
m.assertEqual(proxied[0].url, "https://inv.example/videoplayback?id=abc&host=rr1.googlevideo.com")
|
|
m.assertEqual(proxied[0].itag, "137")
|
|
end function
|
|
|
|
@it("leaves the source formats untouched, so a second pass routes the same")
|
|
function _()
|
|
manifest = new DashManifest("https://inv.example")
|
|
formats = [{ itag: "137", url: "https://rr1.googlevideo.com/videoplayback?id=abc" }]
|
|
first = manifest.ProxyFormatsThroughInvidious(formats)
|
|
second = manifest.ProxyFormatsThroughInvidious(formats)
|
|
m.assertEqual(formats[0].url, "https://rr1.googlevideo.com/videoplayback?id=abc")
|
|
m.assertEqual(second[0].url, first[0].url)
|
|
end function
|
|
|
|
@it("passes formats without a url through")
|
|
function _()
|
|
manifest = new DashManifest("https://inv.example")
|
|
proxied = manifest.ProxyFormatsThroughInvidious([{ itag: "140" }])
|
|
m.assertEqual(proxied.Count(), 1)
|
|
m.assertEqual(proxied[0].itag, "140")
|
|
m.assertInvalid(proxied[0].url)
|
|
end function
|
|
|
|
@describe("DashManifest.FromVideoMetadata DRM")
|
|
|
|
function DrmFormat(itag as string, mimeType as string, drmFamilies as dynamic) as object
|
|
format = {
|
|
itag: itag
|
|
url: `https://rr1.googlevideo.com/videoplayback?itag=${itag}`
|
|
type: mimeType
|
|
bitrate: 1000000
|
|
init: "0-700"
|
|
index: "701-900"
|
|
}
|
|
if mimeType.startsWith("video")
|
|
format.width = 1920
|
|
format.height = 1080
|
|
end if
|
|
if drmFamilies <> invalid
|
|
format.drmFamilies = drmFamilies
|
|
end if
|
|
return format
|
|
end function
|
|
|
|
' Each audio/video AdaptationSet as { reps: its Representation ids, drm: its ContentProtection schemeIdUris }.
|
|
function DrmAdaptationSets(formats as object) as object
|
|
manifest = new DashManifest("")
|
|
xml = CreateObject("roXMLElement")
|
|
xml.Parse(manifest.FromVideoMetadata({ videoId: "v", lengthSeconds: 100, isPostLiveDvr: false, adaptiveFormats: formats, storyboards: [] }, {}, false))
|
|
sets = []
|
|
for each adaptationSet in xml.GetNamedElements("Period").GetNamedElements("AdaptationSet")
|
|
contentType = adaptationSet@contentType
|
|
if contentType <> "audio" and contentType <> "video"
|
|
continue for
|
|
end if
|
|
reps = []
|
|
for each representation in adaptationSet.GetNamedElements("Representation")
|
|
reps.Push(representation@id)
|
|
end for
|
|
drm = []
|
|
for each contentProtection in adaptationSet.GetNamedElements("ContentProtection")
|
|
drm.Push(contentProtection@schemeIdUri)
|
|
end for
|
|
sets.Push({ reps: reps, drm: drm })
|
|
end for
|
|
return sets
|
|
end function
|
|
|
|
@it("leaves out formats whose only DRM is FairPlay, and keeps the formats without DRM")
|
|
function _()
|
|
sets = m.DrmAdaptationSets([
|
|
m.DrmFormat("137", `video/mp4; codecs="avc1.640028"`, ["WIDEVINE", "PLAYREADY"])
|
|
m.DrmFormat("399", `video/mp4; codecs="vp09.00.40.08.00.01.01.01.00"`, ["FAIRPLAY"])
|
|
m.DrmFormat("140", `audio/mp4; codecs="mp4a.40.2"`, ["WIDEVINE", "PLAYREADY"])
|
|
m.DrmFormat("141", `audio/mp4; codecs="mp4a.40.2"`, ["FAIRPLAY"])
|
|
m.DrmFormat("136", `video/mp4; codecs="avc1.4D401F"`, invalid)
|
|
])
|
|
reps = []
|
|
for each adaptationSet in sets
|
|
reps.Append(adaptationSet.reps)
|
|
end for
|
|
reps.Sort()
|
|
m.assertEqual(reps, ["136", "137", "140"])
|
|
end function
|
|
|
|
@it("marks each set with the DRM systems its formats carry")
|
|
function _()
|
|
widevine = "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
|
|
playready = "urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95"
|
|
sets = m.DrmAdaptationSets([
|
|
m.DrmFormat("140", `audio/mp4; codecs="mp4a.40.2"`, ["WIDEVINE", "PLAYREADY"])
|
|
m.DrmFormat("139", `audio/mp4; codecs="mp4a.40.5"`, ["WIDEVINE"])
|
|
m.DrmFormat("136", `video/mp4; codecs="avc1.4D401F"`, invalid)
|
|
])
|
|
drmByRep = {}
|
|
for each adaptationSet in sets
|
|
m.assertEqual(adaptationSet.reps.Count(), 1)
|
|
drmByRep[adaptationSet.reps[0]] = adaptationSet.drm
|
|
end for
|
|
m.assertEqual(drmByRep["140"], [widevine, playready])
|
|
m.assertEqual(drmByRep["139"], [widevine])
|
|
m.assertEqual(drmByRep["136"], [])
|
|
end function
|
|
|
|
@describe("DashManifest.FillLiveManifest")
|
|
|
|
' The filled startNumber, <S> entries ({ t, d, r }) and now.
|
|
function FillTemplate(headSeqnum as integer, firstSeqnum = 100 as integer, windowSegments = 10 as integer, durationRuns = invalid as dynamic) as object
|
|
if durationRuns = invalid
|
|
durationRuns = [{ fromSeqnum: firstSeqnum, startMs: 250, durationMs: 5000 }]
|
|
end if
|
|
manifest = new DashManifest("")
|
|
template = `${LIVE_START_NUMBER_TOKEN}|${LIVE_SEGMENTS_TOKEN}|${LIVE_NOW_TOKEN}`
|
|
parts = manifest.FillLiveManifest(template, headSeqnum, durationRuns, windowSegments * durationRuns[0].durationMs).Split("|")
|
|
entries = []
|
|
for each match in CreateObject("roRegex", "<S t=.(\d+). d=.(\d+). r=.(\d+). />", "").MatchAll(parts[1])
|
|
entries.Push({ t: match[1].ToInt(), d: match[2].ToInt(), r: match[3].ToInt() })
|
|
end for
|
|
return { startNumber: parts[0].ToInt(), s: entries, now: parts[2] }
|
|
end function
|
|
|
|
@it("grows a young stream's list from its first segment")
|
|
function _()
|
|
atLoad = m.FillTemplate(3, 0, 8640)
|
|
m.assertEqual(atLoad.startNumber, 0)
|
|
m.assertEqual(atLoad.s[0].r, 2)
|
|
later = m.FillTemplate(50, 0, 8640)
|
|
m.assertEqual(later.startNumber, 0)
|
|
m.assertEqual(later.s[0].t, 250)
|
|
m.assertEqual(later.s[0].r, 49)
|
|
end function
|
|
|
|
@it("lists the window behind the head at load: from the first segment to head - 1")
|
|
function _()
|
|
filled = m.FillTemplate(109)
|
|
m.assertEqual(filled.startNumber, 100)
|
|
m.assertEqual(filled.s, [{ t: 250, d: 5000, r: 8 }])
|
|
end function
|
|
|
|
@it("slides startNumber and S@t together as the head advances")
|
|
function _()
|
|
filled = m.FillTemplate(115)
|
|
m.assertEqual(filled.startNumber, 105)
|
|
m.assertEqual(filled.s, [{ t: 5 * 5000 + 250, d: 5000, r: 9 }])
|
|
end function
|
|
|
|
@it("still lists the head when it is the first segment: an empty timeline isn't expressible")
|
|
function _()
|
|
filled = m.FillTemplate(100)
|
|
m.assertEqual(filled.startNumber, 100)
|
|
m.assertEqual(filled.s[0].r, 0)
|
|
end function
|
|
|
|
@it("starts sliding exactly when a young stream's list fills the window")
|
|
function _()
|
|
full = m.FillTemplate(10, 0, 10)
|
|
m.assertEqual(full.startNumber, 0)
|
|
m.assertEqual(full.s[0].r, 9)
|
|
sliding = m.FillTemplate(11, 0, 10)
|
|
m.assertEqual(sliding.startNumber, 1)
|
|
m.assertEqual(sliding.s, [{ t: 5000 + 250, d: 5000, r: 9 }])
|
|
end function
|
|
|
|
@it("lists segments past a re-measured duration with it, keeping the earlier ones' times")
|
|
function _()
|
|
filled = m.FillTemplate(20, 0, 33230, [{ fromSeqnum: 0, startMs: 250, durationMs: 1300 }, { fromSeqnum: 10, startMs: 13250, durationMs: 2000 }])
|
|
m.assertEqual(filled.startNumber, 0)
|
|
m.assertEqual(filled.s, [{ t: 250, d: 1300, r: 9 }, { t: 13250, d: 2000, r: 9 }])
|
|
end function
|
|
|
|
@it("keeps a gap before a run that starts past the previous one's end")
|
|
function _()
|
|
' segments 0-9 end at 13250; segment 10 realigned to 20250
|
|
runs = [{ fromSeqnum: 0, startMs: 250, durationMs: 1300 }, { fromSeqnum: 10, startMs: 20250, durationMs: 2000 }]
|
|
filled = m.FillTemplate(15, 0, 33230, runs)
|
|
m.assertEqual(filled.s, [{ t: 250, d: 1300, r: 9 }, { t: 20250, d: 2000, r: 4 }])
|
|
' a time inside the gap (13250-20250) maps to the run after it
|
|
manifest = new DashManifest("")
|
|
m.assertEqual(manifest.LiveSegmentAtOrAfter(runs, 18250), 10)
|
|
m.assertEqual(manifest.LiveSegmentAtOrAfter(runs, 13000), 10)
|
|
m.assertEqual(manifest.LiveSegmentAtOrAfter(runs, 11000), 9)
|
|
end function
|
|
|
|
@it("slides by time over mixed durations: the list never spans more than the window")
|
|
function _()
|
|
' window 10 x 1000 ms; segments 0-4 at 1000, 5+ at 2000; head 12 lists up to 11
|
|
filled = m.FillTemplate(12, 0, 10, [{ fromSeqnum: 0, startMs: 250, durationMs: 1000 }, { fromSeqnum: 5, startMs: 5250, durationMs: 2000 }])
|
|
m.assertEqual(filled.startNumber, 7)
|
|
m.assertEqual(filled.s, [{ t: 250 + 5 * 1000 + 2 * 2000, d: 2000, r: 4 }])
|
|
end function
|
|
|
|
@it("fills every placeholder, with the current time as now")
|
|
function _()
|
|
filled = m.FillTemplate(109)
|
|
m.assertEqual(filled.now.Instr("{{"), -1)
|
|
now = CreateObject("roDateTime")
|
|
stamped = CreateObject("roDateTime")
|
|
stamped.FromISO8601String(filled.now)
|
|
m.assertTrue(Abs(now.AsSeconds() - stamped.AsSeconds()) <= 1)
|
|
end function
|
|
|
|
@describe("DashManifest.FormatDuration")
|
|
|
|
@it("formats milliseconds as an xs:duration")
|
|
function _()
|
|
manifest = new DashManifest("")
|
|
m.assertEqual(manifest.FormatDuration(0), "PT0.000S")
|
|
m.assertEqual(manifest.FormatDuration(999), "PT0.999S")
|
|
m.assertEqual(manifest.FormatDuration(1500), "PT1.500S")
|
|
m.assertEqual(manifest.FormatDuration(10000), "PT10.000S")
|
|
m.assertEqual(manifest.FormatDuration(17900000123&), "PT17900000.123S")
|
|
end function
|
|
|
|
@describe("DashManifest.GetDurationMs")
|
|
|
|
@it("returns a post-live DVR duration past 32 bits")
|
|
function _()
|
|
manifest = new DashManifest("")
|
|
m.assertEqual(manifest.GetDurationMs({ isPostLiveDvr: true, postLiveDvrDurationMs: 17900000123& }), 17900000123&)
|
|
end function
|
|
|
|
@it("falls back to the first format's approxDurationMs, then to lengthSeconds")
|
|
function _()
|
|
manifest = new DashManifest("")
|
|
m.assertEqual(manifest.GetDurationMs({ adaptiveFormats: [{ approxDurationMs: "17900000123" }], lengthSeconds: 60 }), 17900000123&)
|
|
m.assertEqual(manifest.GetDurationMs({ adaptiveFormats: [{ approxDurationMs: "0" }], lengthSeconds: 60 }), 60000&)
|
|
m.assertEqual(manifest.GetDurationMs({ adaptiveFormats: [{}], lengthSeconds: 60 }), 60000&)
|
|
m.assertEqual(manifest.GetDurationMs({ isPostLiveDvr: true, adaptiveFormats: [], lengthSeconds: 60 }), 60000&)
|
|
end function
|
|
|
|
end class
|
|
|
|
end namespace
|