-
Notifications
You must be signed in to change notification settings - Fork 315
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
Media Playlist Set* methods modifying wrong segments #36
Comments
I had considered proposing alternatives to this exact FIFO method (looking at these examples: https://gist.github.com/moraes/2141121), where we could have auto extending playlists (see rasky's suggestion), but this would potentially be a breaking change, as others may depend on the playlist full behaviour, either case, this version should still be fixed (if it isn't intentional behaviour). |
@grafov when you have time, do you have any thoughts on this? Importantly, am I doing something wrong here, or is this an actual problem? |
Finally I looked this bug, it reproduced as explained above. I fully agree with @bradleyfalzon, my usage of uint without check was wrong. Bradley please merge your commit it fix problem properly. |
Fix #36 Media Playlist Set* methods modifying wrong segment
Well I found pull request and merged it. Thank you! |
Thanks @grafov, much appreciated |
Fix #36 Media Playlist Set* methods modifying wrong segment
I believe there maybe an issue with the Set* methods when the media playlist capacity is not a power of 2. It appears that once the playlist is full, a Set* (such as
SetDiscontinuity()
orSetKey()
) sets the correct value on the wrong segment.The following should demonstrate this, ignore the fact I'm ignoring errors, even when checked the problem still occurs. The
SetKey()
method best shows the issue as I can set the key URI (and IV) to be the same as the segment URI to better illustrate the problem, but the same occurs withSetDiscontinuity()
(and likely other methods that use thep.Segments[(p.tail-1)%p.capacity]
calculation).Output
Generally, it looks like the problem is that the
.Append()
method sets playlist tail property (p.tail
) to be modulo capacity and stores it back inp.tail
(p.tail
is always between 0 andp.capacity
). Whereas the Set* methods assume this is a incrementing integer (based on they're calculation of(p.tail-1)%p.capacity
). Essentially, becausep.tail
wraps to zero and because it is a uint, whenp.tail
is 0 the result ofp.tail-1
is 18446744073709551615. Changing this to an int doesn't quite fix things either, at least not without still requiring further changes within the Set* methods (but this may also be the preferred solution) and more casting.I believe a simple change maybe:
There's other methods to fix it in each Set* method, via (something similar to, but perhaps using a private
tail()
method to obtain the correct tail):I wanted to get hear others' thoughts on this before I go too much further, as this maybe a misunderstanding, maybe another solution, or this proposed change may cause other unintended consequences. This isn't a straight forward issue as there's multiple causes (depending on your opinion) and multiple solutions.
I'll be happy to send in a PR + tests and also address the
Remove()
methods (as well as the corresponding head variable), just focusing on theAppend()
and Set* methods first.Note, I can't reproduce the issue when there capacity is a power of 2, e.g.: 1,2,4,8,16 - this may explain why the issue hasn't been discussed before?
I think there's two ways to solve this, move tail/head to ints and handle negatives in Set* methods, or use the above method (tail to always be incrementing). I'll continue to have a bit of a think about this, but I want to hear others' opinions.
The text was updated successfully, but these errors were encountered: