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

Add support for HLS tags with both value and attributes #1810

Conversation

MilosRasic
Copy link
Contributor

@MilosRasic MilosRasic commented Feb 18, 2019

Fixes the problem reported in #1808

HLS parser wrongly assumes that a tag may have either a value or attributes, not both.

The RFC doesn't describe a general tag format or even give a name to what's called tag value in the Shaka Player codebase, but it clearly gives the format of EXTINF tag:

#EXTINF:<duration>,[<title>]

This PR makes the following changes:

  • Removes either value or attributes validation from shaka.hls.Tag
  • Simplifies branching and adds a check for value in the list of attributes in shaka.hls.ManifestTextParser.parseTag()
  • Removes misuse of let in shaka.hls.ManifestTextParser.parseTag(), most local variables are never reassigned and can be const
  • Adds a test case to guard against regression

Copy link
Contributor

@theodab theodab left a comment

Choose a reason for hiding this comment

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

Overall this looks pretty good to me.

if (blockValue) {
value = blockValue[1];
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you move attributeRegex to here, so no unrelated code is between it being declared and it being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather define regexes in one place and use them later as needed, but you're the maintainer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it's just personal preference. I don't even know if the rest of the team would agree with me, but I'm the first responder so I get to make the calls.

'(1) <NAME>:<VALUE> ' +
'(2) <NAME>:<ATTRIBUTE_LIST> ' +
' (3) <NAME>');

/** @const {number} */
this.id = id;

Copy link
Contributor

Choose a reason for hiding this comment

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

A bit below this, Tag has a "toString" method. That method was also made assuming that tags cannot have both values and attribute lists. It should also be updated to account for this change.

Correspondingly, there's also a few simple tests for "toString" in the manifest text parser unit tests. There should be a new test for attribute+value tags in that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Been a while since I've used protoypes directly. The new test case also caught that hls.Tag.toString() is treating all attributes as strings and stringifying them with quotes, so I added numeric value detection to avoid adding quotes. Detecting a numeric string with isNan(Number(str)) is shaky but all the ways of tricking it that I know shouldn't happen in this case.

An attribute's format is 'AttributeName=AttributeValue'.
The parsing logic goes like this:
1. Everything before ':' is a name (we ignore '#').
2. Everything after should be parsed as attributes if it contains '='.
3. Otherwise, this is a value.
2. Everything after ':' is a list of items,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is confusingly worded. I think it'd be clearer like...

  1. Everything after ':' is a list of comma-separated items.
    2a. The first item might be a value, if it does not contain '='.
    2b. Otherwise, items are attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it was better originally but exceeded the 80 character limit, then it went downhill. Copy-pasted your wording. Sounds much better.

…tes and stringify numeric attributes properly, small code style and comment changes
@theodab
Copy link
Contributor

theodab commented Feb 20, 2019

Okay, I think this looks good now. Thanks for the PR!

@theodab theodab merged commit 5db06a6 into shaka-project:master Feb 20, 2019
@shaka-bot
Copy link
Collaborator

All tests passed!

@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Jul 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants