Skip to content

Commit

Permalink
Merge branch 'master' into feature/audio-track-fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
tchakabam committed Jun 8, 2018
2 parents 4b47218 + 7cd8d7d commit fce0fb7
Show file tree
Hide file tree
Showing 33 changed files with 114 additions and 56 deletions.
8 changes: 0 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
module.exports = {
'env': {
'browser': true,
'commonjs': true,
'es6': true
},
'globals': {
// Allowed globals
'console': true,
// "MediaSource": true,
'performance': true,
'crypto': true,
'fetch': true,
'Request': true,
'Headers': true,
'escape': true,

// Compile-time defines
'__VERSION__': true,
Expand Down
12 changes: 9 additions & 3 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1103,12 +1103,18 @@ get : position of live sync point (ie edge of live position minus safety delay d

## Runtime Events

Hls.js fires a bunch of events, that could be registered as below:
Hls.js fires a bunch of events, that could be registered and unregistered as below:

```js
hls.on(Hls.Events.LEVEL_LOADED,function(event,data) {
function onLevelLoaded (event, data) {
var level_duration = data.details.totalduration;
});
}
// subscribe event
hls.on(Hls.Events.LEVEL_LOADED, onLevelLoaded);
// unsubscribe event
hls.off(Hls.Events.LEVEL_LOADED, onLevelLoaded);
// subscribe for a single event call only
hls.once(Hls.Events.LEVEL_LOADED, onLevelLoaded);
```
Full list of Events is available below:

Expand Down
8 changes: 5 additions & 3 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ module.exports = function(config) {
frameworks: ['mocha', 'sinon', 'should'],

// list of files / patterns to load in the browser
files: ['tests/tests.webpack.js'],
files: [
'tests/unit/**/*.js'
],

// list of files to exclude
exclude: [],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'tests/tests.webpack.js': ['webpack', 'sourcemap']
'**/*.js': ['webpack', 'sourcemap']
},

// test results reporter to use
Expand All @@ -37,7 +39,7 @@ module.exports = function(config) {
},

webpack: {
devtool: 'inline-source-map',
devtool: 'eval',
module: {
rules: [
// instrument only testing sources with Istanbul
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"docs:release": "npm run docs:clean && npm run docs:generate && npm run docs:update",
"lint": "npm run lint:src && npm run lint:tests",
"lint:fix": "eslint src/ tests/ --fix",
"lint:quiet": "eslint src/ tests/ --quiet",
"lint:src": "eslint src/",
"lint:tests": "eslint tests/",
"lint:demo": "eslint demo/",
Expand Down
7 changes: 0 additions & 7 deletions scripts/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@
# https://docs.travis-ci.com/user/customizing-the-build/#Implementing-Complex-Build-Steps
set -ev

function testNodeRequire {
# check that hls.js doesn't error if requiring in node
# see https://github.com/video-dev/hls.js/pull/1642
node -e 'require("./" + require("./package.json").main)'
}

npm install

if [ "${TRAVIS_MODE}" = "build" ]; then
npm run lint
npm run build
testNodeRequire
elif [ "${TRAVIS_MODE}" = "unitTests" ]; then
npm run test:unit
elif [ "${TRAVIS_MODE}" = "funcTests" ]; then
Expand Down
2 changes: 2 additions & 0 deletions src/controller/abr-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { ErrorDetails } from '../errors';
import { logger } from '../utils/logger';
import EwmaBandWidthEstimator from '../utils/ewma-bandwidth-estimator';

const { performance } = window;

class AbrController extends EventHandler {
constructor (hls) {
super(hls, Event.FRAG_LOADING,
Expand Down
2 changes: 2 additions & 0 deletions src/controller/audio-stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import TaskLoop from '../task-loop';
import { FragmentState } from './fragment-tracker';
import Fragment from '../loader/fragment';

const { performance } = window;

const State = {
STOPPED: 'STOPPED',
STARTING: 'STARTING',
Expand Down
4 changes: 2 additions & 2 deletions src/controller/buffer-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class BufferController extends EventHandler {
ms.addEventListener('sourceended', this.onmse);
ms.addEventListener('sourceclose', this.onmsc);
// link video and media Source
media.src = URL.createObjectURL(ms);
media.src = window.URL.createObjectURL(ms);
// cache the locally generated object url
this._objectUrl = media.src;
}
Expand Down Expand Up @@ -137,7 +137,7 @@ class BufferController extends EventHandler {
// Detach properly the MediaSource from the HTMLMediaElement as
// suggested in https://github.com/w3c/media-source/issues/53.
if (this.media) {
URL.revokeObjectURL(this._objectUrl);
window.URL.revokeObjectURL(this._objectUrl);

// clean up video tag src only if it's our own url. some external libraries might
// hijack the video tag and change its 'src' without destroying the Hls instance first
Expand Down
2 changes: 1 addition & 1 deletion src/controller/cap-level-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CapLevelController extends EventHandler {
}

onMediaAttaching (data) {
this.media = data.media instanceof HTMLVideoElement ? data.media : null;
this.media = data.media instanceof window.HTMLVideoElement ? data.media : null;
}

onManifestParsed (data) {
Expand Down
2 changes: 2 additions & 0 deletions src/controller/eme-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { ErrorTypes, ErrorDetails } from '../errors';

import { logger } from '../utils/logger';

const { XMLHttpRequest } = window;

const MAX_LICENSE_REQUEST_FAILURES = 3;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/controller/fps-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Event from '../events';
import EventHandler from '../event-handler';
import { logger } from '../utils/logger';

const { performance } = window;

class FPSController extends EventHandler {
constructor (hls) {
super(hls, Event.MEDIA_ATTACHING);
Expand All @@ -22,7 +24,7 @@ class FPSController extends EventHandler {
onMediaAttaching (data) {
const config = this.hls.config;
if (config.capLevelOnFPSDrop) {
const video = this.video = data.media instanceof HTMLVideoElement ? data.media : null;
const video = this.video = data.media instanceof window.HTMLVideoElement ? data.media : null;
if (typeof video.getVideoPlaybackQuality === 'function') {
this.isVideoPlaybackQualityAvailable = true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/controller/level-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ErrorTypes, ErrorDetails } from '../errors';
import { isCodecSupportedInMp4 } from '../utils/codecs';
import { addGroupId } from './level-helper';

const { performance } = window;

export default class LevelController extends EventHandler {
constructor (hls) {
super(hls,
Expand Down
14 changes: 7 additions & 7 deletions src/controller/stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class StreamController extends TaskLoop {

break;
case State.FRAG_LOADING_WAITING_RETRY:
var now = performance.now();
var now = window.performance.now();
var retryDate = this.retryDate;
// if current time is gt than retryDate, or if media seeking let's switch to IDLE state to retry loading
if (!retryDate || (now >= retryDate) || (this.media && this.media.seeking)) {
Expand Down Expand Up @@ -953,12 +953,12 @@ class StreamController extends TaskLoop {
// switch back to IDLE state ... we just loaded a fragment to determine adequate start bitrate and initialize autoswitch algo
this.state = State.IDLE;
this.startFragRequested = false;
stats.tparsed = stats.tbuffered = performance.now();
stats.tparsed = stats.tbuffered = window.performance.now();
this.hls.trigger(Event.FRAG_BUFFERED, { stats: stats, frag: fragCurrent, id: 'main' });
this.tick();
} else if (fragLoaded.sn === 'initSegment') {
this.state = State.IDLE;
stats.tparsed = stats.tbuffered = performance.now();
stats.tparsed = stats.tbuffered = window.performance.now();
details.initSegment.data = data.payload;
this.hls.trigger(Event.FRAG_BUFFERED, { stats: stats, frag: fragCurrent, id: 'main' });
this.tick();
Expand Down Expand Up @@ -1157,7 +1157,7 @@ class StreamController extends TaskLoop {
fragNew.sn === fragCurrent.sn &&
fragNew.level === fragCurrent.level &&
this.state === State.PARSING) {
this.stats.tparsed = performance.now();
this.stats.tparsed = window.performance.now();
this.state = State.PARSED;
this._checkAppendedParsed();
}
Expand Down Expand Up @@ -1256,7 +1256,7 @@ class StreamController extends TaskLoop {
logger.log(`main buffered : ${TimeRanges.toString(media.buffered)}`);
this.fragPrevious = frag;
const stats = this.stats;
stats.tbuffered = performance.now();
stats.tbuffered = window.performance.now();
// we should get rid of this.fragLastKbps
this.fragLastKbps = Math.round(8 * stats.total / (stats.tbuffered - stats.tfirst));
this.hls.trigger(Event.FRAG_BUFFERED, { stats: stats, frag: frag, id: 'main' });
Expand Down Expand Up @@ -1287,7 +1287,7 @@ class StreamController extends TaskLoop {
// exponential backoff capped to config.fragLoadingMaxRetryTimeout
let delay = Math.min(Math.pow(2, this.fragLoadError) * this.config.fragLoadingRetryDelay, this.config.fragLoadingMaxRetryTimeout);
logger.warn(`mediaController: frag loading failed, retry in ${delay} ms`);
this.retryDate = performance.now() + delay;
this.retryDate = window.performance.now() + delay;
// retry loading state
// if loadedmetadata is not set, it means that we are emergency switch down on first frag
// in that case, reset startFragRequested flag
Expand Down Expand Up @@ -1379,7 +1379,7 @@ class StreamController extends TaskLoop {
const expectedPlaying = !((media.paused && media.readyState > 1) || // not playing when media is paused and sufficiently buffered
media.ended || // not playing when media is ended
media.buffered.length === 0); // not playing if nothing buffered
const tnow = performance.now();
const tnow = window.performance.now();

if (currentTime !== this.lastCurrentTime) {
// The playhead is now moving, but was previously stalled
Expand Down
2 changes: 2 additions & 0 deletions src/controller/subtitle-stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { logger } from '../utils/logger';
import Decrypter from '../crypt/decrypter';
import TaskLoop from '../task-loop';

const { performance } = window;

const State = {
STOPPED: 'STOPPED',
IDLE: 'IDLE',
Expand Down
12 changes: 10 additions & 2 deletions src/crypt/decrypter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ import AESDecryptor from './aes-decryptor';
import { ErrorTypes, ErrorDetails } from '../errors';
import { logger } from '../utils/logger';

/* globals self: false */
import Event from '../events';

import { getSelfScope } from '../utils/get-self-scope';

// see https://stackoverflow.com/a/11237259/589493
/* eslint-disable-next-line no-undef */
const window = getSelfScope(); // safeguard for code that might run both on worker and main thread

const { performance, crypto } = window;

class Decrypter {
constructor (observer, config, { removePKCS7Padding = true } = {}) {
Expand All @@ -16,7 +24,7 @@ class Decrypter {
// built in decryptor expects PKCS7 padding
if (removePKCS7Padding) {
try {
const browserCrypto = crypto || self.crypto;
const browserCrypto = crypto || window.crypto;
this.subtle = browserCrypto.subtle || browserCrypto.webkitSubtle;
} catch (e) {}
}
Expand Down
4 changes: 4 additions & 0 deletions src/demux/adts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import { logger } from '../utils/logger';
import { ErrorTypes, ErrorDetails } from '../errors';

import Event from '../events';

import { getSelfScope } from '../utils/get-self-scope';

export function getAudioConfig (observer, data, offset, audioCodec) {
let adtsObjectType, // :int
adtsSampleingIndex, // :int
Expand Down
15 changes: 13 additions & 2 deletions src/demux/demuxer-inline.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* inline demuxer.
* probe fragments and instantiate appropriate demuxer depending on content type (TSDemuxer, AACDemuxer, ...)
/**
*
* inline demuxer: probe fragments and instantiate
* appropriate demuxer depending on content type (TSDemuxer, AACDemuxer, ...)
*
*/

import Event from '../events';
Expand All @@ -12,6 +15,14 @@ import MP3Demuxer from '../demux/mp3demuxer';
import MP4Remuxer from '../remux/mp4-remuxer';
import PassThroughRemuxer from '../remux/passthrough-remuxer';

import { getSelfScope } from '../utils/get-self-scope';

// see https://stackoverflow.com/a/11237259/589493
/* eslint-disable-next-line no-undef */
const window = getSelfScope(); // safeguard for code that might run both on worker and main thread

const { performance } = window;

class DemuxerInline {
constructor (observer, typeSupported, config, vendor) {
this.observer = observer;
Expand Down
9 changes: 7 additions & 2 deletions src/demux/demuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import DemuxerInline from '../demux/demuxer-inline';
import { logger } from '../utils/logger';
import { ErrorTypes, ErrorDetails } from '../errors';
import { getMediaSource } from '../utils/mediasource-helper';
import { getSelfScope } from '../utils/get-self-scope';

// see https://stackoverflow.com/a/11237259/589493
/* eslint-disable-next-line no-undef */
const window = getSelfScope(); // safeguard for code that might run both on worker and main thread

const MediaSource = getMediaSource();

Expand Down Expand Up @@ -64,7 +69,7 @@ class Demuxer {
logger.error('error while initializing DemuxerWorker, fallback on DemuxerInline');
if (w) {
// revoke the Object URL that was used to create demuxer worker, so as not to leak it
URL.revokeObjectURL(w.objectURL);
window.URL.revokeObjectURL(w.objectURL);
}
this.demuxer = new DemuxerInline(observer, typeSupported, config, vendor);
this.w = undefined;
Expand Down Expand Up @@ -129,7 +134,7 @@ class Demuxer {
switch (data.event) {
case 'init':
// revoke the Object URL that was used to create demuxer worker, so as not to leak it
URL.revokeObjectURL(this.w.objectURL);
window.URL.revokeObjectURL(this.w.objectURL);
break;
// special case for FRAG_PARSING_DATA: data1 and data2 are transferable objects
case Event.FRAG_PARSING_DATA:
Expand Down
1 change: 1 addition & 0 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@ const HlsEvents = {
// fired upon stream controller state transitions - data: { previousState, nextState }
STREAM_STATE_TRANSITION: 'hlsStreamStateTransition'
};

export default HlsEvents;
3 changes: 2 additions & 1 deletion src/hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export default class Hls {
};
this.on = observer.on.bind(observer);
this.off = observer.off.bind(observer);
this.once = observer.once.bind(observer);
this.trigger = observer.trigger.bind(observer);

// core controllers and network loaders
Expand Down Expand Up @@ -608,7 +609,7 @@ export default class Hls {
}

/**
* @type {booelan}
* @type {boolean}
*/
get subtitleDisplay () {
const subtitleTrackController = this.subtitleTrackController;
Expand Down
2 changes: 2 additions & 0 deletions src/loader/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { logger } from '../utils/logger';
import MP4Demuxer from '../demux/mp4demuxer';
import M3U8Parser from './m3u8-parser';

const { performance } = window;

/**
* `type` property values for this loaders' context object
* @enum
Expand Down
5 changes: 3 additions & 2 deletions src/remux/mp4-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

// import Hex from '../utils/hex';
import { makeArrayFromArrayLike } from '../utils/make-array-from-array-like';

const UINT32_MAX = Math.pow(2, 32) - 1;

Expand Down Expand Up @@ -334,7 +335,7 @@ class MP4 {
len = data.byteLength;
sps.push((len >>> 8) & 0xFF);
sps.push((len & 0xFF));
sps = sps.concat(Array.prototype.slice.call(data)); // SPS
sps = sps.concat(makeArrayFromArrayLike(data)); // SPS
}

// assemble the PPSs
Expand All @@ -343,7 +344,7 @@ class MP4 {
len = data.byteLength;
pps.push((len >>> 8) & 0xFF);
pps.push((len & 0xFF));
pps = pps.concat(Array.prototype.slice.call(data));
pps = pps.concat(makeArrayFromArrayLike(data));
}

let avcc = MP4.box(MP4.types.avcC, new Uint8Array([
Expand Down
Loading

0 comments on commit fce0fb7

Please sign in to comment.