-
Notifications
You must be signed in to change notification settings - Fork 429
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: store queue and current transmux on transmuxer instead of global #1045
Changes from all commits
17f0fb3
3b00e18
d2e183b
a92b445
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ import Config from './config'; | |
import window from 'global/window'; | ||
import { initSegmentId, segmentKeyId } from './bin-utils'; | ||
import { mediaSegmentRequest, REQUEST_ERRORS } from './media-segment-request'; | ||
import TransmuxWorker from 'worker!./transmuxer-worker.js'; | ||
import segmentTransmuxer from './segment-transmuxer'; | ||
import { TIME_FUDGE_FACTOR, timeUntilRebuffer as timeUntilRebuffer_ } from './ranges'; | ||
import { minRebufferMaxBandwidthSelector } from './playlist-selectors'; | ||
|
@@ -530,7 +529,6 @@ export default class SegmentLoader extends videojs.EventTarget { | |
}; | ||
|
||
this.transmuxer_ = this.createTransmuxer_(); | ||
|
||
this.triggerSyncInfoUpdate_ = () => this.trigger('syncinfoupdate'); | ||
this.syncController_.on('syncinfoupdate', this.triggerSyncInfoUpdate_); | ||
|
||
|
@@ -591,20 +589,13 @@ export default class SegmentLoader extends videojs.EventTarget { | |
} | ||
|
||
createTransmuxer_() { | ||
const transmuxer = new TransmuxWorker(); | ||
|
||
transmuxer.postMessage({ | ||
action: 'init', | ||
options: { | ||
parse708captions: this.parse708captions_, | ||
remux: false, | ||
alignGopsAtEnd: this.safeAppend_, | ||
keepOriginalTimestamps: true, | ||
handlePartialData: this.handlePartialData_ | ||
} | ||
return segmentTransmuxer.createTransmuxer({ | ||
remux: false, | ||
alignGopsAtEnd: this.safeAppend_, | ||
keepOriginalTimestamps: true, | ||
handlePartialData: this.handlePartialData_, | ||
parse708captions: this.parse708captions_ | ||
}); | ||
|
||
return transmuxer; | ||
} | ||
|
||
/** | ||
|
@@ -632,9 +623,6 @@ export default class SegmentLoader extends videojs.EventTarget { | |
this.abort_(); | ||
if (this.transmuxer_) { | ||
this.transmuxer_.terminate(); | ||
// Although it isn't an instance of a class, the segment transmuxer must still be | ||
// cleaned up. | ||
segmentTransmuxer.dispose(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dispose is gone, segmentTransmuxer stores no state. |
||
} | ||
this.resetStats_(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
const transmuxQueue = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now stored on transmuxer, not global. |
||
let currentTransmux; | ||
import TransmuxWorker from 'worker!./transmuxer-worker.js'; | ||
|
||
export const handleData_ = (event, transmuxedData, callback) => { | ||
const { | ||
|
@@ -66,30 +65,31 @@ export const handleGopInfo_ = (event, transmuxedData) => { | |
transmuxedData.gopInfo = event.data.gopInfo; | ||
}; | ||
|
||
export const processTransmux = ({ | ||
transmuxer, | ||
bytes, | ||
audioAppendStart, | ||
gopsToAlignWith, | ||
isPartial, | ||
remux, | ||
onData, | ||
onTrackInfo, | ||
onAudioTimingInfo, | ||
onVideoTimingInfo, | ||
onVideoSegmentTimingInfo, | ||
onAudioSegmentTimingInfo, | ||
onId3, | ||
onCaptions, | ||
onDone | ||
}) => { | ||
export const processTransmux = (options) => { | ||
const { | ||
transmuxer, | ||
bytes, | ||
audioAppendStart, | ||
gopsToAlignWith, | ||
isPartial, | ||
remux, | ||
onData, | ||
onTrackInfo, | ||
onAudioTimingInfo, | ||
onVideoTimingInfo, | ||
onVideoSegmentTimingInfo, | ||
onAudioSegmentTimingInfo, | ||
onId3, | ||
onCaptions, | ||
onDone | ||
} = options; | ||
const transmuxedData = { | ||
isPartial, | ||
buffer: [] | ||
}; | ||
|
||
const handleMessage = (event) => { | ||
if (!currentTransmux) { | ||
if (transmuxer.currentTransmux !== options) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need access to options above so that we can verify that we haven't been disposed. |
||
// disposed | ||
return; | ||
} | ||
|
@@ -134,7 +134,7 @@ export const processTransmux = ({ | |
}); | ||
|
||
/* eslint-disable no-use-before-define */ | ||
dequeue(); | ||
dequeue(transmuxer); | ||
/* eslint-enable */ | ||
}; | ||
|
||
|
@@ -187,30 +187,30 @@ export const processTransmux = ({ | |
transmuxer.postMessage({ action: isPartial ? 'partialFlush' : 'flush' }); | ||
}; | ||
|
||
export const dequeue = () => { | ||
currentTransmux = null; | ||
if (transmuxQueue.length) { | ||
currentTransmux = transmuxQueue.shift(); | ||
if (typeof currentTransmux === 'function') { | ||
currentTransmux(); | ||
export const dequeue = (transmuxer) => { | ||
transmuxer.currentTransmux = null; | ||
if (transmuxer.transmuxQueue.length) { | ||
transmuxer.currentTransmux = transmuxer.transmuxQueue.shift(); | ||
if (typeof transmuxer.currentTransmux === 'function') { | ||
transmuxer.currentTransmux(); | ||
} else { | ||
processTransmux(currentTransmux); | ||
processTransmux(transmuxer.currentTransmux); | ||
} | ||
} | ||
}; | ||
|
||
export const processAction = (transmuxer, action) => { | ||
transmuxer.postMessage({ action }); | ||
dequeue(); | ||
dequeue(transmuxer); | ||
}; | ||
|
||
export const enqueueAction = (action, transmuxer) => { | ||
if (!currentTransmux) { | ||
currentTransmux = action; | ||
if (!transmuxer.currentTransmux) { | ||
transmuxer.currentTransmux = action; | ||
processAction(transmuxer, action); | ||
return; | ||
} | ||
transmuxQueue.push(processAction.bind(null, transmuxer, action)); | ||
transmuxer.transmuxQueue.push(processAction.bind(null, transmuxer, action)); | ||
}; | ||
|
||
export const reset = (transmuxer) => { | ||
|
@@ -222,23 +222,35 @@ export const endTimeline = (transmuxer) => { | |
}; | ||
|
||
export const transmux = (options) => { | ||
if (!currentTransmux) { | ||
currentTransmux = options; | ||
if (!options.transmuxer.currentTransmux) { | ||
options.transmuxer.currentTransmux = options; | ||
processTransmux(options); | ||
return; | ||
} | ||
transmuxQueue.push(options); | ||
options.transmuxer.transmuxQueue.push(options); | ||
}; | ||
|
||
export const dispose = () => { | ||
// clear out module-level references | ||
currentTransmux = null; | ||
transmuxQueue.length = 0; | ||
export const createTransmuxer = (options) => { | ||
const transmuxer = new TransmuxWorker(); | ||
|
||
transmuxer.currentTransmux = null; | ||
transmuxer.transmuxQueue = []; | ||
const term = transmuxer.terminate; | ||
|
||
transmuxer.terminate = () => { | ||
transmuxer.currentTransmux = null; | ||
transmuxer.transmuxQueue.length = 0; | ||
return term.call(transmuxer); | ||
}; | ||
|
||
transmuxer.postMessage({action: 'init', options}); | ||
|
||
return transmuxer; | ||
}; | ||
|
||
export default { | ||
reset, | ||
dispose, | ||
endTimeline, | ||
transmux | ||
transmux, | ||
createTransmuxer | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This moved to
segmentTransmuxer.createTransmuxer
for a few reasons: