Skip to content

Commit

Permalink
Don't change start time in SegmentIndex.fit().
Browse files Browse the repository at this point in the history
Since we have gap jumping, we don't need to worry about a gap at the
beginning of the segment index.  By changing the start time of the
first segment, it makes merging complicated since the pre-fit and
post-fit times are different.  This difference can cause duplicate
entries in the index.

Issue shaka-project#1464
Closes shaka-project#1486

Change-Id: Ib3521e186cd8e256366a3c3e922e0764bd58bbd9
  • Loading branch information
TheModMaker authored and Isaev Ivan committed Jul 13, 2018
1 parent 2a1c2c5 commit a13d454
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
18 changes: 0 additions & 18 deletions lib/media/segment_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ goog.require('goog.asserts');
goog.require('shaka.log');
goog.require('shaka.media.SegmentReference');
goog.require('shaka.util.IDestroyable');
goog.require('shaka.util.ManifestParserUtils');



Expand Down Expand Up @@ -254,9 +253,6 @@ shaka.media.SegmentIndex.prototype.evict = function(time) {
* @param {?number} periodDuration
*/
shaka.media.SegmentIndex.prototype.fit = function(periodDuration) {
const tolerance =
shaka.util.ManifestParserUtils.GAP_OVERLAP_TOLERANCE_SECONDS;

goog.asserts.assert(periodDuration != null,
'Period duration must be known for static content!');
goog.asserts.assert(periodDuration != Infinity,
Expand Down Expand Up @@ -284,20 +280,6 @@ shaka.media.SegmentIndex.prototype.fit = function(periodDuration) {
return;
}

// Adjust the first SegmentReference if the start time is smaller than the gap
// tolerance (including negative).
let firstReference = this.references_[0];
if (firstReference.startTime < tolerance) {
this.references_[0] =
new shaka.media.SegmentReference(
firstReference.position,
/* startTime */ 0,
firstReference.endTime,
firstReference.getUris,
firstReference.startByte,
firstReference.endByte);
}

// Adjust the last SegmentReference.
let lastReference = this.references_[this.references_.length - 1];
this.references_[this.references_.length - 1] =
Expand Down
5 changes: 4 additions & 1 deletion lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,10 @@ shaka.media.StreamingEngine.prototype.getSegmentReferenceNeeded_ = function(
let optimalPosition = Math.max(0, position - 1);
reference = this.getSegmentReferenceIfAvailable_(
mediaState, currentPeriodIndex, optimalPosition);
let drift = (reference.endTime - reference.startTime) / 3;
if (playheadTime > reference.endTime + drift)
reference = this.getSegmentReferenceIfAvailable_(
mediaState, currentPeriodIndex, optimalPosition + 1);
}
return reference ||
this.getSegmentReferenceIfAvailable_(
Expand Down Expand Up @@ -1504,7 +1508,6 @@ shaka.media.StreamingEngine.prototype.fetchAndAppend_ = function(
// We may set |needInitSegment| to true in switch(), so set it to false here,
// since we want it to remain true if switch() is called.
mediaState.needInitSegment = false;

shaka.log.v2(logPrefix, 'fetching segment');
let fetchSegment = this.fetch_(reference, mediaState.type);

Expand Down
2 changes: 1 addition & 1 deletion lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2073,7 +2073,7 @@ shaka.Player.prototype.defaultConfig_ = function() {
ignoreTextStreamFailures: false,
startAtSegmentBoundary: false,
smallGapLimit: 0.5,
jumpLargeGaps: false,
jumpLargeGaps: true,
durationBackoff: 1
},
abrFactory: shaka.abr.SimpleAbrManager,
Expand Down
2 changes: 1 addition & 1 deletion test/media/segment_index_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() {
index.fit(/* periodDuration */ 15);
let newReferences = [
/* ref 0 dropped because it ends before the period starts */
makeReference(1, 0, 4, uri(1)), // start time clamped to 0
makeReference(1, -3, 4, uri(1)),
makeReference(2, 4, 11, uri(2)),
makeReference(3, 11, 15, uri(3)) // end time clamped to period
/* ref 4 dropped because it starts after the period ends */
Expand Down

0 comments on commit a13d454

Please sign in to comment.