021896e3 by David LaPalomento

Merge branch 'boxcast-sync-pts-offsets'

2 parents 7add9298 d94275ef
......@@ -30,29 +30,25 @@ window.videojs.Hls.AacStream = function() {
this.tags = [];
// (pts:uint, pes_size:int, dataAligned:Boolean):void
this.setNextTimeStamp = function(pts, pes_size, dataAligned) {
// on the first invocation, capture the starting PTS value
// (pts:uint):void
this.setTimeStampOffset = function(pts) {
pts_offset = pts;
// keep track of the last time a metadata tag was written out
// set the initial value so metadata will be generated before any
// payload data
lastMetaPts = pts - 1000;
};
// on subsequent invocations, calculate the PTS based on the starting offset
this.setNextTimeStamp = function(pts, pes_size, dataAligned) {
next_pts = pts - pts_offset;
pes_length = pes_size;
// If data is aligned, flush all internal buffers
if (dataAligned) {
state = 0;
}
};
// (pts:uint, pes_size:int, dataAligned:Boolean):void
this.setNextTimeStamp = function(pts, pes_size, dataAligned) {
next_pts = pts - pts_offset;
pes_length = pes_size;
this.setNextTimeStamp(pts, pes_size, dataAligned);
// If data is aligned, flush all internal buffers
if (dataAligned) {
state = 0;
}
};
// (data:ByteArray, o:int = 0, l:int = 0):void
......
......@@ -258,24 +258,21 @@
this.tags = [];
//(pts:uint, dts:uint, dataAligned:Boolean):void
this.setNextTimeStamp = function(pts, dts, dataAligned) {
// on the first invocation, capture the starting PTS value
//(pts:uint):void
this.setTimeStampOffset = function(pts) {
pts_offset = pts;
};
// on subsequent invocations, calculate the PTS based on the starting offset
this.setNextTimeStamp = function(pts, dts, dataAligned) {
// We could end up with a DTS less than 0 here. We need to deal with that!
next_pts = pts - pts_offset;
next_dts = dts - pts_offset;
// If data is aligned, flush all internal buffers
if (dataAligned) {
this.finishFrame();
}
};
//(pts:uint, dts:uint, dataAligned:Boolean):void
this.setNextTimeStamp = function(pts, dts, dataAligned) {
// We could end up with a DTS less than 0 here. We need to deal with that!
next_pts = pts - pts_offset;
next_dts = dts - pts_offset;
this.setNextTimeStamp(pts, dts, dataAligned);
// If data is aligned, flush all internal buffers
if (dataAligned) {
this.finishFrame();
}
};
this.finishFrame = function() {
......
......@@ -19,7 +19,10 @@
streamBuffer = new Uint8Array(MP2T_PACKET_LENGTH),
streamBufferByteCount = 0,
h264Stream = new H264Stream(),
aacStream = new AacStream();
aacStream = new AacStream(),
h264HasTimeStampOffset = false,
aacHasTimeStampOffset = false,
timeStampOffset;
// expose the stream metadata
self.stream = {
......@@ -344,10 +347,24 @@
}
if (pid === self.stream.programMapTable[STREAM_TYPES.h264]) {
if (!h264HasTimeStampOffset) {
h264HasTimeStampOffset = true;
if (timeStampOffset === undefined) {
timeStampOffset = pts;
}
h264Stream.setTimeStampOffset(timeStampOffset);
}
h264Stream.setNextTimeStamp(pts,
dts,
dataAlignmentIndicator);
} else if (pid === self.stream.programMapTable[STREAM_TYPES.adts]) {
if (!aacHasTimeStampOffset) {
aacHasTimeStampOffset = true;
if (timeStampOffset === undefined) {
timeStampOffset = pts;
}
aacStream.setTimeStampOffset(timeStampOffset);
}
aacStream.setNextTimeStamp(pts,
pesPacketSize,
dataAlignmentIndicator);
......
......@@ -70,6 +70,7 @@ test('starting PTS values can be negative', function() {
nalUnitTypes.access_unit_delimiter_rbsp
]);
h264Stream.setTimeStampOffset(-100);
h264Stream.setNextTimeStamp(-100, -100, true);
h264Stream.writeBytes(accessUnitDelimiter, 0, accessUnitDelimiter.byteLength);
h264Stream.setNextTimeStamp(-99, -99, true);
......