-
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 1 commit
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
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. Same strategy as my other comment here |
||
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); | ||
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. Lets switch the order of the arguments here to be |
||
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))); | ||
}; | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,18 +4,18 @@ 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.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 | ||
); | ||
} | ||
}; | ||
|
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.
This is a nightmare to read. I think its best we try to come at this with a different approach.
The main issue with the merge is that if the second object in the merge has a property that is
undefined
, it overwrites that property withundefined
, so removing those properties from the object before we even get to merging should solve the issue without needing all this complex logic.I think that we should return to what you had before this commit of just merging the full segment info objects instead of merging these properties individually.
Then, to fix the issue of a property being
undefined
, ingetSegmentInformation
, before returning the segment info object, save it to a variable and then delete properties that are undefined