-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:dzianis-dashkevich/web-media-box in…
…to dash-parser-parent-node
- Loading branch information
Showing
21 changed files
with
758 additions
and
53 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/web-media-box/src/dash-parser/consts/attributes.ts
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,44 @@ | ||
// All fields we want to retiive from specific Nodes | ||
// Note not all are required. | ||
|
||
// TODO: This file will be removed, but keeping so I can copy attributes to the | ||
// node processors. | ||
|
||
export interface Attribute { | ||
name: string, | ||
required: boolean, | ||
default?: unknown | ||
} | ||
|
||
export const BaseURLAttributes: Array<Attribute> = [ | ||
{ name: 'id', required: true }, | ||
]; | ||
|
||
export const SegmentTemplateAttributes: Array<Attribute> = [ | ||
{ name: 'media', required: false }, | ||
{ name: 'index', required: false }, | ||
{ name: 'initialization', required: false }, | ||
{ name: 'bitstreamSwitching', required: false }, | ||
]; | ||
|
||
export const UTCTimingAttributes: Array<Attribute> = [ | ||
{ name: 'schemeIdUri', required: true }, | ||
{ name: 'value', required: false }, | ||
]; | ||
|
||
export const EventStreamAttributes: Array<Attribute> = [ | ||
{ name: 'schemeIdUri', required: true }, | ||
{ name: 'value', required: false }, | ||
{ name: 'xlink:href', required: false }, | ||
{ name: 'xlink:actuate', required: false, default: `onRequest` }, | ||
{ name: 'timescale', required: false }, | ||
{ name: 'presentationTimeOffset', required: false, default: 0 }, | ||
]; | ||
|
||
export const EventAttributes: Array<Attribute> = [ | ||
{ name: 'presentationTime', required: false, default: 0 }, | ||
{ name: 'id', required: false }, | ||
{ name: 'duration', required: false }, | ||
{ name: 'contentEncoding', required: false }, | ||
{ name: 'messageData', required: false }, | ||
]; |
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
250 changes: 250 additions & 0 deletions
250
packages/web-media-box/src/dash-parser/parseAttributes.ts
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,250 @@ | ||
import { parseDivisionValue } from './utils/string'; | ||
import { parseDuration, parseDate } from './utils/time'; | ||
|
||
type Parsers = { | ||
[key: string]: (value: string) => string | number; | ||
} | ||
|
||
const parsers: Parsers = { | ||
/** | ||
* Specifies the duration of the entire Media Presentation. Format is a duration string | ||
* as specified in ISO 8601 | ||
* | ||
* @param value value of attribute as a string | ||
* @return The duration in seconds | ||
*/ | ||
mediaPresentationDuration(value: string): number { | ||
return parseDuration(value); | ||
}, | ||
|
||
/** | ||
* Specifies the Segment availability start time for all Segments referred to in this | ||
* MPD. For a dynamic manifest, it specifies the anchor for the earliest availability | ||
* time. Format is a date string as specified in ISO 8601 | ||
* | ||
* @param value value of attribute as a string | ||
* @return The date as seconds from unix epoch | ||
*/ | ||
availabilityStartTime(value: string): number { | ||
return parseDate(value) / 1000; | ||
}, | ||
|
||
/** | ||
* Specifies the smallest period between potential changes to the MPD. Format is a | ||
* duration string as specified in ISO 8601 | ||
* | ||
* @param value value of attribute as a string | ||
* @return The duration in seconds | ||
*/ | ||
minimumUpdatePeriod(value: string): number { | ||
return parseDuration(value); | ||
}, | ||
|
||
/** | ||
* Specifies the suggested presentation delay. Format is a | ||
* duration string as specified in ISO 8601 | ||
* | ||
* @param value value of attribute as a string | ||
* @return The duration in seconds | ||
*/ | ||
suggestedPresentationDelay(value: string): number { | ||
return parseDuration(value); | ||
}, | ||
|
||
/** | ||
* specifices the type of mpd. Can be either "static" or "dynamic" | ||
* | ||
* @param value value of attribute as a string | ||
* @return The type as a string | ||
*/ | ||
type(value: string): string { | ||
return value; | ||
}, | ||
|
||
/** | ||
* Specifies the duration of the smallest time shifting buffer for any Representation | ||
* in the MPD. Format is a duration string as specified in ISO 8601 | ||
* | ||
* @param value value of attribute as a string | ||
* @return The duration in seconds | ||
*/ | ||
timeShiftBufferDepth(value: string): number { | ||
return parseDuration(value); | ||
}, | ||
|
||
/** | ||
* Specifies the PeriodStart time of the Period relative to the availabilityStarttime. | ||
* Format is a duration string as specified in ISO 8601 | ||
* | ||
* @param value value of attribute as a string | ||
* @return The duration in seconds | ||
*/ | ||
start(value: string): number { | ||
return parseDuration(value); | ||
}, | ||
|
||
/** | ||
* Specifies the width of the visual presentation | ||
* | ||
* @param value value of attribute as a string | ||
* @return The parsed width | ||
*/ | ||
width(value: string): number { | ||
return parseInt(value, 10); | ||
}, | ||
|
||
/** | ||
* Specifies the height of the visual presentation | ||
* | ||
* @param value value of attribute as a string | ||
* @return The parsed height | ||
*/ | ||
height(value: string): number { | ||
return parseInt(value, 10); | ||
}, | ||
|
||
/** | ||
* Specifies the bitrate of the representation | ||
* | ||
* @param value value of attribute as a string | ||
* @return The parsed bandwidth | ||
*/ | ||
bandwidth(value: string): number { | ||
return parseInt(value, 10); | ||
}, | ||
|
||
/** | ||
* Specifies the frame rate of the representation | ||
* | ||
* @param value value of attribute as a string | ||
* @return The parsed frame rate | ||
*/ | ||
frameRate(value: string): number { | ||
return parseDivisionValue(value); | ||
}, | ||
|
||
/** | ||
* Specifies the number of the first Media Segment in this Representation in the Period | ||
* | ||
* @param value value of attribute as a string | ||
* @return The parsed number | ||
*/ | ||
startNumber(value: string): number { | ||
return parseInt(value, 10); | ||
}, | ||
|
||
/** | ||
* Specifies the timescale in units per seconds | ||
* | ||
* @param value of attribute as a string | ||
* @return The parsed timescale | ||
*/ | ||
timescale(value: string): number { | ||
return parseInt(value, 10); | ||
}, | ||
|
||
/** | ||
* Specifies the presentationTimeOffset. | ||
* | ||
* @param value value of the attribute as a string | ||
* @return The parsed presentationTimeOffset | ||
*/ | ||
presentationTimeOffset(value: string): number { | ||
return parseInt(value, 10); | ||
}, | ||
|
||
/** | ||
* Specifies the constant approximate Segment duration | ||
* NOTE: The <Period> element also contains an @duration attribute. This duration | ||
* specifies the duration of the Period. This attribute is currently not | ||
* supported by the rest of the parser, however we still check for it to prevent | ||
* errors. | ||
* | ||
* @param value value of attribute as a string | ||
* @return The parsed duration | ||
*/ | ||
duration(value: string): number { | ||
const parsedValue = parseInt(value, 10); | ||
|
||
if (isNaN(parsedValue)) { | ||
return parseDuration(value); | ||
} | ||
|
||
return parsedValue; | ||
}, | ||
|
||
/** | ||
* Specifies the Segment duration, in units of the value of the @timescale. | ||
* | ||
* @param value value of attribute as a string | ||
* @return The parsed duration | ||
*/ | ||
d(value: string): number { | ||
return parseInt(value, 10); | ||
}, | ||
|
||
/** | ||
* Specifies the MPD start time, in @timescale units, the first Segment in the series | ||
* starts relative to the beginning of the Period | ||
* | ||
* @param value value of attribute as a string | ||
* @return The parsed time | ||
*/ | ||
t(value: string): number { | ||
return parseInt(value, 10); | ||
}, | ||
|
||
/** | ||
* Specifies the repeat count of the number of following contiguous Segments with the | ||
* same duration expressed by the value of @d | ||
* | ||
* @param value value of attribute as a string | ||
* @return The parsed number | ||
*/ | ||
r(value: string): number { | ||
return parseInt(value, 10); | ||
}, | ||
|
||
/** | ||
* Specifies the presentationTime. | ||
* | ||
* @param value value of the attribute as a string | ||
* @return The parsed presentationTime | ||
*/ | ||
presentationTime(value: string): number { | ||
return parseInt(value, 10); | ||
}, | ||
|
||
/** | ||
* Default parser for all other attributes. Acts as a no-op and just returns the value | ||
* as a string | ||
* | ||
* @param value value of attribute as a string | ||
* @return Unparsed value | ||
*/ | ||
DEFAULT(value: string): string { | ||
return value; | ||
} | ||
}; | ||
|
||
/** | ||
* Gets all the attributes and values of the provided node, parses attributes with known | ||
* types, and returns an object with attribute names mapped to values. | ||
* | ||
* @param attributes The key/value pairs of attributes to parse | ||
* @return Object with all attributes parsed | ||
*/ | ||
export const parseAttributes = (attributes: Record<string, unknown>): Record<string, unknown> => { | ||
interface Attrs { | ||
[key: string]: unknown | ||
}; | ||
|
||
const newAttributes: Attrs = {}; | ||
|
||
for (const att in attributes) { | ||
const parseFn: (value: string) => string | number = parsers[att] || parsers.DEFAULT; | ||
newAttributes[att] = parseFn(attributes[att] as string); | ||
} | ||
|
||
return newAttributes; | ||
}; |
Oops, something went wrong.