Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Jan 21, 2021
1 parent e1b8202 commit e21afd7
Show file tree
Hide file tree
Showing 6 changed files with 487 additions and 86 deletions.
76 changes: 38 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@
"@rollup/plugin-replace": "^2.3.4",
"@videojs/generator-helpers": "~2.0.1",
"karma": "^5.2.3",
"rollup": "^2.36.1",
"rollup": "^2.37.1",
"rollup-plugin-data-files": "^0.1.0",
"sinon": "^9.2.3",
"videojs-generate-karma-config": "~7.0.0",
"videojs-generate-rollup-config": "~6.1.0",
"videojs-generate-karma-config": "~7.1.0",
"videojs-generate-rollup-config": "~6.2.0",
"videojs-generator-verify": "~3.0.1",
"videojs-standard": "^8.0.4"
},
Expand Down
70 changes: 39 additions & 31 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ const setHoldBack = function(manifest) {
if (partTargetDuration && !serverControl.hasOwnProperty(phb)) {
serverControl[phb] = partTargetDuration * 3;
this.trigger('info', {
message: `${tag} defaulting ${phb} to partTargetDuration * 3 ${serverControl[phb]}.`
message: `${tag} defaulting ${phb} to partTargetDuration * 3 (${serverControl[phb]}).`
});
}

// if part hold back is too small default it to part target duration * 2
if (partTargetDuration && serverControl[phb] < (minPartDuration)) {
this.trigger('warn', {
message: `${tag} clamping ${phb} (${serverControl[phb]}) to partTargetDuration * 2 ${minPartDuration}).`
message: `${tag} clamping ${phb} (${serverControl[phb]}) to partTargetDuration * 2 (${minPartDuration}).`
});

serverControl[phb] = minPartDuration;
Expand Down Expand Up @@ -440,32 +440,44 @@ export default class Parser extends Stream {

if (!entry.attributes.hasOwnProperty('SKIPPED-SEGMENTS')) {
this.trigger('warn', {
message: '#EXT-X-SKIP SKIPPED-SEGMENTS is required but missing!'
message: '#EXT-X-SKIP lacks required attribute SKIPPED-SEGMENTS'
});
}
},
'part'() {
this.manifest.parts = this.manifest.parts || [];
this.manifest.parts.push(entry.attributes);
let message = `#EXT-X-PART #${this.manifest.parts.length - 1} lacks`;
let warn = true;
const missingAttributes = [];

['URI', 'DURATION'].forEach(function(k) {
if (!entry.attributes[k]) {
message += ` ${k}`;
warn = true;
missingAttributes.push(k);
}
});

if (warn) {
this.trigger('warn', {message});
if (missingAttributes.length) {
const index = this.manifest.parts.length - 1;

this.trigger('warn', {
message: `#EXT-X-PART #${index} lacks required attribute(s) ${missingAttributes.join(', ')}`
});
}

if (this.manifest.renditionReports) {
this.manifest.renditionReports.forEach((r, i) => {
if (!r.hasOwnProperty('LAST-PART')) {
this.trigger('warn', {
message: `#EXT-X-RENDITION-REPORT #${i} lacks required attribute(s) LAST-PART`
});
}
});
}
},
'server-control'() {
const attrs = entry.attributes;

this.manifest.serverControl = attrs;
if (!attrs['CAN-BLOCK-RELOAD']) {
if (!attrs.hasOwnProperty('CAN-BLOCK-RELOAD')) {
this.manifest.serverControl['CAN-BLOCK-RELOAD'] = false;
this.trigger('info', {
message: '#EXT-X-SERVER-CONTROL defaulting CAN-BLOCK-RELOAD to false'
Expand All @@ -474,9 +486,8 @@ export default class Parser extends Stream {
setHoldBack.call(this, this.manifest);

if (attrs.hasOwnProperty('CAN-SKIP-DATERANGES') && !attrs.hasOwnProperty('CAN-SKIP-UNTIL')) {

this.trigger('warn', {
message: '#EXT-X-SERVER-CONTROL CAN-SKIP-DATERANGES requires CAN-SKIP-UNTIL but it is not present'
message: '#EXT-X-SERVER-CONTROL lacks required attribute CAN-SKIP-UNTIL which is required when CAN-SKIP-DATERANGES is set'
});

}
Expand All @@ -485,52 +496,49 @@ export default class Parser extends Stream {
this.manifest.preloadHints = this.manifest.preloadHints || [];
this.manifest.preloadHints.push(entry.attributes);

let message = `#EXT-X-PRELOAD-HINT #${this.manifest.preloadHints.length - 1} lacks`;
let warn = true;
const missingAttributes = [];

['TYPE', 'URI'].forEach(function(k) {
if (!entry.attributes[k]) {
message += ` ${k}`;
warn = true;
missingAttributes.push(k);
}
});

if (warn) {
this.trigger('warn', {message});
if (missingAttributes.length) {
const index = this.manifest.preloadHints.length - 1;

this.trigger('warn', {
message: `#EXT-X-PRELOAD-HINT #${index} lacks required attribute(s) ${missingAttributes.join(', ')}`
});
}
},
'rendition-report'() {
this.manifest.renditionReports = this.manifest.renditionReports || [];
this.manifest.renditionReports.push(entry.attributes);
const index = this.manifest.renditionReports.length - 1;
let message = `#EXT-X-RENDITION-REPORT #${index} lacks`;
let warn = true;
const missingAttributes = [];
const warning = `#EXT-X-RENDITION-REPORT #${index} lacks required attribute(s)`;

['LAST-MSN', 'URI'].forEach(function(k) {
if (!entry.attributes[k]) {
message += ` ${k}`;
warn = true;
missingAttributes.push(k);
}
});

if (warn) {
this.trigger('warn', {message});
if (this.manifest.parts && !entry.attributes['LAST-PART']) {
missingAttributes.push('LAST-PART');
}

if (this.manifest.parts && !entry.attributes['LAST-PART']) {
// its only likely, as its not required for all renditions to have parts,
// but if the current one does than it likely.
this.trigger('warn', {
message: `#EXT-X-RENDITION-REPORT #${index} likely lacks required LAST-PART`
});
if (missingAttributes.length) {
this.trigger('warn', {message: `${warning} ${missingAttributes.join(', ')}`});
}
},
'part-inf'() {
this.manifest.partInf = entry.attributes;

if (!entry.attributes.hasOwnProperty('PART-TARGET')) {
this.trigger('warn', {
message: '#EXT-X-PART-INF lacks required PART-TARGET'
message: '#EXT-X-PART-INF lacks required attribute PART-TARGET'
});
} else {
this.manifest.partTargetDuration = entry.attributes['PART-TARGET'];
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/integration/llhls.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
"mediaSequence": 266,
"preloadHints": [
{"TYPE": "PART", "URI": "filePart273.3.mp4"},
{"TYPE": "PART", "URI": "filePart273.4.mp4"}
{"TYPE": "PART", "URI": "filePart273.4.mp4", "BYTERANGE-LENGTH": 10, "BYTERANGE-START": 0}
],
"renditionReports": [
{"LAST-MSN": 273, "LAST-PART": 2, "URI": "../1M/waitForMSN.php"},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/integration/llhls.m3u8
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fileSequence272.mp4
#EXT-X-PART:DURATION=0.33334,URI="filePart273.1.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart273.2.mp4"
#EXT-X-PRELOAD-HINT:TYPE=PART,URI="filePart273.3.mp4"
#EXT-X-PRELOAD-HINT:TYPE=PART,URI="filePart273.4.mp4"
#EXT-X-PRELOAD-HINT:TYPE=PART,URI="filePart273.4.mp4",BYTERANGE-START=0,BYTERANGE-LENGTH=10

#EXT-X-RENDITION-REPORT:URI="../1M/waitForMSN.php",LAST-MSN=273,LAST-PART=2
#EXT-X-RENDITION-REPORT:URI="../4M/waitForMSN.php",LAST-MSN=273,LAST-PART=1
Loading

0 comments on commit e21afd7

Please sign in to comment.