stream.hls_playlist: refactor M3U8Parser #4540
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
and cache mapping as class attribute (avoid parent class lookups)
parse_line()
parse_tag_...
methods by definition order of RFC 8216parse_tag_...
method with link to RFC 8216parse_tag_...
methodand update parse methods accordingly
This improves the performance of the
M3U8Parser
, as it doesn't have to generate a string with the name of supported tag methods for each tag anymore, and it can simply look up tags in a pre-generated mapping of tags->callbacks that get only built once after the first instantiation of the class. This is fully compatible withM3U8Parser
subclasses which override or add tag methods, and nothing has to be changed by those subclasses (tag method names stay the same). Subclasses have their own cache.One thing to note is that the parser doesn't call
tag.lower()
anymore inparse_line()
, which means that if for some reason an HLS playlist includes lowercase tag names or anything that doesn't match the exact case of the tag names, those invalid tags won't be recognized anymore, because tags are case sensitive.These changes will introduce a merge conflict with #4538.