Skip to content

Commit

Permalink
add elementary stream methods to fragment class
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkim9 committed Jan 11, 2018
1 parent 5847693 commit ed89ce5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/controller/audio-stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/controller/stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand Down
2 changes: 1 addition & 1 deletion src/helper/fragment-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 14 additions & 2 deletions src/loader/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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}
Expand Down
34 changes: 19 additions & 15 deletions tests/unit/helper/fragment-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,29 @@ 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;

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([
Expand Down Expand Up @@ -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 });
};

Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit ed89ce5

Please sign in to comment.