-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 incorrect segment position after manifest update #838
Fix incorrect segment position after manifest update #838
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
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.
This makes sense to me, but I would like to see an additional test added to test/media/segment_index_unit.js to ensure we don't regress in the future. Thanks!
Can you please provide an example manifest that reproduces your issue? We calculate the If this is a bug on our part, then it will mess with other parts, like calculation of |
@albertcsm Can you provide an example manifest? Otherwise we are going to close the PR. |
OK, I will provide two versions of the manifest that has segments removed for retention |
I wasn't able to reproduce the issue at this moment, actually it is not easy to hit the issue. Anyway, I attached the sample manifests from my encoder. The two manifests are consecutive snapshot of the manifest, with 4 seconds between them. Some segments from period 17 were removed in the second manifest. |
Your content is bad. The reason you are not seeing more problems is because you use The encoder is removing segments from the list without updating the For example, in the audio stream, the first segment initially starts at |
@TheModMaker I am not sure if |
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 forgot that we are supporting this use-case for other content. Sory for my confusion.
Also please add a unit test for this.
newReferences.push(r2); | ||
var r = new shaka.media.SegmentReference(r1.position, | ||
r2.startTime, r2.endTime, r2.getUris, r2.startByte, r2.endByte); | ||
newReferences.push(r); |
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 it could be implemented differently. If you just increment i
(not j
), then the last segment will be treated as new and will be appended with the logic below (I think).
If you do it that way, I would suggest moving the check to the higher else-if chain.
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.
@TheModMaker, I don't think I understand you. If we're processing both a new and old ref, and replacing one with the other, why wouldn't we increment the indices on both arrays?
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.
Because if there are leftover new refs after this loop finishes, the code below will append them while adjusting the position numbers correctly (see line 165+ below). So if we increment i
(ignore old ref), the last ref will be treated as a new ref and that code will handle the renumbering.
I am also suggesting that you don't push anything, just increment i
. For example:
if (r1.startTime < r2.startTime) {
...
} else if (r1.startTime > r2.startTime) {
...
} else if (Math.abs(r1.endTime - r2.endTime) > 0.1) {
// When a period is changed...
goog.asserts.assert(...);
i++; // r2 will be pushed as a new ref by the code below.
} else {
newReferences.push(r1);
i++;
j++;
}
But maybe this is too subtle, the old code is fine if that is better.
I have added a unit test, please check, thanks. |
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.
Looks good to me, just two nits.
I believe you marked the files as executable, they should be normal text files. This can be fixed with:
git add --chmod=-x lib/media/segment_index.js test/media/segment_index.js
git checkout -- lib/media/segment_index.js test/media/segment_index.js
test/media/segment_index_unit.js
Outdated
@@ -255,6 +255,29 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { | |||
expect(index1.references_[1]).toEqual(references2[0]); | |||
expect(index1.references_[2]).toEqual(references2[1]); | |||
}); | |||
|
|||
it('last live stream reference with corrected position', function() { |
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.
Also add a comment here with the URL to your PR.
@TheModMaker Oh yes, thanks for pointing out, I was making the change over a mounted folder on a Windows desktop... I have fixed it and added the PR link. |
Letting @TheModMaker review and approve
I'm running tests right now. Assuming they pass, we'll wait for final approval from @TheModMaker. Thanks! |
All tests passed! |
The fix has been cherry-picked for v2.1.6. |
As part of Period-flattening, I'm trying to reduce our dependence on the "position" field of SegmentReference. If it can be eliminated, we can more easily concatenate Arrays of SegmentReferences without modifying them. There has long been a comment at the top of SegmentIndex's merge method stating that we only ever extend the references, but never interleave them. The code, however, is structured in such a way that it could interleave them. This could cause the offset of a given SegmentReference in the Array to change, which would be counter to the comment about only ever extending the list. This change simplifies merge() so that it can only ever extend the array of SegmentReferences. This will guarantee that their offset within the Array will not change during the merge operation. This, in turn, enables further SegmentIndex changes to move "next" segment tracking out of StreamingEngine (where it is based on the "position" field of SegmentReference) and into SegmentIndex (where it could be based on offset into the Array of references). It removes one test related to PR #838. This test was about our ability to update the position of the final segment in a list. This doesn't seem to make a lot of sense, and we're going to stop relying on segment position anyway. Issue #1339 (period-flattening) Change-Id: I2067e2266cf2d02c0e6350d6b57d74f9ed1b27d3
I observed quite a lot of assertion failure
Assertion failed: SegmentReferences are incorrect
for a multiple period DASH, and encountered some rare player stuck.Before the stuck happen, there was console log that suggest the stuck is due to not being able to find segment from position number:
segment doest not exist: currentPeriod.startTime=1216.3484667 position=5
I found that the issue was caused by incorrect position number of segment references after segment merge on manifest update.
When the segment reference from the newer manifest get merged, the position number is left untouched. However, it may have changed due to removal of previous segments from the period. Please see the attached diagram, the segment number changed from 5 to 1 after manifest update. Consequently, any attempt to locate the next segment by position would fail.

After patching the player with corrected position number, the assert failures no longer occur.
The segments in my manifest are not aligning close to the period boundaries, so may be a corner case that other users may not see the same issue.
Please check my code diff, thanks.