-
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
Parse <SegmentList> and <SegmentBase> #18
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fb9b91a
Merge pull request #1 from videojs/master
OshinKaramian e31b500
Real messy early commit
8629106
Merge pull request #2 from videojs/master
OshinKaramian 9e06c2c
Sort of resolve merge
6b89e5a
Add segmentBase
0fa09fc
Add some tests, modify some logic to accomodate spec, shuffle some co…
2a9f36a
Add more tests and cover more cases, add comments
1d5b64f
uncomment some commented out tests, eslint fixes, package.json fix
e7469b6
Add parantheses to make this clearer
2e4b4ec
Code review updates
4539d9c
Add parsing for Initialization nodes
9b1aad7
Code review updates and add tests for urlType
8bb1413
Fix lint errors
b9f69ad
Update variable names to be cleareR
06cd527
Fix indentation
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import errors from '../errors'; | ||
import urlTypeConverter from './urlType'; | ||
import { parseByDuration } from './timeParser'; | ||
|
||
/** | ||
* Translates SegmentBase into a set of segments. | ||
* (DASH SPEC Section 5.3.9.3.2) contains a set of <SegmentURL> nodes. Each | ||
* node should be translated into segment. | ||
* | ||
* @param {Object} attributes | ||
* Object containing all inherited attributes from parent elements with attribute | ||
* names as keys | ||
* @return {Object.<Array>} list of segments | ||
*/ | ||
export const segmentsFromBase = (attributes) => { | ||
const { | ||
baseUrl, | ||
initialization = {}, | ||
sourceDuration, | ||
timescale = 1, | ||
startNumber = 1, | ||
periodIndex = 0, | ||
indexRange = '', | ||
duration | ||
} = attributes; | ||
|
||
// base url is required for SegmentBase to work, per spec (Section 5.3.9.2.1) | ||
if (!baseUrl) { | ||
throw new Error(errors.NO_BASE_URL); | ||
} | ||
|
||
const initSegment = urlTypeConverter({ | ||
baseUrl, | ||
source: initialization.sourceURL, | ||
range: initialization.range | ||
}); | ||
const segment = urlTypeConverter({ baseUrl, source: baseUrl, range: indexRange }); | ||
|
||
segment.map = initSegment; | ||
|
||
const parsedTimescale = parseInt(timescale, 10); | ||
|
||
// If there is a duration, use it, otherwise use the given duration of the source | ||
// (since SegmentBase is only for one total segment) | ||
if (duration) { | ||
const parsedDuration = parseInt(duration, 10); | ||
const start = parseInt(startNumber, 10); | ||
const segmentTimeInfo = parseByDuration(start, | ||
periodIndex, | ||
parsedTimescale, | ||
parsedDuration, | ||
sourceDuration); | ||
|
||
if (segmentTimeInfo.length >= 1) { | ||
segment.duration = segmentTimeInfo[0].duration; | ||
segment.timeline = segmentTimeInfo[0].timeline; | ||
} | ||
} else if (sourceDuration) { | ||
segment.duration = (sourceDuration / parsedTimescale); | ||
segment.timeline = 0; | ||
} | ||
|
||
return [segment]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { parseByDuration, parseByTimeline } from './timeParser'; | ||
import urlTypeConverter from './urlType'; | ||
import errors from '../errors'; | ||
|
||
/** | ||
* Converts a <SegmentUrl> (of type URLType from the DASH spec 5.3.9.2 Table 14) | ||
* to an object that matches the output of a segment in videojs/mpd-parser | ||
* | ||
* @param {Object} attributes | ||
* Object containing all inherited attributes from parent elements with attribute | ||
* names as keys | ||
* @param {Object} segmentUrl | ||
* <SegmentURL> node to translate into a segment object | ||
* @return {Object} translated segment object | ||
*/ | ||
const SegmentURLToSegmentObject = (attributes, segmentUrl) => { | ||
const { baseUrl, initialization = {} } = attributes; | ||
|
||
const initSegment = urlTypeConverter({ | ||
baseUrl, | ||
source: initialization.sourceURL, | ||
range: initialization.range | ||
}); | ||
|
||
const segment = urlTypeConverter({ | ||
baseUrl, | ||
source: segmentUrl.media, | ||
range: segmentUrl.mediaRange | ||
}); | ||
|
||
segment.map = initSegment; | ||
|
||
return segment; | ||
}; | ||
|
||
/** | ||
* Generates a list of segments using information provided by the SegmentList element | ||
* SegmentList (DASH SPEC Section 5.3.9.3.2) contains a set of <SegmentURL> nodes. Each | ||
* node should be translated into segment. | ||
* | ||
* @param {Object} attributes | ||
* Object containing all inherited attributes from parent elements with attribute | ||
* names as keys | ||
* @param {Object[]|undefined} segmentTimeline | ||
* List of objects representing the attributes of each S element contained within | ||
* the SegmentTimeline element | ||
* @return {Object.<Array>} list of segments | ||
*/ | ||
export const segmentsFromList = (attributes, segmentTimeline) => { | ||
const { | ||
timescale = 1, | ||
duration, | ||
segmentUrls = [], | ||
periodIndex = 0, | ||
startNumber = 1 | ||
} = attributes; | ||
|
||
// Per spec (5.3.9.2.1) no way to determine segment duration OR | ||
// if both SegmentTimeline and @duration are defined, it is outside of spec. | ||
if ((!duration && !segmentTimeline) || | ||
(duration && segmentTimeline)) { | ||
throw new Error(errors.SEGMENT_TIME_UNSPECIFIED); | ||
} | ||
|
||
const parsedTimescale = parseInt(timescale, 10); | ||
const start = parseInt(startNumber, 10); | ||
const segmentUrlMap = segmentUrls.map(segmentUrlObject => | ||
SegmentURLToSegmentObject(attributes, segmentUrlObject)); | ||
let segmentTimeInfo; | ||
|
||
if (duration) { | ||
const parsedDuration = parseInt(duration, 10); | ||
|
||
segmentTimeInfo = parseByDuration(start, | ||
periodIndex, | ||
parsedTimescale, | ||
parsedDuration, | ||
attributes.sourceDuration); | ||
} | ||
|
||
if (segmentTimeline) { | ||
segmentTimeInfo = parseByTimeline(start, | ||
periodIndex, | ||
parsedTimescale, | ||
segmentTimeline, | ||
attributes.sourceDuration); | ||
} | ||
|
||
const segments = segmentTimeInfo.map((segmentTime, index) => { | ||
if (segmentUrlMap[index]) { | ||
const segment = segmentUrlMap[index]; | ||
|
||
segment.timeline = segmentTime.timeline; | ||
segment.duration = segmentTime.duration; | ||
return segment; | ||
} | ||
// Since we're mapping we should get rid of any blank segments (in case | ||
// the given SegmentTimeline is handling for more elements than we have | ||
// SegmentURLs for). | ||
}).filter(segment => segment); | ||
|
||
return segments; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this common/supposed/allowed to happen? What cases cause this?
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.
So... this shouldn't happen if the mpd is well constructed. But, let's say you have a segment timeline that defines r=10, but you only have 5 segments listed. We will have too many duration objects for the number of segments we have. I guess we could throw an error, but I felt like handling it and truncating made more sense in this case.
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.
Makes sense. I suppose its either we crash up front, or play what we can parse and just have an incomplete video, which is better than no video