Skip to content

Commit

Permalink
fix: handle null return value from CaptionParser.parse (#890)
Browse files Browse the repository at this point in the history
CaptionParser can return null during parse, we used to handle this case but broke when we switched to the web worker caption parser in #863.
  • Loading branch information
brandonocasey authored Jul 6, 2020
1 parent c807930 commit 7b8fff2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
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

0 comments on commit 7b8fff2

Please sign in to comment.