Live stream fixes
This commit is contained in:
1 parent
ae1d2b8acf
commit
555665488d
17 files changed
+280
-148
No files matched your search
@@ -140,6 +140,24 @@ namespace Tests
|
||||
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
|
||||
|
||||
@@ -160,6 +160,22 @@ namespace Tests
|
||||
m.assertEqual(parsedResponse.error, `Live stream head check returned no X-Head-Seqnum / X-Head-Time (HTTP 200)\n`)
|
||||
end function
|
||||
|
||||
@describe("Innertube.FetchLiveHead")
|
||||
|
||||
@it("sends the check once more when the answer lacks the head, whatever its status")
|
||||
function _()
|
||||
m.server.routes = {
|
||||
"/live/failing": { status: 503 }
|
||||
"/live/failingwithhead": { status: 503, headers: { "X-Head-Seqnum": "40", "X-Head-Time-Millis": "80000" } }
|
||||
}
|
||||
failing = Tests.HttpTestServerUrl("/live/failing?itag=1")
|
||||
m.assertFalse(Innertube.HasLiveHead(Innertube.FetchLiveHead(failing, invalid)))
|
||||
m.assertEqual(Tests.HttpTestServerHits(m.server, failing), 2)
|
||||
failingWithHead = Tests.HttpTestServerUrl("/live/failingwithhead?itag=1")
|
||||
m.assertTrue(Innertube.HasLiveHead(Innertube.FetchLiveHead(failingWithHead, invalid)))
|
||||
m.assertEqual(Tests.HttpTestServerHits(m.server, failingWithHead), 1)
|
||||
end function
|
||||
|
||||
@describe("Innertube.ReadLiveHeadSeqnum")
|
||||
|
||||
@it("reads X-Head-Seqnum")
|
||||
@@ -187,6 +203,15 @@ namespace Tests
|
||||
m.assertInvalid(Innertube.ReadLiveHeadTimeSecAsMs(m.ResponseWithHeaders({ "X-Head-Time-Millis": "17900000123" })))
|
||||
end function
|
||||
|
||||
@describe("Innertube.ReadLiveHeadAnyTimeMs")
|
||||
|
||||
@it("reads X-Head-Time-Millis, else X-Head-Time-Sec")
|
||||
function _()
|
||||
m.assertEqual(Innertube.ReadLiveHeadAnyTimeMs(m.ResponseWithHeaders({ "X-Head-Time-Millis": "17900000123", "X-Head-Time-Sec": "17900000" })), 17900000123&)
|
||||
m.assertEqual(Innertube.ReadLiveHeadAnyTimeMs(m.ResponseWithHeaders({ "X-Head-Time-Sec": "17900000" })), 17900000000&)
|
||||
m.assertInvalid(Innertube.ReadLiveHeadAnyTimeMs(m.ResponseWithHeaders({ "X-Head-Seqnum": "40" })))
|
||||
end function
|
||||
|
||||
function ResponseWithHeaders(headers as object) as HttpClient.Response
|
||||
return new HttpClient.Response({ headers: headers })
|
||||
end function
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import "pkg:/components/Services/Innertube/PostLiveDvrInfo.bs"
|
||||
import "pkg:/source/tests/HttpTestServer.bs"
|
||||
import "pkg:/source/tests/LoggingGlobals.bs"
|
||||
import "pkg:/source/utils/UrlUtils.bs"
|
||||
|
||||
namespace Tests
|
||||
|
||||
@@ -21,37 +22,52 @@ namespace Tests
|
||||
m.global.telemetry.LogEvent = {}
|
||||
end function
|
||||
|
||||
@describe("Innertube.FetchPostLiveDvrHead")
|
||||
|
||||
@it("reads a HEAD's status and headers")
|
||||
function _()
|
||||
m.server.routes = { "/dvr/head": { status: 200, headers: { "X-Head-Seqnum": "40", "X-Head-Time-Millis": "80000" } } }
|
||||
result = Innertube.FetchPostLiveDvrHead(Tests.HttpTestServerUrl("/dvr/head?itag=1"), invalid, "cpn1", Innertube.ClientType.Tv, invalid)
|
||||
m.assertEqual(result.statusCode, 200)
|
||||
m.assertTrue(Innertube.HasPostLiveDvrHead(result))
|
||||
m.assertEqual(Tests.HttpTestServerHits(m.server, result.url), 1)
|
||||
end function
|
||||
|
||||
@it("sends a failed HEAD once more")
|
||||
function _()
|
||||
m.server.routes = { "/dvr/failing": { status: 503 } }
|
||||
result = Innertube.FetchPostLiveDvrHead(Tests.HttpTestServerUrl("/dvr/failing?itag=1"), "0", invalid, Innertube.ClientType.Tv, invalid)
|
||||
m.assertEqual(result.statusCode, 503)
|
||||
m.assertFalse(Innertube.HasPostLiveDvrHead(result))
|
||||
m.assertEqual(Tests.HttpTestServerHits(m.server, result.url), 2)
|
||||
end function
|
||||
|
||||
@describe("Innertube.GetPostLiveDvrInfo")
|
||||
|
||||
@it("reads the duration and segment count from the live edge's head")
|
||||
function _()
|
||||
m.server.routes = { "/dvr/ended": { status: 200, headers: { "X-Head-Seqnum": "40", "X-Head-Time-Millis": "80000" } } }
|
||||
parsedResponse = {}
|
||||
Innertube.GetPostLiveDvrInfo(parsedResponse, [{ url: Tests.HttpTestServerUrl("/dvr/ended?itag=1") }], invalid, Innertube.ClientType.Tv, invalid)
|
||||
Innertube.GetPostLiveDvrInfo(parsedResponse, [{ url: Tests.HttpTestServerUrl("/dvr/ended?itag=1") }], invalid, invalid)
|
||||
m.assertEqual(parsedResponse.postLiveDvrDurationMs, 80000)
|
||||
m.assertEqual(parsedResponse.postLiveDvrSegmentCount, 40)
|
||||
end function
|
||||
|
||||
@it("reads a duration past 32 bits")
|
||||
function _()
|
||||
m.server.routes = { "/dvr/long": { status: 200, headers: { "X-Head-Seqnum": "3580000", "X-Head-Time-Millis": "17900000123" } } }
|
||||
parsedResponse = {}
|
||||
Innertube.GetPostLiveDvrInfo(parsedResponse, [{ url: Tests.HttpTestServerUrl("/dvr/long?itag=1") }], invalid, invalid)
|
||||
m.assertEqual(parsedResponse.postLiveDvrDurationMs, 17900000123&)
|
||||
m.assertEqual(parsedResponse.postLiveDvrSegmentCount, 3580000)
|
||||
end function
|
||||
|
||||
@it("reads the head from sq=0 when the live edge has none")
|
||||
function _()
|
||||
formatUrl = Tests.HttpTestServerUrl("/dvr/cached?itag=1")
|
||||
fallbackUrl = UrlUtils.AppendQueryParams(Innertube.GetLiveHeadUrl(formatUrl, "cpn1"), { "sq": "0" })
|
||||
routes = { "/dvr/cached": { status: 200 } }
|
||||
routes[fallbackUrl.Replace(Tests.HttpTestServerUrl(""), "")] = { status: 200, headers: { "X-Head-Seqnum": "40", "X-Head-Time-Millis": "80000" } }
|
||||
m.server.routes = routes
|
||||
parsedResponse = {}
|
||||
Innertube.GetPostLiveDvrInfo(parsedResponse, [{ url: formatUrl }], "cpn1", invalid)
|
||||
m.assertEqual(Tests.HttpTestServerHits(m.server, Innertube.GetLiveHeadUrl(formatUrl, "cpn1")), 2)
|
||||
m.assertEqual(Tests.HttpTestServerHits(m.server, fallbackUrl), 1)
|
||||
m.assertEqual(parsedResponse.postLiveDvrDurationMs, 80000)
|
||||
m.assertEqual(parsedResponse.postLiveDvrSegmentCount, 40)
|
||||
end function
|
||||
|
||||
@it("sets nothing when neither the live edge nor sq=0 has a head")
|
||||
function _()
|
||||
m.server.routes = { "/dvr/nohead": { status: 200 } }
|
||||
formatUrl = Tests.HttpTestServerUrl("/dvr/nohead?itag=1")
|
||||
parsedResponse = {}
|
||||
Innertube.GetPostLiveDvrInfo(parsedResponse, [{ url: formatUrl }], "cpn1", invalid)
|
||||
m.assertEqual(Tests.HttpTestServerHits(m.server, UrlUtils.AppendQueryParams(Innertube.GetLiveHeadUrl(formatUrl, "cpn1"), { "sq": "0" })), 2)
|
||||
m.assertFalse(parsedResponse.DoesExist("postLiveDvrDurationMs"))
|
||||
m.assertFalse(parsedResponse.DoesExist("postLiveDvrSegmentCount"))
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -388,34 +388,45 @@ namespace Tests
|
||||
m.assertFalse(summary.DoesExist("stream_source"))
|
||||
end function
|
||||
|
||||
@it("the live head check counts of the video load, without defaults, read once")
|
||||
@it("the live head check and timeline counts of the video load, without defaults, read once")
|
||||
function _()
|
||||
m.fakeTransport.isLive = true
|
||||
m.fakeTop.content.videoLoadId = "live1"
|
||||
WriteAsciiFile(LIVE_HEAD_COUNTS_PATH, FormatJson({ "video_load_id": "live1", "counts": { "checks_sent": 6, "answered_after_wait": 1, "timed_out": 0 } }))
|
||||
WriteAsciiFile(LIVE_LOAD_COUNTS_PATH, FormatJson({
|
||||
"video_load_id": "live1"
|
||||
"live_head": { "checks_sent": 6, "answered_after_wait": 1, "timed_out": 0 }
|
||||
"live_timeline": { "timed_checks": 3, "corrections": 1, "stall_corrections": 0, "drift_ms_min": -3425, "drift_ms_max": 0, "duration_runs_max": 2 }
|
||||
}))
|
||||
summary = m.SendAt(1000)
|
||||
m.assertEqual(summary.live_head, { "checks_sent": 6, "answered_after_wait": 1 })
|
||||
m.assertFalse(CreateObject("roFileSystem").Exists(LIVE_HEAD_COUNTS_PATH), "read once")
|
||||
m.assertFalse(m.SendAt(2000).DoesExist("live_head"))
|
||||
m.assertEqual(summary.live_timeline, { "timed_checks": 3, "corrections": 1, "drift_ms_min": -3425, "duration_runs_max": 2 })
|
||||
m.assertFalse(CreateObject("roFileSystem").Exists(LIVE_LOAD_COUNTS_PATH), "read once")
|
||||
summary = m.SendAt(2000)
|
||||
m.assertFalse(summary.DoesExist("live_head"))
|
||||
m.assertFalse(summary.DoesExist("live_timeline"))
|
||||
end function
|
||||
|
||||
@it("a live play without live head check counts has none")
|
||||
@it("a live play without live load counts has none")
|
||||
function _()
|
||||
m.fakeTransport.isLive = true
|
||||
m.fakeTop.content.videoLoadId = "live1"
|
||||
DeleteFile(LIVE_HEAD_COUNTS_PATH)
|
||||
m.assertFalse(m.SendAt(1000).DoesExist("live_head"))
|
||||
DeleteFile(LIVE_LOAD_COUNTS_PATH)
|
||||
summary = m.SendAt(1000)
|
||||
m.assertFalse(summary.DoesExist("live_head"))
|
||||
m.assertFalse(summary.DoesExist("live_timeline"))
|
||||
end function
|
||||
|
||||
@it("leaves the live head check counts of another video load")
|
||||
@it("leaves the live load counts of another video load")
|
||||
function _()
|
||||
m.fakeTransport.isLive = true
|
||||
m.fakeTop.content.videoLoadId = "live1"
|
||||
handoff = FormatJson({ "video_load_id": "live2", "counts": { "checks_sent": 6 } })
|
||||
WriteAsciiFile(LIVE_HEAD_COUNTS_PATH, handoff)
|
||||
m.assertFalse(m.SendAt(1000).DoesExist("live_head"))
|
||||
m.assertEqual(ReadAsciiFile(LIVE_HEAD_COUNTS_PATH), handoff)
|
||||
DeleteFile(LIVE_HEAD_COUNTS_PATH)
|
||||
handoff = FormatJson({ "video_load_id": "live2", "live_head": { "checks_sent": 6 }, "live_timeline": { "corrections": 1 } })
|
||||
WriteAsciiFile(LIVE_LOAD_COUNTS_PATH, handoff)
|
||||
summary = m.SendAt(1000)
|
||||
m.assertFalse(summary.DoesExist("live_head"))
|
||||
m.assertFalse(summary.DoesExist("live_timeline"))
|
||||
m.assertEqual(ReadAsciiFile(LIVE_LOAD_COUNTS_PATH), handoff)
|
||||
DeleteFile(LIVE_LOAD_COUNTS_PATH)
|
||||
end function
|
||||
|
||||
@it("a live play: the first video segment's bitrate and the network's at the first playing")
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Tests
|
||||
end function
|
||||
|
||||
protected override function afterEach()
|
||||
DeleteFile(LIVE_HEAD_COUNTS_PATH)
|
||||
DeleteFile(LIVE_LOAD_COUNTS_PATH)
|
||||
end function
|
||||
|
||||
' What VideoContentJob sets on the player's content for a video load.
|
||||
@@ -172,15 +172,18 @@ namespace Tests
|
||||
m.assertInvalid(pending["_fetch"]["_urlTransfer"])
|
||||
end function
|
||||
|
||||
@it("writes the load's head check counts at every refresh")
|
||||
@it("writes the load's head check and timeline counts at every refresh, after its correction")
|
||||
function _()
|
||||
m.LoadLive([{ seqnum: 10, timeMs: 18630 }, { seqnum: -1, timeMs: invalid }])
|
||||
m.RefreshDue()
|
||||
handoff = StringUtils.ParseJsonSafe(ReadAsciiFile(LIVE_LOAD_COUNTS_PATH))
|
||||
m.assertEqual(handoff["live_timeline"]["corrections"], 1)
|
||||
m.RefreshDue()
|
||||
handoff = StringUtils.ParseJsonSafe(ReadAsciiFile(LIVE_HEAD_COUNTS_PATH))
|
||||
handoff = StringUtils.ParseJsonSafe(ReadAsciiFile(LIVE_LOAD_COUNTS_PATH))
|
||||
m.assertEqual(handoff["video_load_id"], "live1")
|
||||
m.assertEqual(handoff["counts"]["checks_sent"], 2)
|
||||
m.assertEqual(handoff["counts"]["answered_without_head"], 1)
|
||||
m.assertEqual(handoff["live_head"]["checks_sent"], 2)
|
||||
m.assertEqual(handoff["live_head"]["answered_without_head"], 1)
|
||||
m.assertEqual(handoff["live_timeline"], m.router.liveTimelineCounts)
|
||||
end function
|
||||
|
||||
@it("gives a list behind the head the cadence since load; the load head ended where the list stays ahead")
|
||||
@@ -220,6 +223,16 @@ namespace Tests
|
||||
' head 5: 600 ms behind, within half a segment
|
||||
m.RefreshDue()
|
||||
m.assertEqual(m.router.liveDurationRuns.Count(), 1)
|
||||
m.assertEqual(m.router.liveTimelineCounts, {
|
||||
"timed_checks": 1
|
||||
"corrections": 0
|
||||
"stall_corrections": 0
|
||||
"drift_ms_min": -600
|
||||
"drift_ms_max": 0
|
||||
"step_ms_min": -600
|
||||
"step_ms_max": 0
|
||||
"duration_runs_max": 1
|
||||
})
|
||||
' head 15 ends at 6000 + 28600 = 34600, listed at 32000: 5 onwards (4 is the last
|
||||
' listed) take 2200 ms, placed to end 15 there: from 10400, past 4's end (10000)
|
||||
m.global.telemetry.LogEvent = {}
|
||||
@@ -233,6 +246,17 @@ namespace Tests
|
||||
m.RefreshDue()
|
||||
m.assertEqual(m.router.liveDurationRuns, [{ fromSeqnum: 5, startMs: 10400, durationMs: 2200 }, { fromSeqnum: 15, startMs: 91600 - 26 * 2253, durationMs: 2253 }])
|
||||
m.assertEmpty(m.global.telemetry.LogEvent)
|
||||
' drift -600, -2600, then -2000 off the realigned list
|
||||
m.assertEqual(m.router.liveTimelineCounts, {
|
||||
"timed_checks": 3
|
||||
"corrections": 2
|
||||
"stall_corrections": 0
|
||||
"drift_ms_min": -2600
|
||||
"drift_ms_max": 0
|
||||
"step_ms_min": -2000
|
||||
"step_ms_max": 0
|
||||
"duration_runs_max": 2
|
||||
})
|
||||
end function
|
||||
|
||||
@it("takes a stall as a gap: the cadence stays, and the list stays on the head after it")
|
||||
@@ -256,6 +280,9 @@ namespace Tests
|
||||
end for
|
||||
m.assertEqual(m.router.liveDurationRuns.Count(), 2)
|
||||
m.assertEqual(m.router.liveLeadMs, 0)
|
||||
m.assertEqual(m.router.liveTimelineCounts["corrections"], 1)
|
||||
m.assertEqual(m.router.liveTimelineCounts["stall_corrections"], 1)
|
||||
m.assertEqual(m.router.liveTimelineCounts["step_ms_min"], -90000)
|
||||
end function
|
||||
|
||||
@it("takes a list ahead by more than the stall bound as cadence: a stall before load heals at once")
|
||||
@@ -264,6 +291,9 @@ namespace Tests
|
||||
m.LoadLive([{ seqnum: 10, timeMs: 40000 }, { seqnum: 15, timeMs: 50000 }], { liveHeadSeqnum: 5, liveHeadTimeMs: 30000, liveSegmentDurationMs: 6000 })
|
||||
m.RefreshDue()
|
||||
m.assertEqual(m.router.liveDurationRuns[1].durationMs, 2000)
|
||||
' head 10 ends at 36000 + 10000, listed to end at 11 x 6000
|
||||
m.assertEqual(m.router.liveTimelineCounts["drift_ms_max"], 20000)
|
||||
m.assertEqual(m.router.liveTimelineCounts["step_ms_max"], 20000)
|
||||
m.RefreshDue()
|
||||
m.assertEqual(m.router.liveDurationRuns.Count(), 2)
|
||||
end function
|
||||
@@ -318,8 +348,25 @@ namespace Tests
|
||||
m.RefreshDue()
|
||||
m.assertEqual(m.router.liveHeadSeqnum, 7)
|
||||
m.assertEqual(m.router.liveDurationRuns.Count(), 1)
|
||||
m.assertEqual(m.router.liveTimelineCounts["timed_checks"], 0)
|
||||
m.RefreshDue()
|
||||
m.assertEqual(m.router.liveDurationRuns.Count(), 2)
|
||||
m.assertEqual(m.router.liveTimelineCounts["timed_checks"], 1)
|
||||
end function
|
||||
|
||||
@it("skips a head check whose time went back, unmeasured, and corrects at a later one")
|
||||
function _()
|
||||
' the load head (2) is at 2630 ms; head 7 claims 2000
|
||||
m.LoadLive([{ seqnum: 7, timeMs: 2000 }, { seqnum: 12, timeMs: 22630 }])
|
||||
m.RefreshDue()
|
||||
m.assertEqual(m.router.liveHeadSeqnum, 7)
|
||||
m.assertEqual(m.router.liveDurationRuns.Count(), 1)
|
||||
m.assertEqual(m.router.liveDriftMs, 0)
|
||||
m.assertEqual(m.router.liveTimelineCounts["timed_checks"], 0)
|
||||
m.assertEqual(m.router.liveTimelineCounts["drift_ms_max"], 0)
|
||||
m.RefreshDue()
|
||||
m.assertEqual(m.router.liveDurationRuns.Count(), 2)
|
||||
m.assertEqual(m.router.liveTimelineCounts["timed_checks"], 1)
|
||||
end function
|
||||
|
||||
@it("times the head of a stream live for 111 days (head time past 32 bits)")
|
||||
|
||||
@@ -58,9 +58,9 @@ function ValidDouble(obj as dynamic) as double
|
||||
end if
|
||||
end function
|
||||
|
||||
' Returns true if the given object is numeric (Integer, Float, or Double)
|
||||
' Returns true if the given object is numeric (Integer, LongInteger, Float, or Double)
|
||||
function IsNumber(obj as dynamic) as boolean
|
||||
return obj <> invalid and (GetInterface(obj, "ifInt") <> invalid or GetInterface(obj, "ifFloat") <> invalid or GetInterface(obj, "ifDouble") <> invalid)
|
||||
return obj <> invalid and (GetInterface(obj, "ifInt") <> invalid or GetInterface(obj, "ifLongInt") <> invalid or GetInterface(obj, "ifFloat") <> invalid or GetInterface(obj, "ifDouble") <> invalid)
|
||||
end function
|
||||
|
||||
' Returns true if the given object is of type String, false otherwise
|
||||
|
||||
@@ -23,6 +23,16 @@ namespace Tests
|
||||
m.assertEqual(ValidString(obj), expected)
|
||||
end function
|
||||
|
||||
@it("Checks if an object is a number")
|
||||
function _()
|
||||
m.assertTrue(IsNumber(-5))
|
||||
m.assertTrue(IsNumber(17900000123&))
|
||||
m.assertTrue(IsNumber(1.5!))
|
||||
m.assertTrue(IsNumber(1.5#))
|
||||
m.assertFalse(IsNumber("5"))
|
||||
m.assertFalse(IsNumber(invalid))
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
Reference in new issue
Block a user