Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(id3): cuechange event not being triggered on audio-only HLS streams #334

Merged
merged 6 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/mse/virtual-source-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ export default class VirtualSourceBuffer extends videojs.EventTarget {
sortedSegments.video.segments.unshift(sortedSegments.video.initSegment);
sortedSegments.video.bytes += sortedSegments.video.initSegment.byteLength;
this.concatAndAppendSegments_(sortedSegments.video, this.videoBuffer_);
// TODO: are video tracks the only ones with text tracks?
addTextTrackData(this, sortedSegments.captions, sortedSegments.metadata);

} else if (this.videoBuffer_ && (this.audioDisabled_ || !this.audioBuffer_)) {
// The transmuxer did not return any bytes of video, meaning it was all trimmed
// for gop alignment. Since we have a video buffer and audio is disabled, updateend
Expand All @@ -491,6 +490,9 @@ export default class VirtualSourceBuffer extends videojs.EventTarget {
triggerUpdateend = true;
}

// Add text-track data for all
addTextTrackData(this, sortedSegments.captions, sortedSegments.metadata);

if (!this.audioDisabled_ && this.audioBuffer_) {
this.concatAndAppendSegments_(sortedSegments.audio, this.audioBuffer_);
}
Expand Down
58 changes: 58 additions & 0 deletions test/mse/html.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,64 @@ QUnit.test('translates metadata events into WebVTT cues', function(assert) {
assert.strictEqual(cues[2].endTime, mediaSource.duration, 'sourceended is fired');
});

QUnit.test('translates metadata events from audio-only stream into WebVTT cues', function(assert) {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t; codecs=\"avc1.4d400d, mp4a.40.2\"');

mediaSource.duration = Infinity;
mediaSource.nativeMediaSource_.duration = 60;

let types = [];
let metadata = [{
cueTime: 12,
frames: [{
data: 'This is a priv tag'
}]
}];

metadata.dispatchType = 0x10;
mediaSource.player_ = {
addRemoteTextTrack(options) {
types.push(options.kind);
return {
track: {
kind: options.kind,
label: options.label,
cues: [],
addCue(cue) {
this.cues.push(cue);
}
}
};
},
remoteTextTracks() {
}
};
sourceBuffer.timestampOffset = 10;

sourceBuffer.transmuxer_.onmessage(createDataMessage('audio', new Uint8Array(1), {
metadata
}));
sourceBuffer.transmuxer_.onmessage(doneMessage);

assert.strictEqual(
sourceBuffer.metadataTrack_.inBandMetadataTrackDispatchType,
16,
'in-band metadata track dispatch type correctly set'
);
let cues = sourceBuffer.metadataTrack_.cues;

assert.strictEqual(types.length, 1, 'created one text track');
assert.strictEqual(types[0], 'metadata', 'the type was metadata');
assert.strictEqual(cues.length, 1, 'created one cue');
assert.strictEqual(cues[0].text, 'This is a priv tag', 'included the text');
assert.strictEqual(cues[0].startTime, 22, 'started at twenty two');
assert.strictEqual(cues[0].endTime, Number.MAX_VALUE, 'ended at the maximum value');
mediaSource.duration = 100;
mediaSource.trigger('sourceended');
assert.strictEqual(cues[0].endTime, mediaSource.duration, 'sourceended is fired');
});

QUnit.test('does not wrap mp4 source buffers', function(assert) {
let mediaSource = new videojs.MediaSource();

Expand Down