Skip to content

Commit

Permalink
Sync each segment against PDT
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyparrish committed Jan 10, 2023
1 parent b4b43f7 commit 81c3dfd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,13 @@ shaka.hls.HlsParser = class {
// first segment.
const segment0TargetTime = segment0.syncTime - lowestSyncTime;
const streamOffset = segment0TargetTime - segment0.startTime;

// Modify all SegmentReferences equally.
streamInfo.stream.segmentIndex.offset(streamOffset);
this.offsetStreamInfo_(streamInfo, streamOffset);

// This is computed across all segments separately to manage
// accumulated drift in durations.
for (const segment of segmentIndex) {
segment.syncAgainst(lowestSyncTime);
}
}
}
}
Expand Down Expand Up @@ -2773,6 +2776,16 @@ shaka.hls.HlsParser = class {
}
}

// lowestSyncTime is a value from a previous playlist update. Use it to
// set reference start times. If this is the first playlist parse, we will
// skip this step, and wait until we have sync time across stream types.
const lowestSyncTime = this.lowestSyncTime_;
if (someSyncTime && lowestSyncTime != Infinity) {
for (const reference of references) {
reference.syncAgainst(lowestSyncTime);
}
}

return references;
}

Expand Down
18 changes: 18 additions & 0 deletions lib/media/segment_reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ goog.provide('shaka.media.InitSegmentReference');
goog.provide('shaka.media.SegmentReference');

goog.require('goog.asserts');
goog.require('shaka.log');
goog.require('shaka.util.ArrayUtils');


Expand Down Expand Up @@ -402,6 +403,23 @@ shaka.media.SegmentReference = class {
partial.trueEndTime += offset;
}
}

/**
* Sync this segment against a particular sync time that will serve as "0" in
* the presentation timeline.
*
* @param {number} lowestSyncTime
* @export
*/
syncAgainst(lowestSyncTime) {
if (this.syncTime == null) {
shaka.log.alwaysError('Sync attempted without sync time!');
return;
}
const desiredStart = this.syncTime - lowestSyncTime;
const offset = desiredStart - this.startTime;
this.offset(offset);
}
};


Expand Down

0 comments on commit 81c3dfd

Please sign in to comment.