Skip to content
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

m3u8-parser: fill missing rendition report attrs #5110

Merged
merged 4 commits into from
Dec 20, 2022

Conversation

erankor
Copy link
Collaborator

@erankor erankor commented Dec 15, 2022

This PR will...

Fill out any missing LAST-MSN/LAST-PART attributes from rendition reports, by copying the respective values from the current level being parsed.

Why is this Pull Request needed?

According to the hls spec -
" A server MAY omit adding an attribute to an EXT-X-RENDITION-REPORT
tag - even a mandatory attribute - if its value is the same as that
of the Rendition Report of the Media Playlist to which the EXT-X-
RENDITION-REPORT tag is being added. Doing so reduces the size of
the Rendition Report."

Are there any points in the code the reviewer needs to double check?

Normally LAST-MSN / LAST-PART are strings, here they are set to an int, from my tests it works just fine, but just a point to keep in mind.

Resolves issues:

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

@erankor erankor force-pushed the fill-missing-rr-attrs branch 2 times, most recently from 6303a94 to 9fade08 Compare December 15, 2022 14:50
Copy link
Collaborator

@robwalch robwalch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you looked at switchParams in base-stream-controller?

Parsed attributes should reflect what was parsed from the playlist. If using the current level details is allowed when these attributes are missing then this can be handled in switchParams using previous details when present:

https://github.com/video-dev/hls.js/blob/v1.2.9/src/controller/base-playlist-controller.ts#L69

- const msn = parseInt(attr['LAST-MSN']);
- let part = parseInt(attr['LAST-PART']);
+ const msn = parseInt(attr['LAST-MSN']) || previous?.lastPartSn;
+ let part = parseInt(attr['LAST-PART']) || previous?.lastPartIndex;

@erankor
Copy link
Collaborator Author

erankor commented Dec 15, 2022

Thanks @robwalch, I drafted something that extracts this info in switchParams from existing fields, but it's a bit clumsy... and I have some problem there with the endSN + 1 - I need to add 1 there only when the last part is after the last segment, and not sure I currently have a way to know if that's the case...

Did you mean that I'll add new fields to LevelDetails to hold this stuff?

@robwalch
Copy link
Collaborator

robwalch commented Dec 15, 2022

Thanks @robwalch, I drafted something that extracts this info in switchParams from existing fields, but it's a bit clumsy... and I have some problem there with the endSN + 1 - I need to add 1 there only when the last part is after the last segment, and not sure I currently have a way to know if that's the case...

Did you mean that I'll add new fields to LevelDetails to hold this stuff?

It is doable with the fields that are there. The LL-HLS playlist reload logic already does this around calls to getDeliveryDirectives. When details.lastPartSn === details.endSN then the last part belongs to the last segment - this is when we increment msn and set part to 0.

@erankor
Copy link
Collaborator Author

erankor commented Dec 16, 2022

Thanks Rob! I updated the PR.
I figured I can just use lastPartSn, since it already has a fallback to endSN when there are no parts.

Btw, in terms of style, my personal preference is always to have flat code, and avoid high levels of indentation. So, in this specific function, I would do something like: if (!renditionReports) { return } at the beginning, and then inside the for loop if (uri !== playlistUri.slice(-uri.length)) { continue } etc. I tried to change only the minimum required in this PR, but if other people here share the same opinion, I will happily apply those changes as well.

@robwalch
Copy link
Collaborator

robwalch commented Dec 16, 2022

Btw, in terms of style

prettier decides. Do npm run prettier and commit the indentation changes.

Why not use the optional operator on previous? it's flatter.

const msn = parseInt(attr['LAST-MSN']) || previous?.lastPartSn;
let part = parseInt(attr['LAST-PART']) || previous?.lastPartIndex;

endSN is not optional and always defined.

according to the hls spec -
"   A server MAY omit adding an attribute to an EXT-X-RENDITION-REPORT
   tag - even a mandatory attribute - if its value is the same as that
   of the Rendition Report of the Media Playlist to which the EXT-X-
   RENDITION-REPORT tag is being added.  Doing so reduces the size of
   the Rendition Report."

this PR fills out any missing LAST-MSN/LAST-PART attributes from
rendition reports, by copying the respective values from the current
level being parsed.
@erankor
Copy link
Collaborator Author

erankor commented Dec 16, 2022

You're right, when I read your first comment, I thought this was just pseudocode :) sorry about that.

Anyway, I removed the isFinite check on msn, following what you wrote about endSN always being defined.
And, changed the checks on part to use >= 0 since lastPartIndex returns -1 when there are no parts.

@erankor
Copy link
Collaborator Author

erankor commented Dec 20, 2022

@robwalch, does this look ok? do you think we can merge it?

@robwalch robwalch added this to the 1.3.0 milestone Dec 20, 2022
@robwalch robwalch merged commit 7dc7f64 into video-dev:master Dec 20, 2022
@erankor erankor deleted the fill-missing-rr-attrs branch December 21, 2022 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants