jellyfin-web/dashboard-ui/bower_components/hls.js/dist/hls.js.map

89 lines
411 KiB
Plaintext
Raw Normal View History

2015-12-15 22:30:14 -07:00
{
"version": 3,
"sources": [
2016-02-24 20:15:07 -07:00
"node_modules/browser-pack/_prelude.js",
"node_modules/events/events.js",
2015-12-15 22:30:14 -07:00
"node_modules/webworkify/index.js",
"src/controller/abr-controller.js",
2016-02-24 20:15:07 -07:00
"src/controller/buffer-controller.js",
2016-03-25 09:35:19 -07:00
"src/controller/cap-level-controller.js",
2015-12-15 22:30:14 -07:00
"src/controller/level-controller.js",
2016-02-24 20:15:07 -07:00
"src/controller/stream-controller.js",
2016-02-01 10:02:17 -07:00
"src/controller/timeline-controller.js",
2015-12-15 22:30:14 -07:00
"src/crypt/aes.js",
"src/crypt/aes128-decrypter.js",
"src/crypt/decrypter.js",
"src/demux/aacdemuxer.js",
2016-01-13 13:58:12 -07:00
"src/demux/adts.js",
2015-12-15 22:30:14 -07:00
"src/demux/demuxer-inline.js",
"src/demux/demuxer-worker.js",
"src/demux/demuxer.js",
"src/demux/exp-golomb.js",
"src/demux/id3.js",
"src/demux/tsdemuxer.js",
"src/errors.js",
2016-01-18 12:07:26 -07:00
"src/event-handler.js",
2015-12-15 22:30:14 -07:00
"src/events.js",
2016-03-25 09:35:19 -07:00
"src/helper/buffer-helper.js",
2015-12-15 22:30:14 -07:00
"src/helper/level-helper.js",
"src/hls.js",
2016-02-24 20:15:07 -07:00
"src/index.js",
2015-12-15 22:30:14 -07:00
"src/loader/fragment-loader.js",
"src/loader/key-loader.js",
"src/loader/playlist-loader.js",
"src/remux/mp4-generator.js",
"src/remux/mp4-remuxer.js",
2016-02-24 20:15:07 -07:00
"src/remux/passthrough-remuxer.js",
2016-01-13 13:58:12 -07:00
"src/utils/attr-list.js",
2015-12-15 22:30:14 -07:00
"src/utils/binary-search.js",
2016-02-01 10:02:17 -07:00
"src/utils/cea-708-interpreter.js",
2015-12-15 22:30:14 -07:00
"src/utils/logger.js",
"src/utils/url.js",
"src/utils/xhr-loader.js"
],
"names": [],
2016-04-08 09:49:34 -07:00
"mappings": "AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC1SA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;AC3DA;;;;AACA;;;;AACA;;;;AACA;;AACA;;;;;;;;;;;;;;IAEM;;;AAEJ,WAFI,aAEJ,CAAY,GAAZ,EAAiB;0BAFb,eAEa;;uEAFb,0BAGI,KAAK,iBAAM,YAAN,EACA,iBAAM,kBAAN,EACA,iBAAM,WAAN,EACA,iBAAM,KAAN,GAJI;;AAKf,UAAK,mBAAL,GAA2B,CAA3B,CALe;AAMf,UAAK,iBAAL,GAAyB,CAAC,CAAD,CANV;AAOf,UAAK,cAAL,GAAsB,CAAC,CAAD,CAPP;AAQf,UAAK,GAAL,GAAW,GAAX,CARe;AASf,UAAK,OAAL,GAAe,MAAK,iBAAL,CAAuB,IAAvB,OAAf,CATe;;GAAjB;;eAFI;;8BAcM;AACR,WAAK,UAAL,GADQ;AAER,6BAAa,SAAb,CAAuB,OAAvB,CAA+B,IAA/B,CAAoC,IAApC,EAFQ;;;;kCAKI,MAAM;AAClB,WAAK,KAAL,GAAa,YAAY,KAAK,OAAL,EAAc,GAA1B,CAAb,CADkB;AAElB,WAAK,WAAL,GAAmB,KAAK,IAAL,CAFD;;;;uCAKD,MAAM;AACvB,UAAI,QAAQ,KAAK,KAAL;;;;AADW,UAKnB,MAAM,OAAN,KAAkB,SAAlB,IAA+B,KAAK,IAAL,CAAU,WAAV,KAA0B,CAA1B,EAA6B;AAC9D,aAAK,iBAAL,GAAyB,CAAC,YAAY,GAAZ,KAAoB,MAAM,QAAN,CAArB,GAAuC,IAAvC,CADqC;AAE9D,aAAK,MAAL,GAAc,KAAC,CAAM,MAAN,GAAe,CAAf,GAAoB,KAAK,iBAAL;;AAF2B,OAAhE;;;;wCAOkB;;;;;;AAMlB,UAAI,MAAM,KAAK,GAAL;UAAU,IAAI,IAAI,KAAJ;UAAU,OAAO,KAAK,WAAL;;;AANvB,UASd,MAAM,CAAC,EAAE,MAAF,IAAY,CAAC,EAAE,UAAF,CAApB,IAAqC,KAAK,SAAL,IAAkB,KAAK,KAAL,EAAY;AACrE,YAAI,eAAe,YAAY,GAAZ,KAAoB,KAAK,QAAL;;AAD8B,YAGjE,eAAgB,MAAM,KAAK,QAAL,EAAgB;AACxC,cAAI,WAAW,KAAK,GAAL,CAAS,CAAT,EAAW,KAAK,MAAL,GAAc,IAAd,GAAqB,YAArB,CAAtB;AADoC,cAEpC,KAAK,WAAL,GAAmB,KAAK,MAAL,EAAa;AAClC,iBAAK,WAAL,GAAmB,KAAK,MAAL,CADe;WAApC;AAGA,cAAI,MAAM,EAAE,WAAF,CAL8B;AAMxC,cAAI,kBAAkB,CAAC,KAAK,WAAL,GAAmB,KAAK,MAAL,CAApB,GAAmC,QAAnC,CANkB;AAOxC,cAAI,wBAAwB,uBAAa,UAAb,CAAwB,CAAxB,EAA0B,GAA1B,EAA8B,IAAI,MAAJ,CAAW,aAAX,CAA9B,CAAwD,GAAxD,GAA8D,GAA9D;;;;AAPY,cAWpC,wBAAwB,IAAE,KAAK,QAAL,IAAiB,kBAAkB,qBAAlB,EAAyC;AACtF,gBAAI,iCAAJ;gBAA8B,sBAA9B;;;AADsF,iBAIjF,gBAAgB,KAAK,KAAL,GAAa,CAAb,EAAiB,iBAAgB,CAAhB,EAAoB,eAA1D,EAA2E;;;;AAIzE,yCAA2B,KAAK,QAAL,GAAgB,IAAI,MAAJ,CAAW,aAAX,EAA0B,OAA1B,IAAqC,IAAI,GAAJ,GAAU,QAAV,CAArD,CAJ8C;AAKzE,6BAAO,GAAP,qEAA6E,wBAAmB,gBAAgB,OAAhB,CAAwB,CAAxB,UAA8B,sBAAsB,OAAtB,CAA8B,CAA9B,UAAoC,yBAAyB,OAAzB,CAAiC,CAAjC,CAAlK,EALyE;AAMzE,kBAAI,2BAA2B,qBAA3B,EAAkD;;AAEpD,sBAFoD;eAAtD;aANF;;;AAJsF,gBAiBlF,2BAA2B,eAA3B,EAA4C;;AAE9C,8BAAgB,KAAK,GAAL,CAAS,CAAT,EAAW,aAAX,CAAhB;;AAF8C,iBAI9C,CAAI,aAAJ,GAAoB,aAApB;;AAJ8C,4BAM9C,CAAO,IAAP,mEAA4E,aAA5E;;AAN8C,kBAQ9C,CAAK,MAAL,CAAY,KAAZ,GAR8C;AAS9C,mBAAK,UAAL,GAT8C;AAU9C,kBAAI,OAAJ,CAAY,iBAAM,2BAAN,EAAmC,EAAC,MAAM,IAAN,EAAhD,EAV8C;
2015-12-15 22:30:14 -07:00
"file": "generated.js",
"sourceRoot": "",
"sourcesContent": [
"(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})",
2016-02-24 20:15:07 -07:00
"// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nfunction EventEmitter() {\n this._events = this._events || {};\n this._maxListeners = this._maxListeners || undefined;\n}\nmodule.exports = EventEmitter;\n\n// Backwards-compat with node 0.10.x\nEventEmitter.EventEmitter = EventEmitter;\n\nEventEmitter.prototype._events = undefined;\nEventEmitter.prototype._maxListeners = undefined;\n\n// By default EventEmitters will print a warning if more than 10 listeners are\n// added to it. This is a useful default which helps finding memory leaks.\nEventEmitter.defaultMaxListeners = 10;\n\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nEventEmitter.prototype.setMaxListeners = function(n) {\n if (!isNumber(n) || n < 0 || isNaN(n))\n throw TypeError('n must be a positive number');\n this._maxListeners = n;\n return this;\n};\n\nEventEmitter.prototype.emit = function(type) {\n var er, handler, len, args, i, listeners;\n\n if (!this._events)\n this._events = {};\n\n // If there is no 'error' event listener then throw.\n if (type === 'error') {\n if (!this._events.error ||\n (isObject(this._events.error) && !this._events.error.length)) {\n er = arguments[1];\n if (er instanceof Error) {\n throw er; // Unhandled 'error' event\n }\n throw TypeError('Uncaught, unspecified \"error\" event.');\n }\n }\n\n handler = this._events[type];\n\n if (isUndefined(handler))\n return false;\n\n if (isFunction(handler)) {\n switch (arguments.length) {\n // fast cases\n case 1:\n handler.call(this);\n break;\n case 2:\n handler.call(this, arguments[1]);\n break;\n case 3:\n handler.call(this, arguments[1], arguments[2]);\n break;\n // slower\n default:\n args = Array.prototype.slice.call(arguments, 1);\n handler.apply(this, args);\n }\n } else if (isObject(handler)) {\n args = Array.prototype.slice.call(arguments, 1);\n listeners = handler.slice();\n len = listeners.length;\n for (i = 0; i < len; i++)\n listeners[i].apply(this, args);\n }\n\n return true;\n};\n\nEventEmitter.prototype.addListener = function(type, listener) {\n var m;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events)\n this._events = {};\n\n // To avoid recursion in the case that type === \"newListener\"! Before\n // adding it to the listeners, first emit \"newListener\".\n if (this._events.newListener)\n this.emit('newListener', type,\n isFunction(listener.listener) ?\n listener.listener : listener);\n\n if (!this._events[type])\n // Optimize the case of one listener. Don't need the extra array object.\n this._events[type] = listener;\n else if (isObject(this._events[type]))\n // If we've already got an array, just append.\n this._even
2016-02-01 10:02:17 -07:00
"var bundleFn = arguments[3];\nvar sources = arguments[4];\nvar cache = arguments[5];\n\nvar stringify = JSON.stringify;\n\nmodule.exports = function (fn) {\n var keys = [];\n var wkey;\n var cacheKeys = Object.keys(cache);\n\n for (var i = 0, l = cacheKeys.length; i < l; i++) {\n var key = cacheKeys[i];\n var exp = cache[key].exports;\n // Using babel as a transpiler to use esmodule, the export will always\n // be an object with the default export as a property of it. To ensure\n // the existing api and babel esmodule exports are both supported we\n // check for both\n if (exp === fn || exp.default === fn) {\n wkey = key;\n break;\n }\n }\n\n if (!wkey) {\n wkey = Math.floor(Math.pow(16, 8) * Math.random()).toString(16);\n var wcache = {};\n for (var i = 0, l = cacheKeys.length; i < l; i++) {\n var key = cacheKeys[i];\n wcache[key] = key;\n }\n sources[wkey] = [\n Function(['require','module','exports'], '(' + fn + ')(self)'),\n wcache\n ];\n }\n var skey = Math.floor(Math.pow(16, 8) * Math.random()).toString(16);\n\n var scache = {}; scache[wkey] = wkey;\n sources[skey] = [\n Function(['require'], (\n // try to call default if defined to also support babel esmodule\n // exports\n 'var f = require(' + stringify(wkey) + ');' +\n '(f.default ? f.default : f)(self);'\n )),\n scache\n ];\n\n var src = '(' + bundleFn + ')({'\n + Object.keys(sources).map(function (key) {\n return stringify(key) + ':['\n + sources[key][0]\n + ',' + stringify(sources[key][1]) + ']'\n ;\n }).join(',')\n + '},{},[' + stringify(skey) + '])'\n ;\n\n var URL = window.URL || window.webkitURL || window.mozURL || window.msURL;\n\n return new Worker(URL.createObjectURL(\n new Blob([src], { type: 'text/javascript' })\n ));\n};\n",
2016-04-08 09:49:34 -07:00
"/*\n * simple ABR Controller\n * - compute next level based on last fragment bw heuristics\n * - implement an abandon rules triggered if we have less than 2 frag buffered and if computed bw shows that we risk buffer stalling\n */\n\nimport Event from '../events';\nimport EventHandler from '../event-handler';\nimport BufferHelper from '../helper/buffer-helper';\nimport {ErrorDetails} from '../errors';\nimport {logger} from '../utils/logger';\n\nclass AbrController extends EventHandler {\n\n constructor(hls) {\n super(hls, Event.FRAG_LOADING,\n Event.FRAG_LOAD_PROGRESS,\n Event.FRAG_LOADED,\n Event.ERROR);\n this.lastLoadedFragLevel = 0;\n this._autoLevelCapping = -1;\n this._nextAutoLevel = -1;\n this.hls = hls;\n this.onCheck = this.abandonRulesCheck.bind(this);\n }\n\n destroy() {\n this.clearTimer();\n EventHandler.prototype.destroy.call(this);\n }\n\n onFragLoading(data) {\n this.timer = setInterval(this.onCheck, 100);\n this.fragCurrent = data.frag;\n }\n\n onFragLoadProgress(data) {\n var stats = data.stats;\n // only update stats if first frag loading\n // if same frag is loaded multiple times, it might be in browser cache, and loaded quickly\n // and leading to wrong bw estimation\n if (stats.aborted === undefined && data.frag.loadCounter === 1) {\n this.lastfetchduration = (performance.now() - stats.trequest) / 1000;\n this.lastbw = (stats.loaded * 8) / this.lastfetchduration;\n //console.log(`fetchDuration:${this.lastfetchduration},bw:${(this.lastbw/1000).toFixed(0)}/${stats.aborted}`);\n }\n }\n\n abandonRulesCheck() {\n /*\n monitor fragment retrieval time...\n we compute expected time of arrival of the complete fragment.\n we compare it to expected time of buffer starvation\n */\n let hls = this.hls, v = hls.media,frag = this.fragCurrent;\n /* only monitor frag retrieval time if\n (video not paused OR first fragment being loaded(ready state === HAVE_NOTHING = 0)) AND autoswitching enabled AND not lowest level (=> means that we have several levels) */\n if (v && (!v.paused || !v.readyState) && frag.autoLevel && frag.level) {\n let requestDelay = performance.now() - frag.trequest;\n // monitor fragment load progress after half of expected fragment duration,to stabilize bitrate\n if (requestDelay > (500 * frag.duration)) {\n let loadRate = Math.max(1,frag.loaded * 1000 / requestDelay); // byte/s; at least 1 byte/s to avoid division by zero\n if (frag.expectedLen < frag.loaded) {\n frag.expectedLen = frag.loaded;\n }\n let pos = v.currentTime;\n let fragLoadedDelay = (frag.expectedLen - frag.loaded) / loadRate;\n let bufferStarvationDelay = BufferHelper.bufferInfo(v,pos,hls.config.maxBufferHole).end - pos;\n // consider emergency switch down only if we have less than 2 frag buffered AND\n // time to finish loading current fragment is bigger than buffer starvation delay\n // ie if we risk buffer starvation if bw does not increase quickly\n if (bufferStarvationDelay < 2*frag.duration && fragLoadedDelay > bufferStarvationDelay) {\n let fragLevelNextLoadedDelay, nextLoadLevel;\n // lets iterate through lower level and try to find the biggest one that could avoid rebuffering\n // we start from current level - 1 and we step down , until we find a matching level\n for (nextLoadLevel = frag.level - 1 ; nextLoadLevel >=0 ; nextLoadLevel--) {\n // compute time to load next fragment at lower level\n // 0.8 : consider only 80% of current bw to be conservative\n // 8 = bits per byte (bps/Bps)\n fragLevelNextLoadedDelay = frag.duration * hls.levels[nextLoadLevel].bitrate / (8 * 0.8 * loadRate);\n logger.log(`fragLoadedDelay/bufferStarvationDelay/fragLevelNextLoadedDelay[${nextLoadLevel}] :${fragLoadedDelay.toFixed(1)}/${bufferStarvationDelay.toFixed(1)}/${fragLevelNextLoadedDelay.toFixed(1)}`)
2016-03-16 22:06:37 -07:00
"/*\n * Buffer Controller\n*/\n\nimport Event from '../events';\nimport EventHandler from '../event-handler';\nimport {logger} from '../utils/logger';\nimport {ErrorTypes, ErrorDetails} from '../errors';\n\n\nclass BufferController extends EventHandler {\n\n constructor(hls) {\n super(hls,\n Event.MEDIA_ATTACHING,\n Event.MEDIA_DETACHING,\n Event.BUFFER_RESET,\n Event.BUFFER_APPENDING,\n Event.BUFFER_CODECS,\n Event.BUFFER_EOS,\n Event.BUFFER_FLUSHING);\n\n // Source Buffer listeners\n this.onsbue = this.onSBUpdateEnd.bind(this);\n this.onsbe = this.onSBUpdateError.bind(this);\n }\n\n destroy() {\n EventHandler.prototype.destroy.call(this);\n }\n\n onMediaAttaching(data) {\n var media = this.media = data.media;\n // setup the media source\n var ms = this.mediaSource = new MediaSource();\n //Media Source listeners\n this.onmso = this.onMediaSourceOpen.bind(this);\n this.onmse = this.onMediaSourceEnded.bind(this);\n this.onmsc = this.onMediaSourceClose.bind(this);\n ms.addEventListener('sourceopen', this.onmso);\n ms.addEventListener('sourceended', this.onmse);\n ms.addEventListener('sourceclose', this.onmsc);\n // link video and media Source\n media.src = URL.createObjectURL(ms);\n }\n\n onMediaDetaching() {\n var ms = this.mediaSource;\n if (ms) {\n if (ms.readyState === 'open') {\n try {\n // endOfStream could trigger exception if any sourcebuffer is in updating state\n // we don't really care about checking sourcebuffer state here,\n // as we are anyway detaching the MediaSource\n // let's just avoid this exception to propagate\n ms.endOfStream();\n } catch(err) {\n logger.warn(`onMediaDetaching:${err.message} while calling endOfStream`);\n }\n }\n ms.removeEventListener('sourceopen', this.onmso);\n ms.removeEventListener('sourceended', this.onmse);\n ms.removeEventListener('sourceclose', this.onmsc);\n // unlink MediaSource from video tag\n this.media.src = '';\n this.media.removeAttribute('src');\n this.mediaSource = null;\n this.media = null;\n this.pendingTracks = null;\n this.sourceBuffer = null;\n }\n this.onmso = this.onmse = this.onmsc = null;\n this.hls.trigger(Event.MEDIA_DETACHED);\n }\n\n onMediaSourceOpen() {\n logger.log('media source opened');\n this.hls.trigger(Event.MEDIA_ATTACHED, { media : this.media });\n // once received, don't listen anymore to sourceopen event\n this.mediaSource.removeEventListener('sourceopen', this.onmso);\n // if any buffer codecs pending, treat it here.\n var pendingTracks = this.pendingTracks;\n if (pendingTracks) {\n this.onBufferCodecs(pendingTracks);\n this.pendingTracks = null;\n this.doAppending();\n }\n }\n\n onMediaSourceClose() {\n logger.log('media source closed');\n }\n\n onMediaSourceEnded() {\n logger.log('media source ended');\n }\n\n\n onSBUpdateEnd() {\n\n if (this._needsFlush) {\n this.doFlush();\n }\n\n if (this._needsEos) {\n this.onBufferEos();\n }\n\n this.hls.trigger(Event.BUFFER_APPENDED);\n\n this.doAppending();\n }\n\n onSBUpdateError(event) {\n logger.error(`sourceBuffer error:${event}`);\n // according to http://www.w3.org/TR/media-source/#sourcebuffer-append-error\n // this error might not always be fatal (it is fatal if decode error is set, in that case\n // it will be followed by a mediaElement error ...)\n this.hls.trigger(Event.ERROR, {type: ErrorTypes.MEDIA_ERROR, details: ErrorDetails.BUFFER_APPENDING_ERROR, fatal: false});\n // we don't need to do more than that, as accordin to the spec, updateend will be fired just after\n }\n\n onBufferReset() {\n var sourceBuffer = this.sourceBuffer;\n if (sourceBuffer) {\n for(var type in sourceBuffer) {\n var sb = sourceBuffer[type];\n try {\n this.mediaSource.removeSourceBuffer(sb);\n sb.removeEventListener('update
2016-03-25 09:35:19 -07:00
"/*\n * cap stream level to media size dimension controller\n*/\n\nimport Event from '../events';\nimport EventHandler from '../event-handler';\n\nclass CapLevelController extends EventHandler {\n\tconstructor(hls) {\n super(hls,\n Event.MEDIA_ATTACHING,\n Event.MANIFEST_PARSED); \n\t}\n\t\n\tdestroy() {\n if (this.hls.config.capLevelToPlayerSize) {\n this.media = null;\n this.autoLevelCapping = Number.POSITIVE_INFINITY;\n if (this.timer) {\n this.timer = clearInterval(this.timer);\n }\n }\n }\n\t \n\tonMediaAttaching(data) {\n this.media = data.media instanceof HTMLVideoElement ? data.media : null; \n }\n\n onManifestParsed(data) {\n if (this.hls.config.capLevelToPlayerSize) {\n this.autoLevelCapping = Number.POSITIVE_INFINITY;\n this.levels = data.levels;\n this.hls.firstLevel = this.getMaxLevel(data.firstLevel);\n clearInterval(this.timer);\n this.timer = setInterval(this.detectPlayerSize.bind(this), 1000);\n this.detectPlayerSize();\n }\n }\n \n detectPlayerSize() {\n if (this.media) {\n let levelsLength = this.levels ? this.levels.length : 0;\n if (levelsLength) {\n this.hls.autoLevelCapping = this.getMaxLevel(levelsLength - 1);\n if (this.hls.autoLevelCapping > this.autoLevelCapping) {\n // if auto level capping has a higher value for the previous one, flush the buffer using nextLevelSwitch\n // usually happen when the user go to the fullscreen mode.\n this.hls.streamController.nextLevelSwitch();\n }\n this.autoLevelCapping = this.hls.autoLevelCapping; \n } \n }\n }\n \n /*\n * returns level should be the one with the dimensions equal or greater than the media (player) dimensions (so the video will be downscaled)\n */\n getMaxLevel(capLevelIndex) {\n let result,\n i,\n level,\n mWidth = this.mediaWidth,\n mHeight = this.mediaHeight,\n lWidth = 0,\n lHeight = 0;\n \n for (i = 0; i <= capLevelIndex; i++) {\n level = this.levels[i];\n result = i;\n lWidth = level.width;\n lHeight = level.height;\n if (mWidth <= lWidth || mHeight <= lHeight) {\n break;\n }\n } \n return result;\n }\n \n get contentScaleFactor() {\n let pixelRatio = 1;\n try {\n pixelRatio = window.devicePixelRatio;\n } catch(e) {}\n return pixelRatio;\n }\n \n get mediaWidth() {\n let width;\n if (this.media) {\n width = this.media.width || this.media.clientWidth || this.media.offsetWidth;\n width *= this.contentScaleFactor;\n }\n return width;\n }\n \n get mediaHeight() {\n let height;\n if (this.media) {\n height = this.media.height || this.media.clientHeight || this.media.offsetHeight;\n height *= this.contentScaleFactor; \n }\n return height;\n }\n}\n\nexport default CapLevelController;",
2016-04-08 09:49:34 -07:00
"/*\n * Level Controller\n*/\n\nimport Event from '../events';\nimport EventHandler from '../event-handler';\nimport {logger} from '../utils/logger';\nimport {ErrorTypes, ErrorDetails} from '../errors';\n\nclass LevelController extends EventHandler {\n\n constructor(hls) {\n super(hls,\n Event.MANIFEST_LOADED,\n Event.LEVEL_LOADED,\n Event.ERROR);\n this.ontick = this.tick.bind(this);\n this._manualLevel = this._autoLevelCapping = -1;\n }\n\n destroy() {\n if (this.timer) {\n clearInterval(this.timer);\n }\n this._manualLevel = -1;\n }\n\n startLoad() {\n this.canload = true;\n // speed up live playlist refresh if timer exists\n if (this.timer) {\n this.tick();\n }\n }\n\n stopLoad() {\n this.canload = false;\n }\n\n onManifestLoaded(data) {\n var levels0 = [], levels = [], bitrateStart, i, bitrateSet = {}, videoCodecFound = false, audioCodecFound = false, hls = this.hls;\n\n // regroup redundant level together\n data.levels.forEach(level => {\n if(level.videoCodec) {\n videoCodecFound = true;\n }\n if(level.audioCodec) {\n audioCodecFound = true;\n }\n var redundantLevelId = bitrateSet[level.bitrate];\n if (redundantLevelId === undefined) {\n bitrateSet[level.bitrate] = levels0.length;\n level.url = [level.url];\n level.urlId = 0;\n levels0.push(level);\n } else {\n levels0[redundantLevelId].url.push(level.url);\n }\n });\n\n // remove audio-only level if we also have levels with audio+video codecs signalled\n if(videoCodecFound && audioCodecFound) {\n levels0.forEach(level => {\n if(level.videoCodec) {\n levels.push(level);\n }\n });\n } else {\n levels = levels0;\n }\n\n // only keep level with supported audio/video codecs\n levels = levels.filter(function(level) {\n var checkSupportedAudio = function(codec) { return MediaSource.isTypeSupported(`audio/mp4;codecs=${codec}`);};\n var checkSupportedVideo = function(codec) { return MediaSource.isTypeSupported(`video/mp4;codecs=${codec}`);};\n var audioCodec = level.audioCodec, videoCodec = level.videoCodec;\n\n return (!audioCodec || checkSupportedAudio(audioCodec)) &&\n (!videoCodec || checkSupportedVideo(videoCodec));\n });\n\n if(levels.length) {\n // start bitrate is the first bitrate of the manifest\n bitrateStart = levels[0].bitrate;\n // sort level on bitrate\n levels.sort(function (a, b) {\n return a.bitrate - b.bitrate;\n });\n this._levels = levels;\n // find index of first level in sorted levels\n for (i = 0; i < levels.length; i++) {\n if (levels[i].bitrate === bitrateStart) {\n this._firstLevel = i;\n logger.log(`manifest loaded,${levels.length} level(s) found, first bitrate:${bitrateStart}`);\n break;\n }\n }\n hls.trigger(Event.MANIFEST_PARSED, {levels: this._levels, firstLevel: this._firstLevel, stats: data.stats});\n } else {\n hls.trigger(Event.ERROR, {type: ErrorTypes.MEDIA_ERROR, details: ErrorDetails.MANIFEST_INCOMPATIBLE_CODECS_ERROR, fatal: true, url: hls.url, reason: 'no level with compatible codecs found in manifest'});\n }\n return;\n }\n\n get levels() {\n return this._levels;\n }\n\n get level() {\n return this._level;\n }\n\n set level(newLevel) {\n if (this._level !== newLevel || this._levels[newLevel].details === undefined) {\n this.setLevelInternal(newLevel);\n }\n }\n\n setLevelInternal(newLevel) {\n // check if level idx is valid\n if (newLevel >= 0 && newLevel < this._levels.length) {\n // stopping live reloading timer if any\n if (this.timer) {\n clearInterval(this.timer);\n this.timer = null;\n }\n this._level = newLevel;\n logger.log(`switching to level ${newLevel}`);\n this.hls.trigger(Event.LEVEL_SWITCH, {level: newLevel});\n var level = this._levels[newLevel];\n // check if we ne
2016-03-27 16:22:53 -07:00
"/*\n * Stream Controller\n*/\n\nimport Demuxer from '../demux/demuxer';\nimport Event from '../events';\nimport EventHandler from '../event-handler';\nimport {logger} from '../utils/logger';\nimport BinarySearch from '../utils/binary-search';\nimport BufferHelper from '../helper/buffer-helper';\nimport LevelHelper from '../helper/level-helper';\nimport {ErrorTypes, ErrorDetails} from '../errors';\n\nconst State = {\n STOPPED : 'STOPPED',\n STARTING : 'STARTING',\n IDLE : 'IDLE',\n PAUSED : 'PAUSED',\n KEY_LOADING : 'KEY_LOADING',\n FRAG_LOADING : 'FRAG_LOADING',\n FRAG_LOADING_WAITING_RETRY : 'FRAG_LOADING_WAITING_RETRY',\n WAITING_LEVEL : 'WAITING_LEVEL',\n PARSING : 'PARSING',\n PARSED : 'PARSED',\n ENDED : 'ENDED',\n ERROR : 'ERROR'\n};\n\nclass StreamController extends EventHandler {\n\n constructor(hls) {\n super(hls,\n Event.MEDIA_ATTACHED,\n Event.MEDIA_DETACHING,\n Event.MANIFEST_LOADING,\n Event.MANIFEST_PARSED,\n Event.LEVEL_LOADED,\n Event.KEY_LOADED,\n Event.FRAG_LOADED,\n Event.FRAG_LOAD_EMERGENCY_ABORTED,\n Event.FRAG_PARSING_INIT_SEGMENT,\n Event.FRAG_PARSING_DATA,\n Event.FRAG_PARSED,\n Event.ERROR,\n Event.BUFFER_APPENDED,\n Event.BUFFER_FLUSHED);\n\n this.config = hls.config;\n this.audioCodecSwap = false;\n this.ticks = 0;\n this.ontick = this.tick.bind(this);\n }\n\n destroy() {\n this.stopLoad();\n if (this.timer) {\n clearInterval(this.timer);\n this.timer = null;\n }\n EventHandler.prototype.destroy.call(this);\n this.state = State.STOPPED;\n }\n\n startLoad(startPosition=0) {\n if (this.levels) {\n var media = this.media, lastCurrentTime = this.lastCurrentTime;\n this.stopLoad();\n this.demuxer = new Demuxer(this.hls);\n if (!this.timer) {\n this.timer = setInterval(this.ontick, 100);\n }\n this.level = -1;\n this.fragLoadError = 0;\n if (media && lastCurrentTime) {\n logger.log(`configure startPosition @${lastCurrentTime}`);\n if (!this.lastPaused) {\n logger.log('resuming video');\n media.play();\n }\n this.state = State.IDLE;\n } else {\n this.lastCurrentTime = this.startPosition ? this.startPosition : startPosition;\n this.state = State.STARTING;\n }\n this.nextLoadPosition = this.startPosition = this.lastCurrentTime;\n this.tick();\n } else {\n logger.warn('cannot start loading as manifest not parsed yet');\n this.state = State.STOPPED;\n }\n }\n\n stopLoad() {\n var frag = this.fragCurrent;\n if (frag) {\n if (frag.loader) {\n frag.loader.abort();\n }\n this.fragCurrent = null;\n }\n this.fragPrevious = null;\n if (this.demuxer) {\n this.demuxer.destroy();\n this.demuxer = null;\n }\n this.state = State.STOPPED;\n }\n\n tick() {\n this.ticks++;\n if (this.ticks === 1) {\n this.doTick();\n if (this.ticks > 1) {\n setTimeout(this.tick, 1);\n }\n this.ticks = 0;\n }\n }\n\n doTick() {\n var pos, level, levelDetails, hls = this.hls, config = hls.config;\n //logger.log(this.state);\n switch(this.state) {\n case State.ERROR:\n //don't do anything in error state to avoid breaking further ...\n case State.PAUSED:\n //don't do anything in paused state either ...\n break;\n case State.STARTING:\n // determine load level\n this.startLevel = hls.startLevel;\n if (this.startLevel === -1) {\n // -1 : guess start Level by doing a bitrate test by loading first fragment of lowest quality level\n this.startLevel = 0;\n this.fragBitrateTest = true;\n }\n // set new level to playlist loader : this will trigger start level load\n this.level = hls.nextLoadLevel = this.startLevel;\n this.state = State.WAITING_LEVEL;\n this.loadedmetadata = false;\n break;\n case State.IDLE:\n // if video not attached AN
2016-02-01 10:02:17 -07:00
"/*\n * Timeline Controller\n*/\n\nimport Event from '../events';\nimport EventHandler from '../event-handler';\nimport CEA708Interpreter from '../utils/cea-708-interpreter';\n\nclass TimelineController extends EventHandler {\n\n constructor(hls) {\n super(hls, Event.MEDIA_ATTACHING,\n Event.MEDIA_DETACHING,\n Event.FRAG_PARSING_USERDATA,\n Event.MANIFEST_LOADING,\n Event.FRAG_LOADED);\n\n this.hls = hls;\n this.config = hls.config;\n\n if (this.config.enableCEA708Captions)\n {\n this.cea708Interpreter = new CEA708Interpreter();\n }\n }\n\n destroy() {\n EventHandler.prototype.destroy.call(this);\n }\n\n onMediaAttaching(data) {\n var media = this.media = data.media;\n this.cea708Interpreter.attach(media);\n }\n\n onMediaDetaching() {\n this.cea708Interpreter.detach();\n }\n\n onManifestLoading()\n {\n this.lastPts = Number.POSITIVE_INFINITY;\n }\n\n onFragLoaded(data)\n {\n var pts = data.frag.start; //Number.POSITIVE_INFINITY;\n\n // if this is a frag for a previously loaded timerange, remove all captions\n // TODO: consider just removing captions for the timerange\n if (pts <= this.lastPts)\n {\n this.cea708Interpreter.clear();\n }\n\n this.lastPts = pts;\n }\n\n onFragParsingUserdata(data) {\n // push all of the CEA-708 messages into the interpreter\n // immediately. It will create the proper timestamps based on our PTS value\n for (var i=0; i<data.samples.length; i++)\n {\n this.cea708Interpreter.push(data.samples[i].pts, data.samples[i].bytes);\n }\n }\n}\n\nexport default TimelineController;\n",
2015-12-15 22:30:14 -07:00
"/*\n *\n * This file contains an adaptation of the AES decryption algorithm\n * from the Standford Javascript Cryptography Library. That work is\n * covered by the following copyright and permissions notice:\n *\n * Copyright 2009-2010 Emily Stark, Mike Hamburg, Dan Boneh.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n * 1. Redistributions of source code must retain the above copyright\n * notice, this list of conditions and the following disclaimer.\n *\n * 2. Redistributions in binary form must reproduce the above\n * copyright notice, this list of conditions and the following\n * disclaimer in the documentation and/or other materials provided\n * with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR\n * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR CONTRIBUTORS BE\n * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\n * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\n * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN\n * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n *\n * The views and conclusions contained in the software and documentation\n * are those of the authors and should not be interpreted as representing\n * official policies, either expressed or implied, of the authors.\n */\nclass AES {\n\n /**\n * Schedule out an AES key for both encryption and decryption. This\n * is a low-level class. Use a cipher mode to do bulk encryption.\n *\n * @constructor\n * @param key {Array} The key as an array of 4, 6 or 8 words.\n */\n constructor(key) {\n /**\n * The expanded S-box and inverse S-box tables. These will be computed\n * on the client so that we don't have to send them down the wire.\n *\n * There are two tables, _tables[0] is for encryption and\n * _tables[1] is for decryption.\n *\n * The first 4 sub-tables are the expanded S-box with MixColumns. The\n * last (_tables[01][4]) is the S-box itself.\n *\n * @private\n */\n this._tables = [[[],[],[],[],[]],[[],[],[],[],[]]];\n\n this._precompute();\n\n var i, j, tmp,\n encKey, decKey,\n sbox = this._tables[0][4], decTable = this._tables[1],\n keyLen = key.length, rcon = 1;\n\n if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {\n throw new Error('Invalid aes key size=' + keyLen);\n }\n\n encKey = key.slice(0);\n decKey = [];\n this._key = [encKey, decKey];\n\n // schedule encryption keys\n for (i = keyLen; i < 4 * keyLen + 28; i++) {\n tmp = encKey[i-1];\n\n // apply sbox\n if (i%keyLen === 0 || (keyLen === 8 && i%keyLen === 4)) {\n tmp = sbox[tmp>>>24]<<24 ^ sbox[tmp>>16&255]<<16 ^ sbox[tmp>>8&255]<<8 ^ sbox[tmp&255];\n\n // shift rows and add rcon\n if (i%keyLen === 0) {\n tmp = tmp<<8 ^ tmp>>>24 ^ rcon<<24;\n rcon = rcon<<1 ^ (rcon>>7)*283;\n }\n }\n\n encKey[i] = encKey[i-keyLen] ^ tmp;\n }\n\n // schedule decryption keys\n for (j = 0; i; j++, i--) {\n tmp = encKey[j&3 ? i : i - 4];\n if (i<=4 || j<4) {\n decKey[j] = tmp;\n } else {\n decKey[j] = decTable[0][sbox[tmp>>>24 ]] ^\n decTable[1][sbox[tmp>>16 & 255]] ^\n decTable[2][sbox[tmp>>8 & 255]] ^\n decTable[3][sbox[tmp & 255]];\n }\n }\n }\n\n /**\n * Expand the S-box tables.\n *\n * @private\n */\n _precompute() {\n var encTable = this._tables[0], decTable = this._tables[1],\n sbox = encTable[4], sboxInv = d
2016-01-13 13:58:12 -07:00
"/*\n *\n * This file contains an adaptation of the AES decryption algorithm\n * from the Standford Javascript Cryptography Library. That work is\n * covered by the following copyright and permissions notice:\n *\n * Copyright 2009-2010 Emily Stark, Mike Hamburg, Dan Boneh.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n * 1. Redistributions of source code must retain the above copyright\n * notice, this list of conditions and the following disclaimer.\n *\n * 2. Redistributions in binary form must reproduce the above\n * copyright notice, this list of conditions and the following\n * disclaimer in the documentation and/or other materials provided\n * with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR\n * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR CONTRIBUTORS BE\n * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\n * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\n * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN\n * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n *\n * The views and conclusions contained in the software and documentation\n * are those of the authors and should not be interpreted as representing\n * official policies, either expressed or implied, of the authors.\n */\n\nimport AES from './aes';\n\nclass AES128Decrypter {\n\n constructor(key, initVector) {\n this.key = key;\n this.iv = initVector;\n }\n\n /**\n * Convert network-order (big-endian) bytes into their little-endian\n * representation.\n */\n ntoh(word) {\n return (word << 24) |\n ((word & 0xff00) << 8) |\n ((word & 0xff0000) >> 8) |\n (word >>> 24);\n }\n\n\n /**\n * Decrypt bytes using AES-128 with CBC and PKCS#7 padding.\n * @param encrypted {Uint8Array} the encrypted bytes\n * @param key {Uint32Array} the bytes of the decryption key\n * @param initVector {Uint32Array} the initialization vector (IV) to\n * use for the first round of CBC.\n * @return {Uint8Array} the decrypted bytes\n *\n * @see http://en.wikipedia.org/wiki/Advanced_Encryption_Standard\n * @see http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_Block_Chaining_.28CBC.29\n * @see https://tools.ietf.org/html/rfc2315\n */\n doDecrypt(encrypted, key, initVector) {\n var\n // word-level access to the encrypted bytes\n encrypted32 = new Int32Array(encrypted.buffer, encrypted.byteOffset, encrypted.byteLength >> 2),\n\n decipher = new AES(Array.prototype.slice.call(key)),\n\n // byte and word-level access for the decrypted output\n decrypted = new Uint8Array(encrypted.byteLength),\n decrypted32 = new Int32Array(decrypted.buffer),\n\n // temporary variables for working with the IV, encrypted, and\n // decrypted data\n init0, init1, init2, init3,\n encrypted0, encrypted1, encrypted2, encrypted3,\n\n // iteration variable\n wordIx;\n\n // pull out the words of the IV to ensure we don't modify the\n // passed-in reference and easier access\n init0 = ~~initVector[0];\n init1 = ~~initVector[1];\n init2 = ~~initVector[2];\n init3 = ~~initVector[3];\n\n // decrypt four word sequences, applying cipher-block chaining (CBC)\n // to each decrypted block\n for (wordIx = 0; wordIx < encrypted32.length; wordIx += 4) {\n // convert big-endian (network order) words into little-endian\n // (javascript order)\n encrypted0 = ~~this.ntoh(encrypted32[wordIx]);\n encrypted1 = ~~this.ntoh(encrypted32[wordIx + 1]);\n
2015-12-15 22:30:14 -07:00
"/*\n * AES128 decryption.\n */\n\nimport AES128Decrypter from './aes128-decrypter';\nimport {ErrorTypes, ErrorDetails} from '../errors';\nimport {logger} from '../utils/logger';\n\nclass Decrypter {\n\n constructor(hls) {\n this.hls = hls;\n try {\n const browserCrypto = window ? window.crypto : crypto;\n this.subtle = browserCrypto.subtle || browserCrypto.webkitSubtle;\n this.disableWebCrypto = !this.subtle;\n } catch (e) {\n this.disableWebCrypto = true;\n }\n }\n\n destroy() {\n }\n\n decrypt(data, key, iv, callback) {\n if (this.disableWebCrypto && this.hls.config.enableSoftwareAES) {\n this.decryptBySoftware(data, key, iv, callback);\n } else {\n this.decryptByWebCrypto(data, key, iv, callback);\n }\n }\n\n decryptByWebCrypto(data, key, iv, callback) {\n logger.log('decrypting by WebCrypto API');\n\n this.subtle.importKey('raw', key, { name : 'AES-CBC', length : 128 }, false, ['decrypt']).\n then((importedKey) => {\n this.subtle.decrypt({ name : 'AES-CBC', iv : iv.buffer }, importedKey, data).\n then(callback).\n catch ((err) => {\n this.onWebCryptoError(err, data, key, iv, callback);\n });\n }).\n catch ((err) => {\n this.onWebCryptoError(err, data, key, iv, callback);\n });\n }\n\n decryptBySoftware(data, key8, iv8, callback) {\n logger.log('decrypting by JavaScript Implementation');\n\n var view = new DataView(key8.buffer);\n var key = new Uint32Array([\n view.getUint32(0),\n view.getUint32(4),\n view.getUint32(8),\n view.getUint32(12)\n ]);\n\n view = new DataView(iv8.buffer);\n var iv = new Uint32Array([\n view.getUint32(0),\n view.getUint32(4),\n view.getUint32(8),\n view.getUint32(12)\n ]);\n\n var decrypter = new AES128Decrypter(key, iv);\n callback(decrypter.decrypt(data).buffer);\n }\n\n onWebCryptoError(err, data, key, iv, callback) {\n if (this.hls.config.enableSoftwareAES) {\n logger.log('disabling to use WebCrypto API');\n this.disableWebCrypto = true;\n this.decryptBySoftware(data, key, iv, callback);\n }\n else {\n logger.error(`decrypting error : ${err.message}`);\n this.hls.trigger(Event.ERROR, {type : ErrorTypes.MEDIA_ERROR, details : ErrorDetails.FRAG_DECRYPT_ERROR, fatal : true, reason : err.message});\n }\n }\n\n}\n\nexport default Decrypter;\n",
2016-03-18 10:28:45 -07:00
"/**\n * AAC demuxer\n */\nimport ADTS from './adts';\nimport {logger} from '../utils/logger';\nimport ID3 from '../demux/id3';\n\n class AACDemuxer {\n\n constructor(observer,remuxerClass) {\n this.observer = observer;\n this.remuxerClass = remuxerClass;\n this.remuxer = new this.remuxerClass(observer);\n this._aacTrack = {container : 'audio/adts', type: 'audio', id :-1, sequenceNumber: 0, samples : [], len : 0};\n }\n\n static probe(data) {\n // check if data contains ID3 timestamp and ADTS sync worc\n var id3 = new ID3(data), offset,len;\n if(id3.hasTimeStamp) {\n // look for ADTS header (0xFFFx)\n for (offset = id3.length, len = data.length; offset < len - 1; offset++) {\n if ((data[offset] === 0xff) && (data[offset+1] & 0xf0) === 0xf0) {\n //logger.log('ADTS sync word found !');\n return true;\n }\n }\n }\n return false;\n }\n\n\n // feed incoming data to the front of the parsing pipeline\n push(data, audioCodec, videoCodec, timeOffset, cc, level, sn, duration) {\n var track = this._aacTrack,\n id3 = new ID3(data),\n pts = 90*id3.timeStamp,\n config, frameLength, frameDuration, frameIndex, offset, headerLength, stamp, len, aacSample;\n // look for ADTS header (0xFFFx)\n for (offset = id3.length, len = data.length; offset < len - 1; offset++) {\n if ((data[offset] === 0xff) && (data[offset+1] & 0xf0) === 0xf0) {\n break;\n }\n }\n\n if (!track.audiosamplerate) {\n config = ADTS.getAudioConfig(this.observer,data, offset, audioCodec);\n track.config = config.config;\n track.audiosamplerate = config.samplerate;\n track.channelCount = config.channelCount;\n track.codec = config.codec;\n track.duration = duration;\n logger.log(`parsed codec:${track.codec},rate:${config.samplerate},nb channel:${config.channelCount}`);\n }\n frameIndex = 0;\n frameDuration = 1024 * 90000 / track.audiosamplerate;\n while ((offset + 5) < len) {\n // The protection skip bit tells us if we have 2 bytes of CRC data at the end of the ADTS header\n headerLength = (!!(data[offset + 1] & 0x01) ? 7 : 9);\n // retrieve frame size\n frameLength = ((data[offset + 3] & 0x03) << 11) |\n (data[offset + 4] << 3) |\n ((data[offset + 5] & 0xE0) >>> 5);\n frameLength -= headerLength;\n //stamp = pes.pts;\n\n if ((frameLength > 0) && ((offset + headerLength + frameLength) <= len)) {\n stamp = pts + frameIndex * frameDuration;\n //logger.log(`AAC frame, offset/length/total/pts:${offset+headerLength}/${frameLength}/${data.byteLength}/${(stamp/90).toFixed(0)}`);\n aacSample = {unit: data.subarray(offset + headerLength, offset + headerLength + frameLength), pts: stamp, dts: stamp};\n track.samples.push(aacSample);\n track.len += frameLength;\n offset += frameLength + headerLength;\n frameIndex++;\n // look for ADTS header (0xFFFx)\n for ( ; offset < (len - 1); offset++) {\n if ((data[offset] === 0xff) && ((data[offset + 1] & 0xf0) === 0xf0)) {\n break;\n }\n }\n } else {\n break;\n }\n }\n this.remuxer.remux(this._aacTrack,{samples : []}, {samples : [ { pts: pts, dts : pts, unit : id3.payload} ]}, { samples: [] }, timeOffset);\n }\n\n destroy() {\n }\n\n}\n\nexport default AACDemuxer;\n",
2016-03-16 22:06:37 -07:00
"/**\n * ADTS parser helper\n */\nimport {logger} from '../utils/logger';\nimport {ErrorTypes, ErrorDetails} from '../errors';\n\n class ADTS {\n\n static getAudioConfig(observer, data, offset, audioCodec) {\n var adtsObjectType, // :int\n adtsSampleingIndex, // :int\n adtsExtensionSampleingIndex, // :int\n adtsChanelConfig, // :int\n config,\n userAgent = navigator.userAgent.toLowerCase(),\n adtsSampleingRates = [\n 96000, 88200,\n 64000, 48000,\n 44100, 32000,\n 24000, 22050,\n 16000, 12000,\n 11025, 8000,\n 7350];\n // byte 2\n adtsObjectType = ((data[offset + 2] & 0xC0) >>> 6) + 1;\n adtsSampleingIndex = ((data[offset + 2] & 0x3C) >>> 2);\n if(adtsSampleingIndex > adtsSampleingRates.length-1) {\n observer.trigger(Event.ERROR, {type: ErrorTypes.MEDIA_ERROR, details: ErrorDetails.FRAG_PARSING_ERROR, fatal: true, reason: `invalid ADTS sampling index:${adtsSampleingIndex}`});\n return;\n }\n adtsChanelConfig = ((data[offset + 2] & 0x01) << 2);\n // byte 3\n adtsChanelConfig |= ((data[offset + 3] & 0xC0) >>> 6);\n logger.log(`manifest codec:${audioCodec},ADTS data:type:${adtsObjectType},sampleingIndex:${adtsSampleingIndex}[${adtsSampleingRates[adtsSampleingIndex]}Hz],channelConfig:${adtsChanelConfig}`);\n // firefox: freq less than 24kHz = AAC SBR (HE-AAC)\n if (userAgent.indexOf('firefox') !== -1) {\n if (adtsSampleingIndex >= 6) {\n adtsObjectType = 5;\n config = new Array(4);\n // HE-AAC uses SBR (Spectral Band Replication) , high frequencies are constructed from low frequencies\n // there is a factor 2 between frame sample rate and output sample rate\n // multiply frequency by 2 (see table below, equivalent to substract 3)\n adtsExtensionSampleingIndex = adtsSampleingIndex - 3;\n } else {\n adtsObjectType = 2;\n config = new Array(2);\n adtsExtensionSampleingIndex = adtsSampleingIndex;\n }\n // Android : always use AAC\n } else if (userAgent.indexOf('android') !== -1) {\n adtsObjectType = 2;\n config = new Array(2);\n adtsExtensionSampleingIndex = adtsSampleingIndex;\n } else {\n /* for other browsers (chrome ...)\n always force audio type to be HE-AAC SBR, as some browsers do not support audio codec switch properly (like Chrome ...)\n */\n adtsObjectType = 5;\n config = new Array(4);\n // if (manifest codec is HE-AAC or HE-AACv2) OR (manifest codec not specified AND frequency less than 24kHz)\n if ((audioCodec && ((audioCodec.indexOf('mp4a.40.29') !== -1) ||\n (audioCodec.indexOf('mp4a.40.5') !== -1))) ||\n (!audioCodec && adtsSampleingIndex >= 6)) {\n // HE-AAC uses SBR (Spectral Band Replication) , high frequencies are constructed from low frequencies\n // there is a factor 2 between frame sample rate and output sample rate\n // multiply frequency by 2 (see table below, equivalent to substract 3)\n adtsExtensionSampleingIndex = adtsSampleingIndex - 3;\n } else {\n // if (manifest codec is AAC) AND (frequency less than 24kHz AND nb channel is 1) OR (manifest codec not specified and mono audio)\n // Chrome fails to play back with low frequency AAC LC mono when initialized with HE-AAC. This is not a problem with stereo.\n if (audioCodec && audioCodec.indexOf('mp4a.40.2') !== -1 && (adtsSampleingIndex >= 6 && adtsChanelConfig === 1) ||\n (!audioCodec && adtsChanelConfig === 1)) {\n adtsObjectType = 2;\n config = new Array(2);\n }\n adtsExtensionSampleingIndex = adtsSampleingIndex;\n }\n }\n /* refer to http://wiki.multimedia.cx/index.php?title=MPEG-4_Audio#Audio_Specific_Config\n ISO 14496-3 (AAC).pdf - Table 1.13 — Syntax of AudioSpecificConfig()\n Audio Profile / Audio Object Type\n 0: Null\n 1: AAC Main\n 2: AAC LC (Low Complexity)\n
2016-02-24 20:15:07 -07:00
"/* inline demuxer.\n * probe fragments and instantiate appropriate demuxer depending on content type (TSDemuxer, AACDemuxer, ...)\n */\n\nimport Event from '../events';\nimport {ErrorTypes, ErrorDetails} from '../errors';\nimport AACDemuxer from '../demux/aacdemuxer';\nimport TSDemuxer from '../demux/tsdemuxer';\nimport MP4Remuxer from '../remux/mp4-remuxer';\nimport PassThroughRemuxer from '../remux/passthrough-remuxer';\n\nclass DemuxerInline {\n\n constructor(hls,typeSupported) {\n this.hls = hls;\n this.typeSupported = typeSupported;\n }\n\n destroy() {\n var demuxer = this.demuxer;\n if (demuxer) {\n demuxer.destroy();\n }\n }\n\n push(data, audioCodec, videoCodec, timeOffset, cc, level, sn, duration) {\n var demuxer = this.demuxer;\n if (!demuxer) {\n var hls = this.hls;\n // probe for content type\n if (TSDemuxer.probe(data)) {\n if (this.typeSupported.mp2t === true) {\n demuxer = new TSDemuxer(hls,PassThroughRemuxer);\n } else {\n demuxer = new TSDemuxer(hls,MP4Remuxer);\n }\n } else if(AACDemuxer.probe(data)) {\n demuxer = new AACDemuxer(hls,MP4Remuxer);\n } else {\n hls.trigger(Event.ERROR, {type : ErrorTypes.MEDIA_ERROR, details: ErrorDetails.FRAG_PARSING_ERROR, fatal: true, reason: 'no demux matching with content found'});\n return;\n }\n this.demuxer = demuxer;\n }\n demuxer.push(data,audioCodec,videoCodec,timeOffset,cc,level,sn,duration);\n }\n}\n\nexport default DemuxerInline;\n",
"/* demuxer web worker.\n * - listen to worker message, and trigger DemuxerInline upon reception of Fragments.\n * - provides MP4 Boxes back to main thread using [transferable objects](https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast) in order to minimize message passing overhead.\n */\n\n import DemuxerInline from '../demux/demuxer-inline';\n import Event from '../events';\n import EventEmitter from 'events';\n\nvar DemuxerWorker = function (self) {\n // observer setup\n var observer = new EventEmitter();\n observer.trigger = function trigger (event, ...data) {\n observer.emit(event, event, ...data);\n };\n\n observer.off = function off (event, ...data) {\n observer.removeListener(event, ...data);\n };\n self.addEventListener('message', function (ev) {\n var data = ev.data;\n //console.log('demuxer cmd:' + data.cmd);\n switch (data.cmd) {\n case 'init':\n self.demuxer = new DemuxerInline(observer, data.typeSupported);\n break;\n case 'demux':\n self.demuxer.push(new Uint8Array(data.data), data.audioCodec, data.videoCodec, data.timeOffset, data.cc, data.level, data.sn, data.duration);\n break;\n default:\n break;\n }\n });\n\n // listen to events triggered by Demuxer\n observer.on(Event.FRAG_PARSING_INIT_SEGMENT, function(ev, data) {\n self.postMessage({event: ev, tracks : data.tracks, unique : data.unique });\n });\n\n observer.on(Event.FRAG_PARSING_DATA, function(ev, data) {\n var objData = {event: ev, type: data.type, startPTS: data.startPTS, endPTS: data.endPTS, startDTS: data.startDTS, endDTS: data.endDTS, data1: data.data1.buffer, data2: data.data2.buffer, nb: data.nb};\n // pass data1/data2 as transferable object (no copy)\n self.postMessage(objData, [objData.data1, objData.data2]);\n });\n\n observer.on(Event.FRAG_PARSED, function(event) {\n self.postMessage({event: event});\n });\n\n observer.on(Event.ERROR, function(event, data) {\n self.postMessage({event: event, data: data});\n });\n\n observer.on(Event.FRAG_PARSING_METADATA, function(event, data) {\n var objData = {event: event, samples: data.samples};\n self.postMessage(objData);\n });\n\n observer.on(Event.FRAG_PARSING_USERDATA, function(event, data) {\n var objData = {event: event, samples: data.samples};\n self.postMessage(objData);\n });\n\n};\n\nexport default DemuxerWorker;\n\n",
"import Event from '../events';\nimport DemuxerInline from '../demux/demuxer-inline';\nimport DemuxerWorker from '../demux/demuxer-worker';\nimport {logger} from '../utils/logger';\nimport Decrypter from '../crypt/decrypter';\n\nclass Demuxer {\n\n constructor(hls) {\n this.hls = hls;\n var typeSupported = {\n mp4 : MediaSource.isTypeSupported('video/mp4'),\n mp2t : hls.config.enableMP2TPassThrough && MediaSource.isTypeSupported('video/mp2t')\n };\n if (hls.config.enableWorker && (typeof(Worker) !== 'undefined')) {\n logger.log('demuxing in webworker');\n try {\n var work = require('webworkify');\n this.w = work(DemuxerWorker);\n this.onwmsg = this.onWorkerMessage.bind(this);\n this.w.addEventListener('message', this.onwmsg);\n this.w.postMessage({cmd: 'init', typeSupported : typeSupported});\n } catch(err) {\n logger.error('error while initializing DemuxerWorker, fallback on DemuxerInline');\n this.demuxer = new DemuxerInline(hls,typeSupported);\n }\n } else {\n this.demuxer = new DemuxerInline(hls,typeSupported);\n }\n this.demuxInitialized = true;\n }\n\n destroy() {\n if (this.w) {\n this.w.removeEventListener('message', this.onwmsg);\n this.w.terminate();\n this.w = null;\n } else {\n this.demuxer.destroy();\n this.demuxer = null;\n }\n if (this.decrypter) {\n this.decrypter.destroy();\n this.decrypter = null;\n }\n }\n\n pushDecrypted(data, audioCodec, videoCodec, timeOffset, cc, level, sn, duration) {\n if (this.w) {\n // post fragment payload as transferable objects (no copy)\n this.w.postMessage({cmd: 'demux', data: data, audioCodec: audioCodec, videoCodec: videoCodec, timeOffset: timeOffset, cc: cc, level: level, sn : sn, duration: duration}, [data]);\n } else {\n this.demuxer.push(new Uint8Array(data), audioCodec, videoCodec, timeOffset, cc, level, sn, duration);\n }\n }\n\n push(data, audioCodec, videoCodec, timeOffset, cc, level, sn, duration, decryptdata) {\n if ((data.byteLength > 0) && (decryptdata != null) && (decryptdata.key != null) && (decryptdata.method === 'AES-128')) {\n if (this.decrypter == null) {\n this.decrypter = new Decrypter(this.hls);\n }\n\n var localthis = this;\n this.decrypter.decrypt(data, decryptdata.key, decryptdata.iv, function(decryptedData){\n localthis.pushDecrypted(decryptedData, audioCodec, videoCodec, timeOffset, cc, level, sn, duration);\n });\n } else {\n this.pushDecrypted(data, audioCodec, videoCodec, timeOffset, cc, level, sn, duration);\n }\n }\n\n onWorkerMessage(ev) {\n var data = ev.data;\n //console.log('onWorkerMessage:' + data.event);\n switch(data.event) {\n case Event.FRAG_PARSING_INIT_SEGMENT:\n var obj = {};\n obj.tracks = data.tracks;\n obj.unique = data.unique;\n this.hls.trigger(Event.FRAG_PARSING_INIT_SEGMENT, obj);\n break;\n case Event.FRAG_PARSING_DATA:\n this.hls.trigger(Event.FRAG_PARSING_DATA,{\n data1: new Uint8Array(data.data1),\n data2: new Uint8Array(data.data2),\n startPTS: data.startPTS,\n endPTS: data.endPTS,\n startDTS: data.startDTS,\n endDTS: data.endDTS,\n type: data.type,\n nb: data.nb\n });\n break;\n case Event.FRAG_PARSING_METADATA:\n this.hls.trigger(Event.FRAG_PARSING_METADATA, {\n samples: data.samples\n });\n break;\n case Event.FRAG_PARSING_USERDATA:\n this.hls.trigger(Event.FRAG_PARSING_USERDATA, {\n samples: data.samples\n });\n break;\n default:\n this.hls.trigger(data.event, data.data);\n break;\n }\n }\n}\n\nexport default Demuxer;\n\n",
"/**\n * Parser for exponential Golomb codes, a variable-bitwidth number encoding scheme used by h264.\n*/\n\nimport {logger} from '../utils/logger';\n\nclass ExpGolomb {\n\n constructor(data) {\n this.data = data;\n // the number of bytes left to examine in this.data\n this.bytesAvailable = this.data.byteLength;\n // the current word being examined\n this.word = 0; // :uint\n // the number of bits left to examine in the current word\n this.bitsAvailable = 0; // :uint\n }\n\n // ():void\n loadWord() {\n var\n position = this.data.byteLength - this.bytesAvailable,\n workingBytes = new Uint8Array(4),\n availableBytes = Math.min(4, this.bytesAvailable);\n if (availableBytes === 0) {\n throw new Error('no bytes available');\n }\n workingBytes.set(this.data.subarray(position, position + availableBytes));\n this.word = new DataView(workingBytes.buffer).getUint32(0);\n // track the amount of this.data that has been processed\n this.bitsAvailable = availableBytes * 8;\n this.bytesAvailable -= availableBytes;\n }\n\n // (count:int):void\n skipBits(count) {\n var skipBytes; // :int\n if (this.bitsAvailable > count) {\n this.word <<= count;\n this.bitsAvailable -= count;\n } else {\n count -= this.bitsAvailable;\n skipBytes = count >> 3;\n count -= (skipBytes >> 3);\n this.bytesAvailable -= skipBytes;\n this.loadWord();\n this.word <<= count;\n this.bitsAvailable -= count;\n }\n }\n\n // (size:int):uint\n readBits(size) {\n var\n bits = Math.min(this.bitsAvailable, size), // :uint\n valu = this.word >>> (32 - bits); // :uint\n if (size > 32) {\n logger.error('Cannot read more than 32 bits at a time');\n }\n this.bitsAvailable -= bits;\n if (this.bitsAvailable > 0) {\n this.word <<= bits;\n } else if (this.bytesAvailable > 0) {\n this.loadWord();\n }\n bits = size - bits;\n if (bits > 0) {\n return valu << bits | this.readBits(bits);\n } else {\n return valu;\n }\n }\n\n // ():uint\n skipLZ() {\n var leadingZeroCount; // :uint\n for (leadingZeroCount = 0; leadingZeroCount < this.bitsAvailable; ++leadingZeroCount) {\n if (0 !== (this.word & (0x80000000 >>> leadingZeroCount))) {\n // the first bit of working word is 1\n this.word <<= leadingZeroCount;\n this.bitsAvailable -= leadingZeroCount;\n return leadingZeroCount;\n }\n }\n // we exhausted word and still have not found a 1\n this.loadWord();\n return leadingZeroCount + this.skipLZ();\n }\n\n // ():void\n skipUEG() {\n this.skipBits(1 + this.skipLZ());\n }\n\n // ():void\n skipEG() {\n this.skipBits(1 + this.skipLZ());\n }\n\n // ():uint\n readUEG() {\n var clz = this.skipLZ(); // :uint\n return this.readBits(clz + 1) - 1;\n }\n\n // ():int\n readEG() {\n var valu = this.readUEG(); // :int\n if (0x01 & valu) {\n // the number is odd if the low order bit is set\n return (1 + valu) >>> 1; // add 1 to make it even, and divide by 2\n } else {\n return -1 * (valu >>> 1); // divide by two then make it negative\n }\n }\n\n // Some convenience functions\n // :Boolean\n readBoolean() {\n return 1 === this.readBits(1);\n }\n\n // ():int\n readUByte() {\n return this.readBits(8);\n }\n\n // ():int\n readUShort() {\n return this.readBits(16);\n }\n // ():int\n readUInt() {\n return this.readBits(32);\n }\n\n /**\n * Advance the ExpGolomb decoder past a scaling list. The scaling\n * list is optionally transmitted as part of a sequence parameter\n * set and is not relevant to transmuxing.\n * @param count {number} the number of entries in this scaling list\n * @see Recommendation ITU-T H.264, Section 7.3.2.1.1.1\n */\n skipScalingList(count) {\n var\n lastScale = 8,\n nextScale = 8,\n j,\n deltaScale;\n for (j = 0; j < count; j++) {\n if (nextScale !== 0) {\n deltaScale = this.readEG();\n nextScale =
2015-12-23 10:46:01 -07:00
"/**\n * ID3 parser\n */\nimport {logger} from '../utils/logger';\n//import Hex from '../utils/hex';\n\n class ID3 {\n\n constructor(data) {\n this._hasTimeStamp = false;\n var offset = 0, byte1,byte2,byte3,byte4,tagSize,endPos,header,len;\n do {\n header = this.readUTF(data,offset,3);\n offset+=3;\n // first check for ID3 header\n if (header === 'ID3') {\n // skip 24 bits\n offset += 3;\n // retrieve tag(s) length\n byte1 = data[offset++] & 0x7f;\n byte2 = data[offset++] & 0x7f;\n byte3 = data[offset++] & 0x7f;\n byte4 = data[offset++] & 0x7f;\n tagSize = (byte1 << 21) + (byte2 << 14) + (byte3 << 7) + byte4;\n endPos = offset + tagSize;\n //logger.log(`ID3 tag found, size/end: ${tagSize}/${endPos}`);\n\n // read ID3 tags\n this._parseID3Frames(data, offset,endPos);\n offset = endPos;\n } else if (header === '3DI') {\n // http://id3.org/id3v2.4.0-structure chapter 3.4. ID3v2 footer\n offset += 7;\n logger.log(`3DI footer found, end: ${offset}`);\n } else {\n offset -= 3;\n len = offset;\n if (len) {\n //logger.log(`ID3 len: ${len}`);\n if (!this.hasTimeStamp) {\n logger.warn('ID3 tag found, but no timestamp');\n }\n this._length = len;\n this._payload = data.subarray(0,len);\n }\n return;\n }\n } while (true);\n }\n\n readUTF(data,start,len) {\n\n var result = '',offset = start, end = start + len;\n do {\n result += String.fromCharCode(data[offset++]);\n } while(offset < end);\n return result;\n }\n\n _parseID3Frames(data,offset,endPos) {\n var tagId,tagLen,tagStart,tagFlags,timestamp;\n while(offset + 8 <= endPos) {\n tagId = this.readUTF(data,offset,4);\n offset +=4;\n\n tagLen = data[offset++] << 24 +\n data[offset++] << 16 +\n data[offset++] << 8 +\n data[offset++];\n\n tagFlags = data[offset++] << 8 +\n data[offset++];\n\n tagStart = offset;\n //logger.log(\"ID3 tag id:\" + tagId);\n switch(tagId) {\n case 'PRIV':\n //logger.log('parse frame:' + Hex.hexDump(data.subarray(offset,endPos)));\n // owner should be \"com.apple.streaming.transportStreamTimestamp\"\n if (this.readUTF(data,offset,44) === 'com.apple.streaming.transportStreamTimestamp') {\n offset+=44;\n // smelling even better ! we found the right descriptor\n // skip null character (string end) + 3 first bytes\n offset+= 4;\n\n // timestamp is 33 bit expressed as a big-endian eight-octet number, with the upper 31 bits set to zero.\n var pts33Bit = data[offset++] & 0x1;\n this._hasTimeStamp = true;\n\n timestamp = ((data[offset++] << 23) +\n (data[offset++] << 15) +\n (data[offset++] << 7) +\n data[offset++]) /45;\n\n if (pts33Bit) {\n timestamp += 47721858.84; // 2^32 / 90\n }\n timestamp = Math.round(timestamp);\n logger.trace(`ID3 timestamp found: ${timestamp}`);\n this._timeStamp = timestamp;\n }\n break;\n default:\n break;\n }\n }\n }\n\n get hasTimeStamp() {\n return this._hasTimeStamp;\n }\n\n get timeStamp() {\n return this._timeStamp;\n }\n\n get length() {\n return this._length;\n }\n\n get payload() {\n return this._payload;\n }\n\n}\n\nexport default ID3;\n\n",
2016-03-18 10:28:45 -07:00
"/**\n * highly optimized TS demuxer:\n * parse PAT, PMT\n * extract PES packet from audio and video PIDs\n * extract AVC/H264 NAL units and AAC/ADTS samples from PES packet\n * trigger the remuxer upon parsing completion\n * it also tries to workaround as best as it can audio codec switch (HE-AAC to AAC and vice versa), without having to restart the MediaSource.\n * it also controls the remuxing process :\n * upon discontinuity or level switch detection, it will also notifies the remuxer so that it can reset its state.\n*/\n\n import ADTS from './adts';\n import Event from '../events';\n import ExpGolomb from './exp-golomb';\n// import Hex from '../utils/hex';\n import {logger} from '../utils/logger';\n import {ErrorTypes, ErrorDetails} from '../errors';\n\n class TSDemuxer {\n\n constructor(observer,remuxerClass) {\n this.observer = observer;\n this.remuxerClass = remuxerClass;\n this.lastCC = 0;\n this.remuxer = new this.remuxerClass(observer);\n }\n\n static probe(data) {\n // a TS fragment should contain at least 3 TS packets, a PAT, a PMT, and one PID, each starting with 0x47\n if (data.length >= 3*188 && data[0] === 0x47 && data[188] === 0x47 && data[2*188] === 0x47) {\n return true;\n } else {\n return false;\n }\n }\n\n switchLevel() {\n this.pmtParsed = false;\n this._pmtId = -1;\n this.lastAacPTS = null;\n this.aacOverFlow = null;\n this._avcTrack = {container : 'video/mp2t', type: 'video', id :-1, sequenceNumber: 0, samples : [], len : 0, nbNalu : 0};\n this._aacTrack = {container : 'video/mp2t', type: 'audio', id :-1, sequenceNumber: 0, samples : [], len : 0};\n this._id3Track = {type: 'id3', id :-1, sequenceNumber: 0, samples : [], len : 0};\n this._txtTrack = {type: 'text', id: -1, sequenceNumber: 0, samples: [], len: 0};\n this.remuxer.switchLevel();\n }\n\n insertDiscontinuity() {\n this.switchLevel();\n this.remuxer.insertDiscontinuity();\n }\n\n // feed incoming data to the front of the parsing pipeline\n push(data, audioCodec, videoCodec, timeOffset, cc, level, sn, duration) {\n var avcData, aacData, id3Data,\n start, len = data.length, stt, pid, atf, offset,\n codecsOnly = this.remuxer.passthrough;\n\n this.audioCodec = audioCodec;\n this.videoCodec = videoCodec;\n this.timeOffset = timeOffset;\n this._duration = duration;\n this.contiguous = false;\n if (cc !== this.lastCC) {\n logger.log('discontinuity detected');\n this.insertDiscontinuity();\n this.lastCC = cc;\n } else if (level !== this.lastLevel) {\n logger.log('level switch detected');\n this.switchLevel();\n this.lastLevel = level;\n } else if (sn === (this.lastSN+1)) {\n this.contiguous = true;\n }\n this.lastSN = sn;\n\n if(!this.contiguous) {\n // flush any partial content\n this.aacOverFlow = null;\n }\n\n var pmtParsed = this.pmtParsed,\n avcId = this._avcTrack.id,\n aacId = this._aacTrack.id,\n id3Id = this._id3Track.id;\n\n // don't parse last TS packet if incomplete\n len -= len % 188;\n // loop through TS packets\n for (start = 0; start < len; start += 188) {\n if (data[start] === 0x47) {\n stt = !!(data[start + 1] & 0x40);\n // pid is a 13-bit field starting at the last bit of TS[1]\n pid = ((data[start + 1] & 0x1f) << 8) + data[start + 2];\n atf = (data[start + 3] & 0x30) >> 4;\n // if an adaption field is present, its length is specified by the fifth byte of the TS packet header.\n if (atf > 1) {\n offset = start + 5 + data[start + 4];\n // continue if there is only adaptation field\n if (offset === (start + 188)) {\n continue;\n }\n } else {\n offset = start + 4;\n }\n if (pmtParsed) {\n if (pid === avcId) {\n if (stt) {\n if (avcData) {\n this._parseAVCPES(this._parsePES(avcData));\n if (codecsOnly) {\n // if we hav
2016-03-14 10:06:02 -07:00
"export const ErrorTypes = {\n // Identifier for a network error (loading error / timeout ...)\n NETWORK_ERROR: 'networkError',\n // Identifier for a media Error (video/parsing/mediasource error)\n MEDIA_ERROR: 'mediaError',\n // Identifier for all other errors\n OTHER_ERROR: 'otherError'\n};\n\nexport const ErrorDetails = {\n // Identifier for a manifest load error - data: { url : faulty URL, response : XHR response}\n MANIFEST_LOAD_ERROR: 'manifestLoadError',\n // Identifier for a manifest load timeout - data: { url : faulty URL, response : XHR response}\n MANIFEST_LOAD_TIMEOUT: 'manifestLoadTimeOut',\n // Identifier for a manifest parsing error - data: { url : faulty URL, reason : error reason}\n MANIFEST_PARSING_ERROR: 'manifestParsingError',\n // Identifier for a manifest with only incompatible codecs error - data: { url : faulty URL, reason : error reason}\n MANIFEST_INCOMPATIBLE_CODECS_ERROR: 'manifestIncompatibleCodecsError',\n // Identifier for playlist load error - data: { url : faulty URL, response : XHR response}\n LEVEL_LOAD_ERROR: 'levelLoadError',\n // Identifier for playlist load timeout - data: { url : faulty URL, response : XHR response}\n LEVEL_LOAD_TIMEOUT: 'levelLoadTimeOut',\n // Identifier for a level switch error - data: { level : faulty level Id, event : error description}\n LEVEL_SWITCH_ERROR: 'levelSwitchError',\n // Identifier for fragment load error - data: { frag : fragment object, response : XHR response}\n FRAG_LOAD_ERROR: 'fragLoadError',\n // Identifier for fragment loop loading error - data: { frag : fragment object}\n FRAG_LOOP_LOADING_ERROR: 'fragLoopLoadingError',\n // Identifier for fragment load timeout error - data: { frag : fragment object}\n FRAG_LOAD_TIMEOUT: 'fragLoadTimeOut',\n // Identifier for a fragment decryption error event - data: parsing error description\n FRAG_DECRYPT_ERROR: 'fragDecryptError',\n // Identifier for a fragment parsing error event - data: parsing error description\n FRAG_PARSING_ERROR: 'fragParsingError',\n // Identifier for decrypt key load error - data: { frag : fragment object, response : XHR response}\n KEY_LOAD_ERROR: 'keyLoadError',\n // Identifier for decrypt key load timeout error - data: { frag : fragment object}\n KEY_LOAD_TIMEOUT: 'keyLoadTimeOut',\n // Identifier for a buffer append error - data: append error description\n BUFFER_APPEND_ERROR: 'bufferAppendError',\n // Identifier for a buffer appending error event - data: appending error description\n BUFFER_APPENDING_ERROR: 'bufferAppendingError',\n // Identifier for a buffer stalled error event\n BUFFER_STALLED_ERROR: 'bufferStalledError',\n // Identifier for a buffer full event\n BUFFER_FULL_ERROR: 'bufferFullError',\n // Identifier for a buffer seek over hole event\n BUFFER_SEEK_OVER_HOLE: 'bufferSeekOverHole'\n};\n",
2016-01-18 12:07:26 -07:00
"/*\n*\n* All objects in the event handling chain should inherit from this class\n*\n*/\n\n//import {logger} from './utils/logger';\n\nclass EventHandler {\n\n constructor(hls, ...events) {\n this.hls = hls;\n this.onEvent = this.onEvent.bind(this);\n this.handledEvents = events;\n this.useGenericHandler = true;\n\n this.registerListeners();\n }\n\n destroy() {\n this.unregisterListeners();\n }\n\n isEventHandler() {\n return typeof this.handledEvents === 'object' && this.handledEvents.length && typeof this.onEvent === 'function';\n }\n\n registerListeners() {\n if (this.isEventHandler()) {\n this.handledEvents.forEach(function(event) {\n if (event === 'hlsEventGeneric') {\n throw new Error('Forbidden event name: ' + event);\n }\n this.hls.on(event, this.onEvent);\n }.bind(this));\n }\n }\n\n unregisterListeners() {\n if (this.isEventHandler()) {\n this.handledEvents.forEach(function(event) {\n this.hls.off(event, this.onEvent);\n }.bind(this));\n }\n }\n\n /*\n * arguments: event (string), data (any)\n */\n onEvent(event, data) {\n this.onEventGeneric(event, data);\n }\n\n onEventGeneric(event, data) {\n var eventToFunction = function(event, data) {\n var funcName = 'on' + event.replace('hls', '');\n if (typeof this[funcName] !== 'function') {\n throw new Error(`Event ${event} has no generic handler in this ${this.constructor.name} class (tried ${funcName})`);\n }\n return this[funcName].bind(this, data);\n };\n eventToFunction.call(this, event, data).call();\n }\n}\n\nexport default EventHandler;",
2016-02-24 20:15:07 -07:00
"module.exports = {\n // fired before MediaSource is attaching to media element - data: { media }\n MEDIA_ATTACHING: 'hlsMediaAttaching',\n // fired when MediaSource has been succesfully attached to media element - data: { }\n MEDIA_ATTACHED: 'hlsMediaAttached',\n // fired before detaching MediaSource from media element - data: { }\n MEDIA_DETACHING: 'hlsMediaDetaching',\n // fired when MediaSource has been detached from media element - data: { }\n MEDIA_DETACHED: 'hlsMediaDetached',\n // fired when we buffer is going to be resetted\n BUFFER_RESET: 'hlsBufferReset',\n // fired when we know about the codecs that we need buffers for to push into - data: {tracks : { container, codec, levelCodec, initSegment, metadata }}\n BUFFER_CODECS: 'hlsBufferCodecs',\n // fired when we append a segment to the buffer - data: { segment: segment object }\n BUFFER_APPENDING: 'hlsBufferAppending',\n // fired when we are done with appending a media segment to the buffer\n BUFFER_APPENDED: 'hlsBufferAppended',\n // fired when the stream is finished and we want to notify the media buffer that there will be no more data\n BUFFER_EOS: 'hlsBufferEos',\n // fired when the media buffer should be flushed - data {startOffset, endOffset}\n BUFFER_FLUSHING: 'hlsBufferFlushing',\n // fired when the media has been flushed\n BUFFER_FLUSHED: 'hlsBufferFlushed',\n // fired to signal that a manifest loading starts - data: { url : manifestURL}\n MANIFEST_LOADING: 'hlsManifestLoading',\n // fired after manifest has been loaded - data: { levels : [available quality levels] , url : manifestURL, stats : { trequest, tfirst, tload, mtime}}\n MANIFEST_LOADED: 'hlsManifestLoaded',\n // fired after manifest has been parsed - data: { levels : [available quality levels] , firstLevel : index of first quality level appearing in Manifest}\n MANIFEST_PARSED: 'hlsManifestParsed',\n // fired when a level playlist loading starts - data: { url : level URL level : id of level being loaded}\n LEVEL_LOADING: 'hlsLevelLoading',\n // fired when a level playlist loading finishes - data: { details : levelDetails object, level : id of loaded level, stats : { trequest, tfirst, tload, mtime} }\n LEVEL_LOADED: 'hlsLevelLoaded',\n // fired when a level's details have been updated based on previous details, after it has been loaded. - data: { details : levelDetails object, level : id of updated level }\n LEVEL_UPDATED: 'hlsLevelUpdated',\n // fired when a level's PTS information has been updated after parsing a fragment - data: { details : levelDetails object, level : id of updated level, drift: PTS drift observed when parsing last fragment }\n LEVEL_PTS_UPDATED: 'hlsLevelPtsUpdated',\n // fired when a level switch is requested - data: { level : id of new level }\n LEVEL_SWITCH: 'hlsLevelSwitch',\n // fired when a fragment loading starts - data: { frag : fragment object}\n FRAG_LOADING: 'hlsFragLoading',\n // fired when a fragment loading is progressing - data: { frag : fragment object, { trequest, tfirst, loaded}}\n FRAG_LOAD_PROGRESS: 'hlsFragLoadProgress',\n // Identifier for fragment load aborting for emergency switch down - data: {frag : fragment object}\n FRAG_LOAD_EMERGENCY_ABORTED: 'hlsFragLoadEmergencyAborted',\n // fired when a fragment loading is completed - data: { frag : fragment object, payload : fragment payload, stats : { trequest, tfirst, tload, length}}\n FRAG_LOADED: 'hlsFragLoaded',\n // fired when Init Segment has been extracted from fragment - data: { moov : moov MP4 box, codecs : codecs found while parsing fragment}\n FRAG_PARSING_INIT_SEGMENT: 'hlsFragParsingInitSegment',\n // fired when parsing sei text is completed - data: { samples : [ sei samples pes ] }\n FRAG_PARSING_USERDATA: 'hlsFragParsingUserdata',\n // fired when parsing id3 is completed - data: { samples : [ id3 samples pes ] }\n FRAG_PARSING_METADATA: 'hlsFragParsingMetadata',\n // fired when data have been extracted from fragment - data: { data1 : moof MP4 box or TS fragments, data2 : mdat MP4 box or null}\n FRAG_PARSING_DATA: 'hlsFragParsingDa
2016-03-25 09:35:19 -07:00
"/**\n * Buffer Helper class, providing methods dealing buffer length retrieval\n*/\n\n\nclass BufferHelper {\n\n static bufferInfo(media, pos,maxHoleDuration) {\n if (media) {\n var vbuffered = media.buffered, buffered = [],i;\n for (i = 0; i < vbuffered.length; i++) {\n buffered.push({start: vbuffered.start(i), end: vbuffered.end(i)});\n }\n return this.bufferedInfo(buffered,pos,maxHoleDuration);\n } else {\n return {len: 0, start: 0, end: 0, nextStart : undefined} ;\n }\n }\n\n static bufferedInfo(buffered,pos,maxHoleDuration) {\n var buffered2 = [],\n // bufferStart and bufferEnd are buffer boundaries around current video position\n bufferLen,bufferStart, bufferEnd,bufferStartNext,i;\n // sort on buffer.start/smaller end (IE does not always return sorted buffered range)\n buffered.sort(function (a, b) {\n var diff = a.start - b.start;\n if (diff) {\n return diff;\n } else {\n return b.end - a.end;\n }\n });\n // there might be some small holes between buffer time range\n // consider that holes smaller than maxHoleDuration are irrelevant and build another\n // buffer time range representations that discards those holes\n for (i = 0; i < buffered.length; i++) {\n var buf2len = buffered2.length;\n if(buf2len) {\n var buf2end = buffered2[buf2len - 1].end;\n // if small hole (value between 0 or maxHoleDuration ) or overlapping (negative)\n if((buffered[i].start - buf2end) < maxHoleDuration) {\n // merge overlapping time ranges\n // update lastRange.end only if smaller than item.end\n // e.g. [ 1, 15] with [ 2,8] => [ 1,15] (no need to modify lastRange.end)\n // whereas [ 1, 8] with [ 2,15] => [ 1,15] ( lastRange should switch from [1,8] to [1,15])\n if(buffered[i].end > buf2end) {\n buffered2[buf2len - 1].end = buffered[i].end;\n }\n } else {\n // big hole\n buffered2.push(buffered[i]);\n }\n } else {\n // first value\n buffered2.push(buffered[i]);\n }\n }\n for (i = 0, bufferLen = 0, bufferStart = bufferEnd = pos; i < buffered2.length; i++) {\n var start = buffered2[i].start,\n end = buffered2[i].end;\n //logger.log('buf start/end:' + buffered.start(i) + '/' + buffered.end(i));\n if ((pos + maxHoleDuration) >= start && pos < end) {\n // play position is inside this buffer TimeRange, retrieve end of buffer position and buffer length\n bufferStart = start;\n bufferEnd = end;\n bufferLen = bufferEnd - pos;\n } else if ((pos + maxHoleDuration) < start) {\n bufferStartNext = start;\n break;\n }\n }\n return {len: bufferLen, start: bufferStart, end: bufferEnd, nextStart : bufferStartNext};\n }\n\n}\n\nexport default BufferHelper;\n",
2016-01-13 13:58:12 -07:00
"/**\n * Level Helper class, providing methods dealing with playlist sliding and drift\n*/\n\nimport {logger} from '../utils/logger';\n\nclass LevelHelper {\n\n static mergeDetails(oldDetails,newDetails) {\n var start = Math.max(oldDetails.startSN,newDetails.startSN)-newDetails.startSN,\n end = Math.min(oldDetails.endSN,newDetails.endSN)-newDetails.startSN,\n delta = newDetails.startSN - oldDetails.startSN,\n oldfragments = oldDetails.fragments,\n newfragments = newDetails.fragments,\n ccOffset =0,\n PTSFrag;\n\n // check if old/new playlists have fragments in common\n if ( end < start) {\n newDetails.PTSKnown = false;\n return;\n }\n // loop through overlapping SN and update startPTS , cc, and duration if any found\n for(var i = start ; i <= end ; i++) {\n var oldFrag = oldfragments[delta+i],\n newFrag = newfragments[i];\n ccOffset = oldFrag.cc - newFrag.cc;\n if (!isNaN(oldFrag.startPTS)) {\n newFrag.start = newFrag.startPTS = oldFrag.startPTS;\n newFrag.endPTS = oldFrag.endPTS;\n newFrag.duration = oldFrag.duration;\n PTSFrag = newFrag;\n }\n }\n\n if(ccOffset) {\n logger.log(`discontinuity sliding from playlist, take drift into account`);\n for(i = 0 ; i < newfragments.length ; i++) {\n newfragments[i].cc += ccOffset;\n }\n }\n\n // if at least one fragment contains PTS info, recompute PTS information for all fragments\n if(PTSFrag) {\n LevelHelper.updateFragPTS(newDetails,PTSFrag.sn,PTSFrag.startPTS,PTSFrag.endPTS);\n } else {\n // adjust start by sliding offset\n var sliding = oldfragments[delta].start;\n for(i = 0 ; i < newfragments.length ; i++) {\n newfragments[i].start += sliding;\n }\n }\n // if we are here, it means we have fragments overlapping between\n // old and new level. reliable PTS info is thus relying on old level\n newDetails.PTSKnown = oldDetails.PTSKnown;\n return;\n }\n\n static updateFragPTS(details,sn,startPTS,endPTS) {\n var fragIdx, fragments, frag, i;\n // exit if sn out of range\n if (sn < details.startSN || sn > details.endSN) {\n return 0;\n }\n fragIdx = sn - details.startSN;\n fragments = details.fragments;\n frag = fragments[fragIdx];\n if(!isNaN(frag.startPTS)) {\n startPTS = Math.min(startPTS,frag.startPTS);\n endPTS = Math.max(endPTS, frag.endPTS);\n }\n\n var drift = startPTS - frag.start;\n\n frag.start = frag.startPTS = startPTS;\n frag.endPTS = endPTS;\n frag.duration = endPTS - startPTS;\n // adjust fragment PTS/duration from seqnum-1 to frag 0\n for(i = fragIdx ; i > 0 ; i--) {\n LevelHelper.updatePTS(fragments,i,i-1);\n }\n\n // adjust fragment PTS/duration from seqnum to last frag\n for(i = fragIdx ; i < fragments.length - 1 ; i++) {\n LevelHelper.updatePTS(fragments,i,i+1);\n }\n details.PTSKnown = true;\n //logger.log(` frag start/end:${startPTS.toFixed(3)}/${endPTS.toFixed(3)}`);\n\n return drift;\n }\n\n static updatePTS(fragments,fromIdx, toIdx) {\n var fragFrom = fragments[fromIdx],fragTo = fragments[toIdx], fragToPTS = fragTo.startPTS;\n // if we know startPTS[toIdx]\n if(!isNaN(fragToPTS)) {\n // update fragment duration.\n // it helps to fix drifts between playlist reported duration and fragment real duration\n if (toIdx > fromIdx) {\n fragFrom.duration = fragToPTS-fragFrom.start;\n if(fragFrom.duration < 0) {\n logger.error(`negative duration computed for frag ${fragFrom.sn},level ${fragFrom.level}, there should be some duration drift between playlist and fragment!`);\n }\n } else {\n fragTo.duration = fragFrom.start - fragToPTS;\n if(fragTo.duration < 0) {\n logger.error(`negative duration computed for frag ${fragTo.sn},level ${fragTo.level}, there should be some duration drift between playlist and fragment!`);\n }\n }\n
2016-03-27 16:22:53 -07:00
"/**\n * HLS interface\n */\n'use strict';\n\nimport Event from './events';\nimport {ErrorTypes, ErrorDetails} from './errors';\nimport PlaylistLoader from './loader/playlist-loader';\nimport FragmentLoader from './loader/fragment-loader';\nimport AbrController from './controller/abr-controller';\nimport BufferController from './controller/buffer-controller';\nimport CapLevelController from './controller/cap-level-controller';\nimport StreamController from './controller/stream-controller';\nimport LevelController from './controller/level-controller';\nimport TimelineController from './controller/timeline-controller';\n//import FPSController from './controller/fps-controller';\nimport {logger, enableLogs} from './utils/logger';\nimport XhrLoader from './utils/xhr-loader';\nimport EventEmitter from 'events';\nimport KeyLoader from './loader/key-loader';\n\nclass Hls {\n\n static isSupported() {\n return (window.MediaSource && window.MediaSource.isTypeSupported('video/mp4; codecs=\"avc1.42E01E,mp4a.40.2\"'));\n }\n\n static get Events() {\n return Event;\n }\n\n static get ErrorTypes() {\n return ErrorTypes;\n }\n\n static get ErrorDetails() {\n return ErrorDetails;\n }\n\n static get DefaultConfig() {\n if(!Hls.defaultConfig) {\n Hls.defaultConfig = {\n autoStartLoad: true,\n debug: false,\n capLevelToPlayerSize: false,\n maxBufferLength: 30,\n maxBufferSize: 60 * 1000 * 1000,\n maxBufferHole: 0.5,\n maxSeekHole: 2,\n seekHoleNudgeDuration : 0.01,\n maxFragLookUpTolerance : 0.2,\n liveSyncDurationCount:3,\n liveMaxLatencyDurationCount: Infinity,\n liveSyncDuration: undefined,\n liveMaxLatencyDuration: undefined,\n maxMaxBufferLength: 600,\n enableWorker: true,\n enableSoftwareAES: true,\n manifestLoadingTimeOut: 10000,\n manifestLoadingMaxRetry: 1,\n manifestLoadingRetryDelay: 1000,\n levelLoadingTimeOut: 10000,\n levelLoadingMaxRetry: 4,\n levelLoadingRetryDelay: 1000,\n fragLoadingTimeOut: 20000,\n fragLoadingMaxRetry: 6,\n fragLoadingRetryDelay: 1000,\n fragLoadingLoopThreshold: 3,\n startFragPrefetch : false,\n // fpsDroppedMonitoringPeriod: 5000,\n // fpsDroppedMonitoringThreshold: 0.2,\n appendErrorMaxRetry: 3,\n loader: XhrLoader,\n fLoader: undefined,\n pLoader: undefined,\n abrController : AbrController,\n bufferController : BufferController,\n capLevelController : CapLevelController,\n streamController: StreamController,\n timelineController: TimelineController,\n enableCEA708Captions: true,\n enableMP2TPassThrough : false\n };\n }\n return Hls.defaultConfig;\n }\n\n static set DefaultConfig(defaultConfig) {\n Hls.defaultConfig = defaultConfig;\n }\n\n constructor(config = {}) {\n var defaultConfig = Hls.DefaultConfig;\n\n if ((config.liveSyncDurationCount || config.liveMaxLatencyDurationCount) && (config.liveSyncDuration || config.liveMaxLatencyDuration)) {\n throw new Error('Illegal hls.js config: don\\'t mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration');\n }\n\n for (var prop in defaultConfig) {\n if (prop in config) { continue; }\n config[prop] = defaultConfig[prop];\n }\n\n if (config.liveMaxLatencyDurationCount !== undefined && config.liveMaxLatencyDurationCount <= config.liveSyncDurationCount) {\n throw new Error('Illegal hls.js config: \"liveMaxLatencyDurationCount\" must be gt \"liveSyncDurationCount\"');\n }\n\n if (config.liveMaxLatencyDuration !== undefined && (config.liveMaxLatencyDuration <= config.liveSyncDuration || config.liveSyncDuration === undefined)) {\n throw new Error('Illegal hls.js config: \"liveMaxLatencyDuration\" must be gt \"liveSyncDuration\"');\n }\n\n enable
2016-02-24 20:15:07 -07:00
"// This is mostly for support of the es6 module export\n// syntax with the babel compiler, it looks like it doesnt support\n// function exports like we are used to in node/commonjs\nmodule.exports = require('./hls.js').default;\n",
2016-03-09 10:40:22 -07:00
"/*\n * Fragment Loader\n*/\n\nimport Event from '../events';\nimport EventHandler from '../event-handler';\nimport {ErrorTypes, ErrorDetails} from '../errors';\n\nclass FragmentLoader extends EventHandler {\n\n constructor(hls) {\n super(hls, Event.FRAG_LOADING);\n }\n\n destroy() {\n if (this.loader) {\n this.loader.destroy();\n this.loader = null;\n }\n EventHandler.prototype.destroy.call(this);\n }\n\n onFragLoading(data) {\n var frag = data.frag;\n this.frag = frag;\n this.frag.loaded = 0;\n var config = this.hls.config;\n frag.loader = this.loader = typeof(config.fLoader) !== 'undefined' ? new config.fLoader(config) : new config.loader(config);\n this.loader.load(frag.url, 'arraybuffer', this.loadsuccess.bind(this), this.loaderror.bind(this), this.loadtimeout.bind(this), config.fragLoadingTimeOut, 1, 0, this.loadprogress.bind(this), frag);\n }\n\n loadsuccess(event, stats) {\n var payload = event.currentTarget.response;\n stats.length = payload.byteLength;\n // detach fragment loader on load success\n this.frag.loader = undefined;\n this.hls.trigger(Event.FRAG_LOADED, {payload: payload, frag: this.frag, stats: stats});\n }\n\n loaderror(event) {\n if (this.loader) {\n this.loader.abort();\n }\n this.hls.trigger(Event.ERROR, {type: ErrorTypes.NETWORK_ERROR, details: ErrorDetails.FRAG_LOAD_ERROR, fatal: false, frag: this.frag, response: event});\n }\n\n loadtimeout() {\n if (this.loader) {\n this.loader.abort();\n }\n this.hls.trigger(Event.ERROR, {type: ErrorTypes.NETWORK_ERROR, details: ErrorDetails.FRAG_LOAD_TIMEOUT, fatal: false, frag: this.frag});\n }\n\n loadprogress(event, stats) {\n this.frag.loaded = stats.loaded;\n this.hls.trigger(Event.FRAG_LOAD_PROGRESS, {frag: this.frag, stats: stats});\n }\n}\n\nexport default FragmentLoader;\n",
"/*\n * Decrypt key Loader\n*/\n\nimport Event from '../events';\nimport EventHandler from '../event-handler';\nimport {ErrorTypes, ErrorDetails} from '../errors';\n\nclass KeyLoader extends EventHandler {\n\n constructor(hls) {\n super(hls, Event.KEY_LOADING);\n this.decryptkey = null;\n this.decrypturl = null;\n }\n\n destroy() {\n if (this.loader) {\n this.loader.destroy();\n this.loader = null;\n }\n EventHandler.prototype.destroy.call(this);\n }\n\n onKeyLoading(data) {\n var frag = this.frag = data.frag,\n decryptdata = frag.decryptdata,\n uri = decryptdata.uri;\n // if uri is different from previous one or if decrypt key not retrieved yet\n if (uri !== this.decrypturl || this.decryptkey === null) {\n var config = this.hls.config;\n frag.loader = this.loader = new config.loader(config);\n this.decrypturl = uri;\n this.decryptkey = null;\n frag.loader.load(uri, 'arraybuffer', this.loadsuccess.bind(this), this.loaderror.bind(this), this.loadtimeout.bind(this), config.fragLoadingTimeOut, config.fragLoadingMaxRetry, config.fragLoadingRetryDelay, this.loadprogress.bind(this), frag);\n } else if (this.decryptkey) {\n // we already loaded this key, return it\n decryptdata.key = this.decryptkey;\n this.hls.trigger(Event.KEY_LOADED, {frag: frag});\n }\n }\n\n loadsuccess(event) {\n var frag = this.frag;\n this.decryptkey = frag.decryptdata.key = new Uint8Array(event.currentTarget.response);\n // detach fragment loader on load success\n frag.loader = undefined;\n this.hls.trigger(Event.KEY_LOADED, {frag: frag});\n }\n\n loaderror(event) {\n if (this.loader) {\n this.loader.abort();\n }\n this.hls.trigger(Event.ERROR, {type: ErrorTypes.NETWORK_ERROR, details: ErrorDetails.KEY_LOAD_ERROR, fatal: false, frag: this.frag, response: event});\n }\n\n loadtimeout() {\n if (this.loader) {\n this.loader.abort();\n }\n this.hls.trigger(Event.ERROR, {type: ErrorTypes.NETWORK_ERROR, details: ErrorDetails.KEY_LOAD_TIMEOUT, fatal: false, frag: this.frag});\n }\n\n loadprogress() {\n\n }\n}\n\nexport default KeyLoader;\n",
2016-04-08 09:49:34 -07:00
"/**\n * Playlist Loader\n*/\n\nimport Event from '../events';\nimport EventHandler from '../event-handler';\nimport {ErrorTypes, ErrorDetails} from '../errors';\nimport URLHelper from '../utils/url';\nimport AttrList from '../utils/attr-list';\n//import {logger} from '../utils/logger';\n\nclass PlaylistLoader extends EventHandler {\n\n constructor(hls) {\n super(hls,\n Event.MANIFEST_LOADING,\n Event.LEVEL_LOADING);\n }\n\n destroy() {\n if (this.loader) {\n this.loader.destroy();\n this.loader = null;\n }\n this.url = this.id = null;\n EventHandler.prototype.destroy.call(this);\n }\n\n onManifestLoading(data) {\n this.load(data.url, null);\n }\n\n onLevelLoading(data) {\n this.load(data.url, data.level, data.id);\n }\n\n load(url, id1, id2) {\n var config = this.hls.config,\n retry,\n timeout,\n retryDelay;\n this.url = url;\n this.id = id1;\n this.id2 = id2;\n if(this.id === null) {\n retry = config.manifestLoadingMaxRetry;\n timeout = config.manifestLoadingTimeOut;\n retryDelay = config.manifestLoadingRetryDelay;\n } else {\n retry = config.levelLoadingMaxRetry;\n timeout = config.levelLoadingTimeOut;\n retryDelay = config.levelLoadingRetryDelay;\n }\n this.loader = typeof(config.pLoader) !== 'undefined' ? new config.pLoader(config) : new config.loader(config);\n this.loader.load(url, '', this.loadsuccess.bind(this), this.loaderror.bind(this), this.loadtimeout.bind(this), timeout, retry, retryDelay);\n }\n\n resolve(url, baseUrl) {\n return URLHelper.buildAbsoluteURL(baseUrl, url);\n }\n\n parseMasterPlaylist(string, baseurl) {\n let levels = [], result;\n\n // https://regex101.com is your friend\n const re = /#EXT-X-STREAM-INF:([^\\n\\r]*)[\\r\\n]+([^\\r\\n]+)/g;\n while ((result = re.exec(string)) != null){\n const level = {};\n\n var attrs = level.attrs = new AttrList(result[1]);\n level.url = this.resolve(result[2], baseurl);\n\n var resolution = attrs.decimalResolution('RESOLUTION');\n if(resolution) {\n level.width = resolution.width;\n level.height = resolution.height;\n }\n level.bitrate = attrs.decimalInteger('AVERAGE-BANDWIDTH') || attrs.decimalInteger('BANDWIDTH');\n level.name = attrs.NAME;\n\n var codecs = attrs.CODECS;\n if(codecs) {\n codecs = codecs.split(',');\n for (let i = 0; i < codecs.length; i++) {\n const codec = codecs[i];\n if (codec.indexOf('avc1') !== -1) {\n level.videoCodec = this.avc1toavcoti(codec);\n } else {\n level.audioCodec = codec;\n }\n }\n }\n\n levels.push(level);\n }\n return levels;\n }\n\n avc1toavcoti(codec) {\n var result, avcdata = codec.split('.');\n if (avcdata.length > 2) {\n result = avcdata.shift() + '.';\n result += parseInt(avcdata.shift()).toString(16);\n result += ('000' + parseInt(avcdata.shift()).toString(16)).substr(-4);\n } else {\n result = codec;\n }\n return result;\n }\n\n cloneObj(obj) {\n return JSON.parse(JSON.stringify(obj));\n }\n\n parseLevelPlaylist(string, baseurl, id) {\n var currentSN = 0,\n totalduration = 0,\n level = {url: baseurl, fragments: [], live: true, startSN: 0},\n levelkey = {method : null, key : null, iv : null, uri : null},\n cc = 0,\n programDateTime = null,\n frag = null,\n result,\n regexp,\n byteRangeEndOffset,\n byteRangeStartOffset;\n\n regexp = /(?:#EXT-X-(MEDIA-SEQUENCE):(\\d+))|(?:#EXT-X-(TARGETDURATION):(\\d+))|(?:#EXT-X-(KEY):(.*))|(?:#EXT(INF):([\\d\\.]+)[^\\r\\n]*([\\r\\n]+[^#|\\r\\n]+)?)|(?:#EXT-X-(BYTERANGE):([\\d]+[@[\\d]*)]*[\\r\\n]+([^#|\\r\\n]+)?|(?:#EXT-X-(ENDLIST))|(?:#EXT-X-(DIS)CONTINUITY))|(?:#EXT-X-(PROGRAM-DATE-TIME):(.*))/g;\n while ((result = regexp.exec(string)) !== null) {\n result.shift();\n result = result.filter(function(n) { return (n !== undefined); });\n s
2016-03-18 10:28:45 -07:00
"/**\n * Generate MP4 Box\n*/\n\n//import Hex from '../utils/hex';\nclass MP4 {\n static init() {\n MP4.types = {\n avc1: [], // codingname\n avcC: [],\n btrt: [],\n dinf: [],\n dref: [],\n esds: [],\n ftyp: [],\n hdlr: [],\n mdat: [],\n mdhd: [],\n mdia: [],\n mfhd: [],\n minf: [],\n moof: [],\n moov: [],\n mp4a: [],\n mvex: [],\n mvhd: [],\n sdtp: [],\n stbl: [],\n stco: [],\n stsc: [],\n stsd: [],\n stsz: [],\n stts: [],\n tfdt: [],\n tfhd: [],\n traf: [],\n trak: [],\n trun: [],\n trex: [],\n tkhd: [],\n vmhd: [],\n smhd: []\n };\n\n var i;\n for (i in MP4.types) {\n if (MP4.types.hasOwnProperty(i)) {\n MP4.types[i] = [\n i.charCodeAt(0),\n i.charCodeAt(1),\n i.charCodeAt(2),\n i.charCodeAt(3)\n ];\n }\n }\n\n var videoHdlr = new Uint8Array([\n 0x00, // version 0\n 0x00, 0x00, 0x00, // flags\n 0x00, 0x00, 0x00, 0x00, // pre_defined\n 0x76, 0x69, 0x64, 0x65, // handler_type: 'vide'\n 0x00, 0x00, 0x00, 0x00, // reserved\n 0x00, 0x00, 0x00, 0x00, // reserved\n 0x00, 0x00, 0x00, 0x00, // reserved\n 0x56, 0x69, 0x64, 0x65,\n 0x6f, 0x48, 0x61, 0x6e,\n 0x64, 0x6c, 0x65, 0x72, 0x00 // name: 'VideoHandler'\n ]);\n\n var audioHdlr = new Uint8Array([\n 0x00, // version 0\n 0x00, 0x00, 0x00, // flags\n 0x00, 0x00, 0x00, 0x00, // pre_defined\n 0x73, 0x6f, 0x75, 0x6e, // handler_type: 'soun'\n 0x00, 0x00, 0x00, 0x00, // reserved\n 0x00, 0x00, 0x00, 0x00, // reserved\n 0x00, 0x00, 0x00, 0x00, // reserved\n 0x53, 0x6f, 0x75, 0x6e,\n 0x64, 0x48, 0x61, 0x6e,\n 0x64, 0x6c, 0x65, 0x72, 0x00 // name: 'SoundHandler'\n ]);\n\n MP4.HDLR_TYPES = {\n 'video': videoHdlr,\n 'audio': audioHdlr\n };\n\n var dref = new Uint8Array([\n 0x00, // version 0\n 0x00, 0x00, 0x00, // flags\n 0x00, 0x00, 0x00, 0x01, // entry_count\n 0x00, 0x00, 0x00, 0x0c, // entry_size\n 0x75, 0x72, 0x6c, 0x20, // 'url' type\n 0x00, // version 0\n 0x00, 0x00, 0x01 // entry_flags\n ]);\n\n var stco = new Uint8Array([\n 0x00, // version\n 0x00, 0x00, 0x00, // flags\n 0x00, 0x00, 0x00, 0x00 // entry_count\n ]);\n\n MP4.STTS = MP4.STSC = MP4.STCO = stco;\n\n MP4.STSZ = new Uint8Array([\n 0x00, // version\n 0x00, 0x00, 0x00, // flags\n 0x00, 0x00, 0x00, 0x00, // sample_size\n 0x00, 0x00, 0x00, 0x00, // sample_count\n ]);\n MP4.VMHD = new Uint8Array([\n 0x00, // version\n 0x00, 0x00, 0x01, // flags\n 0x00, 0x00, // graphicsmode\n 0x00, 0x00,\n 0x00, 0x00,\n 0x00, 0x00 // opcolor\n ]);\n MP4.SMHD = new Uint8Array([\n 0x00, // version\n 0x00, 0x00, 0x00, // flags\n 0x00, 0x00, // balance\n 0x00, 0x00 // reserved\n ]);\n\n MP4.STSD = new Uint8Array([\n 0x00, // version 0\n 0x00, 0x00, 0x00, // flags\n 0x00, 0x00, 0x00, 0x01]);// entry_count\n\n var majorBrand = new Uint8Array([105,115,111,109]); // isom\n var avc1Brand = new Uint8Array([97,118,99,49]); // avc1\n var minorVersion = new Uint8Array([0, 0, 0, 1]);\n\n MP4.FTYP = MP4.box(MP4.types.ftyp, majorBrand, minorVersion, majorBrand, avc1Brand);\n MP4.DINF = MP4.box(MP4.types.dinf, MP4.box(MP4.types.dref, dref));\n }\n\n static box(type) {\n var\n payload = Array.prototype.slice.call(arguments, 1),\n size = 8,\n i = payload.length,\n len = i,\n result;\n // calculate the total size we need to allocate\n while (i--) {\n size += payload[i].byteLength;\n }\n result = new Uint8Array(size);\n result[0] = (size >> 24) & 0xff;\n result[1] = (size >> 16) & 0xff;\n result[2] = (size >> 8) & 0xff;\n result[3] = size & 0xff;\n result.set(type, 4);\n // copy the payload into the result\n for (i = 0, size = 8; i < len; i++) {\n
2016-03-27 16:22:53 -07:00
"/**\n * fMP4 remuxer\n*/\n\n\nimport Event from '../events';\nimport {logger} from '../utils/logger';\nimport MP4 from '../remux/mp4-generator';\nimport {ErrorTypes, ErrorDetails} from '../errors';\n\nclass MP4Remuxer {\n constructor(observer) {\n this.observer = observer;\n this.ISGenerated = false;\n this.PES2MP4SCALEFACTOR = 4;\n this.PES_TIMESCALE = 90000;\n this.MP4_TIMESCALE = this.PES_TIMESCALE / this.PES2MP4SCALEFACTOR;\n }\n\n get passthrough() {\n return false;\n }\n\n destroy() {\n }\n\n insertDiscontinuity() {\n this._initPTS = this._initDTS = this.nextAacPts = this.nextAvcDts = undefined;\n }\n\n switchLevel() {\n this.ISGenerated = false;\n }\n\n remux(audioTrack,videoTrack,id3Track,textTrack,timeOffset, contiguous) {\n // generate Init Segment if needed\n if (!this.ISGenerated) {\n this.generateIS(audioTrack,videoTrack,timeOffset);\n }\n if (this.ISGenerated) {\n //logger.log('nb AVC samples:' + videoTrack.samples.length);\n if (videoTrack.samples.length) {\n this.remuxVideo(videoTrack,timeOffset,contiguous);\n }\n //logger.log('nb AAC samples:' + audioTrack.samples.length);\n if (audioTrack.samples.length) {\n this.remuxAudio(audioTrack,timeOffset,contiguous);\n }\n }\n //logger.log('nb ID3 samples:' + audioTrack.samples.length);\n if (id3Track.samples.length) {\n this.remuxID3(id3Track,timeOffset);\n }\n //logger.log('nb ID3 samples:' + audioTrack.samples.length);\n if (textTrack.samples.length) {\n this.remuxText(textTrack,timeOffset);\n }\n //notify end of parsing\n this.observer.trigger(Event.FRAG_PARSED);\n }\n\n generateIS(audioTrack,videoTrack,timeOffset) {\n var observer = this.observer,\n audioSamples = audioTrack.samples,\n videoSamples = videoTrack.samples,\n pesTimeScale = this.PES_TIMESCALE,\n tracks = {},\n data = { tracks : tracks, unique : false },\n computePTSDTS = (this._initPTS === undefined),\n initPTS, initDTS;\n\n if (computePTSDTS) {\n initPTS = initDTS = Infinity;\n }\n if (audioTrack.config && audioSamples.length) {\n audioTrack.timescale = audioTrack.audiosamplerate;\n // MP4 duration (track duration in seconds multiplied by timescale) is coded on 32 bits\n // we know that each AAC sample contains 1024 frames....\n // in order to avoid overflowing the 32 bit counter for large duration, we use smaller timescale (timescale/gcd)\n // we just need to ensure that AAC sample duration will still be an integer (will be 1024/gcd)\n if (audioTrack.timescale * audioTrack.duration > Math.pow(2, 32)) {\n let greatestCommonDivisor = function(a, b) {\n if ( ! b) {\n return a;\n }\n return greatestCommonDivisor(b, a % b);\n };\n audioTrack.timescale = audioTrack.audiosamplerate / greatestCommonDivisor(audioTrack.audiosamplerate,1024);\n }\n logger.log ('audio mp4 timescale :'+ audioTrack.timescale);\n tracks.audio = {\n container : 'audio/mp4',\n codec : audioTrack.codec,\n initSegment : MP4.initSegment([audioTrack]),\n metadata : {\n channelCount : audioTrack.channelCount\n }\n };\n if (computePTSDTS) {\n // remember first PTS of this demuxing context. for audio, PTS + DTS ...\n initPTS = initDTS = audioSamples[0].pts - pesTimeScale * timeOffset;\n }\n }\n\n if (videoTrack.sps && videoTrack.pps && videoSamples.length) {\n videoTrack.timescale = this.MP4_TIMESCALE;\n tracks.video = {\n container : 'video/mp4',\n codec : videoTrack.codec,\n initSegment : MP4.initSegment([videoTrack]),\n metadata : {\n width : videoTrack.width,\n height : videoTrack.height\n }\n };\n if (computePTSDTS) {\n initPTS = Math.min(initPTS,videoSamples[0].pts - pesTimeScale * timeOffset);\n initDTS = Math.min(initDTS,videoSamples[0].dts - pe
2016-03-18 10:28:45 -07:00
"/**\n * passthrough remuxer\n*/\nimport Event from '../events';\n\nclass PassThroughRemuxer {\n constructor(observer) {\n this.observer = observer;\n this.ISGenerated = false;\n }\n\n get passthrough() {\n return true;\n }\n\n destroy() {\n }\n\n insertDiscontinuity() {\n }\n\n switchLevel() {\n this.ISGenerated = false;\n }\n\n remux(audioTrack,videoTrack,id3Track,textTrack,timeOffset,rawData) {\n var observer = this.observer;\n // generate Init Segment if needed\n if (!this.ISGenerated) {\n var tracks = {},\n data = { tracks : tracks, unique : true },\n track = videoTrack,\n codec = track.codec;\n\n if (codec) {\n data.tracks.video = {\n container : track.container,\n codec : codec,\n metadata : {\n width : track.width,\n height : track.height\n }\n };\n }\n\n track = audioTrack;\n codec = track.codec;\n if (codec) {\n data.tracks.audio = {\n container : track.container,\n codec : codec,\n metadata : {\n channelCount : track.channelCount\n }\n };\n }\n this.ISGenerated = true;\n observer.trigger(Event.FRAG_PARSING_INIT_SEGMENT,data);\n }\n observer.trigger(Event.FRAG_PARSING_DATA, {\n data1: rawData,\n startPTS: timeOffset,\n startDTS: timeOffset,\n type: 'audiovideo',\n nb: 1\n });\n }\n}\n\nexport default PassThroughRemuxer;\n",
2016-01-25 13:28:29 -07:00
"\n// adapted from https://github.com/kanongil/node-m3u8parse/blob/master/attrlist.js\nclass AttrList {\n\n constructor(attrs) {\n if (typeof attrs === 'string') {\n attrs = AttrList.parseAttrList(attrs);\n }\n for(var attr in attrs){\n if(attrs.hasOwnProperty(attr)) {\n this[attr] = attrs[attr];\n }\n }\n }\n\n decimalInteger(attrName) {\n const intValue = parseInt(this[attrName], 10);\n if (intValue > Number.MAX_SAFE_INTEGER) {\n return Infinity;\n }\n return intValue;\n }\n\n hexadecimalInteger(attrName) {\n if(this[attrName]) {\n let stringValue = (this[attrName] || '0x').slice(2);\n stringValue = ((stringValue.length & 1) ? '0' : '') + stringValue;\n\n const value = new Uint8Array(stringValue.length / 2);\n for (let i = 0; i < stringValue.length / 2; i++) {\n value[i] = parseInt(stringValue.slice(i * 2, i * 2 + 2), 16);\n }\n return value;\n } else {\n return null;\n }\n }\n\n hexadecimalIntegerAsNumber(attrName) {\n const intValue = parseInt(this[attrName], 16);\n if (intValue > Number.MAX_SAFE_INTEGER) {\n return Infinity;\n }\n return intValue;\n }\n\n decimalFloatingPoint(attrName) {\n return parseFloat(this[attrName]);\n }\n\n enumeratedString(attrName) {\n return this[attrName];\n }\n\n decimalResolution(attrName) {\n const res = /^(\\d+)x(\\d+)$/.exec(this[attrName]);\n if (res === null) {\n return undefined;\n }\n return {\n width: parseInt(res[1], 10),\n height: parseInt(res[2], 10)\n };\n }\n\n static parseAttrList(input) {\n const re = /\\s*(.+?)\\s*=((?:\\\".*?\\\")|.*?)(?:,|$)/g;\n var match, attrs = {};\n while ((match = re.exec(input)) !== null) {\n var value = match[2], quote = '\"';\n\n if (value.indexOf(quote) === 0 &&\n value.lastIndexOf(quote) === (value.length-1)) {\n value = value.slice(1, -1);\n }\n attrs[match[1]] = value;\n }\n return attrs;\n }\n\n}\n\nexport default AttrList;\n",
2015-12-15 22:30:14 -07:00
"var BinarySearch = {\n /**\n * Searches for an item in an array which matches a certain condition.\n * This requires the condition to only match one item in the array,\n * and for the array to be ordered.\n *\n * @param {Array} list The array to search.\n * @param {Function} comparisonFunction\n * Called and provided a candidate item as the first argument.\n * Should return:\n * > -1 if the item should be located at a lower index than the provided item.\n * > 1 if the item should be located at a higher index than the provided item.\n * > 0 if the item is the item you're looking for.\n *\n * @return {*} The object if it is found or null otherwise.\n */\n search: function(list, comparisonFunction) {\n var minIndex = 0;\n var maxIndex = list.length - 1;\n var currentIndex = null;\n var currentElement = null;\n \n while (minIndex <= maxIndex) {\n currentIndex = (minIndex + maxIndex) / 2 | 0;\n currentElement = list[currentIndex];\n \n var comparisonResult = comparisonFunction(currentElement);\n if (comparisonResult > 0) {\n minIndex = currentIndex + 1;\n }\n else if (comparisonResult < 0) {\n maxIndex = currentIndex - 1;\n }\n else {\n return currentElement;\n }\n }\n \n return null;\n }\n};\n\nmodule.exports = BinarySearch;\n",
2016-02-24 20:15:07 -07:00
"/*\n * CEA-708 interpreter\n*/\n\nclass CEA708Interpreter {\n\n constructor() {\n }\n\n attach(media) {\n this.media = media;\n this.display = [];\n this.memory = [];\n }\n\n detach()\n {\n this.clear();\n }\n\n destroy() {\n }\n\n _createCue()\n {\n var VTTCue = window.VTTCue || window.TextTrackCue;\n\n var cue = this.cue = new VTTCue(-1, -1, '');\n cue.text = '';\n cue.pauseOnExit = false;\n\n // make sure it doesn't show up before it's ready\n cue.startTime = Number.MAX_VALUE;\n\n // show it 'forever' once we do show it\n // (we'll set the end time once we know it later)\n cue.endTime = Number.MAX_VALUE;\n\n this.memory.push(cue);\n }\n\n clear()\n {\n var textTrack = this._textTrack;\n if (textTrack && textTrack.cues)\n {\n while (textTrack.cues.length > 0)\n {\n textTrack.removeCue(textTrack.cues[0]);\n }\n }\n }\n\n push(timestamp, bytes)\n {\n if (!this.cue)\n {\n this._createCue();\n }\n\n var count = bytes[0] & 31;\n var position = 2;\n var tmpByte, ccbyte1, ccbyte2, ccValid, ccType;\n\n for (var j=0; j<count; j++)\n {\n tmpByte = bytes[position++];\n ccbyte1 = 0x7F & bytes[position++];\n ccbyte2 = 0x7F & bytes[position++];\n ccValid = ((4 & tmpByte) === 0 ? false : true);\n ccType = (3 & tmpByte);\n\n if (ccbyte1 === 0 && ccbyte2 === 0)\n {\n continue;\n }\n\n if (ccValid)\n {\n if (ccType === 0) // || ccType === 1\n {\n // Standard Characters\n if (0x20 & ccbyte1 || 0x40 & ccbyte1)\n {\n this.cue.text += this._fromCharCode(ccbyte1) + this._fromCharCode(ccbyte2);\n }\n // Special Characters\n else if ((ccbyte1 === 0x11 || ccbyte1 === 0x19) && ccbyte2 >= 0x30 && ccbyte2 <= 0x3F)\n {\n // extended chars, e.g. musical note, accents\n switch (ccbyte2)\n {\n case 48:\n this.cue.text += '®';\n break;\n case 49:\n this.cue.text += '°';\n break;\n case 50:\n this.cue.text += '½';\n break;\n case 51:\n this.cue.text += '¿';\n break;\n case 52:\n this.cue.text += '™';\n break;\n case 53:\n this.cue.text += '¢';\n break;\n case 54:\n this.cue.text += '';\n break;\n case 55:\n this.cue.text += '£';\n break;\n case 56:\n this.cue.text += '♪';\n break;\n case 57:\n this.cue.text += ' ';\n break;\n case 58:\n this.cue.text += 'è';\n break;\n case 59:\n this.cue.text += 'â';\n break;\n case 60:\n this.cue.text += 'ê';\n break;\n case 61:\n this.cue.text += 'î';\n break;\n case 62:\n this.cue.text += 'ô';\n break;\n case 63:\n this.cue.text += 'û';\n break;\n }\n }\n if ((ccbyte1 === 0x11 || ccbyte1 === 0x19) && ccbyte2 >= 0x20 && ccbyte2 <= 0x2F)\n {\n // Mid-row codes: color/underline\n switch (ccbyte2)\n {\n case 0x20:\n // White\n break;\n case 0x21:\n // White Underline\n break;\n case 0x22:\n // Green\n break;\n case 0x23:\n // Green Underline\n break;\n case 0x24:\n // Blue\n break;\n case 0x25:\n // Blue Underline\n
2015-12-15 22:30:14 -07:00
"'use strict';\n\nfunction noop() {}\n\nconst fakeLogger = {\n trace: noop,\n debug: noop,\n log: noop,\n warn: noop,\n info: noop,\n error: noop\n};\n\nlet exportedLogger = fakeLogger;\n\n//let lastCallTime;\n// function formatMsgWithTimeInfo(type, msg) {\n// const now = Date.now();\n// const diff = lastCallTime ? '+' + (now - lastCallTime) : '0';\n// lastCallTime = now;\n// msg = (new Date(now)).toISOString() + ' | [' + type + '] > ' + msg + ' ( ' + diff + ' ms )';\n// return msg;\n// }\n\nfunction formatMsg(type, msg) {\n msg = '[' + type + '] > ' + msg;\n return msg;\n}\n\nfunction consolePrintFn(type) {\n const func = window.console[type];\n if (func) {\n return function(...args) {\n if(args[0]) {\n args[0] = formatMsg(type, args[0]);\n }\n func.apply(window.console, args);\n };\n }\n return noop;\n}\n\nfunction exportLoggerFunctions(debugConfig, ...functions) {\n functions.forEach(function(type) {\n exportedLogger[type] = debugConfig[type] ? debugConfig[type].bind(debugConfig) : consolePrintFn(type);\n });\n}\n\nexport var enableLogs = function(debugConfig) {\n if (debugConfig === true || typeof debugConfig === 'object') {\n exportLoggerFunctions(debugConfig,\n // Remove out from list here to hard-disable a log-level\n //'trace',\n 'debug',\n 'log',\n 'info',\n 'warn',\n 'error'\n );\n // Some browsers don't allow to use bind on console object anyway\n // fallback to default if needed\n try {\n exportedLogger.log();\n } catch (e) {\n exportedLogger = fakeLogger;\n }\n }\n else {\n exportedLogger = fakeLogger;\n }\n};\n\nexport var logger = exportedLogger;\n",
2016-03-09 10:40:22 -07:00
"var URLHelper = {\n\n // build an absolute URL from a relative one using the provided baseURL\n // if relativeURL is an absolute URL it will be returned as is.\n buildAbsoluteURL: function(baseURL, relativeURL) {\n // remove any remaining space and CRLF\n relativeURL = relativeURL.trim();\n if (/^[a-z]+:/i.test(relativeURL)) {\n // complete url, not relative\n return relativeURL;\n }\n\n var relativeURLQuery = null;\n var relativeURLHash = null;\n\n var relativeURLHashSplit = /^([^#]*)(.*)$/.exec(relativeURL);\n if (relativeURLHashSplit) {\n relativeURLHash = relativeURLHashSplit[2];\n relativeURL = relativeURLHashSplit[1];\n }\n var relativeURLQuerySplit = /^([^\\?]*)(.*)$/.exec(relativeURL);\n if (relativeURLQuerySplit) {\n relativeURLQuery = relativeURLQuerySplit[2];\n relativeURL = relativeURLQuerySplit[1];\n }\n\n var baseURLHashSplit = /^([^#]*)(.*)$/.exec(baseURL);\n if (baseURLHashSplit) {\n baseURL = baseURLHashSplit[1];\n }\n var baseURLQuerySplit = /^([^\\?]*)(.*)$/.exec(baseURL);\n if (baseURLQuerySplit) {\n baseURL = baseURLQuerySplit[1];\n }\n\n var baseURLDomainSplit = /^((([a-z]+):)?\\/\\/[a-z0-9\\.\\-_~]+(:[0-9]+)?\\/)(.*)$/i.exec(baseURL);\n var baseURLProtocol = baseURLDomainSplit[3];\n var baseURLDomain = baseURLDomainSplit[1];\n var baseURLPath = baseURLDomainSplit[5];\n\n var builtURL = null;\n if (/^\\/\\//.test(relativeURL)) {\n builtURL = baseURLProtocol+'://'+URLHelper.buildAbsolutePath('', relativeURL.substring(2));\n }\n else if (/^\\//.test(relativeURL)) {\n builtURL = baseURLDomain+URLHelper.buildAbsolutePath('', relativeURL.substring(1));\n }\n else {\n builtURL = URLHelper.buildAbsolutePath(baseURLDomain+baseURLPath, relativeURL);\n }\n\n // put the query and hash parts back\n if (relativeURLQuery) {\n builtURL += relativeURLQuery;\n }\n if (relativeURLHash) {\n builtURL += relativeURLHash;\n }\n return builtURL;\n },\n\n // build an absolute path using the provided basePath\n // adapted from https://developer.mozilla.org/en-US/docs/Web/API/document/cookie#Using_relative_URLs_in_the_path_parameter\n // this does not handle the case where relativePath is \"/\" or \"//\". These cases should be handled outside this.\n buildAbsolutePath: function(basePath, relativePath) {\n var sRelPath = relativePath;\n var nUpLn, sDir = '', sPath = basePath.replace(/[^\\/]*$/, sRelPath.replace(/(\\/|^)(?:\\.?\\/+)+/g, '$1'));\n for (var nEnd, nStart = 0; nEnd = sPath.indexOf('/../', nStart), nEnd > -1; nStart = nEnd + nUpLn) {\n nUpLn = /^\\/(?:\\.\\.\\/)*/.exec(sPath.slice(nEnd))[0].length;\n sDir = (sDir + sPath.substring(nStart, nEnd)).replace(new RegExp('(?:\\\\\\/+[^\\\\\\/]*){0,' + ((nUpLn - 1) / 3) + '}$'), '/');\n }\n return sDir + sPath.substr(nStart);\n }\n};\n\nmodule.exports = URLHelper;\n",
2016-03-02 10:05:35 -07:00
"/**\n * XHR based logger\n*/\n\nimport {logger} from '../utils/logger';\n\nclass XhrLoader {\n\n constructor(config) {\n if (config && config.xhrSetup) {\n this.xhrSetup = config.xhrSetup;\n }\n }\n\n destroy() {\n this.abort();\n this.loader = null;\n }\n\n abort() {\n var loader = this.loader,\n timeoutHandle = this.timeoutHandle;\n if (loader && loader.readyState !== 4) {\n this.stats.aborted = true;\n loader.abort();\n }\n if (timeoutHandle) {\n window.clearTimeout(timeoutHandle);\n }\n }\n\n load(url, responseType, onSuccess, onError, onTimeout, timeout, maxRetry, retryDelay, onProgress = null, frag = null) {\n this.url = url;\n if (frag && !isNaN(frag.byteRangeStartOffset) && !isNaN(frag.byteRangeEndOffset)) {\n this.byteRange = frag.byteRangeStartOffset + '-' + (frag.byteRangeEndOffset-1);\n }\n this.responseType = responseType;\n this.onSuccess = onSuccess;\n this.onProgress = onProgress;\n this.onTimeout = onTimeout;\n this.onError = onError;\n this.stats = {trequest: performance.now(), retry: 0};\n this.timeout = timeout;\n this.maxRetry = maxRetry;\n this.retryDelay = retryDelay;\n this.loadInternal();\n }\n\n loadInternal() {\n var xhr;\n\n if (typeof XDomainRequest !== 'undefined') {\n xhr = this.loader = new XDomainRequest();\n } else {\n xhr = this.loader = new XMLHttpRequest();\n }\n\n xhr.onloadend = this.loadend.bind(this);\n xhr.onprogress = this.loadprogress.bind(this);\n\n xhr.open('GET', this.url, true);\n if (this.byteRange) {\n xhr.setRequestHeader('Range', 'bytes=' + this.byteRange);\n }\n xhr.responseType = this.responseType;\n this.stats.tfirst = null;\n this.stats.loaded = 0;\n if (this.xhrSetup) {\n this.xhrSetup(xhr, this.url);\n }\n this.timeoutHandle = window.setTimeout(this.loadtimeout.bind(this), this.timeout);\n xhr.send();\n }\n\n loadend(event) {\n var xhr = event.currentTarget,\n status = xhr.status,\n stats = this.stats;\n // don't proceed if xhr has been aborted\n if (!stats.aborted) {\n // http status between 200 to 299 are all successful\n if (status >= 200 && status < 300) {\n window.clearTimeout(this.timeoutHandle);\n stats.tload = performance.now();\n this.onSuccess(event, stats);\n } else {\n // error ...\n if (stats.retry < this.maxRetry) {\n logger.warn(`${status} while loading ${this.url}, retrying in ${this.retryDelay}...`);\n this.destroy();\n window.setTimeout(this.loadInternal.bind(this), this.retryDelay);\n // exponential backoff\n this.retryDelay = Math.min(2 * this.retryDelay, 64000);\n stats.retry++;\n } else {\n window.clearTimeout(this.timeoutHandle);\n logger.error(`${status} while loading ${this.url}` );\n this.onError(event);\n }\n }\n }\n }\n\n loadtimeout(event) {\n logger.warn(`timeout while loading ${this.url}` );\n this.onTimeout(event, this.stats);\n }\n\n loadprogress(event) {\n var stats = this.stats;\n if (stats.tfirst === null) {\n stats.tfirst = performance.now();\n }\n stats.loaded = event.loaded;\n if (this.onProgress) {\n this.onProgress(event, stats);\n }\n }\n}\n\nexport default XhrLoader;\n"
2015-12-15 22:30:14 -07:00
]
}