mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-14 15:56:38 +03:00
c13830e535
SegmentReference used to have presentationTimeOffset, which, subtracted from the period start time, was then _added_ to the timestamps in the segment by MediaSource. Now, SegmentReference has a timestampOffset field, which is exactly what MediaSource's timestampOffset field is set to on the SourceBuffer before this segment is appended. For DASH, this is periodStart minus presentationTimeOffset. This also adds append window start & end times to the SegmentReference. Now segments can be appended to SourceBuffers without reference to the period. Note that start & end times of the SegmentReference in each segment index are still relative to the period. This will change in a follow-up. Issue #1339 (flatten periods) Issue #892 (refactor StreamingEngine) Change-Id: I9d54eb2b529ec643c9475b8e9d218c3e2e826a26
237 lines
6.5 KiB
JavaScript
237 lines
6.5 KiB
JavaScript
/** @license
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.provide('shaka.media.InitSegmentReference');
|
|
goog.provide('shaka.media.SegmentReference');
|
|
|
|
goog.require('goog.asserts');
|
|
|
|
|
|
/**
|
|
* Creates an InitSegmentReference, which provides the location to an
|
|
* initialization segment.
|
|
*
|
|
* @export
|
|
*/
|
|
shaka.media.InitSegmentReference = class {
|
|
/**
|
|
* @param {function():!Array.<string>} uris A function that creates the URIs
|
|
* of the resource containing the segment.
|
|
* @param {number} startByte The offset from the start of the resource to the
|
|
* start of the segment.
|
|
* @param {?number} endByte The offset from the start of the resource to the
|
|
* end of the segment, inclusive. A value of null indicates that the
|
|
* segment extends to the end of the resource.
|
|
*/
|
|
constructor(uris, startByte, endByte) {
|
|
/** @type {function():!Array.<string>} */
|
|
this.getUris = uris;
|
|
|
|
/** @const {number} */
|
|
this.startByte = startByte;
|
|
|
|
/** @const {?number} */
|
|
this.endByte = endByte;
|
|
}
|
|
|
|
/**
|
|
* Returns the offset from the start of the resource to the
|
|
* start of the segment.
|
|
*
|
|
* @return {number}
|
|
* @export
|
|
*/
|
|
getStartByte() {
|
|
return this.startByte;
|
|
}
|
|
|
|
/**
|
|
* Returns the offset from the start of the resource to the end of the
|
|
* segment, inclusive. A value of null indicates that the segment extends
|
|
* to the end of the resource.
|
|
*
|
|
* @return {?number}
|
|
* @export
|
|
*/
|
|
getEndByte() {
|
|
return this.endByte;
|
|
}
|
|
|
|
/**
|
|
* Returns the size of the init segment.
|
|
* @return {?number}
|
|
*/
|
|
getSize() {
|
|
if (this.endByte) {
|
|
return this.endByte - this.startByte;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* SegmentReference provides the start time, end time, and location to a media
|
|
* segment.
|
|
*
|
|
* @export
|
|
*/
|
|
shaka.media.SegmentReference = class {
|
|
/**
|
|
* @param {number} position The segment's position within a particular Period.
|
|
* The following should hold true between any two SegmentReferences from the
|
|
* same Period, r1 and r2:
|
|
* IF r2.position > r1.position THEN
|
|
* [ (r2.startTime > r1.startTime) OR
|
|
* (r2.startTime == r1.startTime AND r2.endTime >= r1.endTime) ]
|
|
* @param {number} startTime The segment's start time in seconds, relative to
|
|
* the start of a particular Period.
|
|
* @param {number} endTime The segment's end time in seconds, relative to
|
|
* the start of a particular Period. The segment ends the instant before
|
|
* this time, so |endTime| must be strictly greater than |startTime|.
|
|
* @param {function():!Array.<string>} uris
|
|
* A function that creates the URIs of the resource containing the segment.
|
|
* @param {number} startByte The offset from the start of the resource to the
|
|
* start of the segment.
|
|
* @param {?number} endByte The offset from the start of the resource to the
|
|
* end of the segment, inclusive. A value of null indicates that the
|
|
* segment extends to the end of the resource.
|
|
* @param {shaka.media.InitSegmentReference} initSegmentReference
|
|
* The segment's initialization segment metadata, or null if the segments
|
|
* are self-initializing.
|
|
* @param {number} timestampOffset
|
|
* The amount of time, in seconds, that must be added to the segment's
|
|
* internal timestamps to align it to the presentation timeline. This
|
|
* value should equal the Period start time minus the first presentation
|
|
* timestamp of the first frame/sample in the Period. For example, for MP4
|
|
* based streams, this value should equal Period start minus the first
|
|
* segment's tfdt box's 'baseMediaDecodeTime' field (after it has been
|
|
* converted to seconds).
|
|
* @param {number} appendWindowStart
|
|
* The start of the append window for this reference, relative to the
|
|
* presentation. Any content from before this time will be removed by
|
|
* MediaSource.
|
|
* @param {number} appendWindowEnd
|
|
* The end of the append window for this reference, relative to the
|
|
* presentation. Any content from after this time will be removed by
|
|
* MediaSource.
|
|
*/
|
|
constructor(
|
|
position, startTime, endTime, uris, startByte, endByte,
|
|
initSegmentReference, timestampOffset, appendWindowStart,
|
|
appendWindowEnd) {
|
|
goog.asserts.assert(startTime < endTime,
|
|
'startTime must be less than endTime');
|
|
goog.asserts.assert((startByte < endByte) || (endByte == null),
|
|
'startByte must be < endByte');
|
|
|
|
/** @const {number} */
|
|
this.position = position;
|
|
|
|
/** @type {number} */
|
|
this.startTime = startTime;
|
|
|
|
/** @type {number} */
|
|
this.endTime = endTime;
|
|
|
|
/** @type {function():!Array.<string>} */
|
|
this.getUris = uris;
|
|
|
|
/** @const {number} */
|
|
this.startByte = startByte;
|
|
|
|
/** @const {?number} */
|
|
this.endByte = endByte;
|
|
|
|
/** @type {shaka.media.InitSegmentReference} */
|
|
this.initSegmentReference = initSegmentReference;
|
|
|
|
/** @type {number} */
|
|
this.timestampOffset = timestampOffset;
|
|
|
|
/** @type {number} */
|
|
this.appendWindowStart = appendWindowStart;
|
|
|
|
/** @type {number} */
|
|
this.appendWindowEnd = appendWindowEnd;
|
|
}
|
|
|
|
/**
|
|
* Returns the segment's position within a particular Period.
|
|
*
|
|
* @return {number} The segment's position.
|
|
* @export
|
|
*/
|
|
getPosition() {
|
|
return this.position;
|
|
}
|
|
|
|
/**
|
|
* Returns the segment's start time in seconds, relative to
|
|
* the start of a particular Period.
|
|
*
|
|
* @return {number}
|
|
* @export
|
|
*/
|
|
getStartTime() {
|
|
return this.startTime;
|
|
}
|
|
|
|
/**
|
|
* Returns the segment's end time in seconds, relative to
|
|
* the start of a particular Period.
|
|
*
|
|
* @return {number}
|
|
* @export
|
|
*/
|
|
getEndTime() {
|
|
return this.endTime;
|
|
}
|
|
|
|
/**
|
|
* Returns the offset from the start of the resource to the
|
|
* start of the segment.
|
|
*
|
|
* @return {number}
|
|
* @export
|
|
*/
|
|
getStartByte() {
|
|
return this.startByte;
|
|
}
|
|
|
|
/**
|
|
* Returns the offset from the start of the resource to the end of the
|
|
* segment, inclusive. A value of null indicates that the segment extends to
|
|
* the end of the resource.
|
|
*
|
|
* @return {?number}
|
|
* @export
|
|
*/
|
|
getEndByte() {
|
|
return this.endByte;
|
|
}
|
|
|
|
/**
|
|
* Returns the size of the segment.
|
|
* @return {?number}
|
|
*/
|
|
getSize() {
|
|
if (this.endByte) {
|
|
return this.endByte - this.startByte;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* A convenient typedef for when either type of reference is acceptable.
|
|
*
|
|
* @typedef {shaka.media.InitSegmentReference|shaka.media.SegmentReference}
|
|
*/
|
|
shaka.media.AnySegmentReference;
|