Skip to content

Commit

Permalink
1.0 plat 6201 (#266)
Browse files Browse the repository at this point in the history
* -1.0-moved reference pts+absolute timestamp to level of playlist (shared by all flavors)

* -1.0-init pts reference on-demand to support upgrade

* -1.0 typo fix
  • Loading branch information
igorshevach authored Oct 9, 2016
1 parent 6c1845a commit 24c0cfc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
45 changes: 21 additions & 24 deletions lib/playlistGenerator/ConcatSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ function ConcatSource(loggerInfo, playlistObj, parentObj, track, chunkPath) {
this.inner.type = "concat";
this.inner.tracks = track || 'v';
this.inner.basePath = chunkPath ? persistenceFormat.getBasePathFromFull(chunkPath) : '';
this.inner.refPTS = -1;
this.inner.refEncoderDTS = -1;
this.inner.offset = 0;

createTimestampList.call(this);
Expand Down Expand Up @@ -276,9 +274,7 @@ ConcatSource.prototype.split = function (newSrc,r) {
firstThatIndex = _.sortedIndex(that.durationsMan.firstDTS, r.to);

newSrc.inner.lastEncoderDTS = that.inner.lastEncoderDTS;
newSrc.inner.refEncoderDTS = that.inner.refEncoderDTS;
newSrc.inner.refPTS = that.inner.refPTS;


// erase clips from *noone's land*
// update duration of a last item before gap if needed
if(lastThisIndex > 0){
Expand Down Expand Up @@ -397,12 +393,12 @@ ConcatSource.prototype.checkDiscontinuity = function (fileInfo,track) {
if (that.durationsMan.durations.length === 0) {
checkClipStartTime.call(that,fileInfo);

that.inner.refPTS = track.firstDTS;
that.inner.refEncoderDTS = track.firstEncoderDTS;
that.playlist.ptsReference.absolute = track.firstDTS;
that.playlist.ptsReference.pts = track.firstEncoderDTS;
firstDTS = track.firstDTS;

that.logger.info("checkDiscontinuity. first chunk. that.inner.refPTS=%j that.inner.refEncoderDTS=%j",
that.inner.refPTS, that.inner.refEncoderDTS);
that.logger.info("checkDiscontinuity. first chunk. that.playlist.ptsReference.absolute=%j that.playlist.ptsReference.pts=%j",
that.playlist.ptsReference.absolute, that.playlist.ptsReference.pts);

} else {
var lastDTS = that.durationsMan.firstDTS.last + that.durationsMan.durations.last;
Expand All @@ -427,23 +423,24 @@ ConcatSource.prototype.checkDiscontinuity = function (fileInfo,track) {
that.ptsStats.addSample(correlation);

// reassign firstDTS in accordance with pts diff to avoid noise
if (that.inner.refPTS > 0) {
if (that.playlist.ptsReference.absolute > 0) {
// prevent wrap issues
var encDist = addWithOverflow(track.firstEncoderDTS-that.inner.refEncoderDTS,track.wrapEncoderDTS);
while( encDist >= track.wrapEncoderDTS / 2){
that.logger.debug("firstDTS - that.inner.refPTS >= track.wrapEncoderDTS / 2. that.inner.refPTS=%j that.inner.refEncoderDTS=%j",
that.inner.refPTS, that.inner.refEncoderDTS);
that.inner.refPTS += track.wrapEncoderDTS / 2;
that.inner.refEncoderDTS = addWithOverflow(that.inner.refEncoderDTS + track.wrapEncoderDTS / 2,track.wrapEncoderDTS);
encDist = addWithOverflow(track.firstEncoderDTS-that.inner.refEncoderDTS,track.wrapEncoderDTS);
var encDist = dtsDistance(track.firstEncoderDTS,that.playlist.ptsReference.pts,track.wrapEncoderDTS),
diffThreshold = track.wrapEncoderDTS / 4;
while( encDist >= diffThreshold){
that.logger.debug("firstDTS - that.playlist.ptsReference.absolute >= threshold. that.playlist.ptsReference.absolute=%j that.playlist.ptsReference.pts=%j threshold=%j",
that.playlist.ptsReference.absolute, that.playlist.ptsReference.pts,diffThreshold);
that.playlist.ptsReference.absolute += diffThreshold;
that.playlist.ptsReference.pts = addWithOverflow(that.playlist.ptsReference.pts + diffThreshold,track.wrapEncoderDTS);
encDist = dtsDistance(track.firstEncoderDTS,that.playlist.ptsReference.pts,track.wrapEncoderDTS);
}
firstDTS = that.inner.refPTS + dtsDistance(track.firstEncoderDTS, that.inner.refEncoderDTS,track.wrapEncoderDTS);
firstDTS = that.playlist.ptsReference.absolute + encDist;
}
// Fill drift information for diagnostics purposes
diagDrift['deltaPts'] = track.firstDTS - that.inner.refPTS;
diagDrift['deltaClock'] = track.firstEncoderDTS - that.inner.refEncoderDTS;
diagDrift['refPts'] = that.inner.refPTS;
diagDrift['refEncoderDts'] = that.inner.refEncoderDTS;
diagDrift['deltaPts'] = track.firstDTS - that.playlist.ptsReference.absolute;
diagDrift['deltaClock'] = dtsDistance(track.firstEncoderDTS,that.playlist.ptsReference.pts,track.wrapEncoderDTS);
diagDrift['refPts'] = that.playlist.ptsReference.absolute;
diagDrift['refEncoderDts'] = that.playlist.ptsReference.pts;

that.emit(playlistUtils.ClipEvents.diagnosticsInfo, that, fileInfo.flavor, diagDrift);

Expand Down Expand Up @@ -483,8 +480,8 @@ ConcatSource.prototype.checkDiscontinuity = function (fileInfo,track) {
Math.floor(track.firstDTS - lastDTS),
Math.floor(encDiff));

that.inner.refPTS = firstDTS;
that.inner.refEncoderDTS = track.firstEncoderDTS;
that.playlist.ptsReference.absolute = firstDTS;
that.playlist.ptsReference.pts = track.firstEncoderDTS;
that.ptsStats.reset();
}

Expand Down
14 changes: 14 additions & 0 deletions lib/playlistGenerator/Playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function Playlist(loggerInfo, serializationCtx) {
inner.clipTimes = [];
inner.sequences = [];
inner.initialClipIndex = 1;


}
// track when and were playlist was reloaded
if (!inner.history) {
Expand All @@ -81,6 +83,18 @@ function Playlist(loggerInfo, serializationCtx) {
util.inherits(Playlist,PlaylistItem);


Object.defineProperty(Playlist.prototype , "ptsReference", {
get: function get_ptsReference() {
if(!this.inner.reference) {
this.inner.reference = {
absolute: -1,
pts: -1
};
}
return this.inner.reference;
}
});

Object.defineProperty(Playlist.prototype , "sequences", {
get: function get_Sequences() {
return this.inner.sequences;
Expand Down
2 changes: 1 addition & 1 deletion lib/playlistGenerator/PlaylistGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function handleClipError (fileInfo){

var n = that.playlistImp.getCurrentTime();

var when = n;// + Math.max(fileInfo.windowSize || 0,1000*60*5);
var when = n + Math.max(fileInfo.windowSize || 0,1000*60*5);

that.logger.warn("handleClipError. chunk %j. will be removed in %j ms",chunkname,when-n);

Expand Down

0 comments on commit 24c0cfc

Please sign in to comment.