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: add support for #EXT-X-I-FRAMES-ONLY #173

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Manifest {
* [EXT-X-MAP](http://tools.ietf.org/html/draft-pantos-http-live-streaming#section-4.3.2.5)
* [EXT-X-PROGRAM-DATE-TIME](http://tools.ietf.org/html/draft-pantos-http-live-streaming#section-4.3.2.6)
* [EXT-X-DATERANGE](https://datatracker.ietf.org/doc/html/draft-pantos-http-live-streaming-23#section-4.3.2.7)
* [EXT-X-I-FRAMES-ONLY](http://tools.ietf.org/html/draft-pantos-http-live-streaming#section-4.3.3.6)

### Media Playlist Tags

Expand Down Expand Up @@ -244,7 +245,6 @@ Example media playlist using `EXT-X-CUE-` tags.

### Not Yet Supported

* [EXT-X-I-FRAMES-ONLY](http://tools.ietf.org/html/draft-pantos-http-live-streaming#section-4.3.3.6)
* [EXT-X-SESSION-DATA](http://tools.ietf.org/html/draft-pantos-http-live-streaming#section-4.3.4.4)
* [EXT-X-SESSION-KEY](http://tools.ietf.org/html/draft-pantos-http-live-streaming#section-4.3.4.5)

Expand Down
11 changes: 11 additions & 0 deletions src/parse-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,16 @@ export default class ParseStream extends Stream {
});
return;
}

match = (/^#EXT-X-I-FRAMES-ONLY/).exec(newLine);
if (match) {
this.trigger('data', {
type: 'tag',
tagType: 'i-frames-only'
});
return;
}

match = (/^#EXT-X-CONTENT-STEERING:(.*)$/).exec(newLine);
if (match) {
event = {
Expand All @@ -646,6 +656,7 @@ export default class ParseStream extends Stream {
};
event.attributes = parseAttributes(match[1]);
this.trigger('data', event);

return;
}

Expand Down
13 changes: 13 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,11 @@ export default class Parser extends Stream {
'independent-segments'() {
this.manifest.independentSegments = true;
},
'i-frames-only'() {
this.manifest.iFramesOnly = true;

this.requiredCompatibilityversion(this.manifest.version, 4);
},
'content-steering'() {
this.manifest.contentSteering = camelCaseKeys(entry.attributes);
this.warnOnMissingAttributes_(
Expand Down Expand Up @@ -798,6 +803,14 @@ export default class Parser extends Stream {
});
}

requiredCompatibilityversion(currentVersion, targetVersion) {
if (currentVersion < targetVersion || !currentVersion) {
this.trigger('warn', {
message: `manifest must be at least version ${targetVersion}`
});
}
}

warnOnMissingAttributes_(identifier, attributes, required) {
const missing = [];

Expand Down
44 changes: 44 additions & 0 deletions test/fixtures/integration/iFramesOnly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module.exports = {
allowCache: true,
dateRanges: [],
iFramesOnly: true,
mister-ben marked this conversation as resolved.
Show resolved Hide resolved
mediaSequence: 0,
playlistType: 'VOD',
segments: [
{
duration: 2.002,
timeline: 0,
uri: '001.ts'
},
{
duration: 2.002,
timeline: 0,
uri: '002.ts'
},
{
duration: 2.002,
timeline: 0,
uri: '003.ts'
},
{
duration: 2.002,
timeline: 0,
uri: '004.ts'
},
{
duration: 2.002,
timeline: 0,
uri: '005.ts'
},
{
duration: 2.002,
timeline: 0,
uri: '006.ts'
}
],
targetDuration: 3,
endList: true,
discontinuitySequence: 0,
discontinuityStarts: [],
version: 4
};
19 changes: 19 additions & 0 deletions test/fixtures/integration/iFramesOnly.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#EXTM3U
#EXT-X-VERSION:4
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:3
#EXT-X-I-FRAMES-ONLY
#EXTINF:2.002,
001.ts
#EXTINF:2.002,
002.ts
#EXTINF:2.002,
003.ts
#EXTINF:2.002,
004.ts
#EXTINF:2.002,
005.ts
#EXTINF:2.002,
006.ts
#EXT-X-ENDLIST
14 changes: 14 additions & 0 deletions test/parse-stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1020,3 +1020,17 @@ QUnit.test('parses #EXT-X-I-FRAME-STREAM-INF', function(assert) {
assert.strictEqual(element.attributes['HDCP-LEVEL'], 'TYPE-1', 'the HDCP level is parsed');
assert.strictEqual(element.attributes.URI, 'hdr10_2160/iframe_index.m3u8', 'the uri text is parsed');
});

QUnit.test('parses #EXT-X-I-FRAMES-ONLY', function(assert) {
const manifest = '#EXT-X-I-FRAMES-ONLY\n';
let element;

this.parseStream.on('data', function(elem) {
element = elem;
});
this.lineStream.push(manifest);

assert.ok(element, 'an event was triggered');
assert.strictEqual(element.type, 'tag', 'the line type is tag');
assert.strictEqual(element.tagType, 'i-frames-only', 'the tag type is i-frames-only');
});
69 changes: 69 additions & 0 deletions test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,75 @@ QUnit.module('m3u8s', function(hooks) {
assert.equal(this.parser.manifest.independentSegments, true);
});

QUnit.test('warns when #EXT-X-I-FRAMES-ONLY the minimum version required is not supported', function(assert) {
this.parser.push([
'#EXTM3U',
'#EXT-X-VERSION:3',
'#EXT-X-PLAYLIST-TYPE:VOD',
'#EXT-X-MEDIA-SEQUENCE:0',
'#EXT-X-TARGETDURATION:3',
'#EXT-X-I-FRAMES-ONLY',
'#EXTINF:2.002,',
'001.ts',
'#EXTINF:2.002,',
'002.ts',
'#EXTINF:2.002,',
'003.ts',
'#EXTINF:2.002,',
'004.ts',
'#EXTINF:2.002,',
'005.ts',
'#EXTINF:2.002,',
'006.ts',
'#EXT-X-ENDLIST'
].join('\n'));
this.parser.end();

const warnings = [
'manifest must be at least version 4'
];

assert.deepEqual(
this.warnings,
warnings,
'warnings as expected'
);
});

QUnit.test('warns when #EXT-X-I-FRAMES-ONLY does not contain a version number', function(assert) {
this.parser.push([
'#EXTM3U',
'#EXT-X-PLAYLIST-TYPE:VOD',
'#EXT-X-MEDIA-SEQUENCE:0',
'#EXT-X-TARGETDURATION:3',
'#EXT-X-I-FRAMES-ONLY',
'#EXTINF:2.002,',
'001.ts',
'#EXTINF:2.002,',
'002.ts',
'#EXTINF:2.002,',
'003.ts',
'#EXTINF:2.002,',
'004.ts',
'#EXTINF:2.002,',
'005.ts',
'#EXTINF:2.002,',
'006.ts',
'#EXT-X-ENDLIST'
].join('\n'));
this.parser.end();

const warnings = [
'manifest must be at least version 4'
];

assert.deepEqual(
this.warnings,
warnings,
'warnings as expected'
);
});

QUnit.test('parses #EXT-X-CONTENT-STEERING', function(assert) {
const expectedContentSteeringObject = {
serverUri: '/foo?bar=00012',
Expand Down
Loading