-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for segments in Period and Representation. #19
Changes from 7 commits
be6b06f
d5e4cbd
a7877d5
59e4b48
705b713
90c0595
bd9d668
984c176
425eaf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can remove this comment |
||
import { merge } from './utils/object'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can remove this line |
||
|
||
/** | ||
* Builds a list of urls that is the product of the reference urls and BaseURL values | ||
|
@@ -52,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 && | ||
|
@@ -78,21 +80,29 @@ export const getSegmentInformation = (adaptationSet) => { | |
template.initialization = { sourceURL: template.initialization }; | ||
} | ||
|
||
return { | ||
const segmentInfo = { | ||
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) | ||
}) | ||
}; | ||
|
||
Object.keys(segmentInfo).forEach(key => { | ||
if (!segmentInfo[key]) { | ||
delete segmentInfo[key]; | ||
} | ||
}); | ||
|
||
return segmentInfo; | ||
}; | ||
|
||
/** | ||
|
@@ -131,15 +141,16 @@ export const getSegmentInformation = (adaptationSet) => { | |
* Callback map function | ||
*/ | ||
export const inheritBaseUrls = | ||
(adaptationSetAttributes, adaptationSetBaseUrls, segmentInfo) => (representation) => { | ||
(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, | ||
attributes: shallowMerge(attributes, { baseUrl }) | ||
segmentInfo: merge(adaptationSetSegmentInfo, representationSegmentInfo), | ||
attributes: merge(attributes, { baseUrl }) | ||
}; | ||
}); | ||
}; | ||
|
@@ -167,20 +178,21 @@ export const inheritBaseUrls = | |
* Callback map function | ||
*/ | ||
export const toRepresentations = | ||
(periodAttributes, periodBaseUrls) => (adaptationSet) => { | ||
(periodAttributes, periodBaseUrls, periodSegmentInfo) => (adaptationSet) => { | ||
const adaptationSetAttributes = getAttributes(adaptationSet); | ||
const adaptationSetBaseUrls = buildBaseUrls(periodBaseUrls, | ||
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); | ||
const representations = findChildren(adaptationSet, 'Representation'); | ||
const adaptationSetSegmentInfo = merge(periodSegmentInfo, segmentInfo); | ||
|
||
return flatten( | ||
representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, segmentInfo))); | ||
representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, adaptationSetSegmentInfo))); | ||
}; | ||
|
||
/** | ||
|
@@ -210,10 +222,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 = merge(mpdAttributes, periodAtt, { periodIndex }); | ||
const adaptationSets = findChildren(period, 'AdaptationSet'); | ||
const periodSegmentInfo = getSegmentInformation(period); | ||
|
||
return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls))); | ||
return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls, periodSegmentInfo))); | ||
}; | ||
|
||
/** | ||
|
@@ -243,4 +257,3 @@ export const inheritAttributes = (mpd, manifestUri = '') => { | |
|
||
return flatten(periods.map(toAdaptationSets(mpdAttributes, mpdBaseUrls))); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
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'; | ||
|
||
// import merge from 'deepmerge'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leftover comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont forget to remove this comment |
||
export const generateSegments = (segmentInfo, attributes) => { | ||
if (segmentInfo.template) { | ||
return segmentsFromTemplate( | ||
shallowMerge(segmentInfo.template, attributes), | ||
merge(attributes, segmentInfo.template), | ||
segmentInfo.timeline | ||
); | ||
} | ||
|
||
if (segmentInfo.base) { | ||
return segmentsFromBase(shallowMerge(segmentInfo.base, attributes)); | ||
return segmentsFromBase(merge(attributes, segmentInfo.base)); | ||
} | ||
|
||
if (segmentInfo.list) { | ||
return segmentsFromList( | ||
shallowMerge(segmentInfo.list, attributes), segmentInfo.timeline | ||
merge(attributes, segmentInfo.list), segmentInfo.timeline | ||
); | ||
} | ||
}; | ||
|
||
export const toPlaylists = representations => { | ||
export const toPlaylists = (representations) => { | ||
return representations.map(({ attributes, segmentInfo }) => { | ||
const segments = generateSegments(segmentInfo, attributes); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can import
merge
along withgetAttributes
here