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

feat(HLS): Improve HLS parsing time #5264

Merged
merged 6 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions lib/hls/hls_classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ goog.provide('shaka.hls.Segment');
goog.provide('shaka.hls.Tag');

goog.require('goog.asserts');
goog.require('shaka.hls.Utils');
goog.require('shaka.util.Error');


Expand Down Expand Up @@ -202,24 +203,43 @@ shaka.hls.Segment = class {
/**
* Creates an HLS segment object.
*
* @param {string} absoluteUri An absolute URI.
* @param {string} absoluteMediaPlaylistUri An absolute Media Playlist URI.
* @param {string} verbatimSegmentUri verbatim segment URI.
* @param {!Array.<shaka.hls.Tag>} tags
* @param {!Array.<shaka.hls.Tag>=} partialSegments
*/
constructor(absoluteUri, tags, partialSegments=[]) {
constructor(absoluteMediaPlaylistUri, verbatimSegmentUri, tags,
partialSegments=[]) {
/** @const {!Array.<shaka.hls.Tag>} */
this.tags = tags;

/**
* An absolute URI.
*
* @const {string}
*/
this.absoluteUri = absoluteUri;
/** @type {?string} */
this.absoluteUri_ = null;

/** @type {?string} */
this.absoluteMediaPlaylistUri_ = absoluteMediaPlaylistUri;

/** @type {?string} */
this.verbatimSegmentUri_ = verbatimSegmentUri;

/** @type {!Array.<shaka.hls.Tag>} */
this.partialSegments = partialSegments;
}

/**
* Returns an absolute URI.
*
* @return {string}
*/
get absoluteUri() {
if (!this.absoluteUri_) {
avelad marked this conversation as resolved.
Show resolved Hide resolved
this.absoluteUri_ = shaka.hls.Utils.constructAbsoluteUri(
this.absoluteMediaPlaylistUri_, this.verbatimSegmentUri_);
this.absoluteMediaPlaylistUri_ = null;
this.verbatimSegmentUri_ = null;
}
return this.absoluteUri_;
}
};


Expand Down
8 changes: 3 additions & 5 deletions lib/hls/manifest_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,13 @@ shaka.hls.ManifestTextParser = class {
// Skip comments.
} else {
const verbatimSegmentUri = line.trim();
const absoluteSegmentUri = shaka.hls.Utils.constructAbsoluteUri(
absoluteMediaPlaylistUri, verbatimSegmentUri);
// Attach the last parsed EXT-X-MAP tag to the segment.
if (currentMapTag) {
segmentTags.push(currentMapTag);
}
// The URI appears after all of the tags describing the segment.
const segment = new shaka.hls.Segment(absoluteSegmentUri, segmentTags,
partialSegmentTags);
const segment = new shaka.hls.Segment(absoluteMediaPlaylistUri,
verbatimSegmentUri, segmentTags, partialSegmentTags);
segments.push(segment);
segmentTags = [];
partialSegmentTags = [];
Expand All @@ -195,7 +193,7 @@ shaka.hls.ManifestTextParser = class {
if (currentMapTag) {
segmentTags.push(currentMapTag);
}
const segment = new shaka.hls.Segment('', segmentTags,
const segment = new shaka.hls.Segment('', '', segmentTags,
partialSegmentTags);
segments.push(segment);
}
Expand Down
31 changes: 18 additions & 13 deletions test/hls/manifest_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ describe('ManifestTextParser', () => {
new shaka.hls.Tag(/* id= */ 0, 'EXT-X-MEDIA-SEQUENCE', [], '1'),
],
segments: [
new shaka.hls.Segment('https://test/test.mp4',
new shaka.hls.Segment('https://test/manifest.m3u8', 'https://test/test.mp4',
[
new shaka.hls.Tag(/* id= */ 2, 'EXTINF', [], '5.99467'),
]),
Expand All @@ -332,7 +332,7 @@ describe('ManifestTextParser', () => {
new shaka.hls.Tag(/* id= */ 0, 'EXT-X-MEDIA-SEQUENCE', [], '1'),
],
segments: [
new shaka.hls.Segment('https://test/test.mp4', [
new shaka.hls.Segment('https://test/manifest.m3u8', 'https://test/test.mp4', [
new shaka.hls.Tag(
/* id= */ 2,
'EXTINF',
Expand Down Expand Up @@ -360,7 +360,7 @@ describe('ManifestTextParser', () => {
new shaka.hls.Tag(/* id= */ 2, 'EXT-X-TARGETDURATION', [], '6'),
],
segments: [
new shaka.hls.Segment('https://test/test.mp4',
new shaka.hls.Segment('https://test/manifest.m3u8', 'https://test/test.mp4',
[
new shaka.hls.Tag(/* id= */ 1, 'EXT-X-KEY',
[
Expand Down Expand Up @@ -393,7 +393,7 @@ describe('ManifestTextParser', () => {
new shaka.hls.Tag(/* id= */ 0, 'EXT-X-MEDIA-SEQUENCE', [], '1'),
],
segments: [
new shaka.hls.Segment('https://test/test.mp4',
new shaka.hls.Segment('https://test/manifest.m3u8', 'test.mp4',
[
new shaka.hls.Tag(/* id= */ 2, 'EXTINF', [], '5.99467'),
]),
Expand Down Expand Up @@ -427,9 +427,9 @@ describe('ManifestTextParser', () => {
new shaka.hls.Tag(/* id= */ 0, 'EXT-X-TARGETDURATION', [], '6'),
],
segments: [
new shaka.hls.Segment('https://test/uri',
new shaka.hls.Segment('https://test/manifest.m3u8', 'uri',
[new shaka.hls.Tag(2, 'EXTINF', [], '5')]),
new shaka.hls.Segment('https://test/uri2',
new shaka.hls.Segment('https://test/manifest.m3u8', 'uri2',
[new shaka.hls.Tag(3, 'EXTINF', [], '4')]),
],
},
Expand All @@ -449,9 +449,9 @@ describe('ManifestTextParser', () => {
new shaka.hls.Tag(/* id= */ 4, 'EXT-X-ENDLIST', []),
],
segments: [
new shaka.hls.Segment('https://test/uri',
new shaka.hls.Segment('https://test/manifest.m3u8', 'uri',
[new shaka.hls.Tag(2, 'EXTINF', [], '5')]),
new shaka.hls.Segment('https://test/uri2',
new shaka.hls.Segment('https://test/manifest.m3u8', 'uri2',
[new shaka.hls.Tag(3, 'EXTINF', [], '4')]),
],
},
Expand Down Expand Up @@ -508,20 +508,23 @@ describe('ManifestTextParser', () => {
],
segments: [
new shaka.hls.Segment(
/* absoluteUri= */ 'https://test/uri',
/* absoluteMediaPlaylistUri= */ 'https://test/manifest.m3u8',
/* verbatimSegmentUri= */ 'uri',
/* tags= */ [
new shaka.hls.Tag(3, 'EXTINF', [], '5'),
mapTag,
]),
new shaka.hls.Segment(
/* absoluteUri= */ 'https://test/uri2',
/* absoluteMediaPlaylistUri= */ 'https://test/manifest.m3u8',
/* verbatimSegmentUri= */ 'uri2',
/* tags= */ [
new shaka.hls.Tag(6, 'EXTINF', [], '2'),
mapTag,
],
/* partialSegments= */ partialSegments1),
new shaka.hls.Segment(
/* absoluteUri= */ '',
/* absoluteMediaPlaylistUri= */ '',
/* verbatimSegmentUri= */ '',
/* tags= */ [mapTag],
/* partialSegments= */ partialSegments2),
],
Expand Down Expand Up @@ -574,13 +577,15 @@ describe('ManifestTextParser', () => {
],
segments: [
new shaka.hls.Segment(
/* absoluteUri= */ 'https://test/uri',
/* absoluteMediaPlaylistUri= */ 'https://test/manifest.m3u8',
/* verbatimSegmentUri= */ 'uri',
/* tags= */ [
new shaka.hls.Tag(3, 'EXTINF', [], '5'),
mapTag,
]),
new shaka.hls.Segment(
/* absoluteUri= */ '',
/* absoluteMediaPlaylistUri= */ '',
/* verbatimSegmentUri= */ '',
/* tags= */ [preloadMapTag],
/* partialSegments= */ preloadSegment),
],
Expand Down