Skip to content

Commit

Permalink
fix: Correctly use videoSegmentTimingInfo from the transmuxer
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Jul 16, 2019
1 parent b13d0fb commit 1c84622
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 78 deletions.
9 changes: 9 additions & 0 deletions src/media-segment-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const transmuxAndNotify = ({
isPartial,
trackInfoFn,
timingInfoFn,
videoSegmentTimingInfoFn,
id3Fn,
captionsFn,
dataFn,
Expand Down Expand Up @@ -318,6 +319,9 @@ const transmuxAndNotify = ({
videoEndFn(videoTimingInfo.end);
}
},
onVideoSegmentTimingInfo: (videoSegmentTimingInfo) => {
videoSegmentTimingInfoFn(videoSegmentTimingInfo);
},
onId3: (id3Frames, dispatchType) => {
id3Fn(segment, id3Frames, dispatchType);
},
Expand All @@ -343,6 +347,7 @@ const handleSegmentBytes = ({
captionParser,
trackInfoFn,
timingInfoFn,
videoSegmentTimingInfoFn,
id3Fn,
captionsFn,
dataFn,
Expand Down Expand Up @@ -431,6 +436,7 @@ const handleSegmentBytes = ({
isPartial,
trackInfoFn,
timingInfoFn,
videoSegmentTimingInfoFn,
id3Fn,
captionsFn,
dataFn,
Expand Down Expand Up @@ -620,6 +626,7 @@ const handleProgress = ({
progressFn,
trackInfoFn,
timingInfoFn,
videoSegmentTimingInfoFn,
id3Fn,
captionsFn,
dataFn,
Expand Down Expand Up @@ -725,6 +732,7 @@ export const mediaSegmentRequest = ({
progressFn,
trackInfoFn,
timingInfoFn,
videoSegmentTimingInfoFn,
id3Fn,
captionsFn,
dataFn,
Expand Down Expand Up @@ -804,6 +812,7 @@ export const mediaSegmentRequest = ({
progressFn,
trackInfoFn,
timingInfoFn,
videoSegmentTimingInfoFn,
id3Fn,
captionsFn,
dataFn,
Expand Down
16 changes: 7 additions & 9 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1555,10 +1555,7 @@ export default class SegmentLoader extends videojs.EventTarget {
segments
});

const videoSegmentTimingInfoCallback =
this.handleVideoSegmentTimingInfo_.bind(this, segmentInfo.requestId);

this.sourceUpdater_.appendBuffer({segmentInfo, type, bytes, videoSegmentTimingInfoCallback}, (error) => {
this.sourceUpdater_.appendBuffer(type, bytes, (error) => {
if (error) {
this.error(`appenderror for ${type} append with ${bytes.length} bytes`);
// If an append errors, we can't recover.
Expand All @@ -1570,7 +1567,7 @@ export default class SegmentLoader extends videojs.EventTarget {
});
}

handleVideoSegmentTimingInfo_(requestId, event) {
handleVideoSegmentTimingInfo_(requestId, videoSegmentTimingInfo) {
if (!this.pendingSegment_ || requestId !== this.pendingSegment_.requestId) {
return;
}
Expand All @@ -1582,14 +1579,14 @@ export default class SegmentLoader extends videojs.EventTarget {
}

segment.videoTimingInfo.transmuxerPrependedSeconds =
event.videoSegmentTimingInfo.prependedContentDuration || 0;
videoSegmentTimingInfo.prependedContentDuration || 0;
segment.videoTimingInfo.transmuxedPresentationStart =
event.videoSegmentTimingInfo.start.presentation;
videoSegmentTimingInfo.start.presentation;
segment.videoTimingInfo.transmuxedPresentationEnd =
event.videoSegmentTimingInfo.end.presentation;
videoSegmentTimingInfo.end.presentation;
// mainly used as a reference for debugging
segment.videoTimingInfo.baseMediaDecodeTime =
event.videoSegmentTimingInfo.baseMediaDecodeTime;
videoSegmentTimingInfo.baseMediaDecodeTime;
}

appendData_(segmentInfo, result) {
Expand Down Expand Up @@ -1658,6 +1655,7 @@ export default class SegmentLoader extends videojs.EventTarget {
progressFn: this.handleProgress_.bind(this),
trackInfoFn: this.handleTrackInfo_.bind(this),
timingInfoFn: this.handleTimingInfo_.bind(this),
videoSegmentTimingInfoFn: this.handleVideoSegmentTimingInfo_.bind(this, segmentInfo.requestId),
captionsFn: this.handleCaptions_.bind(this),
id3Fn: this.handleId3_.bind(this),

Expand Down
4 changes: 4 additions & 0 deletions src/segment-transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const processTransmux = ({
onTrackInfo,
onAudioTimingInfo,
onVideoTimingInfo,
onVideoSegmentTimingInfo,
onId3,
onCaptions,
onDone
Expand Down Expand Up @@ -102,6 +103,9 @@ export const processTransmux = ({
if (event.data.action === 'videoTimingInfo') {
onVideoTimingInfo(event.data.videoTimingInfo);
}
if (event.data.action === 'videoSegmentTimingInfo') {
onVideoSegmentTimingInfo(event.data.videoSegmentTimingInfo);
}
if (event.data.action === 'id3Frame') {
onId3([event.data.id3Frame], event.data.id3Frame.dispatchType);
}
Expand Down
26 changes: 3 additions & 23 deletions src/source-updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,38 +272,18 @@ export default class SourceUpdater extends videojs.EventTarget {
* @param {Function} done the function to call when done
* @see http://www.w3.org/TR/media-source/#widl-SourceBuffer-appendBuffer-void-ArrayBuffer-data
*/
appendBuffer({segmentInfo, type, bytes, videoSegmentTimingInfoCallback}, doneFn) {
appendBuffer(type, bytes, doneFn) {
this.processedAppend_ = true;
const originalAction = actions.appendBuffer(bytes, segmentInfo || {mediaIndex: -1});
const originalDoneFn = doneFn;
let action = originalAction;

if (videoSegmentTimingInfoCallback) {
action = (_type, sourceUpdater) => {
if (_type === 'video' && this.videoBuffer) {
this.videoBuffer.addEventListener('videoSegmentTimingInfo', videoSegmentTimingInfoCallback);
}
originalAction(type, sourceUpdater);
};

doneFn = (err) => {
if (this.videoBuffer) {
this.videoBuffer.removeEventListener('videoSegmentTimingInfo', videoSegmentTimingInfoCallback);
}
originalDoneFn(err);
};
}

if (type === 'audio' && this.videoBuffer && !this.videoAppendQueued_) {
this.delayedAudioAppendQueue_.push([{type, bytes, videoSegmentTimingInfoCallback}, doneFn]);
this.delayedAudioAppendQueue_.push([type, bytes, doneFn]);
this.logger_(`delayed audio append of ${bytes.length} until video append`);
return;
}

pushQueue({
type,
sourceUpdater: this,
action,
action: actions.appendBuffer(bytes),
doneFn,
name: 'appendBuffer'
});
Expand Down
8 changes: 8 additions & 0 deletions test/segment-transmuxer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ QUnit.test('transmux returns data for full appends', function(assert) {
const trackInfoFn = sinon.spy();
const audioTimingFn = sinon.spy();
const videoTimingFn = sinon.spy();
const videoSegmentTimingInfoFn = sinon.spy();

this.transmuxer = createTransmuxer(false);

Expand All @@ -80,13 +81,15 @@ QUnit.test('transmux returns data for full appends', function(assert) {
onTrackInfo: trackInfoFn,
onAudioTimingInfo: audioTimingFn,
onVideoTimingInfo: videoTimingFn,
onVideoSegmentTimingInfo: videoSegmentTimingInfoFn,
onId3: noop,
onCaptions: noop,
onDone: () => {
assert.ok(dataFn.callCount, 'got data events');
assert.ok(trackInfoFn.callCount, 'got trackInfo events');
assert.ok(audioTimingFn.callCount, 'got audioTimingInfo events');
assert.ok(videoTimingFn.callCount, 'got videoTimingInfo events');
assert.ok(videoSegmentTimingInfoFn.callCount, 'got videoSegmentTimingInfo events');
done();
}
});
Expand All @@ -109,6 +112,7 @@ QUnit.test('transmux returns captions for full appends', function(assert) {
onTrackInfo: noop,
onAudioTimingInfo: noop,
onVideoTimingInfo: noop,
onVideoSegmentTimingInfo: noop,
onId3: noop,
onCaptions: captionsFn,
onDone: () => {
Expand All @@ -125,6 +129,7 @@ QUnit.test('transmux returns data for partial appends', function(assert) {
const trackInfoFn = sinon.spy();
const audioTimingFn = sinon.spy();
const videoTimingFn = sinon.spy();
const videoSegmentTimingInfoFn = sinon.spy();

this.transmuxer = createTransmuxer(true);

Expand All @@ -136,6 +141,8 @@ QUnit.test('transmux returns data for partial appends', function(assert) {
isPartial: true,
onData: () => {
dataFn();
// TODO: parial appends don't current fire this
// assert.ok(videoSegmentTimingInfoFn.callCount, 'got videoSegmentTimingInfoFn event');
assert.ok(trackInfoFn.callCount, 'got trackInfo event');
assert.ok(videoTimingFn.callCount, 'got videoTimingInfo event');

Expand All @@ -147,6 +154,7 @@ QUnit.test('transmux returns data for partial appends', function(assert) {
onTrackInfo: trackInfoFn,
onAudioTimingInfo: audioTimingFn,
onVideoTimingInfo: videoTimingFn,
onVideoSegmentTimingInfo: videoSegmentTimingInfoFn,
onId3: noop,
onCaptions: noop,
// This will be called on partialdone events,
Expand Down
Loading

0 comments on commit 1c84622

Please sign in to comment.