From fa15919d0e314bdcd60db4df31fc164ba2002cb7 Mon Sep 17 00:00:00 2001 From: Chuck Wilson Date: Fri, 18 Aug 2017 19:43:16 -0400 Subject: [PATCH] fix duplicate caption processing (#156) --- src/flash-source-buffer.js | 9 +++++++++ src/flash-transmuxer-worker.js | 5 +++++ src/html-media-source.js | 11 +++++++++++ src/transmuxer-worker.js | 5 +++++ 4 files changed, 30 insertions(+) diff --git a/src/flash-source-buffer.js b/src/flash-source-buffer.js index 15bc3a7..c31d639 100644 --- a/src/flash-source-buffer.js +++ b/src/flash-source-buffer.js @@ -186,8 +186,13 @@ export default class FlashSourceBuffer extends videojs.EventTarget { } }); + let onHlsReset = this.onHlsReset_.bind(this); + + this.mediaSource_.player_.tech_.on('hls-reset', onHlsReset); + this.mediaSource_.player_.tech_.hls.on('dispose', () => { this.transmuxer_.terminate(); + this.mediaSource_.player_.tech_.off('hls-reset', onHlsReset); }); } @@ -547,4 +552,8 @@ export default class FlashSourceBuffer extends videojs.EventTarget { return tags; } + + onHlsReset_() { + this.transmuxer_.postMessage({action: 'resetCaptions'}); + } } diff --git a/src/flash-transmuxer-worker.js b/src/flash-transmuxer-worker.js index 1b9d60f..fc521ce 100644 --- a/src/flash-transmuxer-worker.js +++ b/src/flash-transmuxer-worker.js @@ -76,6 +76,11 @@ class MessageHandlers { flush() { this.transmuxer.flush(); } + + resetCaptions() { + this.transmuxer.resetCaptions(); + } + } /** diff --git a/src/html-media-source.js b/src/html-media-source.js index 8a4c704..d25f645 100644 --- a/src/html-media-source.js +++ b/src/html-media-source.js @@ -159,6 +159,14 @@ export default class HtmlMediaSource extends videojs.EventTarget { }); }; + this.onHlsReset_ = () => { + this.sourceBuffers.forEach((sourceBuffer) => { + if (sourceBuffer.transmuxer_) { + sourceBuffer.transmuxer_.postMessage({action: 'resetCaptions'}); + } + }); + }; + // Re-emit MediaSource events on the polyfill [ 'sourceopen', @@ -180,6 +188,8 @@ export default class HtmlMediaSource extends videojs.EventTarget { this.player_ = videojs(video.parentNode); + this.player_.tech_.on('hls-reset', this.onHlsReset_); + if (this.player_.audioTracks && this.player_.audioTracks()) { this.player_.audioTracks().on('change', this.updateActiveSourceBuffers_); this.player_.audioTracks().on('addtrack', this.updateActiveSourceBuffers_); @@ -230,6 +240,7 @@ export default class HtmlMediaSource extends videojs.EventTarget { // event handlers left to unbind anyway if (this.player_.el_) { this.player_.off('mediachange', this.onPlayerMediachange_); + this.player_.tech_.off('hls-reset', this.onHlsReset_); } }); } diff --git a/src/transmuxer-worker.js b/src/transmuxer-worker.js index 4b7eb27..bdba9d5 100644 --- a/src/transmuxer-worker.js +++ b/src/transmuxer-worker.js @@ -132,6 +132,11 @@ class MessageHandlers { flush(data) { this.transmuxer.flush(); } + + resetCaptions() { + this.transmuxer.resetCaptions(); + } + } /**