Skip to content

Commit 8e59b38

Browse files
ishita12jforbes
authored andcommitted
feat: Adding support for segments in Period and Representation. (#19)
1 parent 4c7e2b4 commit 8e59b38

File tree

10 files changed

+1248
-132
lines changed

10 files changed

+1248
-132
lines changed

package-lock.json

Lines changed: 192 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"src/"
5050
],
5151
"devDependencies": {
52+
"babel-eslint": "^8.2.1",
5253
"babel-plugin-external-helpers": "^6.22.0",
5354
"babel-plugin-transform-object-assign": "^6.8.0",
5455
"babel-preset-es2015": "^6.14.0",

src/inheritAttributes.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { flatten } from './utils/list';
2-
import { shallowMerge, getAttributes } from './utils/object';
2+
import { getAttributes, merge } from './utils/object';
33
import { parseDuration } from './utils/time';
44
import { findChildren, getContent } from './utils/xml';
55
import resolveUrl from './utils/resolveUrl';
@@ -52,7 +52,7 @@ export const getSegmentInformation = (adaptationSet) => {
5252
const segmentTemplate = findChildren(adaptationSet, 'SegmentTemplate')[0];
5353
const segmentList = findChildren(adaptationSet, 'SegmentList')[0];
5454
const segmentUrls = segmentList && findChildren(segmentList, 'SegmentURL')
55-
.map(s => shallowMerge({ tag: 'SegmentURL' }, getAttributes(s)));
55+
.map(s => merge({ tag: 'SegmentURL' }, getAttributes(s)));
5656
const segmentBase = findChildren(adaptationSet, 'SegmentBase')[0];
5757
const segmentTimelineParentNode = segmentList || segmentTemplate;
5858
const segmentTimeline = segmentTimelineParentNode &&
@@ -78,21 +78,29 @@ export const getSegmentInformation = (adaptationSet) => {
7878
template.initialization = { sourceURL: template.initialization };
7979
}
8080

81-
return {
81+
const segmentInfo = {
8282
template,
8383
timeline: segmentTimeline &&
8484
findChildren(segmentTimeline, 'S').map(s => getAttributes(s)),
85-
list: segmentList && shallowMerge(
85+
list: segmentList && merge(
8686
getAttributes(segmentList),
8787
{
8888
segmentUrls,
8989
initialization: getAttributes(segmentInitialization)
9090
}),
91-
base: segmentBase && shallowMerge(
91+
base: segmentBase && merge(
9292
getAttributes(segmentBase), {
9393
initialization: getAttributes(segmentInitialization)
9494
})
9595
};
96+
97+
Object.keys(segmentInfo).forEach(key => {
98+
if (!segmentInfo[key]) {
99+
delete segmentInfo[key];
100+
}
101+
});
102+
103+
return segmentInfo;
96104
};
97105

98106
/**
@@ -131,15 +139,16 @@ export const getSegmentInformation = (adaptationSet) => {
131139
* Callback map function
132140
*/
133141
export const inheritBaseUrls =
134-
(adaptationSetAttributes, adaptationSetBaseUrls, segmentInfo) => (representation) => {
142+
(adaptationSetAttributes, adaptationSetBaseUrls, adaptationSetSegmentInfo) => (representation) => {
135143
const repBaseUrlElements = findChildren(representation, 'BaseURL');
136144
const repBaseUrls = buildBaseUrls(adaptationSetBaseUrls, repBaseUrlElements);
137-
const attributes = shallowMerge(adaptationSetAttributes, getAttributes(representation));
145+
const attributes = merge(adaptationSetAttributes, getAttributes(representation));
146+
const representationSegmentInfo = getSegmentInformation(representation);
138147

139148
return repBaseUrls.map(baseUrl => {
140149
return {
141-
segmentInfo,
142-
attributes: shallowMerge(attributes, { baseUrl })
150+
segmentInfo: merge(adaptationSetSegmentInfo, representationSegmentInfo),
151+
attributes: merge(attributes, { baseUrl })
143152
};
144153
});
145154
};
@@ -167,20 +176,21 @@ export const inheritBaseUrls =
167176
* Callback map function
168177
*/
169178
export const toRepresentations =
170-
(periodAttributes, periodBaseUrls) => (adaptationSet) => {
179+
(periodAttributes, periodBaseUrls, periodSegmentInfo) => (adaptationSet) => {
171180
const adaptationSetAttributes = getAttributes(adaptationSet);
172181
const adaptationSetBaseUrls = buildBaseUrls(periodBaseUrls,
173182
findChildren(adaptationSet, 'BaseURL'));
174183
const role = findChildren(adaptationSet, 'Role')[0];
175184
const roleAttributes = { role: getAttributes(role) };
176-
const attrs = shallowMerge(periodAttributes,
185+
const attrs = merge(periodAttributes,
177186
adaptationSetAttributes,
178187
roleAttributes);
179188
const segmentInfo = getSegmentInformation(adaptationSet);
180189
const representations = findChildren(adaptationSet, 'Representation');
190+
const adaptationSetSegmentInfo = merge(periodSegmentInfo, segmentInfo);
181191

182192
return flatten(
183-
representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, segmentInfo)));
193+
representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, adaptationSetSegmentInfo)));
184194
};
185195

186196
/**
@@ -210,10 +220,12 @@ export const toRepresentations =
210220
*/
211221
export const toAdaptationSets = (mpdAttributes, mpdBaseUrls) => (period, periodIndex) => {
212222
const periodBaseUrls = buildBaseUrls(mpdBaseUrls, findChildren(period, 'BaseURL'));
213-
const periodAttributes = shallowMerge({ periodIndex }, mpdAttributes);
223+
const periodAtt = getAttributes(period);
224+
const periodAttributes = merge(mpdAttributes, periodAtt, { periodIndex });
214225
const adaptationSets = findChildren(period, 'AdaptationSet');
226+
const periodSegmentInfo = getSegmentInformation(period);
215227

216-
return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls)));
228+
return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls, periodSegmentInfo)));
217229
};
218230

219231
/**
@@ -243,4 +255,3 @@ export const inheritAttributes = (mpd, manifestUri = '') => {
243255

244256
return flatten(periods.map(toAdaptationSets(mpdAttributes, mpdBaseUrls)));
245257
};
246-

src/toPlaylists.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
import { shallowMerge } from './utils/object';
1+
import { merge } from './utils/object';
22
import { segmentsFromTemplate } from './segment/segmentTemplate';
33
import { segmentsFromList } from './segment/segmentList';
44
import { segmentsFromBase } from './segment/segmentBase';
55

66
export const generateSegments = (segmentInfo, attributes) => {
77
if (segmentInfo.template) {
88
return segmentsFromTemplate(
9-
shallowMerge(segmentInfo.template, attributes),
9+
merge(attributes, segmentInfo.template),
1010
segmentInfo.timeline
1111
);
1212
}
13-
1413
if (segmentInfo.base) {
15-
return segmentsFromBase(shallowMerge(segmentInfo.base, attributes));
14+
return segmentsFromBase(merge(attributes, segmentInfo.base));
1615
}
17-
1816
if (segmentInfo.list) {
1917
return segmentsFromList(
20-
shallowMerge(segmentInfo.list, attributes), segmentInfo.timeline
18+
merge(attributes, segmentInfo.list), segmentInfo.timeline
2119
);
2220
}
2321
};
2422

25-
export const toPlaylists = representations => {
23+
export const toPlaylists = (representations) => {
2624
return representations.map(({ attributes, segmentInfo }) => {
2725
const segments = generateSegments(segmentInfo, attributes);
2826

0 commit comments

Comments
 (0)