-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: more accurate segment choices and logging #1127
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1127 +/- ##
==========================================
- Coverage 86.20% 86.13% -0.08%
==========================================
Files 39 39
Lines 9289 9272 -17
Branches 2127 2123 -4
==========================================
- Hits 8008 7986 -22
- Misses 1281 1286 +5
Continue to review full report at Codecov.
|
|
||
if (time > 0) { | ||
if ((time + TIME_FUDGE_FACTOR) > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep TIME_FUDGE_FACTOR
at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: What is TIME_FUDGE_FACTOR
used for here? Is using it causing timing issues down the line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this may be the wrong place for us to use time fudging. We should probably only ever fudge time in one place: when we are trying to determine the next segment to request and are not simply walking the playlist (mediaIndex++). In that case, all requests to get media info/segment info should be as precise as possible given the current segment information, then, once the final segment is determined, we should decide whether we want to fudge the time at all to conservatively request a segment (i.e., whether to request back 1 segment, or, as an alternative, get media info for time with a fudge factor included).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change basically encompasses what you are saying. We only use getMediaIndexForTime
when we are not incrementing mediaIndex/partIndex. This change makes it so that cumulatively we can only be off by TIME_FUDGE_FACTOR
rather than every single part/segments duration being incremented or decremented by TIME_FUDGE_FACTOR
. For the sake of time I think that we might want to add a TODO here to see if we should even use TIME_FUDGE_FACTOR at all. I lean towards not using it, but it will require a bit more testing and could easily enough be an isolated change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 a TODO would be good for now. This definitely is better than before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth making an issue/a note in our major/refactoring epic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
@@ -870,7 +870,7 @@ export const LoaderCommonFactory = ({ | |||
}); | |||
|
|||
QUnit.test('drops partIndex if playlist update drops parts', function(assert) { | |||
assert.timeout(100000000000000000000); | |||
loader.duration_ = () => Infinity; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ie 11 has the duration as NaN here, so sync-controller gets a sync point of 1
for a vod video.
bdd1e83
to
a4a45df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying out https://conventionalcomments.org/ again.
|
||
if (time > 0) { | ||
if ((time + TIME_FUDGE_FACTOR) > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: What is TIME_FUDGE_FACTOR
used for here? Is using it causing timing issues down the line?
@@ -2967,6 +2954,65 @@ QUnit.module('SegmentLoader', function(hooks) { | |||
}); | |||
}); | |||
|
|||
QUnit.test('sync request can be thrown away', function(assert) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: looks like this test is failing under IE11. https://github.com/videojs/http-streaming/pull/1127/checks?check_run_id=2659611689#step:13:478
|
||
if (time > 0) { | ||
if ((time + TIME_FUDGE_FACTOR) > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this may be the wrong place for us to use time fudging. We should probably only ever fudge time in one place: when we are trying to determine the next segment to request and are not simply walking the playlist (mediaIndex++). In that case, all requests to get media info/segment info should be as precise as possible given the current segment information, then, once the final segment is determined, we should decide whether we want to fudge the time at all to conservatively request a segment (i.e., whether to request back 1 segment, or, as an alternative, get media info for time with a fudge factor included).
// throw away the isSyncRequest segment if | ||
// it wouldn't have been the next segment we request. | ||
if (segmentInfo.isSyncRequest) { | ||
this.syncController_.saveSegmentTimingInfo({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may have to be careful here, since we're losing some of our timing logic, which may lead to inaccurate next requests:
http-streaming/src/segment-loader.js
Lines 2860 to 2863 in 1c7a63b
// Now that the end of the segment has been reached, we can set the end time. It's | |
// best to wait until all appends are done so we're sure that the primary media is | |
// finished (and we have its end time). | |
this.updateTimingInfoEnd_(segmentInfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call this function within this block? From a brief glance it seems like it only estimates the segment end point using start/duration unless we have an end
. Seems like we should call it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should probably call it. On that note we may also want to consider adding a property to the segment whether the last time we requested that segment it was a sync request (and clear it if it's requested on a non sync request). It may help us for debugging, particularly now that it's no longer being appended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
called
Co-authored-by: Garrett Singer <[email protected]>
Co-authored-by: Garrett Singer <[email protected]>
src/segment-loader.js
Outdated
|
||
return `${name} [${seq + index}/${seq + segmentLen}]` + | ||
(hasPartIndex ? ` part [${partIndex}/${zeroBasedPartCount}]` : '') + | ||
(hasPartIndex ? ` part [${partIndex}/${totalParts}]` : '') + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this take into account the 0 based indexing vs total. Maybe we can just say `[index 0, 3 total]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep the name zeroBasedPartCount
here I guess. I do subtract 1 to make it zero based.
Description
This pull request refactors two functions that are the cause of latency drift in live streams during rendition changes. It also vastly improves the segmentInfoString logging logic.
SegmentLoader#getSyncSegmentCandidate
What we do right now is choose a segment that will never be the one we want, still append it to the source buffer and then ignore the final "end result" (saving the media/part index as the current one).
I have improved this logic in the following ways:
Playlist#getMediaInfoForTime
Currently we add
TIME_FUDGE_FACTOR
for each segment and this causes us to choose the wrong segment more often then not for playlists with > 15 segments as we will be off by more than half a second in those cases. Instead we should only addTIME_FUDGE_FACTOR
a single time when comparing against the time we want. We might even want to consider not usingTIME_FUDGE_FACTOR
here.