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): parse EXT-X-GAP #4134

Merged
merged 1 commit into from Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/hls/hls_parser.js
Expand Up @@ -1865,6 +1865,11 @@ shaka.hls.HlsParser = class {
}
}

let status = shaka.media.SegmentReference.Status.AVAILABLE;
if (shaka.hls.Utils.getFirstTagWithName(tags, 'EXT-X-GAP')) {
status = shaka.media.SegmentReference.Status.MISSING;
}

// Create SegmentReferences for the partial segments.
const partialSegmentRefs = [];
if (this.lowLatencyMode_ && hlsSegment.partialSegments.length) {
Expand Down Expand Up @@ -1978,6 +1983,7 @@ shaka.hls.HlsParser = class {
tilesLayout,
tileDuration,
syncTime,
status,
);
}

Expand Down
41 changes: 40 additions & 1 deletion lib/media/segment_reference.js
Expand Up @@ -162,12 +162,15 @@ shaka.media.SegmentReference = class {
* @param {?number=} syncTime
* A time value, expressed in the same scale as the start and end time, which
* is used to synchronize between streams.
* @param {shaka.media.SegmentReference.Status=} status
* The segment status is used to indicate that a segment does not exist or is
* not available.
*/
constructor(
startTime, endTime, uris, startByte, endByte, initSegmentReference,
timestampOffset, appendWindowStart, appendWindowEnd,
partialReferences = [], tilesLayout = '', tileDuration = null,
syncTime = null) {
syncTime = null, status = shaka.media.SegmentReference.Status.AVAILABLE) {
// A preload hinted Partial Segment has the same startTime and endTime.
goog.asserts.assert(startTime <= endTime,
'startTime must be less than or equal to endTime');
Expand Down Expand Up @@ -220,6 +223,9 @@ shaka.media.SegmentReference = class {

/** @type {?number} */
this.syncTime = syncTime;

/** @type {shaka.media.SegmentReference.Status} */
this.status = status;
}

/**
Expand Down Expand Up @@ -315,6 +321,39 @@ shaka.media.SegmentReference = class {
getTileDuration() {
return this.tileDuration;
}

/**
* Returns the segment's status.
*
* @return {shaka.media.SegmentReference.Status}
* @export
*/
getStatus() {
return this.status;
}

/**
* Mark the reference as unavailable.
*
* @export
*/
markAsUnavailable() {
this.status = shaka.media.SegmentReference.Status.UNAVAILABLE;
}
};


/**
* Rather than using booleans to communicate what the state of the reference,
* we have this enum.
*
* @enum {number}
* @export
*/
shaka.media.SegmentReference.Status = {
AVAILABLE: 0,
UNAVAILABLE: 1,
MISSING: 2,
};


Expand Down
99 changes: 99 additions & 0 deletions test/hls/hls_parser_unit.js
Expand Up @@ -1424,6 +1424,105 @@ describe('HlsParser', () => {
}
});

it('parse EXT-X-GAP', async () => {
const master = [
'#EXTM3U\n',
'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="eng",',
'CHANNELS="2",URI="audio"\n',
'#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1,mp4a",',
'RESOLUTION=960x540,FRAME-RATE=60,AUDIO="aud1"\n',
'video\n',
].join('');

const video = [
'#EXTM3U\n',
'#EXT-X-PLAYLIST-TYPE:VOD\n',
'#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n',
'#EXTINF:5,\n',
'main.mp4\n',
'#EXTINF:5,\n',
'#EXT-X-GAP\n',
'main.mp4\n',
'#EXTINF:5,\n',
'main.mp4\n',
].join('');

const audio = [
'#EXTM3U\n',
'#EXT-X-PLAYLIST-TYPE:VOD\n',
'#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n',
'#EXTINF:5,\n',
'main.mp4\n',
'#EXTINF:5,\n',
'#EXT-X-GAP\n',
'main.mp4\n',
'#EXTINF:5,\n',
'main.mp4\n',
].join('');

fakeNetEngine
.setResponseText('test:/master', master)
.setResponseText('test:/audio', audio)
.setResponseText('test:/video', video)
.setResponseValue('test:/init.mp4', initSegmentData)
.setResponseValue('test:/main.mp4', segmentData);

const actual = await parser.start('test:/master', playerInterface);

expect(actual.variants.length).toBe(1);

const variant = actual.variants[0];
expect(variant.video).toBeTruthy();
expect(variant.audio).toBeTruthy();

const available = shaka.media.SegmentReference.Status.AVAILABLE;
const missing = shaka.media.SegmentReference.Status.MISSING;

await variant.video.createSegmentIndex();
goog.asserts.assert(variant.video.segmentIndex != null,
'Null segmentIndex!');

const firstVideoReference = variant.video.segmentIndex.get(0);
const secondVideoReference = variant.video.segmentIndex.get(1);
const thirdVideoReference = variant.video.segmentIndex.get(2);

expect(firstVideoReference).not.toBe(null);
expect(secondVideoReference).not.toBe(null);
expect(thirdVideoReference).not.toBe(null);

if (firstVideoReference) {
expect(firstVideoReference.getStatus()).toBe(available);
}
if (secondVideoReference) {
expect(secondVideoReference.getStatus()).toBe(missing);
}
if (thirdVideoReference) {
expect(thirdVideoReference.getStatus()).toBe(available);
}

await variant.audio.createSegmentIndex();
goog.asserts.assert(variant.audio.segmentIndex != null,
'Null segmentIndex!');

const firstAudioReference = variant.audio.segmentIndex.get(0);
const secondAudioReference = variant.audio.segmentIndex.get(1);
const thirdAudioReference = variant.audio.segmentIndex.get(2);

expect(firstAudioReference).not.toBe(null);
expect(secondAudioReference).not.toBe(null);
expect(thirdAudioReference).not.toBe(null);

if (firstAudioReference) {
expect(firstAudioReference.getStatus()).toBe(available);
}
if (secondAudioReference) {
expect(secondAudioReference.getStatus()).toBe(missing);
}
if (thirdAudioReference) {
expect(thirdAudioReference.getStatus()).toBe(available);
}
});

it('Disable audio does not create audio streams', async () => {
const master = [
'#EXTM3U\n',
Expand Down