From be6b06f5faff9496b68922089be729601f50eca5 Mon Sep 17 00:00:00 2001
From: ishita12 <30434843+ishita12@users.noreply.github.com>
Date: Tue, 13 Feb 2018 10:17:43 -0500
Subject: [PATCH 1/9] Adding support for segments in Period and Representation
---
package-lock.json | 5 +
package.json | 1 +
src/inheritAttributes.js | 33 ++-
test/inheritAttributes.test.js | 485 +++++++++++++++++++++++++++++++++
4 files changed, 511 insertions(+), 13 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index a11a6282..9007aa41 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1615,6 +1615,11 @@
"integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=",
"dev": true
},
+ "deepmerge": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-2.0.1.tgz",
+ "integrity": "sha512-VIPwiMJqJ13ZQfaCsIFnp5Me9tnjURiaIFxfz7EH0Ci0dTSQpZtSLrqOicXqEd/z2r+z+Klk9GzmnRsgpgbOsQ=="
+ },
"define-properties": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.2.tgz",
diff --git a/package.json b/package.json
index d7333240..5123f1f5 100644
--- a/package.json
+++ b/package.json
@@ -86,6 +86,7 @@
"version": "5.0.0"
},
"dependencies": {
+ "deepmerge": "^2.0.1",
"global": "^4.3.0",
"url-toolkit": "^2.1.1"
}
diff --git a/src/inheritAttributes.js b/src/inheritAttributes.js
index 285427f6..d5946a01 100644
--- a/src/inheritAttributes.js
+++ b/src/inheritAttributes.js
@@ -4,6 +4,7 @@ import { parseDuration } from './utils/time';
import { findChildren, getContent } from './utils/xml';
import resolveUrl from './utils/resolveUrl';
import errors from './errors';
+import merge from 'deepmerge';
/**
* Builds a list of urls that is the product of the reference urls and BaseURL values
@@ -131,17 +132,21 @@ export const getSegmentInformation = (adaptationSet) => {
* Callback map function
*/
export const inheritBaseUrls =
-(adaptationSetAttributes, adaptationSetBaseUrls, segmentInfo) => (representation) => {
+(adaptationSetAttributes, adaptationSetBaseUrls, periodAdaptationSetInfo) => (representation) => {
const repBaseUrlElements = findChildren(representation, 'BaseURL');
const repBaseUrls = buildBaseUrls(adaptationSetBaseUrls, repBaseUrlElements);
const attributes = shallowMerge(adaptationSetAttributes, getAttributes(representation));
-
- return repBaseUrls.map(baseUrl => {
- return {
- segmentInfo,
- attributes: shallowMerge(attributes, { baseUrl })
- };
- });
+ const segmentInfoFromRepresenation = getSegmentInformation(representation);
+ const segmentRepresentationInfo = merge(periodAdaptationSetInfo, segmentInfoFromRepresenation);
+
+ if (segmentRepresentationInfo) {
+ return repBaseUrls.map(baseUrl => {
+ return {
+ segmentInfo: segmentRepresentationInfo,
+ attributes: shallowMerge(attributes, { baseUrl })
+ };
+ });
+ }
};
/**
@@ -167,7 +172,7 @@ export const inheritBaseUrls =
* Callback map function
*/
export const toRepresentations =
-(periodAttributes, periodBaseUrls) => (adaptationSet) => {
+(periodAttributes, periodBaseUrls, periodInfo) => (adaptationSet) => {
const adaptationSetAttributes = getAttributes(adaptationSet);
const adaptationSetBaseUrls = buildBaseUrls(periodBaseUrls,
findChildren(adaptationSet, 'BaseURL'));
@@ -178,9 +183,10 @@ export const toRepresentations =
roleAttributes);
const segmentInfo = getSegmentInformation(adaptationSet);
const representations = findChildren(adaptationSet, 'Representation');
+ const periodAdaptationSetInfo = merge(periodInfo, segmentInfo);
return flatten(
- representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, segmentInfo)));
+ representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, periodAdaptationSetInfo)));
};
/**
@@ -210,10 +216,12 @@ export const toRepresentations =
*/
export const toAdaptationSets = (mpdAttributes, mpdBaseUrls) => (period, periodIndex) => {
const periodBaseUrls = buildBaseUrls(mpdBaseUrls, findChildren(period, 'BaseURL'));
- const periodAttributes = shallowMerge({ periodIndex }, mpdAttributes);
+ const periodAtt = getAttributes(period);
+ const periodAttributes = shallowMerge(periodAtt, { periodIndex }, mpdAttributes);
const adaptationSets = findChildren(period, 'AdaptationSet');
+ const periodInfo = getSegmentInformation(period);
- return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls)));
+ return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls, periodInfo)));
};
/**
@@ -243,4 +251,3 @@ export const inheritAttributes = (mpd, manifestUri = '') => {
return flatten(periods.map(toAdaptationSets(mpdAttributes, mpdBaseUrls)));
};
-
diff --git a/test/inheritAttributes.test.js b/test/inheritAttributes.test.js
index aa04067f..d274c9fa 100644
--- a/test/inheritAttributes.test.js
+++ b/test/inheritAttributes.test.js
@@ -197,6 +197,7 @@ QUnit.test('end to end - basic', function(assert) {
height="404"
id="test"
width="720">
+
@@ -273,6 +274,7 @@ QUnit.test('end to end - inherits BaseURL from all levels', function(assert) {
id="test"
width="720">
buzz/
+
@@ -349,6 +351,7 @@ QUnit.test('end to end - alternate BaseURLs', function(assert) {
height="404"
id="test"
width="720">
+
@@ -490,3 +493,485 @@ QUnit.test('end to end - alternate BaseURLs', function(assert) {
assert.equal(actual.length, 6);
assert.deepEqual(actual, expected);
});
+
+QUnit.test(' End to End test for representation', function(assert) {
+ const actual = inheritAttributes(stringToMpdXml(
+ `
+
+ https://www.example.com/base/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ https://example.com/en.vtt
+
+
+
+
+ `
+ ));
+
+ const expected = [{
+ attributes: {
+ bandwidth: '5000000',
+ baseUrl: 'https://www.example.com/base/',
+ codecs: 'avc1.64001e',
+ height: '404',
+ id: 'test',
+ mediaPresentationDuration: 'PT30S',
+ mimeType: 'video/mp6',
+ periodIndex: 0,
+ role: {
+ value: 'main'
+ },
+ sourceDuration: 30,
+ width: '720'
+ },
+ segmentInfo: {
+ base: {
+ indexRange: '820-2087',
+ indexRangeExact: 'true',
+ initialization: {
+ range: '0-567'
+ }
+ },
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }, {
+ attributes: {
+ baseUrl: 'https://www.example.com/base/',
+ mediaPresentationDuration: 'PT30S',
+ mimeType: 'video/mp4',
+ periodIndex: 0,
+ height: '545',
+ role: {
+ value: 'main'
+ },
+ sourceDuration: 30
+ },
+ segmentInfo: {
+ base: {
+ indexRange: '820-2087',
+ indexRangeExact: 'true',
+ initialization: {
+ range: '0-987'
+ }
+ },
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }, {
+ attributes: {
+ bandwidth: '256',
+ baseUrl: 'https://example.com/en.vtt',
+ id: 'en',
+ lang: 'en',
+ mediaPresentationDuration: 'PT30S',
+ mimeType: 'text/vtt',
+ periodIndex: 0,
+ role: {},
+ sourceDuration: 30
+ },
+ segmentInfo: {
+ base: undefined,
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }];
+
+ assert.equal(actual.length, 3);
+ assert.deepEqual(actual, expected);
+});
+
+// Testing for support of segment tags in period element
+
+QUnit.test(' End to End test for period', function(assert) {
+ const actual = inheritAttributes(stringToMpdXml(
+ `
+
+ https://www.example.com/base/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ https://example.com/en.vtt
+
+
+
+
+ `
+ ));
+
+ const expected = [{
+ attributes: {
+ bandwidth: '5000000',
+ baseUrl: 'https://www.example.com/base/',
+ duration: 'PT0H4M40.414S',
+ codecs: 'avc1.64001e',
+ height: '404',
+ id: 'test',
+ mediaPresentationDuration: 'PT30S',
+ mimeType: 'video/mp6',
+ periodIndex: 0,
+ role: {
+ value: 'main'
+ },
+ sourceDuration: 30,
+ width: '720'
+ },
+ segmentInfo: {
+ base: {
+ indexRange: '9999',
+ indexRangeExact: 'true',
+ initialization: {
+ range: '0-1111'
+ }
+ },
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }, {
+ attributes: {
+ baseUrl: 'https://www.example.com/base/',
+ mediaPresentationDuration: 'PT30S',
+ duration: 'PT0H4M40.414S',
+ mimeType: 'video/mp4',
+ periodIndex: 0,
+ height: '545',
+ role: {
+ value: 'main'
+ },
+ sourceDuration: 30
+ },
+ segmentInfo: {
+ base: {
+ indexRange: '9999',
+ indexRangeExact: 'false',
+ initialization: {
+ range: '0-1111'
+ }
+ },
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }, {
+ attributes: {
+ bandwidth: '256',
+ baseUrl: 'https://example.com/en.vtt',
+ duration: 'PT0H4M40.414S',
+ id: 'en',
+ lang: 'en',
+ mediaPresentationDuration: 'PT30S',
+ mimeType: 'text/vtt',
+ periodIndex: 0,
+ role: {},
+ sourceDuration: 30
+ },
+ segmentInfo: {
+ base: undefined,
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }];
+
+ assert.equal(actual.length, 3);
+ assert.deepEqual(actual, expected);
+});
+
+// Test for only periodAdaptationSetInfo
+
+QUnit.test(' End to End test for returning period info', function(assert) {
+ const actual = inheritAttributes(stringToMpdXml(
+ `
+
+ https://www.example.com/base/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ https://example.com/en.vtt
+
+
+
+
+
+ `
+ ));
+
+ const expected = [{
+ attributes: {
+ bandwidth: '5000000',
+ baseUrl: 'https://www.example.com/base/',
+ duration: 'PT0H4M40.414S',
+ codecs: 'avc1.64001e',
+ height: '404',
+ id: 'test',
+ mediaPresentationDuration: 'PT30S',
+ mimeType: 'video/mp6',
+ periodIndex: 0,
+ role: {
+ value: 'main'
+ },
+ sourceDuration: 30,
+ width: '720'
+ },
+ segmentInfo: {
+ base: {
+ indexRange: '9999',
+ indexRangeExact: 'true',
+ initialization: {
+ range: '0-1111'
+ }
+ },
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }, {
+ attributes: {
+ baseUrl: 'https://www.example.com/base/',
+ mediaPresentationDuration: 'PT30S',
+ duration: 'PT0H4M40.414S',
+ mimeType: 'video/mp4',
+ periodIndex: 0,
+ height: '545',
+ role: {
+ value: 'main'
+ },
+ sourceDuration: 30
+ },
+ segmentInfo: {
+ base: {
+ indexRange: '9999',
+ indexRangeExact: 'false',
+ initialization: {
+ range: '0-1111'
+ }
+ },
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }, {
+ attributes: {
+ bandwidth: '256',
+ baseUrl: 'https://example.com/en.vtt',
+ duration: 'PT0H4M40.414S',
+ id: 'en',
+ lang: 'en',
+ mediaPresentationDuration: 'PT30S',
+ mimeType: 'text/vtt',
+ periodIndex: 0,
+ role: {},
+ sourceDuration: 30
+ },
+ segmentInfo: {
+ base: {
+ indexRange: '9999',
+ indexRangeExact: 'false',
+ initialization: {
+ range: '0-1111'
+ }
+ },
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }];
+
+ assert.equal(actual.length, 3);
+ assert.deepEqual(actual, expected);
+});
+
+// testing for returning adaptation set information
+
+QUnit.test(' End to End test for returning adaptation set info', function(assert) {
+ const actual = inheritAttributes(stringToMpdXml(
+ `
+
+ https://www.example.com/base/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ https://example.com/en.vtt
+
+
+
+
+ `
+ ));
+
+ const expected = [{
+ attributes: {
+ bandwidth: '5000000',
+ baseUrl: 'https://www.example.com/base/',
+ duration: 'PT0H4M40.414S',
+ codecs: 'avc1.64001e',
+ height: '404',
+ id: 'test',
+ mediaPresentationDuration: 'PT30S',
+ mimeType: 'video/mp6',
+ periodIndex: 0,
+ role: {
+ value: 'main'
+ },
+ sourceDuration: 30,
+ width: '720'
+ },
+ segmentInfo: {
+ base: {
+ indexRange: '1212',
+ indexRangeExact: 'true',
+ initialization: {
+ range: '0-8888'
+
+ }
+ },
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }, {
+ attributes: {
+ baseUrl: 'https://www.example.com/base/',
+ mediaPresentationDuration: 'PT30S',
+ duration: 'PT0H4M40.414S',
+ mimeType: 'video/mp4',
+ periodIndex: 0,
+ height: '545',
+ role: {
+ value: 'main'
+ },
+ sourceDuration: 30
+ },
+ segmentInfo: {
+ base: {
+ indexRange: '1212',
+ indexRangeExact: 'false',
+ initialization: {
+ range: '0-8888'
+ }
+ },
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }, {
+ attributes: {
+ bandwidth: '256',
+ baseUrl: 'https://example.com/en.vtt',
+ duration: 'PT0H4M40.414S',
+ id: 'en',
+ lang: 'en',
+ mediaPresentationDuration: 'PT30S',
+ mimeType: 'text/vtt',
+ periodIndex: 0,
+ role: {},
+ sourceDuration: 30
+ },
+ segmentInfo: {
+ base: undefined,
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }];
+
+ assert.equal(actual.length, 3);
+ assert.deepEqual(actual, expected);
+});
From d5e4cbd104bc9831cceeac418a0c44cd67ca47f2 Mon Sep 17 00:00:00 2001
From: ishita12 <30434843+ishita12@users.noreply.github.com>
Date: Tue, 13 Feb 2018 14:00:16 -0500
Subject: [PATCH 2/9] Testing for getting atmost one segment at each level
---
src/inheritAttributes.js | 14 ++--
src/toPlaylists.js | 2 +-
test/inheritAttributes.test.js | 133 +++++++++++++++++++++++++++++++++
3 files changed, 140 insertions(+), 9 deletions(-)
diff --git a/src/inheritAttributes.js b/src/inheritAttributes.js
index d5946a01..a4360dc3 100644
--- a/src/inheritAttributes.js
+++ b/src/inheritAttributes.js
@@ -139,14 +139,12 @@ export const inheritBaseUrls =
const segmentInfoFromRepresenation = getSegmentInformation(representation);
const segmentRepresentationInfo = merge(periodAdaptationSetInfo, segmentInfoFromRepresenation);
- if (segmentRepresentationInfo) {
- return repBaseUrls.map(baseUrl => {
- return {
- segmentInfo: segmentRepresentationInfo,
- attributes: shallowMerge(attributes, { baseUrl })
- };
- });
- }
+ return repBaseUrls.map(baseUrl => {
+ return {
+ segmentInfo: segmentRepresentationInfo,
+ attributes: shallowMerge(attributes, { baseUrl })
+ };
+ });
};
/**
diff --git a/src/toPlaylists.js b/src/toPlaylists.js
index 6d5a95d8..f8a31d01 100644
--- a/src/toPlaylists.js
+++ b/src/toPlaylists.js
@@ -22,7 +22,7 @@ export const generateSegments = (segmentInfo, attributes) => {
}
};
-export const toPlaylists = representations => {
+export const toPlaylists = (representations) => {
return representations.map(({ attributes, segmentInfo }) => {
const segments = generateSegments(segmentInfo, attributes);
diff --git a/test/inheritAttributes.test.js b/test/inheritAttributes.test.js
index d274c9fa..f410e2d8 100644
--- a/test/inheritAttributes.test.js
+++ b/test/inheritAttributes.test.js
@@ -6,6 +6,7 @@ import {
import { stringToMpdXml } from '../src/stringToMpdXml';
import errors from '../src/errors';
import QUnit from 'qunit';
+import { toPlaylists } from '../src/toPlaylists';
QUnit.module('buildBaseUrls');
@@ -975,3 +976,135 @@ QUnit.test(' End to End test for returning adaptation set info', function(assert
assert.equal(actual.length, 3);
assert.deepEqual(actual, expected);
});
+
+// Atmost one segment at each levels
+
+QUnit.only(' Test for checking atmost one segment at each level', function(assert) {
+ const actual = toPlaylists(inheritAttributes(stringToMpdXml(
+ `
+
+ https://www.example.com/base/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `
+ )));
+
+ const expected = [{
+ attributes: {
+ bandwidth: '5000000',
+ baseUrl: 'https://www.example.com/base/',
+ duration: 'PT0H4M40.414S',
+ codecs: 'avc1.64001e',
+ height: '404',
+ id: 'test',
+ mediaPresentationDuration: 'PT30S',
+ mimeType: 'video/mp6',
+ periodIndex: 0,
+ role: {
+ value: 'main'
+ },
+ sourceDuration: 30,
+ width: '720'
+ },
+ segmentInfo: {
+ base: {
+ indexRange: '1212',
+ indexRangeExact: 'true',
+ initialization: {
+ range: '0-8888'
+
+ }
+ },
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }, {
+ attributes: {
+ baseUrl: 'https://www.example.com/base/',
+ mediaPresentationDuration: 'PT30S',
+ duration: 'PT0H4M40.414S',
+ mimeType: 'video/mp4',
+ periodIndex: 0,
+ height: '545',
+ role: {
+ value: 'main'
+ },
+ sourceDuration: 30
+ },
+ segmentInfo: {
+ base: {
+ indexRange: '1212',
+ indexRangeExact: 'false',
+ initialization: {
+ range: '0-8888'
+ }
+ },
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }, {
+ attributes: {
+ bandwidth: '256',
+ baseUrl: 'https://example.com/en.vtt',
+ duration: 'PT0H4M40.414S',
+ id: 'en',
+ lang: 'en',
+ mediaPresentationDuration: 'PT30S',
+ mimeType: 'text/vtt',
+ periodIndex: 0,
+ role: {},
+ sourceDuration: 30
+ },
+ segmentInfo: {
+ base: undefined,
+ list: undefined,
+ template: undefined,
+ timeline: undefined
+ }
+ }];
+
+ assert.equal(actual.length, 3);
+ assert.deepEqual(actual, expected);
+});
From a7877d5310d16848a0a3c060518b1f89f70b4f54 Mon Sep 17 00:00:00 2001
From: ishita12 <30434843+ishita12@users.noreply.github.com>
Date: Wed, 14 Feb 2018 14:17:09 -0500
Subject: [PATCH 3/9] Adding tests for checking presence of multiple segment
tags at a particular level and updating other tests
---
package-lock.json | 200 ++++++-
package.json | 1 +
src/toPlaylists.js | 20 +-
test/inheritAttributes.test.js | 580 ++++++++++++++------
test/manifests/maat_vtt_segmentTemplate.mpd | 24 +-
test/manifests/segmentBase.mpd | 4 +-
test/manifests/segmentList.mpd | 10 +-
7 files changed, 647 insertions(+), 192 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index 9007aa41..7b5b1948 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4,6 +4,152 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
+ "@babel/code-frame": {
+ "version": "7.0.0-beta.36",
+ "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0-beta.36.tgz",
+ "integrity": "sha512-sW77BFwJ48YvQp3Gzz5xtAUiXuYOL2aMJKDwiaY3OcvdqBFurtYfOpSa4QrNyDxmOGRFSYzUpabU2m9QrlWE7w==",
+ "dev": true,
+ "requires": {
+ "chalk": "2.3.1",
+ "esutils": "2.0.2",
+ "js-tokens": "3.0.2"
+ },
+ "dependencies": {
+ "ansi-styles": {
+ "version": "3.2.0",
+ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz",
+ "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==",
+ "dev": true,
+ "requires": {
+ "color-convert": "1.9.1"
+ }
+ },
+ "chalk": {
+ "version": "2.3.1",
+ "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.1.tgz",
+ "integrity": "sha512-QUU4ofkDoMIVO7hcx1iPTISs88wsO8jA92RQIm4JAwZvFGGAV2hSAA1NX7oVj2Ej2Q6NDTcRDjPTFrMCRZoJ6g==",
+ "dev": true,
+ "requires": {
+ "ansi-styles": "3.2.0",
+ "escape-string-regexp": "1.0.5",
+ "supports-color": "5.2.0"
+ }
+ },
+ "has-flag": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
+ "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
+ "dev": true
+ },
+ "supports-color": {
+ "version": "5.2.0",
+ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.2.0.tgz",
+ "integrity": "sha512-F39vS48la4YvTZUPVeTqsjsFNrvcMwrV3RLZINsmHo+7djCvuUzSIeXOnZ5hmjef4bajL1dNccN+tg5XAliO5Q==",
+ "dev": true,
+ "requires": {
+ "has-flag": "3.0.0"
+ }
+ }
+ }
+ },
+ "@babel/helper-function-name": {
+ "version": "7.0.0-beta.36",
+ "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.0.0-beta.36.tgz",
+ "integrity": "sha512-/SGPOyifPf20iTrMN+WdlY2MbKa7/o4j7B/4IAsdOusASp2icT+Wcdjf4tjJHaXNX8Pe9bpgVxLNxhRvcf8E5w==",
+ "dev": true,
+ "requires": {
+ "@babel/helper-get-function-arity": "7.0.0-beta.36",
+ "@babel/template": "7.0.0-beta.36",
+ "@babel/types": "7.0.0-beta.36"
+ }
+ },
+ "@babel/helper-get-function-arity": {
+ "version": "7.0.0-beta.36",
+ "resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.36.tgz",
+ "integrity": "sha512-vPPcx2vsSoDbcyWr9S3nd0FM3B4hEXnt0p1oKpwa08GwK0fSRxa98MyaRGf8suk8frdQlG1P3mDrz5p/Rr3pbA==",
+ "dev": true,
+ "requires": {
+ "@babel/types": "7.0.0-beta.36"
+ }
+ },
+ "@babel/template": {
+ "version": "7.0.0-beta.36",
+ "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.0.0-beta.36.tgz",
+ "integrity": "sha512-mUBi90WRyZ9iVvlWLEdeo8gn/tROyJdjKNC4W5xJTSZL+9MS89rTJSqiaJKXIkxk/YRDL/g/8snrG/O0xl33uA==",
+ "dev": true,
+ "requires": {
+ "@babel/code-frame": "7.0.0-beta.36",
+ "@babel/types": "7.0.0-beta.36",
+ "babylon": "7.0.0-beta.36",
+ "lodash": "4.17.4"
+ },
+ "dependencies": {
+ "babylon": {
+ "version": "7.0.0-beta.36",
+ "resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.36.tgz",
+ "integrity": "sha512-rw4YdadGwajAMMRl6a5swhQ0JCOOFyaYCfJ0AsmNBD8uBD/r4J8mux7wBaqavvFKqUKQYWOzA1Speams4YDzsQ==",
+ "dev": true
+ }
+ }
+ },
+ "@babel/traverse": {
+ "version": "7.0.0-beta.36",
+ "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.0.0-beta.36.tgz",
+ "integrity": "sha512-OTUb6iSKVR/98dGThRJ1BiyfwbuX10BVnkz89IpaerjTPRhDfMBfLsqmzxz5MiywUOW4M0Clta0o7rSxkfcuzw==",
+ "dev": true,
+ "requires": {
+ "@babel/code-frame": "7.0.0-beta.36",
+ "@babel/helper-function-name": "7.0.0-beta.36",
+ "@babel/types": "7.0.0-beta.36",
+ "babylon": "7.0.0-beta.36",
+ "debug": "3.1.0",
+ "globals": "11.3.0",
+ "invariant": "2.2.2",
+ "lodash": "4.17.4"
+ },
+ "dependencies": {
+ "babylon": {
+ "version": "7.0.0-beta.36",
+ "resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.36.tgz",
+ "integrity": "sha512-rw4YdadGwajAMMRl6a5swhQ0JCOOFyaYCfJ0AsmNBD8uBD/r4J8mux7wBaqavvFKqUKQYWOzA1Speams4YDzsQ==",
+ "dev": true
+ },
+ "debug": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
+ "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
+ "dev": true,
+ "requires": {
+ "ms": "2.0.0"
+ }
+ },
+ "globals": {
+ "version": "11.3.0",
+ "resolved": "https://registry.npmjs.org/globals/-/globals-11.3.0.tgz",
+ "integrity": "sha512-kkpcKNlmQan9Z5ZmgqKH/SMbSmjxQ7QjyNqfXVc8VJcoBV2UEg+sxQD15GQofGRh2hfpwUb70VC31DR7Rq5Hdw==",
+ "dev": true
+ }
+ }
+ },
+ "@babel/types": {
+ "version": "7.0.0-beta.36",
+ "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.0.0-beta.36.tgz",
+ "integrity": "sha512-PyAORDO9um9tfnrddXgmWN9e6Sq9qxraQIt5ynqBOSXKA5qvK1kUr+Q3nSzKFdzorsiK+oqcUnAFvEoKxv9D+Q==",
+ "dev": true,
+ "requires": {
+ "esutils": "2.0.2",
+ "lodash": "4.17.4",
+ "to-fast-properties": "2.0.0"
+ },
+ "dependencies": {
+ "to-fast-properties": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
+ "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=",
+ "dev": true
+ }
+ }
+ },
"JSONStream": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.1.tgz",
@@ -293,16 +439,25 @@
}
},
"babel-eslint": {
- "version": "6.1.2",
- "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-6.1.2.tgz",
- "integrity": "sha1-UpNBn+NnLWZZjTJ9qWlFZ7pqXy8=",
+ "version": "8.2.1",
+ "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-8.2.1.tgz",
+ "integrity": "sha512-RzdVOyWKQRUnLXhwLk+eKb4oyW+BykZSkpYwFhM4tnfzAG5OWfvG0w/uyzMp5XKEU0jN82+JefHr39bG2+KhRQ==",
"dev": true,
"requires": {
- "babel-traverse": "6.26.0",
- "babel-types": "6.26.0",
- "babylon": "6.18.0",
- "lodash.assign": "4.2.0",
- "lodash.pickby": "4.6.0"
+ "@babel/code-frame": "7.0.0-beta.36",
+ "@babel/traverse": "7.0.0-beta.36",
+ "@babel/types": "7.0.0-beta.36",
+ "babylon": "7.0.0-beta.36",
+ "eslint-scope": "3.7.1",
+ "eslint-visitor-keys": "1.0.0"
+ },
+ "dependencies": {
+ "babylon": {
+ "version": "7.0.0-beta.36",
+ "resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.36.tgz",
+ "integrity": "sha512-rw4YdadGwajAMMRl6a5swhQ0JCOOFyaYCfJ0AsmNBD8uBD/r4J8mux7wBaqavvFKqUKQYWOzA1Speams4YDzsQ==",
+ "dev": true
+ }
}
},
"babel-generator": {
@@ -2135,6 +2290,22 @@
"unified": "6.1.6"
}
},
+ "eslint-scope": {
+ "version": "3.7.1",
+ "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.1.tgz",
+ "integrity": "sha1-PWPD7f2gLgbgGkUq2IyqzHzctug=",
+ "dev": true,
+ "requires": {
+ "esrecurse": "4.2.0",
+ "estraverse": "4.2.0"
+ }
+ },
+ "eslint-visitor-keys": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz",
+ "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==",
+ "dev": true
+ },
"espree": {
"version": "3.5.2",
"resolved": "https://registry.npmjs.org/espree/-/espree-3.5.2.tgz",
@@ -6854,6 +7025,19 @@
"tsmlb": "1.0.0"
},
"dependencies": {
+ "babel-eslint": {
+ "version": "6.1.2",
+ "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-6.1.2.tgz",
+ "integrity": "sha1-UpNBn+NnLWZZjTJ9qWlFZ7pqXy8=",
+ "dev": true,
+ "requires": {
+ "babel-traverse": "6.26.0",
+ "babel-types": "6.26.0",
+ "babylon": "6.18.0",
+ "lodash.assign": "4.2.0",
+ "lodash.pickby": "4.6.0"
+ }
+ },
"commander": {
"version": "2.12.2",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.12.2.tgz",
diff --git a/package.json b/package.json
index 5123f1f5..c3e397b0 100644
--- a/package.json
+++ b/package.json
@@ -49,6 +49,7 @@
"src/"
],
"devDependencies": {
+ "babel-eslint": "^8.2.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-object-assign": "^6.8.0",
"babel-preset-es2015": "^6.14.0",
diff --git a/src/toPlaylists.js b/src/toPlaylists.js
index f8a31d01..17cd3a54 100644
--- a/src/toPlaylists.js
+++ b/src/toPlaylists.js
@@ -2,22 +2,20 @@ import { shallowMerge } from './utils/object';
import { segmentsFromTemplate } from './segment/segmentTemplate';
import { segmentsFromList } from './segment/segmentList';
import { segmentsFromBase } from './segment/segmentBase';
-
+// import merge from 'deepmerge';
export const generateSegments = (segmentInfo, attributes) => {
- if (segmentInfo.template) {
- return segmentsFromTemplate(
- shallowMerge(segmentInfo.template, attributes),
- segmentInfo.timeline
+ if (segmentInfo.list) {
+ return segmentsFromList(
+ shallowMerge(attributes, segmentInfo.list), segmentInfo.timeline
);
}
-
if (segmentInfo.base) {
- return segmentsFromBase(shallowMerge(segmentInfo.base, attributes));
+ return segmentsFromBase(shallowMerge(attributes, segmentInfo.base));
}
-
- if (segmentInfo.list) {
- return segmentsFromList(
- shallowMerge(segmentInfo.list, attributes), segmentInfo.timeline
+ if (segmentInfo.template) {
+ return segmentsFromTemplate(
+ shallowMerge(attributes, segmentInfo.template),
+ segmentInfo.timeline
);
}
};
diff --git a/test/inheritAttributes.test.js b/test/inheritAttributes.test.js
index f410e2d8..73bb2740 100644
--- a/test/inheritAttributes.test.js
+++ b/test/inheritAttributes.test.js
@@ -274,8 +274,8 @@ QUnit.test('end to end - inherits BaseURL from all levels', function(assert) {
height="404"
id="test"
width="720">
- buzz/
+ buzz/
@@ -337,26 +337,26 @@ QUnit.test('end to end - inherits BaseURL from all levels', function(assert) {
QUnit.test('end to end - alternate BaseURLs', function(assert) {
const actual = inheritAttributes(stringToMpdXml(
`
-
+
https://www.example.com/base/
https://www.test.com/base/
-
+
segments/
media/
-
+
+ bandwidth= "5000000"
+ codecs= "avc1.64001e"
+ height= "404"
+ id= "test"
+ width= "720" >
-
-
+
+
https://example.com/en.vtt
@@ -495,37 +495,37 @@ QUnit.test('end to end - alternate BaseURLs', function(assert) {
assert.deepEqual(actual, expected);
});
-QUnit.test(' End to End test for representation', function(assert) {
+QUnit.test(' End to End test for checking support of segments in representation', function(assert) {
const actual = inheritAttributes(stringToMpdXml(
`
-
+
https://www.example.com/base/
-
-
-
-
+
+
+
+
+ mimeType= "video/mp6"
+ bandwidth= "5000000"
+ codecs= "avc1.64001e"
+ height= "404"
+ id= "test"
+ width= "720" >
-
+
+ height= "545" >
-
+
-
+
https://example.com/en.vtt
@@ -610,40 +610,38 @@ QUnit.test(' End to End test for representation', function(assert) {
assert.deepEqual(actual, expected);
});
-// Testing for support of segment tags in period element
-
-QUnit.test(' End to End test for period', function(assert) {
+QUnit.test(' End to End test for checking support of segments in period ', function(assert) {
const actual = inheritAttributes(stringToMpdXml(
`
-
+
https://www.example.com/base/
-
-
-
+
+
+
-
-
-
+
+
+
+ mimeType= "video/mp6"
+ bandwidth= "5000000"
+ codecs= "avc1.64001e"
+ height= "404"
+ id= "test"
+ width= "720" >
-
+ height= "545" >
+
-
+
-
+
https://example.com/en.vtt
@@ -733,38 +731,38 @@ QUnit.test(' End to End test for period', function(assert) {
// Test for only periodAdaptationSetInfo
-QUnit.test(' End to End test for returning period info', function(assert) {
+QUnit.test(' End to End test for returning period information', function(assert) {
const actual = inheritAttributes(stringToMpdXml(
`
-
+
https://www.example.com/base/
-
-
-
+
+
+
-
-
-
+
+
+
+ mimeType= "video/mp6"
+ bandwidth= "5000000"
+ codecs= "avc1.64001e"
+ height= "404"
+ id= "test"
+ width= "720" >
-
+ height= "545" >
+
-
+
-
+
https://example.com/en.vtt
@@ -861,34 +859,34 @@ QUnit.test(' End to End test for returning period info', function(assert) {
// testing for returning adaptation set information
-QUnit.test(' End to End test for returning adaptation set info', function(assert) {
+QUnit.test(' End to End test for returning adaptation set information', function(assert) {
const actual = inheritAttributes(stringToMpdXml(
`
-
+
https://www.example.com/base/
-
-
-
-
-
+
+
+
+
+
+ mimeType= "video/mp6"
+ bandwidth= "5000000"
+ codecs= "avc1.64001e"
+ height= "404"
+ id= "test"
+ width= "720" >
-
+ height= "545" >
+
-
-
+
+
https://example.com/en.vtt
@@ -977,134 +975,388 @@ QUnit.test(' End to End test for returning adaptation set info', function(assert
assert.deepEqual(actual, expected);
});
-// Atmost one segment at each levels
-
-QUnit.only(' Test for checking atmost one segment at each level', function(assert) {
+QUnit.test(' Test for checking presence of atmost one segment at each level', function(assert) {
const actual = toPlaylists(inheritAttributes(stringToMpdXml(
`
-
- https://www.example.com/base/
-
-
-
-
+
+ https://www.example.com/base
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
+ mimeType= "video/mp6"
+ bandwidth= "5000000"
+ codecs= "avc1.64001e"
+ height= "404"
+ id= "test"
+ width= "720" >
+
+
-
-
-
-
-
-
+ height= "545" >
`
- )));
+)));
const expected = [{
attributes: {
bandwidth: '5000000',
- baseUrl: 'https://www.example.com/base/',
+ baseUrl: 'https://www.example.com/base',
duration: 'PT0H4M40.414S',
codecs: 'avc1.64001e',
height: '404',
id: 'test',
+ lang: 'es',
mediaPresentationDuration: 'PT30S',
mimeType: 'video/mp6',
periodIndex: 0,
role: {
value: 'main'
},
+ segmentAlignment: 'true',
sourceDuration: 30,
- width: '720'
+ width: '720',
+ startWithSAP: '1'
},
- segmentInfo: {
- base: {
- indexRange: '1212',
- indexRangeExact: 'true',
- initialization: {
- range: '0-8888'
-
- }
+ segments: [
+ {
+ duration: 1,
+ map: {
+ uri: '',
+ resolvedUri: 'https://www.example.com/base'
+ },
+ resolvedUri: 'https://www.example.com/low/segment-1.ts',
+ timeline: 0,
+ uri: 'low/segment-1.ts'
},
- list: undefined,
- template: undefined,
- timeline: undefined
- }
+ {
+ duration: 1,
+ map: {
+ uri: '',
+ resolvedUri: 'https://www.example.com/base'
+ },
+ resolvedUri: 'https://www.example.com/low/segment-2.ts',
+ timeline: 0,
+ uri: 'low/segment-2.ts'
+ },
+ {
+ duration: 1,
+ map: {
+ uri: '',
+ resolvedUri: 'https://www.example.com/base'
+ },
+ resolvedUri: 'https://www.example.com/low/segment-3.ts',
+ timeline: 0,
+ uri: 'low/segment-3.ts'
+ },
+ {
+ duration: 1,
+ map: {
+ uri: '',
+ resolvedUri: 'https://www.example.com/base'
+ },
+ resolvedUri: 'https://www.example.com/low/segment-4.ts',
+ timeline: 0,
+ uri: 'low/segment-4.ts'
+ },
+ {
+ duration: 1,
+ map: {
+ uri: '',
+ resolvedUri: 'https://www.example.com/base'
+ },
+ resolvedUri: 'https://www.example.com/low/segment-5.ts',
+ timeline: 0,
+ uri: 'low/segment-5.ts'
+ },
+ {
+ duration: 1,
+ map: {
+ uri: '',
+ resolvedUri: 'https://www.example.com/base'
+ },
+ resolvedUri: 'https://www.example.com/low/segment-6.ts',
+ timeline: 0,
+ uri: 'low/segment-6.ts'
+ }
+ ]
}, {
attributes: {
- baseUrl: 'https://www.example.com/base/',
- mediaPresentationDuration: 'PT30S',
+ baseUrl: 'https://www.example.com/base',
duration: 'PT0H4M40.414S',
+ lang: 'es',
+ height: '545',
+ mediaPresentationDuration: 'PT30S',
mimeType: 'video/mp4',
periodIndex: 0,
- height: '545',
role: {
value: 'main'
},
- sourceDuration: 30
+ segmentAlignment: 'true',
+ sourceDuration: 30,
+ startWithSAP: '1'
+
},
- segmentInfo: {
- base: {
- indexRange: '1212',
- indexRangeExact: 'false',
- initialization: {
- range: '0-8888'
- }
+ segments: undefined
+ }];
+
+ assert.equal(actual.length, 2);
+ assert.deepEqual(actual, expected);
+});
+
+QUnit.test('Test to check if SegmentTemplate or SegmentList is present on one level, the other shall not be present on lower level in heirarchy', function(assert) {
+ const actual = toPlaylists(inheritAttributes(stringToMpdXml(
+ `
+
+ https://www.example.com/base
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `
+)));
+
+ const expected = [{
+ attributes: {
+ bandwidth: '5000000',
+ baseUrl: 'https://www.example.com/base',
+ duration: 'PT0H4M40.414S',
+ codecs: 'avc1.64001e',
+ height: '404',
+ id: 'test',
+ lang: 'es',
+ mediaPresentationDuration: 'PT30S',
+ mimeType: 'video/mp6',
+ periodIndex: 0,
+ role: {
+ value: 'main'
},
- list: undefined,
- template: undefined,
- timeline: undefined
- }
+ segmentAlignment: 'true',
+ sourceDuration: 30,
+ width: '720',
+ startWithSAP: '1'
+ },
+ segments: [
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/0.m4f',
+ timeline: 0,
+ uri: 'test/es/0.m4f'
+ },
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/1.m4f',
+ timeline: 0,
+ uri: 'test/es/1.m4f'
+ },
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/2.m4f',
+ timeline: 0,
+ uri: 'test/es/2.m4f'
+ },
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/3.m4f',
+ timeline: 0,
+ uri: 'test/es/3.m4f'
+ },
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/4.m4f',
+ timeline: 0,
+ uri: 'test/es/4.m4f'
+ },
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/5.m4f',
+ timeline: 0,
+ uri: 'test/es/5.m4f'
+ },
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/6.m4f',
+ timeline: 0,
+ uri: 'test/es/6.m4f'
+ },
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/7.m4f',
+ timeline: 0,
+ uri: 'test/es/7.m4f'
+ },
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/8.m4f',
+ timeline: 0,
+ uri: 'test/es/8.m4f'
+ },
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/9.m4f',
+ timeline: 0,
+ uri: 'test/es/9.m4f'
+ },
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/10.m4f',
+ timeline: 0,
+ uri: 'test/es/10.m4f'
+ },
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/11.m4f',
+ timeline: 0,
+ uri: 'test/es/11.m4f'
+ },
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/12.m4f',
+ timeline: 0,
+ uri: 'test/es/12.m4f'
+ },
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/13.m4f',
+ timeline: 0,
+ uri: 'test/es/13.m4f'
+ },
+ {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/14.m4f',
+ timeline: 0,
+ uri: 'test/es/14.m4f'
+ },
+ {
+ duration: 0.240000000000002,
+ map: {
+ resolvedUri: 'https://www.example.com/test/es/init.m4f',
+ uri: 'test/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/test/es/15.m4f',
+ timeline: 0,
+ uri: 'test/es/15.m4f'
+ }
+ ]
}, {
attributes: {
- bandwidth: '256',
- baseUrl: 'https://example.com/en.vtt',
+ baseUrl: 'https://www.example.com/base',
duration: 'PT0H4M40.414S',
- id: 'en',
- lang: 'en',
+ lang: 'es',
+ height: '545',
mediaPresentationDuration: 'PT30S',
- mimeType: 'text/vtt',
+ mimeType: 'video/mp4',
periodIndex: 0,
- role: {},
- sourceDuration: 30
+ role: {
+ value: 'main'
+ },
+ segmentAlignment: 'true',
+ sourceDuration: 30,
+ startWithSAP: '1'
+
},
- segmentInfo: {
- base: undefined,
- list: undefined,
- template: undefined,
- timeline: undefined
- }
+ segments: undefined
}];
- assert.equal(actual.length, 3);
+ assert.equal(actual.length, 2);
assert.deepEqual(actual, expected);
});
diff --git a/test/manifests/maat_vtt_segmentTemplate.mpd b/test/manifests/maat_vtt_segmentTemplate.mpd
index af40bbeb..bae42077 100644
--- a/test/manifests/maat_vtt_segmentTemplate.mpd
+++ b/test/manifests/maat_vtt_segmentTemplate.mpd
@@ -6,21 +6,33 @@
-
-
+
+
+
+
+
+
-
-
+
+
+
+
+
+
-
-
+
+
+
+
+
+
diff --git a/test/manifests/segmentBase.mpd b/test/manifests/segmentBase.mpd
index 609202a5..df4b2927 100644
--- a/test/manifests/segmentBase.mpd
+++ b/test/manifests/segmentBase.mpd
@@ -4,7 +4,9 @@
-
+
+
+
1080p.ts
diff --git a/test/manifests/segmentList.mpd b/test/manifests/segmentList.mpd
index 0977c5a4..453fe7d9 100644
--- a/test/manifests/segmentList.mpd
+++ b/test/manifests/segmentList.mpd
@@ -4,7 +4,9 @@
-
+
+
+
@@ -22,7 +24,11 @@
-
+
+
+
+
+
From 59e4b4838e0ea443bf592735c226a8272a97da7c Mon Sep 17 00:00:00 2001
From: ishita12 <30434843+ishita12@users.noreply.github.com>
Date: Thu, 15 Feb 2018 21:37:53 -0500
Subject: [PATCH 4/9] Updating the tests
---
src/inheritAttributes.js | 27 +-
src/toPlaylists.js | 14 +-
test/inheritAttributes.test.js | 873 ++++++++++++++++++---------------
3 files changed, 490 insertions(+), 424 deletions(-)
diff --git a/src/inheritAttributes.js b/src/inheritAttributes.js
index a4360dc3..56260d0c 100644
--- a/src/inheritAttributes.js
+++ b/src/inheritAttributes.js
@@ -132,16 +132,20 @@ export const getSegmentInformation = (adaptationSet) => {
* Callback map function
*/
export const inheritBaseUrls =
-(adaptationSetAttributes, adaptationSetBaseUrls, periodAdaptationSetInfo) => (representation) => {
+(adaptationSetAttributes, adaptationSetBaseUrls, adaptationSetSegmentInfo) => (representation) => {
const repBaseUrlElements = findChildren(representation, 'BaseURL');
const repBaseUrls = buildBaseUrls(adaptationSetBaseUrls, repBaseUrlElements);
const attributes = shallowMerge(adaptationSetAttributes, getAttributes(representation));
- const segmentInfoFromRepresenation = getSegmentInformation(representation);
- const segmentRepresentationInfo = merge(periodAdaptationSetInfo, segmentInfoFromRepresenation);
+ const representationSegmentInfo = getSegmentInformation(representation);
return repBaseUrls.map(baseUrl => {
return {
- segmentInfo: segmentRepresentationInfo,
+ segmentInfo: {
+ list: adaptationSetSegmentInfo.list && representationSegmentInfo.list ? merge(adaptationSetSegmentInfo.list, representationSegmentInfo.list) : adaptationSetSegmentInfo.list && !representationSegmentInfo.list ? adaptationSetSegmentInfo.list : !adaptationSetSegmentInfo.list && representationSegmentInfo.list ? representationSegmentInfo.list : undefined,
+ template: adaptationSetSegmentInfo.template && representationSegmentInfo.template ? merge(adaptationSetSegmentInfo.template, representationSegmentInfo.template) : adaptationSetSegmentInfo.template && !representationSegmentInfo.template ? adaptationSetSegmentInfo.template : !adaptationSetSegmentInfo.template && representationSegmentInfo.template ? representationSegmentInfo.template : undefined,
+ base: adaptationSetSegmentInfo.base && representationSegmentInfo.base ? merge(adaptationSetSegmentInfo.base, representationSegmentInfo.base) : adaptationSetSegmentInfo.base && !representationSegmentInfo.base ? adaptationSetSegmentInfo.base : !adaptationSetSegmentInfo.base && representationSegmentInfo.base ? representationSegmentInfo.base : undefined,
+ timeline: adaptationSetSegmentInfo.timeline && representationSegmentInfo.timeline ? merge(adaptationSetSegmentInfo.timeline, representationSegmentInfo.timeline) : adaptationSetSegmentInfo.timeline && !representationSegmentInfo.timeline ? adaptationSetSegmentInfo.timeline : !adaptationSetSegmentInfo.timeline && representationSegmentInfo.timeline ? representationSegmentInfo.timeline : undefined
+ },
attributes: shallowMerge(attributes, { baseUrl })
};
});
@@ -170,7 +174,7 @@ export const inheritBaseUrls =
* Callback map function
*/
export const toRepresentations =
-(periodAttributes, periodBaseUrls, periodInfo) => (adaptationSet) => {
+(periodAttributes, periodBaseUrls, periodSegmentInfo) => (adaptationSet) => {
const adaptationSetAttributes = getAttributes(adaptationSet);
const adaptationSetBaseUrls = buildBaseUrls(periodBaseUrls,
findChildren(adaptationSet, 'BaseURL'));
@@ -181,10 +185,15 @@ export const toRepresentations =
roleAttributes);
const segmentInfo = getSegmentInformation(adaptationSet);
const representations = findChildren(adaptationSet, 'Representation');
- const periodAdaptationSetInfo = merge(periodInfo, segmentInfo);
+ const adaptationSetSegmentInfo = {
+ list: periodSegmentInfo.list && segmentInfo.list ? merge(periodSegmentInfo.list, segmentInfo.list) : periodSegmentInfo.list && !segmentInfo.list ? periodSegmentInfo.list : !periodSegmentInfo.list && segmentInfo.list ? segmentInfo.list : undefined,
+ template: periodSegmentInfo.template && segmentInfo.template ? merge(periodSegmentInfo.template, segmentInfo.template) : periodSegmentInfo.template && !segmentInfo.template ? periodSegmentInfo.template : !periodSegmentInfo.template && segmentInfo.template ? segmentInfo.template : undefined,
+ base: periodSegmentInfo.base && segmentInfo.base ? merge(periodSegmentInfo.base, segmentInfo.base) : periodSegmentInfo.base && !segmentInfo.base ? periodSegmentInfo.base : !periodSegmentInfo.base && segmentInfo.base ? segmentInfo.base : undefined,
+ timeline: periodSegmentInfo.timeline && segmentInfo.timeline ? merge(periodSegmentInfo.timeline, segmentInfo.timeline) : periodSegmentInfo.timeline && !segmentInfo.timeline ? periodSegmentInfo.timeline : !periodSegmentInfo.timeline && segmentInfo.timeline ? segmentInfo.timeline : undefined
+ };
return flatten(
- representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, periodAdaptationSetInfo)));
+ representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, adaptationSetSegmentInfo)));
};
/**
@@ -217,9 +226,9 @@ export const toAdaptationSets = (mpdAttributes, mpdBaseUrls) => (period, periodI
const periodAtt = getAttributes(period);
const periodAttributes = shallowMerge(periodAtt, { periodIndex }, mpdAttributes);
const adaptationSets = findChildren(period, 'AdaptationSet');
- const periodInfo = getSegmentInformation(period);
+ const periodSegmentInfo = getSegmentInformation(period);
- return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls, periodInfo)));
+ return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls, periodSegmentInfo)));
};
/**
diff --git a/src/toPlaylists.js b/src/toPlaylists.js
index 17cd3a54..e231572c 100644
--- a/src/toPlaylists.js
+++ b/src/toPlaylists.js
@@ -4,18 +4,18 @@ import { segmentsFromList } from './segment/segmentList';
import { segmentsFromBase } from './segment/segmentBase';
// import merge from 'deepmerge';
export const generateSegments = (segmentInfo, attributes) => {
- if (segmentInfo.list) {
- return segmentsFromList(
- shallowMerge(attributes, segmentInfo.list), segmentInfo.timeline
+ if (segmentInfo.template) {
+ return segmentsFromTemplate(
+ shallowMerge(attributes, segmentInfo.template),
+ segmentInfo.timeline
);
}
if (segmentInfo.base) {
return segmentsFromBase(shallowMerge(attributes, segmentInfo.base));
}
- if (segmentInfo.template) {
- return segmentsFromTemplate(
- shallowMerge(attributes, segmentInfo.template),
- segmentInfo.timeline
+ if (segmentInfo.list) {
+ return segmentsFromList(
+ shallowMerge(attributes, segmentInfo.list), segmentInfo.timeline
);
}
};
diff --git a/test/inheritAttributes.test.js b/test/inheritAttributes.test.js
index 73bb2740..30d1fe7d 100644
--- a/test/inheritAttributes.test.js
+++ b/test/inheritAttributes.test.js
@@ -198,7 +198,6 @@ QUnit.test('end to end - basic', function(assert) {
height="404"
id="test"
width="720">
-
@@ -274,7 +273,6 @@ QUnit.test('end to end - inherits BaseURL from all levels', function(assert) {
height="404"
id="test"
width="720">
-
buzz/
@@ -352,7 +350,6 @@ QUnit.test('end to end - alternate BaseURLs', function(assert) {
height= "404"
id= "test"
width= "720" >
-
@@ -520,11 +517,9 @@ QUnit.test(' End to End test for checking support of segments in representation'
-
-
https://example.com/en.vtt
@@ -621,8 +616,6 @@ QUnit.test(' End to End test for checking support of segments in period ', funct
-
-
-
-
-
-
-
https://example.com/en.vtt
@@ -667,31 +655,6 @@ QUnit.test(' End to End test for checking support of segments in period ', funct
sourceDuration: 30,
width: '720'
},
- segmentInfo: {
- base: {
- indexRange: '9999',
- indexRangeExact: 'true',
- initialization: {
- range: '0-1111'
- }
- },
- list: undefined,
- template: undefined,
- timeline: undefined
- }
- }, {
- attributes: {
- baseUrl: 'https://www.example.com/base/',
- mediaPresentationDuration: 'PT30S',
- duration: 'PT0H4M40.414S',
- mimeType: 'video/mp4',
- periodIndex: 0,
- height: '545',
- role: {
- value: 'main'
- },
- sourceDuration: 30
- },
segmentInfo: {
base: {
indexRange: '9999',
@@ -704,103 +667,6 @@ QUnit.test(' End to End test for checking support of segments in period ', funct
template: undefined,
timeline: undefined
}
- }, {
- attributes: {
- bandwidth: '256',
- baseUrl: 'https://example.com/en.vtt',
- duration: 'PT0H4M40.414S',
- id: 'en',
- lang: 'en',
- mediaPresentationDuration: 'PT30S',
- mimeType: 'text/vtt',
- periodIndex: 0,
- role: {},
- sourceDuration: 30
- },
- segmentInfo: {
- base: undefined,
- list: undefined,
- template: undefined,
- timeline: undefined
- }
- }];
-
- assert.equal(actual.length, 3);
- assert.deepEqual(actual, expected);
-});
-
-// Test for only periodAdaptationSetInfo
-
-QUnit.test(' End to End test for returning period information', function(assert) {
- const actual = inheritAttributes(stringToMpdXml(
- `
-
- https://www.example.com/base/
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- https://example.com/en.vtt
-
-
-
-
-
- `
- ));
-
- const expected = [{
- attributes: {
- bandwidth: '5000000',
- baseUrl: 'https://www.example.com/base/',
- duration: 'PT0H4M40.414S',
- codecs: 'avc1.64001e',
- height: '404',
- id: 'test',
- mediaPresentationDuration: 'PT30S',
- mimeType: 'video/mp6',
- periodIndex: 0,
- role: {
- value: 'main'
- },
- sourceDuration: 30,
- width: '720'
- },
- segmentInfo: {
- base: {
- indexRange: '9999',
- indexRangeExact: 'true',
- initialization: {
- range: '0-1111'
- }
- },
- list: undefined,
- template: undefined,
- timeline: undefined
- }
}, {
attributes: {
baseUrl: 'https://www.example.com/base/',
@@ -857,9 +723,7 @@ QUnit.test(' End to End test for returning period information', function(assert)
assert.deepEqual(actual, expected);
});
-// testing for returning adaptation set information
-
-QUnit.test(' End to End test for returning adaptation set information', function(assert) {
+QUnit.test(' End to End test for checking support of Segments in Adaptation set', function(assert) {
const actual = inheritAttributes(stringToMpdXml(
`
@@ -877,12 +741,9 @@ QUnit.test(' End to End test for returning adaptation set information', function
height= "404"
id= "test"
width= "720" >
-
-
-
@@ -941,7 +802,7 @@ QUnit.test(' End to End test for returning adaptation set information', function
segmentInfo: {
base: {
indexRange: '1212',
- indexRangeExact: 'false',
+ indexRangeExact: 'true',
initialization: {
range: '0-8888'
}
@@ -975,7 +836,10 @@ QUnit.test(' End to End test for returning adaptation set information', function
assert.deepEqual(actual, expected);
});
-QUnit.test(' Test for checking presence of atmost one segment at each level', function(assert) {
+// Although according to the Spec, at most one set of Segment information should be present at each level,
+// This test would still handle the case and prevent errors if multiple set of segment information are present at any particular level.
+
+QUnit.test(' Test for checking use of only one set of Segment Information when multiple are present', function(assert) {
const actual = toPlaylists(inheritAttributes(stringToMpdXml(
`
@@ -999,13 +863,12 @@ QUnit.test(' Test for checking presence of atmost one segment at each level', fu
bandwidth= "5000000"
codecs= "avc1.64001e"
height= "404"
- id= "test"
+ id= "125000"
width= "720" >
-
-
+ height= "545"
+ id="125000" >
@@ -1020,7 +883,7 @@ QUnit.test(' Test for checking presence of atmost one segment at each level', fu
duration: 'PT0H4M40.414S',
codecs: 'avc1.64001e',
height: '404',
- id: 'test',
+ id: '125000',
lang: 'es',
mediaPresentationDuration: 'PT30S',
mimeType: 'video/mp6',
@@ -1033,74 +896,158 @@ QUnit.test(' Test for checking presence of atmost one segment at each level', fu
width: '720',
startWithSAP: '1'
},
- segments: [
- {
- duration: 1,
- map: {
- uri: '',
- resolvedUri: 'https://www.example.com/base'
- },
- resolvedUri: 'https://www.example.com/low/segment-1.ts',
- timeline: 0,
- uri: 'low/segment-1.ts'
- },
- {
- duration: 1,
- map: {
- uri: '',
- resolvedUri: 'https://www.example.com/base'
- },
- resolvedUri: 'https://www.example.com/low/segment-2.ts',
- timeline: 0,
- uri: 'low/segment-2.ts'
- },
- {
- duration: 1,
- map: {
- uri: '',
- resolvedUri: 'https://www.example.com/base'
- },
- resolvedUri: 'https://www.example.com/low/segment-3.ts',
- timeline: 0,
- uri: 'low/segment-3.ts'
- },
- {
- duration: 1,
- map: {
- uri: '',
- resolvedUri: 'https://www.example.com/base'
- },
- resolvedUri: 'https://www.example.com/low/segment-4.ts',
- timeline: 0,
- uri: 'low/segment-4.ts'
- },
- {
- duration: 1,
- map: {
- uri: '',
- resolvedUri: 'https://www.example.com/base'
- },
- resolvedUri: 'https://www.example.com/low/segment-5.ts',
- timeline: 0,
- uri: 'low/segment-5.ts'
- },
- {
- duration: 1,
- map: {
- uri: '',
- resolvedUri: 'https://www.example.com/base'
- },
- resolvedUri: 'https://www.example.com/low/segment-6.ts',
- timeline: 0,
- uri: 'low/segment-6.ts'
- }
- ]
+ segments: [{
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/0.m4f',
+ timeline: 0,
+ uri: '125000/es/0.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/1.m4f',
+ timeline: 0,
+ uri: '125000/es/1.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/2.m4f',
+ timeline: 0,
+ uri: '125000/es/2.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/3.m4f',
+ timeline: 0,
+ uri: '125000/es/3.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/4.m4f',
+ timeline: 0,
+ uri: '125000/es/4.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/5.m4f',
+ timeline: 0,
+ uri: '125000/es/5.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/6.m4f',
+ timeline: 0,
+ uri: '125000/es/6.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/7.m4f',
+ timeline: 0,
+ uri: '125000/es/7.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/8.m4f',
+ timeline: 0,
+ uri: '125000/es/8.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/9.m4f',
+ timeline: 0,
+ uri: '125000/es/9.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/10.m4f',
+ timeline: 0,
+ uri: '125000/es/10.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/11.m4f',
+ timeline: 0,
+ uri: '125000/es/11.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/12.m4f',
+ timeline: 0,
+ uri: '125000/es/12.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/13.m4f',
+ timeline: 0,
+ uri: '125000/es/13.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/14.m4f',
+ timeline: 0,
+ uri: '125000/es/14.m4f'
+ }, {
+ duration: 0.240000000000002,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/15.m4f',
+ timeline: 0,
+ uri: '125000/es/15.m4f'
+ }]
}, {
attributes: {
baseUrl: 'https://www.example.com/base',
duration: 'PT0H4M40.414S',
lang: 'es',
height: '545',
+ id: '125000',
mediaPresentationDuration: 'PT30S',
mimeType: 'video/mp4',
periodIndex: 0,
@@ -1112,14 +1059,161 @@ QUnit.test(' Test for checking presence of atmost one segment at each level', fu
startWithSAP: '1'
},
- segments: undefined
+ segments: [{
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/0.m4f',
+ timeline: 0,
+ uri: '125000/es/0.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/1.m4f',
+ timeline: 0,
+ uri: '125000/es/1.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/2.m4f',
+ timeline: 0,
+ uri: '125000/es/2.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/3.m4f',
+ timeline: 0,
+ uri: '125000/es/3.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/4.m4f',
+ timeline: 0,
+ uri: '125000/es/4.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/5.m4f',
+ timeline: 0,
+ uri: '125000/es/5.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/6.m4f',
+ timeline: 0,
+ uri: '125000/es/6.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/7.m4f',
+ timeline: 0,
+ uri: '125000/es/7.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/8.m4f',
+ timeline: 0,
+ uri: '125000/es/8.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/9.m4f',
+ timeline: 0,
+ uri: '125000/es/9.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/10.m4f',
+ timeline: 0,
+ uri: '125000/es/10.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/11.m4f',
+ timeline: 0,
+ uri: '125000/es/11.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/12.m4f',
+ timeline: 0,
+ uri: '125000/es/12.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/13.m4f',
+ timeline: 0,
+ uri: '125000/es/13.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/14.m4f',
+ timeline: 0,
+ uri: '125000/es/14.m4f'
+ }, {
+ duration: 0.240000000000002,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/15.m4f',
+ timeline: 0,
+ uri: '125000/es/15.m4f'
+ }]
}];
assert.equal(actual.length, 2);
assert.deepEqual(actual, expected);
});
-QUnit.test('Test to check if SegmentTemplate or SegmentList is present on one level, the other shall not be present on lower level in heirarchy', function(assert) {
+// Although the Spec states that if SegmentTemplate or SegmentList is present on one level of the hierarchy the other one shall not be present on any lower level,
+// This test would still handle the case if both are present in the hierarchy and would prevent throwing errors.
+
+QUnit.test('Test to check use of either Segment Template or Segment List when both are present in the hierarchy', function(assert) {
const actual = toPlaylists(inheritAttributes(stringToMpdXml(
`
@@ -1127,27 +1221,24 @@ QUnit.test('Test to check if SegmentTemplate or SegmentList is present on one le
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
@@ -1162,7 +1253,7 @@ QUnit.test('Test to check if SegmentTemplate or SegmentList is present on one le
duration: 'PT0H4M40.414S',
codecs: 'avc1.64001e',
height: '404',
- id: 'test',
+ id: '125000',
lang: 'es',
mediaPresentationDuration: 'PT30S',
mimeType: 'video/mp6',
@@ -1175,188 +1266,154 @@ QUnit.test('Test to check if SegmentTemplate or SegmentList is present on one le
width: '720',
startWithSAP: '1'
},
- segments: [
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/0.m4f',
- timeline: 0,
- uri: 'test/es/0.m4f'
- },
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/1.m4f',
- timeline: 0,
- uri: 'test/es/1.m4f'
- },
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/2.m4f',
- timeline: 0,
- uri: 'test/es/2.m4f'
- },
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/3.m4f',
- timeline: 0,
- uri: 'test/es/3.m4f'
- },
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/4.m4f',
- timeline: 0,
- uri: 'test/es/4.m4f'
- },
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/5.m4f',
- timeline: 0,
- uri: 'test/es/5.m4f'
- },
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/6.m4f',
- timeline: 0,
- uri: 'test/es/6.m4f'
- },
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/7.m4f',
- timeline: 0,
- uri: 'test/es/7.m4f'
- },
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/8.m4f',
- timeline: 0,
- uri: 'test/es/8.m4f'
- },
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/9.m4f',
- timeline: 0,
- uri: 'test/es/9.m4f'
- },
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/10.m4f',
- timeline: 0,
- uri: 'test/es/10.m4f'
- },
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/11.m4f',
- timeline: 0,
- uri: 'test/es/11.m4f'
- },
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/12.m4f',
- timeline: 0,
- uri: 'test/es/12.m4f'
- },
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/13.m4f',
- timeline: 0,
- uri: 'test/es/13.m4f'
- },
- {
- duration: 1.984,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/14.m4f',
- timeline: 0,
- uri: 'test/es/14.m4f'
- },
- {
- duration: 0.240000000000002,
- map: {
- resolvedUri: 'https://www.example.com/test/es/init.m4f',
- uri: 'test/es/init.m4f'
- },
- resolvedUri: 'https://www.example.com/test/es/15.m4f',
- timeline: 0,
- uri: 'test/es/15.m4f'
- }
- ]
- }, {
- attributes: {
- baseUrl: 'https://www.example.com/base',
- duration: 'PT0H4M40.414S',
- lang: 'es',
- height: '545',
- mediaPresentationDuration: 'PT30S',
- mimeType: 'video/mp4',
- periodIndex: 0,
- role: {
- value: 'main'
+ segments: [{
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
},
- segmentAlignment: 'true',
- sourceDuration: 30,
- startWithSAP: '1'
-
- },
- segments: undefined
- }];
+ resolvedUri: 'https://www.example.com/125000/es/0.m4f',
+ timeline: 0,
+ uri: '125000/es/0.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/1.m4f',
+ timeline: 0,
+ uri: '125000/es/1.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/2.m4f',
+ timeline: 0,
+ uri: '125000/es/2.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/3.m4f',
+ timeline: 0,
+ uri: '125000/es/3.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/4.m4f',
+ timeline: 0,
+ uri: '125000/es/4.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/5.m4f',
+ timeline: 0,
+ uri: '125000/es/5.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/6.m4f',
+ timeline: 0,
+ uri: '125000/es/6.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/7.m4f',
+ timeline: 0,
+ uri: '125000/es/7.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/8.m4f',
+ timeline: 0,
+ uri: '125000/es/8.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/9.m4f',
+ timeline: 0,
+ uri: '125000/es/9.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/10.m4f',
+ timeline: 0,
+ uri: '125000/es/10.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/11.m4f',
+ timeline: 0,
+ uri: '125000/es/11.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/12.m4f',
+ timeline: 0,
+ uri: '125000/es/12.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/13.m4f',
+ timeline: 0,
+ uri: '125000/es/13.m4f'
+ }, {
+ duration: 1.984,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/14.m4f',
+ timeline: 0,
+ uri: '125000/es/14.m4f'
+ }, {
+ duration: 0.240000000000002,
+ map: {
+ resolvedUri: 'https://www.example.com/125000/es/init.m4f',
+ uri: '125000/es/init.m4f'
+ },
+ resolvedUri: 'https://www.example.com/125000/es/15.m4f',
+ timeline: 0,
+ uri: '125000/es/15.m4f'
+ }]
+ }
+];
- assert.equal(actual.length, 2);
+ assert.equal(actual.length, 1);
assert.deepEqual(actual, expected);
});
From 705b713be49259cb8c7794feb3acd42e423cf84b Mon Sep 17 00:00:00 2001
From: ishita12 <30434843+ishita12@users.noreply.github.com>
Date: Tue, 20 Feb 2018 09:55:17 -0500
Subject: [PATCH 5/9] Updating the tests
---
src/inheritAttributes.js | 24 +++---
test/inheritAttributes.test.js | 131 ++++++---------------------------
2 files changed, 34 insertions(+), 121 deletions(-)
diff --git a/src/inheritAttributes.js b/src/inheritAttributes.js
index 56260d0c..54744f8b 100644
--- a/src/inheritAttributes.js
+++ b/src/inheritAttributes.js
@@ -79,7 +79,7 @@ export const getSegmentInformation = (adaptationSet) => {
template.initialization = { sourceURL: template.initialization };
}
- return {
+ const segmentInfo = {
template,
timeline: segmentTimeline &&
findChildren(segmentTimeline, 'S').map(s => getAttributes(s)),
@@ -94,6 +94,14 @@ export const getSegmentInformation = (adaptationSet) => {
initialization: getAttributes(segmentInitialization)
})
};
+
+ Object.keys(segmentInfo).forEach(key => {
+ if (!segmentInfo[key]) {
+ delete segmentInfo[key];
+ }
+ });
+
+ return segmentInfo;
};
/**
@@ -140,12 +148,7 @@ export const inheritBaseUrls =
return repBaseUrls.map(baseUrl => {
return {
- segmentInfo: {
- list: adaptationSetSegmentInfo.list && representationSegmentInfo.list ? merge(adaptationSetSegmentInfo.list, representationSegmentInfo.list) : adaptationSetSegmentInfo.list && !representationSegmentInfo.list ? adaptationSetSegmentInfo.list : !adaptationSetSegmentInfo.list && representationSegmentInfo.list ? representationSegmentInfo.list : undefined,
- template: adaptationSetSegmentInfo.template && representationSegmentInfo.template ? merge(adaptationSetSegmentInfo.template, representationSegmentInfo.template) : adaptationSetSegmentInfo.template && !representationSegmentInfo.template ? adaptationSetSegmentInfo.template : !adaptationSetSegmentInfo.template && representationSegmentInfo.template ? representationSegmentInfo.template : undefined,
- base: adaptationSetSegmentInfo.base && representationSegmentInfo.base ? merge(adaptationSetSegmentInfo.base, representationSegmentInfo.base) : adaptationSetSegmentInfo.base && !representationSegmentInfo.base ? adaptationSetSegmentInfo.base : !adaptationSetSegmentInfo.base && representationSegmentInfo.base ? representationSegmentInfo.base : undefined,
- timeline: adaptationSetSegmentInfo.timeline && representationSegmentInfo.timeline ? merge(adaptationSetSegmentInfo.timeline, representationSegmentInfo.timeline) : adaptationSetSegmentInfo.timeline && !representationSegmentInfo.timeline ? adaptationSetSegmentInfo.timeline : !adaptationSetSegmentInfo.timeline && representationSegmentInfo.timeline ? representationSegmentInfo.timeline : undefined
- },
+ segmentInfo: merge(adaptationSetSegmentInfo, representationSegmentInfo),
attributes: shallowMerge(attributes, { baseUrl })
};
});
@@ -185,12 +188,7 @@ export const toRepresentations =
roleAttributes);
const segmentInfo = getSegmentInformation(adaptationSet);
const representations = findChildren(adaptationSet, 'Representation');
- const adaptationSetSegmentInfo = {
- list: periodSegmentInfo.list && segmentInfo.list ? merge(periodSegmentInfo.list, segmentInfo.list) : periodSegmentInfo.list && !segmentInfo.list ? periodSegmentInfo.list : !periodSegmentInfo.list && segmentInfo.list ? segmentInfo.list : undefined,
- template: periodSegmentInfo.template && segmentInfo.template ? merge(periodSegmentInfo.template, segmentInfo.template) : periodSegmentInfo.template && !segmentInfo.template ? periodSegmentInfo.template : !periodSegmentInfo.template && segmentInfo.template ? segmentInfo.template : undefined,
- base: periodSegmentInfo.base && segmentInfo.base ? merge(periodSegmentInfo.base, segmentInfo.base) : periodSegmentInfo.base && !segmentInfo.base ? periodSegmentInfo.base : !periodSegmentInfo.base && segmentInfo.base ? segmentInfo.base : undefined,
- timeline: periodSegmentInfo.timeline && segmentInfo.timeline ? merge(periodSegmentInfo.timeline, segmentInfo.timeline) : periodSegmentInfo.timeline && !segmentInfo.timeline ? periodSegmentInfo.timeline : !periodSegmentInfo.timeline && segmentInfo.timeline ? segmentInfo.timeline : undefined
- };
+ const adaptationSetSegmentInfo = merge(periodSegmentInfo, segmentInfo);
return flatten(
representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, adaptationSetSegmentInfo)));
diff --git a/test/inheritAttributes.test.js b/test/inheritAttributes.test.js
index 30d1fe7d..ab725c70 100644
--- a/test/inheritAttributes.test.js
+++ b/test/inheritAttributes.test.js
@@ -73,12 +73,7 @@ QUnit.module('getSegmentInformation');
QUnit.test('undefined Segment information when no Segment nodes', function(assert) {
const adaptationSet = { childNodes: [] };
- const expected = {
- template: void 0,
- timeline: void 0,
- list: void 0,
- base: void 0
- };
+ const expected = {};
assert.deepEqual(getSegmentInformation(adaptationSet), expected,
'undefined segment info');
@@ -93,10 +88,7 @@ QUnit.test('gets SegmentTemplate attributes', function(assert) {
}]
};
const expected = {
- template: { media: 'video.mp4' },
- timeline: void 0,
- list: void 0,
- base: void 0
+ template: { media: 'video.mp4' }
};
assert.deepEqual(getSegmentInformation(adaptationSet), expected,
@@ -112,14 +104,11 @@ QUnit.test('gets SegmentList attributes', function(assert) {
}]
};
const expected = {
- template: void 0,
- timeline: void 0,
list: {
duration: '10',
segmentUrls: [],
initialization: {}
- },
- base: void 0
+ }
};
assert.deepEqual(getSegmentInformation(adaptationSet), expected,
@@ -135,9 +124,6 @@ QUnit.test('gets SegmentBase attributes', function(assert) {
}]
};
const expected = {
- template: void 0,
- timeline: void 0,
- list: void 0,
base: { duration: '10', initialization: {} }
};
@@ -167,9 +153,7 @@ QUnit.test('gets SegmentTemplate and SegmentTimeline attributes', function(asser
};
const expected = {
template: { media: 'video.mp4' },
- timeline: [{ d: '10' }, { d: '5' }, { d: '7' }],
- list: void 0,
- base: void 0
+ timeline: [{ d: '10' }, { d: '5' }, { d: '7' }]
};
assert.deepEqual(getSegmentInformation(adaptationSet), expected,
@@ -227,10 +211,7 @@ QUnit.test('end to end - basic', function(assert) {
width: '720'
},
segmentInfo: {
- base: undefined,
- list: undefined,
- template: {},
- timeline: undefined
+ template: {}
}
}, {
attributes: {
@@ -244,12 +225,7 @@ QUnit.test('end to end - basic', function(assert) {
role: {},
sourceDuration: 30
},
- segmentInfo: {
- base: undefined,
- list: undefined,
- template: undefined,
- timeline: undefined
- }
+ segmentInfo: {}
}];
assert.equal(actual.length, 2);
@@ -303,10 +279,7 @@ QUnit.test('end to end - inherits BaseURL from all levels', function(assert) {
width: '720'
},
segmentInfo: {
- base: undefined,
- list: undefined,
- template: {},
- timeline: undefined
+ template: {}
}
}, {
attributes: {
@@ -320,12 +293,7 @@ QUnit.test('end to end - inherits BaseURL from all levels', function(assert) {
role: {},
sourceDuration: 30
},
- segmentInfo: {
- base: undefined,
- list: undefined,
- template: undefined,
- timeline: undefined
- }
+ segmentInfo: { }
}];
assert.equal(actual.length, 2);
@@ -379,10 +347,7 @@ QUnit.test('end to end - alternate BaseURLs', function(assert) {
width: '720'
},
segmentInfo: {
- base: undefined,
- list: undefined,
- template: {},
- timeline: undefined
+ template: {}
}
}, {
attributes: {
@@ -401,10 +366,7 @@ QUnit.test('end to end - alternate BaseURLs', function(assert) {
width: '720'
},
segmentInfo: {
- base: undefined,
- list: undefined,
- template: {},
- timeline: undefined
+ template: {}
}
}, {
attributes: {
@@ -423,10 +385,7 @@ QUnit.test('end to end - alternate BaseURLs', function(assert) {
width: '720'
},
segmentInfo: {
- base: undefined,
- list: undefined,
- template: {},
- timeline: undefined
+ template: {}
}
}, {
attributes: {
@@ -445,10 +404,7 @@ QUnit.test('end to end - alternate BaseURLs', function(assert) {
width: '720'
},
segmentInfo: {
- base: undefined,
- list: undefined,
- template: {},
- timeline: undefined
+ template: {}
}
}, {
attributes: {
@@ -462,12 +418,7 @@ QUnit.test('end to end - alternate BaseURLs', function(assert) {
role: {},
sourceDuration: 30
},
- segmentInfo: {
- base: undefined,
- list: undefined,
- template: undefined,
- timeline: undefined
- }
+ segmentInfo: {}
}, {
attributes: {
bandwidth: '256',
@@ -480,12 +431,7 @@ QUnit.test('end to end - alternate BaseURLs', function(assert) {
role: {},
sourceDuration: 30
},
- segmentInfo: {
- base: undefined,
- list: undefined,
- template: undefined,
- timeline: undefined
- }
+ segmentInfo: {}
}];
assert.equal(actual.length, 6);
@@ -552,10 +498,7 @@ QUnit.test(' End to End test for checking support of segments in representation'
initialization: {
range: '0-567'
}
- },
- list: undefined,
- template: undefined,
- timeline: undefined
+ }
}
}, {
attributes: {
@@ -576,10 +519,7 @@ QUnit.test(' End to End test for checking support of segments in representation'
initialization: {
range: '0-987'
}
- },
- list: undefined,
- template: undefined,
- timeline: undefined
+ }
}
}, {
attributes: {
@@ -593,12 +533,7 @@ QUnit.test(' End to End test for checking support of segments in representation'
role: {},
sourceDuration: 30
},
- segmentInfo: {
- base: undefined,
- list: undefined,
- template: undefined,
- timeline: undefined
- }
+ segmentInfo: {}
}];
assert.equal(actual.length, 3);
@@ -662,10 +597,7 @@ QUnit.test(' End to End test for checking support of segments in period ', funct
initialization: {
range: '0-1111'
}
- },
- list: undefined,
- template: undefined,
- timeline: undefined
+ }
}
}, {
attributes: {
@@ -687,10 +619,7 @@ QUnit.test(' End to End test for checking support of segments in period ', funct
initialization: {
range: '0-1111'
}
- },
- list: undefined,
- template: undefined,
- timeline: undefined
+ }
}
}, {
attributes: {
@@ -712,10 +641,7 @@ QUnit.test(' End to End test for checking support of segments in period ', funct
initialization: {
range: '0-1111'
}
- },
- list: undefined,
- template: undefined,
- timeline: undefined
+ }
}
}];
@@ -781,10 +707,7 @@ QUnit.test(' End to End test for checking support of Segments in Adaptation set'
range: '0-8888'
}
- },
- list: undefined,
- template: undefined,
- timeline: undefined
+ }
}
}, {
attributes: {
@@ -806,10 +729,7 @@ QUnit.test(' End to End test for checking support of Segments in Adaptation set'
initialization: {
range: '0-8888'
}
- },
- list: undefined,
- template: undefined,
- timeline: undefined
+ }
}
}, {
attributes: {
@@ -824,12 +744,7 @@ QUnit.test(' End to End test for checking support of Segments in Adaptation set'
role: {},
sourceDuration: 30
},
- segmentInfo: {
- base: undefined,
- list: undefined,
- template: undefined,
- timeline: undefined
- }
+ segmentInfo: {}
}];
assert.equal(actual.length, 3);
From 90c0595e7e877964700d16204772ab85c271ed57 Mon Sep 17 00:00:00 2001
From: ishita12 <30434843+ishita12@users.noreply.github.com>
Date: Tue, 20 Feb 2018 11:42:21 -0500
Subject: [PATCH 6/9] Changing order of attributes
---
src/inheritAttributes.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/inheritAttributes.js b/src/inheritAttributes.js
index 54744f8b..d2b40046 100644
--- a/src/inheritAttributes.js
+++ b/src/inheritAttributes.js
@@ -222,7 +222,7 @@ export const toRepresentations =
export const toAdaptationSets = (mpdAttributes, mpdBaseUrls) => (period, periodIndex) => {
const periodBaseUrls = buildBaseUrls(mpdBaseUrls, findChildren(period, 'BaseURL'));
const periodAtt = getAttributes(period);
- const periodAttributes = shallowMerge(periodAtt, { periodIndex }, mpdAttributes);
+ const periodAttributes = shallowMerge(mpdAttributes, periodAtt, { periodIndex });
const adaptationSets = findChildren(period, 'AdaptationSet');
const periodSegmentInfo = getSegmentInformation(period);
From bd9d668e9812c7dbd1ab1c718074e33b989fc266 Mon Sep 17 00:00:00 2001
From: ishita12 <30434843+ishita12@users.noreply.github.com>
Date: Tue, 20 Feb 2018 14:04:23 -0500
Subject: [PATCH 7/9] Updating shallowMerge to be a deepMerge function
---
package-lock.json | 5 -----
package.json | 1 -
src/inheritAttributes.js | 19 ++++++++++---------
src/toPlaylists.js | 8 ++++----
src/utils/object.js | 23 +++++++++++++++++------
test/utils.test.js | 20 ++++++++++----------
6 files changed, 41 insertions(+), 35 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index 7b5b1948..21dd4492 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1770,11 +1770,6 @@
"integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=",
"dev": true
},
- "deepmerge": {
- "version": "2.0.1",
- "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-2.0.1.tgz",
- "integrity": "sha512-VIPwiMJqJ13ZQfaCsIFnp5Me9tnjURiaIFxfz7EH0Ci0dTSQpZtSLrqOicXqEd/z2r+z+Klk9GzmnRsgpgbOsQ=="
- },
"define-properties": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.2.tgz",
diff --git a/package.json b/package.json
index c3e397b0..85785845 100644
--- a/package.json
+++ b/package.json
@@ -87,7 +87,6 @@
"version": "5.0.0"
},
"dependencies": {
- "deepmerge": "^2.0.1",
"global": "^4.3.0",
"url-toolkit": "^2.1.1"
}
diff --git a/src/inheritAttributes.js b/src/inheritAttributes.js
index d2b40046..88d99e3a 100644
--- a/src/inheritAttributes.js
+++ b/src/inheritAttributes.js
@@ -1,10 +1,11 @@
import { flatten } from './utils/list';
-import { shallowMerge, getAttributes } from './utils/object';
+import { getAttributes } from './utils/object';
import { parseDuration } from './utils/time';
import { findChildren, getContent } from './utils/xml';
import resolveUrl from './utils/resolveUrl';
import errors from './errors';
-import merge from 'deepmerge';
+// import merge from 'deepmerge';
+import { merge } from './utils/object';
/**
* Builds a list of urls that is the product of the reference urls and BaseURL values
@@ -53,7 +54,7 @@ export const getSegmentInformation = (adaptationSet) => {
const segmentTemplate = findChildren(adaptationSet, 'SegmentTemplate')[0];
const segmentList = findChildren(adaptationSet, 'SegmentList')[0];
const segmentUrls = segmentList && findChildren(segmentList, 'SegmentURL')
- .map(s => shallowMerge({ tag: 'SegmentURL' }, getAttributes(s)));
+ .map(s => merge({ tag: 'SegmentURL' }, getAttributes(s)));
const segmentBase = findChildren(adaptationSet, 'SegmentBase')[0];
const segmentTimelineParentNode = segmentList || segmentTemplate;
const segmentTimeline = segmentTimelineParentNode &&
@@ -83,13 +84,13 @@ export const getSegmentInformation = (adaptationSet) => {
template,
timeline: segmentTimeline &&
findChildren(segmentTimeline, 'S').map(s => getAttributes(s)),
- list: segmentList && shallowMerge(
+ list: segmentList && merge(
getAttributes(segmentList),
{
segmentUrls,
initialization: getAttributes(segmentInitialization)
}),
- base: segmentBase && shallowMerge(
+ base: segmentBase && merge(
getAttributes(segmentBase), {
initialization: getAttributes(segmentInitialization)
})
@@ -143,13 +144,13 @@ export const inheritBaseUrls =
(adaptationSetAttributes, adaptationSetBaseUrls, adaptationSetSegmentInfo) => (representation) => {
const repBaseUrlElements = findChildren(representation, 'BaseURL');
const repBaseUrls = buildBaseUrls(adaptationSetBaseUrls, repBaseUrlElements);
- const attributes = shallowMerge(adaptationSetAttributes, getAttributes(representation));
+ const attributes = merge(adaptationSetAttributes, getAttributes(representation));
const representationSegmentInfo = getSegmentInformation(representation);
return repBaseUrls.map(baseUrl => {
return {
segmentInfo: merge(adaptationSetSegmentInfo, representationSegmentInfo),
- attributes: shallowMerge(attributes, { baseUrl })
+ attributes: merge(attributes, { baseUrl })
};
});
};
@@ -183,7 +184,7 @@ export const toRepresentations =
findChildren(adaptationSet, 'BaseURL'));
const role = findChildren(adaptationSet, 'Role')[0];
const roleAttributes = { role: getAttributes(role) };
- const attrs = shallowMerge(periodAttributes,
+ const attrs = merge(periodAttributes,
adaptationSetAttributes,
roleAttributes);
const segmentInfo = getSegmentInformation(adaptationSet);
@@ -222,7 +223,7 @@ export const toRepresentations =
export const toAdaptationSets = (mpdAttributes, mpdBaseUrls) => (period, periodIndex) => {
const periodBaseUrls = buildBaseUrls(mpdBaseUrls, findChildren(period, 'BaseURL'));
const periodAtt = getAttributes(period);
- const periodAttributes = shallowMerge(mpdAttributes, periodAtt, { periodIndex });
+ const periodAttributes = merge(mpdAttributes, periodAtt, { periodIndex });
const adaptationSets = findChildren(period, 'AdaptationSet');
const periodSegmentInfo = getSegmentInformation(period);
diff --git a/src/toPlaylists.js b/src/toPlaylists.js
index e231572c..48379225 100644
--- a/src/toPlaylists.js
+++ b/src/toPlaylists.js
@@ -1,4 +1,4 @@
-import { shallowMerge } from './utils/object';
+import { merge } from './utils/object';
import { segmentsFromTemplate } from './segment/segmentTemplate';
import { segmentsFromList } from './segment/segmentList';
import { segmentsFromBase } from './segment/segmentBase';
@@ -6,16 +6,16 @@ import { segmentsFromBase } from './segment/segmentBase';
export const generateSegments = (segmentInfo, attributes) => {
if (segmentInfo.template) {
return segmentsFromTemplate(
- shallowMerge(attributes, segmentInfo.template),
+ merge(attributes, segmentInfo.template),
segmentInfo.timeline
);
}
if (segmentInfo.base) {
- return segmentsFromBase(shallowMerge(attributes, segmentInfo.base));
+ return segmentsFromBase(merge(attributes, segmentInfo.base));
}
if (segmentInfo.list) {
return segmentsFromList(
- shallowMerge(attributes, segmentInfo.list), segmentInfo.timeline
+ merge(attributes, segmentInfo.list), segmentInfo.timeline
);
}
};
diff --git a/src/utils/object.js b/src/utils/object.js
index e2565f4d..3727bb63 100644
--- a/src/utils/object.js
+++ b/src/utils/object.js
@@ -1,13 +1,24 @@
import { from } from './list';
-export const shallowMerge = (...objects) => {
+export const merge = (...objects) => {
+
+ const isObject = (obj) => {
+ return obj && typeof obj === 'object';
+ };
+
return objects.reduce((x, y) => {
- return Object.keys(y)
- .reduce((o, key) => {
- o[key] = y[key];
- return o;
- }, x);
+ Object.keys(y).forEach(key => {
+
+ if (Array.isArray(x[key]) && Array.isArray(y[key])) {
+ x[key] = x[key].concat(y[key]);
+ } else if (isObject(x[key]) && isObject(y[key])) {
+ x[key] = merge(x[key], y[key]);
+ } else {
+ x[key] = y[key];
+ }
+ });
+ return x;
}, {});
};
diff --git a/test/utils.test.js b/test/utils.test.js
index b67c33cb..67287e42 100644
--- a/test/utils.test.js
+++ b/test/utils.test.js
@@ -1,4 +1,4 @@
-import { shallowMerge, getAttributes } from '../src/utils/object';
+import { getAttributes, merge } from '../src/utils/object';
import { parseDuration } from '../src/utils/time';
import { flatten, range, from } from '../src/utils/list';
import { findChildren, getContent } from '../src/utils/xml';
@@ -8,25 +8,25 @@ import QUnit from 'qunit';
QUnit.module('utils');
-QUnit.module('shallowMerge');
+QUnit.module('merge');
QUnit.test('empty', function(assert) {
- assert.deepEqual(shallowMerge({}, { a: 1 }), { a: 1 });
- assert.deepEqual(shallowMerge({ a: 1 }, { a: 1 }), { a: 1 });
- assert.deepEqual(shallowMerge({ a: 1 }, {}), { a: 1 });
+ assert.deepEqual(merge({}, { a: 1 }), { a: 1 });
+ assert.deepEqual(merge({ a: 1 }, { a: 1 }), { a: 1 });
+ assert.deepEqual(merge({ a: 1 }, {}), { a: 1 });
});
QUnit.test('append', function(assert) {
- assert.deepEqual(shallowMerge({ a: 1 }, { b: 3 }), { a: 1, b: 3 });
+ assert.deepEqual(merge({ a: 1 }, { b: 3 }), { a: 1, b: 3 });
});
QUnit.test('overwrite', function(assert) {
- assert.deepEqual(shallowMerge({ a: 1 }, { a: 2 }), { a: 2 });
+ assert.deepEqual(merge({ a: 1 }, { a: 2 }), { a: 2 });
});
QUnit.test('empty', function(assert) {
- assert.deepEqual(shallowMerge({}, {}), {});
- assert.deepEqual(shallowMerge({}, 1), {});
- assert.deepEqual(shallowMerge(1, {}), {});
+ assert.deepEqual(merge({}, {}), {});
+ assert.deepEqual(merge({}, 1), {});
+ assert.deepEqual(merge(1, {}), {});
});
QUnit.module('flatten');
From 984c176f755239c6b8e909aa4680c8826509faa4 Mon Sep 17 00:00:00 2001
From: ishita12 <30434843+ishita12@users.noreply.github.com>
Date: Tue, 20 Feb 2018 14:47:33 -0500
Subject: [PATCH 8/9] Updating shallowMerge to be a deepMerge function
---
src/inheritAttributes.js | 4 +---
src/toPlaylists.js | 2 +-
src/utils/object.js | 24 ++++++++++++------------
3 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/src/inheritAttributes.js b/src/inheritAttributes.js
index 88d99e3a..0f31d791 100644
--- a/src/inheritAttributes.js
+++ b/src/inheritAttributes.js
@@ -1,11 +1,9 @@
import { flatten } from './utils/list';
-import { getAttributes } from './utils/object';
+import { getAttributes, merge } from './utils/object';
import { parseDuration } from './utils/time';
import { findChildren, getContent } from './utils/xml';
import resolveUrl from './utils/resolveUrl';
import errors from './errors';
-// import merge from 'deepmerge';
-import { merge } from './utils/object';
/**
* Builds a list of urls that is the product of the reference urls and BaseURL values
diff --git a/src/toPlaylists.js b/src/toPlaylists.js
index 48379225..a8812118 100644
--- a/src/toPlaylists.js
+++ b/src/toPlaylists.js
@@ -2,7 +2,7 @@ import { merge } from './utils/object';
import { segmentsFromTemplate } from './segment/segmentTemplate';
import { segmentsFromList } from './segment/segmentList';
import { segmentsFromBase } from './segment/segmentBase';
-// import merge from 'deepmerge';
+
export const generateSegments = (segmentInfo, attributes) => {
if (segmentInfo.template) {
return segmentsFromTemplate(
diff --git a/src/utils/object.js b/src/utils/object.js
index 3727bb63..35308975 100644
--- a/src/utils/object.js
+++ b/src/utils/object.js
@@ -1,24 +1,24 @@
import { from } from './list';
-export const merge = (...objects) => {
+const isObject = (obj) => {
+ return !!obj && typeof obj === 'object';
+};
- const isObject = (obj) => {
- return obj && typeof obj === 'object';
- };
+export const merge = (...objects) => {
- return objects.reduce((x, y) => {
+ return objects.reduce((result, source) => {
- Object.keys(y).forEach(key => {
+ Object.keys(source).forEach(key => {
- if (Array.isArray(x[key]) && Array.isArray(y[key])) {
- x[key] = x[key].concat(y[key]);
- } else if (isObject(x[key]) && isObject(y[key])) {
- x[key] = merge(x[key], y[key]);
+ if (Array.isArray(result[key]) && Array.isArray(source[key])) {
+ result[key] = result[key].concat(source[key]);
+ } else if (isObject(result[key]) && isObject(source[key])) {
+ result[key] = merge(result[key], source[key]);
} else {
- x[key] = y[key];
+ result[key] = source[key];
}
});
- return x;
+ return result;
}, {});
};
From 425eaf96d7bb2807bc6d7f1d174d6238540182ef Mon Sep 17 00:00:00 2001
From: ishita12 <30434843+ishita12@users.noreply.github.com>
Date: Fri, 23 Feb 2018 14:16:28 -0500
Subject: [PATCH 9/9] Adding tests for testing merge function
---
test/utils.test.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/test/utils.test.js b/test/utils.test.js
index 67287e42..8f1044e3 100644
--- a/test/utils.test.js
+++ b/test/utils.test.js
@@ -29,6 +29,55 @@ QUnit.test('empty', function(assert) {
assert.deepEqual(merge(1, {}), {});
});
+QUnit.test('Test for checking the merge when multiple segment Information are present', function(assert) {
+
+ const adaptationSetInfo = {
+
+ base: { duration: '10'}
+ };
+
+ const representationInfo = {
+
+ base: { duration: '25', indexRange: '230-252'}
+ };
+
+ const expected = {
+
+ base: { duration: '25', indexRange: '230-252'}
+ };
+
+ assert.deepEqual(merge(adaptationSetInfo, representationInfo), expected,
+ 'Merged SegmentBase info');
+
+});
+
+QUnit.test('Test for checking the merge when segment Information is present at a level and is undefined at another', function(assert) {
+ const periodInfo = {
+ base: {
+ initialization: {
+ range: '0-8888'
+
+ }
+ }
+ };
+
+ const adaptationSetInfo = {
+
+ base: { duration: '10', indexRange: '230-252'}
+ };
+
+ const representationInfo = {};
+
+ const expected = {
+
+ base: { duration: '10', indexRange: '230-252', initialization: {range: '0-8888'}}
+ };
+
+ assert.deepEqual(merge(periodInfo, adaptationSetInfo, representationInfo), expected,
+ 'Merged SegmentBase info');
+
+});
+
QUnit.module('flatten');
QUnit.test('empty', function(assert) {
assert.deepEqual(flatten([]), []);