Skip to content

Commit

Permalink
add functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkim9 committed Dec 12, 2017
1 parent 8393f20 commit bc36043
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 50 deletions.
57 changes: 9 additions & 48 deletions src/helper/fragment-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@ export class FragmentTracker extends EventHandler {
this.bufferPadding = 0.2;

this.fragments = {};
//
// // This holds all the loading fragments until the buffer is populated
// this.loadingFragments = {};
// // This holds all the successfully loaded fragments until the buffer is evicted
// this.goodFragments = {};
// // This keeps track of all fragments that loaded differently into the buffer from the PTS
// this.partialFragments = {};
// this.partialFragmentTimes = {};

this.timeRanges = {};
this.config = hls.config;
}
Expand All @@ -38,9 +31,9 @@ export class FragmentTracker extends EventHandler {
}

/**
* Partial fragments effected by coded frame eviction will be unregistered
* Partial fragments effected by coded frame eviction will be removed
* The browser will unload parts of the buffer to free up memory for new buffer data
* Fragments will need to be reloaded when the buffer is freed up, unregistering partial fragments will allow them to reload(since there might be parts that are still playable)
* Fragments will need to be reloaded when the buffer is freed up, removing partial fragments will allow them to reload(since there might be parts that are still playable)
* @param type The type of media this is (eg. video, audio)
* @param timeRange TimeRange object from a sourceBuffer
*/
Expand Down Expand Up @@ -78,33 +71,10 @@ export class FragmentTracker extends EventHandler {

}
}
// for (let fragKey in this.goodFragments) {
// if (this.goodFragments.hasOwnProperty(fragKey)) {
// fragment = this.goodFragments[fragKey];
// let found = false;
// for (let i = 0; i < timeRange.length; i++) {
// startTime = timeRange.start(i) - this.bufferPadding;
// endTime = timeRange.end(i) + this.bufferPadding;
// if (fragment.startPTS >= startTime && fragment.endPTS <= endTime) {
// // Fragment is entirely contained in buffer
// found = true;
// // No need to check the other timeRange times since it's completely playable
// break;
// }
// if(fragment.endPTS <= startTime) {
// // No need to check the rest of the timeRange as it is in order
// break;
// }
// }
// if(!found) {
// delete this.goodFragments[fragKey];
// }
// }
// }
}

