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: handle null return value from CaptionParser.parse #890

Merged
merged 2 commits into from
Jul 6, 2020
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
2 changes: 1 addition & 1 deletion src/transmuxer-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class MessageHandlers {

this.self.postMessage({
action: 'mp4Captions',
captions: parsed.captions,
captions: parsed && parsed.captions || [],
data: segment.buffer
}, [segment.buffer]);
}
Expand Down
Binary file added test/segments/mp4Captions.mp4
Binary file not shown.
59 changes: 59 additions & 0 deletions test/transmuxer-worker.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import QUnit from 'qunit';
import TransmuxWorker from 'worker!../src/transmuxer-worker.worker.js';
import {
mp4Captions as mp4CaptionsSegment,
muxed as muxedSegment,
oneSecond as oneSecondSegment,
caption as captionSegment
Expand Down Expand Up @@ -321,6 +322,64 @@ QUnit.test('caption events are returned', function(assert) {
});
});

QUnit.test('can parse mp4 captions', function(assert) {
const done = assert.async();
const data = mp4CaptionsSegment();

this.transmuxer = createTransmuxer(false);
this.transmuxer.onmessage = (e) => {
const message = e.data;

assert.equal(message.action, 'mp4Captions', 'returned mp4Captions event');
assert.deepEqual(message.captions.length, 2, 'two captions');
assert.deepEqual(
new Uint8Array(message.data),
data,
'data returned to main thread'
);

done();
};

this.transmuxer.postMessage({
action: 'pushMp4Captions',
data,
timescales: 30000,
trackIds: [1],
byteLength: data.byteLength,
byteOffset: 0
});
});

QUnit.test('returns empty array without mp4 captions', function(assert) {
const done = assert.async();
const data = muxedSegment();

this.transmuxer = createTransmuxer(false);
this.transmuxer.onmessage = (e) => {
const message = e.data;

assert.equal(message.action, 'mp4Captions', 'returned mp4Captions event');
assert.deepEqual(message.captions, [], 'no captions');
assert.deepEqual(
new Uint8Array(message.data),
data,
'data returned to main thread'
);

done();
};

this.transmuxer.postMessage({
action: 'pushMp4Captions',
data,
timescales: 30000,
trackIds: [1],
byteLength: data.byteLength,
byteOffset: 0
});
});

QUnit.module('Transmuxer Worker: Partial Transmuxer', {
beforeEach(assert) {
assert.timeout(5000);
Expand Down