Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/parsers/manifest/dash/common/indexes/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,19 @@ export interface IBaseIndex {
* ```
*/
indexTimeOffset: number;
/** Information on the initialization segment. */
initialization:
| {
/**
* URL path, to add to the wanted CDN, to access the initialization segment.
* `null` if no URL exists.
*/
url: string | null;
/** possible byte range to request it. */
range?: [number, number] | undefined;
}
| undefined;
/**
* Information on the initialization segment.
* `null` if this index has no initialization segment.
*/
initialization: {
/**
* URL path, to add to the wanted CDN, to access the initialization segment.
* `null` if no URL exists.
*/
url: string | null;
/** possible byte range to request it. */
range?: [number, number] | undefined;
} | null;
/**
* URL base to access any segment.
* Can contain token to replace to convert it to real URLs.
Expand Down Expand Up @@ -257,10 +258,11 @@ export default class BaseRepresentationIndex implements IRepresentationIndex {
}

/**
* Construct init Segment.
* @returns {Object}
* Construct the metadata object for the init Segment linked to that index.
* Returns `null` if no initialization segment appears to be linked to that index.
* @returns {Object|null}
*/
getInitSegment(): ISegment {
getInitSegment(): ISegment | null {
return getInitSegment(this._index, this._isEMSGWhitelisted);
}

Expand Down
40 changes: 32 additions & 8 deletions src/parsers/manifest/dash/common/indexes/get_init_segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,50 @@
*/

import type { IPrivateInfos, ISegment } from "../../../../../manifest/index.ts";
import isNullOrUndefined from "../../../../../utils/is_null_or_undefined.ts";
import type { IEMSG } from "../../../../containers/isobmff/index.ts";

/**
* Construct init segment for the given index.
* Construct the metadata object for the init Segment linked to that index.
* Returns `null` if no initialization segment appears to be linked to that index.
* @param {Object} index
* @param {function} isEMSGWhitelisted
* @returns {Object}
* @returns {Object|null}
*/
export default function getInitSegment(
index: {
/** Convert time numbers into seconds (`ticks / timescale == seconds`). */
timescale: number;
initialization?:
{ url: string | null; range?: [number, number] | undefined } | undefined;
/**
* Information on the initialization segment present on the index.
* `null` if there's no such information.
*/
initialization: { url: string | null; range?: [number, number] | undefined } | null;
/** Optional range for the index segment (e.g. ISOBMFF's sidx). */
indexRange?: [number, number] | undefined;
/**
* Temporal offset, in the current timescale (see timescale), to add to the
* presentation time (time a segment has at decoding time) to obtain the
* corresponding media time (original time of the media segment in the index
* and on the media file).
* For example, to look for a segment beginning at a second `T` on a
* HTMLMediaElement, we actually will look for a segment in the index
* beginning at:
* ```
* T * timescale + indexTimeOffset
* ```
*/
indexTimeOffset: number;
},
/**
* Callback returning `true` if the corresponding inband event is supposed to
* be listened to.
*/
isEMSGWhitelisted?: (inbandEvent: IEMSG) => boolean,
): ISegment {
): ISegment | null {
const { initialization } = index;
if (initialization === null) {
return null;
}
const privateInfos: IPrivateInfos = {};
if (isEMSGWhitelisted !== undefined) {
privateInfos.isEMSGWhitelisted = isEMSGWhitelisted;
Expand All @@ -47,9 +71,9 @@ export default function getInitSegment(
end: 0,
duration: 0,
timescale: 1,
range: !isNullOrUndefined(initialization) ? initialization.range : undefined,
range: initialization.range,
indexRange: index.indexRange,
url: initialization?.url ?? null,
url: initialization.url,
complete: true,
privateInfos,
timestampOffset: -(index.indexTimeOffset / index.timescale),
Expand Down
37 changes: 21 additions & 16 deletions src/parsers/manifest/dash/common/indexes/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,19 @@ export interface IListIndex {
* ```
*/
indexTimeOffset: number;
/** Information on the initialization segment. */
initialization?:
| {
/**
* URL path, to add to the wanted CDN, to access the initialization segment.
* `null` if no URL exists.
*/
url: string | null;
/** possible byte range to request it. */
range?: [number, number] | undefined;
}
| undefined;
/**
* Information on the initialization segment.
* `null` if this index has no initialization segment.
*/
initialization: {
/**
* URL path, to add to the wanted CDN, to access the initialization segment.
* `null` if no URL exists.
*/
url: string | null;
/** possible byte range to request it. */
range?: [number, number] | undefined;
} | null;
/** Information on the list of segments for this index. */
list: Array<{
/**
Expand Down Expand Up @@ -186,17 +187,21 @@ export default class ListRepresentationIndex implements IRepresentationIndex {
indexTimeOffset,
indexRange: index.indexRange,
initialization: isNullOrUndefined(index.initialization)
? undefined
? null
: { url: initializationUrl, range: index.initialization.range },
};
}

/**
* Construct init Segment.
* @returns {Object}
* Construct the metadata object for the init Segment linked to that index.
* Returns `null` if no initialization segment appears to be linked to that index.
* @returns {Object|null}
*/
getInitSegment(): ISegment {
getInitSegment(): ISegment | null {
const initSegment = getInitSegment(this._index);
if (initSegment === null) {
return null;
}
if (initSegment.privateInfos === undefined) {
initSegment.privateInfos = {};
}
Expand Down
32 changes: 17 additions & 15 deletions src/parsers/manifest/dash/common/indexes/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ export interface ITemplateIndex {
timescale: number;
/** Byte range for a possible index of segments in the server. */
indexRange?: [number, number] | undefined;
/** Information on the initialization segment. */
initialization?:
| {
/**
* URL path, to add to the wanted CDN, to access the initialization segment.
*/
url: string | null;
/** possible byte range to request it. */
range?: [number, number] | undefined;
}
| undefined;
/**
* Information on the initialization segment.
* `null` if this index has no initialization segment.
*/
initialization: {
/**
* URL path, to add to the wanted CDN, to access the initialization segment.
*/
url: string | null;
/** possible byte range to request it. */
range?: [number, number] | undefined;
} | null;
/**
* URL base to access any segment.
* Can contain token to replace to convert it to real URLs.
Expand Down Expand Up @@ -214,7 +215,7 @@ export default class TemplateRepresentationIndex implements IRepresentationIndex
indexRange: index.indexRange,
indexTimeOffset,
initialization: isNullOrUndefined(index.initialization)
? undefined
? null
: { url: initializationUrl, range: index.initialization.range },
url: segmentUrlTemplate,
presentationTimeOffset,
Expand All @@ -229,10 +230,11 @@ export default class TemplateRepresentationIndex implements IRepresentationIndex
}

/**
* Construct init Segment.
* @returns {Object}
* Construct the metadata object for the init Segment linked to that index.
* Returns `null` if no initialization segment appears to be linked to that index.
* @returns {Object|null}
*/
getInitSegment(): ISegment {
getInitSegment(): ISegment | null {
return getInitSegment(this._index, this._isEMSGWhitelisted);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,19 @@ export interface ITimelineIndex {
* ```
*/
indexTimeOffset: number;
/** Information on the initialization segment. */
initialization?:
| {
/**
* URL path, to add to the wanted CDN, to access the initialization segment.
* `null` if no URL exists.
*/
url: string | null;
/** possible byte range to request it. */
range?: [number, number] | undefined;
}
| undefined;
/**
* Information on the initialization segment.
* `null` if this index has no initialization segment.
*/
initialization: {
/**
* URL path, to add to the wanted CDN, to access the initialization segment.
* `null` if no URL exists.
*/
url: string | null;
/** possible byte range to request it. */
range?: [number, number] | undefined;
} | null;
/**
* Template for the URL suffix (to concatenate to the wanted CDN), to access any
* media segment.
Expand Down Expand Up @@ -358,7 +359,7 @@ export default class TimelineRepresentationIndex implements IRepresentationIndex
indexRange: index.indexRange,
indexTimeOffset,
initialization: isNullOrUndefined(index.initialization)
? undefined
? null
: {
url: initializationUrl,
range: index.initialization.range,
Expand All @@ -383,10 +384,11 @@ export default class TimelineRepresentationIndex implements IRepresentationIndex
}

/**
* Construct init Segment.
* @returns {Object}
* Construct the metadata object for the init Segment linked to that index.
* Returns `null` if no initialization segment appears to be linked to that index.
* @returns {Object|null}
*/
getInitSegment(): ISegment {
getInitSegment(): ISegment | null {
return getInitSegment(this._index, this._isEMSGWhitelisted);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/contents/static/DASH_static_SelfInitializing/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const BASE_URL =
"http://" +
__TEST_CONTENT_SERVER__.URL +
":" +
__TEST_CONTENT_SERVER__.PORT +
"/DASH_static_SelfInitializing/media/";

export default {
url: BASE_URL + "manifest.mpd",
transport: "dash",
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<MPD
xmlns="urn:mpeg:dash:schema:mpd:2011"
type="static"
mediaPresentationDuration="PT10S"
minBufferTime="PT1S">
<Period id="period" duration="PT10S">
<AdaptationSet
id="video"
contentType="video"
mimeType="video/mp4"
codecs="avc1.42c00d"
segmentAlignment="true">
<Representation
id="video-representation"
bandwidth="50842"
width="320"
height="180">
<SegmentTemplate
timescale="1"
duration="10"
startNumber="1"
initialization="../../DASH_static_SegmentTemplate_Multi_Periods/media/mp4-live-periods-h264bl_low-.mp4"
media="../../DASH_static_SegmentTemplate_Multi_Periods/media/mp4-live-periods-h264bl_low-$Number$.m4s" />
</Representation>
</AdaptationSet>
<AdaptationSet
id="text-template"
contentType="text"
lang="en"
mimeType="text/vtt">
<Representation id="text-template-representation" bandwidth="256">
<SegmentTemplate
timescale="1"
duration="10"
startNumber="1"
media="text-template-$Number$.vtt" />
</Representation>
</AdaptationSet>
<AdaptationSet
id="text-timeline"
contentType="text"
lang="fr"
mimeType="text/vtt">
<Representation id="text-timeline-representation" bandwidth="256">
<SegmentTemplate timescale="1" media="text-timeline-$Time$.vtt">
<SegmentTimeline>
<S t="0" d="10" />
</SegmentTimeline>
</SegmentTemplate>
</Representation>
</AdaptationSet>
<AdaptationSet
id="text-list"
contentType="text"
lang="de"
mimeType="text/vtt">
<Representation id="text-list-representation" bandwidth="256">
<SegmentList timescale="1" duration="10">
<SegmentURL media="text-list.vtt" />
</SegmentList>
</Representation>
</AdaptationSet>
</Period>
</MPD>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
WEBVTT

00:00.000 --> 00:10.000
The SegmentList was loaded.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
WEBVTT

00:00.000 --> 00:10.000
The duration-based SegmentTemplate was loaded.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
WEBVTT

00:00.000 --> 00:10.000
The SegmentTimeline was loaded.
Loading
Loading