diff --git a/src/controller/audio-stream-controller.js b/src/controller/audio-stream-controller.js index a4c2141aa02..e46f6e55335 100644 --- a/src/controller/audio-stream-controller.js +++ b/src/controller/audio-stream-controller.js @@ -645,7 +645,7 @@ class AudioStreamController extends TaskLoop { data.endDTS = data.startDTS + fragCurrent.duration; } - fragCurrent.elementaryStreams.add(data.type); + fragCurrent.addElementaryStream(data.type); logger.log(`parsed ${data.type},PTS:[${data.startPTS.toFixed(3)},${data.endPTS.toFixed(3)}],DTS:[${data.startDTS.toFixed(3)}/${data.endDTS.toFixed(3)}],nb:${data.nb}`); LevelHelper.updateFragPTSDTS(track.details,fragCurrent,data.startPTS,data.endPTS); diff --git a/src/controller/stream-controller.js b/src/controller/stream-controller.js index 73cdec1f841..2b06f14c97b 100644 --- a/src/controller/stream-controller.js +++ b/src/controller/stream-controller.js @@ -1090,7 +1090,7 @@ class StreamController extends TaskLoop { data.endDTS = data.startDTS + fragCurrent.duration; } - frag.elementaryStreams.add(data.type); + frag.addElementaryStream(data.type); logger.log(`Parsed ${data.type},PTS:[${data.startPTS.toFixed(3)},${data.endPTS.toFixed(3)}],DTS:[${data.startDTS.toFixed(3)}/${data.endDTS.toFixed(3)}],nb:${data.nb},dropped:${data.dropped || 0}`); diff --git a/src/helper/fragment-tracker.js b/src/helper/fragment-tracker.js index 8a4ae7673e1..c17053e306b 100644 --- a/src/helper/fragment-tracker.js +++ b/src/helper/fragment-tracker.js @@ -69,7 +69,7 @@ export class FragmentTracker extends EventHandler { let fragmentEntity = this.fragments.get(fragKey); fragmentEntity.buffered = true; for (let [elementaryStream, timeRange] of this.timeRanges) { - if(fragment.elementaryStreams.has(elementaryStream) === true) { + if(fragment.hasElementaryStream(elementaryStream) === true) { // Check for malformed fragments // Gaps need to be calculated for each elementaryStream fragmentEntity.range[elementaryStream] = this.getBufferedTimes(fragment.startPTS, fragment.endPTS, timeRange); diff --git a/src/loader/fragment.js b/src/loader/fragment.js index a8e7fcc3e84..4eaa11d8cdf 100644 --- a/src/loader/fragment.js +++ b/src/loader/fragment.js @@ -11,8 +11,9 @@ export default class Fragment { this._decryptdata = null; this.tagList = []; - // Set is used because the elements do not repeat - this.elementaryStreams = new Set(); + // Holds the type of data this fragment contains(eg. video/audio) + // Set is used because the elements should not repeat + this._elementaryStreams = new Set(); } get url() { @@ -72,6 +73,17 @@ export default class Fragment { return this._decryptdata; } + /** + * @param {ElementaryStreamType} + */ + addElementaryStream(type) { + this._elementaryStreams.add(type); + } + + hasElementaryStream(type) { + return this._elementaryStreams.has(type) === true; + } + /** * Utility method for parseLevelPlaylist to create an initialization vector for a given segment * @returns {Uint8Array} diff --git a/tests/unit/helper/fragment-tracker.js b/tests/unit/helper/fragment-tracker.js index eae2ddb199c..8712517f0b6 100644 --- a/tests/unit/helper/fragment-tracker.js +++ b/tests/unit/helper/fragment-tracker.js @@ -13,6 +13,14 @@ function createMockBuffer(buffered) { }; } +function createMockFragment(data, types) { + data._elementaryStreams = new Set(types); + data.hasElementaryStream = (type) => { + return data._elementaryStreams.has(type) === true; + } + return data; +} + describe('FragmentTracker', () => { describe('getPartialFragment', () => { let hls, fragmentTracker, fragment, buffered, partialFragment, timeRanges; @@ -20,14 +28,14 @@ describe('FragmentTracker', () => { hls = new Hls({}); fragmentTracker = new FragmentTracker(hls); - fragment = { + fragment = createMockFragment({ startPTS: 0, endPTS: 1, sn: 1, level: 1, - elementaryStreams: new Set(['audio', 'video']), type: 'main' - }; + }, ['audio', 'video']); + hls.trigger(Event.FRAG_LOADED, { frag: fragment }); buffered = createMockBuffer([ @@ -67,14 +75,13 @@ describe('FragmentTracker', () => { let addFragment = () => { - fragment = { + fragment = createMockFragment({ startPTS: 0, endPTS: 1, sn: 1, level: 0, - elementaryStreams: new Set(['audio', 'video']), type: 'main' - }; + }, ['audio', 'video']); hls.trigger(Event.FRAG_LOADED, { frag: fragment }); }; @@ -160,14 +167,13 @@ describe('FragmentTracker', () => { fragmentTracker = new FragmentTracker(hls); it('supports audio buffer', () => { - fragment = { + fragment = createMockFragment({ startPTS: 0, endPTS: 1, sn: 1, level: 1, - elementaryStreams: new Set(['audio', 'video']), type: 'main' - }; + }, ['audio', 'video']); hls.trigger(Event.FRAG_LOADED, { frag: fragment }); timeRanges = new Map(); @@ -191,14 +197,13 @@ describe('FragmentTracker', () => { }); it('supports video buffer', () => { - fragment = { + fragment = createMockFragment({ startPTS: 0, endPTS: 1, sn: 1, level: 1, - elementaryStreams: new Set(['audio', 'video']), type: 'main' - }; + }, ['audio', 'video']); hls.trigger(Event.FRAG_LOADED, { frag: fragment }); timeRanges = new Map(); @@ -222,14 +227,13 @@ describe('FragmentTracker', () => { }); it('supports audio only buffer', () => { - fragment = { + fragment = createMockFragment({ startPTS: 0, endPTS: 1, sn: 1, level: 1, - elementaryStreams: new Set(['audio']), type: 'audio' - }; + }, ['audio']); hls.trigger(Event.FRAG_LOADED, { frag: fragment }); timeRanges = new Map();