/**
* Fragments that are loading will be checked in the buffer to see if they are loaded properly
* Checks if the fragment passed in is loaded in the buffer properly
* Partially loaded fragments will be registered as a partial fragment
* @param fragment Check the fragment against all sourceBuffers loaded
*/
Expand All @@ -113,11 +83,12 @@ export class FragmentTracker extends EventHandler {
let fragKey = this.getFragmentKey(fragment);
let fragmentIsOK = true;
let fragmentObject = this.fragments[fragKey];
let timeRange;

for(let type in this.timeRanges) {
if (this.timeRanges.hasOwnProperty(type)) {
if(fragment.type === 'main' || fragment.type === type) {
let timeRange = this.timeRanges[type];
timeRange = this.timeRanges[type];
// Check for malformed fragments
fragmentGaps = [];
for (let i = 0; i < timeRange.length; i++) {
Expand All @@ -144,15 +115,6 @@ export class FragmentTracker extends EventHandler {
}

fragmentObject.range[type] = fragmentGaps;

// if(this.config.debug) {
// let fragmentGapString = '';
// for (let key in fragmentGaps) {
// let time = fragmentGaps[key];
// fragmentGapString += `[${time.startPTS}, ${time.endPTS}]`;
// }
// logger.warn(`fragment-tracker: fragment with malformed PTS detected(${type}), level: ${fragment.level} sn: ${fragment.sn} startPTS: ${fragment.startPTS} endPTS: ${fragment.endPTS} loadedPTS: ${fragmentGapString}`);
// }
}
}
}
Expand Down Expand Up @@ -197,7 +159,6 @@ export class FragmentTracker extends EventHandler {
}

/**
* getState
* @param fragment The fragment to check
* @returns {string} Returns the fragment state when a fragment never loaded or if it partially loaded
*/
Expand All @@ -210,8 +171,7 @@ export class FragmentTracker extends EventHandler {
}

/**
* removeFragment
* Calling removeFragment will remove a fragment from fragment tracker until it is loaded again
* Remove a fragment from fragment tracker until it is loaded again
* @param fragment The fragment to remove
*/
removeFragment(fragment) {
Expand All @@ -236,11 +196,12 @@ export class FragmentTracker extends EventHandler {
* Fires when the buffer is updated
*/
onBufferAppended(e) {
let timeRange;
// Store the latest timeRanges loaded in the buffer
this.timeRanges = e.timeRanges;
for(let type in this.timeRanges) {
if (this.timeRanges.hasOwnProperty(type)) {
let timeRange = this.timeRanges[type];
timeRange = this.timeRanges[type];
this.detectEvictedFragments(type, timeRange);
}
}
Expand Down
28 changes: 27 additions & 1 deletion tests/functional/auto/hlsjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,31 @@ describe('testing hls.js playback in the browser on "'+browserDescription+'"', f
}
}

const testIsPlayingVOD = function(url) {
return function() {
return this.browser.executeAsyncScript(function(url) {
var callback = arguments[arguments.length - 1];
startStream(url, callback);
video.onloadeddata = function() {
let expectedPlaying = !(video.paused || // not playing when video is paused
video.ended || // not playing when video is ended
video.buffered.length === 0); // not playing if nothing buffered
let currentTime = video.currentTime;
window.setTimeout(function() {
if(expectedPlaying) {
callback({ playing : currentTime !== video.currentTime});
} else {
callback({ playing : false });
}

}, 5000);
};
}, url).then(function(result) {
assert.strictEqual(result.playing, true);
});
}
}

for (var name in streams) {
var stream = streams[name];
var url = stream.url;
Expand All @@ -245,7 +270,8 @@ describe('testing hls.js playback in the browser on "'+browserDescription+'"', f
if (stream.live) {
it('should seek near the end and receive video seeked event for ' + stream.description, testSeekOnLive(url));
} else {
it('should seek to start ' + stream.description, testSeekStartVOD(url));
it('should play ' + stream.description, testIsPlayingVOD(url));
// it('should seek to start ' + stream.description, testSeekStartVOD(url));
// it('should seek 5s from end and receive video ended event for ' + stream.description, testSeekOnVOD(url));
//it('should seek on end and receive video ended event for ' + stream.description, testSeekEndVOD(url));
}
Expand Down
3 changes: 2 additions & 1 deletion tests/functional/streams.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"bbb_aes": {"url": "http://streambox.fr/playlists/sample_aes/index.m3u8", "description": "SAMPLE-AES encrypted", "live": false , "abr": false},
"mp3": {"url": "https://player.webvideocore.net/CL1olYogIrDWvwqiIKK7eLBkzvO18gwo9ERMzsyXzwt_t-ya8ygf2kQBZww38JJT/8i4vvznv8408.m3u8", "description": "MP3 VOD demo", "live": false , "abr": false, "blacklist_ua" : ["safari"]},
"mpeg_audio": {"url": "https://pl.streamingvideoprovider.com/mp3-playlist/playlist.m3u8", "description": "MPEG Audio Only demo", "live": false , "abr": false, "blacklist_ua" : ["internet explorer","MicrosoftEdge","safari","firefox"]},
"fmp4": {"url": "https://storage.googleapis.com/shaka-demo-assets/angel-one-hls/hls.m3u8", "description": "HLS fMP4 Angel One multiple audio tracks", "live": false , "abr": false, "blacklist_ua" : ["safari"]}
"fmp4": {"url": "https://storage.googleapis.com/shaka-demo-assets/angel-one-hls/hls.m3u8", "description": "HLS fMP4 Angel One multiple audio tracks", "live": false , "abr": false, "blacklist_ua" : ["safari"]},
"offset_pts": {"url": "https://video-dev.github.io/streams/pts_shift/master.m3u8", "description": "DK Turntable, PTS shifted by 2.3s", "live": false , "abr": false}
}

0 comments on commit bc36043

Please sign in to comment.